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 
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
  return a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
  return a < b ? a : b;
}
const char lf = '\n';
namespace ae86 {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t = buf;
inline int fetch() {
  if (s == t) {
    t = (s = buf) + fread(buf, 1, bufl, stdin);
    if (s == t) return EOF;
  }
  return *s++;
}
inline int ty() {
  int a = 0;
  int b = 1, c = fetch();
  while (!isdigit(c)) b ^= c == '-', c = fetch();
  while (isdigit(c)) a = a * 10 + c - 48, c = fetch();
  return b ? a : -a;
}
}  // namespace ae86
using ae86::ty;
const int _ = 300007, __ = _ + _;
struct bfa {
  int bfa[__], bsz[__];
  long long va[__], vb[__];
  pair<int, int> stk[9999999];
  int top;
  long long ans;
  long long fuck(int x) { return va[x] * vb[x]; }
  void make(int n) {
    int nn = n + n;
    top = 0, ans = 0;
    for (int i = 1; i <= nn; i++) bfa[i] = i, bsz[i] = 1;
    for (int i = 1; i <= n; i++) va[i] = 1, vb[i] = 0;
    for (int i = n + 1; i <= nn; i++) va[i] = 0, vb[i] = 1;
  }
  int findbfa(int x) {
    if (bfa[x] == x) return x;
    return findbfa(bfa[x]);
  }
  void linka(int a, int b) {
    a = findbfa(a), b = findbfa(b);
    if (a == b) return;
    if (bsz[a] < bsz[b]) swap(a, b);
    ans -= fuck(a), ans -= fuck(b);
    stk[++top] = pair<int, int>(a, b), bfa[b] = a, bsz[a] += bsz[b],
    va[a] += va[b], vb[a] += vb[b];
    ans += fuck(a);
  }
  void redo(int tar) {
    while (top > tar) {
      auto [a, b] = stk[top--];
      ans -= fuck(a);
      bfa[b] = b, bsz[a] -= bsz[b], va[a] -= va[b], vb[a] -= vb[b];
      ans += fuck(a), ans += fuck(b);
    }
  }
} f;
long long ans[_] = {0};
struct sgt {
  static const int _t = _ << 2;
  vector<pair<int, int> > t[_t];
  void plant(int x, int l, int r) {
    t[x].clear();
    if (l == r) return;
    plant((x << 1), l, ((l + r) >> 1)),
        plant((x << 1 | 1), ((l + r) >> 1) + 1, r);
  }
  void change(int x, int l, int r, int tl, int tr, pair<int, int> dlt) {
    if (tl <= l && r <= tr) {
      t[x].emplace_back(dlt);
      return;
    }
    if (tl <= ((l + r) >> 1)) change((x << 1), l, ((l + r) >> 1), tl, tr, dlt);
    if (tr > ((l + r) >> 1))
      change((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr, dlt);
  }
  void make(int x, int l, int r) {
    int temp = f.top;
    for (auto i : t[x]) f.linka(i.first, i.second);
    if (l == r)
      ans[l] = f.ans;
    else
      make((x << 1), l, ((l + r) >> 1)),
          make((x << 1 | 1), ((l + r) >> 1) + 1, r);
    f.redo(temp);
  }
} t;
map<pair<int, int>, int> las;
int n;
int main() {
  ios::sync_with_stdio(0), cout.tie(nullptr);
  n = ty();
  t.plant(1, 1, n), f.make(n);
  for (int i = 1; i <= n; i++) {
    int a = ty(), b = ty();
    pair<int, int> ha = pair<int, int>(a, n + b);
    if (!las.count(ha))
      las[ha] = i;
    else
      t.change(1, 1, n, las[ha], i - 1, ha), las.erase(ha);
  }
  for (auto i : las) t.change(1, 1, n, i.second, n, i.first);
  t.make(1, 1, n);
  for (int i = 1; i <= n; i++) cout << ans[i] << " \n"[i == n];
  return 0;
}
