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;
const int oo = 2139063143;
const int N = 1010000;
const int P = 1000000007;
const double eps = 1e-7;
template <typename T>
inline void sc(T &x) {
  x = 0;
  static int p;
  p = 1;
  static char c;
  c = getchar();
  while (!isdigit(c)) {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c - 48);
    c = getchar();
  }
  x *= p;
}
template <typename T>
inline void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
inline void pr(T x) {
  print(x), putchar(' ');
}
template <typename T1, typename T2>
void chkmax(T1 &A, T2 B) {
  A = A >= B ? A : B;
}
template <typename T1, typename T2>
void chkmin(T1 &A, T2 B) {
  A = A <= B ? A : B;
}
struct UNION {
  int fa[N], a[N], b[N];
  long long sum;
  int getf(int x) { return fa[x] == x ? x : getf(fa[x]); }
  void init() {
    for (int i = 1; i <= 3e5; i++) a[i] = 1, fa[i] = i;
    for (int i = 3e5 + 1; i <= 6e5; i++) b[i] = 1, fa[i] = i;
  }
  struct BACK {
    int x, y, ax, ay, bx, by;
  } st[N];
  int z = 0;
  void back(int las) {
    while (z > las) {
      int x = st[z].x, y = st[z].y;
      sum -= (long long)a[x] * b[x];
      fa[x] = x, fa[y] = y;
      a[x] = st[z].ax, a[y] = st[z].ay;
      b[x] = st[z].bx, b[y] = st[z].by;
      sum += (long long)a[x] * b[x] + (long long)a[y] * b[y];
      --z;
    }
  }
  void merge(int x, int y) {
    x = getf(x), y = getf(y);
    if (x != y) {
      if (a[x] + b[x] < a[y] + b[y]) swap(x, y);
      st[++z] = (BACK){x, y, a[x], a[y], b[x], b[y]};
      sum -= (long long)a[x] * b[x] + (long long)a[y] * b[y];
      fa[y] = x, a[x] += a[y], b[x] += b[y];
      sum += (long long)a[x] * b[x];
    }
  }
} U;
pair<int, int> x[N];
vector<int> G[N << 2];
void ins(int p, int l, int r, int L, int R, int i) {
  if (L <= l && r <= R) return G[p].push_back(i), void();
  int mid = (l + r) >> 1, ls = p << 1, rs = ls | 1;
  if (L <= mid) ins(ls, l, mid, L, R, i);
  if (R > mid) ins(rs, mid + 1, r, L, R, i);
}
long long ans[N];
void solve(int p, int l, int r) {
  int las = U.z;
  for (int i : G[p]) U.merge(x[i].first, x[i].second + 300000);
  if (l == r)
    pr(U.sum);
  else {
    int mid = (l + r) >> 1, ls = p << 1, rs = ls | 1;
    solve(ls, l, mid);
    solve(rs, mid + 1, r);
  }
  U.back(las);
}
map<pair<int, int>, int> id;
int las[N];
int main() {
  int n = 0, m;
  sc(m);
  for (int i = 1; i <= m; i++) {
    sc(x[i].first), sc(x[i].second);
    int g = id[x[i]];
    if (las[g])
      ins(1, 1, m, las[g], i - 1, i), las[g] = 0;
    else {
      if (!g) g = id[x[i]] = ++n;
      las[g] = i;
    }
  }
  for (int i = 1; i <= m; i++) {
    int g = id[x[i]];
    if (las[g]) ins(1, 1, m, las[g], m, i), las[g] = 0;
  }
  U.init();
  solve(1, 1, m);
  return 0;
}
