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
harshit sharma: 2017-04-04 09:34:47

@sushant you have to give answer n fixed format i.e you have to print 100000 not 1e+5

sushantgokhale: 2017-04-04 09:24:32

tried it even using string but still its showing WA :|

sushantgokhale: 2017-04-04 09:15:29

@harshit sharma. In long double, its not overflowing. Confirmed it. 10^100 is shown as 1e+100. But if converted to fixed point format in c++, it shown as 100000000678787896365... . Dont know why this is being rounded.

harshit sharma: 2017-04-04 08:23:14

your value might be overflowing @sushant

sushantgokhale: 2017-04-04 06:07:14

does it require output in form of fixed point floating format or scientific format will also do? If I convert to fixed point, getting lot of round off. Any suggestions?

Simran Saha: 2017-04-03 07:58:05

can anybody provide some more test cases?

ameyanator: 2017-03-19 22:32:56

barely 3-4 lines of logic. If you're using java then use hasNextBigInteger() available in scanner class.

vanvinhbk94: 2017-02-19 04:57:07

use c++,
while (cin>>s){

Last edit: 2017-02-19 05:02:04
nilabja16180: 2017-02-15 21:24:45

With python AC in One Go
Got AC in C++, try in C++(take care digits ending with 5)

Last edit: 2017-02-15 23:02:36
scorpion_ajay: 2017-01-16 09:12:45

just get the pattern, rest is easy
60th finally :)

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