#include <iostream>
using namespace std;
const int MAX_ELEM = 10000;
int main() {
int n, v[MAX_ELEM + MAX_ELEM + 1], m, k, x;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> v[i];
}
cin >> m;
for (int j = 1; j <= m; ++j) {
if (m <= MAX_ELEM) {
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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWF9FTEVNID0gMTAwMDA7CgppbnQgbWFpbigpIHsKICAgIGludCBuLCB2W01BWF9FTEVNICsgTUFYX0VMRU0gKyAxXSwgbSwgaywgeDsKICAgIGNpbiA+PiBuOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKSB7CiAgICAgICAgY2luID4+IHZbaV07CiAgICB9CiAgICBjaW4gPj4gbTsKICAgIGZvciAoaW50IGogPSAxOyBqIDw9IG07ICsraikgewogICAgICAgIGlmIChtIDw9IE1BWF9FTEVNKSB7CiAgICAgICAgICAgIGNpbiA+PiBrOwogICAgICAgICAgICBpZiAoayA9PSAxKSB7CiAgICAgICAgICAgICAgICBjaW4gPj4geDsKICAgICAgICAgICAgICAgICsrbjsKICAgICAgICAgICAgICAgIHZbbl0gPSB4OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChrID09IDIpIHsKICAgICAgICAgICAgICAgIGlmIChuID4gMCkgewogICAgICAgICAgICAgICAgICAgIC0tbjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIGNvdXQgPDwgbiA8PCAiXG4gIjsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47ICsraSkgewogICAgICAgIGNvdXQgPDwgdltpXSA8PCAiICI7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==