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 N = 6e5 + 10;
int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
int q, r[N], c[N], fa[N];
map<pair<int, int>, int> M;
vector<pair<int, int> > tr[N << 2];
long long ans;
struct opt {
  int x, y, r, c;
  long long ans;
};
vector<opt> vec;
int getf(int x) { return x == fa[x] ? x : getf(fa[x]); }
void merge(int x, int y) {
  x = getf(x);
  y = getf(y);
  if (x == y) return;
  if (r[x] + c[x] > r[y] + c[y]) swap(x, y);
  vec.push_back((opt){x, y, r[y], c[y], ans});
  ans -= 1ll * r[x] * c[x] + 1ll * r[y] * c[y];
  fa[x] = y;
  r[y] += r[x];
  c[y] += c[x];
  ans += 1ll * r[y] * c[y];
}
void undo(int pre) {
  while (int(vec.size()) > pre) {
    auto t = vec.back();
    fa[t.x] = t.x;
    r[t.y] = t.r;
    c[t.y] = t.c;
    ans = t.ans;
    vec.pop_back();
  }
}
void insert(int L, int R, pair<int, int> v, int x = 1, int l = 1, int r = q) {
  if (L <= l && r <= R) {
    tr[x].push_back(make_pair(v.first, v.second + 3e5));
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) insert(L, R, v, (x << 1), l, mid);
  if (R > mid) insert(L, R, v, (x << 1 | 1), mid + 1, r);
}
void dfs(int x = 1, int l = 1, int r = q) {
  int pre = int(vec.size());
  for (auto t : tr[x]) merge(t.first, t.second);
  if (l == r) {
    cout << ans << ' ';
    undo(pre);
    return;
  }
  int mid = (l + r) >> 1;
  dfs((x << 1), l, mid);
  dfs((x << 1 | 1), mid + 1, r);
  undo(pre);
}
int main() {
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int x = gi(), y = gi();
    if (M.count(make_pair(x, y)))
      insert(M[make_pair(x, y)], i - 1, make_pair(x, y)),
          M.erase(make_pair(x, y));
    else
      M[make_pair(x, y)] = i;
  }
  for (auto x : M) insert(x.second, q, x.first);
  for (int i = 1; i <= 6e5; i++) fa[i] = i, r[i] = (i <= 3e5), c[i] = (i > 3e5);
  dfs();
  return 0;
}
