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

Solution (Python):
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()

Solution (Python):
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()

Solution (Python):
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()

Solution (Python):
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()

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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")

Solution (Python):

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)

Solution (Python):
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]  
    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]

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





  




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])

Solution (Python):
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)

Solution (Python):
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')

Solution (Python):
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()

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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()

Solution (Python):
from collections import deque

q = int(input())

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

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

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

    
    else:
        L.popleft()

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

Solution (Python):
from collections import deque

q = int(input())

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

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

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

    
    else:
        L.popleft()

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

Solution (Python):
import sys
import collections
input = sys.stdin.readline
q = int(input())
A = collections.deque()
cursol = 0

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()
    
A.rotate(cursol)
for a in A:
    print(a)

Solution (Python):
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()

Solution (Python):
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')

Solution (Python):
import sys

def input():
    return sys.stdin.readline().rstrip()

class Node:
    def __init__(self, value, prev_node, next_node):
        self.value = value
        self.prev_node = prev_node
        self.next_node = next_node

class LinkedList:
    def __init__(self):
        self.current_node = Node(None, None, None)
        self.front_node = self.current_node
        self.end_node = self.current_node

    def insert(self, value):
        current_node = self.current_node
        prev_node = current_node.prev_node
        if prev_node == None:
            newNode = Node(value, None, current_node)
            current_node.prev_node = newNode
            self.current_node = newNode
            self.front_node = newNode
        else:
            newNode = Node(value, prev_node, current_node)
            prev_node.next_node = newNode
            current_node.prev_node = newNode
            self.current_node = newNode

    def remove(self):
        prev_node = self.current_node.prev_node
        next_node = self.current_node.next_node
        if prev_node == None:
            next_node.prev_node = None
            self.front_node = next_node
            self.current_node = next_node
        else:
            next_node.prev_node = prev_node
            prev_node.next_node = next_node
            self.current_node = next_node

    def move(self, diff):
        if diff > 0:
            for _ in range(diff):
                self.current_node = self.current_node.next_node
        elif diff < 0:
            for _ in range(-diff):
                self.current_node = self.current_node.prev_node

    def print(self):
        node = self.front_node
        while node != self.end_node:
            print(node.value)
            node = node.next_node

input()
a = LinkedList()
while True:
    line = input()
    if not line:
        break
    if line[0] == '0':
        a.insert(int(line[2:]))
    elif line[0] == '1':
        a.move(int(line[2:]))
    else:
        a.remove()

a.print()

Solution (Python):
import collections


class CursorList():
    def __init__(self):
        self.vector = collections.deque()
        self.cursor = 0

    def insert(self, x):
        self.vector.appendleft(x)
        return self

    def move(self, d):
        self.vector.rotate(-d)
        self.cursor += d
        return self

    def erase(self):
        self.vector.popleft()
        return self


num_queue = int((input()))
L = CursorList()

for i in range(0, num_queue):
    queue = tuple(map(int, input().split(' ')))
    if queue[0] == 0:
        L.insert(queue[1])
    elif queue[0] == 1:
        L.move(queue[1])
    elif queue[0] == 2:
        L.erase()

L.vector.rotate(L.cursor)
print('\n'.join(map(str, L.vector)))

Solution (Python):
from collections import deque
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

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()

Solution (Python):
import sys
from collections import deque

q = int(input())
L = deque()
L2 = deque()
cur = 0
for i in range(q):
    query = sys.stdin.readline()
    if query[0] == '0':
        L2.appendleft(query[2:].strip())
    elif query[0] == '1':
        n = int(query[2:].strip())
        if n > 0:
            for _ in range(n):
                L.append(L2[0])
                L2.popleft()
        else:
            for _ in range(-n):
                L2.appendleft(L[-1])
                L.pop()
    else:
        L2.popleft()

for i in L:
    print(i)
for i in L2:
    print(i)

Solution (Python):
from collections import deque
import sys

n=int(input())
A=deque()
cur=0
for i in range(n):
  S=input()
  if S[0]=='0':
    A.append(S[2:])
  elif S[0]=='1':
    A.rotate(int(S[2:]))
    cur-=int(S[2:])
  elif S[0]=='2':
    A.pop()
A.rotate(cur)
A.reverse()
print(*A, sep="\n")

Solution (Python):
from typing import List


class Node:
    __slots__ = ['prev', 'next', 'data']

    def __init__(self, prev, next, data) -> None:
        self.prev = prev
        self.next = next
        self.data = data


def insert(x: int, cur: Node) -> Node:
    cur.prev.next = cur.prev = cur = Node(cur.prev, cur, x)
    return cur


def move(x: int, cur: Node) -> Node:
    if x > 0:
        for _ in range(x):
            cur = cur.next
    else:
        for _ in range(-x):
            cur = cur.prev
    return cur


def erase(cur: Node) -> Node:
    cur.next.prev = cur.prev
    cur.prev.next = cur = cur.next
    return cur


if __name__ == "__main__":
    num_query = int(input())
    root = Node(None, None, None)
    cur = root.next = Node(root, None, None)

    for _ in range(num_query):
        op, *value = map(lambda x: int(x), input().split())
        if (0 == op):
            cur = insert(value[0], cur)
        elif (1 == op):
            cur = move(value[0], cur)
        elif (2 == op):
            cur = erase(cur)
        else:
            pass

    ans: List[int] = []
    it = root.next
    while it.next:
        ans.append(it.data)
        it = it.next

    for elem in ans:
        print(elem)

Solution (Python):
import sys

class DLLNode:
    __slots__ = ['prev', 'next', 'data']

    def __init__(self, prev, next, data):
        self.prev = prev
        self.next = next
        self.data = data

root = DLLNode(None, None, None)
cur = root.next = DLLNode(root, None, None)

def insert(x, cur):
    cur.prev.next = cur.prev = cur = DLLNode(cur.prev, cur, x)
    return cur

def move(x, cur):
    d = int(x)
    if d > 0:
        for _ in range(d):
            cur = cur.next
    else:
        for _ in range(-d):
            cur = cur.prev
    return cur

def erase(_, cur):
    cur.next.prev = cur.prev
    cur.prev.next = cur = cur.next
    return cur

C = {'0': insert, '1': move, '2': erase}
sys.stdin.readline()
for query in sys.stdin:
    cur = C[query[0]](query[2:], cur)

ans = []
it = root.next
while it.next:
    ans.append(it.data)
    it = it.next

sys.stdout.writelines(ans)

Solution (Python):
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()

Solution (Python):

"""
Dynamic Arrays and List - List
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_1_C&lang=jp

"""

class Node:
    def __init__(self, value=0):
        self.key = value
        self.prev, self.next = None, None

class Lst:
    def __init__(self):
        self.nil = Node('END')
        self.nil.next = self.nil
        self.nil.prev = self.nil
        self.cur = self.nil

    def insert(self, value):
        x = Node(value)
        x.prev = self.cur.prev
        self.cur.prev.next = x
        self.cur.prev = x
        x.next = self.cur
        self.cur = x

    def move(self, d):
        if d >= 0:
            for _ in range(d):
                self.cur = self.cur.next
        else:
            for _ in range(abs(d)):
                self.cur = self.cur.prev


    def erase(self):
        if self.cur == self.nil:
            return
        p = self.cur.next
        self.cur.prev.next = self.cur.next
        self.cur.next.prev = self.cur.prev
        self.cur = p


lst = Lst()
for _ in range(int(input())):
    op, n = (input() + ' 1').split()[:2]
    if op == '0':
        lst.insert(int(n))
    elif op == '1':
        lst.move(int(n))
    else:
        lst.erase()

cur = lst.nil
while cur.next != lst.nil:
    cur = cur.next
    print(cur.key)

Solution (Python):
from sys import stdin

class LinkedList():
    def __init__(self):
        self.head = [None, None, None]
        self.head[1] = self.pos = self.tail = [self.head, None, None]

    def insert(self, x):
        temp = [self.pos[0], self.pos, x]
        self.pos[0][1] = self.pos[0] = self.pos = [self.pos[0], self.pos, x]

    def move_right(self, d):
        for _ in range(d):
            self.pos = self.pos[1]

    def move_left(self, d):
        for _ in range(d):
            self.pos = self.pos[0]

    def move(self, d):
        if d > 0:
            self.move_right(d)
        else:
            self.move_left(d * -1)

    def erase(self):
        self.pos[1][0] = self.pos[0]
        self.pos = self.pos[0][1] = self.pos[1]

    def to_list(self):
        index = self.head[1]
        out = []
        while(index[1] is not None):
            out.append(index[2])
            index = index[1]
        return out

n = stdin.readline()
queries = stdin.readlines()
ll = LinkedList()

for query in queries:
    
    
    query = query.split()
    if query[0] == '0':
        ll.insert(query[1])
    elif query[0] == '1':
        ll.move(int(query[1]))
    else:
        ll.erase()

print('\n'.join(ll.to_list()))

Solution (Python):
class Node:
    def __init__(self, val=None, prev=None, nextNode=None):
        self.val = val
        self.prev = prev
        self.nextNode = nextNode

class LinkedList():
    def __init__(self):
        self.end = Node('END')
        self.cursol_node = self.end
    
    def insertBefore(self, x):
        new_node = Node(val=x, prev=self.cursol_node.prev, nextNode=self.cursol_node)
        if self.cursol_node.prev != None:
            self.cursol_node.prev.nextNode = new_node
        
        self.cursol_node.prev = new_node
        
        self.cursol_node = new_node

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

    def erase(self):
        if self.cursol_node != self.end:
            if self.cursol_node.prev != None:
                
                self.cursol_node.prev.nextNode = self.cursol_node.nextNode
            self.cursol_node.nextNode.prev = self.cursol_node.prev
            self.cursol_node = self.cursol_node.nextNode
    
    def print_nodes_val(self):
        ans_list = []
        target_node = self.end
        while True:
            if target_node.prev == None:break
            else:
                target_node = target_node.prev
                ans_list.append(target_node.val)
        ans_list = ans_list[::-1]
        return ans_list

linkedList = LinkedList()
n = int(input())
for i in range(n):
    q,*x = map(int, input().split())
    x = x[0] if x else None
    if q == 0:
        linkedList.insertBefore(x)
    elif q == 1:
        linkedList.move(x)
    elif q == 2:
        linkedList.erase()
print('\n'.join(map(str,linkedList.print_nodes_val())))