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;
char _;
int n, par[600005], xcnt[600005], ycnt[600005];
int first, second, gl, gr;
long long ans;
map<pair<int, int>, int> m;
vector<pair<int, int> > seg[1200005];
vector<pair<int, int> > res[1200005];
int root(int A) {
  for (; par[A] != 0; A = par[A])
    ;
  return A;
}
bool mrg(int A, int B, int N) {
  A = root(A);
  B = root(B);
  if (A == B) return 0;
  if (xcnt[A] + ycnt[A] < xcnt[B] + ycnt[B]) {
    return mrg(B, A, N);
  }
  res[N].push_back(make_pair(A, B));
  par[B] = A;
  ans -= 1LL * xcnt[A] * ycnt[A];
  ans -= 1LL * xcnt[B] * ycnt[B];
  xcnt[A] += xcnt[B];
  ycnt[A] += ycnt[B];
  ans += 1LL * xcnt[A] * ycnt[A];
  return 1;
}
void unmrg(int A, int B) {
  par[B] = 0;
  ans -= 1LL * xcnt[A] * ycnt[A];
  xcnt[A] -= xcnt[B];
  ycnt[A] -= ycnt[B];
  ans += 1LL * xcnt[A] * ycnt[A];
  ans += 1LL * xcnt[B] * ycnt[B];
}
void add(int L, int R, int N) {
  if (L > gr || R < gl) return;
  if (gl <= L && R <= gr) {
    seg[N].push_back(make_pair(first, second));
    return;
  }
  add(L, (L + R) / 2, N * 2 + 1);
  add((L + R) / 2 + 1, R, N * 2 + 2);
}
void solve(int L, int R, int N) {
  for (int l = 0; l < seg[N].size(); ++l) {
    mrg(seg[N][l].first, seg[N][l].second + 300000, N);
  }
  if (L == R) {
    printf("%lli ", ans);
  } else {
    solve(L, (L + R) / 2, N * 2 + 1);
    solve((L + R) / 2 + 1, R, N * 2 + 2);
  }
  for (int l = res[N].size() - 1; l >= 0; --l) {
    unmrg(res[N][l].first, res[N][l].second);
  }
}
int32_t main() {
  for (int l = 1; l <= 300000; ++l) ycnt[l + 300000] = xcnt[l] = 1;
  scanf("%i", &n);
  for (int l = 0; l < n; ++l) {
    scanf("%i%i", &first, &second);
    if (m.count(make_pair(first, second))) {
      gl = m[make_pair(first, second)];
      gr = l - 1;
      m.erase(make_pair(first, second));
      add(0, n - 1, 0);
    } else {
      m[make_pair(first, second)] = l;
    }
  }
  for (auto i : m) {
    first = i.first.first;
    second = i.first.second;
    gl = i.second;
    gr = n - 1;
    add(0, n - 1, 0);
  }
  solve(0, n - 1, 0);
  return 0;
}
