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;
inline int read() {
  int x = 0;
  bool t = false;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') t = true, ch = getchar();
  while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
  return t ? -x : x;
}
int f[300300 << 1], sz[300300 << 1], szx[300300 << 1], szy[300300 << 1];
int getf(int x) { return x == f[x] ? x : getf(f[x]); }
pair<int, int> St[300300];
int top;
long long ans;
long long Calc(int x) { return 1ll * szx[x] * szy[x]; }
void Merge(int x, int y) {
  x = getf(x);
  y = getf(y);
  if (x == y) return;
  if (sz[x] < sz[y]) swap(x, y);
  ans -= Calc(x) + Calc(y);
  f[y] = x;
  sz[x] += sz[y];
  szx[x] += szx[y];
  szy[x] += szy[y];
  ans += Calc(x);
  St[++top] = make_pair(x, y);
}
void undo(int x, int y) {
  ans -= Calc(x);
  f[y] = y;
  sz[x] -= sz[y];
  szx[x] -= szx[y];
  szy[x] -= szy[y];
  ans += Calc(x);
  ans += Calc(y);
}
int n;
map<pair<int, int>, int> M;
vector<pair<int, int> > t[300300 << 2];
void Modify(int now, int l, int r, int L, int R, pair<int, int> w) {
  if (L <= l && r <= R) {
    t[now].push_back(w);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) Modify((now << 1), l, mid, L, R, w);
  if (R > mid) Modify((now << 1 | 1), mid + 1, r, L, R, w);
}
void Divide(int now, int l, int r) {
  int ntop = top;
  for (pair<int, int> u : t[now]) Merge(u.first, u.second);
  if (l == r)
    printf("%lld ", ans);
  else {
    int mid = (l + r) >> 1;
    Divide((now << 1), l, mid);
    Divide((now << 1 | 1), mid + 1, r);
  }
  while (top > ntop) undo(St[top].first, St[top].second), --top;
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    int x = read(), y = read() + 300300;
    pair<int, int> w = make_pair(x, y);
    f[x] = x;
    sz[x] = szx[x] = 1;
    f[y] = y;
    sz[y] = szy[y] = 1;
    if (!M[w])
      M[w] = i;
    else
      Modify(1, 1, n, M[w], i - 1, w), M[w] = 0;
  }
  for (auto u : M)
    if (M[u.first]) Modify(1, 1, n, M[u.first], n, u.first);
  Divide(1, 1, n);
  return 0;
}
