https://www.acmicpc.net/problem/2164
import sys
N = int(sys.stdin.readline())
card=[]
card=list(range(1,N+1))
while len(card)!=1:
card.pop(0)
if len(card)==1:
break
a=card.pop(0)
card.append(a)
print(card[0])
from collections import deque
N=int(input())
deque=deque([i for i in range(1,N+1)])
while(len(deque)>1):
deque.popleft()
move=deque.popleft()
deque.append(move)
print(deque[0])
input = int(input())
square = 2
while True:
if (input == 1 or input == 2):
print(input)
break
square *= 2
if (square >= input):
print((input - (square // 2)) * 2)
break
출처: https://tooo1.tistory.com/88 [개발자 퉁이리:티스토리]