malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   string tostr(int n) {     stringstream rr;     rr << n;     return rr.str();   }   long long qpow(long long n, long long k) {     long long ans = 1;     while (k) {       if (k & 1) ans = ans * n;       n = n * n;       k >>= 1;     }     return ans;   }   const int mod = 1e9 + 7;   const int mxn = 1e5 + 9;   const int eps = 1e-9;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     int i, j, k, l, st;     vector<char> v;     string s, p;     cin >> s;     if (s[0] ==  - )       st = 1, cout <<  ( ;     else       st = 0;     cout <<  $ ;     p = s.substr(st);     if (p.find( . ) == -1)       for (i = p.size() - 1; i >= 0; i--) {         v.push_back(p[i]);         if ((p.size() - i) % 3 == 0 && i != 0) v.push_back( , );       }     else       for (i = p.find( . ) - 1; i >= 0; i--) {         v.push_back(p[i]);         if ((p.find( . ) - i) % 3 == 0 && i != 0) v.push_back( , );       }     reverse(v.begin(), v.end());     for (auto c : v) cout << c;     cout <<  . ;     if (p.find( . ) == -1)       cout <<  00 ;     else {       cout << p[p.find( . ) + 1];       if (p[p.find( . ) + 2] !=   0 )         cout << p[p.find( . ) + 2];       else         cout <<  0 ;     }     if (st == 1) cout <<  ) ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 1;   int dp[N][N];   bool palid[N][N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     int n = s.size();     for (int d = 0; d < n; d++)       for (int i = 0; i < n; i++) {         int j = i + d;         if (j >= n) continue;         palid[i][j] = (s[i] == s[j]);         if (i + 1 <= j - 1) palid[i][j] &= palid[i + 1][j - 1];       }     for (int d = 0; d < n; d++)       for (int i = 0; i < n; i++) {         int j = i + d;         if (j >= n) continue;         dp[i][j] = palid[i][j];         if (i + 1 <= j) dp[i][j] += dp[i + 1][j];         if (i <= j - 1) dp[i][j] += dp[i][j - 1];         if (i + 1 <= j - 1) dp[i][j] -= dp[i + 1][j - 1];       }     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int l, r;       cin >> l >> r;       l--;       r--;       cout << dp[l][r] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, flag;   int ar[101][101], ars[101][101], c[101][101], q[101][101];   int fu() {     int y = 1;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (ars[i][j] != c[i][j]) y = 0;     return y;   }   void f() {     flag = max(flag, fu());     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) q[i][j] = c[j][n - i - 1];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) c[i][j] = q[i][j];     flag = max(flag, fu());     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) q[i][j] = c[j][n - i - 1];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) c[i][j] = q[i][j];     flag = max(flag, fu());     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) q[i][j] = c[j][n - i - 1];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) c[i][j] = q[i][j];     flag = max(flag, fu());   }   int main() {     cin >> n;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         char a;         cin >> a;         if (a ==  X )           ar[i][j] = 0;         else           ar[i][j] = 1;         c[i][j] = ar[i][j];       }     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         char a;         cin >> a;         if (a ==  X )           ars[i][j] = 0;         else           ars[i][j] = 1;       }     f();     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) c[i][j] = ar[n - i - 1][j];     f();     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) c[i][j] = ar[i][n - j - 1];     f();     if (flag) {       cout <<  Yes ;     } else       cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   int main() {     int a, b, c, count = 0, i, j;     scanf( %d%d%d , &a, &b, &c);     if ((a == c) || (b == c)) {       count++;     } else {       for (i = 0; i <= c; i += a) {         for (j = 0; j <= c; j += b) {           if ((i + j) == c) {             count++;             break;           }         }       }     }     if (count != 0) {       printf( Yes );     } else {       printf( No );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j, a, b, k;     vector<vector<bool> > M;     cin >> n;     m = 5;     M.resize(m);     for (i = 0; i < m; i++) M[i].resize(m);     for (i = 0; i < n; i++) {       cin >> a >> b;       a--;       b--;       M[a][b] = M[b][a] = true;     }     for (i = 0; i < m - 2; i++)       for (j = i + 1; j < m - 1; j++)         for (k = j + 1; k < m; k++)           if (M[i][j] == M[i][k] && M[i][j] == M[j][k]) {             cout <<  WIN ;             return 0;           }     cout <<  FAIL ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int flag = 0;     char s[6][6];     for (int i = 0; i < 4; i++)       for (int j = 0; j < 4; j++) cin >> s[i][j];     for (int i = 0; i < 4; i++) {       if (flag) break;       for (int j = 0; j < 4; j++) {         if (s[i][j] ==  x  && s[i][j + 1] ==  x  &&             (s[i][j + 2] ==  .  || s[i][j - 1] ==  . )) {           cout <<  YES ;           flag = 1;           break;         } else if (s[i][j] ==  x  && s[i][j + 1] ==  .  && s[i][j + 2] ==  x ) {           cout <<  YES ;           flag = 1;           break;         } else if (s[i][j] ==  x  && s[i + 1][j] ==  x  &&                    (s[i + 2][j] ==  .  || s[i - 1][j] ==  . )) {           cout <<  YES ;           flag = 1;           break;         } else if (s[i][j] ==  x  && s[i + 1][j] ==  .  && s[i + 2][j] ==  x ) {           cout <<  YES ;           flag = 1;           break;         } else if (s[i][j] ==  x  && s[i + 1][j + 1] ==  x  &&                    (s[i + 2][j + 2] ==  .  || s[i - 1][j - 1] ==  . )) {           cout <<  YES ;           flag = 1;           break;         } else if (s[i][j] ==  x  && s[i + 1][j + 1] ==  .  &&                    s[i + 2][j + 2] ==  x ) {           cout <<  YES ;           flag = 1;           break;         } else if (s[i][j] ==  x  && s[i + 1][j - 1] ==  x  &&                    (s[i + 2][j - 2] ==  .  || s[i - 1][j + 1] ==  . )) {           cout <<  YES ;           flag = 1;           break;         } else if (s[i][j] ==  x  && s[i + 1][j - 1] ==  .  &&                    s[i + 2][j - 2] ==  x ) {           cout <<  YES ;           flag = 1;           break;         }       }     }     if (!flag) cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   int main(void) {     int n, i;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       if ((i % 2) != 0) {         printf( I hate );         if (i == n) {           printf(  it );           break;         }       } else {         printf( I love );         if (i == n) {           printf(  it );           break;         }       }       printf(  that  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool IO_FILE = 0;   ifstream ifs( input.txt );   ofstream ofs( output.txt );   int main() {     if (IO_FILE) {       cin.rdbuf(ifs.rdbuf());       cout.rdbuf(ofs.rdbuf());     }     int n, m;     cin >> n >> m;     char *s = new char[m];     bool res = 1;     char prev =  E ;     for (int i = 0; i < n; i++) {       cin >> s;       char p = s[0];       res = 1;       if (prev !=  E  && p == prev) {         res = 0;         break;       }       for (int j = 1; j < m; j++)         if (!(res = s[j] == p)) break;       if (!res) break;       prev = p;     }     cout << (res ?  YES  :  NO );   }
#include <bits/stdc++.h>   using namespace std;   vector<int> d[2], f;   vector<vector<bool> > nab;   int n, len = -1;   const int INF = 1 << 29;   int calc(vector<bool> &a, vector<bool> &b) {     vector<bool> c(a.size() + b.size() + 1);     for (int i = 0; i < b.size(); ++i) c[i] = b[i];     for (int i = b.size(); i < c.size(); ++i) c[i + 1] = a[i - (int)b.size()];     vector<int> p(c.size());     p[0] = 0;     for (int i = 1; i < p.size(); ++i) {       int j = p[i - 1];       while (j > 0 && (c[i] != c[j] || i == b.size() || j == b.size()))         j = p[j - 1];       if (c[i] == c[j] && !(i == b.size() || j == b.size())) j++;       p[i] = j;     }     return p[c.size() - 1];   }   vector<vector<int> > p;   inline int suf(vector<bool> &a, int &l) {     int ans = 0;     for (int i = len - l; i < len; ++i) ans |= ((int)a[i] << (i + l - len));     return ans;   }   inline int pref(vector<bool> &a, int &l) {     int ans = 0;     for (int i = 0; i < l; ++i) ans |= ((int)a[i] << i);     return ans;   }   int main() {     cin.sync_with_stdio(0);     cin >> n;     nab.resize(n);     d[0].resize(n + 1);     d[1].resize(n + 1);     string str;     for (int i = 0; i < n; ++i) {       cin >> str;       if (len == -1) len = str.size();       nab[i].resize(len);       for (int j = 0; j < len; ++j) nab[i][j] = (str[j] ==  0  ? 0 : 1);     }     p.resize(len + 1, vector<int>(1 << len, -1));     d[0][0] = d[1][0] = 0;     p[0][0] = 1;     vector<int> f(n);     f[0] = len;     for (int i = 1; i < n; ++i) f[i] = f[i - 1] + len - calc(nab[i - 1], nab[i]);     int suffix[len + 1], prefix[len + 1];     d[1][1] = d[0][1] = len;     int bestp, bestd, now;     for (int i = 2; i <= n; ++i) {       d[0][i] = min(d[0][i - 1], d[1][i - 1]) + f[i - 1] - f[i - 2];       d[1][i] = INF;       for (int j = 1; j <= len; ++j) {         suffix[j] = suf(nab[i - 2], j);         prefix[j] = pref(nab[i - 1], j);       }       bestp = p[0][0];       d[1][i] = d[1][bestp] + f[i - 2] - f[bestp - 1] + len;       for (int j = 1; j <= len; ++j) {         int &pp = p[j][prefix[j]];         if (pp != -1) {           now = d[1][pp] + f[i - 2] - f[pp - 1] + len - j;           if (now < d[1][i]) {             d[1][i] = now;             bestp = pp;           }         }       }       if (d[1][i] < d[1][p[0][0]] + f[i - 1] - f[p[0][0] - 1]) p[0][0] = i;       for (int j = 1; j <= len; ++j) {         int &ps = p[j][suffix[j]];         if (ps == -1 || (d[1][i] < d[1][ps] + f[i - 1] - f[ps - 1])) ps = i;       }     }     cout << min(d[1][n], d[0][n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;      void solve(){       int n;       cin >> n;       vector<int64_t> X;       vector<int64_t> Y;       int x,y;       for (int i = 0; i < n; i++){           cin >> x >> y;           X.push_back(x);           Y.push_back(y);       }       sort(X.begin(),X.end());               sort(Y.begin(),Y.end());               int64_t res;       if (n%2 == 0){           res = (X.at(n/2)-X.at(n/2-1)+1)*(Y.at(n/2)-Y.at(n/2-1)+1);       } else {           res = 1;       }       cout << res << endl;       return;   }      int main() {       int t;       cin >> t;       while (t){           solve();           t--;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x0;     cin >> n >> x0;     int x = x0;     int a[n][2];     for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1];     int c = 0, d = 0;     for (int i = 0; i < n; i++) {       if (min(a[i][0], a[i][1]) > x) {         x = min(a[i][0], a[i][1]);         c++;       } else if (max(a[i][0], a[i][1]) < x) {         d++;         x = max(a[i][0], a[i][1]);       }       if (c > 0 && d > 0) break;     }     if (c > 0 && d > 0)       cout <<  -1 n ;     else {       c = 0;       for (int i = 0; i < n; i++) {         if (x >= min(a[i][0], a[i][1]) && x <= max(a[i][0], a[i][1])) c++;       }       if (c == n)         cout << abs(x - x0) << endl;       else         cout <<  -1 n ;     }   }
#include <bits/stdc++.h>   using namespace std;   void input() {     freopen( in.txt ,  r , stdin);     freopen( out.txt ,  w , stdout);   }   const int N = 1e6 + 10;   vector<int> G[N];   int in[N], n, cnt[3], vis[N];   void dfs(int x, int flag) {     cnt[flag]++;     vis[x] = 1;     for (int i = 0; i < G[x].size(); i++) {       int u = G[x][i];       if (vis[u]) continue;       dfs(u, (flag + 1) % 2);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n - 1; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     dfs(1, 1);     cout << min(cnt[0], cnt[1]) - 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   int main() {     int n, k;     scanf( %d %d , &n, &k);     int cnt = 0, a[100];     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; i++) {       if (a[i] >= a[k - 1] && a[i] > 0) cnt++;     }     printf( %d , cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n = 0;   vector<int> v;   int flag[2010];   int countt = 0;   int k = 0;   int maxt = 0;   int main() {     cin >> n;     cin >> k;     for (int i = 0; i < n; i++) {       int kari = 0;       cin >> kari;       v.push_back(kari);       if (i == 0) {         maxt = kari;       } else {         maxt = max(maxt, kari);       }     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         vector<int> u;         vector<int> d;         u.clear();         d.clear();         int sum = 0;         for (int jj = 0; jj < n; jj++) {           if (jj < i || j < jj) {             d.push_back(v[jj]);           } else {             sum += v[jj];             u.push_back(v[jj]);           }         }         sort(u.begin(), u.end());         sort(d.begin(), d.end());         maxt = max(maxt, sum);         {           int ii = 0;           int jj = d.size() - 1;           for (; ii < u.size() && jj >= 0 && ii < k; ii++, jj--) {             sum -= u[ii];             sum += d[jj];             maxt = max(maxt, sum);           }         }       }     }     cout << maxt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int64_t k = 0;   inline bool equals(string& s1, int64_t i1, int64_t j1, string& s2, int64_t i2,                      int64_t j2) {     if (j1 != j2) {       return false;     }     auto x = j1;     for (int64_t i = 0; i < x; i++) {       if (s1[i1 + i] != s2[i2 + i]) {         return false;       }     }     return true;   }   bool equivilant(string& s1, int64_t i1, int64_t j1, string& s2, int64_t i2,                   int64_t j2) {     if (equals(s1, i1, j1, s2, i2, j2)) {       return true;     }     if (j1 != j2 || j1 % 2 == 1) {       return false;     }     auto x = j1 / 2;     if (equivilant(s1, i1, x, s2, i2, x) &&         equivilant(s1, i1 + x, x, s2, i2 + x, x)) {       return true;     }     if (equivilant(s1, i1, x, s2, i2 + x, x) &&         equivilant(s1, i1 + x, x, s2, i2, x)) {       return true;     }     return false;   }   int main() {     ios::sync_with_stdio(false);     string s1;     cin >> s1;     string s2;     cin >> s2;     if (equivilant(s1, 0, s1.size(), s2, 0, s2.size())) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct QUERY {     int query, time, number;   };   void update(vector<map<int, int> > &tree, int v, int tl, int tr, int &pos,               int query, int value) {     if (pos < tl || pos > tr) return;     if (query == 1)       tree[v][value]++;     else if (query == 2)       tree[v][value]--;     if (tr != tl) {       update(tree, 2 * v, tl, (tr + tl) / 2, pos, query, value);       update(tree, 2 * v + 1, (tr + tl) / 2 + 1, tr, pos, query, value);     }   }   int sum(vector<map<int, int> > &tree, int v, int tl, int tr, int i, int j,           int value) {     if (i > tr || j < tl) return 0;     if (i <= tl && j >= tr) return tree[v][value];     int sum1 = sum(tree, 2 * v, tl, (tr + tl) / 2, i, j, value);     int sum2 = sum(tree, 2 * v + 1, (tr + tl) / 2 + 1, tr, i, j, value);     return sum1 + sum2;   }   int main() {     int n;     cin >> n;     vector<QUERY> a(n + 1);     vector<int> num(n + 1);     vector<int> t(n + 1);     for (int i = 1; i <= n; ++i) {       cin >> a[i].query >> a[i].time >> a[i].number;       num[i] = a[i].number;       t[i] = a[i].time;     }     sort(num.begin(), num.end());     num.erase(unique(num.begin(), num.end()), num.end());     sort(t.begin(), t.end());     t.erase(unique(t.begin(), t.end()), t.end());     map<int, int> help;     for (unsigned int i = 1; i < num.size(); ++i) {       help.insert(make_pair(num[i], i));     }     for (int i = 1; i <= n; ++i) {       a[i].number = help[a[i].number];     }     help.clear();     for (unsigned int i = 1; i < t.size(); ++i) {       help.insert(make_pair(t[i], i));     }     for (int i = 1; i <= n; ++i) {       a[i].time = help[a[i].time];     }     int len = t.size() - 1;     int tree_size = 4 * len;     vector<map<int, int> > tree(tree_size);     for (int i = 1; i <= n; ++i) {       if (a[i].query != 3)         update(tree, 1, 1, len, a[i].time, a[i].query, a[i].number);       else         cout << sum(tree, 1, 1, len, 1, a[i].time, a[i].number) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 10;   int n;   int a[N];   long long query(int l, int r) {     vector<pair<long long, long long> > stack;     long long ret = 0;     long long cur = 0;     for (int i = l + 1; i <= r; ++i) {       long long diff = abs(a[i] - a[i - 1]);       long long tot = 1;       for (; stack.size();) {         if (stack.back().first <= diff) {           tot += stack.back().second;           cur -= stack.back().first * stack.back().second;           stack.pop_back();         } else {           break;         }       }       stack.push_back(make_pair(diff, tot));       cur += diff * tot;       ret += cur;     }     return ret;   }   void solve() {     int q;     cin >> n >> q;     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);     }     for (; q--;) {       int l, r;       scanf( %d%d , &l, &r);       --l, --r;       cout << query(l, r) << endl;     }   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long s, k;   long long a[5000];   long long ans[5000];   int t;   int dfs(int n, int m) {     if (n == 0) {       if (t == 1) {         cout << 2 << endl;         cout << 0 <<     << ans[0] << endl;       } else {         cout << t << endl;         for (int i = t - 1; i >= 0; i--) cout << ans[i] <<    ;         cout << endl;       }       exit(0);     }     for (int i = m; i >= 0; i--) {       if (n >= a[i]) {         ans[t++] = a[i];         dfs(n - a[i], i - 1);         t--;       }     }   }   int main() {     cin >> s >> k;     int m = 0;     a[0] = 1;     for (int i = 1; a[i - 1] < s; i++) {       for (int j = i - 1; j >= 0 && j >= i - k; j--) a[i] += a[j];       m = i;     }     if (a[m] > s) m--;     dfs(s, m);   }
#include <bits/stdc++.h>   int cmp(const void *a, const void *b) { return (*(int *)a - *(int *)b); }   long long int mod;   void f(long long int p) {     long long ans = 1, n = 3;     while (p) {       if (p & 1) ans = (ans * n) % mod;       n = (n * n) % mod;       p = p >> 1;     }     ans--;     while (ans < 0) ans += mod;     printf( %lld , ans);   }   int main() {     long long int n;     scanf( %lld%lld , &n, &mod);     f(n);     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:128777216 )   const int null = 0;   using namespace std;   template <class T>   int size(const T &a) {     return int(a.size());   }   template <class T>   T abs(const T &a) {     return (a < 0 ? -a : a);   }   template <class T>   T sqr(const T &a) {     return a * a;   }   const double pi = acos(-1.0);   const int max_n = 2048;   char s[max_n][max_n];   struct Res {     int r, c;     int d;     int moves;     Res() { moves = -1; }   } dp[max_n][max_n];   bool was[max_n][max_n];   Res &calc(int r, int c, int d = -1) {     Res &res = dp[r][c];     if (res.moves >= 0) {       return res;     }     if (was[r][c]) {       cout << -1 << endl;       exit(0);     }     was[r][c] = true;     switch (s[r][c]) {       case  # :         res.moves = 0;         res.d = -1;         res.r = r;         res.c = c;         break;       case  > :         res = calc(r, c + 1, 1);         res.moves++;         if (res.moves == 1) {           res.d = 1;         }         break;       case  < :         res = calc(r, c - 1, 2);         res.moves++;         if (res.moves == 1) {           res.d = 2;         }         break;       case  ^ :         res = calc(r - 1, c, 3);         res.moves++;         if (res.moves == 1) {           res.d = 3;         }         break;       case  v :         res = calc(r + 1, c, 4);         res.moves++;         if (res.moves == 1) {           res.d = 4;         }         break;     }     return res;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %s , s[i]);     }     int res = 0;     Res best;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         Res cur = calc(i, j);         if (cur.moves > best.moves) {           best = cur;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         Res cur = dp[i][j];         if (cur.moves + best.moves > res &&             (cur.d != best.d || cur.r != best.r || cur.c != best.c ||              cur.moves != best.moves)) {           res = cur.moves + best.moves;         }       }     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int T, x;   char str[100005], ans[100005];   char usd[100005];   int main() {     scanf( %d , &T);     while (T--) {       scanf( %s , str + 1);       scanf( %d , &x);       int n = strlen(str + 1);       for (int i = 1; i <= n; ++i) {         if (str[i] ==  0 ) {           if (i + x <= n) ans[i + x] =  0 ;           if (i - x >= 1) ans[i - x] =  0 ;         }       }       for (int i = 1; i <= n; ++i)         if (!ans[i]) ans[i] =  1 ;       for (int i = 1; i <= n; ++i) {         if (i - x >= 1 && ans[i - x] ==  1 )           usd[i] =  1 ;         else if (i + x <= n && ans[i + x] ==  1 )           usd[i] =  1 ;         else           usd[i] =  0 ;       }       bool flag = true;       for (int i = 1; i <= n; ++i)         if (usd[i] != str[i]) {           flag = false;           break;         }       if (!flag)         printf( -1 n );       else         printf( %s n , ans + 1);       for (int i = 1; i <= n; ++i) ans[i] = 0;     }     return 0;   }