#include <bits/stdc++.h>
#include <map>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int q;
cin >> q;
map<long long, long long> cnt;
while (q--) {
int op;
cin >> op;
if (op == 1) {
long long x, y;
cin >> x >> y;
cnt[x] += y;
} else if (op == 2) {
long long x, y;
cin >> x >> y;
auto it = cnt.find(x);
if (it != cnt.end()) it->second = max(0LL, it->second - y);
} else if (op == 3) {
for (auto &kv : cnt) kv.second = min(kv.second, 1LL);
} else {
long long x;
cin >> x;
auto it = cnt.find(x);
cout << (it == cnt.end() ? 0LL : it->second) << "\n";
}
}
return 0;
}