#include <iostream>
using namespace std;
int main() {
int n, v[10001], m, k, x;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> v[i];
}
cin >> m;
for (int j = 1; j <= m; ++j) {
cin >> k;
if (k == 1) {
cin >> x;
++n;
v[n] = x;
}
if (k == 2) {
if(n > 0){
--n;
}
}
}
cout << n << "\n ";
for (int i = 1; i <= n; ++i) {
cout << v[i] << " ";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgICBpbnQgbiwgdlsxMDAwMV0sIG0sIGssIHg7CiAgICBjaW4gPj4gbjsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47ICsraSkgewogICAgICAgIGNpbiA+PiB2W2ldOwogICAgfQogICAgY2luID4+IG07CiAgICBmb3IgKGludCBqID0gMTsgaiA8PSBtOyArK2opIHsKICAgICAgICBjaW4gPj4gazsKICAgICAgICBpZiAoayA9PSAxKSB7CiAgICAgICAgICAgIGNpbiA+PiB4OwogICAgICAgICAgICArK247CiAgICAgICAgICAgIHZbbl0gPSB4OwogICAgICAgIH0KICAgICAgICBpZiAoayA9PSAyKSB7CiAgICAgICAgCWlmKG4gPiAwKXsKICAgICAgICAgICAgLS1uOwogICAgICAgIAl9CiAgICAgICAgfQogICAgfQogICAgY291dCA8PCBuIDw8ICJcbiAiOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKSB7CiAgICAgICAgY291dCA8PCB2W2ldIDw8ICIgIjsKICAgIH0KICAgIHJldHVybiAwOwp9