#include <iostream>
using namespace std;
int main() {
int n, v[10000], 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;
for (int i = 1; i <= n; ++i) {
if (k == 1) {
cin >> x;
++n;
v[n] = x;
}
if (k == 2 ) {
--n;
}}
}
cout << n << "\n ";
for (int i = 1; i <= n; ++i) {
cout << v[i] << " ";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgICBpbnQgbiwgdlsxMDAwMF0sIG0sIGssIHg7CiAgICBjaW4gPj4gbjsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47ICsraSkgewogICAgICAgIGNpbiA+PiB2W2ldOwogICAgfQogICAgY2luID4+IG07CiAgICBmb3IgKGludCBqID0gMTsgaiA8PSBtOyArK2opIHsKICAgICAgICBjaW4gPj4gazsKICAgICAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyArK2kpIHsKICAgICAgICBpZiAoayA9PSAxKSB7CiAgICAgICAgICAgIGNpbiA+PiB4OwogICAgICAgICAgICArK247CiAgICAgICAgICAgIHZbbl0gPSB4OwogICAgICAgIH0KICAgICAgICBpZiAoayA9PSAyICkgewogICAgICAgICAgICAtLW47CiAgICAgICAgfX0KICAgICAgICAKICAgIH0KICAgIGNvdXQgPDwgbiA8PCAiXG4gIjsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47ICsraSkgewogICAgICAgIGNvdXQgPDwgdltpXSA8PCAiICI7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==
MwoxIDIgMyAKNAoyCjIKMgoxIDkKLTEKOQoKCjMKMSAyIDMKMwoxIDkKMSA2CjEgMAotNgoxIDIgMyA5IDYgMAoKMwoxIDIgMwo0IAoyCjIKMSA5CjIKLTEKMQoKMwoxIDIgMyAKMwoyCjIKMSA5Ci0yCjEgOQoKMwoxIDIgMwo0Cj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