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;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
  return x * f;
}
const int N = 6e5 + 5, M = 3e5;
int f[N], siz[N], sizl[N], sizr[N], st[N << 1], top;
long long ans;
inline int get(int x) {
  while (x ^ f[x]) x = f[x];
  return x;
}
inline void merge(int x, int y) {
  x = get(x), y = get(y);
  if (x == y) return;
  if (siz[x] < siz[y]) swap(x, y);
  ans -= 1ll * sizl[x] * sizr[x];
  ans -= 1ll * sizl[y] * sizr[y];
  siz[x] += siz[y];
  sizl[x] += sizl[y];
  sizr[x] += sizr[y];
  ans += 1ll * sizl[x] * sizr[x];
  f[y] = x;
  st[++top] = y, st[++top] = x;
}
inline void del() {
  int x = st[top--], y = st[top--];
  ans -= 1ll * sizl[x] * sizr[x];
  siz[x] -= siz[y];
  sizl[x] -= sizl[y];
  sizr[x] -= sizr[y];
  ans += 1ll * sizl[x] * sizr[x];
  ans += 1ll * sizl[y] * sizr[y];
  f[y] = y;
}
vector<pair<int, int> > vt[N << 1];
inline void Insert(int p, int l, int r, int L, int R, pair<int, int> i) {
  if (l >= L && r <= R) return vt[p].push_back(i), void();
  int mid = (l + r) >> 1;
  if (L <= mid) Insert(p << 1, l, mid, L, R, i);
  if (R > mid) Insert(p << 1 | 1, mid + 1, r, L, R, i);
}
inline void solve(int p, int l, int r) {
  int now = top;
  for (auto u : vt[p]) merge(u.first, u.second);
  if (l == r)
    printf("%lld ", ans);
  else {
    int mid = (l + r) >> 1;
    solve(p << 1, l, mid);
    solve(p << 1 | 1, mid + 1, r);
  }
  while (top > now) del();
}
map<pair<int, int>, int> mp;
int n;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    int x = read(), y = read() + M;
    if (mp.find(make_pair(x, y)) == mp.end())
      mp[make_pair(x, y)] = i;
    else
      Insert(1, 1, n, mp[make_pair(x, y)], i - 1, make_pair(x, y)),
          mp.erase(make_pair(x, y));
  }
  for (auto u : mp) Insert(1, 1, n, u.second, n, u.first);
  for (int i = 1; i <= M; i++) f[i] = i, sizl[i] = siz[i] = 1;
  for (int i = M + 1; i <= M + M; i++) f[i] = i, sizr[i] = siz[i] = 1;
  solve(1, 1, n);
  return 0;
}