MINCOUNT - Move To Invert

no tags 

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

hide comments
nagesh: 2011-05-21 15:59:03

nice problem...:D
Just simple mathematics!!!

darryl: 2011-03-29 09:56:27

Just some math, watch out if h <= 2

Sushovan Sen: 2011-03-26 01:48:36

Ans for 100 is 1683

Nishit H Soni : 2011-03-18 17:44:53

hey!!
for 100 ans is 1683.....
please do not distract coders.....

Pawan: 2011-03-18 05:28:56

@ premnath yes answer for 100 is 2451.

Vipul Aggarwal: 2011-03-11 09:33:24

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.

.::Manish Kumar::.: 2010-12-14 20:04:37

Lesson: Sometimes simple problems cause big problems.

Alexander: 2010-11-19 17:03:23

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.

zingoba: 2010-10-21 21:14:17

isn't the correct answer for 10000000000 : 24999999995000000001?
NO! Its not :)

Last edit: 2010-11-08 20:52:24
premanandh_j: 2010-08-14 05:28:47

is the output fr 100 is 2451?...

Last edit: 2010-08-14 05:56:35

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