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;
class opt {
 public:
  int x, y, fx, fy;
  pair<int, int> sx, sy;
};
vector<opt> O;
int q, n, fa[600010];
long long cur, ans[300010];
pair<int, int> siz[600010];
inline int getf(int x) { return x == fa[x] ? x : getf(fa[x]); }
inline long long vl(pair<int, int> &t) { return 1ll * t.first * t.second; }
inline int merge(int x, int y) {
  x = getf(x);
  y = getf(y);
  if (x == y) return 0;
  O.push_back((opt){x, y, fa[x], fa[y], siz[x], siz[y]});
  if (siz[x].first + siz[x].second > siz[y].first + siz[y].second) swap(x, y);
  cur -= vl(siz[x]) + vl(siz[y]);
  fa[x] = y;
  siz[y].first += siz[x].first;
  siz[y].second += siz[x].second;
  cur += vl(siz[y]);
  return 1;
}
inline void rollback() {
  opt p = O.back();
  O.pop_back();
  int x = p.x, y = p.y;
  pair<int, int> tmp =
      make_pair(p.sx.first + p.sy.first, p.sx.second + p.sy.second);
  cur -= vl(tmp);
  cur += vl(p.sx) + vl(p.sy);
  fa[x] = p.fx;
  fa[y] = p.fy;
  siz[x] = p.sx;
  siz[y] = p.sy;
}
map<pair<int, int>, int> mp;
vector<pair<int, int> > v[1200010];
class seg {
 public:
  int x, y, l, r;
} sg[300010];
void modify(int p, int l, int r, int ml, int mr, int x, int y) {
  if (ml <= l && r <= mr) {
    v[p].push_back(make_pair(x, y));
    return;
  }
  int mid = (l + r) >> 1;
  if (ml <= mid) modify((p << 1), l, mid, ml, mr, x, y);
  if (mr > mid) modify(((p << 1) | 1), mid + 1, r, ml, mr, x, y);
}
void solve(int p, int l, int r) {
  int cnt = 0;
  for (auto &x : v[p]) cnt += merge(x.first, x.second);
  if (l == r)
    ans[l] = cur;
  else {
    int mid = (l + r) >> 1;
    solve((p << 1), l, mid);
    solve(((p << 1) | 1), mid + 1, r);
  }
  for (int i = 0; i < cnt; i++) rollback();
}
int main() {
  for (int i = 1; i <= 300000; i++) fa[i] = i, siz[i] = make_pair(1, 0);
  for (int i = 300001; i <= 600000; i++) fa[i] = i, siz[i] = make_pair(0, 1);
  scanf("%d", &q);
  for (int i = 1, ti, tj; i <= q; i++) {
    scanf("%d%d", &ti, &tj);
    if (mp.find(make_pair(ti, tj)) != mp.end()) {
      sg[++n] = (seg){ti, tj, mp[make_pair(ti, tj)], i - 1};
      mp.erase(make_pair(ti, tj));
    } else {
      mp[make_pair(ti, tj)] = i;
    }
  }
  for (auto &x : mp)
    sg[++n] = (seg){x.first.first, x.first.second, x.second, q};
  for (int i = 1; i <= n; i++)
    modify(1, 1, q, sg[i].l, sg[i].r, sg[i].x, sg[i].y + 300000);
  solve(1, 1, q);
  for (int i = 1; i <= q; i++) printf("%lld ", ans[i]);
  return 0;
}