malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline int Max(int a, int b) { return (a > b ? a : b); }   inline int Min(int a, int b) { return (a > b ? b : a); }   int dp[45][65][65];   int cnt[65], K;   void Init() {     for (int i = 0; i < 65; i++) {       int n = i;       int x = 0;       while (n) {         x++;         n &= (n - 1);       }       cnt[i] = x;     }   }   int get(int num) {     int k = K - 1;     return (num | ((num >> 1)) | ((num << 1) & k));   }   int main() {     int i, j, k, t;     int a, b, c, x, y, z;     int n, m;     Init();     while (scanf( %d%d , &n, &m) != EOF) {       if (n > m) swap(n, m);       K = (1 << n);       if (m == 1 && n == 1) {         puts( 0 );         continue;       }       for (i = 0; i < K; i++)         for (j = 0; j < K; j++) {           if ((i | get(j)) == K - 1) {             dp[2][i][j] = cnt[i] + cnt[j];           } else             dp[2][i][j] = 100000000;         }       for (i = 3; i <= m; i++)         for (j = 0; j < K; j++)           for (k = 0; k < K; k++) {             dp[i][j][k] = 100000000;             for (t = 0; t < K; t++) {               int my = j | get(k) | t;               if (dp[i - 1][k][t] == 100000000 || my != K - 1) continue;               dp[i][j][k] = Min(dp[i][j][k], dp[i - 1][k][t] + cnt[j]);             }           }       int ans = 100000000;       for (j = 0; j < K; j++)         for (k = 0; k < K; k++)           for (t = 0; t < K; t++) {             if ((get(t | j) | k) != K - 1) continue;             ans = Min(ans, dp[m][j][k] + cnt[t]);           }       printf( %d n , n * m - ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct ms {     string s;     int id;   };   bool operator<(const ms &a, const ms &b) { return a.s < b.s; }   vector<ms> sv, msv[11];   string s;   int n, lenmin = 11, lenmax = 0;   bool used[10000] = {false};   int main(void) {     int i;     cin >> n;     sv.reserve(n);     for (i = 0; i < n; ++i) {       cin >> s;       if ((int)s.length() > lenmax) lenmax = s.length();       if ((int)s.length() < lenmin) lenmin = s.length();       ms sid = {s, i};       sv.push_back(sid);       msv[s.length()].push_back(sid);     }     cin >> s;     for (i = 0; i < n; ++i) sv[i].s.append(s);     sort(sv.begin(), sv.end());     for (i = 1; i <= 10; ++i) {       sort(msv[i].begin(), msv[i].end());       reverse(msv[i].begin(), msv[i].end());     }     lenmax = lenmax + lenmin;     for (i = 0; i < n; ++i)       if (!used[sv[i].id]) {         cout << sv[i].s;         used[sv[i].id] = true;         lenmin = lenmax - sv[i].s.length() + 1;         while (used[msv[lenmin].back().id]) msv[lenmin].pop_back();         cout << msv[lenmin].back().s <<   n ;         used[msv[lenmin].back().id] = true;         msv[lenmin].pop_back();       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Szukaj(vector<int>& moje, vector<bool>& jest, int x) {     int nr = -1;     for (int i = 0; i < moje.size(); ++i) {       if (moje[i] >= x && jest[i]) {         if (nr == -1)           nr = i;         else {           if (moje[i] < moje[nr]) nr = i;         }       }     }     return nr;   }   int main() {     ios_base::sync_with_stdio(0);     int n, m;     cin >> n >> m;     vector<int> atk, def;     for (int i = 0; i < n; ++i) {       string op;       int s;       cin >> op >> s;       if (op ==  ATK )         atk.push_back(s);       else         def.push_back(s);     }     vector<int> moje(m);     for (int i = 0; i < m; ++i) cin >> moje[i];     int odp = 0;     sort(atk.begin(), atk.end());     sort(moje.begin(), moje.end());     reverse(moje.begin(), moje.end());     for (int i = 1; i <= min(atk.size(), moje.size()); ++i) {       vector<int> a, b;       for (int j = 0; j < i; ++j) a.push_back(moje[j]);       for (int j = i - 1; j >= 0; --j) b.push_back(atk[j]);       int s = 0;       bool ok = true;       for (int j = 0; j < i; ++j) {         if (a[j] >= b[j])           s += a[j] - b[j];         else           ok = false;       }       if (ok) odp = max(odp, s);     }     bool ok = true;     int s = 0;     vector<bool> jest(moje.size(), true);     sort(def.begin(), def.end());     for (int i = 0; i < def.size(); ++i) {       int nr = Szukaj(moje, jest, def[i] + 1);       if (nr != -1)         jest[nr] = false;       else         ok = false;     }     for (int i = 0; i < atk.size(); ++i) {       int nr = Szukaj(moje, jest, atk[i]);       if (nr != -1) {         jest[nr] = false;         s += moje[nr] - atk[i];       } else         ok = false;     }     for (int i = 0; i < moje.size(); ++i)       if (jest[i]) s += moje[i];     if (ok) odp = max(odp, s);     cout << odp;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int d, s;     int id;   };   node a[100009], b[100009];   map<int, int> Map;   vector<int> e[100009], vec;   int match[100009];   int vis[100009];   int n, m;   bool cmp(node x, node y) { return x.d > y.d; }   bool find(int x) {     for (int i = 0; i < e[x].size(); i++) {       if (match[e[x][i]] == x) continue;       if (match[e[x][i]] == 0 || find(match[e[x][i]])) {         match[e[x][i]] = x;         return true;       }     }     return false;   }   int main() {     int d, s;     scanf( %d , &n);     memset(match, 0, sizeof(match));     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a[i].d, &a[i].s);       a[i].id = i;       Map[a[i].s] = i;     }     cin >> m;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &d, &s);       if (Map.find(s) != Map.end()) {         if (a[Map[s]].d <= d) e[Map[s]].push_back(i);       }       if (Map.find(s + 1) != Map.end()) {         if (a[Map[s + 1]].d <= d) e[Map[s + 1]].push_back(i);       }     }     sort(a + 1, a + 1 + n, cmp);     long long ans1 = 0, ans2 = 0;     for (int i = 1; i <= n; i++) {       if (find(a[i].id)) {         ans1++;         ans2 += a[i].d;       }     }     cout << ans2 << endl;     cout << ans1 << endl;     for (int i = 1; i <= m; i++) {       if (match[i] != 0) cout << i <<     << match[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = (1 << 18) + 5;   const int MAXM = 1005;   bitset<MAXM> STree[MAXN], Prime, mask;   int Lazy[MAXN], a[MAXN], in[MAXN], out[MAXN], time_tag, n, m, H[MAXN];   vector<int> G[MAXN];   void dfs(int i, int fa) {     in[i] = ++time_tag;     H[in[i]] = i;     for (int v : G[i]) {       if (v == fa) continue;       dfs(v, i);     }     out[i] = time_tag;   }   void init(int k, int l, int r) {     if (r == l) return;     if (r - l == 1) {       STree[k][a[H[l]]] = 1;       return;     }     int m = l + r >> 1;     init(k << 1, l, m);     init(k << 1 | 1, m, r);     STree[k] = STree[k << 1] | STree[k << 1 | 1];     return;   }   void inline push_down(int k) {     if (Lazy[k]) {       (Lazy[k << 1] += Lazy[k]) %= m;       (Lazy[k << 1 | 1] += Lazy[k]) %= m;       STree[k << 1] = ((STree[k << 1] << Lazy[k]) & mask) |                       ((STree[k << 1] >> (m - Lazy[k])) & mask);       STree[k << 1 | 1] = ((STree[k << 1 | 1] << Lazy[k]) & mask) |                           ((STree[k << 1 | 1] >> (m - Lazy[k])) & mask);       Lazy[k] = 0;     }   }   void inline maintain(int k) {     STree[k] = STree[k << 1] | STree[k << 1 | 1];     return;   }   void modify(int k, int l, int r, int ql, int qr, int val) {     if (ql >= r || qr <= l) return;     if (ql <= l && r <= qr) {       (Lazy[k] += val) %= m;       STree[k] = ((STree[k] << val) & mask) | ((STree[k] >> (m - val)) & mask);       return;     }     push_down(k);     int m = l + r >> 1;     modify(k << 1, l, m, ql, qr, val);     modify(k << 1 | 1, m, r, ql, qr, val);     maintain(k);   }   bitset<MAXM> query(int k, int l, int r, int ql, int qr) {     if (ql >= r || qr <= l) return bitset<MAXM>();     if (ql <= l && r <= qr) return STree[k];     push_down(k);     int m = l + r >> 1;     bitset<MAXM> ret =         query(k << 1, l, m, ql, qr) | query(k << 1 | 1, m, r, ql, qr);     maintain(k);     return ret;   }   int main() {     Prime = ~Prime;     Prime[0] = Prime[1] = 0;     for (int i = (2); i < (1001); i++) {       if (Prime[i]) {         for (int j = i + i; j <= 1000; j += i) {           Prime[j] = 0;         }       }     }     scanf( %d%d , &n, &m);     for (int i = (0); i < (m); i++) mask[i] = 1;     for (int i = (1); i < (n + 1); i++) scanf( %d , a + i), a[i] %= m;     for (int i = (1); i < (n); i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v), G[v].push_back(u);     }     dfs(1, -1);     init(1, 1, time_tag + 1);     int q;     scanf( %d , &q);     for (int cas = (0); cas < (q); cas++) {       int op, v, x;       scanf( %d , &op);       if (op == 1) {         scanf( %d%d , &v, &x);         modify(1, 1, time_tag + 1, in[v], out[v] + 1, x % m);       } else {         scanf( %d , &v);         bitset<MAXM> res = Prime & query(1, 1, time_tag + 1, in[v], out[v] + 1);         printf( %d n , res.count());       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 600 + 5;   const int M = 2e5 + 5;   template <class T>   inline void getin(T& num) {     char c;     bool flag = 0;     num = 0;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) flag = 1;     while (c >=  0  && c <=  9 ) {       num = num * 10 + c - 48;       c = getchar();     }     if (flag) num = -num;   }   int n, m, u, v, In[N];   int tot, x[N], y[N], Out[N];   int cnt, fir[N], tar[M], nxt[M];   long long p, f[N][N], a[N][N];   inline void link(int a, int b) {     tar[++cnt] = b, In[b]++, Out[a]++;     nxt[cnt] = fir[a], fir[a] = cnt;   }   template <class T>   inline void add(T& a, T b) {     a += b;     if (a >= p) a -= p;   }   inline void Dp() {     queue<int> q;     int c = 0;     for (int i = 1; i <= n; i++) {       if (!In[i]) x[++tot] = i;       if (!Out[i]) y[++c] = i;     }     for (int i = 1; i <= n; i++) f[i][i] = 1;     for (int i = 1; i <= n; i++)       if (!In[i]) q.push(i);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = fir[u]; i; i = nxt[i]) {         int v = tar[i];         for (int i = 1; i <= n; i++) add(f[i][v], f[i][u]);         In[v]--;         if (!In[v]) q.push(v);       }     }     for (int i = 1; i <= tot; i++)       for (int j = 1; j <= tot; j++) a[i][j] = f[x[i]][y[j]];   }   inline int calc(int n) {     int ret = 1;     for (int i = 1; i <= n; i++) {       if (a[i][i] < 0) {         ret = -ret;         for (int k = i; k <= n; k++) a[i][k] = -a[i][k];       }       for (int j = i + 1; j <= n; j++) {         for (int k = i; k <= n; k++) a[i][k] %= p, a[j][k] %= p;         while (a[j][i]) {           if (a[j][i] < 0) {             ret = -ret;             for (int k = i; k <= n; k++) a[j][k] = -a[j][k];           }           int t = a[i][i] / a[j][i];           for (int k = i; k <= n; k++) a[i][k] = (a[i][k] - t * a[j][k]) % p;           for (int k = i; k <= n; k++) swap(a[i][k], a[j][k]);           ret = -ret;         }       }       if (a[i][i] == 0) return 0;       ret = 1ll * ret * a[i][i] % p;     }     return (ret + p) % p;   }   int main() {     getin(n), getin(m), getin(p);     for (int i = 1; i <= m; i++) getin(u), getin(v), link(u, v);     Dp();     cout << calc(tot) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   bool is_right(complex<long long> p1, complex<long long> p2,                 complex<long long> p3) {     return (conj(p2 - p1) * (p3 - p1)).imag() < 0;   }   const int N = 1e5 + 5;   vector<complex<long long> > U;   complex<long long> a[N];   int n;   void read_input() {     cin >> n;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       a[i] = complex<long long>(x, y - 1LL * x * x);     }   }   void solve() {     sort(a, a + n, [](complex<long long> a, complex<long long> b) {       return make_pair(a.real(), a.imag()) < make_pair(b.real(), b.imag());     });     for (int i = 0; i < n; U.push_back(a[i++]))       while (U.size() > 1 && !is_right(U[U.size() - 2], U.back(), a[i]))         U.pop_back();     cout << U.size() - (U.size() > 1 && U[0].real() == U[1].real()) - 1;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     read_input(), solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool chkmin(T& x, T y) {     return x > y ? x = y, true : false;   }   template <class T>   inline bool chkmax(T& x, T y) {     return x < y ? x = y, true : false;   }   inline int read(void) {     int x, f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return x * f;   }   template <typename T>   struct Graph {     enum { maxn = 305, maxm = 200000 };     struct Edge {       int to, nxt;       T w, cap, flow;     } v[maxm];     int h[maxn], cnt;     Graph() { memset(h, -1, sizeof(h)); }     void add1(int x, int y, T w, T cap) {       v[cnt] = Edge{y, h[x], w, cap, 0};       h[x] = cnt++;     }     void add(int x, int y, T w, T cap) {       add1(x, y, w, cap);       add1(y, x, -w, 0);     }   };   Graph<int> G;   int Ss, Se;   static int f[305];   int dfs(int x, int re) {     if (x == Se || re <= 0) return re;     int s1 = 0, t;     for (int i = G.h[x]; i != -1; i = G.v[i].nxt) {       int to = G.v[i].to;       if (f[to] != f[x] + 1) continue;       t = dfs(to, min(re, G.v[i].cap - G.v[i].flow));       G.v[i].flow += t;       G.v[i ^ 1].flow -= t;       s1 += t;       re -= t;       if (re == 0) break;     }     return s1;   }   bool bfs(int x) {     queue<int> Q;     memset(f, -1, sizeof(f));     Q.push(x);     f[x] = 0;     while (!Q.empty()) {       int u = Q.front();       Q.pop();       for (int i = G.h[u]; i != -1; i = G.v[i].nxt) {         if (G.v[i].flow >= G.v[i].cap) continue;         int to = G.v[i].to;         if (f[to] != -1) continue;         f[to] = f[u] + 1;         Q.push(to);       }     }     return f[Se] != -1;   }   int dinic() {     int ans = 0;     while (bfs(Ss)) ans += dfs(Ss, 1000000000);     return ans;   }   bool vi[305];   int n, lk[305], v, x, ans, w;   vector<int> V[305];   bool dfs(int x) {     vi[x] = 1;     for (int i = 0; i <= V[x].size() - 1; ++i) {       int to = V[x][i];       if (!lk[to] || (!vi[lk[to]] && dfs(lk[to]))) {         lk[to] = x;         return 1;       }     }     return 0;   }   int main(void) {     n = read();     for (int i = 1; i <= n; ++i) {       v = read();       while (v--) {         x = read();         V[i].push_back(x);       }     }     for (int i = 1; i <= n; ++i) {       memset(vi, 0, sizeof(vi));       dfs(i);     }     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= V[i].size() - 1; ++j)         G.add(i, lk[V[i][j]], 0, 1000000000);     Ss = n + 1;     Se = n + 2;     for (int i = 1; i <= n; ++i) {       w = -read();       if (w < 0)         G.add(i, Se, 0, -w);       else         G.add(Ss, i, 0, w), ans += w;     }     printf( %d n , -(ans - dinic()));     return 0;   }
#include <bits/stdc++.h>   int valid(char prev, char next) {     char s[] =  aeioun ;     for (int i = 0; i < 6; i++)       if (prev == s[i]) return 1;     for (int i = 0; i < 5; i++)       if (next == s[i]) return 1;     return 0;   }   int main() {     char s[300];     scanf( %s , s);     int v = 1;     for (int i = 0; s[i] !=   0 ; i++) v &= valid(s[i], s[i + 1]);     printf( %s n , v ?  Yes  :  No );   }
#include <bits/stdc++.h>   using namespace std;   map<pair<long long, long long>, pair<long long, long long> > mp;   long long n;   pair<long long, long long> solve(pair<long long, long long> a) {     if (a.second < 10)       return make_pair(a.first || a.second, a.second - max(a.first, a.second));     if (mp[a].first) return mp[a];     long long ans = 0, p = 1;     while (a.second >= p * 10) p *= 10;     pair<long long, long long> b =         solve(make_pair(max(a.first, a.second / p), a.second % p));     ans += b.first;     pair<long long, long long> c =         solve(make_pair(a.first, a.second / p * p + b.second));     ans += c.first;     return mp[a] = make_pair(ans, c.second);   }   int main() {     cin >> n;     cout << solve(make_pair(0, n)).first;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int k;   int n1, n2, n3;   int t1, t2, t3;   int v1[3000];   int v2[3030];   int v3[3030];   int main() {     ios::sync_with_stdio(false);     cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;     int time = t1 + t2 + t3 - 1;     int pos = 0;     int res = 0;     for (int i = 0; i <= time + 1; i++) {       v1[i] = 0;       v2[i] = 0;       v3[i] = 0;     }     for (int i = 1; i <= k; i++) {       int posnew = -1;       for (int j = pos; j <= pos + time + 1; j++) {         int kk = j - pos;         if ((v1[kk] + 1 <= n1) &&             ((kk + t1 > time + 1) || (v2[kk + t1] + 1 <= n2)) &&             ((kk + t1 + t2 > time + 1) || (v3[kk + t1 + t2] + 1 <= n3))) {           posnew = j;           break;         }       }       int t = min(pos + time + 1, posnew + time);       for (int j = posnew; j <= t; j++) {         if (j <= posnew + t1 - 1)           v1[j - pos]++;         else if (j <= posnew + t1 + t2 - 1)           v2[j - pos]++;         else           v3[j - pos]++;         v1[j - posnew] = v1[j - pos];         v2[j - posnew] = v2[j - pos];         v3[j - posnew] = v3[j - pos];       }       for (int j = t + 1; j <= posnew + time; j++) {         if (j <= posnew + t1 - 1) {           v1[j - posnew] = 1;           v2[j - posnew] = 0;           v3[j - posnew] = 0;         } else if (j <= posnew + t1 + t2 - 1) {           v2[j - posnew] = 1;           v1[j - posnew] = 0;           v3[j - posnew] = 0;         } else {           v3[j - posnew] = 1;           v1[j - posnew] = 0;           v2[j - posnew] = 0;         }       }       v1[time + 1] = 0;       v2[time + 1] = 0;       v3[time + 1] = 0;       res = posnew + time;       pos = posnew;     }     cout << res + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;      #define int int64_t   #define MOD 998244353   #define inf 9e18   #define tikoo (int) (1e9 + 7)      template<typename T, typename T1> T max(T a, T1 b) { if (b > a) a = b; return a; }   template<typename T, typename T1> T min(T a, T1 b) { if (b < a) a = b; return a; }   int fastpow(int a, int b, int m = tikoo) { int res = 1; a %= m;       while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res; }      signed main() {       ios_base::sync_with_stdio(0);       cin.tie(0), cout.tie(0);       int t = 1;       cin >> t;       while (t--) {           int n, k;           cin >> n >> k;           cout << fastpow(n, k) <<   n ;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   void cppio() {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   const int maxn = int(2e5) + 10;   int n;   int a[maxn];   int p, q;   long long first, second;   int gcd(int a, int b) {     if (!b) {       first = 1, second = 0;       return a;     }     int q = a / b;     int ret = gcd(b, a % b);     tie(first, second) = make_pair(second, first - second * q);     return ret;   }   int ans[maxn][3];   int main() {     cppio();     cin >> n;     for (int i = 1; i <= (n); ++i) cin >> a[i];     if (n == 1) {       cout <<  1 1 n  << (-a[1]) <<   n1 1 n0 n1 1 n0 n ;       return 0;     }     cout << 1 <<     << n <<   n0  ;     for (int i = 2; i <= n; ++i) {       cout << (-n * 1ll * a[i]) <<    ;     }     cout <<   n ;     cout << 1 <<     << 1 <<   n ;     cout << (-a[1]) <<   n ;     cout << 2 <<     << n <<   n ;     for (int i = 2; i <= n; ++i) {       int first = a[i];       cout << ((n - 1) * 1ll * first) <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100005], dist[100005], sad[100005], subt[100005], ans = 0LL;   vector<pair<long long, long long> > adj[100005];   void dfs(long long node, long long par, long long min_vertex) {     if (par != -1) sad[node] = (a[node] < dist[node] - dist[min_vertex]);     min_vertex = (dist[node] < dist[min_vertex]) ? node : min_vertex;     for (auto i : adj[node])       if (par != i.first) {         dist[i.first] += (dist[node] + i.second);         dfs(i.first, node, min_vertex);         subt[node] += subt[i.first];       }     subt[node]++;   }   void dfs1(long long node, long long par) {     if (sad[node]) {       ans += subt[node];       return;     }     for (auto i : adj[node])       if (i.first != par) dfs1(i.first, node);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       long long n, i, j, k;       cin >> n;       for (i = 1; i <= n; i++) cin >> a[i];       for (i = 1; i <= n - 1; i++) {         long long x, wt;         cin >> x >> wt;         adj[i + 1].push_back(make_pair(x, wt));         adj[x].push_back(make_pair(i + 1, wt));       }       dfs(1, -1, 1);       dfs1(1, -1);       cout << ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 10;   const int M = 128;   const int inf = 0x7fffffff;   const long long INF = 9E18;   const int mod = 1e9 + 7;   int n, m;   int pos[M][maxn], len[M];   int dp[M][maxn];   char s[M][maxn];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s , s[i] + 1);       for (int j = 1; j <= m; j++) {         if (s[i][j] ==  1 ) pos[i][len[i]++] = j;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (len[i] == 0) {           puts( -1 );           return 0;         }         int cnt = len[i];         int loc = lower_bound(pos[i], pos[i] + cnt, j) - pos[i];         int movl = inf, movr = inf;         if (loc == len[i]) {           loc--;           movr = j - pos[i][loc];           movl = m - (j - pos[i][0]);         } else if (loc == 0) {           movl = pos[i][loc] - j;           movr = m - (pos[i][len[i] - 1] - j);         } else {           movl = pos[i][loc] - j;           movr = j - pos[i][--loc];         }         dp[i][j] = min(movl, movr);       }     }     int ans = inf;     for (int i = 1; i <= m; i++) {       int sum = 0;       for (int j = 1; j <= n; j++) {         sum += dp[j][i];       }       ans = min(ans, sum);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string x;     deque<char> vec;     int c;     bool flag;     int max = 0;     for (int i = 0; i < 8; i++) {       cin >> x;       for (int j = 0; j < x.length(); j++) vec.push_back(x[j]);       if (i % 2 == 0) {         c = 0;         while (true) {           c++;           flag = true;           for (int j = 1; j < x.length(); j++) {             if (x[j] == x[j - 1]) {               flag = false;               char temp = vec.back();               vec.pop_back();               vec.push_front(temp);               break;             }           }           if (c == 9 || flag == true) break;         }       } else if (i % 2 != 0) {         c = 0;         while (true) {           c++;           flag = true;           for (int j = 1; j < x.length(); j++) {             if (x[j] == x[j - 1]) {               flag = false;               char temp = vec.back();               vec.pop_back();               vec.push_front(temp);               break;             }           }           if (c == 9 || flag == true) break;         }       }       if (c > max) max = c;     }     if (flag == false || max == 9)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long ans = 0;     bool flag = false;     if (n == 2) {       cout << 1 <<   n ;       return 0;     }     for (int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         flag = true;         break;       }     }     if (!flag) {       cout << 1 <<   n ;       return 0;     }     if (n & 1) {       flag = false;       long long x = n - 2;       for (int i = 2; i <= sqrt(x); i++) {         if (x % i == 0) {           flag = true;           break;         }       }       if (!flag) {         cout << 2 <<   n ;         return 0;       } else         cout << 3 <<   n ;     } else {       cout << 2 <<   n ;     }   }