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
2011-05-21 15:59:03 nagesh
nice problem...:D
Just simple mathematics!!!
2011-03-29 09:56:27 darryl
Just some math, watch out if h <= 2
2011-03-26 01:48:36 Sushovan Sen
Ans for 100 is 1683
2011-03-18 17:44:53 Nishit H Soni
hey!!
for 100 ans is 1683.....
please do not distract coders.....
2011-03-18 05:28:56 Pawan
@ premnath yes answer for 100 is 2451.
2011-03-11 09:33:24 Vipul Aggarwal
Please check the source code of id#4795530. Gives correct answer for all the test cases mentioned above including 10^10 on my comp. But shows WA here.Kindly help.
2010-12-14 20:04:37 .::Manish Kumar::.
Lesson: Sometimes simple problems cause big problems.
2010-11-19 17:03:23 Alexander
The correct result for h=10^10 *is* smaller than 2**64 but not smaller than 2**63, so use unsigned long long. Also make sure your intermediate calculations don't overflow.
2010-10-21 21:14:17 zingoba
isn't the correct answer for 10000000000 : 24999999995000000001?
NO! Its not :)

Last edit: 2010-11-08 20:52:24
2010-08-14 05:28:47 premanandh_j
is the output fr 100 is 2451?...

Last edit: 2010-08-14 05:56:35
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.