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>
long long gi() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
std::mt19937 rnd(time(NULL));
template <class T>
void cxk(T& a, T b) {
  a = a > b ? a : b;
}
template <class T>
void cnk(T& a, T b) {
  a = a < b ? a : b;
}
std::map<std::pair<int, int>, int> st;
int px[300010], py[300010], ps[300010], pt[300010];
int fa[600010], siz[600010], sl[600010], sr[600010];
long long ans[300010], now;
int hd(int x) {
  while (fa[x] ^ x) x = fa[x];
  return x;
}
std::stack<int> stk;
std::vector<int> seg[1048589];
void update(int x, int l, int r, int L, int R, int p) {
  if (L <= l && r <= R) return seg[x].push_back(p);
  if (L <= ((l + r) >> 1)) update(x << 1, l, ((l + r) >> 1), L, R, p);
  if (((l + r) >> 1) < R) update(x << 1 | 1, ((l + r) >> 1) + 1, r, L, R, p);
}
bool Union(int x, int y) {
  x = hd(x), y = hd(y);
  if (x == y) return 0;
  if (siz[x] > siz[y]) std::swap(x, y);
  fa[x] = y;
  now += 1ll * sl[x] * sr[y] + 1ll * sr[x] * sl[y];
  siz[y] += siz[x];
  sl[y] += sl[x], sr[y] += sr[x];
  stk.push(x);
  return 1;
}
void Pop() {
  int x = stk.top();
  stk.pop();
  siz[fa[x]] -= siz[x], sl[fa[x]] -= sl[x], sr[fa[x]] -= sr[x],
      now -= 1ll * sl[x] * sr[fa[x]] + 1ll * sr[x] * sl[fa[x]];
  fa[x] = x;
}
void divide(int x, int l, int r) {
  int sum = 0;
  for (int i : seg[x]) sum += Union(px[i], py[i]);
  if (l == r)
    ans[l] = now;
  else
    divide(x << 1, l, ((l + r) >> 1)),
        divide(x << 1 | 1, ((l + r) >> 1) + 1, r);
  while (sum--) Pop();
}
int main() {
  int n = 300000, q = gi(), x, y, m = 0;
  for (int i = 1; i <= n + n; ++i)
    fa[i] = i, siz[i] = 1, sl[i] = i <= n, sr[i] = i > n;
  for (int i = 1; i <= q; ++i) {
    x = gi(), y = gi() + n;
    if (st.find({x, y}) == st.end())
      ps[++m] = i, px[m] = x, py[m] = y, st[{x, y}] = m;
    else
      pt[st[{x, y}]] = i - 1, st.erase({x, y});
  }
  for (auto s : st) pt[s.second] = q;
  for (int i = 1; i <= m; ++i) update(1, 1, q, ps[i], pt[i], i);
  divide(1, 1, q);
  for (int i = 1; i <= q; ++i) printf("%lld ", ans[i]);
  return 0;
}