malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   int N, M, Q;   vector<int> V[100002], W[100002];   int X[100002], Y[100002], T[100002], weight[100002];   int A[100002];   bool S[100002];   int xglob, yglob;   inline bool compare(const int& i1, const int& i2) {     return atan2(Y[i1] - yglob, X[i1] - xglob) <            atan2(Y[i2] - yglob, X[i2] - xglob);   }   void Dfs(int x) {     S[x] = true;     weight[x] = 1;     W[x].resize(V[x].size());     for (int i = 0; i < int(V[x].size()); ++i)       if (!S[V[x][i]]) {         T[V[x][i]] = x;         Dfs(V[x][i]);         weight[x] += weight[V[x][i]];         W[x][i] = -weight[V[x][i]];       }     for (int i = 0; i < int(V[x].size()); ++i)       if (V[x][i] == T[x]) W[x][i] = weight[x];     for (int i = 1; i < int(W[x].size()); ++i) W[x][i] += W[x][i - 1];   }   int main() {     cin >> N >> M;     for (int i = 1, nod1, nod2; i <= M; ++i) {       cin >> nod1 >> nod2;       V[nod1].push_back(nod2);       V[nod2].push_back(nod1);     }     int minx = -1;     for (int i = 1; i <= N; ++i) {       cin >> X[i] >> Y[i];       if (minx == -1 || X[i] < X[minx]) minx = i;     }     X[N + 1] = -0x3f3f3f3f, Y[N + 1] = -0x3f3f3f3f;     V[minx].push_back(N + 1);     V[N + 1].push_back(minx);     for (int i = 1; i <= N; ++i) {       xglob = X[i], yglob = Y[i];       sort(V[i].begin(), V[i].end(), compare);     }     Dfs(N + 1);     cin >> Q;     for (int i = 1; i <= Q; ++i) {       cin >> A[0];       long long area = 0;       for (int j = 1; j <= A[0]; ++j) {         cin >> A[j];         if (j >= 2)           area += 1LL * X[A[j - 1]] * Y[A[j]] - 1LL * X[A[j]] * Y[A[j - 1]];       }       area += 1LL * X[A[A[0]]] * Y[A[1]] - 1LL * X[A[1]] * Y[A[A[0]]];       if (area < 0) reverse(A + 1, A + A[0] + 1);       A[A[0] + 1] = A[1];       ++A[0];       A[A[0] + 1] = A[2];       ++A[0];       int result = 0;       for (int j = 2; j <= A[0] - 1; ++j) {         int step = 1 << 16, nod1, nod2;         for (nod1 = -1; step; step >>= 1)           if (nod1 + step < int(V[A[j]].size()) &&               atan2(Y[V[A[j]][nod1 + step]] - Y[A[j]],                     X[V[A[j]][nod1 + step]] - X[A[j]]) -                       atan2(Y[A[j - 1]] - Y[A[j]], X[A[j - 1]] - X[A[j]]) <                   eps)             nod1 += step;         step = 1 << 16;         for (nod2 = -1; step; step >>= 1)           if (nod2 + step < int(V[A[j]].size()) &&               atan2(Y[V[A[j]][nod2 + step]] - Y[A[j]],                     X[V[A[j]][nod2 + step]] - X[A[j]]) -                       atan2(Y[A[j + 1]] - Y[A[j]], X[A[j + 1]] - X[A[j]]) <                   eps)             nod2 += step;         if (nod1 < nod2)           result += W[A[j]][nod2 - 1] - W[A[j]][nod1];         else           result += W[A[j]][W[A[j]].size() - 1] -                     (W[A[j]][nod1] - (nod2 == 0 ? 0 : W[A[j]][nod2 - 1]));       }       cout << result <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int n;     cin >> n;     vector<long long int> a, d;     for (long long int i = 0; i < n; i++) {       long long int temp;       cin >> temp;       a.push_back(temp);     }     for (long long int i = 0; i < n; i++) {       long long int temp;       cin >> temp;       d.push_back(a[i] - temp);     }     sort(d.begin(), d.end());     long long int i = 0, j = n - 1, s = 0;     while (i != j) {       if (d[i] + d[j] > 0) {         j--;       } else {         i++;         s += n - j - 1;       }     }     s += (n - j - 1) * (n - j) / 2;     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string n;     cin >> n;     int ans = 0;     while (n.size() > 1) {       int k = 0;       for (int i = 0; i < n.size(); i++) {         k += n[i] - 48;       }       ans++;       stringstream ss;       ss << k;       string str = ss.str();       n = str;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T, a, b, c, i, count = 0;     cin >> T;     for (i = 0; i < T; i++) {       cin >> a >> b >> c;       if ((a + b + c) >= 2) {         count++;       }     }     cout << count <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   struct Node {     int a[3], idx;     bool operator<(const Node& ano) const {       if (a[1] == ano.a[1]) {         if (a[2] == ano.a[2]) return a[0] < ano.a[0];         return a[2] < ano.a[2];       }       return a[1] < ano.a[1];     }   } t[N];   int main() {     int n;     cin >> n;     double ans1 = 0;     int k1 = 0;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 3; j++) scanf( %d , &t[i].a[j]);       t[i].idx = i;       sort(t[i].a, t[i].a + 3);       if (ans1 < 0.5 * t[i].a[0]) {         ans1 = 0.5 * t[i].a[0];         k1 = i;       }     }     sort(t + 1, t + 1 + n);     double ans2 = 0;     int k21 = 0, k22 = 0;     for (int i = 2; i <= n; i++) {       if (i != n && t[i].a[0] == t[i + 1].a[0] && t[i].a[2] == t[i + 1].a[2] &&           t[i].a[1] == t[i + 1].a[1]) {         continue;       }       if (t[i].a[2] == t[i - 1].a[2] && t[i].a[1] == t[i - 1].a[1]) {         int nlen = t[i].a[0] + t[i - 1].a[0];         int minlen = min(t[i].a[1], min(t[i].a[2], nlen));         if (ans2 < 0.5 * minlen) {           ans2 = 0.5 * minlen;           k21 = t[i - 1].idx, k22 = t[i].idx;         }       }     }     if (ans1 >= ans2)       cout <<  1 n  << k1 << endl;     else       cout <<  2 n  << k21 <<     << k22 << endl;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:65777216 )   using namespace std;   const int N = 2222;   const int INF = 111111111;   const double eps = 1e-9;   const double pi = 3.14159265358979;   char s[N], u[N];   int n, m, ans = INF;   inline int check(int pos) {     int res = 0;     for (int i = 0; i < (m); i++) {       if (pos + i < 0 || pos + i >= n) continue;       if (s[pos + i] == u[i]) ++res;     }     return res;   }   int main() {     gets(s);     gets(u);     n = strlen(s);     m = strlen(u);     for (int i = -m; i <= m + n; i++) ans = min(ans, m - check(i));     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k = 0;     int ladder = 0;     string slogan;     cin >> k >> ladder;     cin >> slogan;     int h = k / 2;     if (ladder != 1 && ladder != k) {       if (ladder > h) {         while (ladder != k) {           cout <<  RIGHT  << endl;           ladder++;         }       } else if (ladder <= h) {         while (ladder != 1) {           cout <<  LEFT  << endl;           ladder--;         }       }     }     string toPrint = ladder == 1 ?  RIGHT  :  LEFT ;     if (toPrint ==  LEFT ) {       string reversed =   ;       for (int i = k - 1; i >= 0; i--) {         reversed += slogan.at(i);       }       slogan = reversed;     }     for (int i = 0; i < k; i++) {       if (i != 0) {         cout << toPrint << endl;       }       cout <<  PRINT   << slogan.at(i) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int md = 1000000007;   void add(int &a, int b) {     a += b;     if (a >= md) a -= md;   }   int f[155][155][2][2], oldf[155][155][2][2], trueoldf[155][155][2][2];   int main() {     int n, m;     scanf( %d %d , &n, &m);     memset(f, 0, sizeof(f));     for (int a = 1; a <= m; a++)       for (int b = a; b <= m; b++) f[a][b][1][1] = 1;     int ans = 0;     for (int i = 1; i <= n; i++) {       long long cnt = 0;       for (int a = 1; a <= m; a++)         for (int b = a; b <= m; b++)           for (int ka = 0; ka <= 1; ka++)             for (int kb = 0; kb <= 1; kb++) cnt += f[a][b][ka][kb];       ans = (ans + cnt * (n - i + 1)) % md;       for (int a = 1; a <= m; a++)         for (int b = a + 1; b <= m; b++)           for (int kb = 0; kb <= 1; kb++) {             add(f[a + 1][b][0][kb], f[a][b][0][kb]);             add(f[a + 1][b][0][kb], f[a][b][1][kb]);           }       for (int a = 1; a <= m; a++)         for (int b = m; b >= a + 1; b--)           for (int ka = 0; ka <= 1; ka++) {             add(f[a][b - 1][ka][0], f[a][b][ka][0]);             add(f[a][b - 1][ka][0], f[a][b][ka][1]);           }       for (int a = m; a >= 2; a--)         for (int b = a; b <= m; b++)           for (int kb = 0; kb <= 1; kb++) {             add(f[a - 1][b][1][kb], f[a][b][1][kb]);           }       for (int a = m; a >= 1; a--)         for (int b = a; b <= m - 1; b++)           for (int ka = 0; ka <= 1; ka++) {             add(f[a][b + 1][ka][1], f[a][b][ka][1]);           }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long v[3], l, ans, minusVal;   long long accSum(long long limit) {     return (limit + 1LL) * (limit + 2LL) / 2LL;   }   long long invalidCase(long long a, long long b, long long c) {     long long ret = 0LL;     for (long long i = 0LL; i <= l; i++) {       long long val = min(c - a - b + i, l - i);       if (val >= 0LL) ret += accSum(val);     }     return ret;   }   int main() {     scanf( %lld %lld %lld %lld , &v[0], &v[1], &v[2], &l);     ans = (l + 1LL) * (l + 2LL) * (l + 3LL) / 6LL;     ans -= invalidCase(v[2], v[1], v[0]);     ans -= invalidCase(v[0], v[2], v[1]);     ans -= invalidCase(v[0], v[1], v[2]);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000 * 1000 * 1000 + 7;   const long long MAXN = 100 * 1000 + 10;   long long t;   long long n, k;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     cin >> t;     while (t--) {       cin >> n >> k;       cout << k * 2 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fin(string s, int i1) {     int mi = 999999999;     for (int d = 1; d <= 9; d++) {       for (int i = i1; i < i1 + 10; i++) {         if (i + 2 * d < s.length()) {           if (s[i] == s[i + d] && s[i] == s[i + 2 * d]) {             mi = min(mi, i + 2 * d);           }         }       }     }     return mi;   }   int main() {     string s;     cin >> s;     long long n = s.length();     long long ans = 0;     for (int i = 0; i < n; i++) {       int p = fin(s, i);       if (n > p) {         ans = ans + n - p;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)2e5 + 100;   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int modexp(long long int x, long long int n, long long int mod) {     long long int result = 1;     while (n > 0) {       if (n % 2 == 1) result = (result % mod * x % mod) % mod;       x = (x % mod * x % mod) % mod;     }     return result;   }   bool vis[N];   vector<long long int> adj[N];   long long int mx = 0;   void DFS(long long int s) {     vis[s] = true;     for (int i = 0; i < adj[s].size(); i++)       if (!vis[adj[s][i]]) DFS(adj[s][i]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       long long int ans = n - (n % k);       long long int x = k / 2;       ans += min(x, n % k);       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 9223372036854775807ll;   const int inf = 2147483647, nmax = 1000006;   struct thing {     long long a, b, c, i;     bool operator<(const thing &obj) const { return c < obj.c; }   } e[nmax], e2[nmax], apm[nmax];   struct thing2 {     long long a, b, c, i, st, dr, mid, ans;     bool operator<(const thing2 &obj) const { return mid < obj.mid; }   };   long long n, m, c[nmax], rng[nmax], v[nmax], ans[nmax];   vector<thing2> r;   long long find(long long x) {     if (x == c[x]) return x;     return c[x] = find(c[x]);   }   void unite(long long x, long long y) {     if (x == y) return;     if (rng[x] > rng[y])       c[y] = x;     else       c[x] = y;     if (rng[x] == rng[y]) ++rng[y];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       cin >> e[i].a >> e[i].b >> e[i].c;       e[i].i = i;       e2[i] = e[i];       ans[i] = -1;     }     sort(e2 + 1, e2 + m + 1);     for (int i = 1; i <= n; ++i) rng[i] = 1, c[i] = i;     int p = 0;     for (int i = 1; i <= m; ++i)       if (find(e2[i].a) != find(e2[i].b)) {         apm[++p] = e2[i];         unite(find(e2[i].a), find(e2[i].b));         v[p] = e2[i].c;       } else {         thing2 obj;         obj.a = e2[i].a;         obj.b = e2[i].b;         obj.c = e2[i].c;         obj.i = e2[i].i;         obj.st = 1;         obj.dr = n - 1;         r.push_back(obj);       }     sort(v + 1, v + n);     for (int t = 1; t <= 32; ++t) {       for (auto &x : r) x.mid = (x.st + x.dr) / 2;       sort(r.begin(), r.end());       for (int i = 1; i <= n; ++i) rng[i] = 1, c[i] = i;       unsigned p = 0;       for (int i = 1; i < n; ++i) {         unite(find(apm[i].a), find(apm[i].b));         while (p < r.size() && v[r[p].mid] <= apm[i].c) {           if (find(r[p].a) == find(r[p].b)) {             r[p].dr = r[p].mid - 1;             r[p].ans = v[r[p].mid];           } else             r[p].st = r[p].mid + 1;           ++p;         }       }     }     for (auto x : r) ans[x.i] = x.ans;     for (int i = 1; i <= m; ++i)       if (ans[i] != -1) cout << ans[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   struct compF {     bool operator()(const pair<T, T> &a, const pair<T, T> &b) {       return a.first < b.first;     }   };   template <typename T>   struct compS {     bool operator()(const pair<T, T> &a, const pair<T, T> &b) {       return a.second < b.second;     }   };   template <typename T>   void printMatrix(const string &txt, vector<vector<T>> &a) {     cout << txt;     for (int i = 0; i < a.size(); ++i) {       for (int j = 0; j < a[i].size(); ++j) cout << a[i][j] <<    ;       cout << endl;     }   }   template <typename T>   void printVector(const string &txt, vector<T> &a) {     cout << txt;     for (int i = 0; i < a.size(); ++i) cout << a[i] <<    ;     cout << endl;   }   template <typename T>   void readVector(int n, vector<T> &a) {     if (a.size() < n) a.resize(n);     for (int i = 0; i < n; ++i) cin >> a[i];   }   template <typename T1, typename T2>   bool exist(map<T1, T2> &m, T1 x) {     if (m.find(x) == m.end()) return false;     return true;   }   long long gcd(long long a, long long b) {     while (a != 0 && b != 0) {       if (b > a)         b %= a;       else         a %= b;     }     return a + b;   }   long long minFactor(long long x) {     for (long long i = 2; i * i <= x; ++i)       if (x % i == 0) return i;     return x;   }   long long allFactors(long long x, vector<long long> &prms,                        vector<long long> &prm_cnt) {     prms.clear();     prm_cnt.clear();     while (x > 1) {       long long t = minFactor(x);       prms.push_back(t);       int s = prms.size() - 1;       prm_cnt.push_back(0);       while (x % t == 0) {         x /= t;         ++prm_cnt[s];       }     }     return 0;   }   long long add(long long x, long long y) {     if (x >= 998244353) x %= 998244353;     if (y >= 998244353) y %= 998244353;     return (x + y) % 998244353;   }   long long mul(long long x, long long y) {     if (x >= 998244353) x %= 998244353;     if (y >= 998244353) y %= 998244353;     return (x * y) % 998244353;   }   long long pow_(long long x, long long y) {     if (y == 0) return 1ll;     if (y % 2 == 0) {       long long k = pow_(x, y / 2);       return (k * k) % 998244353;     } else {       return mul(x, pow_(x, y - 1));     }   }   long long n, m;   long long fact[2 * (int)(1e5) + 2], rfact[2 * (int)(1e5) + 2];   long long C(long long n, long long m) {     long long num = fact[n];     long long den = mul(rfact[m], rfact[n - m]);     return mul(num, den);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     fact[0] = fact[1] = rfact[0] = rfact[1] = 1ll;     for (long long i = 2; i <= 2 * (int)(1e5); ++i) {       fact[i] = mul(fact[i - 1], i);       rfact[i] = pow_(fact[i], 998244353 - 2);     }     cin >> n >> m;     if (n == 2) {       cout << 0 << endl;       return 0;     }     long long t = n - 1;     long long res = 0;     long long c = 0;     for (long long i = t; i <= m; ++i) {       long long cr = C(i - 1, t - 1);       c = add(c, cr);     }     long long t2 = pow_(2, t - 2);     res = mul(c, mul(max(t2, 1ll), t - 1));     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int isP(long int hj) {     long int op;     for (op = 2; op <= sqrt(hj); op++) {       if (hj % op == 0) return 0;     }     return 1;   }   void swap(long long int *p, long long int *q) {     long long int tmp = *p;     *p = *q;     *q = tmp;   }   void tog(int *p) {     if (*p == 1)       *p = 0;     else       *p = 1;   }   string fdi(int hi) {     switch (hi) {       case 0:         return  zero ;       case 1:         return  one ;       case 2:         return  two ;       case 3:         return  three ;       case 4:         return  four ;       case 5:         return  five ;       case 6:         return  six ;       case 7:         return  seven ;       case 8:         return  eight ;       case 9:         return  nine ;     }   }   string rdx(int hi) {     switch (hi) {       case 2:         return  twenty ;       case 3:         return  thirty ;       case 4:         return  forty ;       case 5:         return  fifty ;       case 6:         return  sixty ;       case 7:         return  seventy ;       case 8:         return  eighty ;       case 9:         return  ninety ;     }   }   long long int bd(long long int mk, long long int nk) {     long long int i;     for (i = min(mk, nk); i >= 1; i--) {       if (mk % i == 0 && nk % i == 0) return i;     }   }   int dsm(long long int pkk) {     if (pkk < 0) pkk *= -1;     while (pkk > 0) {       if (pkk % 10 == 8) return 1;       pkk /= 10;     }     return 0;   }   int main() {     long long int nk, l, nl, np, odI, evI, r, a1, a2, amt, maxu, y3, sx, sy, bsm,         fsm, bu, cp, bf, pr, res, lastm, c, r1, r2, x1, x2, y1, y2, maxN, m1, m2,         prev, prc, cost, ind, ans, g, p, inc, cap, sm, d, nxt, mn, t, up, a, b,         lc, la, e, preI, t2, brk, clbp, clb, et, jmp, u, l1, l2, sq, nd, maxi, li,         ri, tr, mp, og, lt1, lt2, n1, n2, c1, c2, minI, min1, p2, p3, ze, fst,         lst, min2, s, sm1, sm2, sm3, sr, sl, ln, rz, rn, car, eq, shr, ng, v,         curr, spl, fl, z, ev, od, m, ct, j, q, k, maxI, max1, max2, lt, md, f, n,         xP, xN, w, h, d2, d1, u1, u2, i, x, y;     cin >> n;     string st;     cin >> st;     a = 0;     b = 0;     if (st[0] ==  a )       a++;     else       b++;     ct = 0;     for (i = 1; i < n; i++) {       if (i % 2 != 0) {         if (st[i] ==  a )           a++;         else           b++;         if (a != b) {           ct++;           if (st[i] ==  a ) {             st[i] =  b ;             a--;             b++;           } else {             st[i] =  a ;             a++;             b--;           }         }       } else {         if (st[i] ==  a )           a++;         else           b++;       }     }     cout << ct << endl;     cout << st;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int q;   long long int input;   long long int lastSum[20];   long long int limit[20];   long long int targetSum(int digit, long long int target) {     long long int ret = lastSum[digit - 1] * target;     ret += target * (target + 1) * digit / 2;     return ret;   }   long long int targetSubSum(long long int target) {     if (target == 0) return 0;     int digit = 0;     long long int tmp = target, ret = 0, mul = 1;     while (tmp) digit++, tmp /= 10, mul *= 10;     ret += lastSum[digit - 1];     target -= (mul / 10) - 1;     ret += target * digit;     return ret;   }   int main() {     long long int mul = 9;     for (int digit = 1; digit < 10; digit++) {       lastSum[digit] = lastSum[digit - 1] + digit * mul;       limit[digit] = limit[digit - 1] + lastSum[digit - 1] * mul +                      digit * mul * (mul + 1) / 2;       mul *= 10;     }     scanf( %d , &q);     while (q) {       scanf( %lld , &input);       int digit = 1;       long long int low = 0, high = 9, answer = 1;       while (limit[digit] < input) digit++, high *= 10;       input -= limit[digit - 1];       while (low <= high) {         long long int mid = (low + high) / 2;         if (targetSum(digit, mid) <= input) {           answer = mid;           low = mid + 1;         } else           high = mid - 1;       }       long long int mul = 1;       for (int i = 1; i < digit; i++) mul *= 10;       input -= targetSum(digit, answer);       if (input == 0)         printf( %lld n , (answer + mul - 1) % 10);       else {         low = 0, high = answer + mul - 1, answer = 0;         while (low <= high) {           long long int mid = (low + high) / 2;           if (targetSubSum(mid) <= input) {             answer = mid;             low = mid + 1;           } else             high = mid - 1;         }         input -= targetSubSum(answer);         if (input == 0)           printf( %lld n , answer % 10);         else {           stack<int> s;           answer++;           while (answer) {             s.push(answer % 10);             answer /= 10;           }           for (int i = 1; i < input; i++) s.pop();           printf( %d n , s.top());         }       }       q--;     }   }
#include <bits/stdc++.h>   using namespace std;   long long BigMod(long long B, long long P, long long M) {     long long R = 1;     while (P > 0) {       if (P % 2 == 1) {         R = (R * B) % M;       }       P /= 2;       B = (B * B) % M;     }     return R;   }   template <class T1>   void deb(T1 e1) {     cout << e1 << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   const int MAX = 100060;   map<int, int> mpp;   int cnt[2][MAX];   int res[MAX];   int main() {     memset(cnt, (0), sizeof(cnt));     ;     vector<int> tmp, rval;     int v;     set<int> com;     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &v);       rval.push_back((v));       tmp.push_back((v));     }     sort(tmp.begin(), tmp.end());     for (int i = 0; i < n; i++) {       mpp[tmp[i]] = i + 1;     }     v = mpp[rval[0]];     com.insert(v);     for (int i = 1; i < n; i++) {       v = mpp[rval[i]];       auto it = com.lower_bound(v);       if (it != com.begin()) {         auto it1 = it;         it1--;         int u = (*it1);         if (cnt[0][u] != -1) {           res[i] = tmp[u - 1];           com.insert(v);           cnt[0][u]--;           continue;         }       }       if (it != com.end()) {         auto it1 = it;         int u = (*it1);         if (cnt[1][u] != -2) {           res[i] = tmp[u - 1];           com.insert(v);           cnt[1][u]--;           continue;         }       }     }     for (int i = 1; i < n; i++) {       if (i != 1) printf(   );       printf( %d , res[i]);     }     printf(  n );     return 0;   }