BISHOPS - Bishops

Yesterday was Sam's birthday. The most interesting gift was definitely the chessboard. Sam quickly learned the rules of chess and defeated his father, all his friends, his little sister, and now no one wants to play with him any more.

So he decided to play with another birthday gift – a Book of Math Problems for Young Mathematicians. He opened the book somewhere in the middle and read the following problem: "How many knights can be placed on a chessboard without threatening each other?" After a while he realized that this was trivial and moved on to the next problem: "How many bishops can be placed on a chessboard without threatening each other?". Sam is in trouble here. He is not able to solve this problem and needs your help.

Sam's chessboard has size N x N. A bishop can move to any distance in any of the four diagonal directions. A bishop threatens another bishop if it can move to the other bishop's position. Your task is to compute the maximum number of bishops that can be placed on a chessboard in such a way that no two bishops threaten each other.


The input file consists of several lines. The line number i contains a single positive integer N representing the size of the i-th chessboard. [1 <= N <= 10^100]


The output file should contain the same number of lines as the input file. The i-th line should contain one number – the maximum number of bishops that can be placed on i-th chessboard without threatening each other.




hide comments
mrmajumder: 2020-02-05 11:36:26

Check for the corner case, very important!

mriow: 2019-10-29 10:11:43 will be your friend to check for the EOF

nikhil_sarda: 2019-08-26 14:48:00

as far as the input is concerned,use getline(cin,<string_name>) ,and while <string_name>!="",
works fine for C++

sanket17: 2019-07-08 11:50:40

Use try except in python
and take case of n=0,n=1

kkksc04: 2019-06-09 05:10:19

why python 2*n-2 can't AC? Who can tell me? Thanks a lot!

Last edit: 2019-06-09 05:10:45
jackobek: 2019-04-30 00:21:48

becouse of endl 3 WA

aj_254: 2019-04-23 20:54:36

my 50th on spoj....all 50 in python ... i make myselt the pythonist. checkout my github rajat_254 for spoj python solutions

Aahitagni Mukherjee: 2019-04-19 22:09:53

take care of corner case. Also use C++14 if you're using boost multiprecision library.

alpish1: 2019-03-27 15:45:17

how many inputs do we have to take in this problem its not specified.

adipat: 2019-02-02 10:45:18

Very simple problem, just focus on finding the pattern. If you're using Python, don't use input(), instead use sys.stdin.readlines().

Last edit: 2019-02-02 10:45:26

Added by:Roman Sol
Time limit:1s
Source limit:10000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Resource:IPSC 2004