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:
    __slots__ = ["val", "prev", "next"]

    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
        else:
            raise
    
    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])



def main():

    q = int(input())

    L = DoublyLinkedList()

    for _ in range(q):
    
        command, *list_num = input().split()
    
        if   command == "0":
            
            x = int(list_num[0])
            L.insert(x)
        elif command == "1":
            
            d = int(list_num[0])
            L.move(d)
        elif command == "2":
            
            L.erase()
        else:
            raise


    L.print_elements()


if __name__ == "__main__":
    main()

Solution (Python):
class Node:
    def __init__(self, left, right, date):
        self.left = left
        self.right = right
        self.date = date

root = Node(None, None, None)
cur = root.right = Node(root, None, None)

def insert(x, cur):
    cur.left.right = cur.left = cur = Node(cur.left,cur, x)
    return cur

def move(x, cur):
    d = int(x[0])
    if d > 0:
        for _ in range(d):
            cur = cur.right
    else:
        for _ in range(-d):
            cur = cur.left
    return cur

def erase(_,cur):
    cur.right.left = cur.left
    cur.left.right = cur.right
    cur = cur.right
    return cur

C = {'0':insert, '1':move, '2':erase}
n = int(input())
for _ in range(n):
    query = input().split()
    cur = C[query[0]](query[1:], cur)

ans = []
it = root.right
while it.right:
    ans.append(it.date)
    it = it.right

for i in range(len(ans)):
    print(ans[i][0])

Solution (Python):
from sys import stdin

class QueueNode(object):
	def __init__(self,data,next=None,prev=None):
		self.data = data
		self.next = next
		self.prev = prev

class LinkList(object):
	def __init__(self,head=None):
		self.head = head
		self.tail = head
		self.cur  = head

	def insert_q(self,data):
		node = QueueNode(data)

		if self.cur is None:
			self.head = node
			self.tail = node
			self.cur  = node
			return

		currentNode = self.cur
		preNode = currentNode.prev

		if currentNode.prev is None:
			currentNode.prev = node
			node.next = currentNode
			self.head = self.cur = node
		else:
			if self.tail is not None:
				currentNode.prev = node
				node.prev = preNode
				node.next = currentNode
				preNode.next = node
				self.cur = node
			else:
				currentNode.next = node
				node.prev = currentNode
				node.next = None
				self.cur = node
				self.tail = node


	def move_q(self,mv):
		currentNode = self.cur
		cnt = mv
		while cnt != 0:
			if mv < 0:
				if currentNode.prev is None:
					self.head = self.cur = currentNode
					break
				else:
					currentNode = currentNode.prev
					self.cur = currentNode
					cnt += 1
			else:
				if currentNode.next is None:
					self.cur = currentNode
					break
				else:
					currentNode = currentNode.next
					self.cur = currentNode
					cnt -= 1


	
	def delete_q(self):
		currentNode = self.cur
		nexNode = currentNode.next
		preNode = currentNode.prev

		
		if preNode is None:
			nexNode.prev = None
			self.head = nexNode
			self.cur = nexNode
		
		elif nexNode is None:
			preNode.next = None
			self.tail = None
		else:
			preNode.next = currentNode.next
			nexNode.prev = currentNode.prev
			self.cur = currentNode.next

	
	def print_q(self):
		if self.head is not None:
			print(self.head.data)

	
	def print_all(self):
		if self.head is not None:
			currentNode = self.head
			while currentNode.next is not None:
				print(currentNode.data)
				currentNode = currentNode.next

if __name__ == '__main__':

	loopnum = int(input())

	ll = LinkList()
	ll.insert_q("E")
	for i in range(loopnum):
		cmd = stdin.readline().strip().split()
		if cmd[0] == "0":
			t = int(cmd[1])
			ll.insert_q(t)
		elif cmd[0] == "1":
			t = int(cmd[1])
			ll.move_q(t)
		else:
			ll.delete_q()
	ll.print_all()

Solution (Python):
q = int(input())
A = [0 for i in range(1500000)]
A[0] = 'end'
cursor = 0
head = [0 for i in range(1500000)]
head_len = 0

def insert(x):
	global cursor
	cursor += 1
	A[cursor] = x
def move(d):
	global cursor, head, head_len
	if d >= 0:
		head[head_len-1+d+(1): head_len-1+(1):-1] = A[cursor-d+1:cursor+1]
	else:
		A[cursor+1:cursor+1+(-d)] = head[head_len-1+(1):head_len-(-d)-1+(1):-1]
	cursor -= d
	head_len += d
def erase():
	global cursor
	cursor -= 1

for i in range(q):
	a = input()
	if a != "2":
		b = [int(i) for i in a.split()]
		if b[0] == 0:
			insert(b[1])
		elif b[0] == 1:
			move(b[1])
	else:
		erase()
	

A[cursor+1:cursor+1+head_len] = head[head_len-1+(1):-1+(1):-1]
length = cursor +  head_len
for i in range(1,length+1)[::-1]:
	print(A[i])

Solution (Python):
cursor = 0
n = int(input())

class LinkedList():
    class Cell():
        def __init__(self,val,pre,post):
            self.val = val
            self.pre = pre
            self.post = post

    def __init__(self):
        self.cursor = LinkedList.Cell(None,None,None)
        
    def insert(self,val):
        temp = self.cursor
        self.cursor = LinkedList.Cell(val,temp.pre,temp)
        if temp.pre != None:
            temp.pre.post = self.cursor
        temp.pre = self.cursor
        
        
            

    def move(self,d):
        if d > 0:
            for i in range(d):
                self.cursor = self.cursor.post
                
        else:
            
            for i in range(-d):
                
                self.cursor = self.cursor.pre
            
    def remove(self):
        temp = self.cursor
        tpos = temp.post
        
        if temp.pre != None:
            tpre = temp.pre
            tpre.post = tpos
            tpos.pre = tpre
        else:
            tpos.pre = None
        del temp
        self.cursor = tpos
        
    def moveToTop(self):
        while self.cursor.pre != None:
            self.cursor = self.cursor.pre

linkedList = LinkedList()

for i in range(n):
    a = [int(j) for j in input().split()]
    if a[0] == 0:
        linkedList.insert(a[1])
    elif a[0] == 1:
        linkedList.move(a[1])
    elif a[0] == 2:
        linkedList.remove()

linkedList.moveToTop()
print(linkedList.cursor.val)
while linkedList.cursor.post.val != None:
    linkedList.cursor = linkedList.cursor.post
    print(linkedList.cursor.val)

Solution (Python):
import sys


class Node:
    __slots__ = ['prev', 'next', 'id', 'val']

    def __init__(self, prev_node, next_node, id, val):
        self.prev = prev_node
        self.next = next_node
        self.id = id
        self.val = val

    def __repr__(self):
        return f'{self.id},{self.val}'


class LinkedList:
    def __init__(self):
        begin_node = Node(None, None, 0, -sys.maxsize)
        end_node = Node(None, None, 1, sys.maxsize)
        begin_node.next = end_node
        end_node.prev = begin_node
        self.Nodes = {0: begin_node, 1: end_node}
        self.id = 2
        self.cursor = self.Nodes[1]

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

    def print_all_node(self):
        out = ''
        while self.cursor.prev is not None:
            self.cursor = self.cursor.prev

        self.cursor = self.cursor.next
        while self.cursor.next is not None:
            out += f'{self.cursor.val}\n'
            self.cursor = self.cursor.next
        print(out, end='')

    def insert(self, val):
        tmp_node = Node(self.cursor.prev, self.cursor, self.id, val)
        self.cursor.prev.next = tmp_node
        self.cursor.prev = tmp_node
        self.Nodes[self.id] = tmp_node
        self.cursor = tmp_node
        self.id += 1

    def erase(self):
        self.cursor.prev.next = self.cursor.next
        self.cursor.next.prev = self.cursor.prev
        del self.Nodes[self.cursor.id]
        self.cursor = self.cursor.next


linkedlist = LinkedList()


nq = int(input())
lines = sys.stdin.readlines()
for i in range(nq):
    query, *arg = lines[i].split()
    
    if query == '0':  
        linkedlist.insert(arg[0])
    elif query == '1':  
        linkedlist.move(int(arg[0]))
    elif query == '2':  
        linkedlist.erase()
    else:
        raise AssertionError

linkedlist.print_all_node()

Solution (Python):



from collections import deque


import sys

input = sys.stdin.readline

def loop_proc():
    q1 = deque()
    q2  = deque()
    l2 = []
    cur = 0
    rflag = True
    n = int(input())
    cnt = 0

    while (cnt < n):
        cnt += 1
        if (rflag == True):
            l = list(map(int,input().split()))
        else:
            l = l2
        c = l[0]
        rflag =True
        
        if ( c == 0 ):
            d = l[1]
            
            if (cnt < n ):
                l2 = list(map(int,input().split()))
                if (l2[0] == 2 ):
                    cnt += 1
                    continue
                rflag =False
            q1.append(d)
        
        elif(c == 1):

            cur = l[1]
            if cur <  0 :
                for i in range(abs(cur)):
                    q1.append(q2.pop())
            else:
                for i in range(abs(cur)):
                    q2.append(q1.pop())

        
        elif(c == 2):
            q1.pop()

    while len(q2) != 0 :
        print (q2.popleft())
    while len(q1) != 0 :
        print (q1.pop())



loop_proc()

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



class LinkedList():
    def __init__(self, val):
        self.val = val
        self.prev = None
        self.next = None

    def insert(self, cursor):
        
        self.prev = cursor.prev
        if self.prev: self.prev.next = self
        self.next = cursor
        cursor.prev = self
        
        return self

    def remove(self):
        
        if self.prev:
            self.prev.next = self.next
        self.next.prev = self.prev
        
        return self.next

    def move(self, count):  
        
        
        cursor = self
        while count > 0:
            cursor = cursor.next
            count -= 1
        while count < 0:
            cursor = cursor.prev
            count += 1
        
        return cursor

    def print_list(self):
        top = self
        while top.prev != None:
            top = top.prev
        while top:
            print(top.val, end = ' ')
            top = top.next
        print()


import sys
cursor = LinkedList(None) 

num_tc = int(sys.stdin.readline())
for i in range(num_tc):
    q = list(map(int, sys.stdin.readline().split()))
    if q[0] == 0:
        elem = LinkedList(q[1])
        cursor = elem.insert(cursor)
    elif q[0] == 1:
        cursor = cursor.move(q[1])
    elif q[0] == 2:
        cursor = cursor.remove()
    else:
        raise ValueError

top = cursor
while top.prev != None:
    top = top.prev

while top.val!=None:
    print(top.val)
    top = top.next