malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long read() {     long long w = 0, f = 1;     char c =    ;     while (c <  0  || c >  9 ) c = getchar(), f = c ==  -  ? -1 : f;     while (c >=  0  && c <=  9 ) w = w * 10 + c - 48, c = getchar();     return w * f;   }   long long read14() {     char c = getchar();     while (c !=  U  && c !=  D  && c !=  L  && c !=  R ) c = getchar();     if (c ==  U ) return 1;     if (c ==  D ) return 2;     if (c ==  L ) return 3;     return 4;   }   long long n, m, p[200005], dl[200005], dr[200005];   vector<long long> a[200005], e[200005];   long long pos(long long x, long long y) {     if (x >= 1 && x <= n && y >= 1 && y <= m) return (x - 1) * m + y;     return n * m + 1 + ((x + y) & 1);   }   long long minn[200005 << 2], tag[200005 << 2], val[200005 << 2];   void build(long long p, long long l, long long r) {     if (l == r) {       val[p] = 1;       return;     }     long long mid = (l + r) >> 1;     build(p << 1, l, mid);     build(p << 1 | 1, mid + 1, r);     val[p] = val[p << 1] + val[p << 1 | 1];   }   void down(long long p, long long l, long long r) {     if (!tag[p]) return;     minn[p << 1] += tag[p];     minn[p << 1 | 1] += tag[p];     tag[p << 1] += tag[p];     tag[p << 1 | 1] += tag[p];     tag[p] = 0;   }   void update(long long p, long long x, long long y, long long v, long long l,               long long r) {     if (x <= l && y >= r) {       minn[p] += v, tag[p] += v;       return;     }     down(p, l, r);     long long mid = (l + r) >> 1;     if (x <= mid) update(p << 1, x, y, v, l, mid);     if (y > mid) update(p << 1 | 1, x, y, v, mid + 1, r);     if (minn[p << 1] == minn[p << 1 | 1])       val[p] = val[p << 1] + val[p << 1 | 1];     else if (minn[p << 1] < minn[p << 1 | 1])       val[p] = val[p << 1];     else       val[p] = val[p << 1 | 1];     minn[p] = min(minn[p << 1], minn[p << 1 | 1]);   }   long long now, ans;   void dfs1(long long u) {     dl[u] = ++now;     for (auto v : e[u]) dfs1(v);     dr[u] = now;   }   void dfs2(long long u, long long rt) {     if (u != rt) update(1, dl[p[u]], dr[p[u]], 1, 1, now), ans -= val[1] - 1;     for (auto v : e[u]) dfs2(v, rt);     if (u != rt) update(1, dl[p[u]], dr[p[u]], -1, 1, now);   }   signed main() {     n = read(), m = read(), ans = n * n * m * m / 4;     for (long long i = 1; i <= n; i++) {       a[i].push_back(0);       for (long long j = 1; j <= m; j++) {         a[i].push_back(read14());         if (a[i][j] == 1)           e[pos(i + 2, j)].push_back(pos(i, j)), p[pos(i, j)] = pos(i + 1, j);         if (a[i][j] == 2)           e[pos(i - 2, j)].push_back(pos(i, j)), p[pos(i, j)] = pos(i - 1, j);         if (a[i][j] == 3)           e[pos(i, j + 2)].push_back(pos(i, j)), p[pos(i, j)] = pos(i, j + 1);         if (a[i][j] == 4)           e[pos(i, j - 2)].push_back(pos(i, j)), p[pos(i, j)] = pos(i, j - 1);       }     }     dfs1(n * m + 1);     build(1, 1, now);     dfs2(n * m + 2, n * m + 2);     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, apple[200000], a, b;   long long tot = 0;   vector<int> adj[200000];   int GCD(long long x, long long y) {     if (y == 0) return x;     return GCD(y, x % y);   }   pair<long long, long long> DFS(int ant, int act) {     if (adj[act].size() == 1) return make_pair(apple[act], 1);     vector<pair<long long, long long> > V;     for (int i = 0; i < adj[act].size(); i++) {       if (adj[act][i] == ant) continue;       V.push_back(DFS(act, adj[act][i]));     }     long long mn = V[0].first;     for (int i = 0; i < V.size(); i++) mn = min(mn, V[i].first);     long long mcm = V[0].second;     for (int i = 1; i < V.size(); i++) {       if (mcm > mn) break;       mcm = (mcm * V[i].second) / GCD(mcm, V[i].second);     }     return make_pair(V.size() * mcm * (mn / mcm), V.size() * mcm);   }   int main() {     scanf( %d , &(n));     for (int i = 1; i <= n; i++) {       scanf( %d , &(apple[i]));       tot += apple[i];     }     for (int i = 1; i < n; i++) {       scanf( %d%d , &(a), &(b));       adj[a].push_back(b);       adj[b].push_back(a);     }     adj[1].push_back(0);     cout << tot - DFS(0, 1).first << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     int k, n;     cin >> n >> k;     int val[100000];     int awake[100000];     for (int i = 0; i < n; ++i) {       cin >> val[i];     }     int sum = 0;     int extra = 0;     int max = 0;     for (int i = 0; i < n; ++i) {       cin >> awake[i];       if (awake[i]) {         sum += val[i];         val[i] = 0;       }       if (i < k) {         extra += val[i];       } else {         extra = extra + val[i] - val[i - k];       }       if (extra > max) {         max = extra;       }     }     sum += max;     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int c, e = 0;     long long int s = 0, a;     for (long long int i = 0; i < n; i++) {       cin >> a;       s += a;       if (a % 2 != 0) {         e++;         if (e == 1)           c = a;         else if (e > 1)           c = min(c, a);       }     }     if (e % 2 != 0) s -= c;     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 10;   const long long inf = 1e14 + 10;   long long n, k;   long long a[N];   long long ps[N];   long long fen[N];   vector<long long> vec;   void upd(long long x) {     for (; x < N; x += (x & (-x))) {       fen[x]++;     }   }   long long get(long long x) {     long long ret = 0;     for (; x > 0; x -= (x & (-x))) {       ret += fen[x];     }     return ret;   }   bool check(long long K) {     long long res = 0;     for (long long i = 0; i < N; i++) {       fen[i] = 0;     }     for (long long i = 1; i <= n; i++) {       long long val = ps[i] - K;       long long ind = upper_bound(vec.begin(), vec.end(), val) - vec.begin();       res += get(ind);       ind = upper_bound(vec.begin(), vec.end(), ps[i]) - vec.begin();       upd(ind);       if (ps[i] >= K) {         res++;       }     }     if (res >= k) {       return true;     } else {       return false;     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       ps[i] = ps[i - 1] + a[i];       vec.push_back(ps[i]);     }     sort(vec.begin(), vec.end());     long long L = -inf;     long long R = inf;     while (R - L > 1) {       long long mid = (L + R) / 2;       if (check(mid)) {         L = mid;       } else {         R = mid;       }     }     cout << L;     return 0;   }
#include <bits/stdc++.h>   int cmpfunc(const void* a, const void* b) { return (*(int*)a - *(int*)b); }   int main() {     int t, x, i, j, c;     scanf( %d , &t);     while (t--) {       char n[101];       int m[101];       scanf( %s , &n);       x = strlen(n);       j = 0;       c = 0;       for (i = 0; i < x; i++) {         if (n[i] ==  1 )           c++;         else if (c > 0) {           m[j++] = c;           c = 0;         }       }       if (c > 0) m[j++] = c;       qsort(m, j, sizeof(int), cmpfunc);       c = 0;       for (i = j - 1; i >= 0; i = i - 2) c = c + m[i];       printf( %d n , c);     }   }
#include <bits/stdc++.h>   using namespace std;   long long ans[100004] = {0};   vector<long long> v[100005];   int main() {     long long n, m, i, j, ms = 0, sum = 0, res = 0;     scanf( %lld %lld , &n, &m);     for (i = 0; i < n; i++) {       long long a, b;       scanf( %lld %lld , &a, &b);       v[a].push_back(b);     }     for (i = 1; i <= m; i++) {       sum = 0;       sort(v[i].begin(), v[i].end());       long long si = v[i].size();       ms = max(ms, si);       for (j = si - 1; j >= 0; j--) {         sum += v[i][j];         if (sum > 0)           ans[si - j] += sum;         else           break;       }     }     for (i = 1; i <= ms; i++) res = max(res, ans[i]);     printf( %lld n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int cmx = 1e5 + 5;   int n, k;   char a[505][505];   int id[505][505];   int cc_sz[505 * 505];   int seen[505 * 505];   bool inside(int x, int y) {     if (0 <= min(x, y) and max(x, y) < n) return true;     return false;   }   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, -1, 1};   void dfs(int x, int y, int cc_no) {     id[x][y] = cc_no;     cc_sz[cc_no]++;     for (int i = 0; i < 4; i++) {       int nx = x + dx[i];       int ny = y + dy[i];       if (inside(nx, ny) and (id[nx][ny] == 0 and a[nx][ny] ==  . ))         dfs(nx, ny, cc_no);     }   }   void add(int x, int y, int &ans, int flag) {     if (a[x][y] ==  .  and seen[id[x][y]] != flag) {       seen[id[x][y]] = flag;       ans += cc_sz[id[x][y]];     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = (0); i <= (n - 1); ++i)       for (int j = (0); j <= (n - 1); ++j) cin >> a[i][j];     int which_cc = 0;     for (int i = (0); i <= (n - 1); ++i)       for (int j = (0); j <= (n - 1); ++j) {         if (id[i][j] == 0 and a[i][j] ==  . ) {           dfs(i, j, ++which_cc);         }       }     int counter = 1;     int best_ans = 0;     for (int y_low = 0; (y_low + k) <= n; y_low++) {       for (int x = 0; x < k; x++)         for (int y = y_low; y < (y_low + k); y++) --cc_sz[id[x][y]];       for (int x_low = 0; (x_low + k) <= n; x_low++) {         int ans = k * k;         for (int x = 0; x < k; x++) {           if (inside(x_low + x, y_low - 1))             add(x_low + x, y_low - 1, ans, counter);           if (inside(x_low + x, y_low + k))             add(x_low + x, y_low + k, ans, counter);         }         for (int y = 0; y < k; y++) {           if (inside(x_low - 1, y_low + y))             add(x_low - 1, y_low + y, ans, counter);           if (inside(x_low + k, y_low + y))             add(x_low + k, y_low + y, ans, counter);         }         counter++;         best_ans = max(best_ans, ans);         if ((x_low + k) != n) {           for (int y = 0; y < k; y++) {             ++cc_sz[id[x_low][y + y_low]];             --cc_sz[id[x_low + k][y + y_low]];           }         }       }       for (int x = n - k; x < n; x++)         for (int y = 0; y < k; y++) ++cc_sz[id[x][y_low + y]];     }     cout << best_ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     int mark = 1;     for (int i = 1; i < s.size(); i++) {       if (s[i] != s[i - 1]) {         mark = -1;         break;       }     }     if (mark == 1) {       cout << s;       for (int i = 1; i < k; i++) {         cout << s[0];       }       return 0;     }     for (int i = s.size() - 1; i >= 1; i--) {       string t1 = s.substr(0, i);       string t2 = s.substr(s.size() - i, i);       if (t1 == t2) {         int len = s.size() - i;         string ost = s.substr(i, len);         string ans = s;         for (int j = 1; j < k; j++) {           ans += ost;         }         int kol = 0;         for (int j = 0; j + s.size() <= ans.size(); j++) {           string mr = ans.substr(j, s.size());           if (mr == s) {             kol++;             if (kol == k) {               string prt = ans.substr(0, j + s.size());               cout << prt << endl;               return 0;             }           }         }       }     }     for (int i = 1; i <= k; i++) {       cout << s;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, s[200003], m, cnt, ans[200003];   vector<pair<int, int> > v[200003], g[200003];   bool vis[200003];   int dfs(int x) {     vis[x] = 1;     int ret = 0, tmp;     for (int i = 0; i < v[x].size(); i++)       if (!vis[v[x][i].first]) {         tmp = dfs(v[x][i].first);         ret += tmp;         ans[v[x][i].second] = -tmp;       }     for (int i = 0; i < g[x].size(); i++)       if (!vis[g[x][i].first]) {         tmp = dfs(g[x][i].first);         ret += tmp;         ans[g[x][i].second] = tmp;       }     return ret - s[x];   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , s + i), cnt += s[i];     cin >> m;     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       v[x].push_back(make_pair(y, i));       g[y].push_back(make_pair(x, i));     }     if (cnt) {       cout <<  Impossible ;       return 0;     }     cout <<  Possible ;     dfs(0);     for (int i = 0; i < m; i++) printf(  n%d , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, j = 0;     cin >> a >> b >> c;     for (int i = 1; i <= a; i++) {       if (b >= 2 * i && c >= 4 * i) j++;     }     cout << j + 2 * j + 4 * j;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Counter {     static int k;     Counter() { k++; }     ~Counter() { k--; }   };   int Counter::k = 0;   template <typename T>   void pr(const string& name, T t) {     cout << name <<   =   << t << endl;   }   template <typename T, typename... Types>   void pr(const string& names, T t, Types... rest) {     auto comma_pos = names.find( , );     cout << names.substr(0, comma_pos) <<   =   << t <<  ,  ;     auto next_name_pos = names.find_first_not_of(   t n , comma_pos + 1);     pr(string(names, next_name_pos), rest...);   }   void mod(long long& a, long long b) {     a %= b;     if (a < 0) a += b;   }   const long long MOD = 1000000007;   deque<long long> DQ;   long long Days[15], N, M;   int main() {     cin >> N >> M;     string line;     Days[1] = 0;     Days[2] = 31;     Days[3] = 59;     Days[4] = 90;     Days[5] = 120;     Days[6] = 151;     Days[7] = 181;     Days[8] = 212;     Days[9] = 243;     Days[10] = 273;     Days[11] = 304;     Days[12] = 334;     getline(cin, line);     while (true) {       getline(cin, line);       if (cin.eof()) break;       long long year = 0, month = 0, day = 0;       for (int i = (0); i <= (3); i++) year = 10 * year + line[i] -  0 ;       for (int i = (5); i <= (6); i++) month = 10 * month + line[i] -  0 ;       for (int i = (8); i <= (9); i++) day = 10 * day + line[i] -  0 ;       long long days = 365 * (year - 1) + Days[month] + day - 1;       days += (year - 1) / 4;       if (year % 4 == 0 && month > 2) days++;       long long hr = 10 * (line[11] -  0 ) + line[12] -  0 ;       long long mn = 10 * (line[14] -  0 ) + line[15] -  0 ;       long long sc = 10 * (line[17] -  0 ) + line[18] -  0 ;       long long sec = days * 60 * 60 * 24 + 3600 * hr + 60 * mn + sc;       if (!DQ.empty() && sec - DQ.front() >= N) DQ.pop_front();       DQ.push_back(sec);       if (DQ.size() >= M) {         cout << line.substr(0, 19) <<   n ;         return 0;       }     }     cout <<  -1 ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[102], b[102];   int main(void) {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; ++i) scanf( %d %d , &a[i], &b[i]);     for (int x = 1; x <= n; ++x) {       int c = 0;       for (int i = 0; i < m; ++i)         if (x >= a[i] && x <= b[i]) ++c;       if (c != 1) {         printf( %d %d n , x, c);         return 0;       }     }     puts( OK );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100100;   long double a[maxn];   int main() {     int n, s;     long long k, b;     while (~scanf( %d , &n)) {       s = 0;       for (int i = 0; i < n; i++) {         scanf( %I64d %I64d , &k, &b);         if (k != 0) {           a[s++] = -(double)(b * 1.0) / (k * 1.0);         }       }       sort(a, a + s);       int count = 0;       for (int i = 1; i < s; i++) {         if (fabs(a[i] - a[i - 1]) > 0) {           count++;         }       }       if (s > 0) {         count++;       }       printf( %d n , count);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long bip(long long x, long long n, long long mod) {     long long res = 1;     while (n) {       if (n & 1) {         res = (res * x) % mod;       }       x = (x * x) % mod;       n >>= 1;     }     return res;   }   const int maxn = INT_MAX;   const long long inf = 1e18;   const int mod = 998244353;   const int N = 1e5 + 10;   void solve() {     string a, b;     cin >> a >> b;     if ((int)b.size() > (int)a.size()) {       sort(a.begin(), a.end());       reverse(a.begin(), a.end());       cout << a;       return;     }     vector<int> cnt(10, 0);     for (int i = 0; i < (int)a.size(); i++) cnt[a[i] -  0 ]++;     vector<int> ans;     for (int i = 0; i < (int)b.size(); i++) {       int k = b[i] -  0 ;       bool ok = 0;       for (int j = k; j >= 0; j--) {         if (cnt[j]) {           ok = 1;           cnt[j]--;           ans.push_back(j);           if (j < k) {             for (int l = 9; l >= 0; l--) {               while (cnt[l]--) ans.push_back(l);             }             for (auto it : ans) cout << it;             return;           }           break;         }       }       if (ok == 0) {         for (int p = i - 1; p >= 0; p--) {           int k = b[p] -  0 ;           ans.pop_back();           cnt[k]++;           bool ok = 0;           for (int j = k - 1; j >= 0; j--) {             if (cnt[j]) {               ok = 1;               break;             }           }           if (ok) {             for (int j = k - 1; j >= 0; j--) {               if (cnt[j]) {                 ans.push_back(j);                 cnt[j]--;                 for (int l = 9; l >= 0; l--) {                   while (cnt[l]--) ans.push_back(l);                 }                 for (auto it : ans) cout << it;                 return;               }             }           }         }       }     }     for (auto it : ans) cout << it;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int tt = 1;     while (tt--) {       solve();       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 100000 + 19;   int a[Maxn], Le[Maxn], Ri[Maxn], cnt, L, R, n, i, ans;   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     Le[cnt = 1] = 1;     a[++n] = a[n - 1] - 1;     for (i = 1; i <= n; i++)       if (a[i] <= a[i - 1]) {         Ri[cnt] = i - 1;         ans = max(ans, Ri[cnt] - Le[cnt] + 1);         Le[++cnt] = i;       }     for (i = 1; i < cnt; i++) {       if (Ri[i] < n - 1 || Le[i] > 1) ans = max(ans, Ri[i] - Le[i] + 2);       if (i > 1)         if (Ri[i - 1] > Le[i - 1] && Ri[i] > Le[i]) {           if (a[Ri[i - 1] - 1] < a[Le[i]] - 1 || a[Ri[i - 1]] < a[Le[i] + 1] - 1)             ans = max(ans, Ri[i] - Le[i - 1] + 1);         } else {           if (Ri[i - 1] == Le[i - 1]) ans = max(ans, Ri[i] - Le[i] + 2);           if (Ri[i] == Le[i]) ans = max(ans, Ri[i - 1] - Le[i - 1] + 2);         }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   vector<int> path[1005];   long long d[105], t[105];   int n, m, u, v;   queue<int> q;   void work(int now) {     for (int i = 1; i <= n; i++) {       d[i] = 1 << 30;       t[i] = 0;     }     d[now] = 0;     t[now] = 1;     q.push(now);     while (!q.empty()) {       u = q.front();       q.pop();       for (int i = 0; i < path[u].size(); i++) {         v = path[u][i];         if (d[v] > d[u] + 1) {           d[v] = d[u] + 1;           t[v] = t[u];           q.push(v);         } else if (d[v] == d[u] + 1) {           t[v] += t[u];         }       }     }   }   int main() {     long long len = 0, tmp = 0;     double ans = 1.0;     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d %d , &u, &v);       path[u].push_back(v);       path[v].push_back(u);     }     int start = 1;     work(start), start++;     len = d[n], tmp = t[n];     for (int i = start; i < n; i++) {       start = 1;       work(i);       int see = 0;       see = d[start] + d[n];       if (see == len) {         double k = 0;         k = (double)(2.0 * t[start] * t[n]) / (1.0 * tmp);         ans = max(ans, k);       }     }     printf( %.12lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long p, q, b, n, tmp;   long long gcd(int x, int y) { return y ? gcd(y, x % y) : x; }   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie();     cin >> n;     for (int i = 0; i < n; i++) {       cin >> p >> q >> b;       q = q / gcd(q, p);       while ((tmp = gcd(q, b)) != 1)         while (q % tmp == 0) q /= tmp;       if (q == 1)         cout <<  Finite  << endl;       else         cout <<  Infinite  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   long long binpow(long long a, long long b) {     if (b == 0) return 1;     long long res = binpow(a, b / 2);     if (b % 2)       return res * res * a;     else       return res * res;   }   vector<int> adj[200006];   bool vis[200006];   bool color[200006];   bool dfs(int x) {     vis[x] = 1;     for (int i = 0; i < adj[x].size(); i++) {       if (!vis[adj[x][i]]) {         color[adj[x][i]] = !color[x];         if (!dfs(adj[x][i])) return false;       } else if (color[adj[x][i]] == color[x]) {         return false;       }     }     return true;   }   bool check(int a, int b) {     while (a != 0) {       int x = a % 10;       if (x == 7) return 1;       a /= 10;     }     while (b != 0) {       int xx = b % 10;       if (xx == 7) return 1;       b /= 10;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tt;     cin >> tt;     vector<pair<pair<int, int>, char>> vv;     int ewq = 0;     while (tt--) {       char c;       int r, l;       cin >> c >> l >> r;       vv.push_back({{l, r}, c});     }     sort(vv.begin(), vv.end());     int F = 0;     int M = 0;     for (int i = 1; i <= 366; i++) {       F = 0;       M = 0;       for (int j = 0; j < vv.size(); j++) {         if (i >= vv[j].first.first && i <= vv[j].first.second) {           if (vv[j].second ==  F )             F++;           else             M++;         }       }       ewq = max(min(F, M), ewq);     }     cout << ewq * 2 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k;     cin >> n >> k;     string x;     cin >> x;     string ans = x;     string y =   ;     long long p = n;     for (long long i = 1; i < n; i++) {       long long j;       y =   ;       for (j = 0; i + j < n; j++) {         if (x[i + j] != ans[j]) break;         y += ans[j];       }       if (i + j == n) {         p = i;         break;       }     }     p = n - p;     while (p--) {       ans.erase(ans.begin());     }     cout << x;     while (--k) {       cout << ans;     }     cout << endl;   }