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 maxn = 300007;
vector<pair<int, int> > sgt[maxn << 2];
void update(int id, int l, int r, int L, int R, pair<int, int> p) {
  if (l >= L && r <= R) {
    sgt[id].push_back(p);
    return;
  }
  if (l > R || L > r) return;
  int mid = (l + r) / 2;
  update((id << 1), l, mid, L, R, p);
  update(((id << 1) | 1), mid + 1, r, L, R, p);
}
long long ans[maxn], res;
int siz[maxn << 1][2], fa[maxn << 1];
int fnd(int x) { return fa[x] == x ? x : fnd(fa[x]); }
stack<int> o;
void merge(int x, int y) {
  x = fnd(x), y = fnd(y);
  if (x == y) return;
  if (siz[x][0] + siz[x][1] < siz[y][0] + siz[y][1]) swap(x, y);
  res -= 1ll * siz[x][0] * siz[x][1];
  res -= 1ll * siz[y][0] * siz[y][1];
  siz[x][0] += siz[y][0];
  siz[x][1] += siz[y][1];
  res += 1ll * siz[x][0] * siz[x][1];
  fa[y] = x;
  o.push(y);
}
void clear(stack<int> cur) {
  while (!cur.empty()) {
    int y = cur.top();
    cur.pop();
    int x = fa[y];
    res -= 1ll * siz[x][0] * siz[x][1];
    siz[x][0] -= siz[y][0];
    siz[x][1] -= siz[y][1];
    fa[y] = y;
    res += 1ll * siz[x][0] * siz[x][1];
    res += 1ll * siz[y][0] * siz[y][1];
  }
}
void query(int id, int l, int r) {
  while (!o.empty()) o.pop();
  for (int i = 0; i < sgt[id].size(); ++i)
    merge(sgt[id][i].first, sgt[id][i].second + maxn);
  stack<int> cur = o;
  if (l == r)
    ans[l] = res;
  else {
    int mid = (l + r) / 2;
    query((id << 1), l, mid);
    query(((id << 1) | 1), mid + 1, r);
  }
  clear(cur);
}
int n;
pair<int, int> a[maxn];
map<pair<int, int>, int> last;
int main() {
  for (int i = 1; i < maxn; ++i) {
    siz[i][0] = 1;
    siz[i + maxn][1] = 1;
    fa[i] = i;
    fa[i + maxn] = i + maxn;
  }
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &a[i].first, &a[i].second);
    if (last.find(a[i]) != last.end() && last[a[i]] != -1) {
      update(1, 1, n, last[a[i]], i - 1, a[i]);
      last[a[i]] = -1;
    } else {
      last[a[i]] = i;
    }
  }
  for (int i = 1; i <= n; ++i)
    if (last[a[i]] == i) {
      update(1, 1, n, last[a[i]], n, a[i]);
    }
  query(1, 1, n);
  for (int i = 1; i <= n; ++i) printf("%I64d ", ans[i]);
  puts("");
  return 0;
}