malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimization( unroll-loops, no-stack-protector )   #pragma GCC target( avx,avx2,fma )   using namespace std;   const int INF = int(1e9) + 99;   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cout.tie(0);     int n;     string s;     cin >> n >> s;     vector<int> max_0(n + 1, 0);     vector<int> max_1(n + 1, 0);     for (int i = n - 1; i >= 0; --i) {       if (s[i] !=  0 ) max_1[i] = 1 + max_1[i + 1];       if (s[i] !=  1 ) max_0[i] = 1 + max_0[i + 1];     }     unordered_map<int, vector<int>> pos_0;     unordered_map<int, vector<int>> pos_1;     int c = 0;     while (c < n) {       if (c == 0 || s[c - 1] ==  1 ) {         for (int len = 1; len <= max_0[c]; ++len) {           pos_0[len].push_back(c);         }         c += max(max_0[c], 1);       } else {         ++c;       }     }     c = 0;     while (c < n) {       if (c == 0 || s[c - 1] ==  0 ) {         for (int len = 1; len <= max_1[c]; ++len) {           pos_1[len].push_back(c);         }         c += max(max_1[c], 1);       } else {         ++c;       }     }     for (int len = 1; len <= n; ++len) {       int pos = 0;       int ans = 0;       int index_0 = 0;       int index_1 = 0;       while (pos < n) {         int npos = INF;         if (max_0[pos] >= len) {           npos = min(npos, pos + len);         }         if (max_1[pos] >= len) {           npos = min(npos, pos + len);         }         while ((index_0 < (int)pos_0[len].size()) && (pos > pos_0[len][index_0]))           ++index_0;         while ((index_1 < (int)pos_1[len].size()) && (pos > pos_1[len][index_1]))           ++index_1;         if (index_0 < (int)pos_0[len].size()) {           npos = min(npos, pos_0[len][index_0] + len);         }         if (index_1 < (int)pos_1[len].size()) {           npos = min(npos, pos_1[len][index_1] + len);         }         if (npos != INF) {           ++ans;         }         pos = npos;       }       cout << ans <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   int main() {     int x, y, z, i, j, k, a, b, c, n, m, t, mat[210210];     scanf( %d , &t);     long long w, sum;     while (t--) {       scanf( %d %lld , &n, &w);       j = -1;       sum = 0;       c = 0;       for (x = 0; x < n; x++) {         scanf( %d , &mat[x]);         if (mat[x] >= (w + 1) / 2 && mat[x] <= w) j = x;         if (mat[x] <= w) sum += mat[x];       }       if (j != -1)         printf( 1 n%d n , j + 1);       else if (sum < (w + 1) / 2)         puts( -1 );       else {         x = -1;         if (sum > w) {           for (x = 0; x < n; x++) {             if (mat[x] > w) continue;             sum -= mat[x];             if (sum >= (w + 1) / 2 && sum <= w) break;           }         }         for (y = x + 1; y < n; y++)           if (mat[y] <= w) c++;         printf( %d n , c);         for (y = x + 1; y < n; y++)           if (mat[y] <= w) printf( %d  , y + 1);         puts(  );       }     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int num;     std::cin >> num;     int arr1[num], arr2[num], sum1 = 0, sum2 = 0;     for (int i = 0; i < num; i++) {       std::cin >> arr1[i];       sum1 |= arr1[i];     }     for (int i = 0; i < num; i++) {       std::cin >> arr2[i];       sum2 |= arr2[i];     }     std::cout << sum1 + sum2 << std::endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 37;   const long long INF = 1LL << 61;   int n, u, r;   long long sum;   int a[MAX_N], b[MAX_N], k[MAX_N], p[MAX_N];   void dfs(int dep, bool f) {     if ((u - dep) % 2 == 0) {       long long s = 0;       for (int i = 1; i <= n; ++i) {         s += (long long)a[i] * k[i];       }       sum = max(sum, s);     }     if (dep == u) return;     int t[MAX_N] = {0};     for (int i = 1; i <= n; ++i) {       t[i] = a[i];     }     if (!f) {       for (int i = 1; i <= n; ++i) {         a[i] = t[i] ^ b[i];       }       dfs(dep + 1, true);     }     for (int i = 1; i <= n; ++i) {       a[i] = t[p[i]] + r;     }     dfs(dep + 1, false);     for (int i = 1; i <= n; ++i) {       a[i] = t[i];     }   }   int main() {     scanf( %d%d%d , &n, &u, &r);     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);     }     for (int i = 1; i <= n; ++i) {       scanf( %d , b + i);     }     for (int i = 1; i <= n; ++i) {       scanf( %d , k + i);     }     for (int i = 1; i <= n; ++i) {       scanf( %d , p + i);     }     sum = -INF;     dfs(0, 0);     printf( %I64d n , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, A[100005], B[100005], C[100005], sum, val;   pair<long long, long long> E[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> A[i];       C[A[i]]++;     }     for (int i = 1; i <= k; i++) {       if (C[i] == 0) val++;     }     for (int i = 1; i <= n; i++) {       cin >> B[i];       E[i].first = B[i];       E[i].second = A[i];     }     sort(E + 1, E + n + 1);     k = 1;     for (int i = 1; k <= val; i++) {       if (C[E[i].second] > 1) {         sum += E[i].first;         C[E[i].second]--;         k++;       }     }     cout << sum <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long T, n, s, sum;   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int main() {     cin >> T;     while (T--) {       cin >> n;       sum = 0;       long long a[100010] = {0};       for (int i = 1; i <= n; i++) {         cin >> s;         a[i] += s;         if (a[i] > 0) a[i + 1] += a[i];         if (a[i] < 0) sum -= a[i];       }       cout << sum << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int dp[1000005];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int a[n + 1];     for (int i = 0; i < n; i++) cin >> a[i];     dp[0] = 1;     for (int i = 0; i < n; i++) {       set<int> s;       for (int j = 1; j * j <= a[i]; j++) {         if (a[i] % j == 0) {           s.insert(j);           s.insert(a[i] / j);         }       }       for (set<int>::reverse_iterator it = s.rbegin(); it != s.rend(); it++) {         dp[*it] = (dp[*it] + dp[*it - 1]) % 1000000007;       }     }     long long int ans = 0;     for (int i = 1; i <= n; i++) {       ans = (ans + dp[i]) % 1000000007;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   long long p = 1e9 + 7, x;   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> x;     while (cin >> x)       cout << ((((x + 4) / 4) % p) * (((x + 6) / 4) % p)) % p <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long int maxn = 200005, mod = pow(10, 9) + 7;   void fast() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   void create_array(vector<long long int>& a) {     for (long long int i = 1;; i++) {       if (i % 3 != 0 and i % 10 != 3) {         a.push_back(i);       }       if (a.size() == 1000) break;     }   }   void solve(vector<long long int>& a) {     long long int k;     cin >> k;     cout << a[k - 1] << endl;   }   int main() {     fast();     long long int t = 1;     vector<long long int> a;     create_array(a);     cin >> t;     while (t--) {       solve(a);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long md = 1000000007;   int main() {     long long n, s, a, t1, t2;     cin >> n;     s = n * 2;     vector<long long> v(s);     for (int i = 0; i < s; i++) {       cin >> a;       v[i] = a;     }     sort(v.begin(), v.end(), greater<long long>());     t1 = 0;     t2 = 0;     for (int i = 0; i < n; i++) {       t1 += v[i];     }     for (int i = v.size() - 1; i >= n; i--) {       t2 += v[i];     }     if (t1 == t2) {       cout << -1 <<   n ;     } else {       for (int i = 0; i < v.size(); i++) {         cout << v[i] <<    ;       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   void segmentedSieve(long long L, long long R) {     long long lim = sqrt(R);     vector<bool> mark(lim + 1, false);     vector<long long> primes;     for (long long i = 2; i <= lim; ++i) {       if (!mark[i]) {         primes.emplace_back(i);         for (long long j = i * i; j <= lim; j += i) mark[j] = true;       }     }     int buenos = 0;     long long len = ceil(sqrt(R - L + 1));     for (long long bloques = 0; bloques < len; ++bloques) {       long long l = L + len * bloques + 1;       if (bloques == 0) l = L;       long long r = min(R, L + len * (bloques + 1));       if (l > r) break;       vector<bool> isPrime(r - l + 1, true);       for (long long i : primes)         for (long long j = max(i * i, (l + i - 1) / i * i); j <= r; j += i)           isPrime[j - l] = false;       if (l == 1) isPrime[0] = false;       for (long long i = l; i <= r; ++i) {         if (i == 2 || (isPrime[i - l] && i % 4 == 1)) {           buenos++;         }       }     }     cout << buenos <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << setprecision(20) << fixed;     long long l, r;     cin >> l >> r;     segmentedSieve(l, r);   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     int n, k, i, o;     cin >> n >> k;     o = n - k;     for (i = 1; i <= o - 1; i++) cout << i <<    ;     for (i = n; i >= o; i--) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T By(T x, T y, T P) {     T F1 = 0;     while (y) {       if (y & 1) {         F1 += x;         if (F1 < 0 || F1 >= P) F1 -= P;       }       x <<= 1;       if (x < 0 || x >= P) x -= P;       y >>= 1;     }     return F1;   }   template <class T>   T Mul(T x, T y, T P) {     T F1 = 1;     x %= P;     while (y) {       if (y & 1) {         F1 = By(F1, x, P);       }       x = By(x, x, P);       y >>= 1;     }     return F1;   }   template <class T>   T Gcd(T x, T y) {     if (y == 0) return x;     T z;     while (z = x % y) {       x = y, y = z;     }     return y;   }   struct EDGE {     int T;     EDGE *Nxt;   };   template <class T>   void UpdataMin(T &x, T y) {     if (y < x) {       x = y;     }   }   template <class T>   void UpdataMax(T &x, T y) {     if (x < y) {       x = y;     }   }   int Dp[61][61][61];   int Map[61][61][61];   int NM[61][61];   int N, M, R, I, J, K;   int main() {     memset(Dp, 63, sizeof(Dp));     memset(NM, 63, sizeof(NM));     scanf( %d%d%d , &N, &M, &R);     for (int i = 0; i < (M); ++i) {       for (int j = 1; j <= (N); ++j)         for (int k = 1; k <= (N); ++k) scanf( %d , &Map[i][j][k]);       for (int l = 1; l <= (N); ++l)         for (int j = 1; j <= (N); ++j)           for (int k = 1; k <= (N); ++k)             if (Map[i][j][l] + Map[i][l][k] < Map[i][j][k])               Map[i][j][k] = Map[i][j][l] + Map[i][l][k];       for (int j = 1; j <= (N); ++j)         for (int k = 1; k <= (N); ++k) UpdataMin(NM[j][k], Map[i][j][k]);     }     for (int i = 1; i <= (N); ++i)       for (int j = 1; j <= (N); ++j) Dp[0][i][j] = NM[i][j];     for (int i = 1; i <= (60); ++i)       for (int j = 1; j <= (N); ++j)         for (int k = 1; k <= (N); ++k)           for (int l = 1; l <= (N); ++l)             UpdataMin(Dp[i][j][l], Dp[i - 1][j][k] + NM[k][l]);     while (R--) {       scanf( %d%d%d , &I, &J, &K);       if (K > 60) K = 60;       printf( %d n , Dp[K][I][J]);     }     scanf( %d , &N);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int maxn = 2e5 + 10;   const int inf = 0x3f3f3f3f;   const double eps = 1e-6;   int n, a[maxn];   int num[maxn];   int pre[maxn];   int lst[maxn];   int up = 500;   int mx = 0;   int c0[maxn], c[maxn];   void add(int x) {     c0[c[x]]--;     c[x]++;     c0[c[x]]++;     mx = max(mx, c[x]);   }   void sub(int x) {     c0[c[x]]--;     c[x]--;     c0[c[x]]++;     mx -= (c0[mx] == 0);   }   int solve1(int D) {     int res = 0;     for (int i = 1; i <= up; i++) {       memset(c, 0, sizeof(c)), memset(c0, 0, sizeof(c0));       mx = 0;       int k = 1, x = 0;       for (int j = 1; j <= n; j++) {         while (k <= n && x + (a[k] == D) <= i) add(a[k]), x += (a[k] == D), k++;         if (c0[mx] >= 2) res = max(res, k - j);         sub(a[j]), x -= (a[j] == D);       }     }     return res;   }   int solve2(int D, int V) {     int res = 0;     memset(pre, 0, sizeof(pre));     memset(lst, -1, sizeof(lst));     for (int i = 1; i <= n; i++) {       if (a[i] == D)         pre[i] = pre[i - 1] + 1;       else if (a[i] == V)         pre[i] = pre[i - 1] - 1;       else         pre[i] = pre[i - 1];     }     for (int i = n; i >= 1; i--) lst[pre[i]] = i;     lst[0] = 0;     for (int i = 1; i <= n; i++) res = max(res, i - lst[pre[i]]);     return res;   }   int main() {     std::ios::sync_with_stdio(false), cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i], num[a[i]]++;     int mx = 0, mx_id = 0, cnt = 0;     for (int i = 1; i <= n; i++) {       if (num[i] > mx)         mx = num[i], mx_id = i, cnt = 1;       else if (num[i] == mx)         cnt++;     }     if (cnt > 1) {       cout << n <<   n ;       return 0;     }     int D = mx_id;     int ans = 0;     ans = max(ans, solve1(D));     for (int V = 1; V <= n; V++) {       if (V == D) continue;       if (num[V] > up) ans = max(ans, solve2(D, V));     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   long long a, b, c, d, e, f, k;   bool check(long long x, long long y) {     if (k == 0) {       return x == c && y == d;     }     return ((c - x) * e + (d - y) * f) % k == 0 &&            (e * (d - y) + f * (x - c)) % k == 0;   }   int main() {     while (cin >> a >> b >> c >> d >> e >> f) {       k = e * e + f * f;       if (check(a, b) || check(-a, -b) || check(b, -a) || check(-b, a)) {         cout <<  YES  << endl;       } else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   const long double E = 1e-7;   unsigned char ccc;   bool _minus = false;   template <typename T>   inline T sqr(T t) {     return (t * t);   }   inline void read(long long &n) {     n = 0;     _minus = false;     while (true) {       ccc = getchar();       if (ccc ==     || ccc ==   n ) break;       if (ccc ==  - ) {         _minus = true;         continue;       }       n = n * 10 + ccc -  0 ;     }     if (_minus) n *= -1;   }   inline void read(int &n) {     n = 0;     _minus = false;     while (true) {       ccc = getchar();       if (ccc ==     || ccc ==   n ) break;       if (ccc ==  - ) {         _minus = true;         continue;       }       n = n * 10 + ccc -  0 ;     }     if (_minus) n *= -1;   }   char wwww[19];   int kkkk;   inline void write(long long y) {     long long x = y;     kkkk = 0;     if (!x)       ++kkkk, wwww[kkkk] =  0 ;     else       while (x) {         ++kkkk;         wwww[kkkk] = char(x % 10 +  0 );         x /= 10;       }     for (int i = kkkk; i >= 1; --i) putchar(wwww[i]);     putchar(   );   }   long long d, k, a, b, t;   long long get(long long x) {     long long ans = max(0LL, x - 1) * t + x * k * a + (d - x * k) * b;     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     srand(time(NULL));     cout.precision(10);     cout << fixed;     cin >> d >> k >> a >> b >> t;     long long ans = ((d - 1) / k) * t + d * a;     long long l = 0, r = d / k;     while (l + 10 < r) {       long long l1 = (l + l + r) / 3, r1 = (l + r + r) / 3;       if (get(l1) < get(r1)) {         r = r1;       } else {         l = l1;       }     }     for (long long i = l; i <= r; i++) ans = min(ans, get(i));     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int r, c;     cin >> r >> c;     char mat[r + 5][c + 5];     for (int i = 1; i <= r; i++) {       for (int j = 1; j <= c; j++) {         cin >> mat[i][j];       }     }     for (int i = 1; i <= r; i++) {       for (int j = 1; j <= c; j++) {         if (mat[i][j] ==  B ) {           int rw = 0, cl = 0;           for (int k = j; k <= c; k++) {             if (mat[i][k] ==  B )               cl++;             else               break;           }           for (int k = i; k <= r; k++) {             if (mat[k][j] ==  B )               rw++;             else               break;           }           cout << i + rw / 2 <<     << j + cl / 2 << endl;           return 0;         }       }     }     return 0;   }
#include <bits/stdc++.h>   int t[100003] = {0};   int main() {     int L, b, f, n;     scanf( %d%d%d%d , &L, &b, &f, &n);     t[L] = 1000;     for (int i = 1; i <= n; i++) {       int req, len;       scanf( %d%d , &req, &len);       if (req == 1) {         bool e = 0;         for (int a = 0; a < L; a++) {           if (t[a]) continue;           int prev = a;           for (int c = a + 1; c <= L; c++) {             a = c;             if (t[c]) {               if (prev == 0 && c == L && L - prev >= len) {                 for (int j = 0; j < len; j++) t[j] = i;                 printf( 0 n );                 e = 1;               } else if (prev == 0 && c >= len + f) {                 for (int j = 0; j < len; j++) t[j] = i;                 printf( 0 n );                 e = 1;               } else if (c == L && L - prev >= len + b ||                          c - prev >= len + b + f) {                 for (int j = prev + b; j < prev + b + len; j++) t[j] = i;                 printf( %d n , prev + b);                 e = 1;               }               break;             }           }           if (e) break;         }         if (!e) printf( -1 n );       } else {         for (int j = 0; j < L; j++)           if (t[j] == len) t[j] = 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 200009;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       long long a[n + 5];       long long na[n + 5];       for (long long i = 1; i <= n; i++) {         cin >> a[i];         na[i] = a[i];       }       sort(na + 1, na + n + 1);       long long p[m + 5];       unordered_map<long long, long long> mp;       for (long long i = 1; i <= m; i++) {         cin >> p[i];         mp[p[i]] = 1;       }       for (long long i = 1; i <= n; i++) {         for (long long i = 1; i < n; i++) {           if (mp[i] == 1 && a[i] > a[i + 1]) {             swap(a[i], a[i + 1]);           }         }       }       long long f = 1;       for (long long i = 1; i <= n; i++) {         if (a[i] != na[i]) {           f = 0;           cout <<  NO                 <<   n ;           break;         }       }       if (f == 1) {         cout <<  YES               <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   int main() {     char g[100];     scanf( %s , g);     for (int w = 0; g[w] !=   0 ; w++) {       if (g[w] >= 65 && g[w] <= 90) g[w] = g[w] + 32;     }     for (int w = 0; g[w] !=   0 ; w++) {       if (!(g[w] ==  a  || g[w] ==  e  || g[w] ==  i  || g[w] ==  o  ||             g[w] ==  u  || g[w] ==  y ))         printf( .%c , g[w]);     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   const int mod = 1e9 + 7;   int arr[500];   int main() {     int k, n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int a;       scanf( %d , &a);       if (a % 2) {         cout <<  First  << endl;         return 0;       }     }     cout <<  Second  << endl;   }
#include <bits/stdc++.h>   using namespace std;   bool vis[30010][210][2][2][2];   int pd[30010][210][2][2][2];   int v[30010];   int n, K;   int solve(int ind, int cut, int s1, int s2, int tem) {     if (cut == K) return 0LL;     if (ind == n) return -0x3f3f3f3f;     int &ans = pd[ind][cut][s1][s2][tem];     if (vis[ind][cut][s1][s2][tem]) return ans;     int p1, p2;     if (s1)       p1 = 1;     else       p1 = -1;     if (s2)       p2 = 1;     else       p2 = -1;     if (cut == 0) p1 = 0LL;     if (cut == K - 1) p2 = 0LL;     vis[ind][cut][s1][s2][tem] = true;     ans = -0x3f3f3f3f;     int x = v[ind] * (p1 + p2);     if (tem) {       ans = max(x + solve(ind + 1, cut + 1, s2 ^ 1, 0, 0),                 x + solve(ind + 1, cut + 1, s2 ^ 1, 1, 0));       ans = max(ans, x + solve(ind + 1, cut, s1, s2, tem));     } else {       ans = max(ans, solve(ind + 1, cut, s1, s2, 0));       ans = max(ans, x + solve(ind + 1, cut, s1, s2, 1));       ans = max(ans, x + solve(ind + 1, cut + 1, s2 ^ 1, 0, 0));       ans = max(ans, x + solve(ind + 1, cut + 1, s2 ^ 1, 1, 0));     }     return ans;   }   int main() {     scanf(  %d %d , &n, &K);     for (int i = 0; i < (n); ++i) scanf(  %d , &v[i]);     int ans = max(solve(0, 0, 0, 0, 0), solve(0, 0, 0, 1, 0));     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = (1 << 19);   string str;   vector<pair<int, char> > sorted;   int cnt[MX], done[MX], K;   int main() {     cin >> str >> K;     for (int j = 0; j < str.size(); j++) cnt[str[j] -  a ]++;     for (int j = 0; j < 26; j++) {       sorted.push_back(make_pair(cnt[j], j +  a ));     }     sort(sorted.begin(), sorted.end());     int ans = 26;     for (auto pp : sorted) {       if (pp.first > K) break;       K -= pp.first;       done[pp.second] = 1;       --ans;     }     cout << ans << endl;     for (auto ch : str)       if (!done[ch]) cout << ch;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   bool isSubSequence(string str1, string str2, int m, int n) {     if (m == 0) return true;     if (n == 0) return false;     if (str1[m - 1] == str2[n - 1])       return isSubSequence(str1, str2, m - 1, n - 1);     return isSubSequence(str1, str2, m, n - 1);   }   int main() {     string s, t;     cin >> s >> t;     int i, j;     int arr1[26] = {0}, arr2[26] = {};     int m = s.length();     int n = t.length();     if (isSubSequence(t, s, n, m) == true) {       cout <<  automaton  << endl;       return 0;     }     for (i = 0; i < s.length(); i++) {       arr1[int(s[i]) - 97]++;     }     for (i = 0; i < t.length(); i++) {       arr2[int(t[i]) - 97]++;     }     int flag = 0;     if (s.length() == t.length()) {       for (i = 0; i < 26; i++) {         if (arr1[i] != arr2[i]) {           flag = 1;           break;         }       }       if (flag == 0) {         cout <<  array  << endl;         return 0;       } else {         cout <<  need tree  << endl;         return 0;       }     }     for (i = 0; i < 26; i++) {       if (arr1[i] < arr2[i]) {         cout <<  need tree  << endl;         return 0;       }     }     cout <<  both  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string s[n];     for (int i = 0; i < n; i++) cin >> s[i];     long long a[m];     for (int i = 0; i < m; i++) cin >> a[i];     long long ans = 0;     for (int i = 0; i < m; i++) {       long long maxi = 0;       for (char c =  A ; c <=  E ; c++) {         long long temp = 0;         for (int j = 0; j < n; j++) {           if (s[j][i] == c) temp += a[i];         }         maxi = max(temp, maxi);       }       ans += maxi;     }     cout << ans << endl;     return 0;   }