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;
struct query {
  int x, y;
};
struct Node {
  int x, y, fa, r;
};
const int ALLN = 6e5 + 10;
const int N = 3e5 + 5;
struct rollbackDSU {
  int p[ALLN], rankk[ALLN], szx[ALLN], szy[ALLN];
  long long ans;
  stack<Node> st;
  void init() {
    for (int i = 1; i < ALLN; i++) p[i] = i, rankk[i] = 0;
    for (int i = 1; i <= N; i++) szx[i] = 1, szy[i] = 0;
    for (int i = N + 1; i < ALLN; i++) szx[i] = 0, szy[i] = 1;
    while (!st.empty()) st.pop();
    ans = 0;
  }
  int find(int x) {
    while (x != p[x]) x = p[x];
    return x;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  void unite(int x, int y) {
    int fx = find(x), fy = find(y);
    if (rankk[fx] > rankk[fy]) swap(fx, fy);
    st.push((Node){fx, fy, p[fx], rankk[fy]});
    if (rankk[fx] == rankk[fy]) rankk[fy]++;
    ans += 1LL * szx[fx] * szy[fy] + 1LL * szx[fy] * szy[fx];
    szx[fy] += szx[fx];
    szy[fy] += szy[fx];
    p[fx] = fy;
  }
  void rollback(int x) {
    Node y;
    for (int i = 1; i <= x; i++) {
      y = st.top();
      st.pop();
      p[y.x] = y.fa;
      rankk[y.y] = y.r;
      szx[y.y] -= szx[y.x];
      szy[y.y] -= szy[y.x];
      ans -= 1LL * szx[y.x] * szy[y.y] + 1LL * szx[y.y] * szy[y.x];
    }
  }
};
query q[N];
vector<int> rec[N << 2];
map<pair<int, int>, int> sav;
long long ans[N];
rollbackDSU dsu;
void update(int ql, int qr, int id, int rt, int l, int r) {
  if (ql <= l && r <= qr) {
    rec[rt].push_back(id);
    return;
  }
  int mid = (l + r) >> 1;
  if (ql <= mid) update(ql, qr, id, rt << 1, l, mid);
  if (qr > mid) update(ql, qr, id, rt << 1 | 1, mid + 1, r);
}
void dfs(int rt, int l, int r) {
  int sz = (int)rec[rt].size(), id, cnt = 0, x, y;
  for (int i = 0; i < sz; i++) {
    id = rec[rt][i];
    x = q[id].x;
    y = q[id].y;
    if (!dsu.same(x, y + N)) {
      dsu.unite(x, y + N);
      cnt++;
    }
  }
  if (l == r)
    ans[l] = dsu.ans;
  else {
    int mid = (l + r) >> 1;
    dfs(rt << 1, l, mid);
    dfs(rt << 1 | 1, mid + 1, r);
  }
  dsu.rollback(cnt);
}
int main() {
  int n, tot, x, y;
  scanf("%d", &n);
  tot = 0;
  dsu.init();
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &x, &y);
    if (sav.count({x, y})) {
      q[++tot] = (query){x, y};
      update(sav[{x, y}], i - 1, tot, 1, 1, n);
      sav.erase({x, y});
    } else
      sav[{x, y}] = i;
  }
  for (auto it : sav) {
    q[++tot] = (query){it.first.first, it.first.second};
    update(it.second, n, tot, 1, 1, n);
  }
  dfs(1, 1, n);
  for (int i = 1; i <= n; i++) printf("%I64d ", ans[i]);
  printf("\n");
  return 0;
}