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;
vector<int> par;
vector<int> rnk;
vector<long long> answer;
vector<long long> xs, ys;
long long ans = 0;
int dsu_ind = 0;
int ch = 0;
struct change {
  int i = -1;
  int p;
  int rank_delta;
  int was_x;
  int was_y;
};
vector<change> changes;
int parent(int v) {
  while (v != par[v]) v = par[v];
  return v;
}
change unite(int u, int v) {
  int pu = parent(u), pv = parent(v);
  change c;
  if (pu == pv) return c;
  if (rnk[pu] < rnk[pv] || (rnk[pu] == rnk[pv] && rand() % 2 == 1)) {
    c.i = pu;
    c.p = pv;
    c.rank_delta = rnk[pu];
    c.was_x = xs[pv];
    c.was_y = ys[pv];
    ans -= xs[pu] * ys[pu] + xs[pv] * ys[pv];
    par[pu] = pv;
    xs[pv] += xs[pu];
    ys[pv] += ys[pu];
    ans += xs[pv] * ys[pv];
  } else {
    c.i = pv;
    c.p = pu;
    c.rank_delta = rnk[pv];
    c.was_x = xs[pu];
    c.was_y = ys[pu];
    ans -= xs[pu] * ys[pu] + xs[pv] * ys[pv];
    par[pv] = pu;
    xs[pu] += xs[pv];
    ys[pu] += ys[pv];
    ans += xs[pu] * ys[pu];
  }
  42;
  ;
  return c;
}
struct segtree {
  int n;
  vector<vector<pair<int, int>>> tree;
  segtree(int n) : n(n), tree(n * 4){};
  void add(int l, int r, pair<int, int>& p, int i, int vl, int vr) {
    if (l == vl && r == vr) {
      tree[i].push_back(p);
      ++ch;
      return;
    }
    int m = (vl + vr) / 2;
    if (r <= m)
      add(l, r, p, 2 * i + 1, vl, m);
    else if (l > m)
      add(l, r, p, 2 * i + 2, m + 1, vr);
    else {
      add(l, m, p, 2 * i + 1, vl, m);
      add(m + 1, r, p, 2 * i + 2, m + 1, vr);
    }
  }
  void add(int l, int r, pair<int, int> p) { add(l, r, p, 0, 0, n - 1); }
  void dfs(int i, int l, int r) {
    int sz = changes.size();
    for (auto p : tree[i]) {
      auto c = unite(p.first, p.second);
      if (c.i != -1) changes.push_back(c);
    }
    if (l == r) {
      answer[l] = ans;
    } else {
      int m = (l + r) / 2;
      dfs(2 * i + 1, l, m);
      dfs(2 * i + 2, m + 1, r);
    }
    while (changes.size() > sz) {
      if (changes.back().i != -1) {
        par[changes.back().i] = changes.back().i;
        rnk[changes.back().p] -= changes.back().rank_delta;
        ans -= xs[changes.back().p] * ys[changes.back().p];
        xs[changes.back().p] = changes.back().was_x;
        ys[changes.back().p] = changes.back().was_y;
        ans += xs[changes.back().i] * ys[changes.back().i];
        ans += xs[changes.back().p] * ys[changes.back().p];
      }
      changes.pop_back();
    }
  }
  void dfs() { dfs(0, 0, n - 1); }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  segtree t(n);
  map<pair<int, int>, int> mp;
  xs.assign(n * 2 + 3, 0);
  ys.assign(n * 2 + 3, 0);
  vector<int> compx, compy;
  vector<pair<int, int>> points(n);
  for (int i = 0; i < n; ++i) {
    cin >> points[i].first >> points[i].second;
    compx.push_back(points[i].first);
    compy.push_back(points[i].second);
  }
  sort(compx.begin(), compx.end());
  compx.erase(unique(compx.begin(), compx.end()), compx.end());
  sort(compy.begin(), compy.end());
  compy.erase(unique(compy.begin(), compy.end()), compy.end());
  for (int i = 0; i < n; ++i) {
    points[i].first = lower_bound(compx.begin(), compx.end(), points[i].first) -
                      compx.begin();
    points[i].second =
        lower_bound(compy.begin(), compy.end(), points[i].second) -
        compy.begin();
    points[i].second += compx.size();
    xs[points[i].first] = 1;
    ys[points[i].second] = 1;
  }
  for (int i = 0; i < n; ++i) {
    auto p = points[i];
    auto it = mp.find(p);
    if (it == mp.end()) {
      mp[p] = i;
    } else if (it->second == -1) {
      it->second = i;
    } else {
      t.add(it->second, i - 1, p);
      it->second = -1;
    }
  }
  for (auto p : mp) {
    if (p.second != -1) t.add(p.second, n - 1, p.first);
  }
  changes.reserve(ch + 10);
  par.resize(n * 2 + 3);
  answer.resize(n);
  rnk.assign(n * 2 + 3, 1);
  for (int i = 0; i < n * 2 + 3; ++i) {
    par[i] = i;
  }
  t.dfs();
  for (int i = 0; i < n; ++i) {
    cout << answer[i] << ' ';
  }
  cout << '\n';
  return 0;
}