#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 5;   int n;   int fa[N], r[N];   int rt[N], ls[N * 30], rs[N * 30], siz[N * 30], tot;   long long sum[N * 30], ans;   void update(int &rt, int l, int r, int p) {     if (!rt) rt = ++tot;     if (l == r) {       siz[rt] = 1, sum[rt] = p;       return;     }     int mid = (l + r) >> 1;     if (p <= mid)       update(ls[rt], l, mid, p);     else       update(rs[rt], mid + 1, r, p);     siz[rt] = siz[ls[rt]] + siz[rs[rt]];     sum[rt] = sum[ls[rt]] + sum[rs[rt]];   }   int merge(int x, int y) {     if (!x || !y) return x | y;     ans -= sum[ls[x]] * siz[rs[x]] + sum[ls[y]] * siz[rs[y]];     ls[x] = merge(ls[x], ls[y]);     rs[x] = merge(rs[x], rs[y]);     ans += sum[ls[x]] * siz[rs[x]];     siz[x] += siz[y];     sum[x] += sum[y];     return x;   }   inline int findf(int x) { return x == fa[x] ? x : fa[x] = findf(fa[x]); }   void unify(int x, int y) {     x = findf(x), y = findf(y);     fa[y] = x;     ans -= sum[rt[x]] * x + sum[rt[y]] * y;     rt[x] = merge(rt[x], rt[y]);     ans += sum[rt[x]] * x;     r[x] = r[y];   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= 400000; i++) fa[i] = i, r[i] = i;     for (int i = 1, a, b; i <= n; i++) {       scanf( %d%d , &a, &b);       int p = rt[a] ? r[findf(a)] + 1 : a;       ans -= 1ll * a * b;       ans += 1ll * p * b;       update(rt[p], 1, n, b);       if (rt[p - 1]) unify(p - 1, p);       if (rt[p + 1]) unify(p, p + 1);       printf( %lld n , ans);     }     return 0;   }   