Elimination Game

You are given the integers from 1 to n arranged in a list. A game proceeds in rounds as follows:

  • First round: remove every other number from left to right, starting with the first number. The first number (1) is removed, the second (2) is kept, the third (3) is removed, the fourth (4) is kept, and so on.
  • Second round: with the remaining numbers, remove every other number from right to left, starting with the rightmost number. The rightmost number is removed, the next one to its left is kept, and so on.
  • Continue alternating directions until only one number remains.

Return the last remaining number.

Examples
Input: 1
Output: 1
Hints

Elimination Game

You are given the integers from 1 to n arranged in a list. A game proceeds in rounds as follows: