#include <iostream>
using namespace std;
struct Node
{
int data;
Node* next;
};
struct List
{
Node* head;
int length;
};
int main()
{
List L;
L.head = nullptr;
L.length = 0;
int n;
cin >> n;
Node *current = nullptr;
for (int i = 0; i < n; i++)
{
int data;
cin >> data;
Node *newNode = new Node;
newNode->data = data;
newNode->next = nullptr;
if (L.head == nullptr)
{
L.head = newNode;
current = newNode;
} else
{
current->next = newNode;
current = newNode;
}
L.length++;
}
int m;
cin >> m;
for (int i = 0; i < m; i++)
{
int op, k;
cin >> op >> k;
if (op == 0)
{
int d;
cin >> d;
if (k < 0 || k > L.length)
{
continue;
}
Node *newNode = new Node;
newNode->data = d;
if (k == 0)
{
newNode->next = L.head;
L.head = newNode;
}
else
{
Node *prev = L.head;
for (int j = 0; j < k - 1; j++)
{
prev = prev->next;
}
newNode->next = prev->next;
prev->next = newNode;
}
L.length++;
}
else if (op == 1)
{
if (k <= 0 || k > L.length)
{
continue;
}
Node *prev = nullptr;
Node *curr = L.head;
for (int j = 0; j < k - 1; j++)
{
prev = curr;
curr = curr->next;
}
if (prev == nullptr)
{
L.head = curr->next;
} else
{
prev->next = curr->next;
}
delete curr;
L.length--;
}
}
// 输出链表
Node *curr = L.head;
while (curr != nullptr)
{
cout << curr->data << " ";
curr = curr->next;
}
// 释放链表内存
curr = L.head;
while (curr != nullptr)
{
Node *temp = curr;
curr = curr->next;
delete temp;
}
return 0;
}