malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   string a, b;   int nex[1000006], f1[1000006], f2[1000006];   long long xa[1000006], xb[1000006], mu[1000006];   const long long base = 1000000007;   int main() {     getline(cin, a);     getline(cin, b);     if (a.length() != b.length()) {       cout <<  -1 -1 ;       return 0;     }     int n = a.length();     nex[n - 1] = n;     for (int i = n - 2; i >= 0; i--) {       int j = nex[i + 1];       while (j < n && a[j - 1] != a[i]) j = nex[j];       if (j - 1 >= 0 && a[i] == a[j - 1])         nex[i] = j - 1;       else         nex[i] = j;     }     int j = n;     for (int i = 0; i <= n - 1; i++) {       while (j < n && b[i] != a[j - 1]) j = nex[j];       if (j - 1 >= 0 && b[i] == a[j - 1]) j--;       f1[i] = j;     }     mu[0] = 1;     for (int i = 1; i <= n; i++) mu[i] = (mu[i - 1] * 95) % base;     xa[0] = a[0] - 32;     for (int i = 1; i <= n - 1; i++)       xa[i] = (xa[i - 1] + mu[i] * (a[i] - 32)) % base;     xb[0] = b[0] - 32;     for (int i = 1; i <= n - 1; i++)       xb[i] = (xb[i - 1] + mu[i] * (b[i] - 32)) % base;     int res1 = -1, res2 = -1;     for (int i = 0; i <= n - 2 && a[i] == b[n - i - 1]; i++) {       if (a[i] != b[n - i - 1]) break;       int j = f1[n - i - 2];       if (j < n && (j == i + 1 || (xa[j - 1] - xa[i] + base) % base ==                                       (xb[j - i - 2] * mu[i + 1]) % base)) {         res1 = i;         res2 = j;       }     }     cout << res1 <<     << res2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[105];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     a[n] = a[0];     int k;     int minn = 10005;     for (int i = 1; i <= n; i++) {       if (abs(a[i] - a[i - 1]) < minn) {         minn = abs(a[i] - a[i - 1]);         k = i;       }     }     if (k >= n) {       cout << 1 <<     << k << endl;     } else {       cout << k + 1 <<     << k << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   long long int n, x, y, b, a[3];   int main() {     long long int x, y;     cin >> x >> y;     long long int a = 0;     while (true) {       if (a % 2 == 0) {         if (x >= 2 && y >= 2) {           x -= 2;           y -= 2;         } else {           if (x >= 1 && y >= 12) {             x--;             y -= 12;           } else {             if (x >= 0 && y >= 22) {               y -= 22;             } else {               break;             }           }         }       } else {         if (x >= 0 && y >= 22) {           y -= 22;         } else {           if (x >= 1 && y >= 12) {             x--;             y -= 12;           } else {             if (x >= 2 && y >= 2) {               x -= 2;               y -= 2;             } else {               break;             }           }         }       }       a++;     }     if (a % 2 == 1) {       cout <<  Ciel ;       return 0;     }     cout <<  Hanako ;   }
#include <bits/stdc++.h>   using namespace std;   inline int ci() {     register char ch;     int f = 1;     while (!isdigit(ch = getchar())) f = ch ==  -  ? -1 : 1;     register int x = ch ^  0 ;     while (isdigit(ch = getchar())) x = (x * 10) + (ch ^  0 );     return f * x;   }   enum { N = 100024 };   int a[N];   int main() {     int n = ci();     for (register int i = (1); i <= (n); i++) a[i] = ci();     sort(a + 1, a + n + 1);     long long a1 = 0, a2 = 0;     int m = n / 2;     for (register int i = (1); i <= (m); i++) a1 += a[i];     for (register int i = (m + 1); i <= (n); i++) a2 += a[i];     printf( %I64d , a1 * a1 + a2 * a2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Dish {     int ind;     int cost;     int cnt;   };   int n;   bool dishComp(Dish a, Dish b) {     if (a.cost == b.cost) {       return a.ind < b.ind;     }     return a.cost < b.cost;   }   int main() {     int m, a, c;     cin >> n >> m;     vector<Dish> dishes;     for (int i = 0; i < n; i++) {       cin >> a;       Dish dish;       dish.ind = i + 1;       dish.cnt = a;       dishes.push_back(dish);     }     int has[n + 1];     for (int i = 0; i < n; i++) {       cin >> c;       dishes[i].cost = c;     }     sort(dishes.begin(), dishes.end(), dishComp);     for (int i = 0; i < n; i++) {       has[dishes[i].ind] = i;     }     int t, d, btindex, cnti;     long long int sm;     int saveIndex = 0;     for (int i = 0; i < m; i++) {       cin >> t >> d;       btindex = has[t];       if (dishes[btindex].cnt >= d) {         sm = (long long int)dishes[btindex].cost * d;         dishes[btindex].cnt = dishes[btindex].cnt - d;       } else {         sm = (long long int)dishes[btindex].cost * dishes[btindex].cnt;         d = d - dishes[btindex].cnt;         dishes[btindex].cnt = 0;         cnti = 0;         while (saveIndex < n) {           if (dishes[saveIndex].cnt < d) {             d = d - dishes[saveIndex].cnt;             sm = sm +                  (long long int)dishes[saveIndex].cost * dishes[saveIndex].cnt;             dishes[saveIndex].cnt = 0;           } else {             sm = sm + (long long int)dishes[saveIndex].cost * d;             dishes[saveIndex].cnt = dishes[saveIndex].cnt - d;             cnti = 1;             break;           }           saveIndex++;         }         if (cnti == 0) sm = 0;       }       cout << sm <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 9;   int seg[MAX * 4][2], n, k, a, b, q, ar[MAX];   void upd(int x, int s = 0, int e = n, int id = 0) {     if (e - s == 1) {       seg[id][0] = min(ar[s], a), seg[id][1] = min(ar[s], b);       return;     }     int mid = s + e >> 1;     if (x < mid)       upd(x, s, mid, id * 2 + 1);     else       upd(x, mid, e, id * 2 + 2);     seg[id][0] = seg[id * 2 + 1][0] + seg[id * 2 + 2][0];     seg[id][1] = seg[id * 2 + 1][1] + seg[id * 2 + 2][1];   }   pair<int, int> gt(int l, int r, int s = 0, int e = n, int id = 0) {     pair<int, int> ret = {0, 0};     if (r <= s || e <= l) return ret;     if (l <= s && e <= r) return {seg[id][0], seg[id][1]};     int mid = s + e >> 1;     pair<int, int> le = gt(l, r, s, mid, id * 2 + 1),                    ri = gt(l, r, mid, e, id * 2 + 2);     ret = {le.first + ri.first, le.second + ri.second};     return ret;   }   int main() {     cin >> n >> k >> a >> b >> q, n++;     while (q--) {       int t, d, a;       cin >> t >> d;       if (t == 1)         cin >> a, ar[d] += a, upd(d);       else         cout << gt(0, d).second + gt(d + k, n).first <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   int main() {     int n;     scanf( %d , &n);     vector<int> a;     int r2 = 0;     int ans;     int prev = 0;     long long res = 0;     int pr2 = 0;     for (int i = 0; i < n; i++) {       int tmp;       scanf( %d , &tmp);       if (i == 0) {         prev = tmp;         continue;       }       if (tmp < prev) {         res += prev - tmp;       }       prev = tmp;     }     printf( %I64d , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Interval {     int start, end;   };   bool compare(Interval i1, Interval i2) { return (i1.start < i2.start); }   vector<long long int> factors;   void Divisors(long long int n) {     for (long long int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i)           factors.push_back(i);         else {           factors.push_back(i);           factors.push_back(n / i);         }       }     }   }   long long int coun[100005] = {0};   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, k, m, t;     cin >> n >> k >> m >> t;     while (t--) {       long long int task, in;       cin >> task >> in;       if (task == 0) {         if (in < k) {           k = k - in;           n = n - in;         } else {           n = in;         }         cout << n <<     << k << endl;       } else {         if (in <= k) {           k = k + 1;           n = n + 1;         } else {           k = k;           n = n + 1;         }         cout << n <<     << k << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   const int N = 254;   const long long INF = 0x3f3f3f3f3f3f3f3fll;   int n, t, K;   int a[N], d[N];   long long A[N], D[N], lim[N];   long long f[N][N][2], g[N][N][2];   inline void down(long long &x, const long long y) { x > y ? x = y : 0; }   inline long long max(const long long x, const long long y) {     return x < y ? y : x;   }   int main() {     int i, j, k, r;     long long times, time2, rem, need;     scanf( %d%d%d , &n, &t, &K);     for (i = 1; i <= n; ++i) scanf( %d%d%lld , a + i, d + i, lim + i);     ++n, a[n] = d[n] = INT_MAX, lim[n] = INF;     for (i = 1; i <= n; ++i) A[i] = A[i - 1] + a[i], D[i] = D[i - 1] + d[i];     memset(f, 63, sizeof f), memset(g, 63, sizeof g);     memset(f, 0, sizeof *f), memset(g, 0, sizeof *g);     for (i = 1; i <= n; ++i)       for (j = 0; j <= t; ++j)         for (k = 0; k < 2; ++k) {           if ((long long)k * a[i] + (long long)j * d[i] <= lim[i] &&               f[i - 1][j][k] < INF) {             down(f[i][j][k], f[i - 1][j][k]),                 times = (k * A[i - 1] + j * D[i - 1] + K - 1) / K;             if (times * K <= k * A[i] + j * D[i]) down(g[i][j][k], times);           }           for (r = 0; r < j; ++r)             if ((times = g[i][r][k]) < INF) {               rem = k * A[i] + r * D[i] - K * times, assert(rem >= 0);               need =                   (max(0, rem + (long long)(j - r) * d[i] - lim[i]) + K - 1) / K;               if (need * K <= rem && f[i - 1][j - r][0] < INF) {                 down(f[i][j][k], times + need + f[i - 1][j - r][0]);                 time2 = ((j - r) * D[i - 1] + K - 1) / K;                 if (time2 * K <= (j - r) * D[i] + (rem - need * K))                   down(g[i][j][k], times + need + time2);               }             }         }     printf( %lld n , f[n][t][1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long C[4003 + 2][4003 + 2];   void pascal() {     for (int i = 0; i < 4003; ++i) C[i][i] = C[i][0] = 1;     for (int i = 2; i < 4003; ++i) {       for (int j = 1; j < i; ++j)         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007LL;     }   }   long long pd[4003 + 2];   long long spd[4003];   long long proc(int N) {     pd[1] = 1;     pd[2] = 3;     pd[3] = 10;     if (N < 4) return pd[N];     spd[1] = 1;     spd[2] = 4;     spd[3] = 14;     for (int n = 4; n <= N; n++) {       for (int i = 2; i < n; i++) {         pd[n] = (pd[n] + (spd[i - 1] * C[n][i]) % 1000000007LL) % 1000000007LL;       }       for (int i = 0; i < n; i++) {         pd[n] = (pd[n] + C[n][i]) % 1000000007LL;       }       spd[n] = (spd[n - 1] + pd[n]) % 1000000007LL;     }     return pd[N];   }   int main() {     pascal();     int n;     scanf( %d , &n);     printf( %lld n , proc(n));   }
#include <bits/stdc++.h>   const int maxn = 2e7 + 10;   const int mod = 998244853;   int n, m, qwq[maxn + 5], ifac[maxn + 5], f[maxn + 5];   void zzh_NB(int &x, int y) { (x += y) >= mod && (x -= mod); }   int add(int x) { return x >= mod ? x - mod : x; }   int readINT() {     int xx = 0, ch = getchar(), f = 1;     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) xx = xx * 10 + ch -  0 , ch = getchar();     return xx * f;   }   int kehaixing(int x) { return x < 0 ? x + mod : x; }   int quick_pp(int x, int k) {     int ans = 1;     for (; k > 0; k >>= 1, x = 1LL * x * x % mod) {       if ((k & 1) == 1) ans = 1LL * ans * x % mod;     }     return ans;   }   int inv(int x) { return quick_pp(x, mod - 2); }   void init(int n) {     qwq[0] = 1;     for (int i = 1; i <= n; i++) qwq[i] = 1LL * qwq[i - 1] * i % mod;     ifac[n] = inv(qwq[n]);     for (int i = n; i >= 1; i--) ifac[i - 1] = 1LL * ifac[i] * i % mod;   }   int wssb(int n, int m) {     if (n < m) return 0;     return 1LL * qwq[n] * ifac[m] % mod * ifac[n - m] % mod;   }   int ans = 0;   inline void duru() {     n = readINT(), m = readINT();     init(n + m);     for (int i = 0; i <= n; i++) {       f[i] = (i <= n - m ? wssb(n + m, n) : wssb(n + m, n - i));     }     for (int i = 0; i <= n; i++) {       zzh_NB(ans, 1LL * i * kehaixing(f[i] - f[i + 1]) % mod);     }     printf( %d n , ans);   }   int main() {     duru();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     cin >> s;     long long int ans = 0;     vector<string> v;     string temp =   ;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  .  && v.size() != 0) {         for (int i = 0; i < v.size(); i++) {           if (temp == v[i]) ++ans;         }         if (temp ==   ) v.pop_back();         temp =   ;         continue;       }       if (s[i] ==  : ) {         for (int i = 0; i < v.size(); i++) {           if (temp == v[i]) ++ans;         }         v.push_back(temp);         temp =   ;         continue;       }       if (s[i] !=  , ) temp += s[i];     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:256000000 )   template <class T>   T sqr(T a) {     return a * a;   }   double a, d, s;   int n;   void init() { cin >> a >> d >> n; }   void solve() {     double x = 0, y = 0;     int dx[4] = {1, 0, -1, 0};     int dy[4] = {0, 1, 0, -1};     int t = d / (4 * a);     d = d - t * (4 * a);     int q = 0;     for (int i = 0; i < n; ++i) {       double t = d;       if (!q) {         if (a - x - t < 1e-5) {           t -= a - x;           x = a;           q++;         }       } else if (q == 1) {         if (a - y - t < 1e-5) {           t -= a - y;           y = a;           q++;         }       } else if (q == 2) {         if (x - t < 1e-5) {           t -= x;           x = 0;           q++;         }       } else {         if (y - t < 1e-5) {           t -= y;           y = 0;           q = 0;         }       }       while (t - a > 1e-5) {         x += dx[q] * a;         y += dy[q] * a;         q++;         if (q == 4) q = 0;         t -= a;       }       x += dx[q] * t;       y += dy[q] * t;       printf( %0.4f %0.4f  n , x, y);     }   }   int main() {     init();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<char> line;   bool isPossible(int gLoc, int k);   int main() {     int n, k;     cin >> n;     cin >> k;     char curr;     int grasshopperLocation;     for (int i = 0; i < n; i++) {       cin >> curr;       line.push_back(curr);       if (curr ==  G ) grasshopperLocation = i;     }     if (isPossible(grasshopperLocation, k))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }   bool isPossible(int gLoc, int k) {     for (int j = gLoc; j < line.size(); j += k) {       if (line[j] ==  T )         return true;       else if (line[j] ==  # )         break;     }     for (int j = gLoc; j >= 0; j -= k) {       if (line[j] ==  T )         return true;       else if (line[j] ==  # )         break;     }     return false;   }
#include <bits/stdc++.h>   using namespace std;   long long read() {     long long x = 0, F = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) F = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + c -  0 ;       c = getchar();     }     return x * F;   }   int add(int x, int y) {     return (x + y >= 998244353) ? x + y - 998244353 : x + y;   }   int dec(int x, int y) { return (x - y < 0) ? x - y + 998244353 : x - y; }   int mul(int x, int y) { return 1LL * x * y % 998244353; }   int n;   pair<int, int> a[800000 + 5];   int dp[800000 + 5][7], pre[800000 + 5];   int ans[800000 + 5], pt[800000 + 5];   int cnt;   int main() {     n = read();     for (int i = 1; i <= n; i++) a[i] = pair<int, int>(read(), i);     sort(a + 1, a + n + 1);     memset(dp, 0x3f, sizeof(dp));     dp[1][1] = 0, pre[1] = 1;     for (int i = 2; i <= n + 1; i++) {       for (int j = 1; j <= 5; j++) {         dp[i][j + 1] =             min(dp[i][j + 1], dp[i - 1][j] - a[i - 1].first + a[i].first);         if (j >= 3) {           if (dp[i][1] > dp[i - 1][j]) {             dp[i][1] = dp[i - 1][j];             pre[i] = j;           }         }       }       if (dp[i][1] > dp[i - 1][6]) {         dp[i][1] = dp[i - 1][6];         pre[i] = 6;       }     }     printf( %d  , dp[n + 1][1]);     int p = n + 1;     while (p >= 1) {       int nxt = p - pre[p];       p = nxt;       cnt++;       ans[p] = cnt;     }     printf( %d n , cnt - 1);     for (int i = 1; i <= n; i++)       if (!ans[i]) ans[i] = ans[i - 1];     for (int i = 1; i <= n; i++) pt[a[i].second] = ans[i];     for (int i = 1; i <= n; i++) printf( %d  , pt[i]);   }
#include <bits/stdc++.h>   using namespace std;   set<int> s[400000];   int bl[400000], S[400000], sz, n, m;   void dfs(int x, int y) {     bl[x] = y;     ++sz;     for (int z : s[x])       if (z != 1 && !bl[z]) dfs(z, y);   }   void dft(int x) {     S[x] = sz;     for (int y : s[x])       if (y != 1 && !S[y]) dft(y);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       s[x].insert(y);       s[y].insert(x);     }     if (s[1].count(n)) return printf( 1 n1 %d n , n), 0;     for (int x : s[1])       if (s[x].count(n)) return printf( 2 n1 %d %d n , x, n), 0;     for (int x : s[1])       for (int y : s[x])         if (s[y].count(n)) return printf( 3 n1 %d %d %d n , x, y, n), 0;     for (int x : s[1])       for (int y : s[x])         if (y != 1 && !s[1].count(y))           return printf( 4 n1 %d %d 1 %d n , x, y, n), 0;     if (!s[1].size()) return puts( -1 ), 0;     for (int x : s[1])       if (!bl[x]) {         sz = 0;         dfs(x, x);         dft(x);       }     int mn = n + 10, mid = 0;     for (int x : s[1])       if (S[x] != s[x].size()) {         if (s[x].size() < mn) {           mn = s[x].size();           mid = x;         }       }     if (mid) {       puts( 5 );       for (int y : s[mid])         if (y != 1)           for (int z : s[y])             if (z != 1 && z != mid && !s[mid].count(z))               return printf( 1 %d %d %d %d %d n , mid, y, z, mid, n), 0;     }     puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mx = 19;   const long long mx1 = 262150;   long long s[mx];   long long n, m, k;   long long extra[mx][mx];   long long dp[mx][mx1];   long long solve(long long prev, long long bitmask, long long m) {     if (m == 0) return 0;     if (dp[prev][bitmask] != -1) return dp[prev][bitmask];     long long ans = INT_MIN;     for (long long j = 0; j < mx; j++) {       if (bitmask & (1 << j))         ans = max(ans, extra[prev][j + 1] + s[j + 1] +                            solve(j + 1, bitmask ^ (1 << j), m - 1));     }     return dp[prev][bitmask] = ans;   }   signed main() {     cin >> n >> m >> k;     for (long long i = 1; i <= n; i++) cin >> s[i];     long long a, b, c;     memset(extra, 0, sizeof(extra));     for (long long i = 0; i < k; i++) {       cin >> a >> b >> c;       extra[a][b] = c;     }     long long bitmask = (1 << n) - 1;     long long prev = 0;     memset(dp, -1, sizeof(dp));     cout << solve(prev, bitmask, m) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const long long LINF = 1e17;   const double DINF = numeric_limits<double>::max();   const int ITER = 300;   const int MOD = 1e9 + 7;   const double EPS = 1e-10;   const int MAXN = 1e5 + 10;   int n;   vector<int> g[MAXN];   int B[MAXN];   int dp[MAXN][2];   void mod(int v) {     for (int i = 0; i < 2; i++) dp[v][i] %= MOD;   }   void dfs(int v) {     dp[v][0] = 1 - B[v];     dp[v][1] = B[v];     for (int u : g[v]) {       int old[2];       old[0] = dp[v][0];       old[1] = dp[v][1];       dp[v][0] = dp[v][1] = 0;       dfs(u);       dp[v][0] += (1ll * old[0] * dp[u][1]) % MOD;       dp[v][1] += (1ll * old[1] * dp[u][1]) % MOD;       mod(v);       dp[v][1] += (1ll * old[1] * dp[u][0]) % MOD;       mod(v);       dp[v][1] += (1ll * old[0] * dp[u][1]) % MOD;       mod(v);       dp[v][0] += (1ll * old[0] * dp[u][0]) % MOD;       mod(v);     }   }   void solve() {     cin >> n;     for (int i = 1; i < n; i++) {       int p;       cin >> p;       g[p].push_back(i);     }     for (int i = 0; i < n; i++) {       cin >> B[i];     }     dfs(0);     cout << dp[0][1] << endl;   }   int main() {     cout << setprecision(12) << fixed;     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int a[3000010], v[2 * 1000010 + 5];   int main() {     int n, k, i, mn, ans, j;     scanf( %d%d , &n, &k);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     mn = a[0];     for (i = 1; i < n; i++) mn = min(mn, a[i]);     if (mn <= k + 1) {       cout << mn;       return 0;     }     ans = k + 1;     for (i = 0; i < n; i++) v[a[i]]++;     for (i = 1; i <= 2 * 1000010; i++) v[i] += v[i - 1];     for (i = k + 2; i <= mn; i++) {       int cnt = 0;       for (j = i; j <= 1000010; j += i) cnt += (v[j + k] - v[j - 1]);       if (cnt == n) ans = i;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> N;     int x = 0;     int res = 0;     if (N == 1) {       printf( 1 n );       printf( 1 n );       return 0;     }     for (int i = 1; i <= N; i++) {       x += i;       if (x > N) {         res = i - 1;         break;       }     }     printf( %d n , res);     for (int i = 1; i < res; i++) {       printf( %d  , i);       N -= i;     }     printf( %d n , N);   }
#include <bits/stdc++.h>   using namespace std;   const int maxint = -1u >> 1;   template <class T>   bool get_max(T& a, const T& b) {     return b > a ? a = b, 1 : 0;   }   template <class T>   bool get_min(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   int k;   int num[26];   string s;   int main() {     cin >> k;     cin >> s;     memset(num, 0, sizeof(num));     for (int i = 0; i < s.size(); i++) num[s[i] -  a ]++;     int flag = 1;     for (int i = 0; i < 26; i++)       if (num[i] % k != 0) {         flag = 0;       }     if (flag == 0)       puts( -1 );     else {       string ans;       for (int i = 0; i < k; i++)         for (int j = 0; j < 26; j++)           for (int g = 0; g < num[j] / k; g++) {             ans = ans + char(j +  a );           }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, m;     cin >> n >> m;     vector<string> v, vec;     for (long long i = 1; i <= n; i++) {       string s;       cin >> s;       v.push_back(s);     }     for (long long i = 1; i <= m; i++) {       string s;       cin >> s;       vec.push_back(s);     }     long long q;     cin >> q;     while (q--) {       long long a;       cin >> a;       long long u = a % v.size();       cout << v[(u - 1 + v.size()) % v.size()];       u = a % vec.size();       cout << vec[(u - 1 + vec.size()) % vec.size()];       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   void z_func(const string &s, vector<int> &z) {     int L = 0, R = 0;     int n = s.length();     z.resize(n);     for (int i = 1; i < n; i++) {       if (i > R) {         L = R = i;         while (R < n && s[R - L] == s[R]) R++;         z[i] = R - L;         R--;       } else {         int k = i - L;         if (z[k] < R - i + 1)           z[i] = z[k];         else {           L = i;           while (R < n && s[R - L] == s[R]) R++;           z[i] = R - L;           R--;         }       }     }   }   int main() {     string str;     cin >> str;     vector<int> z;     z_func(str, z);     int maxz = 0, res = 0;     int n = (int)str.length();     for (int i = 0; i < (int)str.length(); i++) {       if (z[i] == n - i) {         if (maxz >= z[i]) res = max(res, z[i]);       }       maxz = max(maxz, z[i]);     }     if (res == 0)       cout <<  Just a legend  << endl;     else       cout << str.substr(0, res) << endl;     return 0;   }