malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   ostream &operator<<(ostream &out, string str) {     for (char c : str) out << c;     return out;   }   template <class L, class R>   ostream &operator<<(ostream &out, pair<L, R> p) {     return out <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {     out <<  { ;     for (auto &e : x) out << e << (&e == &*--x.end() ?    :  ,  );     return out <<  } ;   }   template <class... Args>   void dump(Args &&...args) {     ((cerr << args <<  ;   ), ...);   }   template <class T>   int size(T &&a) {     return (int)a.size();   }   using LL = long long;   using PII = pair<int, int>;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     for (int _t = 0; _t < t; _t++) {       int l, r;       cin >> l >> r;       if (2 * l > r)         cout <<  -1 -1 n ;       else         cout << l <<     << 2 * l <<   n ;     }   }
#include <bits/stdc++.h>   char str[100005], ans[100005];   int out[100005];   struct Edge {     int link[400005], next[400005], son[400005], l;     void clear() {       l = 0;       memset(son, 0, sizeof(son));     }     void addedge(int x, int y) {       link[++l] = y;       next[l] = son[x];       son[x] = l;     }   };   Edge e;   int top = 0;   int main() {     scanf( %s , str);     int l = strlen(str);     for (int i = l - 1; i >= 0; --i) e.addedge(str[i], i);     for (char c =  z ; c >=  a ; --c)       for (int p = e.son[c]; p; p = e.next[p])         if (top == 0 || e.link[p] > out[top]) out[++top] = e.link[p];     for (int i = 1; i <= top; ++i) ans[i - 1] = str[out[i]];     printf( %s n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n][4];     int l = 0;     char l0[3], l1[3], l2[3];     for (int i = 0; i < n; i++) {       cin >> l0 >> l1;       for (int j = 0; j <= l; j++) {         if (j == l) {           a[j][0] = l0[0];           a[j][1] = l0[1];           a[j][2] = l1[0];           a[j][3] = l1[1];           l++;           break;         }         if ((a[j][0] == l0[0] && a[j][1] == l0[1] && a[j][2] == l1[0] &&              a[j][3] == l1[1]) ||             (a[j][0] == l0[1] && a[j][1] == l1[1] && a[j][2] == l0[0] &&              a[j][3] == l1[0]) ||             (a[j][0] == l1[1] && a[j][1] == l1[0] && a[j][2] == l0[1] &&              a[j][3] == l0[0]) ||             (a[j][0] == l1[0] && a[j][1] == l0[0] && a[j][2] == l1[1] &&              a[j][3] == l0[1])) {           break;         }       }       if (i != n - 1) cin >> l2;     }     cout << l;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0), cin.tie(0);     int arr[4];     for (int i = 0; i < (int)4; i++) cin >> arr[i];     sort(arr, arr + 4);     bool ok = 0;     for (int mask = 0; mask < (1 << 4); mask++) {       int sum1 = 0;       int sum2 = 0;       for (int bit = 0; bit < 4; bit++) {         if (mask & (1 << bit)) {           sum1 += arr[bit];         } else {           sum2 += arr[bit];         }       }       if (sum1 == sum2) {         ok = 1;         break;       }     }     if (ok)       cout <<  YES  <<   n ;     else       cout <<  NO  <<   n ;     return 0;   }
#include <bits/stdc++.h>   inline int read() {     int s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   inline long long readll() {     long long s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   using namespace std;   int a[1000003];   long long w[1000003], ans[1000003];   long long qp(long long x, long long y) {     if (y == 1) return x;     if (y & 1) {       long long t = qp(x, y >> 1);       return t * t % 998244353LL * x % 998244353LL;     }     long long t = qp(x, y >> 1);     return t * t % 998244353LL;   }   int main() {     int n = read();     for (int i = 1; i <= n; i++) a[i] = read();     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) w[i] = w[i - 1] + a[i];     for (int i = 1; i < n; i++)       for (int j = i; j > 0; j -= (n - i)) ans[i] += w[j], ans[i] %= 998244353LL;     for (int i = n - 1; i >= 0; i--)       printf( %lld  , ans[i] * qp(n, 998244351LL) % 998244353LL);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[40005];   int main() {     int i, j;     int n, m, x;     while (scanf( %d %d , &n, &m) != EOF) {       if ((n == 1 || n == 2) && m == 1) {         printf( -1 n );         continue;       }       if (n < (2 * m + 1)) {         if (m == 1) {           printf( %d n , n * m);           for (i = 1; i <= n; i++) {             for (j = 1; j <= m; j++) {               x = i + j;               if (x > n) {                 x = x - n;               }               printf( %d %d n , i, x);             }           }         } else           printf( -1 n );         continue;       }       printf( %d n , n * m);       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           x = i + j;           if (x > n) {             x = x - n;           }           printf( %d %d n , i, x);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool collinear(int x1, int y1, int x2, int y2, int x3, int y3) {     return (y1 - y2) * (x1 - x3) == (y1 - y3) * (x1 - x2);   }   int main() {     int n, x, y;     cin >> n;     vector<pair<int, int> > points;     for (int i = 0; i < n; i++) {       cin >> x >> y;       points.push_back(make_pair(x, y));     }     long long ans = 0;     for (int i = 0; i < n - 2; i++)       for (int j = i + 1; j < n - 1; j++)         for (int k = j + 1; k < n; k++) {           if (!collinear(points[i].first, points[i].second, points[j].first,                          points[j].second, points[k].first, points[k].second))             ans++;         }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Get() {     char c;     while (c = getchar(), c <  0  || c >  9 )       ;     int X = c - 48;     while (c = getchar(), c >=  0  && c <=  9 ) X = X * 10 + c - 48;     return X;   }   int Pow(int A, int B, int Mod) {     if (!B) return 1;     int T = Pow((long long)A * A % Mod, B / 2, Mod);     if (B & 1) T = (long long)T * A % Mod;     return T;   }   int main() {     int N = Get(), M = Get(), Mod = Get();     static int G[600][600], In[600], Out[600];     memset(G, 0, sizeof(G));     memset(In, 0, sizeof(In));     memset(Out, 0, sizeof(Out));     for (int i = 0; i < M; i++) {       int X = Get() - 1, Y = Get() - 1;       G[X][Y]++;       In[Y]++;       Out[X]++;     }     static vector<int> List[600];     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++)         if (G[i][j]) List[i].push_back(j);     static int Temp[600], Stack[600];     int Top = 0;     for (int i = 0; i < N; i++) {       Temp[i] = In[i];       if (!Temp[i]) Stack[Top++] = i;     }     static int Queue[600];     int Count = 0;     while (Top--) {       int V = Stack[Top];       Queue[Count++] = V;       for (int i = 0; i < N; i++)         if (G[V][i]) {           Temp[i] -= G[V][i];           if (!Temp[i]) Stack[Top++] = i;         }     }     static int P[600][600];     memset(P, 0, sizeof(P));     for (int i = 0; i < N; i++) {       int V = Queue[i];       P[V][V] = 1;       for (int j = i; j < N; j++) {         int U = Queue[j];         if (!P[V][U]) continue;         for (int k = 0; k < List[U].size(); k++) {           int _U = List[U][k];           P[V][_U] = ((long long)P[V][U] * G[U][_U] + P[V][_U]) % Mod;         }       }     }     int K0 = 0, K1 = 0;     static int X[600], Y[600];     for (int i = 0; i < N; i++) {       if (!In[i] && Out[i]) X[K0++] = i;       if (!Out[i] && In[i]) Y[K1++] = i;     }     int K = K0;     static long long A[600][600];     for (int i = 0; i < K; i++)       for (int j = 0; j < K; j++) A[i][j] = P[X[i]][Y[j]];     int Ans = 1;     for (int i = 0; i < N; i++)       if (!In[i] && !Out[i]) X[K0++] = Y[K1++] = i;     for (int i = 0; i < K0; i++)       for (int j = 0; j < K0; j++)         if (X[i] < X[j] && Y[i] > Y[j]) Ans = -Ans;     for (int i = 0; i < K; i++) {       int P = i;       while (P < K && !A[P][i]) P++;       if (P == K) {         printf( 0 n );         return 0;       }       if (P != i) {         Ans = -Ans;         for (int j = i; j < K; j++) swap(A[i][j], A[P][j]);       }       int Q = Pow(A[i][i], Mod - 2, Mod);       for (int j = i + 1; j < K; j++) {         int T = (long long)A[j][i] * Q % Mod;         if (!T) continue;         for (int k = i; k < K; k++) {           A[j][k] = (A[j][k] - (long long)T * A[i][k]) % Mod;           if (A[j][k] < 0) A[j][k] += Mod;         }       }     }     for (int i = 0; i < K; i++) Ans = (long long)Ans * A[i][i] % Mod;     if (Ans < 0) Ans += Mod;     printf( %d n , Ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int par[20][100001], dep[100001], lg[100001], sizes[100001];   bool isParent[100001];   vector<int> adj[100001];   void dfs(int u) {     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v != par[0][u]) {         isParent[u] = true;         dep[v] = dep[u] + 1;         par[0][v] = u;         dfs(v);       }     }   }   int subtree(int u) {     if (sizes[u] == -1) {       sizes[u] = 1;       if (isParent[u]) {         for (int i = 0; i < adj[u].size(); i++) {           int v = adj[u][i];           if (v != par[0][u]) sizes[u] += subtree(v);         }       }     }     return sizes[u];   }   void buildLCA(int root, int n) {     memset(par, -1, sizeof par);     memset(sizes, -1, sizeof sizes);     memset(isParent, false, sizeof isParent);     dep[root] = 0;     dfs(root);     for (int i = 2; i < n; i++) lg[i] = lg[i >> 1] + 1;     for (int i = 1; (1 << i) < n; i++)       for (int u = 0; u < n; u++)         if ((1 << i) <= dep[u]) par[i][u] = par[i - 1][par[i - 1][u]];     subtree(root);   }   int climb(int u, int k) {     if (dep[u] < k) return -1;     for (; k > 0; k -= (1 << lg[k])) u = par[lg[k]][u];     return u;   }   int lca(int a, int b) {     if (dep[a] < dep[b])       b = climb(b, dep[b] - dep[a]);     else       a = climb(a, dep[a] - dep[b]);     for (int k = lg[dep[a]]; k >= 0 && a != b; k--)       if (par[k][a] != par[k][b]) {         a = par[k][a];         b = par[k][b];       }     if (a != b && dep[a] > 0) {       a = par[0][a];       b = par[0][b];     }     return a == b ? a : -1;   }   int dist(int u, int v) {     int L = lca(u, v);     return L == -1 ? -1 : dep[u] + dep[v] - 2 * dep[L];   }   int main() {     int n, m;     cin >> n;     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     buildLCA(1, n + 1);     cin >> m;     while (m--) {       int a, b;       cin >> a >> b;       if (a != b) {         int l = lca(a, b), distance = dist(a, b);         if (distance % 2 == 0) {           if (dep[a] != dep[b]) {             int deepernode;             if (dep[a] > dep[b])               deepernode = a;             else               deepernode = b;             int mid1 = climb(deepernode, distance / 2),                 mid2 = climb(deepernode, distance / 2 - 1);             cout << sizes[mid1] - sizes[mid2] << endl;           } else {             int aa = climb(a, dist(a, l) - 1), bb = climb(b, dist(a, l) - 1);             cout << n - sizes[aa] - sizes[bb] << endl;           }         } else           cout << 0 << endl;       } else         cout << n << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300100;   int head[maxn], nxt[maxn << 1], ver[maxn << 1], tot;   void addedge(int a, int b) {     nxt[++tot] = head[a];     ver[tot] = b;     head[a] = tot;     nxt[++tot] = head[b];     ver[tot] = a;     head[b] = tot;   }   int f[maxn], getlen;   void treedp(int x, int fat) {     f[x] = 0;     int mx = 0, sm = 0;     for (int i = head[x]; i; i = nxt[i]) {       int y = ver[i];       if (y == fat) continue;       treedp(y, x);       int F = f[y] + 1;       f[x] = max(f[x], F);       if (F >= mx)         sm = mx, mx = F;       else if (F > sm)         sm = F;     }     getlen = max(getlen, mx + sm);   }   int getpath(int x) {     getlen = 0;     treedp(x, 0);     return getlen;   }   int v[maxn], fa[maxn];   int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   int main() {     int n, m, q;     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= m; i++) {       int a, b;       scanf( %d%d , &a, &b);       addedge(a, b);       fa[find(a)] = find(b);     }     for (int i = 1; i <= n; i++)       if (find(i) == i) v[i] = getpath(i);     for (int i = 1; i <= q; i++) {       int opt, a, b;       scanf( %d , &opt);       if (opt == 1)         scanf( %d , &a), printf( %d n , v[find(a)]);       else {         scanf( %d%d , &a, &b);         a = find(a);         b = find(b);         if (a == b) continue;         v[b] = max(max(v[a], v[b]), ((v[a] + 1) >> 1) + ((v[b] + 1) >> 1) + 1);         fa[a] = b;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[5002];   int main() {     int n, i;     scanf( %d , &n);     if (n <= 2) {       printf( 1 n1 n );       return 0;     }     if (n == 3) {       printf( 2 n1 3 n );       return 0;     }     int curr = (n & 1) ? n : n - 1;     for (i = 0; i < n; i++) {       if (curr < 0) curr = (n & 1) ? n - 1 : n;       arr[i] = curr;       curr -= 2;     }     printf( %d n , n);     for (i = 0; i < n; i++) printf( %d  , arr[i]);     putchar(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, i, m = 1000000007, a, b;   int main() {     cin >> n;     a = 1, b = 1;     for (i = 0; i < 3 * n; i++) a = (a * 3) % m;     for (i = 0; i < n; i++) b = (b * 7) % m;     cout << (a - b + m) % m;     return 0;   }
#include <bits/stdc++.h>   const int mxn = 1e5;   int cost[mxn][3], go[mxn][2], deg[mxn], path[mxn];   int color[mxn];   long long cc[3][3];   int main() {     int n, u, a, b, c = 0;     scanf( %d , &n);     for (int j = 0; j < 3; ++j)       for (int i = 1; i <= n; ++i) scanf( %d , &cost[i][j]);     for (int i = 1; i < n; ++i) {       scanf( %d%d , &a, &b);       ++deg[a], ++deg[b];       go[a][0] ? go[a][1] = b : go[a][0] = b;       go[b][0] ? go[b][1] = a : go[b][0] = a;     }     for (int i = 1; i <= n; ++i) {       if (deg[i] == 1) ++c, u = i;       if (deg[i] > 2) return 0 * printf( -1 );     }     if (c != 2) return 0 * printf( -1 );     for (int i = 1, v = u, p = 0, pa; p != v; ++i, p = pa) {       path[i] = pa = v;       if (go[v][0] != p && go[v][0])         v = go[v][0];       else if (go[v][1] != p && go[v][1])         v = go[v][1];     }     for (int i = 0; i < 3; ++i) {       for (int j = 0; j < 3; ++j)         if (i != j) {           a = i, b = j;           cc[i][j] = cost[path[1]][i] + cost[path[2]][j];           for (int k = 3; k <= n; ++k) {             c = (3 - a - b) % 3;             cc[i][j] += cost[path[k]][c];             a = b, b = c;           }         }     }     long long min_cost = (long long)1e18;     for (int i = 0; i < 3; ++i)       for (int j = 0; j < 3; ++j)         if (i != j)           if (min_cost > cc[i][j]) a = i, b = j, min_cost = cc[i][j];     color[path[1]] = a, color[path[2]] = b;     for (int k = 3; k <= n; ++k) {       c = (3 - a - b) % 3;       color[path[k]] = c;       a = b, b = c;     }     printf( %lld n , min_cost);     for (int i = 1; i <= n; ++i) printf( %d  , color[i] + 1);   }
#include <bits/stdc++.h>   using namespace std;   map<string, int> ma;   map<string, int>::iterator p;   long i, n, m;   double ex, k;   int main() {     cin >> n >> m >> k;     string st;     for (i = 1; i <= n; i++) {       cin >> st >> ex;       ma[st] = (int)(ex * k + 1e-9);       if (ma[st] < 100) ma.erase(st);     }     for (i = 1; i <= m; i++) {       cin >> st;       ma[st] += 0;     }     cout << ma.size() << endl;     for (p = ma.begin(); p != ma.end(); p++)       cout << p->first <<     << p->second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long cc = 1e9 + 7;   map<int, int> A;   map<int, int>::iterator itr, it;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       int nn = s.size();       vector<int> p;       for (int j = 0; j < nn; j++) {         int nnn = p.size();         if (p.size() == 0) {           if (s[j] ==  ( )             p.push_back(1);           else             p.push_back(-1);         } else {           if (s[j] ==  ) ) {             if (p[nnn - 1] == 1)               p.pop_back();             else               p.push_back(-1);           } else {             p.push_back(1);           }         }       }       int nnn = p.size();       if (nnn == 0)         A[0]++;       else if (p[0] == p[nnn - 1]) {         A[(p[0] * nnn)]++;       }     }     int sum = 0;     for (itr = A.begin(); itr != A.end(); itr++) {       if (itr->first == 0) {         sum += (itr->second) / 2;       } else {         int yy = itr->first;         it = A.find(0 - yy);         if (it != A.end()) {           sum += (min(itr->second, it->second));           it->second = 0;         }       }     }     cout << sum << endl;   }
#include<bits/stdc++.h>   using namespace std;   typedef long long int ll;   #define endl   n                bool powerOf2(ll x){       return x && (!(x&(x-1)));   }      void solve(){              ll u, v;              cin>>u>>v;                     if(v<u || (powerOf2(u) && !powerOf2(v))){           cout<< No n ;       }else{           if(u==v || (powerOf2(v))){               cout<< Yes n ;           }else{               ll num = u;                                                          bool flag = false;                                 while(num<v){                   ll maxN = -1;                      for(int i = 0;i<32; i++){                                              ll msk = 1<<i;                                              if(num + msk > v){                           break;                       }                                              if(num & msk){                           if(num + msk == v){                               flag = true;                               break;                           }                           maxN = max(maxN, msk);                       }                   }                                                         if(flag || maxN == -1) break;                                      num+=maxN;               }                                             if(flag || num==v){                   cout<< Yes n ;               }else{                   cout<< No n ;               }                          }               }                                  }      int main(){       int t;       cin>>t;       while(t--)           solve();       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 7;   int clr[MAX] = {0}, vis[MAX] = {0}, res = 0;   vector<int> adj[MAX];   void dfs(int u, int p, int clr_p) {     int f = 0;     if (!vis[clr[u]]) {       f = 1;       vis[clr[u]] = 1;       res++;     } else if (p != -1 && clr_p != clr[u])       res++;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (p == v) continue;       dfs(v, u, clr[u]);     }     if (f) vis[clr[u]] = 0;   }   int main(int argc, char const *argv[]) {     int n, x;     cin >> n;     for (int i = 2; i <= n; i++) {       cin >> x;       adj[i].push_back(x);       adj[x].push_back(i);     }     for (int i = 1; i <= n; i++) cin >> clr[i];     dfs(1, -1, -1);     std::cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<int, int> > e;   bool check(vector<pair<int, int> > res) {     if (res.size() > (n + m + 1) / 2) return false;     vector<int> d(n, 0), d2(n, 0);     for (pair<int, int> i : res) {       d[--i.first]++;       d[--i.second]++;     }     for (pair<int, int> i : e) {       d2[--i.first]++;       d2[--i.second]++;     }     for (int i = 0; i < n; i++) {       if ((d2[i] + 1) / 2 > d[i]) return false;     }     return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     e.resize(m);     vector<set<int> > g(n + 1);     for (int i = 0; i < m; i++) {       cin >> e[i].first >> e[i].second;       g[e[i].first].insert(e[i].second);       g[e[i].second].insert(e[i].first);     }     for (int i = 1; i <= n; i++) {       if ((int)(g[i].size()) & 1) {         g[i].insert(0);         g[0].insert(i);       }     }     vector<int> c(n + 1, 0);     vector<pair<int, int> > res;     for (int s = 1; s <= n; s++) {       if (!c[s]) {         vector<int> st, ep;         st.push_back(s);         while (!st.empty()) {           int f = st.back();           c[f] = 1;           if (g[f].empty()) {             st.pop_back();             ep.push_back(f);           } else {             int v = *g[f].begin();             g[f].erase(v);             g[v].erase(f);             st.push_back(v);           }         }         ep.pop_back();         for (int i = 0; i < (int)ep.size(); i++) {           int v0 = ep[(ep.size() + i - 1) % ep.size()], v1 = ep[i],               v2 = ep[(i + 1) % ep.size()], v3 = ep[(i + 2) % ep.size()];           if (!v1 || !v2) continue;           if (!v0 || !v3 || !(i & 1)) {             res.push_back({v1, v2});           }         }       }     }     cout << res.size() <<   n ;     for (pair<int, int> i : res) {       cout << i.first <<     << i.second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long input() {     long long x;     scanf( %lld , &x);     return x;   }   const int inf = 1e9;   int clamp(int a, int l, int r) {     if (a < l) a = l;     if (a > r) a = r;     return a;   }   int main() {     int n, m;     cin >> n >> m;     vector<int> pos(1010101, -1);     vector<int> L(1010101, -1), R(1010101, -1);     set<tuple<int, int, int, int>> st;     const int MostLeft = 1010101 - 2;     const int MostRight = 1010101 - 3;     pos[MostLeft] = -inf;     pos[MostRight] = inf;     const auto calcPos = [&](int i, int j) {       if (i == MostLeft && j == MostRight) return 1;       return clamp((pos[i] + pos[j]) / 2, 1, n);     };     const auto calcDist = [&](int i, int j) {       if (i == MostLeft && j == MostRight)         return n - 1;       else if (i == MostLeft)         return pos[j] - 1;       else if (j == MostRight)         return n - pos[i];       return (pos[j] - pos[i]) / 2;     };     for (int ii = 0; ii < m; ii++) {       int t = input();       int id = input();       if (t == 1) {         int lid, rid;         if (st.empty()) {           lid = MostLeft;           rid = MostRight;         } else {           tie(ignore, ignore, lid, rid) = *st.begin();           st.erase(st.begin());         }         pos[id] = calcPos(lid, rid);         R[lid] = L[rid] = id;         L[id] = lid;         R[id] = rid;         st.emplace(-calcDist(lid, id), pos[lid], lid, id);         st.emplace(-calcDist(id, rid), pos[id], id, rid);         printf( %d n , pos[id]);       } else {         int lid = L[id];         int rid = R[id];         R[lid] = rid;         L[rid] = lid;         st.erase(make_tuple(-calcDist(lid, id), pos[lid], lid, id));         st.erase(make_tuple(-calcDist(id, rid), pos[id], id, rid));         st.emplace(-calcDist(lid, rid), pos[lid], lid, rid);       }     }   }