#include <bits/stdc++.h>
using namespace std;
const int BASE = 2;
const int INVBASE1 = 500000004, INVBASE2 = 500000005;
const int N = 1e6 + 5;
pair<int, int> MOD = make_pair(1e9 + 7, 1e9 + 9);
pair<int, int> POWBASE[N], INVPOWBASE[N];
pair<int, int> pre[N], suf[N];
int S[N];
int best_even[N], best_odd[N];
pair<int, int> add(pair<int, int> a, pair<int, int> b) {
pair<int, int> res = make_pair((a.first + b.first) % MOD.first, (a.second + b.second) % MOD.second);
if(res.first < 0) res.first += MOD.first;
if(res.second < 0) res.second += MOD.second;
return res;
}
pair<int, int> mult(pair<int, int> a, pair<int, int> b) {
pair<int, int> res = make_pair((a.first * 1LL * b.first) % MOD.first, (a.second * 1LL * b.second) % MOD.second);
if(res.first < 0) res.first += MOD.first;
if(res.second < 0) res.second += MOD.second;
return res;
}
pair<int, int> neg(pair<int, int> a) {
pair<int, int> res = make_pair(-a.first, -a.second);
if(a.first < 0) res.first += MOD.first;
if(a.second < 0) res.second += MOD.second;
return res;
}
bool is_palin(int l, int r) {
if(l < 0 or l > r) return 0;
int mid = (l + r)/2;
pair<int, int> lhash = mult(add(pre[mid], l - 1 >= 0 ? neg(pre[l - 1]) : make_pair(0, 0)), INVPOWBASE[l]);
if((r - l + 1) % 2 == 0) mid++;
pair<int, int> rhash = add(suf[r], mult(POWBASE[r - mid + 1], mid - 1 >= 0 ? neg(suf[mid - 1]) : make_pair(0, 0)));
int b1 = (lhash == rhash);
/*
int b2 = 1;
for(int i = l; i <= r; i++)
if(S[i] != S[r + l - i]) b2 = 0;
if(b1 != b2) {
cerr<<l<<" "<<r<<" brute: "<<b2<<", sol: "<<b1<<endl;
for(int i = l; i <= r; i++) cerr<<S[i];
cerr<<endl;
cerr<<lhash.first<<" "<<rhash.first<<endl;
assert(false);
}
*/
return b1;
}
int main() {
cin.tie(NULL);
ios::sync_with_stdio(false);
cout.tie(NULL);
POWBASE[0] = {1, 1};
for(int i = 1; i < N; i++) POWBASE[i] = mult(POWBASE[i - 1], {BASE, BASE});
INVPOWBASE[0] = {1, 1};
for(int i = 1; i < N; i++) INVPOWBASE[i] = mult(INVPOWBASE[i - 1], {INVBASE1, INVBASE2});
int n, type, ptr = -1, d;
cin>>n;
assert(n >= 1 and n <= 1000000);
for(int i = 0; i < n; i++) {
cin>>type;
if(type == 1) {
cin>>d;
assert(d >= 0 and d <= 1);
ptr++;
S[ptr] = d;
pre[ptr] = add(ptr - 1 >= 0 ? pre[ptr - 1] : make_pair(0, 0), mult({d, d}, POWBASE[ptr]));
suf[ptr] = add(ptr - 1 >= 0 ? mult(suf[ptr - 1], {BASE, BASE}) : make_pair(0, 0), {d, d});
int prev_odd = ptr - 1 >= 0 ? best_odd[ptr - 1] : -1;
best_odd[ptr] = is_palin(ptr - (prev_odd + 2) + 1, ptr) ? prev_odd + 2 : prev_odd;
int prev_even = ptr - 1 >= 0 ? best_even[ptr - 1] : 0;
best_even[ptr] = is_palin(ptr - (prev_even + 2) + 1, ptr) ? prev_even + 2 : prev_even;
} else if(type == 2) {
ptr--;
} else {
assert(false);
}
assert(ptr >= -1);
if(ptr == -1) cout<<0<<'\n';
else cout<<max(best_odd[ptr], best_even[ptr])<<'\n';
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgQkFTRSA9IDI7CmNvbnN0IGludCBJTlZCQVNFMSA9IDUwMDAwMDAwNCwgSU5WQkFTRTIgPSA1MDAwMDAwMDU7CmNvbnN0IGludCBOID0gMWU2ICsgNTsKCnBhaXI8aW50LCBpbnQ+IE1PRCA9IG1ha2VfcGFpcigxZTkgKyA3LCAxZTkgKyA5KTsKcGFpcjxpbnQsIGludD4gUE9XQkFTRVtOXSwgSU5WUE9XQkFTRVtOXTsKcGFpcjxpbnQsIGludD4gcHJlW05dLCBzdWZbTl07CmludCBTW05dOwppbnQgYmVzdF9ldmVuW05dLCBiZXN0X29kZFtOXTsKCnBhaXI8aW50LCBpbnQ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