Problem:

List

 

  For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.

  
insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.

  
move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.

  
erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END.
  

  In the initial state, $L$ is empty and the cursor points END.

Input

  The input is given in the following format.

$q$
$query_1$
$query_2$
:
$query_q$

Each query $query_i$ is given by

0 $x$

or

1 $d$

or

2

  where the first digits 0, 1 and 2 represent insert, move and erase operations respectively.

Output

  Print all elements of the list in order after performing given operations. Print an element in a line.

Constraints

  
$1 \leq q \leq 500,000$

  
The cursor indicates an element of $L$ or END during the operations

  
Erase operation will not given when the cursor points END

  
$-1,000,000,000 \leq x \leq 1,000,000,000$

  
Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000

  
$L$ is not empty after performing all operations

Sample Input 1

5
0 1
0 2
0 3
1 1
2

Sample Output 1

3
1



Sample input:
5
0 1
0 2
0 3
1 1
2


Sample output:
3
1

Submission status: Wrong Answer

Solution code:
from sys import stdin

num = int(input())

list2 = ["END"]
cur = list2.index("END")

for i in range(num):
	cmd = stdin.readline().strip().split()

	if cmd[0] == "0":
		#直前にxを挿入する.その要素を指す
		if cur == 0:
			list2.insert(0,cmd[1])
			cur = 0
		else:
			list2.insert(cur-1,cmd[1])
			cur -= 1

	elif cmd[0] == "1":
		#正の場合カーソルを＋移動、負の場合－移動
		cur += int(cmd[1])
	else:
		#該当の要素を削除。無ければENDを指す
		tmp = cur
		list2.pop(cur)
		cur1 = list2.index("END")
		if tmp == cur1 - 1:
			cur = list2.index("END")
		else:
			cur += 1

list2.remove("END")
print(*list2,sep='\n')

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque

num = int(input())

list2 = deque()

list2.appendleft("END")
cur = 0

for i in range(num):
	cmd = stdin.readline().strip()

	if cmd[0:1] == "0":
		if cur == 0:
			list2.appendleft(cmd[2:])
		else:
			list2.insert(cur,cmd[2:])
	elif cmd[0:1] == "1":
		cur += int(cmd[2:])
	else:
		list2.remove(list2[cur])

list2.remove("END")
print(*list2,sep='\n')

Submission status: Wrong Answer

Solution code:
arr = []
cur = 0

q = int(input())
for i in range(q):
    op = list(map(int, input().split(' ')))
    if op[0] == 0:
        arr.insert(cur, op[1])
    elif op[0] == 1:
        cur += op[1]
    elif op[0] == 2:
        arr.pop(cur)
    if len(arr) >= cur: cur = len(arr)-1

for ele in arr:
    print(ele)

Submission status: Wrong Answer

Solution code:
arr = []
cur = 0

q = int(input())
for i in range(q):
    op = list(map(int, input().split(' ')))
    if op[0] == 0:
        arr.insert(cur, op[1])
    elif op[0] == 1:
        cur += op[1]
    elif op[0] == 2:
        arr.pop(cur)
    if len(arr) <= cur: cur = len(arr)-1

for ele in arr:
    print(ele)

Submission status: Wrong Answer

Solution code:
from collections import deque

cursor = 0
arr = deque()

for _ in range(int(input())):
    q = [int(x) for x in input().split()]

    if q[0] == 0:
        try:
            arr.insert(cursor-1, q[1])
            cursor -= 1
        except:
            arr.insert(0, q[1])
    elif q[0] == 1:
        cursor += q[1]
    else:
        arr.remove(arr[cursor])
        if cursor < len(arr):
            cursor += 1


for a in arr:
    print(a)

Submission status: Wrong Answer

Solution code:
class Node:
    def __init__(self, value):
        self.value = value
        self.next = None
        self.prev = None


def run():
    n = int(input())
    tail = Node(None)
    node = tail

    for _ in range(n):
        command = input()
        if command.startswith('0'):
            nn = Node(int(command[2:]))
            nn.prev, nn.next = node.prev, node
            if node.prev is not None:
                node.prev.next = nn
            node.prev = nn
            node = node.prev
        elif command.startswith('1'):
            i = int(command[2:])
            if i > 0:
                for _ in range(i):
                    node = node.next
            else:
                for _ in range(-i):
                    node = node.prev
        elif command.startswith('2'):
            p, n = node.prev, node.next
            node.prev, node.next = None, None
            node = n
            if p is None:
                n.prev = None
            else:
                n.prev, p.next = p, n
        else:
            raise ValueError('invalid command')

    st = []
    node = tail.prev
    while node is not None:
        st.append(node.value)
        node = node.prev

    for n in st:
        print(n)


if __name__ == '__main__':
    run()

Submission status: Wrong Answer

Solution code:
class Node:
    def __init__(self, val=None, prev=None, next=None):
        self.val = val
        self.prev = prev
        self.next = next

class DoublyLinkedList():
    def __init__(self, cur=None):
        self.num = 0
        self.cur = cur
        self.first = cur

    def insert(self, x):
        if self.cur == None:
            self.cur = Node(x, None, None)
            self.first = self.cur
        else:
            prev = self.cur.prev
            new_node = Node(x, prev, self.cur)
            if prev != None: prev.next = new_node
            self.cur.prev = new_node
            self.cur = new_node
        self.__set_first()

    def move(self, d):
        if d > 0:
            for i in range(d):
                if self.cur.next == None: break
                self.cur = self.cur.next
        elif d < 0:
            for i in range(abs(d)):
                if self.cur.prev == None: break
                self.cur = self.cur.prev

    def erase(self):
        if self.cur.next == None:
            self.cur = self.cur.prev
            if self.cur != None: self.cur.next = None
        else:
            if self.cur.prev != None: self.cur.prev.next = self.cur.next
            self.cur.next.prev = self.cur.prev
            self.cur = self.cur.next
        self.__set_first()

    def __set_first(self):
        if self.cur != None and self.cur.prev == None:
            self.first = self.cur

    def print_elements(self):
        node = self.first
        while True:
            if node == None: break
            print(node.val)
            node = node.next

dll = DoublyLinkedList()
q = int(input())
for i in range(q):
    op = list(map(int, input().split(' ')))
    if op[0] == 0:
        dll.insert(op[1])
    elif op[0] == 1:
        dll.move(op[1])
    elif op[0] == 2:
        dll.erase()

dll.print_elements()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

num = int(input())

list2 = ["END"]
cur = list2.index("END")

for i in range(num):
	cmd = stdin.readline().strip().split()

	if cmd[0] == "0":
		if cur == 0:
			list2.insert(0,cmd[1])
			cur = 0
		else:
			list2.insert(cur,cmd[1])

	elif cmd[0] == "1":
		cur += int(cmd[1])
	else:
		tmp = cur
		list2.pop(cur)
		cur1 = list2.index("END")
		if tmp == cur1 - 1:
			cur = list2.index("END")

list2.remove("END")
print(*list2,sep='\n')

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

num = int(input())

list2 = ["END"]
cur = list2.index("END")

for i in range(num):
	cmd = stdin.readline().strip().split()

	if cmd[0] == "0":
		#直前にxを挿入する.その要素を指す
#		if cur == 0:
#			list2.insert(0,cmd[1])
#			cur = 0
#		else:
		list2.insert(cur,cmd[1])
#		print("cur="+str(cur))

	elif cmd[0] == "1":
		#正の場合カーソルを＋移動、負の場合－移動
		cur += int(cmd[1])
#		print("cur="+str(cur))
	else:
		#該当の要素を削除。curは後ろを指す(curは移動しない！).無ければENDを指す
		tmp = cur
		list2.pop(cur)
		cur1 = list2.index("END")
		if tmp == cur1 - 1:
			cur = list2.index("END")
#		print("cur="+str(cur))
#	print(list2)

#print("----")
list2.remove("END")
print(*list2,sep='\n')

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

num = int(input())

list2 = ["END"]
cur = list2.index("END")

for i in range(num):
	cmd = stdin.readline().strip().split()

	if cmd[0] == "0":
		list2.insert(cur,cmd[1])
	elif cmd[0] == "1":
		cur += int(cmd[1])
	else:
		list2.pop(cur)

list2.remove("END")
print(*list2,sep='\n')

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat May 19 17:41:47 2018
AOJ ITP2_1_C
@author: maezawa
"""

q = int(input())
a = ['end']
curs = 0

for i in range(q):
    ops= list(map(int,input().split()))
    if ops[0] == 0:
        a.insert(curs,ops[1])
    elif ops[0] == 1:
        curs += ops[1]
    else:
        a.pop(curs)
        
for i in range(len(a)-1):
    print(a[i])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
list = []
cursor = 0

for i in range(n):
    cmd = [int(i) for i in input().split()]

    if cmd[0] == 0:
        list.insert(cursor, cmd[1])

    elif cmd[0] == 1:
        cursor += cmd[1]

    elif cmd[0] == 2:
        list.pop(cursor)

for x in list:
    print(x)

Submission status: Time Limit Exceeded

Solution code:
from array import array

n = int(input())
arr = array('I', [])
cursor = 0

for i in range(n):
    cmd = [int(i) for i in input().split()]

    if cmd[0] == 0:
        arr.insert(cursor, cmd[1])

    elif cmd[0] == 1:
        cursor += cmd[1]

    elif cmd[0] == 2:
        arr.pop(cursor)

for x in arr:
    print(x)

Submission status: Time Limit Exceeded

Solution code:
arr = []
cur = 0

q = int(input())
for i in range(q):
    op = list(map(int, input().split(' ')))
    if op[0] == 0:
        arr.insert(cur, op[1])
    elif op[0] == 1:
        cur += op[1]
    elif op[0] == 2:
        arr.pop(cur)

for ele in arr:
    print(ele)

Submission status: Time Limit Exceeded

Solution code:
arr = []
cur = 0

q = int(input())
for i in range(q):
    op = list(map(int, input().split(' ')))
    if op[0] == 0:
        arr.insert(cur, op[1])
    elif op[0] == 1:
        cur += op[1]
    elif op[0] == 2:
        arr.pop(cur)

for ele in arr:
    print(ele)

Submission status: Time Limit Exceeded

Solution code:

def run():
    n = int(input())
    li = []
    index = 0

    for _ in range(n):
        command = input()
        if command.startswith('0'):
            val = int(command[2:])
            li.insert(index, val)
        elif command.startswith('1'):
            i = int(command[2:])
            index += i
        elif command.startswith('2'):
            del(li[index])
        else:
            raise ValueError('invalid command')

    for n in li:
        print(n)


if __name__ == '__main__':
    run()

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n = int(input())
    lists = list()
    c = 0

    for i in range(n):
        q = input().split()

        if int(q[0]) == 0:
            lists.insert(c, int(q[1]))
        elif int(q[0]) == 1:
            c += int(q[1])
        else:
            lists.pop(c)
            if c == len(lists) - 1:
                c -= 1

    for i in lists:
        print(i)

Submission status: Time Limit Exceeded

Solution code:
# coding=utf-8

A = []
cursor = 0

N = int(input())
for i in range(N):
    query = list(map(int, input().split()))
    if query[0] == 0:
        A.insert(cursor, query[1])
    elif query[0] == 1:
        cursor += query[1]
    elif query[0] == 2:
        A.pop(cursor)
[print(x) for x in A]

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n = int(input())
    lists = []
    c = 0
    count = 0

    for i in range(n):
        q = input().split()
        a, b = (q[0], q[1]) if len(q) == 2 else (q[0], None)

        if a == '0':
            lists.insert(c, int(b))
            count += 1
        elif a == '1':
            c += int(b)
        else:
            lists.pop(c)
            count -= 1
            if c == len(lists) - 1:
                c -= 1

    for i in lists:
        print(i)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n = int(input())
    lists = []
    c = 0
    count = 0

    for i in range(n):
        q = input().split()
        a, b = (q[0], q[1]) if len(q) == 2 else (q[0], None)

        if a == '0':
            lists.insert(c, int(b))
            count += 1
        elif a == '1':
            c += int(b)
        else:
            lists.pop(c)
            count -= 1
            if c == count - 1:
                c -= 1

    for i in lists:
        print(i)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 24 14:53:50 2018
ITP21B
@author: maezawa
"""


l = []
csl = 0

n = int(input())

for i in range(n):
    c = list(map(int, input().split()))
    if c[0] == 0:
        l.insert(csl, c[1])
    elif c[0] == 1:
        csl += c[1]
    else:
        l.pop(csl)

for i in l:
    print(i)

Submission status: Accepted

Solution code:
class Node:
    def __init__(self, value):
        self.value = value
        self.next = None
        self.prev = None


def run():
    n = int(input())
    tail = Node(None)
    node = tail

    for _ in range(n):
        command = input()
        if command.startswith('0'):
            nn = Node(int(command[2:]))
            nn.prev, nn.next = node.prev, node
            if node.prev is not None:
                node.prev.next = nn
            node.prev = nn
            node = node.prev
        elif command.startswith('1'):
            i = int(command[2:])
            if i > 0:
                for _ in range(i):
                    node = node.next
            else:
                for _ in range(-i):
                    node = node.prev
        elif command.startswith('2'):
            p, n = node.prev, node.next
            node.prev, node.next = None, None
            node = n
            if p is None:
                n.prev = None
            else:
                n.prev, p.next = p, n
        else:
            raise ValueError('invalid command')

    st = []
    node = tail.prev
    while node is not None:
        st.append(node.value)
        node = node.prev

    while len(st) > 0:
        print(st.pop())


if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
class List:
    def __init__(self, value=None):
        self.value = value
        self.next = None
        self.prev = None

    def insert(self, value):
        node = self.__class__(value)
        node.prev, node.next = self.prev, self
        if self.prev is not None:
            self.prev.next = node
        self.prev = node
        return node

    def delete(self):
        p, n = self.prev, self.next
        self.prev, self.next = None, None
        if p is None:
            n.prev = None
        else:
            n.prev, p.next = p, n
        return n

    def move(self, i):
        node = self
        if i > 0:
            for _ in range(i):
                node = node.next
        else:
            for _ in range(-i):
                node = node.prev
        return node

    def __iter__(self):
        return List.ListIterator(self)

    class ListIterator:
        def __init__(self, node):
            while node.prev is not None:
                node = node.prev
            self.node = node

        def __iter__(self):
            return self

        def __next__(self):
            val = self.node.value
            if val is None:
                raise StopIteration
            self.node = self.node.next
            return val


def run():
    n = int(input())
    li = List()

    for _ in range(n):
        command = input()
        if command.startswith('0'):
            li = li.insert(int(command[2:]))
        elif command.startswith('1'):
            li = li.move(int(command[2:]))
        elif command.startswith('2'):
            li = li.delete()
        else:
            raise ValueError('invalid command')

    for v in li:
        print(v)


if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
class Node:
    def __init__(self, val=None, prev=None, next=None):
        self.val = val
        self.prev = prev
        self.next = next

class DoublyLinkedList():
    def __init__(self):
        self.end = Node(val='END', prev=None, next=None)
        self.cur = self.end

    def insert(self, x):
        new_node = Node(val=x, prev=self.cur.prev, next=self.cur)
        if self.cur.prev != None: self.cur.prev.next = new_node
        self.cur.prev = new_node
        self.cur = new_node

    def move(self, d):
        if d > 0:
            for i in range(d):
                if self.cur.next == None: break
                self.cur = self.cur.next
        elif d < 0:
            for i in range(abs(d)):
                if self.cur.prev == None: break
                self.cur = self.cur.prev

    def erase(self):
        if self.cur == self.end: return
        if self.cur.prev != None: self.cur.prev.next = self.cur.next
        self.cur.next.prev = self.cur.prev
        self.cur = self.cur.next

    def print_elements(self):
        node_list = []
        crnode = self.end
        while True:
            if crnode.prev == None: break
            node_list.append(crnode.prev.val)
            crnode = crnode.prev
        for i in range(len(node_list)-1, -1, -1):
            print(node_list[i])

dll = DoublyLinkedList()
q = int(input())
for i in range(q):
    op = list(map(int, input().split(' ')))
    if op[0] == 0:
        dll.insert(op[1])
    elif op[0] == 1:
        dll.move(op[1])
    elif op[0] == 2:
        dll.erase()

dll.print_elements()

Submission status: Accepted

Solution code:
class Node:
    def __init__(self, value):
        self.value = value
        self.next = None
        self.prev = None
 
 
def run():
    n = int(input())
    tail = Node(None)
    node = tail
 
    for _ in range(n):
        command = input()
        if command.startswith('0'):
            nn = Node(int(command[2:]))
            nn.prev, nn.next = node.prev, node
            if node.prev is not None:
                node.prev.next = nn
            node.prev = nn
            node = node.prev
        elif command.startswith('1'):
            i = int(command[2:])
            if i > 0:
                for _ in range(i):
                    node = node.next
            else:
                for _ in range(-i):
                    node = node.prev
        elif command.startswith('2'):
            p, n = node.prev, node.next
            node.prev, node.next = None, None
            node = n
            if p is None:
                n.prev = None
            else:
                n.prev, p.next = p, n
        else:
            raise ValueError('invalid command')
 
    st = []
    node = tail.prev
    while node is not None:
        st.append(node.value)
        node = node.prev
 
    while len(st) > 0:
        print(st.pop())
 
 
if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
from collections import deque
import sys

def main():
    n=int(input())
    sum_d=0
    aa=deque()
    for _ in range(n):
        qq=list(map(int, input().split()))
        if qq[0]==0:
            aa.appendleft(qq[1])
        elif qq[0]==1:
            aa.rotate(-qq[1])
            sum_d+=qq[1]
        else:
            aa.popleft()
    aa.rotate(sum_d)
    for a in aa:
        print(a)

main()

Submission status: Accepted

Solution code:
from collections import deque
L = deque()
cnt = 0
n = int(input())
for i in range(n):
    tmp = input().split()
    if tmp[0] == "0":
        L.append(tmp[1])
    elif tmp[0] == "1":
        L.rotate(int(tmp[1]))
        cnt-=int(tmp[1])
    else:
        L.pop()
L.rotate(cnt)
L.reverse()
for i in L:
    print(i)

Submission status: Accepted

Solution code:
readline = open(0).readline
writelines = open(1, 'w').writelines

Q = int(readline())
root = [None, None, None]
cursor = root[1] = [root, None, None]


def insert(x):
    global cursor
    cursor[0][1] = cursor[0] = cursor = [cursor[0], cursor, x]


def move(d):
    global cursor
    if d > 0:
        for _ in range(d):
            cursor = cursor[1]
    else:
        for _ in range(-d):
            cursor = cursor[0]


def erase():
    global cursor
    cursor[1][0] = cursor[0]
    cursor[0][1] = cursor = cursor[1]


C = [insert, move, erase].__getitem__
for q in range(Q):
    t, *a = map(int, readline().split())
    C(t)(*a)
root = root[1]
ans = []
while root[1]:
    ans.append("%d\n" % root[2])
    root = root[1]
writelines(ans)

Submission status: Accepted

Solution code:
readline = open(0).readline
writelines = open(1, 'w').writelines

Q = int(readline())
root = [None, None, None]
cursor = root[1] = [root, None, None]


def insert(x):
    global cursor
    cursor[0][1] = cursor[0] = cursor = [cursor[0], cursor, x]


def move(d):
    global cursor
    if d > 0:
        for _ in range(d):
            cursor = cursor[1]
    else:
        for _ in range(-d):
            cursor = cursor[0]


def erase():
    global cursor
    cursor[1][0] = cursor[0]
    cursor[0][1] = cursor = cursor[1]


C = [insert, move, erase].__getitem__
for q in range(Q):
    t, *a = map(int, readline().split())
    C(t)(*a)
root = root[1]
ans = []
while root[1]:
    ans.append("%d\n" % root[2])
    root = root[1]
writelines(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque

input = sys.stdin.readline
q = int(input())
ans = deque()
cursor = 0
for _ in range(q):
    query = [int(i) for i in input().split()]
    if query[0] == 0:
        ans.appendleft(query[1])
    elif query[0] == 1:
        ans.rotate(-1 * query[1])
        cursor += query[1]
    else:
        ans.popleft()
ans.rotate(cursor)
print(*ans, sep="\n")

Submission status: Accepted

Solution code:
#3747518
q=int(input())
from collections import deque
l=deque()
c=0
for _ in range(q):
    *qi,=map(int, input().split())
    if qi[0]==0:
        l.append(qi[1])
    elif qi[0]==1:
        d=qi[1]
        l.rotate(d)
        c-=d
    else:
        l.pop()

l.rotate(c)
l.reverse()
for li in l:
    print(li)

Submission status: Accepted

Solution code:
num = int(input())
root = [None, None, None]   #[前の値、次の値、カーソル部のデータ]
root[1] = [root, None, None]
cursor = root[1]

def insert(x):
    global cursor

    cursor[0][1]= cursor[0] = cursor = [cursor[0], cursor, x]

def move(d):
    global cursor
    if d > 0:
        for i in range(d):
            cursor = cursor[1]  #d回だけcursorをたどる
    else:
        for i in range(-d):
            cursor = cursor[0]

def erase():
    global cursor
    cursor[1][0] = cursor[0]
    cursor = cursor[1]
    cursor[0][1] = cursor

for j in range(num):
    queryi = list(map(int, input().split()))

    if queryi[0] == 0:
        insert(queryi[1])
    elif queryi[0] == 1:
        move(queryi[1])
    else:
        erase()

root = root[1]
while root[1]:
    print(root[2])
    root = root[1]

Submission status: Accepted

Solution code:
import sys
from collections import deque
dq = deque()

#def insert_elem(ad_elem,curosor):

#def move(move_distance,cursor):

  #  return cursor

#def erase(cursor):


query_num = int(input())
cursor = 0
for i in range(query_num):
    query = sys.stdin.readline()
    if query[0] == '0':
        n = int(query[2:].strip())
        dq.appendleft(n)
    elif query[0] == '1':
        n = int(query[2:].strip())
        dq.rotate(-n)
        cursor += n
    else:
        dq.popleft()

dq.rotate(cursor)
for i in range(len(dq)):
    print(dq[i])

Submission status: Accepted

Solution code:
from collections import deque

q = int(input())

L = deque()
pointer = 0

for i in range(q):
    query = input().split()

    if query[0] == "0":
        L.appendleft(int(query[1]))
    elif query[0] == "1":
        pointer += int(query[1])
        L.rotate(-int(query[1]))
    else:
        L.popleft()
L.rotate(pointer)
for i in L:
    print(i)

Submission status: Accepted

Solution code:
from collections import deque
q = int(input())
dq = deque()
cur = 0
while q:
    q -= 1
    s = [*map(int, input().split())]
    if s[0] == 0:
        dq.append(s[1])
    elif s[0] == 1:
        dq.rotate(s[1])
        cur += s[1]
    else:
        dq.pop()
dq.rotate(-cur)
dq.reverse()
print(*dq, sep = '\n')

Submission status: Accepted

Solution code:
from collections import deque

def main():
    m = int(input())
    c = 0
    dq = deque()
    for _ in range(m):
        q = list(map(int,input().split()))
        if q[0] == 0:dq.appendleft(q[1])
        elif q[0] == 1:
            dq.rotate(-q[1])
            c+=q[1]
        else :dq.popleft()
    dq.rotate(c)
    for e in dq:print(e)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
    from sys import stdin
    f_i = stdin
    q = f_i.readline()
    d = 0

    from collections import deque
    L = deque()

    for l in f_i:
        if  l[0] == "0":
            L.append(l[2:])
        elif l[0] == "1":
            r = int(l[2:])
            L.rotate(r)
            d -= r
        else:
            L.pop()
    L.rotate(d)
    L.reverse()
    print("".join(L),end= "")
solve()

Submission status: Accepted

Solution code:
from collections import deque

d = deque()
q = int(input())
key = 0
for i in range(q):
    x, *y = map(int,input().split())
    if x == 0:
        d.append(y[0])
    elif x == 1:
        d.rotate(y[0])
        key -= y[0]
    else:
        d.pop()
d.rotate(key)
d.reverse()
for i in d:
    print(i)

Submission status: Accepted

Solution code:
from collections import deque

d=deque()
cur=0
n=int(input())

for i in range(n):
    q=list(map(int,input().split()))
    if q[0]==0:
        d.append(q[1])
    elif q[0]==1:
        d.rotate(q[1])
        cur-=q[1]
    else:
        d.pop()
        
d.rotate(cur)
d.reverse()

for i in d:
    print(i)

Submission status: Accepted

Solution code:
from collections import deque
import itertools

c = 0
l =deque([])

n = int(input())

for i in range(n):
    m = list(map(int,input().split()))
    if m[0] == 0:
        l.appendleft(m[1])

    elif m[0] == 1:
        l.rotate(-m[1])
        c += m[1]
    
    elif m[0] == 2:
        l.popleft()

ans = list(itertools.islice(l,len(l)-c,None)) + list(itertools.islice(l,None,len(l)-c))
for j in ans:
    print(j)

Submission status: Accepted

Solution code:
from collections import deque

dll = [[-1,-1, None]]
first = 0
cursor = 0

def insert(x):
    global cursor, first
    dll.append([dll[cursor][0],cursor,x])
    new_cursor = len(dll) - 1
    if dll[cursor][0] != -1:
        dll[dll[cursor][0]][1] = new_cursor
    dll[cursor][0] = new_cursor
    if cursor == first:
        first = new_cursor
    cursor = new_cursor

def move(d):
    global cursor
    if d > 0:
        for _ in range(d):
            cursor = dll[cursor][1]
    elif d < 0:
        for _ in range(-d):
            cursor = dll[cursor][0]

def erase():
    global cursor, first
    if dll[cursor][0] != -1:
        dll[dll[cursor][0]][1] = dll[cursor][1]
    if dll[cursor][1] != -1:
        dll[dll[cursor][1]][0] = dll[cursor][0]
    if cursor == first:
        first = dll[cursor][1]
    cursor = dll[cursor][1]

def main():
    Q = int(input())
    for _ in range(Q):
        query = input().split()
        if query[0] == '0':
            insert(query[1])
        elif query[0] == '1':
            move(int(query[1]))
        elif query[0] == '2':
            erase()

    i = first
    while dll[i][2] != None:
        print(dll[i][2])
        i = dll[i][1]

main()

Submission status: Accepted

Solution code:
from collections import deque

q = int(input())

L = deque()
cursor = 0
for i in range(q):
    inp = input()

    # insert
    if inp[0] == "0":
        operation, x = inp.split()
        L.appendleft(x)

    # move
    elif inp[0] == "1":
        operation, d = list(map(int, inp.split()))
        L.rotate(-d)
        cursor += d

    # erase
    else:
        L.popleft()

L.rotate(cursor)
[print(a) for a in L]

Submission status: Accepted

Solution code:
import sys
import collections
input = sys.stdin.readline
q = int(input())
A = collections.deque()
cursol = 0
# print('-----')
for i in range(q):
    query = input().split()
    if query[0] == '0':
        A.appendleft(query[1])
    elif query[0] == '1':
        A.rotate(-int(query[1]))
        cursol += int(query[1])
    elif query[0] == '2':
        A.popleft()
    # print(A)
A.rotate(cursol)
for a in A:
    print(a)

Submission status: Accepted

Solution code:
class Node():
    def __init__(self, prv = None, nxt = None, val = None):
        self.prv = prv
        self.nxt = nxt
        self.val = val

class DoublyLinkedList():
    def __init__(self):
        self.head = Node(prv=None, nxt=None, val="H")
        self.cur_node = self.head
        self.tail = Node(prv=None, nxt=None, val="E")
        
    def insert(self, x):
        if self.cur_node == self.head:
            new_node = Node(prv=None, nxt=None, val=x)

            new_node.prv = self.head
            new_node.nxt = self.tail

            self.head.nxt = new_node
            self.tail.prv = new_node

            self.cur_node = new_node

        elif self.cur_node == self.tail:
            new_node = Node(prv=None, nxt=None, val=x)

            self.tail.prv.nxt = new_node

            new_node.prv = self.tail.prv
            new_node.nxt = self.tail
            
            self.tail.prv = new_node
            self.cur_node = new_node
            
        else:
            new_node = Node(prv=None, nxt=None, val=x)

            if self.cur_node.prv is self.head:
                new_node.prv = self.head
                self.head.nxt = new_node
            else:
                new_node.prv = self.cur_node.prv
                self.cur_node.prv.nxt = new_node
               
            if self.cur_node is not self.tail:
                new_node.nxt = self.cur_node
                self.cur_node.prv = new_node

            self.cur_node = new_node

    def move(self, d):
        if d > 0:
            for _ in range(d):
                if self.cur_node.nxt is not None:
                    self.cur_node = self.cur_node.nxt
        elif d < 0:
            for _ in range(-d):
                self.cur_node = self.cur_node.prv
            
    def erase(self):
        prv = self.cur_node.prv
        nxt = self.cur_node.nxt

        if prv is self.head:
            self.head.nxt = nxt
        else:
            prv.nxt = nxt

        nxt.prv = prv
        self.cur_node = nxt

    def dump(self):
        cur = self.head.nxt

        while True:
            if cur is self.tail :
                break
            
            print(cur.val)
            cur = cur.nxt

def main():
    dll = DoublyLinkedList()
    q = int(input())

    for _ in range(q):
        com, *para = map(int, input().split())

        if   com == 0:
            dll.insert(para[0])

        elif com == 1:
            dll.move(para[0])

        elif com == 2:
            dll.erase()
    dll.dump()
    
main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

from collections import deque

L = deque([])
i = 0

Q = int(input())

for _ in range(Q):
    q = list(map(int,input().split()))
    if q[0] == 0:
        L.append(q[1])
    elif q[0] == 1:
        L.rotate(q[1])
        i -= q[1]
    else:
        L.pop()

L.rotate(i)
L.reverse()

print(*L,sep='\n')