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: Time Limit Exceeded)

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

typedef struct node {
    int num;
    struct node *next_node;
} Node;

void insert(Node *list_crnt, Node *a, int x){
    a->num = list_crnt->num;
    a->next_node = list_crnt->next_node;

    list_crnt->next_node = a;
    list_crnt->num = x;
}

Node *move(Node *list_head, Node *list_crnt, int *list_position, int d){
    int i;
    Node *the_node;
    if(d>0){
        for(i=0;i<d;i++){
            list_crnt = list_crnt->next_node;
            *list_position += 1;
        }
    }else{
        the_node = list_head;
        for(i=0;i<(*list_position)+d;i++)the_node = the_node->next_node;
        list_crnt = the_node;
        *list_position += d;
    }

    return list_crnt;
}

void erase(Node *list_crnt){
    Node *ptr;
    list_crnt->num = list_crnt->next_node->num;
    ptr = list_crnt->next_node;
    list_crnt->next_node = list_crnt->next_node->next_node;
    free(ptr);
}

int main(){
    int q;
    int i;
    int request;
    int x;
    int d;

    Node *list_head;
    Node *list_crnt;
    int list_position=0;
    Node *first_node;

    Node *start;
    Node *end = calloc(1, sizeof(Node));;

    
    first_node = calloc(1, sizeof(Node));
    list_head = list_crnt = first_node;
    first_node->next_node = end;
    
    scanf("%d", &q);

    for(i=0;i<q;i++){
        //printf("----------\n");
        scanf("%d", &request);
        switch(request){
            case 0: scanf("%d", &x);
                    insert(list_crnt, calloc(1, sizeof(Node)), x);
                    break;
            case 1: scanf("%d", &d);
                    list_crnt = move(list_head, list_crnt, &list_position, d);
                    break;
            case 2: erase(list_crnt);
                    break;
            default:break;
        }
        //printf("position = %d\n", list_position);
        /*start = list_head;
        while(start->next_node!=end){
            printf("%d\n",start->num);
            start = start->next_node;
        }*/
        //printf("----------\n");
    }

    start = list_head;
    while(start->next_node!=end){
        printf("%d\n",start->num);
        start = start->next_node;
    }
    return 0;
}