malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 100005;   const long long INF = 1000000000;   struct edge {     long long a, b, cap, flow;   };   long long n, s, t, d[MAXN], ptr[MAXN], q[MAXN];   vector<edge> e;   vector<long long> g[MAXN];   void add_edge(long long a, long long b, long long cap) {     edge e1 = {a, b, cap, 0};     edge e2 = {b, a, 0, 0};     g[a].push_back((long long)e.size());     e.push_back(e1);     g[b].push_back((long long)e.size());     e.push_back(e2);   }   bool bfs() {     long long qh = 0, qt = 0;     q[qt++] = s;     memset(d, -1, n * sizeof d[0]);     d[s] = 0;     while (qh < qt && d[t] == -1) {       long long v = q[qh++];       for (size_t i = 0; i < g[v].size(); ++i) {         long long id = g[v][i], to = e[id].b;         if (d[to] == -1 && e[id].flow < e[id].cap) {           q[qt++] = to;           d[to] = d[v] + 1;         }       }     }     return d[t] != -1;   }   long long dfs(long long v, long long flow) {     if (!flow) return 0;     if (v == t) return flow;     for (; ptr[v] < (long long)g[v].size(); ++ptr[v]) {       long long id = g[v][ptr[v]], to = e[id].b;       if (d[to] != d[v] + 1) continue;       long long pushed = dfs(to, min(flow, e[id].cap - e[id].flow));       if (pushed) {         e[id].flow += pushed;         e[id ^ 1].flow -= pushed;         return pushed;       }     }     return 0;   }   long long dinic() {     long long flow = 0;     for (;;) {       if (!bfs()) break;       memset(ptr, 0, n * sizeof ptr[0]);       while (long long pushed = dfs(s, INF)) flow += pushed;     }     return flow;   }   vector<long long> ext[5005];   long long pt[5005], club[5005], pre[5005], add[5005], lev[5005];   int main() {     long long std, m, d;     scanf( %lld %lld , &std, &m);     for (int i = 1; i < std + 1; i++) scanf( %lld , &pt[i]);     for (int i = 1; i < std + 1; i++) scanf( %lld , &club[i]);     scanf( %lld , &d);     for (int i = 0; i < d; i++) {       scanf( %lld , &add[i]);       lev[add[i]] = 1;     }     for (int i = 0; i < m; i++) add_edge(0, i + 1, 1);     for (int i = 0; i < 5000; i++) add_edge(m + 1 + i, 5000 + m, 1);     s = 0, t = 5000 + m, n = 5000 + m + 1;     vector<long long> pp;     long long start = 0;     for (int i = 1; i < std + 1; i++) {       if (!lev[i]) {         if (pt[i] > 0)           ext[pt[i]].push_back(i);         else           add_edge(club[i], m + 1 + pt[i], 1);       }     }     for (int i = d - 1; i >= 0; i--) {       while (1) {         bool ok = true;         if (!dinic()) ok = false;         if (!ok) break;         start++;         for (int j = 0; j < ext[start].size(); j++) {           long long ss = ext[start][j];           add_edge(club[ss], m + 1 + pt[ss], 1);         }       }       if (pt[add[i]] > start)         ext[pt[add[i]]].push_back(add[i]);       else         add_edge(club[add[i]], m + 1 + pt[add[i]], 1);       pp.push_back(start);     }     reverse(pp.begin(), pp.end());     for (int i = 0; i < pp.size(); i++) cout << pp[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e15;   long long l, r;   void Input() { cin >> l >> r; }   void Solve() {     if (r <= 10) {       long long Res = 0;       for (long long a = l; a <= r; ++a) {         for (long long b = l; b <= a; ++b) Res = max(Res, a % b);       }       cout << Res;     } else {       long long m = max(r / 2 + 1, l);       cout << max(r % l, r % m);     }     cout <<   n ;   }   int main() {     if (fopen( trash.inp ,  r ))       freopen( trash.inp ,  r , stdin), freopen( trash.out ,  w , stdout);     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int Test;     cin >> Test;     while (Test--) {       Input();       Solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int i, cnt = 0;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  x  && s[i + 1] ==  x  && s[i + 2] ==  x  && i < n - 2) cnt++;     }     cout << cnt << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int BLOCK = 316;   const int N = 100100;   vector<int> vc, g[N];   int col[N], l[N], r[N], nm[N], kol[N], ans[N], sum[N];   int tin[N], tout[N], n, q, kl[N];   void dfs(int v, int p) {     tin[v] = ((int)vc.size());     vc.push_back(v);     for (int u : g[v]) {       if (u == p) continue;       dfs(u, v);     }     tout[v] = ((int)vc.size()) - 1;   }   bool cmp(int x, int y) {     int lx = l[x] / BLOCK;     int ly = l[y] / BLOCK;     if (lx == ly) {       if (lx & 1)         return r[x] > r[y];       else         return r[x] < r[y];     } else       return lx < ly;   }   void add(int ps) {     int cur = col[vc[ps]];     kol[cur]++;     sum[kol[cur]]++;   }   void del(int ps) {     int cur = col[vc[ps]];     sum[kol[cur]]--;     kol[cur]--;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> q;     for (int i = 0; i < n; i++) cin >> col[i];     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       g[x].push_back(y);       g[y].push_back(x);     }     dfs(0, -1);     for (int i = 0; i < q; i++) {       int v;       cin >> v >> kl[i];       v--;       l[i] = tin[v];       r[i] = tout[v];       nm[i] = i;     }     sort(nm, nm + q, cmp);     int lf = 0, rt = -1;     for (int it = 0; it < q; it++) {       int i = nm[it];       while (lf < l[i]) del(lf++);       while (rt < r[i]) add(++rt);       while (lf > l[i]) add(--lf);       while (rt > r[i]) del(rt--);       ans[i] = sum[kl[i]];     }     for (int i = 0; i < q; i++) cout << ans[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int f[10001];   int main() {     int a, b = -99999, c = 0;     cin >> a;     for (int i = 1; i <= a; i++) cin >> f[i];     for (int i = 1; i <= a; i++) b = max(b, f[i]);     for (int i = 1; i <= a; i++) c += (b - f[i]);     cout << c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = (int)1e9, MAXN = (int)1e3;   const long long ooll = 1000000000000000000ll;   int weight[MAXN][MAXN], length[MAXN][MAXN], ride[MAXN], cost[MAXN], n, m, first,       last;   vector<vector<int> > graph;   int temp[MAXN];   void calculate(int v) {     memset(temp, 0, sizeof temp);     set<pair<int, int> > s;     s.insert(make_pair(0, v));     temp[v] = -1;     while (!s.empty()) {       int r = s.begin()->first;       int u = s.begin()->second;       weight[v][u] = cost[v];       for (int i = 0; i < (graph[u].size()); i++) {         int node = graph[u][i];         if (r + length[u][node] <= ride[v]) {           if (!temp[node]) {             temp[node] = r + length[u][node];             s.insert(make_pair(temp[node], node));           } else if (temp[node] > r + length[u][node]) {             s.erase(s.find(make_pair(temp[node], node)));             temp[node] = r + length[u][node];             s.insert(make_pair(temp[node], node));           }         }       }       s.erase(make_pair(r, u));     }     weight[v][v] = 0;   }   long long ans[MAXN];   void dijkstra() {     set<pair<long long, int> > s;     for (int i = 0; i < (n); i++) ans[i] = ooll, s.insert(make_pair(ooll, i));     ans[first] = 0;     s.erase(make_pair(ooll, first));     s.insert(make_pair(0, first));     while (!s.empty()) {       long long r = s.begin()->first;       if (r == ooll) break;       int u = s.begin()->second;       for (int i = 0; i < (graph[u].size()); i++) {         int node = graph[u][i];         if (ans[node] > r + weight[u][node]) {           s.erase(s.find(make_pair(ans[node], node)));           ans[node] = r + weight[u][node];           s.insert(make_pair(ans[node], node));         }       }       s.erase(make_pair(r, u));     }   }   int main() {     cin >> n >> m >> first >> last;     first--, last--;     graph = vector<vector<int> >(n);     int x, y, z;     for (int i = 0; i < (m); i++) {       cin >> x >> y >> z;       x--, y--;       if (!length[x][y])         graph[x].push_back(y), graph[y].push_back(x),             length[x][y] = length[y][x] = z;       else         length[x][y] = length[y][x] = min(length[x][y], z);     }     for (int i = 0; i < (n); i++) cin >> ride[i] >> cost[i];     for (int i = 0; i < (n); i++) calculate(i);     graph = vector<vector<int> >(n);     for (int i = 0; i < (n); i++)       for (int j = 0; j < (n); j++)         if (weight[i][j]) graph[i].push_back(j);     dijkstra();     if (ans[last] == ooll)       cout <<  -1  << endl;     else       cout << ans[last] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   int a[N], mx[N], ans[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<pair<int, int> > vec;     for (int i = 1; i <= n; i++) {       cin >> a[i];       vec.emplace_back(a[i], i);     }     memset(mx, 0, sizeof(mx));     sort(vec.begin(), vec.end());     ans[n - 1] = vec.back().first;     while (!vec.empty()) {       int i = vec.back().second;       vec.pop_back();       int len = min(i - 1, n - i);       mx[len] = max(mx[len], a[i]);     }     for (int i = n - 1; i >= 0; i--) {       mx[i] = max(mx[i], mx[i + 1]);     }     for (int i = n - 2; i >= 0; i -= 2) {       ans[i] = mx[(n - 2 - i) >> 1];     }     for (int i = 1; i < n; i++) {       vec.emplace_back(min(a[i], a[i + 1]), i);     }     memset(mx, 0, sizeof(mx));     sort(vec.begin(), vec.end());     while (!vec.empty()) {       int i = vec.back().second;       vec.pop_back();       int len = min(i - 1, n - 1 - i);       mx[len] = max(mx[len], min(a[i], a[i + 1]));     }     for (int i = n - 1; i >= 0; i--) {       mx[i] = max(mx[i], mx[i + 1]);     }     for (int i = n - 3; i >= 0; i -= 2) {       ans[i] = mx[(n - 3 - i) >> 1];     }     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int setBit(int N, int pos) { return N = N | (1 << pos); }   inline int resetBit(int N, int pos) { return N = N & ~(1 << pos); }   inline bool checkBit(int N, int pos) { return (bool)(N & (1 << pos)); }   const long long MAX = 300005;   int n;   vector<int> graph[MAX];   struct data {     int k;     long long x;   };   vector<data> qrList[MAX];   long long ans[MAX], what[MAX], levelDel[MAX];   void dfs(int u, int l = 0, long long tot = 0, int par = -1) {     for (data &p : qrList[u]) {       tot += p.x;       if (l + p.k + 1 <= n) levelDel[l + p.k + 1] += p.x;     }     tot -= levelDel[l];     ans[u] = tot;     for (int &v : graph[u]) {       if (v == par) continue;       dfs(v, l + 1, tot, u);     }     for (data &p : qrList[u]) {       tot -= p.x;       if (l + p.k + 1 <= n) levelDel[l + p.k + 1] -= p.x;     }   }   int main() {     int i, u, v, q, k;     long long x;     scanf( %d , &n);     for (i = 0; i < n - 1; i++) {       scanf( %d %d , &u, &v);       u--, v--;       graph[u].push_back(v);       graph[v].push_back(u);     }     scanf( %d , &q);     while (q--) {       scanf( %d %d , &u, &k);       scanf( %lld , &x);       u--;       qrList[u].push_back({k, x});     }     dfs(0);     for (i = 0; i < n; i++) printf( %lld  , ans[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5005;   int id[maxn][maxn];   char s[maxn][maxn];   char c[maxn];   int l[maxn], r[maxn], u[maxn], d[maxn];   int n, m, t;   void init() {     int i, j;     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         l[id[i][j]] = id[i][j - 1];         r[id[i][j]] = id[i][j + 1];         u[id[i][j]] = id[i - 1][j];         d[id[i][j]] = id[i + 1][j];       }     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         if (s[i][j] ==  . ) {           r[l[id[i][j]]] = r[id[i][j]];           l[r[id[i][j]]] = l[id[i][j]];           u[d[id[i][j]]] = u[id[i][j]];           d[u[id[i][j]]] = d[id[i][j]];         }       }     }   }   void del(int k) {     r[l[k]] = r[k];     l[r[k]] = l[k];     u[d[k]] = u[k];     d[u[k]] = d[k];   }   int dfs(int cur) {     if (cur == 0) return 0;     del(cur);     if (c[cur] ==  U ) return dfs(u[cur]) + 1;     if (c[cur] ==  D ) return dfs(d[cur]) + 1;     if (c[cur] ==  L ) return dfs(l[cur]) + 1;     if (c[cur] ==  R ) return dfs(r[cur]) + 1;     return 0;   }   void work() {     int i, j;     int ans, max = 0, num;     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         if (s[i][j] !=  . ) {           init();           ans = dfs(id[i][j]);           if (ans > max) {             max = ans;             num = 1;           } else if (ans == max)             num++;         }       }     }     printf( %d %d n , max, num);   }   int main() {     int i, j;     while (scanf( %d%d , &n, &m) != EOF) {       for (i = 1; i <= n; i++) scanf( %s , &s[i][1]);       t = 0;       memset(id, 0, sizeof(id));       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           t++;           id[i][j] = t;           c[t] = s[i][j];         }       }       work();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void printv(vector<int> v) {     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;     cout << endl;   }   unsigned long long summ(unsigned long long n) { return ((n * n) + n) / 2; }   bool isubseq(string s, string s1) {     int ln = s1.length();     int lll = s.length();     int i = 0, j = 0;     for (; i < ln && j < lll; i++) j += (s1[i] == s[j]);     return j == lll;   }   bool incirc(double x, double y, double center_x, double center_y, double r) {     return (x - center_x) * (x - center_x) + (y - center_y) * (y - center_y) <=            r * r;   }   unsigned long long gcd(unsigned long long a, unsigned long long b) {     unsigned long long c;     while (a != 0) {       c = a;       a = b % a;       b = c;     }     return b;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int a, b, different = 0, same = 0;     cin >> a >> b;     different = (a < b) ? a : b;     same = abs(a - b) / 2;     cout << different <<     << same << endl;     return 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     x = 0;     char c = getchar();     bool flag = false;     while (!isdigit(c)) {       if (c ==  - ) flag = true;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c ^ 48);       c = getchar();     }     if (flag) x = -x;   }   int n, m, q;   int dis[5010];   bool vis[5010];   vector<pair<int, int> > ve;   struct edge {     int to, nxt, v, c;     edge(int x = 0, int y = 0, int z = 0, int w = 0) {       to = x, nxt = y, v = z, c = w;     }   } e[5010];   int head[5010], edge_cnt = 1;   void add(int from, int to, int val, int cost) {     e[++edge_cnt] = edge(to, head[from], val, cost), head[from] = edge_cnt;     e[++edge_cnt] = edge(from, head[to], 0, -cost), head[to] = edge_cnt;   }   bool spfa() {     for (int i = 1; i <= n; ++i) vis[i] = false, dis[i] = 1000000000;     queue<int> q;     q.push(1), vis[1] = true, dis[1] = 0;     while (!q.empty()) {       int x = q.front();       q.pop(), vis[x] = false;       for (int i = head[x]; i; i = e[i].nxt) {         int y = e[i].to, c = e[i].c;         if (dis[y] <= dis[x] + c || !e[i].v) continue;         dis[y] = dis[x] + c;         if (!vis[y]) q.push(y), vis[y] = true;       }     }     return dis[n] != 1000000000;   }   int dfs(int x, int lim) {     if (x == n) return lim;     vis[x] = true;     int res = lim, flow;     for (int i = head[x]; i; i = e[i].nxt) {       int y = e[i].to, v = e[i].v;       if (dis[y] != dis[x] + e[i].c || vis[y] || !v) continue;       if (flow = dfs(y, min(res, v))) {         res -= flow, e[i].v -= flow, e[i ^ 1].v += flow;         if (!res) break;       }     }     return lim - res;   }   void dinic() {     int flow, v = 0, s = 0;     while (spfa())       while (flow = dfs(1, 1000000000))         v += flow, s += flow * dis[n], ve.push_back(make_pair(v, s));   }   int main() {     read(n), read(m);     for (int i = 1; i <= m; ++i) {       int x, y, v;       read(x), read(y), read(v), add(x, y, 1, v);     }     dinic(), read(q);     while (q--) {       int x;       double v = 1000000000;       read(x);       for (int i = 0; i < ve.size(); ++i)         v = min(v, (double)(x + ve[i].second) / ve[i].first);       printf( %.10lf n , v);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double ESP = 1e-9;   const int N = 2e5 + 1;   int arr[N], n;   bool canCover(double d) {     int used = 0;     double lastcoverd = 0.0;     for (int i = 0; i < n; ++i) {       if (arr[i] > lastcoverd) {         lastcoverd = arr[i] + (2 * d);         ++used;       }     }     return used <= 3;   }   double bs() {     double low = 0, high = 2e9 + 1, mid;     while (high - low > ESP) {       mid = low + (high - low) / 2;       if (canCover(mid)) {         high = mid;       } else {         low = mid;       }     }     return high;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , arr + i);     }     sort(arr, arr + n);     double d = bs();     printf( %.7f n , d);     int used = 0;     double lastcoverd = 0.0;     for (int i = 0; i < n; ++i) {       if (arr[i] - lastcoverd > ESP) {         lastcoverd = arr[i] + (2 * d);         printf( %.7f  , arr[i] + d);         used++;       }     }     while (used < 3) {       printf( %.7f  , 0.0);       ++used;     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 200005;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> v(n);     for (long long i = 0; i < n; i++) cin >> v[i];     vector<long long> ans(n);     sort(v.begin(), v.end());     long long idx = 0;     for (long long i = 1; i < n; i += 2) {       ans[i] = v[idx++];     }     for (long long i = 0; i < n; i += 2) {       ans[i] = v[idx++];     }     long long x = 0;     for (long long i = 1; i < n - 1; i++) {       if (ans[i] < ans[i - 1] and ans[i] < ans[i + 1]) x++;     }     cout << x <<   n ;     for (auto i : ans) {       cout << i <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mn = 200005;   const int mod = 1e9 + 7;   int n, m;   unordered_set<int> h[mn];   priority_queue<pair<int, int> > q;   int sum = 0;   int maxi, mini;   vector<tuple<int, int, int> > ans;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       int u;       scanf( %d , &u);       for (int j = 1; j <= u; j++) {         int v;         scanf( %d , &v);         h[i].insert(v);       }       sum += u;     }     mini = sum / n;     maxi = mini + (sum % n != 0);     for (int i = 1; i <= n; i++) {       if ((int)h[i].size() >= maxi) {         q.push({(int)h[i].size(), i});       }     }     for (int i = 1; i <= n; i++) {       while ((int)h[i].size() < mini) {         pair<int, int> u = q.top();         q.pop();         for (auto it = h[u.second].begin(); it != h[u.second].end(); it++) {           if (!h[i].count(*it)) {             h[i].insert(*it);             ans.push_back({u.second, i, *it});             h[u.second].erase(it++);             if ((int)h[i].size() == mini || (int)h[u.second].size() <= maxi)               break;           }         }         if ((int)h[u.second].size() >= maxi)           q.push({(int)h[u.second].size(), u.second});       }     }     for (int i = 1; i <= n; i++) {       if (q.top().first == maxi) break;       while ((int)h[i].size() == mini) {         pair<int, int> u = q.top();         q.pop();         for (auto it = h[u.second].begin(); it != h[u.second].end(); it++) {           if (!h[i].count(*it)) {             h[i].insert(*it);             ans.push_back({u.second, i, *it});             h[u.second].erase(it++);             break;           }         }         if ((int)h[u.second].size() >= maxi)           q.push({(int)h[u.second].size(), u.second});       }     }     printf( %d n , (int)ans.size());     for (auto &i : ans) {       printf( %d %d %d n , get<0>(i), get<1>(i), get<2>(i));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     string s;     cin >> s;     int c1[n], c2[n];     c2[0] = a[0];     if (s[0] ==  1 )       c1[0] = a[0];     else       c1[0] = 0;     for (int i = 1; i < n; i++) {       c1[i] = c1[i - 1];       c2[i] = c2[i - 1] + a[i];       if (s[i] ==  1 ) {         c1[i] += a[i];       }     }     int last, ans = c1[n - 1];     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  1 ) {         last = i;         break;       }     }     for (int i = 1; i <= last; i++) {       if (s[i] ==  1 ) {         ans = max(ans, c2[i - 1] + c1[n - 1] - c1[i]);       }     }     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     register int X = 0;     register char ch = 0;     while (ch < 48 || ch > 57) ch = getchar();     while (ch >= 48 && ch <= 57) X = X * 10 + (ch ^ 48), ch = getchar();     return X;   }   int n, m;   struct Point {     int l, r, x, y;   } b[600500];   int tn;   map<pair<int, int>, int> mmp;   int f[600500], xc[600500], yc[600500];   struct Data {     int x, y;   } stk[600500];   int top;   long long ans;   int findf(int x) { return f[x] == x ? x : findf(f[x]); }   void marge(int x, int y) {     x = findf(x);     y = findf(y);     if (x == y) return;     ans -= 1ll * xc[x] * yc[x] + 1ll * xc[y] * yc[y];     if (xc[x] + yc[x] > xc[y] + yc[y]) swap(x, y);     stk[++top] = (Data){x, y};     f[x] = y;     xc[y] += xc[x];     yc[y] += yc[x];     ans += 1ll * xc[y] * yc[y];   }   void undo(int x, int y) {     f[x] = x;     xc[y] -= xc[x];     yc[y] -= yc[x];   }   vector<int> s[600500 << 1];   void solve(int l, int r, int num) {     long long sav = ans;     int tim = top;     Point *v;     for (int i = 0; i < s[num].size(); i++) {       v = &b[s[num][i]];       if (v->l <= l && r <= v->r) marge(v->x, v->y);     }     if (l == r)       printf( %lld  , ans);     else {       int mid = (l + r) >> 1;       for (int i = 0; i < s[num].size(); i++) {         v = &b[s[num][i]];         if (!(v->l <= l && r <= v->r)) {           if (v->l <= mid) s[num << 1].push_back(s[num][i]);           if (v->r > mid) s[num << 1 | 1].push_back(s[num][i]);         }       }       s[num].clear();       solve(l, mid, num << 1);       solve(mid + 1, r, num << 1 | 1);     }     while (tim < top) {       undo(stk[top].x, stk[top].y);       top--;     }     ans = sav;   }   int main() {     m = read();     n = 300005;     pair<int, int> sav;     for (int i = 1, x, y; i <= m; i++) {       x = read();       y = read() + n;       sav = make_pair(x, y);       if (mmp[sav]) {         b[mmp[sav]].r = i - 1;         mmp[sav] = 0;       } else         b[mmp[sav] = ++tn] = (Point){i, 0, x, y};     }     for (int i = 1; i <= tn; i++) {       if (b[i].r == 0) b[i].r = m;       s[1].push_back(i);     }     for (int i = 1; i <= n + n; i++) {       f[i] = i;       xc[i] = (i <= n);       yc[i] = !xc[i];     }     solve(1, m, 1);     return 0;   }