VECTAR10 - Card Game

no tags 

Changu and Mangu have an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. They want to play a game. They perform a wierd operation as long as there are at least two cards in the deck: Changu throws away the top card and then Mangu moves the card that is now on the top of the deck to the bottom of the deck. Your task is to find the last remaining card.

Input

Each line of input (except the last) contains a positive number n ≤ 1000000. The last line contains 0 and this line should not be processed. Input will not contain more than 500000 lines.

Output

For each number from input produce one line of output giving the last remaining card.

Example

Sample Input:
2
3
4
0

Sample Output:
2
2
4

Warning: Large I/O data, be careful with certain languages


hide comments
akshayvenkat: 2016-07-05 19:21:23

@Piyush please to helpppp >.< getting WA

yaay AC :D great problem bro!

Last edit: 2016-07-05 19:25:10
pvsmpraveen: 2016-07-05 18:38:34

@Piyush : Can you check my submission, i am getting a WA

Re: Your solution is correct. Look at the constraints and check for border cases. Good Luck :)

Done! , Thanks

Last edit: 2016-07-05 18:46:00

Added by:Piyush Kumar
Date:2016-07-05
Time limit:0.100s-3s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU JS-MONKEY