malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename T1>   T amax(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T& a, T1 b) {     if (b < a) a = b;     return a;   }   const long long N = 200005, INF = 2000000000000000000;   const long long SIX = 1000000;   bool prime(long long n) {     long long i = 0;     for (i = 2; i * i <= n; i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   void solve() {     long long n, k;     cin >> n >> k;     string s;     cin >> s;     long long i = 0;     long long ans = 0;     if (n == 1 && k != 0) {       cout <<  0 ;       return;     }     for (i = 0; i < n; i++) {       if (i == 0 && ans < k) {         if (s[i] !=  1 ) {           s[i] =  1 ;           ans++;         }       } else if (i > 0 && ans < k) {         if (s[i] !=  0 ) {           s[i] =  0 ;           ans++;         }       }     }     cout << s <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long t;     t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   map<pair<long long, long long>, long long> ma;   void put(long long u, long long v, long long w) {     while (v != u) {       long long par;       if (v > u) {         par = v / 2;         ma[make_pair(par, v)] += w;         ma[make_pair(v, par)] += w;         v /= 2;       } else {         par = u / 2;         ma[make_pair(par, u)] += w;         ma[make_pair(u, par)] += w;         u /= 2;       }     }   }   long long solve(long long u, long long v) {     long long ans = 0;     while (v != u) {       long long par;       if (v > u) {         par = v / 2;         ans += ma[make_pair(par, v)];         v /= 2;       } else {         par = u / 2;         ans += ma[make_pair(par, u)];         u /= 2;       }     }     return ans;   }   int main() {     long long u, v, w, ans;     int q, ty;     cin >> q;     while (q--) {       cin >> ty;       if (ty == 1) {         cin >> u >> v >> w;         put(u, v, w);       } else {         cin >> u >> v;         cout << solve(u, v) << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using P = pair<ll, ll>;   using PP = pair<ll, P>;   const ll n_ = 2222 + 100, inf = 1e18 + 1, mod = 1e9 + 7, sqrtN = 333;   ll dy[4] = {-1, 0, 1, 0}, dx[4] = {0, 1, 0, -1};   ll n, m, k, tc = 1, a, b, c, sum, x, y, z, w, base, ans;   ll gcd(ll x, ll y) {     if (!y) return x;     return gcd(y, x % y);   }   ll dp[n_][n_][2], A[n_][n_];   void solve() {     ll q;     cin >> n >> m >> q;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) A[i][j] = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         dp[i][j][0] = A[i][j] * (dp[i][j - 1][1] + A[i][j - 1]);         dp[i][j][1] = A[i][j] * (dp[i - 1][j][0] + A[i - 1][j]);         ans += dp[i][j][0] + dp[i][j][1] + A[i][j];       }     ll i, j;     while (q--) {       cin >> i >> j;       ans -= dp[i][j][0] + dp[i][j][1] + A[i][j];       A[i][j] ^= 1;       dp[i][j][0] = A[i][j] * (dp[i][j - 1][1] + A[i][j - 1]);       dp[i][j][1] = A[i][j] * (dp[i - 1][j][0] + A[i - 1][j]);       ans += dp[i][j][0] + dp[i][j][1] + A[i][j];       b = i + 1, a = j, c = 0;       while (1) {         if (b > n || a > m) break;         ans -= dp[b][a][0] + dp[b][a][1] + A[b][a];         dp[b][a][0] = A[b][a] * (dp[b][a - 1][1] + A[b][a - 1]);         dp[b][a][1] = A[b][a] * (dp[b - 1][a][0] + A[b - 1][a]);         ans += dp[b][a][0] + dp[b][a][1] + A[b][a];         if (c)           b++;         else           a++;         c = (c + 1) % 2;       }       b = i, a = j + 1, c = 1;       while (1) {         if (b > n || a > m) break;         ans -= dp[b][a][0] + dp[b][a][1] + A[b][a];         dp[b][a][0] = A[b][a] * (dp[b][a - 1][1] + A[b][a - 1]);         dp[b][a][1] = A[b][a] * (dp[b - 1][a][0] + A[b - 1][a]);         ans += dp[b][a][0] + dp[b][a][1] + A[b][a];         if (c)           b++;         else           a++;         c = (c + 1) % 2;       }       cout << ans <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     while (tc--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string str, s =  QWERTYUIOPASDFGHJKLZXCVBNM ;     cin >> str;     set<char> m;     long long result = 1;     for (int i = 0; i < str.size(); i++) {       if (str[i] ==  ? ) {         if (i == 0) {           result *= 9;         } else           result *= 10;       } else if (s.find(str[i]) != string::npos) {         if (i == 0) {           result *= 9;           m.insert(str[i]);         } else {           if (m.find(str[i]) == m.end()) {             result *= (10 - m.size());             m.insert(str[i]);           }         }       }     }     cout << result <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int T, n, cnt, now[N], ans[N];   char ch[N];   vector<int> A, B, C;   map<pair<int, int>, bool> col;   inline void ask() {     int i, j;     if (!A.size()) return;     printf( Q %d  , (int)A.size());     for (i = 0; i < A.size(); i++) printf( %d %d  , A[i], B[i]);     puts(  );     fflush(stdout);     scanf( %s , ch + 1);     for (i = 1; i <= A.size(); i++)       col[make_pair(A[i - 1], B[i - 1])] = (ch[i] ==  1 );   }   int main() {     int i, j, t;     cin >> T;     while (T--) {       cnt = 0, col.clear();       memset(ans, 0, sizeof(ans));       scanf( %d , &n);       A.clear(), B.clear();       for (int i = 2; i <= n; i += 2) {         A.push_back(i - 1);         B.push_back(i);       }       ask();       A.clear();       B.clear();       for (int i = 3; i <= n; i += 2) {         A.push_back(i - 1);         B.push_back(i);       }       ask();       now[++cnt] = 1;       for (int i = 2; i <= n; i++)         if (!col[make_pair(i - 1, i)]) now[++cnt] = i;       A.clear();       B.clear();       for (int i = 3; i <= cnt; i += 4)         A.push_back(now[i - 2]), B.push_back(now[i]);       for (int i = 4; i <= cnt; i += 4)         A.push_back(now[i - 2]), B.push_back(now[i]);       ask();       A.clear();       B.clear();       for (int i = 5; i <= cnt; i += 4)         A.push_back(now[i - 2]), B.push_back(now[i]);       for (int i = 6; i <= cnt; i += 4)         A.push_back(now[i - 2]), B.push_back(now[i]);       ask();       ans[now[1]] = 1;       if (cnt > 1) ans[now[2]] = 2;       for (int i = 3; i <= cnt; i++) {         if (col[make_pair(now[i - 2], now[i])])           ans[now[i]] = ans[now[i - 2]];         else           ans[now[i]] = 6 - ans[now[i - 2]] - ans[now[i - 1]];       }       A.clear();       B.clear();       C.clear();       for (int i = 1, t; i <= n; i++) {         if (ans[i]) t = ans[i];         ans[i] = t;         if (ans[i] == 1)           A.push_back(i);         else if (ans[i] == 2)           B.push_back(i);         else if (ans[i] == 3)           C.push_back(i);       }       printf( A %d %d %d n , (int)A.size(), (int)B.size(), (int)C.size());       for (int i = 0; i < A.size(); i++) printf( %d  , A[i]);       puts(  );       for (int i = 0; i < B.size(); i++) printf( %d  , B[i]);       puts(  );       for (int i = 0; i < C.size(); i++) printf( %d  , C[i]);       puts(  );       fflush(stdout);     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( no-stack-protector )   #pragma GCC target( sse,sse2,ssse3,sse3,sse4,popcnt,avx,mmx,abm,tune=native )   using namespace std;   signed main() {     cin.tie(nullptr)->sync_with_stdio(false);     long long n, k;     cin >> n >> k;     string s, t;     cin >> s >> t;     long long ans = 0, hv = 1;     for (long long i = 0; i < n; i++) {       if (hv < k) {         hv *= 2;         if (s[i] == t[i]) {           hv--;         } else if (s[i] ==  b  && t[i] ==  a ) {           hv -= 2;         }         hv = min(hv, k);       }       ans += hv;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     vector<long long> a(2 * n);     for (long long i = 0; i < 2 * n; ++i) {       cin >> a[i];     }     sort(a.begin(), a.end());     if (n == 1) {       cout << 0;       return 0;     }     long long mn = 2e9;     for (long long i = 1; i < n; ++i) {       mn = min(a[i + n - 1] - a[i], mn);     }     cout << min(min((a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]),                     (a[2 * n - 1] - a[n]) * (a[n - 1] - a[0])),                 mn * (a[2 * n - 1] - a[0]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   const int MOD = 998244353;   long long fac[MAXN];   struct Edge {     int to, next;   } edge[MAXN * 2];   int head[MAXN], tot;   void AddEdge(int s, int t) {     edge[tot].to = t;     edge[tot].next = head[s];     head[s] = tot++;     edge[tot].to = s;     edge[tot].next = head[t];     head[t] = tot++;   }   int visit[MAXN];   void init() {     memset(head, -1, sizeof(head));     memset(visit, 0, sizeof(visit));     tot = 0;   }   long long DFS(int u) {     visit[u] = 1;     long long ret = 1;     int cnt = 1;     if (u == 1) cnt = 0;     for (int e = head[u]; e != -1; e = edge[e].next) {       int v = edge[e].to;       if (!visit[v]) {         cnt++;         ret = (ret * DFS(v)) % MOD;       }     }     ret = (ret * fac[cnt]) % MOD;     return ret;   }   int main() {     int n;     cin >> n;     long long fa = 1;     for (int i = 1; i < MAXN; i++) {       fa = (fa * i) % MOD;       fac[i] = fa;     }     init();     int u, v;     for (int i = 0; i < n - 1; i++) {       scanf( %d%d , &u, &v);       AddEdge(u, v);     }     cout << (DFS(1) * n) % MOD << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int block;   unordered_map<int, int> x;   vector<long long> a;   struct query {     int l, r, pos;     bool operator<(const query &other) const {       if (l / block == other.l / block) return r < other.r;       return l / block < other.l / block;     }   };   int l = 0, r = -1, cnt = 0;   void remove(int val) {     if (x[val] == val) cnt--;     x[val]--;     if (x[val] == val) cnt++;     if (x[val] == 0) x.erase(val);   }   void add(int val) {     if (x[val] == val) cnt--;     x[val]++;     if (x[val] == val) cnt++;   }   void solve() {     long long n, m;     cin >> n >> m;     block = sqrt(n) + 1;     a.resize(n);     for (long long i = 0; i < n; i++) cin >> a[i];     vector<query> q(m);     for (int i = 0; i < m; i++) {       cin >> q[i].l >> q[i].r;       q[i].pos = i;       q[i].l--, q[i].r--;     }     sort(q.begin(), q.end());     vector<int> ans(m);     for (int i = 0; i < m; i++) {       while (l < q[i].l) remove(a[l++]);       while (l > q[i].l) add(a[--l]);       while (r < q[i].r) add(a[++r]);       while (r > q[i].r) remove(a[r--]);       ans[q[i].pos] = cnt;     }     for (auto i : ans) cout << i <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[110];   long long g[110], f[110][110][110];   char s[110];   int main() {     int L, R;     scanf( %d , &n);     gets(s);     if (s[0] !=  0 ) gets(s);     for (int i = 1; i <= n; i++) {       scanf( %d , &g[i]);       for (int j = 1; j < i; j++) g[i] = max(g[i], g[j] + g[i - j]);     }     for (int i = 1; i <= n; i++) a[i] = s[i - 1] - 48;     for (int t = 0; t < n; t++)       for (int i = 1; i <= n - t; i++)         for (int k = 1; k <= i; k++) {           f[i][i + t][k] = g[k] + f[i + 1][i + t][1];           for (int j = 1; j <= t; j++)             if (a[i] == a[i + j])               f[i][i + t][k] = max(f[i][i + t][k], f[i + 1][i + j - 1][1] +                                                        f[i + j][i + t][k + 1]);         }     printf( %I64d n , f[1][n][1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     map<int, int> m;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] != 0) {         m[arr[i]]++;       }     }     cout << m.size() << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:536870912 )   #pragma warning(disable : 4996)   using namespace std;   const int N = 2e5 + 100, X[2] = {997, 449};   char s[N], t[N];   long long int h[2][N], p[2][N];   int w[N], g[N], lb[N], rb[N];   int n;   pair<long long int, long long int> getH(int l, int r) {     return {h[0][r] - h[0][l - 1] * p[0][r - l + 1],             h[1][r] - h[1][l - 1] * p[1][r - l + 1]};   }   int lcp(int a, int b) {     int l = 0, r = n - max(a, b) + 1;     while (r - l > 1) {       int p = (r + l) >> 1;       if (getH(a + 1, a + p) == getH(b + 1, b + p))         l = p;       else         r = p;     }     return l;   }   int main() {     scanf( %d %s %s , &n, s, t);     reverse(s, s + n);     reverse(t, t + n);     for (int i = 0; i < 2; i++) {       p[i][0] = 1;       for (int j = 0; j < n; j++) {         p[i][j + 1] = p[i][j] * X[i];         h[i][j + 1] = h[i][j] * X[i] + s[j];       }     }     int c = 0;     for (int i = 0; i < n; i++) {       if (t[i] ==  0 ) w[c++] = i;     }     sort(w, w + c, [](int a, int b) {       int x = lcp(a, b);       return s[a + x] < s[b + x];     });     for (int i = 0; i < c - 1; i++) {       g[i] = lcp(w[i], w[i + 1]);     }     vector<int> v;     for (int i = 0; i < c - 1; i++) {       while (!v.empty() && g[v.back()] >= g[i]) v.pop_back();       lb[i] = v.empty() ? -1 : v.back();       v.push_back(i);     }     v.clear();     for (int i = c - 2; i >= 0; i--) {       while (!v.empty() && g[v.back()] >= g[i]) v.pop_back();       rb[i] = v.empty() ? c - 1 : v.back();       v.push_back(i);     }     long long int ans = 0;     for (int i = 0; i < c; i++) ans = max(ans, (long long int)n - w[i]);     for (int i = 0; i < c - 1; i++) {       ans = max(ans, g[i] * (long long int)(rb[i] - lb[i]));     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int N = 20 + 5;   int go[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};   int n, m, k;   char s[N][N];   struct Node {     int x, y, v;   } t[N];   int tot;   int sx, sy;   struct State {     int x, y, S;   };   int vis[N][N][1 << 10];   int dis[N][N][1 << 10];   inline int calc(int S) {     int sum = 0;     for (register int i = 1; i <= k; i++)       if (S & (1 << (i - 1))) {         sum += t[i].v;       }     return sum;   }   inline int ok(int x, int y, int nx, int ny, int i) {     if (nx == t[i].x && ny < t[i].y)       if (x < nx) return 1;     if (x == t[i].x && y < t[i].y)       if (x > nx) return 1;     return 0;   }   int main() {     cin >> n >> m;     k = 0;     for (register int i = 1; i <= n; i++) {       for (register int j = 1; j <= m; j++) {         cin >> s[i][j];         if (s[i][j] ==  S ) sx = i, sy = j;         if (isdigit(s[i][j])) {           k = max(k, s[i][j] -  0 );           t[s[i][j] -  0 ] = {i, j, 0};         }       }     }     for (register int i = 1; i <= k; i++) cin >> t[i].v;     for (register int i = 1; i <= n; i++)       for (register int j = 1; j <= m; j++)         if (s[i][j] ==  B ) {           t[++k] = {i, j, -inf / 1000};         }     queue<State> Q;     memset(dis, 0x3f, sizeof(dis));     Q.push(State{sx, sy, 0});     dis[sx][sy][0] = 0;     int ans = 0;     while (Q.size()) {       State tmp = Q.front();       Q.pop();       int x = tmp.x, y = tmp.y, S = tmp.S;       if (x == sx && y == sy) {         ans = max(ans, calc(S) - dis[x][y][S]);       }       for (register int i = 0; i < 4; i++) {         int nx = x + go[i][0];         int ny = y + go[i][1];         if (nx < 1 || ny < 1 || nx > n || ny > m ||             (s[nx][ny] !=  .  && s[nx][ny] !=  S ))           continue;         int T = S;         for (register int j = 1; j <= k; j++)           if (ok(x, y, nx, ny, j)) T ^= (1 << (j - 1));         if (dis[nx][ny][T] == inf) {           dis[nx][ny][T] = dis[x][y][S] + 1;           Q.push(State{nx, ny, T});         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (1 << 23);   bool vis[maxn], num[maxn];   int n, m;   void dfs(int x) {     if (vis[x]) return;     vis[x] = 1;     for (int i = 0; i < n; i++) {       if (x & (1 << i)) dfs(x ^ (1 << i));     }     if (num[x]) dfs((1 << n) - 1 - x);   }   int main() {     int x;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d , &x);       num[x] = 1;     }     int ans = 0;     for (int i = 0; i < (1 << n); i++) {       if (num[i] && !vis[i]) dfs(((1 << n) - 1) & (~i)), ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long c1, c2;   int n, k;   long long p(long long m) {     long long mini = LLONG_MAX;     for (int i = 1; i <= n; ++i)       if ((n + i) / (i + 1) <= m and m <= n / i)         mini = min(mini, 1LL * i * i * (m * (i + 1) - n) +                              1LL * (i + 1) * (i + 1) * (n - m * i));     return m * (c1 + c2) - 2 * c2 * n + c2 * mini;   }   int main() {     scanf( %d %lld %lld%*c , &n, &c1, &c2);     for (int i = 0; i < n; ++i) k += getchar() ==  1 ;     int lo = 1, hi = k;     while (lo < hi) {       int mid = lo + (hi - lo) / 2;       if (p(mid) <= p(mid + 1))         hi = mid;       else         lo = mid + 1;     }     printf( %lld n , p(lo));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-5;   int main() {     int n, k;     cin >> n >> k;     vector<int> cur(n);     vector<int> p(n);     vector<int> goal(n);     for (int i = 0; i < n; i++) {       cin >> p[i];     }     for (int i = 0; i < n; i++) cin >> goal[i];     bool ok = true;     for (int i = 0; i < n; i++) {       cur[i] = i + 1;       if (goal[i] != cur[i]) ok = false;     }     if (ok) {       cout <<  NO  << endl;       return 0;     }     int step_forward = 1000;     int step_backward = 1000;     for (int i = 0; i < k; i++) {       bool ok = true;       vector<int> nxt;       for (int j = 0; j < n; j++) {         nxt.push_back(cur[p[j] - 1]);         if (nxt[j] != goal[j]) ok = false;       }       if (ok) {         step_forward = i + 1;         break;       }       cur = nxt;     }     cur = goal;     for (int i = 0; i < k; i++) {       bool ok = true;       vector<int> nxt;       for (int j = 0; j < n; j++) {         nxt.push_back(cur[p[j] - 1]);         if (nxt[j] != j + 1) ok = false;       }       if (ok) {         step_backward = i + 1;         break;       }       cur = nxt;     }     if (step_forward == 1 && step_backward == 1 && k > 1) {       cout <<  NO  << endl;       return 0;     }     if (step_forward <= k && step_forward % 2 == k % 2) {       cout <<  YES  << endl;       return 0;     }     if (step_backward <= k && step_backward % 2 == k % 2) {       cout <<  YES  << endl;       return 0;     }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   ostream& operator<<(ostream& out, const pair<A, B>& a) {     return out <<  (  << a.first <<  ,   << a.second <<  ) ;   }   template <class A>   ostream& operator<<(ostream& out, const vector<A>& v) {     out <<  [ ;     for (int i = 0; i < v.size(); i++) {       if (i) out <<  ,  ;       out << v[i];     }     return out <<  ] ;   }   bool Check(int n, int pos) { return (bool)(n & (1 << pos)); }   struct edg {     long long to, w, c;   };   vector<edg> g[100005];   vector<long long> v1, v2;   int vis[100005];   long long sum, s;   void calc(long long ws, long long lf, long long c) {     while (ws) {       long long wy = ws;       ws /= 2LL;       wy = wy - ws;       if (c == 1)         v1.emplace_back(wy * lf);       else         v2.emplace_back(wy * lf);     }   }   long long dfs(long long i, long long ws) {     vis[i] = 1;     long long ret = 0;     bool is_leaf = true;     for (auto j : g[i]) {       if (vis[j.to] == -1) {         is_leaf = false;         int r = dfs(j.to, ws + j.w);         ret += r;         calc(j.w, r, j.c);       }     }     if (is_leaf) {       sum += ws;       return 1LL;     }     return ret;   }   void solve() {     int n;     cin >> n >> s;     for (int i = 1; i < n; i++) {       int u, v, w, c;       cin >> u >> v >> w >> c;       u--, v--;       g[u].push_back({v, w, c});       g[v].push_back({u, w, c});     }     memset(vis, -1, sizeof(vis));     dfs(0, 0);     sort(v1.begin(), v1.end(), greater<long long>());     sort(v2.begin(), v2.end(), greater<long long>());     int len1 = v1.size();     int len2 = v2.size();     long long res = 0;     int i = -1, j = 0;     while (sum > s && i + 1 < len1) {       res++;       i++;       sum -= v1[i];     }     while (sum > s && j < len2) {       res += 2;       sum -= v2[j];       j++;     }     long long cur = res;     while (i >= 0) {       sum += v1[i];       cur--;       i--;       while (sum > s && j < len2) {         sum -= v2[j];         cur += 2;         j++;       }       if (sum <= s) {         res = min(res, cur);       }     }     cout << res <<   n ;     for (int i = 0; i <= n; i++) g[i].clear();     v1.clear();     v2.clear();     sum = 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int q = 1;     cin >> q;     for (int kase = 1; kase <= q; kase++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   int main() {     int n;     scanf( %d , &n);     if (n % 2 == 0) {       printf( -1 n );       return 0;     }     for (int i = 0; i < n; ++i) {       printf( %d  , i);     }     printf(  n );     for (int i = 0; i < n; ++i) {       printf( %d  , (i + 1) % n);     }     printf(  n );     for (int i = 0; i < n; ++i) {       printf( %d  , (2 * i + 1) % n);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a;     int n, m;     cin >> a >> n;     m = a.size();     string ans =   ;     while (n--) {       string b;       cin >> b;       if (b.substr(0, 0 + m) == a) {         if (ans ==   )           ans = b;         else if (b < ans)           ans = b;       }     }     if (ans !=   )       cout << ans;     else       cout << a;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x, q[100100];   char t;   vector<int> d;   bool used[100100];   void calc(int x) {     d.resize(0);     for (int i = 2; i * i <= x; i++)       if (x % i == 0) {         while (x % i == 0) x /= i;         d.push_back(i);       }     if (x != 1) d.push_back(x);   }   int main() {     scanf( %d%d n , &n, &m);     memset((used), (false), sizeof((used)));     memset((q), (0), sizeof((q)));     for (int i = 0; i < (m); i++) {       while (t = getchar(), t !=  +  && t !=  - )         ;       scanf( %d , &x);       if (t ==  + ) {         if (used[x]) {           puts( Already on );           continue;         }         calc(x);         bool ok = true;         for (int j = 0; j < (d.size()); j++)           if (q[d[j]]) {             printf( Conflict with %d n , q[d[j]]);             ok = false;             break;           }         if (ok) {           for (int j = 0; j < (d.size()); j++) q[d[j]] = x;           used[x] = true;           puts( Success );         }       } else {         if (!used[x]) {           puts( Already off );           continue;         }         used[x] = false;         calc(x);         for (int j = 0; j < (d.size()); j++) q[d[j]] = 0;         puts( Success );       }     }   }