Problem: 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 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 6e5 + 5;
struct DELNode {
  int u, dep, sz1, sz2;
  DELNode(int u = 0, int dep = 0, int sz1 = 0, int sz2 = 0)
      : u(u), dep(dep), sz1(sz1), sz2(sz2) {}
};
int fa[maxn], siz[maxn][2], dep[maxn];
vector<int> wife[maxn << 2];
struct edge {
  int u, v, l, r;
} e[maxn];
int ecnt, n, mx1, mx2;
long long ans;
map<pair<int, int>, int> mp;
stack<DELNode> st;
template <typename T>
inline void read(T &x) {
  char c;
  int f = 1;
  while (!isdigit(c = getchar())) (c == '-') && (f = -1);
  x = c ^ 48;
  while (isdigit(c = getchar())) x = x * 10 + (c ^ 48);
  x *= f;
}
inline int findf(int x) {
  while (x != fa[x]) x = fa[x];
  return x;
}
inline void merge(int u, int v) {
  if (u == v) return;
  if (dep[u] > dep[v]) swap(u, v);
  st.push(DELNode(u, dep[u] == dep[v], siz[u][0], siz[u][1]));
  ans = ans - 1ll * siz[v][0] * siz[v][1] - 1ll * siz[u][0] * siz[u][1];
  fa[u] = v;
  siz[v][0] += siz[u][0];
  siz[v][1] += siz[u][1];
  dep[v] += (dep[u] == dep[v]);
  ans = ans + 1ll * siz[v][0] * siz[v][1];
}
void modify(int u, int l, int r, int x, int y, int id) {
  if (x <= l && r <= y) return void(wife[u].push_back(id));
  int mid = (l + r) >> 1;
  if (x <= mid) modify(u << 1, l, mid, x, y, id);
  if (y > mid) modify(u << 1 | 1, mid + 1, r, x, y, id);
}
void solve(int u, int l, int r) {
  int nowsiz = st.size();
  for (const auto &i : wife[u]) merge(findf(e[i].u), findf(e[i].v + mx1));
  if (l == r)
    printf("%lld ", ans);
  else {
    int mid = (l + r) >> 1;
    solve(u << 1, l, mid);
    solve(u << 1 | 1, mid + 1, r);
  }
  while (st.size() > nowsiz) {
    DELNode x = st.top();
    ans = ans - 1ll * siz[fa[x.u]][0] * siz[fa[x.u]][1];
    dep[fa[x.u]] -= x.dep;
    siz[fa[x.u]][0] -= x.sz1;
    siz[fa[x.u]][1] -= x.sz2;
    ans = ans + 1ll * siz[fa[x.u]][0] * siz[fa[x.u]][1] +
          1ll * siz[x.u][0] * siz[x.u][1];
    fa[x.u] = x.u;
    st.pop();
  }
}
int main() {
  int u, v, m;
  read(m);
  for (int i = 1; i <= m; ++i) {
    read(u);
    read(v);
    mx1 = max(mx1, u);
    mx2 = max(mx2, v);
    if (mp.find(make_pair(u, v)) == mp.end()) {
      mp[make_pair(u, v)] = ++ecnt;
      e[ecnt].u = u;
      e[ecnt].v = v;
      e[ecnt].l = i;
      e[ecnt].r = m;
    } else
      e[mp[make_pair(u, v)]].r = i - 1, mp.erase(make_pair(u, v));
  }
  for (int i = 1; i <= mx1; ++i) fa[i] = i, siz[i][0] = 1;
  for (int i = mx1 + 1; i <= mx1 + mx2; ++i) fa[i] = i, siz[i][1] = 1;
  for (int i = 1; i <= ecnt; ++i) modify(1, 1, m, e[i].l, e[i].r, i);
  solve(1, 1, m);
  return 0;
}