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 MAXVAL = (int)3e5;
struct DSU {
  int par[2 * MAXVAL + 1], szx[2 * MAXVAL + 1], szy[2 * MAXVAL + 1];
  stack<int> stk;
  long long ans;
  inline void init() {
    ans = 0;
    for (int i = 1; i <= 2 * MAXVAL; i++) {
      szx[i] = szy[i] = par[i] = 0;
    }
    for (int i = 1; i <= MAXVAL; i++) {
      szx[i] = szy[i + MAXVAL] = 1;
    }
  }
  int root(int x) {
    if (par[x] == 0) return x;
    return root(par[x]);
  }
  inline void join(int a, int b) {
    b += MAXVAL;
    a = root(a), b = root(b);
    if (szx[a] + szy[a] > szx[b] + szy[b]) {
      swap(a, b);
    }
    if (a != b) {
      par[a] = b;
      ans -= 1LL * szx[a] * szy[a] + 1LL * szx[b] * szy[b];
      szx[b] += szx[a];
      szy[b] += szy[a];
      ans += 1LL * szx[b] * szy[b];
      stk.push(a);
    } else {
      stk.push(-1);
    }
  }
  inline void undo() {
    if (stk.top() != -1) {
      int a = stk.top();
      int b = par[a];
      ans -= 1LL * szx[b] * szy[b];
      szx[b] -= szx[a];
      szy[b] -= szy[a];
      ans += 1LL * szx[a] * szy[a] + 1LL * szx[b] * szy[b];
      par[a] = 0;
    }
    stk.pop();
  }
} dsu;
const int MAXQ = (int)3e5;
vector<int> aint[4 * MAXQ + 1];
int x[MAXQ + 1], y[MAXQ + 1];
void update(int nod, int left, int right, int l, int r, int id) {
  if (l <= left && right <= r) {
    aint[nod].push_back(id);
  } else {
    int mid = (left + right) / 2;
    if (l <= mid) update(2 * nod, left, mid, l, r, id);
    if (mid < r) update(2 * nod + 1, mid + 1, right, l, r, id);
  }
}
long long sol[MAXQ + 1];
void solve(int nod, int left, int right) {
  for (auto it : aint[nod]) {
    dsu.join(x[it], y[it]);
  }
  if (left == right) {
    sol[left] = dsu.ans;
  } else {
    int mid = (left + right) / 2;
    solve(2 * nod, left, mid);
    solve(2 * nod + 1, mid + 1, right);
  }
  for (auto it : aint[nod]) {
    dsu.undo();
  }
}
int main() {
  int i, q;
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> q;
  map<pair<int, int>, int> mp;
  vector<int> pos(q + 1);
  for (i = 1; i <= q; i++) {
    cin >> x[i] >> y[i];
    if (mp[{x[i], y[i]}]) {
      pos[mp[{x[i], y[i]}]] = i - 1;
      mp[{x[i], y[i]}] = 0;
      pos[i] = -1;
    } else {
      mp[{x[i], y[i]}] = i;
    }
  }
  for (i = 1; i <= q; i++) {
    if (pos[i] == 0) {
      pos[i] = q;
    }
    if (pos[i] != -1) {
      update(1, 1, q, i, pos[i], i);
    }
  }
  dsu.init();
  solve(1, 1, q);
  for (i = 1; i <= q; i++) {
    cout << sol[i] << " ";
  }
  return 0;
}
