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;
template <typename T>
void chkmax(T& x, T y) {
  if (x < y) x = y;
}
template <typename T>
void chkmin(T& x, T y) {
  if (x > y) x = y;
}
inline int read() {
  int x = 0;
  char c = getchar();
  bool f = 0;
  while (c < 48) f |= c == '-', c = getchar();
  while (c > 47) x = x * 10 + (c ^ 48), c = getchar();
  return f ? -x : x;
}
const int maxn = 6e5 + 10;
int n = 3e5, q;
map<pair<int, int>, int> mp;
int par[maxn], sz1[maxn], sz2[maxn];
int top, st[maxn];
long long as;
int find(int x) {
  while (x != par[x]) x = par[x];
  return x;
}
void unite(int x, int y) {
  if ((x = find(x)) != (y = find(y))) {
    if (sz1[x] + sz2[x] < sz1[y] + sz2[y]) swap(x, y);
    par[y] = x, as -= 1ll * sz1[x] * sz2[x], as -= 1ll * sz1[y] * sz2[y],
    sz1[x] += sz1[y], sz2[x] += sz2[y], as += 1ll * sz1[x] * sz2[x],
    st[++top] = y;
  }
}
void revert(int k) {
  while (top > k) {
    int u = st[top--];
    sz1[par[u]] -= sz1[u], sz2[par[u]] -= sz2[u], par[u] = u;
  }
}
vector<pair<int, int> > vec[maxn << 2];
void add(int k, int l, int r, int ql, int qr, pair<int, int> e) {
  if (ql <= l && r <= qr) return vec[k].push_back(e), void();
  if (ql <= ((l + r) >> 1)) add(k << 1, l, ((l + r) >> 1), ql, qr, e);
  if (qr > ((l + r) >> 1)) add(k << 1 | 1, ((l + r) >> 1) + 1, r, ql, qr, e);
}
void divide(int k, int l, int r) {
  int tp = top;
  long long TAS = as;
  for (pair<int, int> p : vec[k]) {
    unite(p.first, p.second);
  }
  if (l == r)
    printf("%I64d ", as);
  else
    divide(k << 1, l, ((l + r) >> 1)),
        divide(k << 1 | 1, ((l + r) >> 1) + 1, r);
  revert(tp), as = TAS;
}
void solve() {
  cin >> q;
  for (int i = (1), iend = (n); i <= iend; ++i)
    par[i] = i, sz1[i] = 1, par[n + i] = n + i, sz2[n + i] = 1;
  for (int i = (1), iend = (q); i <= iend; ++i) {
    int u = read(), v = n + read(), x = mp[{u, v}];
    if (x) {
      add(1, 1, q, x, i - 1, {u, v}), mp.erase({u, v});
    } else {
      mp[{u, v}] = i;
    }
  }
  for (auto p : mp) {
    add(1, 1, q, p.second, q, p.first);
  }
  divide(1, 1, q);
}
signed main() {
  solve();
  return 0;
}