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
malibarbar: 2016-08-23 14:03:48

Ac in one in c++

piyush_arora1: 2016-08-12 19:08:47

Don't forget that for n = 0 or n = 1, output is n. Also for input use while(cin >> n).

baadshah_: 2016-06-22 22:47:50

For input USE: while((scanf("%s",&num))!=EOF)

avisheksanvas: 2016-05-19 12:38:00

C++ people. After reading in a Character array, store it in an Integer array. It'll make your work easier.
And store it opposite. That'll ease multiplication and division. :)
A trivial bid integer implementation. Direct Formula.

lalit_nit: 2016-01-23 16:21:07

For Java Coders..... in.hasNextBigInteger();...... insted of some input cases...... this costed me 3WA :/

aman8soni: 2015-07-08 04:52:15

@rpc1: while(scanf("%d",&t)!=EOF)

Dushyant Singh: 2015-06-28 07:09:16

@king: I have done it in 36. :-)

saumya: 2014-10-26 10:24:14

Had to learn a little Java just for this question .. finally AC after two compilation errors :P

stranger: 2014-01-06 06:15:54


N <= 10^100, long long is not suitable

Shashank Gupta: 2013-11-06 09:25:14

One line, 82 characters in Python. :) Kinda fun.

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