#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = (1<<20);
multiset<ll> S[N];
ll path[N];
ll ans[N];
void modify(int d, int b, bool add) {
if(add) S[d].insert(b);
else S[d].erase(S[d].find(b));
for (; d >= 1; d /= 2){
ll path_childs = (2*d) >= N ? 0LL : max(path[2*d], path[2*d+1]);
ll ans_childs = (2*d) >= N ? 0LL : max(ans[2*d], ans[2*d+1]);
path[d] = 0LL;
if(!S[d].empty())
path[d] = max(0LL, max(path_childs, 0LL) + *prev(S[d].end()));
ans[d] = max(0LL, max(path[d], ans_childs));
}
}
int main(){
int q; cin >> q;
while(q--){
int t, d, b;
cin >> t >> d >> b;
modify(d, b, (t==1));
cout << max(ans[1], 0LL) << endl;
}
}