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 in C (judge verdict: Accepted)

#include <stdio.h>
#include <limits.h>
#include <stdlib.h>

// Here we implement list in double linked list.

typedef struct _Node {
	int value;
	struct _Node *prev;
	struct _Node *next;
} Node;

typedef struct {
	Node *head;
	Node *cursor;
} List;

Node *createNode(int _value) {
	Node *node = (Node*)malloc(sizeof(Node));
	node->value = _value;
	node->prev = NULL;
	node->next = NULL;
	return node;
}

List *initList() {
	Node *end_node = createNode(INT_MAX);	// we set INT_MAX as the special element END
	List *list = (List*)malloc(sizeof(List));
	list->head = end_node;
	list->cursor = end_node;
	return list;
}

void disposeList(List *_list) {
	Node *tmp;
	if (_list != NULL) {
		for (tmp = _list->head; tmp != NULL; tmp = _list->head) {
			_list->head = tmp->next;
			free(tmp);
		}
	}
}

void insert(List *_list, int _x) {
	Node *new_node = createNode(_x);
	new_node->next = _list->cursor;
	if (_list->head == _list->cursor) {	// if cursor indicate the head
		_list->head = new_node;
	}
	else {
		new_node->prev = _list->cursor->prev;
		new_node->prev->next = new_node;
	}
	_list->cursor->prev = new_node;
	_list->cursor = new_node;
}

void move(List *_list, int _d) {
	if (_d > 0) {
		while (_d--) {
			_list->cursor = _list->cursor->next;
		}
	}
	else {
		while (_d++) {
			_list->cursor = _list->cursor->prev;
		}
	}
}

void erase(List *_list) {
	Node *tmp = _list->cursor;
	tmp->next->prev = tmp->prev;
	if (_list->head == _list->cursor) {
		_list->head = tmp->next;
	}
	else {
		tmp->prev->next = tmp->next;
	}
	_list->cursor = tmp->next;
	free(tmp);
}

void printList(List *_list) {
	Node *tmp = _list->head;
	while (tmp->value != INT_MAX) {
		printf("%d\n", tmp->value);
		tmp = tmp->next;
	}
}

int main() {
	int q;  // amount of queries
	int op; // number of operations
	int si; // the second input
	int i;  // index
	List *list = initList();
	scanf("%d", &q);
	for (i = 0; i != q; ++i) {
		scanf("%d", &op);
		switch (op) {
			case 0:
				scanf("%d", &si);
				insert(list, si);
				break;
			case 1:
				scanf("%d", &si);
				move(list, si);
				break;
			default:
				erase(list);
		}
	}
	printList(list);
	disposeList(list);
	return 0;
}