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;
template <typename T1, typename T2>
bool chkmin(T1 &x, T2 y) {
  return y < x ? (x = y, true) : false;
}
template <typename T1, typename T2>
bool chkmax(T1 &x, T2 y) {
  return y > x ? (x = y, true) : false;
}
const int N = 300005;
vector<pair<int, int>> h[4 * N];
namespace dsu {
vector<pair<long long &, long long>> ops;
vector<char> added;
long long cnt[N + N][2];
long long q[N + N];
long long ans;
int ge(int x) { return q[x] == x ? x : ge(q[x]); }
void un(int x, int y) {
  x = ge(x), y = ge(y);
  added.push_back(x != y ? 1 : 0);
  if (x == y) return;
  if (cnt[x][0] + cnt[x][1] > cnt[y][0] + cnt[y][1]) swap(x, y);
  ops.push_back({ans, ans});
  ans += cnt[x][0] * cnt[y][1] + cnt[x][1] * cnt[y][0];
  for (int j = 0; j < 2; ++j) {
    ops.push_back({cnt[y][j], cnt[y][j]});
    cnt[y][j] += cnt[x][j];
  }
  ops.push_back({q[x], q[x]});
  q[x] = y;
}
void backtrack() {
  if (!added.back()) {
    added.pop_back();
    return;
  }
  added.pop_back();
  for (int i = 0; i < 4; ++i) {
    ops.back().first = ops.back().second;
    ops.pop_back();
  }
}
}  // namespace dsu
vector<pair<int, int>> t[4 * N];
void add(int v, int vl, int vr, int l, int r, pair<int, int> p) {
  if (l > r || vr < l || r < vl) return;
  if (l <= vl && vr <= r) {
    t[v].push_back(p);
    return;
  }
  int vm = (vl + vr) >> 1;
  add(v + v, vl, vm, l, r, p);
  add(v + v + 1, vm + 1, vr, l, r, p);
}
void dfs(int v, int vl, int vr) {
  for (auto &p : t[v]) dsu::un(p.first, p.second);
  if (vl == vr)
    cout << dsu::ans << ' ';
  else {
    int vm = (vl + vr) >> 1;
    dfs(v + v, vl, vm);
    dfs(v + v + 1, vm + 1, vr);
  }
  for (int i = 0; i < t[v].size(); ++i) dsu::backtrack();
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 0; i < N + N; ++i) {
    dsu::cnt[i][i >= N] = 1;
    dsu::q[i] = i;
  }
  int Q;
  cin >> Q;
  map<pair<int, int>, vector<int>> ev;
  for (int t = 1; t <= Q; ++t) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    y += N;
    ev[{x, y}].push_back(t);
  }
  for (auto &p : ev) {
    auto &e = p.second;
    for (int i = 0; i < e.size(); i += 2) {
      int l = e[i];
      int r = Q;
      if (i + 1 < e.size()) r = e[i + 1] - 1;
      add(1, 1, Q, l, r, p.first);
    }
  }
  dfs(1, 1, Q);
  cout << '\n';
  return 0;
}