malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   int n, m;   int f[2000010], mx, mn = (int)1e7;   short check(int x) {     int i;     for (i = x; i <= mx; i += x)       if (f[i + x - 1] >= i && f[i + x - 1] - i > m) return 0;     return 1;   }   int main() {     int i, x;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) {       scanf( %d , &x);       f[x] = x;       mx = mx > x ? mx : x;       mn = mn < x ? mn : x;     }     mx <<= 1;     for (i = 1; i <= mx; i++) f[i] = f[i] > f[i - 1] ? f[i] : f[i - 1];     mx >>= 1;     for (i = mn; i > 1; i--)       if (check(i)) break;     printf( %d , i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string raspuns;   long long n, x, y;   int read() {     char c;     int nr = 0;     c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) {       nr = nr * 10 + (c -  0 );       c = getchar();     }     return nr;   }   int main() {     n = read();     long long sa, sg;     sa = sg = 0;     for (long long i = 0; i < n; i++) {       x = read();       y = read();       if (sa + x - sg <= 500) {         sa += x;         raspuns +=  A ;       } else if (sg + y - sa <= 500) {         sg += y;         raspuns +=  G ;       }     }     if (raspuns !=   0 )       cout << raspuns;     else       cout <<  -1 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     for (; b; a %= b, swap(a, b))       ;     return a;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, x;       cin >> n >> x;       int cnt = 0;       for (int i = 0; i < n - 1; i++) {         int u, v;         cin >> u >> v;         if (u == x || v == x) cnt++;       }       if (cnt <= 1) {         cout <<  Ayush n ;         continue;       }       if (n % 2)         cout <<  Ashish n ;       else         cout <<  Ayush n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   int in[maxn];   int t1, t2;   struct edge {     int v, w;   };   vector<edge> g[maxn];   void dfs(int u, int fa) {     if (in[u] == 1) {       if (!t1) t1 = u;       t2 = u;     }     for (edge e : g[u]) {       if (e.v == fa) continue;       dfs(e.v, u);     }   }   struct Ans {     int a, b, c;   };   vector<Ans> ans;   void add(int a, int b, int c) {     if (a == b || !c) return;     ans.push_back({a, b, c});   }   int main() {     int n;     cin >> n;     for (int i = 1; i < n; ++i) {       int u, v, w;       cin >> u >> v >> w;       in[u]++, in[v]++;       g[u].push_back({v, w});       g[v].push_back({u, w});     }     for (int i = 1; i <= n; ++i)       if (in[i] == 2) {         cout <<  NO  << endl;         return 0;       }     cout <<  YES  << endl;     for (int u = 1; u <= n; ++u) {       for (edge e : g[u]) {         int v = e.v, w = e.w;         if (v < u) continue;         int a1, a2, b1, b2;         t1 = t2 = 0;         dfs(u, v);         a1 = t1, a2 = t2;         t1 = t2 = 0;         dfs(v, u);         b1 = t1, b2 = t2;         add(a1, b1, w / 2);         add(a2, b2, w / 2);         add(a1, a2, -w / 2);         add(b1, b2, -w / 2);       }     }     cout << ans.size() << endl;     for (auto p : ans) cout << p.a <<     << p.b <<     << p.c << endl;   }
#include <bits/stdc++.h>   using namespace std;   namespace whatever {   int readu() {     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     int value = ch -  0 ;     ch = getchar();     while (isdigit(ch)) {       value = value * 10 + ch -  0 ;       ch = getchar();     }     return value;   }   void writeu(int n) {     if (n < 10)       putchar(n +  0 );     else {       writeu(n / 10);       putchar(n % 10 +  0 );     }   }   namespace tree {   vector<int> tree_adj[100001 + 100000];   int size[100001 + 100000];   int heavy[100001 + 100000];   int depth[100001 + 100000];   int father[100001 + 100000];   void dfs1(int cur) {     size[cur] = 1;     for (auto to : tree_adj[cur])       if (to != father[cur]) {         depth[to] = depth[cur] + 1;         father[to] = cur;         dfs1(to);         size[cur] += size[to];         if (size[heavy[cur]] < size[to]) heavy[cur] = to;       }   }   int top[100001 + 100000];   void dfs2(int cur) {     for (auto to : tree_adj[cur])       if (to != father[cur]) {         top[to] = (to == heavy[cur] ? top[cur] : to);         dfs2(to);       }   }   int lca(int a, int b) {     while (top[a] != top[b]) {       if (depth[top[a]] > depth[top[b]])         a = father[top[a]];       else         b = father[top[b]];     }     return (depth[a] < depth[b] ? a : b);   }   }  // namespace tree   namespace graph {   vector<int> adj[100001];   int dfn[100001];   int low[100001];   int dfs_time;   int stack[100001];   int top;   int bcc_cnt;   void dfs(int cur) {     dfn[cur] = low[cur] = ++dfs_time;     stack[top++] = cur;     for (auto to : adj[cur]) {       if (!dfn[to]) {         dfs(to);         low[cur] = min(low[cur], low[to]);         if (low[to] == dfn[cur]) {           ++bcc_cnt;           do {             --top;             tree::tree_adj[stack[top]].push_back(100000 + bcc_cnt);             tree::tree_adj[100000 + bcc_cnt].push_back(stack[top]);           } while (stack[top] != to);           tree::tree_adj[cur].push_back(100000 + bcc_cnt);           tree::tree_adj[100000 + bcc_cnt].push_back(cur);         }       } else         low[cur] = min(low[cur], dfn[to]);     }   }   }  // namespace graph   void run() {     int n = readu();     int m = readu();     int q = readu();     while (--m != -1) {       int u = readu();       int v = readu();       graph::adj[u].push_back(v);       graph::adj[v].push_back(u);     }     graph::dfs(1);     assert(graph::top == 1);     assert(graph::stack[0] == 1);     tree::dfs1(1);     assert(tree::size[1] == graph::bcc_cnt + n);     tree::dfs2(1);     while (--q != -1) {       int a = readu();       int b = readu();       int l = tree::lca(a, b);       int dis = tree::depth[a] - tree::depth[l] + tree::depth[b] - tree::depth[l];       assert(dis % 2 == 0);       writeu(dis / 2);       putchar(  n );     }   }   }  // namespace whatever   int main() { whatever::run(); }
#include <bits/stdc++.h>   using namespace std;   const int mxN = 20;   int n, m, a[mxN][mxN], c[4][2] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};   vector<vector<int>> ops, cs{{0, 2, 3, 1}, {2, 4, 5, 3}, {0, 2, 4, 5, 3, 1}};   array<int, 2> p[mxN * mxN + 1];   set<vector<int>> vis;   void oc(int i1, int j1, bool b) {     ops.push_back({});     for (int i = 0; i < 4; ++i)       ops.back().push_back(a[i1 + c[i ^ b][0]][j1 + c[i ^ b][1]]);     for (int i = 2; i >= 0; --i)       swap(a[i1 + c[i ^ b][0]][j1 + c[i ^ b][1]],            a[i1 + c[(i + 1) ^ b][0]][j1 + c[(i + 1) ^ b][1]]);     for (int i = 0; i < 4; ++i)       p[a[i1 + c[i][0]][j1 + c[i][1]]] = {i1 + c[i][0], j1 + c[i][1]};   }   void cr(bool b) {     for (int i = n - 1; i > 2 - b; --i) {       for (int j = m - 1; j >= 0; --j) {         int d = b ? (j < 2 ? j ^ 1 : j) * n + i + 1                   : i * m + (j < 2 ? j ^ 1 : j) + 1,             ti = j ? i : i - 1, tj = j ? j : 1;         if (!j && p[d][0] == i) {           oc(i - 1, 0, 0);           oc(i - 2, 0, 0);           oc(i - 2, 0, 0);           oc(i - 1, 0, 1);           oc(i - 2, 0, 0);           break;         }         if (!p[d][0]) oc(0, p[d][1] - (p[d][1] > 0), !p[d][1]);         if (!p[d][1]) oc(p[d][0] - 1, 0, 1);         while (p[d][1] < tj) oc(p[d][0] - 1, p[d][1], 1);         while (p[d][1] > tj) oc(p[d][0] - 1, p[d][1] - 1, 0);         while (p[d][0] < ti) oc(p[d][0], p[d][1] - 1, 0);       }       oc(i - 1, 0, 0);     }   }   bool dfs(vector<int> &u) {     bool ok = 1;     for (int i = 0; i < 5 && ok; ++i) ok = u[i] < u[i + 1];     if (ok) return 1;     vis.insert(u);     for (vector<int> &c : cs) {       vector<int> v = u;       ops.push_back({});       for (int ci : c) ops.back().push_back(u[ci]);       for (int i = c.size() - 2; i >= 0; --i) swap(v[c[i]], v[c[i + 1]]);       if (vis.find(v) == vis.end() && dfs(v)) return 1;       ops.pop_back();     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) cin >> a[i][j], p[a[i][j]] = {i, j};     cr(0);     for (int i = 0; i < n; ++i)       for (int j = i + 1; j < m; ++j) swap(a[i][j], a[j][i]);     for (int i = 1; i <= n * m; ++i) swap(p[i][0], p[i][1]);     swap(n, m);     cr(1);     vector<int> v;     for (int j = 0; j < 3; ++j)       for (int i = 0; i < 2; ++i) v.push_back(a[i][j]);     dfs(v);     cout << ops.size();     for (vector<int> op : ops) {       cout <<   n  << op.size();       for (int oi : op) cout <<     << oi;     }   }
#include <bits/stdc++.h>   using namespace std;   void solve(vector<int> &v, int n, int k) {     set<int> s;     for (int i = 0; i < n; i++) s.insert(v[i]);     if (s.size() >= k) {       vector<int> res;       cout <<  YES  << endl;       for (auto x : s) {         for (int i = 0; i < n; i++) {           if (x == v[i]) {             res.push_back(i + 1);             break;           }         }       }       for (int i = 0; i < k; i++) {         cout << res[i] <<    ;       }       cout << endl;     } else       cout <<  NO  << endl;   }   int main() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     solve(a, n, k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   int n, a[7], cnt[7], t[N];   void GetData() {     int i;     scanf( %d , &n);     for (i = 0; i < 3; ++i) scanf( %d , &a[i]);     for (i = 0; i < n; ++i) scanf( %d , &t[i]);   }   void Solve() {     int i, j, ans, mn;     bool flag = false;     sort(a, a + 3);     sort(t, t + n);     a[3] = a[0] + a[1];     a[4] = a[0] + a[2];     a[5] = a[1] + a[2];     a[6] = a[3] + a[2];     if (t[n - 1] > a[6])       ans = -1, mn = 0;     else {       if (a[2] > a[3]) {         swap(a[2], a[3]);         flag = true;       }       memset(cnt, 0, sizeof(cnt));       for (i = 0; i < n; ++i) {         for (j = 0; j < 7; ++j) {           if (a[j] >= t[i]) {             cnt[j]++;             break;           }         }       }       ans = cnt[6];       for (; cnt[5] > 0; ++ans) {         cnt[5]--;         if (cnt[0] > 0) cnt[0]--;       }       for (; cnt[4] > 0; ++ans) {         cnt[4]--;         if (cnt[1] > 0)           cnt[1]--;         else if (cnt[0] > 0)           cnt[0]--;       }       if (flag) {         for (; cnt[3] > 0; ++ans) {           cnt[3]--;           if (cnt[0] > 0 && cnt[1] > 0) {             cnt[0]--;             cnt[1]--;           } else if (cnt[0] > 0) {             if (cnt[0] > 1)               cnt[0] -= 2;             else if (cnt[2] > 0)               cnt[2]--;             else               cnt[0]--;           } else if (cnt[1] > 0) {             if (cnt[2] > 0)               cnt[2]--;             else               cnt[1]--;           } else if (cnt[2] > 0)             cnt[2]--;         }       } else {         for (; cnt[3] > 0; ++ans) {           cnt[3]--;           if (cnt[2] > 0)             cnt[2]--;           else if (cnt[1] > 0)             cnt[1]--;           else if (cnt[0] > 0)             cnt[0]--;         }       }       mn = n;       for (i = 0; i <= cnt[2]; ++i) {         int a, b, c, tmp = i;         a = cnt[0];         b = cnt[1];         c = cnt[2];         c -= i;         if (c >= i)           c -= i;         else if (b >= i - c)           b -= i - c, c = 0;         else {           if (a >= i - c - b)             a -= i - c - b;           else             a = 0;           b = c = 0;         }         if (c > 0) {           if (b < c)             a = max(0, a - c - c + b);           else             a = max(0, a - c);           b = max(0, b - c);           tmp += c;         }         if (b >= a * 2)           tmp += (b + 1) / 2;         else           tmp += (a + b + 2) / 3;         mn = min(mn, tmp);       }     }     printf( %d n , ans + mn);   }   int main() {     GetData();     Solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     cin.tie(0);     cout.tie(0);     cin.sync_with_stdio(0);     cout.sync_with_stdio(0);     long long n;     cin >> n;     vector<long long> v(n);     vector<long long> msuf(n + 1);     for (long long i = 0; i < n; ++i) cin >> v[i];     for (long long i = n - 1; i >= 0; --i)       msuf[i] = max(v[i] + 1, msuf[i + 1] - 1);     for (long long i = 1; i < n; ++i) msuf[i] = max(msuf[i], msuf[i - 1]);     long long second = 0;     for (long long i = 0; i < n; ++i) second += msuf[i] - v[i] - 1;     cout << second << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   const long long MOD = 1e9 + 7;   const long long MODD = 1e9 + 1;   const long long MODL = 998244353;   const long long N = 200005;   const long long INF = 1e18;   const long long mx = 1e5 + 1;   long long Power(long long x, long long y) {     long long r = 1;     while (y) {       if (y & 1) r = 1ll * r * x % MOD;       x = 1ll * x * x % MOD, y >>= 1;     }     return r;   }   bool sortbysec(const pair<int, int>& a, const pair<int, int>& b) {     return (a.second < b.second);   }   bool sortstring(const string& a, const string& b) { return a + b < b + a; }   long long GCD(long long a, long long b) {     if (b == 0) return a;     a %= b;     return GCD(b, a);   }   bool isZero(int i) { return i == 0; }   int ce(int n, int m) {     int ans = 0;     if (n % m == 0)       ans = n / m;     else       ans = n / m + 1;     return ans;   }   int solve(int n) {     int m, k;     cin >> m >> k;     int p = 0;     int q = 0, qq = 0;     int r = 0;     int x = ce(n, m);     int s = 0;     if (n % m != 0) {       for (int i = n - 1; i >= 0; i--) {         if (i % x == 0 && (n - i) % (n / m) == 0 &&             (i / x + (n - i) / (n / m) == m)) {           s = i;           break;         }       }     }     s = (n - s) / (n / m);     for (int i = 0; i < k; i++) {       for (int j = 0; j < m - s; j++) {         cout << x <<    ;         r = j * x + p;         for (int k = 0; k < x; k++) {           cout << r % n + 1 <<    ;           q = r % n;           r++;         }         cout <<   n ;       }       qq = q;       for (int j = 0; j < s; j++) {         cout << n / m <<    ;         r = q + 1;         for (int k = 0; k < n / m; k++) {           cout << r % n + 1 <<    ;           q = r % n;           r++;         }         cout <<   n ;       }       p = qq + 1;     }     cout <<   n ;     return 0;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     int n = 0;     cin >> t;     while (t--) {       cin >> n;       solve(n);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int e = 0;     int d;     int a[15], b[15], l[10];     for (int f = 0; f < n; f++) cin >> a[f];     for (int j = 0; j < m; j++) cin >> b[j];     int rr = 0, tt = 0;     for (int g = 0; g < n; g++) {       if (a[g] < 0 || a[g] > 9) {         for (int r = g; r < n; r++) a[r] = a[r + 1];         rr++;       }     }     for (int h = 0; h < m; h++) {       if (b[h] < 0 || b[h] > 9) {         for (int t = h; t < m; t++) b[t] = b[t + 1];         tt++;       }     }     if (n >= 0 && n <= 10 && m >= 0 && m <= 10) {       for (int c = 0; c < n - rr; c++) {         for (int d = 0; d < m - tt; d++) {           if (a[c] == b[d]) {             l[e] = a[c];             e++;           }         }       }       for (int k = 0; k < e; k++) cout << l[k] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, a;     cin >> n >> k;     list<int> lst;     map<int, bool> vis;     for (int i = 0; i < n; i++) {       cin >> a;       if (lst.size() < k) {         if (vis.find(a) == vis.end()) {           lst.push_front(a);           vis[a] = true;         }         continue;       }       if (vis.find(a) == vis.end() || vis[a] == false) {         vis[a] = true;         vis[lst.back()] = false;         lst.pop_back();         lst.push_front(a);       }     }     cout << lst.size() << endl;     for (auto it = lst.begin(); it != lst.end(); it++) cout << (*it) <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y;   } A[10005], B[10005], CA[10005], CB[10005];   int tim, qim;   node operator+(node a, node b) { return node{a.x + b.x, a.y + b.y}; }   node operator-(node a, node b) { return node{a.x - b.x, a.y - b.y}; }   int operator*(node a, node b) { return a.x * b.x + a.y * b.y; }   int operator/(node a, node b) { return a.x * b.y - a.y * b.x; }   bool operator<(node a, node b) {     if (a.x == b.x) return a.y > b.y;     return a.x < b.x;   }   void convex_hull(node p[], node c[], int n, int &tp) {     sort(p + 1, p + n + 1);     tp = 0;     for (int i = 1; i <= n; i++) {       while (tp > 1 && (c[tp] - p[i]) / (c[tp - 1] - p[i]) >= 0) tp--;       c[++tp] = p[i];     }     int k = tp--;     for (int i = n; i >= 1; i--) {       while (tp > k && (c[tp] - p[i]) / (c[tp - 1] - p[i]) >= 0) tp--;       c[++tp] = p[i];     }     tp--;   }   bool solve(node a[], node b[], int na, int nb) {     random_shuffle(a + 1, a + na + 1);     random_shuffle(b + 1, b + nb + 1);     for (int i = 1; i <= na; i++)       for (int j = i + 1, k; j <= na; j++) {         node pa = a[i], pb = a[j];         double lp = -1e100, rp = 1e100, inf = 1e100;         for (k = 1; k <= na; k++) {           if (k == i) continue;           if (k == j) continue;           int ta = (a[k] - pa) * (a[k] - pb);           int tb = (pa - a[k]) / (pa - pb);           assert(tb != 0);           if (tb == 0) {             if (ta > 0)               break;             else               continue;           }           double r = (double)ta / tb;           if (tb < 0)             rp = min(rp, r);           else if (tb > 0)             lp = max(lp, r);           if (lp > rp) break;         }         if (k <= na || lp > rp) continue;         for (k = 1; k <= nb; k++) {           int ta = (b[k] - pa) * (b[k] - pb);           int tb = (pa - b[k]) / (pa - pb);           if (tb == 0) {             if (ta <= 0)               break;             else               continue;           }           double r = (double)ta / tb;           if (tb > 0)             rp = min(rp, r);           else if (tb < 0)             lp = max(lp, r);           if (lp >= rp) break;         }         if (k > nb && lp < rp) return 1;       }     return 0;   }   int main() {     srand(time(NULL));     clock_t st, ed;     double totaltime;     st = clock();     int n, m, cn, cm, i;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) scanf( %d%d , &A[i].x, &A[i].y);     for (i = 1; i <= m; i++) scanf( %d%d , &B[i].x, &B[i].y);     if (n == 1 || m == 1) return puts( YES ), 0;     convex_hull(A, CA, n, cn);     convex_hull(B, CB, m, cm);     if (solve(CA, B, cn, m) || solve(CB, A, cm, n))       puts( YES );     else       puts( NO );     ed = clock();     totaltime = (double)(ed - st) / CLOCKS_PER_SEC;   }
#include <bits/stdc++.h>   using namespace std;   int ky[8] = {-1, 1, -2, 2, -2, 2, -1, 1};   int kx[8] = {-2, -2, -1, -1, 1, 1, 2, 2};   int dy[4] = {-1, 0, 1, 0};   int dx[4] = {0, 1, 0, -1};   int ddy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};   int ddx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};   const double PI = acos(-1.0);   int n;   int c, p;   int k;   int num;   struct Group {     int c, p, idx;   };   Group a[1000];   Group b[1000];   pair<int, int> t[1000];   int ret1, ret2;   int cnt1, cnt2;   set<int> s;   vector<pair<int, int>> pos1, pos2;   int ns;   bool comp1(const Group &x, const Group &y) {     return x.p > y.p || (x.p == y.p && x.c < y.c);   }   bool comp2(const Group &x, const Group &y) {     return x.c < y.c || (x.c == y.c && x.p > y.p);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> c >> p;       a[i].c = c;       a[i].p = p;       a[i].idx = i + 1;       b[i].c = c;       b[i].p = p;       b[i].idx = i + 1;     }     sort(a, a + n, comp1);     sort(b, b + n, comp2);     cin >> k;     for (int i = 0; i < k; i++) {       cin >> num;       t[i].first = num;       t[i].second = i + 1;     }     sort(t, t + k);     for (int i = 0; i < n; i++) {       for (int j = 0; j < k; j++) {         if (s.count(j)) continue;         if (a[i].c <= t[j].first) {           ret1 += a[i].p;           cnt1++;           pos1.push_back({a[i].idx, t[j].second});           s.insert(j);           break;         }       }     }     s.clear();     for (int i = 0; i < n; i++) {       for (int j = 0; j < k; j++) {         if (s.count(j)) continue;         if (b[i].c <= t[j].first) {           ret2 += b[i].p;           cnt2++;           pos2.push_back({b[i].idx, t[j].second});           s.insert(j);           break;         }       }     }     if (ret1 <= ret2) {       cout << cnt2 <<     << ret2 <<   n ;       ns = pos2.size();       for (int i = 0; i < ns; i++)         cout << pos2[i].first <<     << pos2[i].second <<   n ;     } else {       cout << cnt1 <<     << ret1 <<   n ;       ns = pos1.size();       for (int i = 0; i < ns; i++)         cout << pos1[i].first <<     << pos1[i].second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int di[] = {0, 0, 1, -1, 1, 1, -1, -1};   int dj[] = {1, -1, 0, 0, 1, -1, 1, -1};   inline int calcMedian(vector<int> &vec) {     if (((int)vec.size()) % 2 == 1) {       return vec[((int)vec.size()) / 2];     }     return (vec[((int)vec.size()) / 2 - 1] + vec[((int)vec.size()) / 2]) / 2;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long init = 0, ans = 0;     int n, m;     cin >> n >> m;     vector<int> vec(m);     vector<vector<int> > adj(n);     for (int i = 0; i < m; ++i) {       cin >> vec[i];       --vec[i];       if (i && vec[i] != vec[i - 1]) {         ans = init += abs(vec[i] - vec[i - 1]);         adj[vec[i]].push_back(vec[i - 1]);         adj[vec[i - 1]].push_back(vec[i]);       }     }     for (int i = 0; i < n; ++i)       if (((int)adj[i].size())) {         sort(adj[i].begin(), adj[i].end());         int median = calcMedian(adj[i]);         long long tmp = 0;         for (int j = 0; j < ((int)adj[i].size()); ++j) {           tmp -= 0LL + abs(adj[i][j] - i);           tmp += 0LL + abs(adj[i][j] - median);         }         if (init + tmp < ans) ans = init + tmp;       }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     ;     string s;     int flag = 0;     cin >> s;     string at =  at , dot =  dot ;     for (int i = 1; i < s.size() - 3; i++) {       if (s.substr(i, 2) == at && flag == 0) {         s.replace(i, 2,  @ );         flag = 1;       }       if (s.substr(i, 3) == dot) {         s.replace(i, 3,  . );       }     }     int j = s.size() - 3;     if (s.substr(j, 2) == at && flag == 0) s.replace(j, 2,  @ );     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long int n, max = 0;     cin >> n;     map<string, long long int> m;     string s;     while (n--) {       cin >> s;       m[s]++;     }     for (auto it = m.begin(); it != m.end(); it++) {       if (it->second > max) {         max = it->second;         s = it->first;       }     }     cout << s << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int maxn = 2 * 1e5;   char s[maxn];   int n;   int l, r;   int is_pal(int l, int r) {     for (int i = l; i <= (r + l) / 2; i++) {       if (s[i] != s[r - (i - l)]) return 0;     }     return 1;   }   int main() {     cin >> (s + 1);     r = strlen(s + 1);     while (is_pal(1, r) && r % 2 == 0 && r) {       r /= 2;     }     if (!is_pal(1, r)) {       cout << 1 << endl;     } else {       r = strlen(s + 1);       for (int i = 1; i <= r / 2; i++) {         if (!is_pal(1, i)) {           cout << 2 << endl;           return 0;         }       }       cout <<  Impossible  << endl;     }     return 0;   }