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>
#pragma GCC optimize(3)
#pragma GCC optimize(2)
using namespace std;
struct qrs {
  int y, fa, fb, tp;
};
long long ans[300011];
vector<int> sz[300011];
vector<int> f[300011];
vector<int> height[300011];
vector<int> xcoord[300011];
vector<pair<int, int>> tree[300011 << 2];
vector<qrs> history;
int Q;
map<int, int> mp[300011];
long long curr = 0;
void preprocess() {
  int i;
  for (i = 0; i < 300011; ++i) {
    f[i].push_back(i);
    sz[i].push_back(1);
    height[i].push_back(0);
  }
}
int find(int x) {
  if (f[x].back() == x) return x;
  return find(f[x].back());
}
void cancelpre() {
  if (history.empty()) return;
  auto q = history.back();
  history.pop_back();
  if (q.tp == 0) {
    curr -= sz[q.fa].back();
    height[q.fa].pop_back();
    xcoord[q.y].pop_back();
  } else if (q.tp == 1) {
    xcoord[q.y].pop_back();
  } else {
    curr -= 1ll * sz[q.fb].back() * height[q.fb].back();
    sz[q.fb].pop_back();
    height[q.fb].pop_back();
    xcoord[q.y].pop_back();
    f[q.fa].pop_back();
    curr += 1ll * sz[q.fa].back() * height[q.fa].back();
    curr += 1ll * sz[q.fb].back() * height[q.fb].back();
  }
}
void addpoint(int x, int y) {
  int fx = find(x);
  if (xcoord[y].empty()) {
    height[fx].push_back(height[fx].back() + 1);
    xcoord[y].push_back(x);
    history.push_back(qrs{y, fx, fx, 0});
    curr += sz[fx].back();
    return;
  }
  int fy = find(xcoord[y].back());
  if (fx == fy) {
    xcoord[y].push_back(x);
    history.push_back(qrs{y, fx, fx, 1});
    return;
  }
  xcoord[y].push_back(x);
  int sz1 = sz[fx].back(), sz2 = sz[fy].back();
  curr -= 1ll * sz1 * height[fx].back();
  curr -= 1ll * sz2 * height[fy].back();
  if (sz1 > sz2) {
    sz[fx].push_back(sz1 + sz2);
    f[fy].push_back(fx);
    height[fx].push_back(height[fx].back() + height[fy].back());
    curr += 1ll * (sz1 + sz2) * height[fx].back();
    history.push_back(qrs{y, fy, fx, 2});
  } else {
    sz[fy].push_back(sz1 + sz2);
    f[fx].push_back(fy);
    height[fy].push_back(height[fx].back() + height[fy].back());
    curr += 1ll * (sz1 + sz2) * height[fy].back();
    history.push_back(qrs{y, fx, fy, 2});
  }
}
void update(int start, int end, int l, int r, int index, int x, int y) {
  if (start > end || l > end || start > r || l > r) return;
  if (start <= l && r <= end) {
    tree[index].emplace_back(x, y);
    return;
  }
  if (end <= ((l + r) >> 1)) {
    update(start, end, l, ((l + r) >> 1), (index << 1), x, y);
  } else if (start >= ((l + r) >> 1) + 1) {
    update(start, end, ((l + r) >> 1) + 1, r, (index << 1 | 1), x, y);
  } else {
    update(start, end, l, ((l + r) >> 1), (index << 1), x, y);
    update(start, end, ((l + r) >> 1) + 1, r, (index << 1 | 1), x, y);
  }
}
void dfs(int l, int r, int index) {
  int i;
  if (l > r) return;
  for (auto p : tree[index]) {
    addpoint(p.first, p.second);
  }
  if (l == r) {
    ans[l] = curr;
    for (i = 0; i < (int)tree[index].size(); ++i) {
      cancelpre();
    }
    return;
  }
  dfs(l, ((l + r) >> 1), (index << 1));
  dfs(((l + r) >> 1) + 1, r, (index << 1 | 1));
  for (i = 0; i < (int)tree[index].size(); ++i) {
    cancelpre();
  }
}
int main() {
  int i;
  scanf("%d", &Q);
  preprocess();
  for (i = 1; i <= Q; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    int z = mp[x][y];
    if (z != 0) {
      mp[x].erase(y);
      update(z, i - 1, 1, Q, 1, x, y);
    } else {
      mp[x][y] = i;
    }
  }
  for (i = 1; i < 300011; ++i) {
    if (mp[i].empty()) continue;
    auto iter = mp[i].begin();
    while (iter != mp[i].end()) {
      if (iter->second != 0) {
        update(iter->second, Q, 1, Q, 1, i, iter->first);
      }
      iter++;
    }
  }
  dfs(1, Q, 1);
  for (i = 1; i <= Q; ++i) {
    printf("%I64d ", ans[i]);
  }
  printf("\n");
  return 0;
}
