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 w = 1, s = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return w * s;
}
int Q, sz1[1000100], sz2[1001001], fa[1001000];
vector<pair<int, int> > vec[2000010];
pair<int, int> tmp[300100];
map<pair<int, int>, int> mp;
inline int find(int x) {
  if (fa[x] == x) return x;
  return find(fa[x]);
}
inline void Modify(int now, int l, int r, int x, int y, pair<int, int> t) {
  if (x <= l && r <= y) {
    vec[now].push_back(t);
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid) Modify(now << 1, l, mid, x, y, t);
  if (y > mid) Modify(now << 1 | 1, mid + 1, r, x, y, t);
}
long long Ans = 0;
pair<int, int> Sta[1000100];
int top = 0;
inline void Solve(int now, int l, int r) {
  int sz = vec[now].size();
  int tot = 0;
  for (register int i = 0; i < sz; ++i) {
    pair<int, int> tmp = vec[now][i];
    int x = find(tmp.first);
    int y = find(tmp.second + 300000);
    if (x != y) {
      ++tot;
      Ans -= 1ll * sz1[x] * sz2[x];
      Ans -= 1ll * sz1[y] * sz2[y];
      if (sz1[x] + sz2[x] < sz1[y] + sz2[y]) {
        fa[x] = y;
        sz1[y] += sz1[x];
        sz2[y] += sz2[x];
        Ans += 1ll * sz1[y] * sz2[y];
        Sta[++top] = make_pair(y, x);
      } else {
        fa[y] = x;
        sz1[x] += sz1[y];
        sz2[x] += sz2[y];
        Ans += 1ll * sz1[x] * sz2[x];
        Sta[++top] = make_pair(x, y);
      }
    }
  }
  if (l == r) {
    cout << Ans << " ";
    for (register int i = 1; i <= tot; ++i) {
      int x = Sta[top].first, y = Sta[top].second;
      fa[y] = y;
      Ans -= 1ll * sz1[x] * sz2[x];
      sz1[x] -= sz1[y];
      sz2[x] -= sz2[y];
      Ans += 1ll * sz1[x] * sz2[x];
      Ans += 1ll * sz1[y] * sz2[y];
      top--;
    }
    return;
  }
  int mid = (l + r) >> 1;
  Solve(now << 1, l, mid);
  Solve(now << 1 | 1, mid + 1, r);
  for (register int i = 1; i <= tot; ++i) {
    int x = Sta[top].first, y = Sta[top].second;
    fa[y] = y;
    Ans -= 1ll * sz1[x] * sz2[x];
    sz1[x] -= sz1[y];
    sz2[x] -= sz2[y];
    Ans += 1ll * sz1[x] * sz2[x];
    Ans += 1ll * sz1[y] * sz2[y];
    top--;
  }
}
int main() {
  Q = read();
  for (register int i = 1; i <= 300000 << 1; ++i)
    fa[i] = i, (i <= 300000) ? (sz1[i] = 1) : (sz2[i] = 1);
  for (register int i = 1; i <= Q; ++i) {
    int x = read(), y = read();
    tmp[i] = make_pair(x, y);
    if (mp[make_pair(x, y)]) {
      Modify(1, 1, Q, mp[make_pair(x, y)], i - 1, make_pair(x, y));
      mp[make_pair(x, y)] = 0;
    } else
      mp[make_pair(x, y)] = i;
  }
  for (register int i = 1; i <= Q; ++i)
    if (mp[tmp[i]]) Modify(1, 1, Q, mp[tmp[i]], Q, tmp[i]), mp[tmp[i]] = 0;
  Solve(1, 1, Q);
  return 0;
}
