malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll MOD = 1e9 + 7;   const int N = 2000;   int board[N][N];   bool flip_row[N];   bool flip_col[N];   int bar[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int y = 0; y < n; ++y) {       string str;       cin >> str;       for (int x = 0; x < n; ++x) {         if (str[x] ==  1 ) board[y][x] ^= 1;       }     }     for (int y = 0; y < n; ++y) {       string str;       cin >> str;       for (int x = 0; x < n; ++x) {         if (str[x] ==  1 ) board[y][x] ^= 1;       }     }     string str;     cin >> str;     for (int i = 0; i < n; ++i) {       if (str[i] ==  1 ) bar[i] ^= 1;     }     for (int y = 0; y < n; ++y) {       for (int x = 0; x < n; ++x) {         if (board[y][x]) {           if (!bar[y])             flip_row[y] = true;           else if (!bar[x])             flip_col[x] = true;         }       }     }     int y0 = 0;     for (y0 = 0; y0 < n; ++y0) {       if (!bar[y0]) continue;       for (int x = 0; x < n; ++x) {         if (bar[x] && board[y0][x]) {           flip_col[x] = true;         }       }       break;     }     for (int y = y0 + 1; y < n; ++y) {       if (!bar[y]) continue;       for (int x = 0; x < n; ++x) {         if (bar[x] && (board[y][x] ^ flip_col[x])) flip_row[y] = true;       }     }     bool fail = false;     for (int y = 0; y < n; ++y) {       for (int x = 0; x < n; ++x) {         if (flip_row[y]) board[y][x] ^= bar[x];         if (flip_col[x]) board[y][x] ^= bar[y];         if (board[y][x] == 1) fail = true;       }     }     if (fail) {       cout <<  -1 n ;     } else {       int cou = 0;       for (int i = 0; i < n; ++i) cou += flip_row[i] + flip_col[i];       cout << cou <<   n ;       for (int x = 0; x < n; ++x) {         if (flip_col[x]) cout <<  col   << x <<   n ;       }       for (int y = 0; y < n; ++y) {         if (flip_row[y]) cout <<  row   << y <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   template <class T>   inline T lcm(T a, T b) {     a = abs(a);     b = abs(b);     return (a / gcd(a, b)) * b;   }   template <class T, class X>   inline bool getbit(T a, X i) {     T t = 1;     return ((a & (t << i)) > 0);   }   template <class T, class X>   inline T setbit(T a, X i) {     T t = 1;     return (a | (t << i));   }   template <class T, class X>   inline T resetbit(T a, X i) {     T t = 1;     return (a & (~(t << i)));   }   inline long long getnum() {     char c = getchar();     long long num, sign = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) sign = -1;     for (num = 0; c >=  0  && c <=  9 ;) {       c -=  0 ;       num = num * 10 + c;       c = getchar();     }     return num * sign;   }   inline long long power(long long a, long long b) {     long long multiply = 1;     for (int i = (0); i < (b); i++) {       multiply *= a;     }     return multiply;   }   string s, t;   long long up[100002], thash, shash[100002];   bool exist[100002];   long long aux[100002], dp[100002], help[100002];   int main() {     int test, cases = 1;     cin >> s >> t;     s =  #  + s;     int l = t.size(), n = s.size() - 1;     up[0] = 1;     for (int i = 1; i < 100002; i++) up[i] = (up[i - 1] * 43) % 1000000007LL;     for (int i = (0); i < (l); i++) {       thash = (thash + (t[i] -  a  + 1) * up[i]) % 1000000007LL;     }     for (int i = (1); i < (n + 1); i++) {       shash[i] = (shash[i - 1] + (s[i] -  a  + 1) * up[i - 1]) % 1000000007LL;     }     for (int i = n; i >= l; i--) {       long long now = (shash[i] - shash[i - l]) % 1000000007LL;       if (now < 0) now += 1000000007LL;       long long temp = (thash * up[i - l]) % 1000000007LL;       if (temp == now) {         exist[i] = true;       }     }     for (int i = 1; i <= n; i++) {       if (exist[i]) {         dp[i] = help[i - l] + i - l + 1;         dp[i] %= 1000000007LL;       } else         dp[i] = dp[i - 1];       aux[i] = dp[i];       aux[i] += aux[i - 1];       aux[i] %= 1000000007LL;       help[i] = help[i - 1] + aux[i];       help[i] %= 1000000007LL;     }     long long ans = 0;     for (int i = (1); i < (n + 1); i++) ans = (ans + dp[i]) % 1000000007LL;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   int dizi[200005][3], ans[200005];   int main() {     int n, i, x, y;     scanf( %d , &n);     if (n == 3) {       printf( 2 1 3 );       return 0;     }     for (i = 1; i <= n; i++) {       scanf( %d %d , &x, &y);       dizi[i][1] = x;       dizi[i][2] = y;     }     for (i = 1; i <= n; i++) {       x = dizi[i][1];       y = dizi[i][2];       if (dizi[x][1] == y || dizi[x][2] == y) {         dizi[i][1] = x;         dizi[i][2] = y;       } else {         dizi[i][1] = y;         dizi[i][2] = x;       }     }     y = 1;     for (i = 1; i <= n; i++) {       x = dizi[y][1];       printf( %d  , x);       y = x;     }   }
#include <bits/stdc++.h>   using namespace std;   int cnt[(1 << 19)], mn[(1 << 19)], mx[(1 << 19)], ans[(1 << 19)];   void solve(int L, int R) {     if (L + 1 == R) {       ans[L] = 0x3f3f3f3f;       mn[L] = cnt[L] ? 0 : 0x3f3f3f3f;       mx[L] = cnt[L] ? 0 : -0x3f3f3f3f;     } else {       int M = (L + R) / 2, i, H = M - L;       solve(L, M), solve(M, R);       for (i = L; i < M; ++i) {         int mn1 = mn[i], mx1 = mx[i], ans1 = ans[i], mn2 = mn[i + H],             mx2 = mx[i + H], ans2 = ans[i + H];         mn[i] = min(mn1, mn2 + H);         mx[i] = max(mx1, mx2 + H);         ans[i] = min({ans1, ans2, mn2 + H - mx1});         mn[i + H] = min(mn2, mn1 + H);         mx[i + H] = max(mx2, mx1 + H);         ans[i + H] = min({ans1, ans2, mn1 + H - mx2});       }     }   }   int main() {     int n, k, i;     scanf( %d%d , &n, &k);     while (n--) {       scanf( %d , &i);       ++cnt[i];     }     solve(0, 1 << k);     for (i = 0; i < (1 << k); ++i) printf( %d  , ans[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   const int MAXN = 1000100;   int q = 0, qq, n;   double x[MAXN], y[MAXN];   double c1[MAXN];   double c2[MAXN];   double c[MAXN];   void solve() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> c1[i];     }     for (int i = 0; i < n; ++i) {       cin >> c2[i];       c[i] = c2[i] + c1[i];     }     double s1 = 0, s2 = 0;     for (int i = 0; i < n; ++i) {       double b = (c[i] + s2 - s1);       double x1 =           -(-b + sqrt(max(0.0, ((b) * (b)) + 4 * (c[i] * s1 - c1[i])))) / 2;       double x2 =           -(-b - sqrt(max(0.0, ((b) * (b)) + 4 * (c[i] * s1 - c1[i])))) / 2;       x[i] = max(x1, x2);       y[i] = c[i] - x[i];       s1 += x[i];       s2 += y[i];     }     cout.precision(10);     for (int i = 0; i < n; ++i) cout << fixed << x[i] <<    ;     cout << endl;     for (int i = 0; i < n; ++i) cout << fixed << y[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     srand(1313);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, count = 0;     cin >> n;     char arr[n][n];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> arr[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         count = 0;         int a = i - 1, b = i + 1, c = j - 1, d = j + 1;         if (a >= 0 && a < n)           if (arr[a][j] ==  o ) count++;         if (b >= 0 && b < n)           if (arr[b][j] ==  o ) count++;         if (c >= 0 && c < n)           if (arr[i][c] ==  o ) count++;         if (d >= 0 && d < n)           if (arr[i][d] ==  o ) count++;         if (count & 1) return cout <<  NO  << endl, 0;       }     }     return cout <<  YES  << endl, 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[400033], pp;   int main() {     int n, k, i;     scanf( %d%d , &n, &k);     for (i = 0; i < k; i++) scanf( %d , &arr[i]);     stack<int> s;     int curr = 1, pos = 1;     for (i = 0; i < k; i++) {       if (arr[i] == curr)         curr++;       else         s.push(arr[i]);       while (!s.empty() && s.top() == curr) {         curr++;         s.pop();       }     }     if (k == n) {       if (curr == (n + 1))         for (i = 0; i < k; i++) printf( %d  , arr[i]);       else         printf( -1 );       return 0;     }     while (1) {       if (s.empty()) {         int aa = n;         while (k < n) {           arr[k++] = aa--;         }         for (i = 0; i < k; i++) printf( %d  , arr[i]);         return 0;       } else {         int aa = s.top() - 1;         if (aa + 1 < curr) {           printf( -1 );           return 0;         }         while (k < n && aa >= curr) {           arr[k++] = aa--;         }         curr = s.top() + 1;         s.pop();       }       if (k > n) {         printf( -1 );         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool elem(set<T> st, T val) {     return (st.find(val) != st.end());   }   template <typename T>   void printv(vector<T> vt) {     for (int i = 0; i < (int)vt.size() - 1; ++i) cout << vt[i] <<    ;     cout << vt[vt.size() - 1] << endl;   }   int d[4][4];   int main(void) {     int n;     cin >> n;     for (int i = 0; i < (int)4; ++i) {       for (int j = 0; j < (int)4; ++j) cin >> d[i][j];     }     int mn = 1000000;     int mnp = -1;     for (int i = 0; i < (int)4; ++i) {       int r = ((d[i][0]) > (d[i][1])) ? (d[i][1]) : (d[i][0]);       int l = ((d[i][2]) > (d[i][3])) ? (d[i][3]) : (d[i][2]);       if (r + l <= n) {         mn = ((d[i][0]) > (d[i][1])) ? (d[i][1]) : (d[i][0]);         mnp = i;       }     }     if (mnp == -1)       cout << -1 << endl;     else       cout << mnp + 1 <<     << mn <<     << n - mn << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 1000005;   long long f[5010][5];   int _prev[5010][5], n;   int a[MAXN];   long long sum[MAXN];   int main() {     scanf( %d , &n);     for (int i = (1); i < (n + 1); i++) scanf( %d , a + i);     for (int i = (1); i < (n + 1); i++) sum[i] = sum[i - 1] + a[i];     for (int i = (1); i < (n + 1); i++)       for (int j = (0); j < (4); j++) {         if (j == 0)           f[i][j] = sum[i];         else {           f[i][j] = 1ll << 63;           for (int k = (0); k < (i + 1); k++) {             if (j & 1 && f[i][j] < f[k][j - 1] - sum[i] + sum[k])               _prev[i][j] = k, f[i][j] = f[k][j - 1] - sum[i] + sum[k];             if (!(j & 1) && f[i][j] < f[k][j - 1] + sum[i] - sum[k])               _prev[i][j] = k, f[i][j] = f[k][j - 1] + sum[i] - sum[k];           }         }       }     long long ans = 1ll << 63, t;     stack<int> res;     for (int k = (0); k < (4); k++)       if (ans <= f[n][k]) ans = f[n][k], t = k;     int now = n;     while (t) {       now = _prev[now][t];       res.push(now);       t--;     }     for (int i = (0); i < (3); i++) {       if (res.empty())         printf( %d  , n);       else         printf( %d  , res.top()), res.pop();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   const long long mod = 1e9 + 7;   long long w[100010], ans = 0;   vector<int> g[100010];   map<long long, int> mp[100010];   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   void dfs(int u, int fa) {     for (int i = 0; i < g[u].size(); ++i) {       int v = g[u][i];       if (v == fa) continue;       for (map<long long, int>::iterator it = mp[u].begin(); it != mp[u].end();            ++it) {         long long d = gcd(it->first, w[v]);         mp[v][d] += it->second;         ans += d % mod * it->second % mod;         ans %= mod;       }       mp[v][w[v]]++;       ans += w[v];       dfs(v, u);     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       scanf( %lld , &w[i]);     }     for (int i = 1; i < n; ++i) {       int a, b;       scanf( %d%d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     mp[1][w[1]]++;     ans += w[1];     ans %= mod;     dfs(1, 0);     printf( %lld n , ans % mod);   }
#include <bits/stdc++.h>   using namespace std;   void swapCols(int p1, int p2, vector<vector<int> >& matrix) {     for (int i = 0; i < ((int)(matrix).size()); i++)       swap(matrix[i][p1], matrix[i][p2]);   }   void swapRows(int p1, int p2, vector<vector<int> >& matrix) {     for (int i = 0; i < ((int)(matrix[0]).size()); i++)       swap(matrix[p1][i], matrix[p2][i]);   }   int main() {     ios ::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<vector<int> > matrix(n, vector<int>(n, 0));     vector<tuple<int, int, int> > operations;     vector<int> cols(n), rows(n);     for (int i = 0; i < (n - 1); i++) {       int u, v;       cin >> u >> v;       u--;       v--;       matrix[u][v] = 1;       rows[u]++;       cols[v]++;     }     int dim = n - 1;     while (dim != 0) {       for (int i = 0; i <= dim; i++) {         if (cols[i] == 0) {           swap(cols[i], cols[dim]);           swapCols(i, dim, matrix);           if (i + 1 != dim + 1)             operations.push_back(make_tuple(2, i + 1, dim + 1));           break;         }       }       for (int i = 0; i <= dim; i++) {         if (rows[i] != 0) {           swap(rows[i], rows[dim]);           swapRows(i, dim, matrix);           if (i + 1 != dim + 1)             operations.push_back(make_tuple(1, i + 1, dim + 1));           break;         }       }       for (int i = 0; i <= dim; i++) {         if (matrix[dim][i] == 1) cols[i]--;         if (matrix[i][dim] == 1) rows[i]--;       }       dim--;     }     cout << ((int)(operations).size()) <<   n ;     for (tuple<int, int, int> tup : operations)       cout << get<0>(tup) <<     << get<1>(tup) <<     << get<2>(tup) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long n, tmp, ans, curr;   string s;   deque<pair<long long, long long> > v;   void add(long long val, long long pos) {     while (v.front().first <= val) {       curr -= v.front().first * (v[1].second - v.front().second);       v.pop_front();     }     v.push_front({val, pos});     curr += v.front().first * (v[1].second - v.front().second);   }   int main() {     cin >> n >> s;     curr = ans = tmp = 0;     v.push_front({1000000, n});     for (int i = s.size() - 1; i >= 0; i--) {       if (s[i] ==  0 ) {         while (tmp >= 0) {           add(tmp, i + tmp);           tmp--;         }         tmp = 0;       } else {         tmp++;         ans += (tmp * (tmp + 1)) / 2ll;         add(tmp, i + tmp);       }       ans += curr;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, s;     cin >> a >> b >> s;     if (a < 0) a *= -1;     if (b < 0) b *= -1;     if (s < (a + b) || (s - a - b) % 2 != 0)       cout <<  No  << endl;     else       cout <<  Yes  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[1 << 14], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 14, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline long long read(long long &x) {     x = 0;     bool f = 1;     char c = gc();     for (; !isdigit(c); c = gc()) {       if (c ==  - ) f ^= 1;       if (c == EOF) return EOF;     }     for (; isdigit(c); c = gc()) x = (x << 1) + (x << 3) + (c ^ 48);     x = f ? x : -x;     return 1;   }   inline void wr(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) wr(x / 10);     putchar(x % 10 | 48);   }   const long long N = 1e5 + 10;   long long n;   long long a[N], ans;   int main() {     read(n);     for (long long i = 1, x; i <= n; ++i) read(a[i]);     sort(a + 1, a + 1 + n);     for (long long i = 2; i <= n; ++i)       if (a[i] - a[i - 1] > 1) ans += a[i] - a[i - 1] - 1;     wr(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-7;   double dp[10050][1005];   int ans[1005];   int main() {     int k, q, p, i, j;     cin >> k >> q;     memset(dp, 0, sizeof dp);     dp[0][0] = 1;     for (i = 1;; ++i) {       for (j = 1; j <= k; ++j) {         dp[i][j] += dp[i - 1][j] * j / k;         dp[i][j] += dp[i - 1][j - 1] * (k - j + 1.0) / k;       }       if (dp[i][k] >= 0.5) break;     }     int cout = 1;     for (i = 1; i <= 1000; ++i) {       while (dp[cout][k] < (i - eps) / 2000) cout++;       ans[i] = cout;     }     while (q--) {       cin >> p;       printf( %d n , ans[p]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2147483647;   const int N = 2005;   int z, n, k, c, i, ind, tab[N];   char t[N];   string s;   vector<pair<int, int> > v;   void sett(int val, int ind) {     if (tab[ind] == val) return;     int i = ind + 1;     while (tab[i] != val) i++;     v.push_back(pair<int, int>(ind, i));     while (ind < i) {       swap(tab[ind], tab[i]);       ind++;       i--;     }   }   int main() {     scanf( %d , &z);     while (z--) {       scanf( %d %d , &n, &k);       scanf( %s , t);       s = t;       for (i = 0; i < n; i++)         if (s[i] ==  ( )           tab[i] = 0;         else           tab[i] = 1;       v.clear();       ind = 0;       for (i = 0; i < k - 1; i++) {         sett(0, ind++);         sett(1, ind++);       }       c = n / 2 - k + 1;       for (i = 0; i < c; i++) sett(0, ind++);       for (i = 0; i < c; i++) sett(1, ind++);       printf( %d n , v.size());       for (auto& w : v) printf( %d %d n , w.first + 1, w.second + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   ifstream f( 1.in );   int n, k, x;   long long a[205], ans;   long long dp[205][205];   int main() {     cin >> n >> k >> x;     for (int i = 1; i <= n; i++) cin >> a[i];     if (k * (x + 1) - 1 < n)       cout <<  -1 ;     else {       for (int i = 1; i <= n; i++) {         for (int j = 0; j < min(x, i); j++) {           if (k * (j + 1) - 1 < i - 1) continue;           for (int l = max(0, i - k); l < i; l++)             dp[i][j + 1] = max(dp[i][j + 1], dp[l][j] + a[i]);         }       }       for (int j = 1; j <= n; j++)         for (int l = n - k + 1; l <= n; l++) ans = max(ans, dp[l][j]);       cout << ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     scanf( %d , &N);     pair<int, int> *P = new pair<int, int>[N];     int *A = new int[N];     for (int i = 0; i < N; i++) {       scanf( %d , &P[i].first);       P[i].second = i;     }     sort(P, P + N);     int p = 0;     for (int i = 0; i < N; i++) {       if (P[i].first < ++p) P[i].first = p;       A[P[i].second] = p = P[i].first;     }     for (int i = 0; i < N; i++) {       if (i != 0) putchar(   );       printf( %d , A[i]);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dcmp(double x, double y) {     return fabs(x - y) <= 1e-9 ? 0 : x < y ? -1 : 1;   };   vector<long long> holder;   void dfs(long long num, int i) {     if (i == 10) {       if (num) holder.push_back(num);       return;     }     dfs(num * 10 + 4, i + 1);     dfs(num * 10 + 7, i + 1);     dfs(num, i + 1);   }   long long solve(long long idx) {     long long ret = 0;     long long hold = 0;     for (int i = 0; i < ((int)((holder).size())); ++i) {       if (idx >= holder[i]) {         ret += (holder[i] * (holder[i] - hold));         hold = holder[i];       } else {         ret += (idx - hold) * holder[i];         break;       }     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long l, r;     cin >> l >> r;     dfs(0, 1);     sort(holder.begin(), holder.end());     holder.push_back(4444444444);     cout << solve(r) - solve(l - 1) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int getsum(long long x) {     int res = 0;     for (int i = 0; i <= m; i++) {       long long num = x + i;       while (num > 0) {         res += num % 10;         num /= 10;         if (res > n) return n + 1;       }     }     return res;   }   int main() {     int q;     scanf( %d , &q);     for (int times = 1; times <= q; times++) {       scanf( %d%d , &n, &m);       long long pow = 100, sum = 0, ans = 1ll << 60;       for (int i = 0; i <= 99; i++)         if (getsum(i) == n) ans = min(ans, 1ll * i);       for (int i = 0; i <= n / 9 - 1; i++) {         for (int j = 1; j <= 9; j++) {           for (int k = 0; k <= 9; k++)             for (int l = 0; l <= 9; l++) {               if (getsum(pow * j + sum + k * 10 + l) == n) {                 ans = min(ans, pow * j + sum + k * 10 + l);               }             }         }         sum += pow * 9;         pow *= 10;         if (getsum(pow + sum) > n) break;       }       if (ans == (1ll << 60))         puts( -1 );       else         printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 301;   int i, j, l, r, k, x, y, z, t, tot;   int f[N][26], sum[N], p[N], q[N];   long long A[N][N], E[N][N], tmp[N][N];   long long n, m, a[N], INF, ans;   char s[N];   void build(int value) {     int x = 0, t;     for (int i = 0; i < strlen(s); i++) {       t = s[i] -  a ;       if (!f[x][t]) f[x][t] = ++tot;       x = f[x][t];     }     sum[x] += value;   }   void init() {     cin >> n >> m;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= n; i++) {       cin >> s;       build(a[i]);     }   }   void Ac() {     int l = 0, r = 0;     for (i = 0; i < 26; i++)       if (f[0][i]) q[++r] = f[0][i];     while (l != r) {       l++;       x = q[l];       for (i = 0; i < 26; i++)         if (f[x][i]) {           q[++r] = f[x][i];           y = p[x];           while (!f[y][i] && y) y = p[y];           if (f[y][i]) y = f[y][i];           p[f[x][i]] = y;           sum[f[x][i]] += sum[y];         }     }   }   void cal(long long c[][N], long long a[][N], long long b[][N]) {     int i, j, k;     for (i = 0; i <= tot; i++)       for (j = 0; j <= tot; j++) tmp[i][j] = INF;     for (i = 0; i <= tot; i++)       for (j = 0; j <= tot; j++)         for (k = 0; k <= tot; k++)           if (a[i][k] + b[k][j] > tmp[i][j]) tmp[i][j] = a[i][k] + b[k][j];     for (i = 0; i <= tot; i++)       for (j = 0; j <= tot; j++) c[i][j] = tmp[i][j];   }   void pr(long long a[][N]) {     for (i = 0; i <= tot; i++) {       for (j = 0; j <= tot; j++)         if (a[i][j] > INF / 2)           cout << a[i][j] <<    ;         else           cout <<  *  ;       printf(  n );     }     printf(  n );   }   void Matrix() {     INF = 1LL << 60;     INF *= -1;     for (i = 0; i <= tot; i++)       for (j = 0; j <= tot; j++) A[i][j] = E[i][j] = INF;     for (i = 0; i <= tot; i++) E[i][i] = 0;     for (i = 0; i <= tot; i++)       for (j = 0; j < 26; j++) {         y = i;         while (y && !f[y][j]) y = p[y];         if (f[y][j]) y = f[y][j];         A[i][y] = sum[y];       }     while (m) {       if (m % 2) cal(E, E, A);       cal(A, A, A);       m /= 2;     }     ans = E[0][0];     for (i = 1; i <= tot; i++) ans = max(ans, E[0][i]);     cout << ans;   }   int main() {     init();     Ac();     Matrix();   }
#include <bits/stdc++.h>   int main() {     int i = 0, j, t, n;     char p[100];     scanf( %s , p);     n = strlen(p);     for (; i < n - 1; i = i + 2) {       for (j = 0; j < n - 1; j = j + 2) {         if (p[j] > p[j + 2]) {           t = p[j];           p[j] = p[j + 2];           p[j + 2] = t;         }       }     }     printf( %s n , p);   }