Problem: For a given set of two-dimensional points S, let's denote its extension E(S) as the result of the following algorithm:

Create another set of two-dimensional points R, which is initially equal to S. Then, while there exist four numbers x_1, y_1, x_2 and y_2 such that (x_1, y_1) ∈ R, (x_1, y_2) ∈ R, (x_2, y_1) ∈ R and (x_2, y_2) ∉ R, add (x_2, y_2) to R. When it is impossible to find such four integers, let R be the result of the algorithm.

Now for the problem itself. You are given a set of two-dimensional points S, which is initially empty. You have to process two types of queries: add some point to S, or remove some point from it. After each query you have to compute the size of E(S).

Input

The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries.

Then q lines follow, each containing two integers x_i, y_i (1 ≤ x_i, y_i ≤ 3 ⋅ 10^5), denoting i-th query as follows: if (x_i, y_i) ∈ S, erase it from S, otherwise insert (x_i, y_i) into S.

Output

Print q integers. i-th integer should be equal to the size of E(S) after processing first i queries.

Example

Input


7
1 1
1 2
2 1
2 2
1 2
1 3
2 1


Output


1 2 4 4 4 6 3 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, m, cnt, top, fa[N], X[N], Y[N];
long long ans, Ans[N];
struct node {
  int x, y;
} zhan[N];
bool operator<(node a, node b) {
  if (a.x == b.x) return a.y < b.y;
  return a.x < b.x;
}
struct node2 {
  int l, r, x, y;
} b[N];
map<node, int> mp;
vector<node> g[N * 4];
inline int read() {
  int ret = 0, f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    ret = ret * 10 + c - 48;
    c = getchar();
  }
  if (f) return -ret;
  return ret;
}
int find(int x) {
  if (fa[x] == x) return x;
  return find(fa[x]);
}
void merge(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  ans -= (1ll * X[x] * Y[x] + 1ll * X[y] * Y[y]);
  if (X[x] + Y[x] > X[y] + Y[y]) swap(x, y);
  zhan[++top] = (node){x, y};
  fa[x] = y;
  X[y] += X[x];
  Y[y] += Y[x];
  ans += 1ll * X[y] * Y[y];
}
void del(int x, int y) {
  ans -= 1ll * X[y] * Y[y];
  fa[x] = x;
  X[y] -= X[x];
  Y[y] -= Y[x];
  ans += (1ll * X[x] * Y[x] + 1ll * X[y] * Y[y]);
}
void change(int nod, int l, int r, int L, int R, int x, int y) {
  if (l == L && r == R) {
    g[nod].push_back((node){x, y});
    return;
  }
  if (R <= (l + r) / 2)
    change(nod * 2, l, (l + r) / 2, L, R, x, y);
  else if (L > (l + r) / 2)
    change(nod * 2 + 1, (l + r) / 2 + 1, r, L, R, x, y);
  else {
    change(nod * 2, l, (l + r) / 2, L, (l + r) / 2, x, y);
    change(nod * 2 + 1, (l + r) / 2 + 1, r, (l + r) / 2 + 1, R, x, y);
  }
}
void solve(int nod, int l, int r) {
  int tim = top;
  for (int i = 0; i < g[nod].size(); i++) merge(g[nod][i].x, g[nod][i].y);
  if (l == r)
    Ans[l] = ans;
  else {
    solve(nod * 2, l, (l + r) / 2);
    solve(nod * 2 + 1, (l + r) / 2 + 1, r);
  }
  while (tim < top) {
    del(zhan[top].x, zhan[top].y);
    top--;
  }
}
int main() {
  int n = 300005;
  m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read() + n;
    node xu = (node){x, y};
    if (mp.count(xu)) {
      b[mp[xu]].r = i - 1;
      mp.erase(xu);
    } else {
      mp[xu] = ++cnt;
      b[cnt] = (node2){i, 0, x, y};
    }
  }
  for (int i = 1; i <= cnt; i++) {
    if (!b[i].r) b[i].r = m;
    change(1, 1, m, b[i].l, b[i].r, b[i].x, b[i].y);
  }
  for (int i = 1; i <= n + n; i++) {
    fa[i] = i;
    X[i] = (i <= n);
    Y[i] = !X[i];
  }
  solve(1, 1, m);
  for (int i = 1; i <= m; i++) printf("%lld ", Ans[i]);
}