Use Deque when pop and append


白駿2164号、カード2
https://www.acmicpc.net/problem/2164
従来の一般的なリストのpopとappendでは、メモリオーバーフローとタイムアウトが発生します.
Dequeを使用すると、問題をより迅速に解決できます.
import sys
import collections
input = sys.stdin.readline
n = int(input())
s = [i for i in range(1,n+1)]
s = collections.deque([i for i in range(1,n+1)])

while len(s) > 1:
    s.popleft()
    s.rotate(-1)

print(s[0])
Reference : https://leonkong.cc/posts/python-deque.html