Time limit
2s
Memory limit
128 MB
There are N cards numbered from 1 through N in a stack. Initially, card 1 is on top and card N is on the bottom.
Repeat the following two operations until only one card remains.
For N = 4, the initial order from top to bottom is 1, 2, 3, 4. After discarding 1 and moving 2 to the bottom, the order becomes 3, 4, 2. Then 3 is discarded and 4 is moved to the bottom, leaving 2, 4. Finally, 2 is discarded and 4 remains.
Given N, write a program that prints the discarded card numbers in order, followed by the number of the final remaining card.
The first line contains an integer N. (1 <= N <= 1,000)
Print one line containing the discarded card numbers in order, followed by the final remaining card number. Separate adjacent numbers with a single space.