#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   template <class T, class T1>   inline void gn(T &first, T1 &second) {     gn(first);     gn(second);   }   template <class T, class T1, class T2>   inline void gn(T &first, T1 &second, T2 &z) {     gn(first);     gn(second);     gn(z);   }   template <class T>   inline void println(T first) {     print(first);     putchar(  n );   }   template <class T>   inline void printsp(T first) {     print(first);     putchar(   );   }   template <class T1, class T2>   inline void print(T1 x1, T2 x2) {     printsp(x1), println(x2);   }   template <class T1, class T2, class T3>   inline void print(T1 x1, T2 x2, T3 x3) {     printsp(x1), printsp(x2), println(x3);   }   template <class T1, class T2, class T3, class T4>   inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {     printsp(x1), printsp(x2), printsp(x3), println(x4);   }   int son[400400][2], pa[400400], sz[400400];   long long sum[400400];   long long ans;   struct SplayTree {     int root;     void init(int first) {       root = first;       sz[first] = 1;       sum[first] = first;     }     void push_up(int first) {       sum[first] = first + sum[son[first][0]] + sum[son[first][1]];       sz[first] = 1 + sz[son[first][0]] + sz[son[first][1]];     }     void rot(int first, int d) {       int second = pa[first], z = pa[second];       son[second][!d] = son[first][d];       pa[son[first][d]] = second;       pa[first] = pa[second];       if (son[z][0] == second)         son[z][0] = first;       else if (son[z][1] == second)         son[z][1] = first;       pa[second] = first;       son[first][d] = second;       push_up(second);     }     void splay(int first, int g) {       while (pa[first] != g) {         if (pa[pa[first]] == g)           rot(first, son[pa[first]][0] == first);         else {           int second = pa[first], z = pa[second];           int d = (son[z][0] == second);           son[second][d] == first ? rot(first, !d) : rot(second, d);           rot(first, d);         }       }       push_up(first);       if (g == 0) root = first, pa[first] = 0;     }     void insert(int first, int second) {       if (second < first) {         if (son[first][0])           insert(son[first][0], second);         else           son[first][0] = second, pa[second] = first;       } else {         if (son[first][1])           insert(son[first][1], second);         else           son[first][1] = second, pa[second] = first;       }       push_up(first);     }     long long insert1(int first, int f) {       son[first][0] = son[first][1] = 0;       sz[first] = 1;       insert(root, first);       splay(first, 0);       if (!f) return -(long long)first * sz[son[first][0]] + sum[son[first][0]];       return -sum[son[first][1]] + (long long)first * sz[son[first][1]];     }     void get(int first, vector<int> &vec) {       if (son[first][0]) get(son[first][0], vec);       vec.push_back(first);       if (son[first][1]) get(son[first][1], vec);     }   } tree[400400];   int id[400400], pos[400400];   int nxt[400400];   int find_nxt(int u) { return u == nxt[u] ? u : nxt[u] = find_nxt(nxt[u]); }   void merge(int u, int v, int f = 0) {     if (sz[tree[u].root] < sz[tree[v].root]) swap(u, v), f = 1;     vector<int> vec;     tree[v].get(tree[v].root, vec);     if (!f) reverse(vec.begin(), vec.end());     for (int i = 0; i < vec.size(); i++) {       ans += tree[u].insert1(vec[i], f);       id[pos[vec[i]]] = u;     }   }   int main() {     int n;     gn(n);     for (int i = 1; i < 400400; i++) nxt[i] = i;     for (int i = 1; i <= n; i++) tree[i].init(i);     for (int i = 0, a, b; i < n; i++) {       gn(a, b);       int aa = a;       a = find_nxt(a);       ans += (long long)(a - aa) * b;       pos[b] = a;       id[a] = b;       nxt[a] = a + 1;       if (nxt[a - 1] > a - 1) merge(id[a - 1], id[a]);       if (nxt[a + 1] > a + 1) merge(id[a], id[a + 1]);       println(ans);     }     return 0;   }