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)
And at the top most level there will be only one coin
Now given h the task is to invert this triangle by moving 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.00≤h<1010;

Output

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

Example

Inputt:
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
2015-06-09 08:29:44 PRIBAN91
Getting lots of TLE in Java. Any suggestion will be appreciated.
2014-10-17 19:50:38 Ankit Aggarwal
http://discuss.codechef.com/questions/50378/spoj-mincount-wa
2014-10-17 08:37:51 Mahesh Mishra
Test Cases are weak..
2014-08-16 21:28:26 pvkcse
As like others,same algo in python got TLE while in C AC with 14 lines...It is the shortest C code written in Spoj by me...
2014-06-16 09:29:26 Ayush Vatsa
Move to challenge
2014-04-03 06:34:47 sarelfeniel
Nice problem! Learnt something about how to cleverly avoid overflow errors.
2014-03-09 18:47:46 mockingjay
it seems that 10^10 is not in test cases
my soln gives 1294379940242040320 stil ac.
2013-12-12 10:59:05 NoName
at last got AC after a lots of TLE...if using c++ then use scanf and printf instead of cin and cout...this shows that scanf and printf are really faster...
2013-08-01 12:40:30 Raman Shukla
Simple O(1) solution... Solve for small cases to get the answer...
2013-04-05 06:29:41 mystique_blue
Move to challenge.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.