#include using namespace std; using ll = long long; unsigned int isqrt(unsigned long long N) { if (N == 0) return 0; unsigned long long x = 2ULL << ((63 ^ countl_zero(N)) >> 1); do { x = (x + N / x) >> 1; } while (N < x * x); return x; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, Q, cr = 0, cb = 0, lca = -1; ll R, B; cin >> N >> R >> B >> Q; vector par(N + 1, -1), lc(N + 1, -1), rc(N + 1, -1); vector D(N + 1); for (int i = 1; i <= N; i++) { int d = (i + isqrt((ll)i * i * 5)) >> 1; if (d <= N) { lc[i] = d; par[lc[i]] = i; } if (d + i <= N) { rc[i] = d + i; par[rc[i]] = i; } } lc[1] = -1; par[1] = -1; vector ch(N + 1), e(N + 1); int cnt = 0; while (Q--) { int t, x; cin >> t >> x; if (t == 1) { if (ch[x]) { ch[x] = false; int ce = 0; if (e[x]) ce++; if (lc[x] != -1 && e[lc[x]]) ce++; if (rc[x] != -1 && e[rc[x]]) ce++; if (ce == 1) { if ((lc[x] == -1 || !e[lc[x]]) && (rc[x] == -1 || !e[rc[x]])) { while (!ch[x] && e[x]) { if ((lc[x] != -1 && e[lc[x]]) || (rc[x] != -1 && e[rc[x]])) { break; } e[x] = false; if (x == lc[par[x]]) cr--; else cb--; x = par[x]; } } if (!e[x]) { while (!ch[x]) { if ((lc[x] != -1 && e[lc[x]]) == (rc[x] != -1 && e[rc[x]])) { break; } if (lc[x] != -1 && e[lc[x]]) { x = lc[x]; cr--; } else { x = rc[x]; cb--; } e[x] = false; } } } cnt--; if (cnt == 0) lca = -1; else { while (e[x]) x = par[x]; lca = x; } } else { ch[x] = true; if (!e[x] && (lc[x] == -1 || !e[lc[x]]) && (rc[x] == -1 || !e[rc[x]])) { if (lca == -1) { lca = x; } else { vector S, T; S.push_back(lca); T.push_back(x); while (S.back() != 1) { S.push_back(par[S.back()]); } while (T.back() != 1) { T.push_back(par[T.back()]); } while (S.size() && T.size() && S.back() == T.back()) { S.pop_back(); T.pop_back(); } for (int v: S) { if (e[v]) break; e[v] = true; if (v == lc[par[v]]) cr++; else cb++; } for (int v: T) { if (e[v]) break; e[v] = true; if (v == lc[par[v]]) cr++; else cb++; } lca = (S.size() ? par[S.back()] : par[T.back()]); } } cnt++; } } else { if (t == 2) R = x; else B = x; } cout << cr * R + cb * B << '\n'; } }