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 sz = 300300;
int val[2][sz * 2];
int p[sz * 2];
vector<pair<int&, int> > edges;
vector<pair<int, int> > t[sz << 2];
vector<long long> request;
long long ans = 0;
int get(int v) { return (v == p[v] ? v : get(p[v])); }
void add(int x, int y) {
  x = get(x);
  y = get(y);
  if (x == y) {
    request.push_back(-1);
    return;
  }
  if (val[1][x] + val[0][x] > val[1][y] + val[0][y]) {
    swap(x, y);
  }
  edges.push_back({p[x], p[x]});
  p[x] = y;
  request.push_back(val[1][x] * 1LL * val[0][y] + val[0][x] * 1LL * val[1][y]);
  ans += request.back();
  for (int i = 0; i < 2; i++) {
    edges.push_back({val[i][y], val[i][y]});
    val[i][y] += val[i][x];
  }
}
void chill() {
  if (request.back() == -1) {
    request.pop_back();
    return;
  } else {
    ans -= request.back();
    request.pop_back();
    for (int i = 0; i < 3; i++) {
      edges.back().first = edges.back().second;
      edges.pop_back();
    }
  }
}
void upd(int v, int l, int r, int tl, int tr, pair<int, int> p) {
  if (tl >= r || tr <= l) return;
  if (tl >= l && tr <= r) {
    t[v].push_back(p);
  } else {
    int tm = (tl + tr) / 2;
    upd(v * 2 + 1, l, r, tl, tm, p);
    upd(v * 2 + 2, l, r, tm, tr, p);
  }
}
void build(int v, int tl, int tr) {
  for (auto [x, y] : t[v]) {
    add(x, y);
  }
  if (tl + 1 == tr) {
    cout << ans << " ";
  } else {
    int tm = (tl + tr) / 2;
    build(v * 2 + 1, tl, tm);
    build(v * 2 + 2, tm, tr);
  }
  for (auto pt : t[v]) {
    chill();
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  memset(val, 0, sizeof val);
  for (int i = 0; i < sz * 2; i++) {
    val[i < sz][i] = 1;
    p[i] = i;
  }
  map<pair<int, int>, vector<int> > query;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    y += sz;
    query[make_pair(x, y)].push_back(i);
  }
  for (auto [pt, ind] : query) {
    for (int i = 0; i < ind.size(); i += 2) {
      int l = ind[i];
      int r = q;
      if (i < ind.size() - 1) {
        r = ind[i + 1];
      }
      upd(0, l, r, 0, q, pt);
    }
  }
  build(0, 0, q);
  return 0;
}
