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 
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v((1 << 20));
int parent[600001], tSize[600001], xSize[600001], ySize[600001], qx[600001],
    qy[600001];
long long ans = 0, queryAns[600001];
void Initialise() {
  for (int i = 1, n = 600001 / 2; i < 600001; ++i) {
    parent[i] = i;
    tSize[i] = 1;
    xSize[i] = (i <= n);
    ySize[i] = (i > n);
  }
}
int Find(int i) {
  for (; parent[i] != i; i = parent[i])
    ;
  return i;
}
void UpdateAns(int i, int x) {
  long long ansx = 1ll * xSize[i] * ySize[i];
  ans += x * ansx;
}
void PushStateToStack(int i,
                      stack<tuple<int, int, int, int, int, long long> > &S) {
  S.push(make_tuple(i, parent[i], tSize[i], xSize[i], ySize[i], ans));
  UpdateAns(i, -1);
}
void Union(int i, int j, stack<tuple<int, int, int, int, int, long long> > &S) {
  i = Find(i), j = Find(j);
  if (i == j) {
    return;
  }
  if (tSize[i] < tSize[j]) {
    swap(i, j);
  }
  PushStateToStack(i, S);
  PushStateToStack(j, S);
  parent[j] = i;
  tSize[i] += tSize[j];
  xSize[i] += xSize[j];
  ySize[i] += ySize[j];
  UpdateAns(i, 1);
}
void ApplyRollback(stack<tuple<int, int, int, int, int, long long> > &S) {
  for (; !S.empty(); S.pop()) {
    int i = get<0>(S.top());
    tie(i, parent[i], tSize[i], xSize[i], ySize[i], ans) = S.top();
  }
}
void Update(int k, int l, int r, int ql, int qr, int x) {
  if (qr < l || r < ql) {
    return;
  }
  if (ql <= l && r <= qr) {
    v[k].push_back(x);
    return;
  }
  Update(2 * k + 1, l, (l + r) / 2, ql, qr, x);
  Update(2 * k + 2, (l + r) / 2 + 1, r, ql, qr, x);
}
void Solve(int k, int l, int r) {
  stack<tuple<int, int, int, int, int, long long> > S;
  for (int i : v[k]) {
    Union(qx[i], qy[i], S);
  }
  if (l != r) {
    Solve(2 * k + 1, l, (l + r) / 2);
    Solve(2 * k + 2, (l + r) / 2 + 1, r);
  } else {
    queryAns[l] = ans;
  }
  ApplyRollback(S);
}
int main() {
  int n;
  map<pair<int, int>, int> pointMap;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    y += (600001 / 2);
    pair<int, int> p = make_pair(x, y);
    auto it = pointMap.find(p);
    if (it == pointMap.end()) {
      pointMap[p] = i;
      qx[i] = x, qy[i] = y;
    } else {
      int j = it->second;
      Update(0, 1, n, j, i - 1, j);
      pointMap.erase(it);
    }
  }
  for (auto q : pointMap) {
    Update(0, 1, n, q.second, n, q.second);
  }
  Initialise();
  Solve(0, 1, n);
  for (int i = 1; i <= n; ++i) {
    printf("%lld ", queryAns[i]);
  }
  printf("\n");
  return 0;
}
