func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   long long seg[5000000];   long long scn[5000000];   void update(long long pos, long long x, long long l = 0, long long r = 300000,               long long ind = 1) {     if (l == r && l == pos)       seg[ind] = x, scn[ind] = x > 0;     else if (l > pos || r < pos)       return;     else if (l != r) {       update(pos, x, l, (l + r) / 2, ind * 2);       update(pos, x, (l + r) / 2 + 1, r, ind * 2 + 1);       seg[ind] = seg[ind * 2] + seg[ind * 2 + 1];       scn[ind] = scn[ind * 2] + scn[ind * 2 + 1];     }   }   long long query(long long light, long long l = 0, long long r = 300000,                   long long ind = 1) {     if (l == r || scn[ind] == light) return seg[ind];     if (scn[ind * 2] >= light)       return query(light, l, (l + r) / 2, ind * 2);     else       return seg[ind * 2] +              query(light - scn[ind * 2], (l + r) / 2 + 1, r, ind * 2 + 1);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     pair<long long, long long> a[n];     set<long long> all;     for (long long i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;       if (a[i].second > 0) {         all.insert(-a[i].second);       }     }     map<long long, long long> mapper;     long long cnt = 1;     for (auto v : all) {       mapper[-v] = cnt++;     }     cnt = 0;     set<long long> light;     for (long long i = 0; i < n; i++) {       if (a[i].first && a[i].second > 0)         light.insert(a[i].second);       else if (a[i].first && a[i].second < 0)         light.erase(-a[i].second);       if (a[i].second > 0)         update(mapper[a[i].second], a[i].second), cnt++;       else if (a[i].second < 0)         update(mapper[-a[i].second], 0), cnt--;       long long ans = seg[1];       if (light.size()) update(mapper[(*light.begin())], 0);       if (cnt == (long long)light.size())         ans += query((long long)light.size() - 1);       else         ans += query(light.size());       if (light.size()) update(mapper[(*light.begin())], (*light.begin()));       cout << ans << endl;     }   }   