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;
int gi() {
  int x = 0, w = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') w = 0, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return w ? x : -x;
}
const int N = 3e5 + 5;
int q, fa[N + N], top;
pair<int, int> sz[N + N], sta[N];
map<pair<int, int>, int> M;
vector<pair<int, int> > vec[N << 2];
long long ans;
pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
pair<int, int> operator-(pair<int, int> a, pair<int, int> b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
int find(int x) { return x == fa[x] ? x : find(fa[x]); }
void modify(int x, int l, int r, int ql, int qr, pair<int, int> p) {
  if (l >= ql && r <= qr) {
    vec[x].push_back(p);
    return;
  }
  int mid = l + r >> 1;
  if (ql <= mid) modify(x << 1, l, mid, ql, qr, p);
  if (qr > mid) modify(x << 1 | 1, mid + 1, r, ql, qr, p);
}
void dfs(int x, int l, int r) {
  int tt = top;
  for (pair<int, int> p : vec[x])
    if (find(p.first) != find(p.second)) {
      int u = find(p.first), v = find(p.second);
      if (sz[u].first + sz[u].second < sz[v].first + sz[v].second) swap(u, v);
      sta[++top] = make_pair(u, v);
      ans -= 1ll * sz[u].first * sz[u].second;
      ans -= 1ll * sz[v].first * sz[v].second;
      fa[v] = u;
      sz[u] = sz[u] + sz[v];
      ans += 1ll * sz[u].first * sz[u].second;
    }
  if (l == r)
    printf("%lld ", ans);
  else {
    int mid = l + r >> 1;
    dfs(x << 1, l, mid);
    dfs(x << 1 | 1, mid + 1, r);
  }
  while (top > tt) {
    int u = sta[top].first, v = sta[top].second;
    --top;
    ans -= 1ll * sz[u].first * sz[u].second;
    fa[v] = v;
    sz[u] = sz[u] - sz[v];
    ans += 1ll * sz[u].first * sz[u].second;
    ans += 1ll * sz[v].first * sz[v].second;
  }
}
int main() {
  q = gi();
  for (int i = 1; i <= q; ++i) {
    int x = gi(), y = gi() + N;
    if (M.find(make_pair(x, y)) == M.end())
      M[make_pair(x, y)] = i;
    else
      modify(1, 1, q, M[make_pair(x, y)], i - 1, make_pair(x, y)),
          M.erase(make_pair(x, y));
  }
  for (auto it = M.begin(); it != M.end(); ++it)
    modify(1, 1, q, (*it).second, q, (*it).first);
  for (int i = 1; i < N + N; ++i) fa[i] = i, sz[i] = make_pair(i < N, i >= N);
  dfs(1, 1, q);
  return 0;
}