malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 500031;   int tests, n, k;   vector<pair<int, int> > g[N];   int used[N];   long long dp[N][2];   void dfs(int v) {     used[v] = 1;     long long guaranteed = 0;     vector<long long> benefits;     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i].first;       int cost = g[v][i].second;       if (used[to] == 1) continue;       dfs(to);       long long without_edge = max(dp[to][0], dp[to][1]);       long long with_edge = dp[to][0] + cost;       guaranteed += without_edge;       long long benefit_here = with_edge - without_edge;       if (benefit_here < 0) benefit_here = 0;       benefits.push_back(benefit_here);     }     sort(benefits.begin(), benefits.end());     reverse(benefits.begin(), benefits.end());     long long S = 0;     for (int i = 0; i < k - 1 && i < benefits.size(); i++) {       S += benefits[i];     }     dp[v][0] = guaranteed + S;     S = 0;     for (int i = 0; i < k && i < benefits.size(); i++) {       S += benefits[i];     }     dp[v][1] = guaranteed + S;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> tests;     for (; tests; --tests) {       cin >> n >> k;       for (int i = 1; i <= n; i++) {         g[i].clear();         used[i] = 0;       }       for (int i = 1; i < n; i++) {         int a, b, c;         cin >> a >> b >> c;         g[a].push_back(make_pair(b, c));         g[b].push_back(make_pair(a, c));       }       dfs(1);       cout << max(dp[1][0], dp[1][1]) << endl;     }     return 0;   }
#include <bits/stdc++.h>   int map[525][525];   int note[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};   int main() {     int time = 0, size = 1, i, j, head, tail;     map[1][1] = 1;     while (time != 9) {       time++;       head = size + 1;       tail = 2 * size;       for (i = 1; i <= size; i++)         for (j = head; j <= tail; j++) map[i][j] = map[i][j - size];       for (i = head; i <= tail; i++)         for (j = 1; j <= size; j++) map[i][j] = map[i - size][j];       for (i = head; i <= tail; i++)         for (j = head; j <= tail; j++) map[i][j] = -map[i - size][j - size];       size *= 2;     }     int k;     scanf( %d , &k);     for (i = 1; i <= note[k]; i++) {       for (j = 1; j <= note[k]; j++)         if (map[i][j] == 1)           printf( + );         else           printf( * );       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int tichnas;     cin >> tichnas;     while (tichnas--) {       long long n, c, m, maxs = 1e9, temp, ans;       map<long long, long long> type;       bool possible;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> c;         type[c]++;       }       for (auto it = type.begin(); it != type.end(); it++)         maxs = min(maxs, it->second + 1);       ans = n;       for (int i = 2; i <= maxs; i++) {         possible = true;         m = 0;         for (auto it = type.begin(); it != type.end() && possible; it++) {           temp = it->second;           if (temp % i == 0)             m += temp / i;           else if (i - 1 - temp % i <= temp / i)             m += temp / i + 1;           else             possible = false;         }         if (possible) ans = m;       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int pgcd(int a, int b) {     if (a == 0) return b;     return pgcd(b % a, a);   }   int nbNombres;   int vals[300 * 1000];   int minRange[20][300 * 1000];   int pgcdRange[20][300 * 1000];   vector<int> possibles(int taille) {     vector<int> sol;     int etage = __builtin_log2(taille);     int pseudo = (1 << etage);     for (int iDebut = 0; iDebut + taille <= nbNombres; iDebut++) {       int mini =           min(minRange[etage][iDebut], minRange[etage][iDebut + taille - pseudo]);       int pg = pgcd(pgcdRange[etage][iDebut],                     pgcdRange[etage][iDebut + taille - pseudo]);       if (mini == pg) sol.push_back(iDebut);     }     return sol;   }   int main() {     cin >> nbNombres;     for (int iNombre = 0; iNombre < nbNombres; iNombre++) {       cin >> vals[iNombre];       minRange[0][iNombre] = vals[iNombre];       pgcdRange[0][iNombre] = vals[iNombre];     }     for (int iPuis = 1; iPuis < 20; iPuis++) {       int curPuis = (1 << iPuis), derPuis = (1 << (iPuis - 1));       for (int iPos = 0; iPos + curPuis <= nbNombres; iPos++) {         minRange[iPuis][iPos] =             min(minRange[iPuis - 1][iPos], minRange[iPuis - 1][iPos + derPuis]);         pgcdRange[iPuis][iPos] = pgcd(pgcdRange[iPuis - 1][iPos],                                       pgcdRange[iPuis - 1][iPos + derPuis]);       }     }     int debut = 0, fin = nbNombres + 1;     while (debut + 1 < fin) {       int mil = (debut + fin) / 2;       if (!possibles(mil).empty()) {         debut = mil;       } else {         fin = mil;       }     }     vector<int> sol = possibles(debut);     cout << sol.size() <<     << debut - 1 << endl;     for (int val : sol) {       cout << val + 1 <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, s, e;   int x[5013];   int a[5013], b[5013], c[5013], d[5013];   long long dp[5013][5013];   int main() {     scanf( %d%d%d , &n, &s, &e);     for (int i = 1; i <= n; i++) scanf( %d , &x[i]);     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 , &c[i]);     for (int i = 1; i <= n; i++) scanf( %d , &d[i]);     memset(dp, 0x7F, sizeof dp);     dp[0][0] = 0;     for (int i = 1; i <= n; i++) {       int diff = 0;       if (s < i && e >= i) diff = 1;       if (e < i && s >= i) diff = -1;       for (int j = 0; j <= n; j++) {         int k = j - diff;         if (k < 0) continue;         if (i == s) {           if (k) dp[i][j] = min(dp[i][j], dp[i - 1][j] + c[i] + x[i]);           dp[i][j + 1] = min(dp[i][j + 1], dp[i - 1][j] + d[i] - x[i]);         } else if (i == e) {           if (j) dp[i][j - 1] = min(dp[i][j - 1], dp[i - 1][j] + a[i] + x[i]);           dp[i][j] = min(dp[i][j], dp[i - 1][j] + b[i] - x[i]);         } else {           if (j && k)             dp[i][j - 1] =                 min(dp[i][j - 1], dp[i - 1][j] + c[i] + a[i] + 2 * x[i]);           if (k) dp[i][j] = min(dp[i][j], dp[i - 1][j] + c[i] + b[i]);           if (j) dp[i][j] = min(dp[i][j], dp[i - 1][j] + d[i] + a[i]);           dp[i][j + 1] = min(dp[i][j + 1], dp[i - 1][j] + d[i] + b[i] - 2 * x[i]);         }       }       if (i == n) continue;       diff = 0;       if (s <= i && e > i) diff = 1;       if (e <= i && s > i) diff = -1;       for (int j = 0; j <= n; j++) {         int k = j - diff;         if (j <= 0 && k <= 0) dp[i][j] = 1e18;       }     }     printf( %lld n , dp[n][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e, f, g = 0, h = 0, i = 0, j, k, l, p = 0;     cin >> a >> b >> c >> d >> e >> f;     g = a - d;     h = b - e;     i = c - f;     if (g > 0) {       j = g / 2;     } else {       j = 0;     }     if (h > 0) {       k = h / 2;     } else {       k = 0;     }     if (i > 0) {       l = i / 2;     } else {       l = 0;     }     if (g >= 0) {       p = p + j;     } else {       p = p + g;     };     if (h >= 0) {       p = p + k;     } else {       p = p + h;     }     if (i >= 0) {       p = p + l;     } else {       p = p + i;     }     if (p >= 0) {       cout <<  Yes ;     } else {       cout <<  No ;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, i, sum = 0;     scanf( %d , &n);     if (n == 1) sum = 1;     if (n == 2) sum = 5;     if (n == 3) sum = 13;     if (n >= 4) {       for (i = 4; i <= n; i++) {         sum = sum + i * i - (i - 2) * (i - 2);       }       sum = sum + 13;     }     printf( %d , sum);   }
#include <bits/stdc++.h>      typedef long long int ll;   typedef long double ld;   typedef unsigned long long ull;      #define RESET(a, b) memset(a, b, sizeof(a))   int INF = 1000000005;   long long INFF = 1000000000000000005LL;      using namespace std;         struct monster {       ll health, attack_power;   };      int main() {                ll t;       cin>>t;       while(t--)       {           ll a,b;           cin>>a>>b;           ll ans=INFF;           if(a==1)           {               if(b!=1)               {                   cout<<1<<endl;               }               else               {                   cout<< 2 n ;               }               continue;           }           if(b>a)           {               cout<< 1 n ;               continue;           }                    for(int i=0;i<=100000;i++)           {               ll x=b+i;               ll y=a;               ll cnt=i;               bool ok=0;               while(y and x!=1)               {                   ok=1;                   y=y/x;                   cnt++;               }                  //cout<<x<<endl;               if(ok)ans=min(ans,cnt);           }           cout<<ans<<endl;             }                //ctime;       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int upd[400000][10];   long long val[400000][10];   bool dirty[400000];   void clean(int n, int l, int r) {     long long buf[10];     memset(buf, 0, sizeof buf);     for (int i = 0; i < 10; i++) {       buf[upd[n][i]] += val[n][i];     }     dirty[n] = false;     for (int i = 0; i < 10; i++) {       val[n][i] = buf[i];     }     if (l < r) {       dirty[n * 2] = dirty[n * 2 + 1] = true;       for (int i = 0; i < 10; i++) {         upd[n * 2][i] = upd[n][upd[n * 2][i]];         upd[n * 2 + 1][i] = upd[n][upd[n * 2 + 1][i]];       }     }     for (int i = 0; i < 10; i++) {       upd[n][i] = i;     }   }   long long get(int rl, int rr, int n = 1, int l = 0, int r = 100000) {     if (l > rr || r < rl) return 0;     if (dirty[n]) clean(n, l, r);     if (l >= rl && r <= rr) {       long long ans = 0;       for (int i = 0; i < 10; i++) {         ans += val[n][i] * i;       }       return ans;     }     long long ans = get(rl, rr, n * 2, l, (l + r) / 2);     ans += get(rl, rr, n * 2 + 1, (l + r) / 2 + 1, r);     return ans;   }   void update(int rl, int rr, int from, int to, int n = 1, int l = 0,               int r = 100000) {     if (l > rr || r < rl) {       clean(n, l, r);       return;     }     if (dirty[n]) clean(n, l, r);     if (l >= rl && r <= rr) {       for (int i = 0; i < 10; i++) {         if (upd[n][i] == from) upd[n][i] = to;       }       dirty[n] = true;       clean(n, l, r);       return;     }     update(rl, rr, from, to, n * 2, l, (l + r) / 2);     update(rl, rr, from, to, n * 2 + 1, (l + r) / 2 + 1, r);     for (int i = 0; i < 10; i++) {       val[n][i] = val[n * 2][i] + val[n * 2 + 1][i];     }   }   int n, q;   int arr[100000];   void build(int n = 1, int l = 0, int r = 100000) {     for (int i = 0; i < 10; i++) upd[n][i] = i;     if (l == r) {       if (l < n) {         int mul = 1;         int c = arr[l];         while (c) {           val[n][c % 10] += mul;           c /= 10;           mul *= 10;         }       }       return;     }     build(n * 2, l, (l + r) / 2);     build(n * 2 + 1, (l + r) / 2 + 1, r);     for (int i = 0; i < 10; i++) {       val[n][i] = val[n * 2][i] + val[n * 2 + 1][i];     }   }   void printtree() {     for (int i = 0; i < n; i++) {       cout << get(i, i) <<    ;     }     cout << endl;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> q;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     build();     for (int i = 0; i < q; i++) {       int t, l, r, x, y;       cin >> t;       if (t == 1) {         cin >> l >> r >> x >> y;         update(l - 1, r - 1, x, y);       } else {         cin >> l >> r;         cout << get(l - 1, r - 1) << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     string ans;     string t;     for (int i = 0; i < n; i++) {       cin >> t;       if (i == 0) {         ans = t;         continue;       }       for (int j = 0; j < t.size(); j++)         if (ans[j] ==  ? )           ans[j] = t[j];         else if (ans[j] == t[j] || t[j] ==  ? )           ans[j] = ans[j];         else           ans[j] =  . ;     }     for (int i = 0; i < ans.size(); i++)       if (ans[i] ==  . )         ans[i] =  ? ;       else if (ans[i] ==  ? )         ans[i] =  a ;     ios_base::sync_with_stdio(false);     printf( %s , ans.c_str());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dr[] = {-1, 0, 1, 0, -1, -1, 1, 1};   const int dc[] = {0, -1, 0, 1, -1, 1, -1, 1};   const int N = 212345;   int n, m, q, p[N], a[N];   int f[N], g[N], last[N];   vector<int> loc[N];   int maxm[N];   int my_find(int id, int val) {     int l = 0, r = loc[id].size();     while (l < r) {       int mid = l + (r - l) / 2;       int x = loc[id][mid];       if (f[x] > val)         r = mid;       else         l = mid + 1;     }     if (l == loc[id].size())       return m + 1;     else       return loc[id][l];   }   int tmin[N * 4];   void build(int o, int l, int r) {     if (l == r)       tmin[o] = maxm[l];     else {       int mid = l + (r - l) / 2;       build(o * 2, l, mid);       build(o * 2 + 1, mid + 1, r);       tmin[o] = min(tmin[o * 2], tmin[o * 2 + 1]);     }   }   const int INF = int(1e9);   int query(int o, int l, int r, int ql, int qr) {     if (ql <= l && r <= qr) {       return tmin[o];     } else {       int mid = l + (r - l) / 2;       int lmax = INF, rmax = INF;       if (ql <= mid) lmax = query(o * 2, l, mid, ql, qr);       if (qr > mid) rmax = query(o * 2 + 1, mid + 1, r, ql, qr);       return min(lmax, rmax);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       p[x] = i;     }     for (int i = 1; i <= m; i++) {       cin >> a[i];       a[i] = p[a[i]];       loc[a[i]].push_back(i);     }     for (int i = 1; i <= n; i++) sort((loc[i]).begin(), (loc[i]).end());     for (int i = 1; i <= m; i++) {       last[a[i]] = i;       if (a[i] == 1)         f[i] = i;       else         f[i] = f[last[a[i] - 1]];     }     for (int i = 1; i <= n; i++) last[i] = m + 1;     g[m + 1] = m + 1;     for (int i = m; i >= 1; i--) {       last[a[i]] = i;       if (a[i] == n)         g[i] = i;       else         g[i] = g[last[a[i] + 1]];     }     for (int i = 1; i <= m; i++) {       if (a[i] == 1)         maxm[i] = g[i];       else         maxm[i] = my_find(a[i] - 1, g[i]);     }     build(1, 1, m);     string ans;     while (q--) {       int l, r;       cin >> l >> r;       if (query(1, 1, m, l, r) <= r)         ans.push_back( 1 );       else         ans.push_back( 0 );     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2050;   int p[N], id[N], rmd[N], P[N], n;   int qry(vector<int> vec) {     cout <<  ?   << vec.size() <<    ;     for (auto t : vec) cout << t <<    ;     cout << endl, fflush(stdout);     int ok;     cin >> ok;     return ok;   }   int query(int x) {     vector<int> vec;     for (int i = 1; i <= n; ++i)       if (!p[i] && x != i) vec.push_back(i);     return qry(vec);   }   void query(int x, int y, int xx, int yy) {     for (int i = 1; i <= n; ++i)       if (!id[x] && !p[i] && rmd[i] == y) {         if (query(i)) id[x] = i;       } else if (!id[xx] && !p[i] && rmd[i] == yy)         if (query(i)) id[xx] = i;     p[id[x]] = x, p[id[xx]] = xx;   }   int main() {     cin >> n;     query(1, 0, n, 0);     for (int t = 2, l = 2, r = n - 1; l <= r; t <<= 1) {       for (int i = 1; i <= n; ++i)         if (!p[i]) {           vector<int> vec;           for (int j = 1; j <= t; ++j)             if (j % t != rmd[i]) vec.push_back(id[j]);           vec.push_back(i);           if (qry(vec)) rmd[i] += t >> 1;         }       while (l <= 2 * t && l <= r) query(l, l % t, r, r % t), ++l, --r;     }     if (p[1] * 2 > n)       for (int i = 1; i <= n; ++i) p[i] = n - p[i] + 1;     cout <<  !  ;     for (int i = 1; i <= n; ++i) cout << p[i] <<    ;     cout << endl, fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   const bool TEST = 0;   const int inf = 0x7fffffff;   using namespace std;   template <typename T>   void pA(T *begin, int n) {     for (int i = 0; i < n; i++) {       cout << *(begin++);     }     printf(  n );   }   const char cho[4] = { R ,  B ,  Y ,  G };   vector<unsigned int> fAns;   bool flag = 0;   bool check(string s, vector<unsigned int> ans) {     if (flag) return 0;     if (TEST) cout << s << endl;     ;     for (int c = 0; c < 4; c++) {       int pre = -4;       for (unsigned int i = 0; i < s.size(); i++) {         if (s[i] ==  ! ) {           if (c == 3)             return 1;           else             continue;         }         if (s[i] == cho[c]) {           if (i - pre >= 4) {             pre = i;           } else             return false;         }       }     }     fAns = ans;     flag = 1;     return 0;   }   int cor(char x) {     switch (x) {       case  R :         return 0;       case  B :         return 1;       case  Y :         return 2;       case  G :         return 3;     }     return 30;   }   void count(string s, vector<unsigned int> ans) {     if (TEST) cout <<  int count  << s << endl;     int sum = 0;     for (unsigned int i = 0; i < 4; i++) {       sum += cor(s[i]);     }     if (sum != 6) return;     for (unsigned int i = 4; i < s.size(); i++) {       if (s[i] ==  ! ) {         ans[cor(s[i - 4])]++;       }     }     fAns = ans;   }   void dfs(unsigned int st, unsigned int curTol, const string s,            vector<unsigned int> ans) {     bool val = 0;     val = check(s, ans);     if (!val) return;     if (st == 4) {       count(s, ans);     }     if (TEST) cout << val << endl;     for (unsigned int i = st; i < 4; i++) {       if (s[i] ==  ! ) {         for (int c = 0; c < 4; c++) {           string s2 = s;           s2[i] = cho[c];           ans[c]++;           dfs(i + 1, curTol + 1, s2, ans);           ans[c]--;         }         return;       }     }     count(s, ans);   }   void sol() {     string s;     cin >> s;     for (int i = 0; i < 4; i++) {       fAns.push_back(0);     }     dfs(0, 0, s, fAns);     for (int i = 0; i < 4; i++) {       if (0 != i) cout <<    ;       cout << fAns[i];     }     cout << endl;   }   void sol2() {     string s;     cin >> s;     for (int i = 0; i < 4; i++) {       fAns.push_back(0);     }     for (int c = 0; c < 4; c++) {       char x = cho[c];       unsigned int pos = s.find_first_of(x);       pos %= 4;       for (unsigned int i = pos; i < s.size(); i += 4) {         if ( !  == s[i]) fAns[cor(x)]++;       }     }     for (int i = 0; i < 4; i++) {       if (0 != i) cout <<    ;       cout << fAns[i];     }     cout << endl;   }   int main() {     sol2();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mx = 1e5 + 10;   long long n, m, a[mx], cnt[mx], r[mx], l[mx], p[mx], ans[mx];   int main() {     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] < mx) cnt[a[i]]++;     }     for (long long i = 0; i < m; i++) cin >> l[i] >> r[i];     for (long long in = 1; in < mx; in++) {       if (cnt[in] >= in) {         p[0] = 0;         for (long long i = 1; i <= n; i++) p[i] = p[i - 1] + (a[i] == in);         for (long long i = 0; i < m; i++)           ans[i] += ((p[r[i]] - p[l[i] - 1]) == in);       }     }     for (long long i = 0; i < m; i++) cout << ans[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[1000010];   char b[1000010];   int main() {     cin >> a;     int ind = 0;     int ans = 0;     int n = strlen(a);     for (int i = 0; i < n; i++) {       if (a[i] ==  [  || a[i] ==  <  || a[i] ==  (  || a[i] ==  { ) {         b[ind] = a[i];         ind++;       } else {         ind--;         if (ind < 0) {           cout <<  Impossible ;           return 0;         }         if (b[ind] ==  [  && a[i] !=  ] ) {           ans++;         } else if (b[ind] ==  <  && a[i] !=  > )           ans++;         else if (b[ind] ==  {  && a[i] !=  } )           ans++;         else if (b[ind] ==  (  && a[i] !=  ) )           ans++;       }     }     if (ind > 0)       cout <<  Impossible ;     else       cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     x = 0;     int f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -f;     for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);     x *= f;   }   inline void print(int x) {     if (x < 0) putchar( - ), x = -x;     if (!x) return;     print(x / 10), putchar((x % 10) ^ 48);   }   inline void write(int x) {     if (!x)       putchar( 0 );     else       print(x);     putchar(  n );   }   int n, ans[5], head[1000050], tot, mx[1000050], mx1[1000050], p, dep[1000050],       d, vis[1000050], f[1000050];   struct edge {     int to, nxt;   } e[1000050 << 1];   void ins(int u, int v) { e[++tot] = (edge){v, head[u]}, head[u] = tot; }   void dfs(int x, int fa) {     dep[x] = dep[fa] + 1;     int cnt = 0;     f[x] = fa;     for (int i = head[x]; i; i = e[i].nxt)       if (e[i].to != fa && !vis[e[i].to]) {         dfs(e[i].to, x), cnt++;         if (!mx[x] || dep[mx[x]] < dep[mx[e[i].to]])           mx1[x] = mx[x], mx[x] = mx[e[i].to];         else if (dep[mx[e[i].to]] > dep[mx1[x]])           mx1[x] = mx[e[i].to];       }     if (!cnt) mx[x] = x;     if (cnt >= 2) {       if (dep[x] > d)         d = dep[x], p = x;       else if (dep[x] == d && dep[mx1[x]] + dep[mx[x]] > dep[mx1[p]] + dep[mx[p]])         p = x;     }   }   int main() {     read(n);     for (int i = 1, x, y; i < n; i++) read(x), read(y), ins(x, y), ins(y, x);     dfs(1, 0), ans[1] = mx[p], ans[3] = mx1[p];     for (int i = head[p]; i; i = e[i].nxt)       if (e[i].to != f[p] && (mx[e[i].to] == mx[p] || mx[e[i].to] == mx1[p]))         vis[e[i].to] = 1;     memset(mx, 0, sizeof mx), memset(mx1, 0, sizeof mx1);     d = 0;     dfs(p, 0), ans[2] = mx[p], ans[4] = mx1[p];     printf( %d %d n%d %d n , ans[1], ans[2], ans[3], ans[4]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string st[n];     int a[m];     for (int i = 0; i < n; i++) {       cin >> st[i];     }     for (int i = 0; i < m; i++) {       cin >> a[i];     }     int maxa = 0;     int ca, cb, cc, cd, ce;     for (int i = 0; i < m; i++) {       ca = 0;       cb = 0;       cc = 0;       cd = 0;       ce = 0;       for (int j = 0; j < n; j++) {         if (st[j][i] ==  A ) ca++;         if (st[j][i] ==  B ) cb++;         if (st[j][i] ==  C ) cc++;         if (st[j][i] ==  D ) cd++;         if (st[j][i] ==  E ) ce++;       }       int x1 = max(ca, cb);       int x2 = max(cc, cd);       int x3 = max(max(x1, x2), ce);       maxa += x3 * a[i];     }     cout << maxa << endl;     return 0;   }