MINCOUNT - Move To Invert

A triangle made of coins of height h is as follows:

  • It has h coins at the base and h-1 coins one level above base and so on. (Coins are placed as shown in the figure below.)
  • At the top-most level there will be only one coin.

Now given h, the task is to invert this triangle by moving the minimum number of coins.

For example when h=4 triangle is:
Invert

For h=4 at least 3 coins must be moved to invert it.

Input

In the first line N will be given and then N lines follow with each line having a integer which is the height of triangle in that test case. (0 ≤ h < 1010.)

Output

For each test case output in a separate line the minimum number of moves required to invert the triangle. Output fits in long long data type.

Example

Input:
1
3

Output:
2

Added by:Abhilash I
Date:2006-12-16
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO
Resource:IIIT Hyderabad Local Programming Contest

hide comments
2013-03-19 19:40:30 Gopinath
Same Algo in Python and C++ , TLE and in C , AC.. :)
2013-03-05 20:26:29 @looser@
same algo in python TLE and in c AC
2013-03-03 09:23:18 Ouditchya Sinha
It's weird, my AC solution gives 1294379940242040320 for 10^10... looks like test cases are weak.
2013-03-03 07:08:04 Po
Answer for 100 is 1683....HOW..Could somebody pls explain?
2012-12-27 05:14:39 bigBOSS
any tricky case plzzz. getting WA
2012-07-27 08:49:32 secret22
how to minimise the time?
its showing time limit exceeded :(
2012-06-22 03:27:23 Pranshul Agarwal
test cases are weak.... output for 10^10 4368837285860298922 still got AC
2012-06-12 18:48:28 eliminator
:)AC gives=>
10000000000 = 16666666668333333333
2012-06-12 18:47:52 eliminator
top row = 1, second row = 2 3, third row = 4 5 6, fourth row = 7 8 9 10 Solution: move 7 to the left of 2, move 10 to the right of 3, move 1 below 8&9
2012-06-03 17:56:18 The Mundane Programmer
not getting how it is inverted by moving 3 coins.......
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.