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;
map<int, map<int, int> > mp;
int n;
struct Seg {
  int l, r;
  vector<pair<int, int> > v;
} C[1200005];
void build(int o, int l, int r) {
  C[o].l = l;
  C[o].r = r;
  if (l >= r) return;
  build(o * 2, l, ((C[o].l + C[o].r) / 2));
  build(o * 2 + 1, ((C[o].l + C[o].r) / 2) + 1, r);
}
void update(int o, int l, int r, pair<int, int> v) {
  if (C[o].l >= l && C[o].r <= r) {
    C[o].v.push_back(v);
    return;
  }
  if (l <= ((C[o].l + C[o].r) / 2)) update(o * 2, l, r, v);
  if (r > ((C[o].l + C[o].r) / 2)) update(o * 2 + 1, l, r, v);
}
struct State {
  long long typ, u, v, s, t;
};
stack<State> sta;
int mk[300005], f[300005];
long long s[300005], t[300005];
int find(int p) { return f[p] == p ? p : find(f[p]); }
long long res, ans[300005];
void Resolve(int o) {
  int siz = sta.size();
  long long _rev = res;
  for (int i = 0, u, v; i < C[o].v.size(); i++) {
    u = C[o].v[i].first;
    v = C[o].v[i].second;
    if (mk[v] == 0) {
      mk[v] = u;
      u = find(u);
      t[u]++;
      res += s[u];
      sta.push({0, u, v, 0, 1});
    } else if (find(mk[v]) != find(u)) {
      u = find(u);
      v = find(mk[v]);
      if (s[u] > s[v]) swap(u, v);
      res += (s[u] + s[v]) * (t[u] + t[v]) - s[u] * t[u] - s[v] * t[v];
      sta.push({1, u, v, s[u], t[u]});
      s[v] += s[u];
      t[v] += t[u];
      f[u] = v;
    }
  }
  if (C[o].l >= C[o].r) {
    ans[C[o].l] = res;
    goto Karkov;
  }
  Resolve(o * 2);
  Resolve(o * 2 + 1);
Karkov:;
  while (sta.size() > siz) {
    State u = sta.top();
    if (u.typ == 0) {
      t[u.u] -= u.t;
      mk[u.v] = 0;
    }
    if (u.typ == 1) {
      s[u.v] -= u.s;
      t[u.v] -= u.t;
      f[u.u] = u.u;
    }
    sta.pop();
  }
  res = _rev;
}
int main() {
  scanf("%d", &n);
  build(1, 1, n);
  for (int i = 1, u, v; i <= n; i++) {
    scanf("%d%d", &u, &v);
    if (mp[u][v] == 0)
      mp[u][v] = i;
    else {
      update(1, mp[u][v], i - 1, make_pair(u, v));
      mp[u][v] = 0;
    }
  }
  for (auto s : mp)
    for (auto t : s.second)
      if (t.second) {
        update(1, t.second, n, make_pair(s.first, t.first));
      }
  for (int i = 1; i <= n; i++) {
    f[i] = i;
    s[i] = 1;
  }
  Resolve(1);
  for (int i = 1; i <= n; i++) printf("%lld ", ans[i]);
}