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 <class T>
inline void chkmin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline void chkmax(T &a, T b) {
  if (a < b) a = b;
}
inline int read() {
  int s = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') ch = getchar(), f = -1;
  while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar();
  return ~f ? s : -s;
}
const int maxn = 3e5 + 20;
vector<pair<int, int> > c[(1 << 20) + 20];
int n;
map<pair<int, int>, int> mp;
void update(int ql, int qr, pair<int, int> x, int o, int l, int r) {
  if (ql <= l && r <= qr) return c[o].push_back(x), void();
  int mid = l + r >> 1;
  if (ql <= mid) update(ql, qr, x, (o << 1), l, mid);
  if (qr > mid) update(ql, qr, x, (o << 1 | 1), mid + 1, r);
}
inline void init() {
  n = read();
  for (int i = (1), _end_ = (n); i <= _end_; i++) {
    int x = read(), y = read();
    int id = mp[make_pair(x, y)];
    if (id == 0)
      mp[make_pair(x, y)] = i;
    else
      update(mp[make_pair(x, y)], i - 1, make_pair(x, y), 1, 1, n),
          mp[make_pair(x, y)] = 0;
  }
  for (pair<pair<int, int>, int> x : mp)
    if (x.second) update(x.second, n, x.first, 1, 1, n);
}
int fa[maxn << 1], szl[maxn << 1], szr[maxn << 1], dep[maxn << 1];
int stx[maxn << 1], sty[maxn << 1], Dep[maxn << 1], top;
long long ans;
inline int fin(int x) {
  while (x != fa[x]) x = fa[x];
  return x;
}
inline void merge(int x, int y) {
  y += 3e5;
  x = fin(x);
  y = fin(y);
  if (dep[x] < dep[y]) swap(x, y);
  stx[++top] = x;
  sty[top] = y;
  Dep[x] = dep[x];
  if (x == y) return;
  ans -= 1ll * szl[x] * szr[x] + 1ll * szl[y] * szr[y];
  szl[x] += szl[y];
  szr[x] += szr[y];
  fa[y] = x;
  chkmax(dep[x], dep[y] + 1);
  ans += 1ll * szl[x] * szr[x];
}
inline void undo() {
  int x = stx[top], y = sty[top], DEEP = Dep[top--];
  if (x == y) return;
  ans -= 1ll * szl[x] * szr[x];
  szl[x] -= szl[y];
  szr[x] -= szr[y];
  fa[y] = y;
  dep[x] = DEEP;
  ans += 1ll * szl[x] * szr[x] + 1ll * szl[y] * szr[y];
}
void dfs(int o, int l, int r) {
  for (pair<int, int> x : c[o]) merge(x.first, x.second);
  int mid = l + r >> 1;
  if (l == r)
    printf("%lld ", ans);
  else
    dfs((o << 1), l, mid), dfs((o << 1 | 1), mid + 1, r);
  for (pair<int, int> x : c[o]) undo();
}
inline void doing() {
  for (int i = (1), _end_ = (3e5); i <= _end_; i++) fa[i] = i, szl[i] = 1;
  for (int i = (3e5 + 1), _end_ = (3e5 + 3e5); i <= _end_; i++)
    fa[i] = i, szr[i] = 1;
  dfs(1, 1, n);
}
int main() {
  init();
  doing();
  return 0;
}
