malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int s = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) s = s * 10 + ch -  0 , ch = getchar();     return s;   }   const int N = 1e5 + 5;   int n, m, k, p;   long long h[N], a[N], c[N];   inline bool check(long long x) {     memset(c, 0, sizeof(c));     priority_queue<pair<long long, int>, vector<pair<long long, int>>,                    greater<pair<long long, int>>>         q;     for (int i = 1; i <= n; i++)       if (x - a[i] * m < h[i]) q.push({x / a[i], i});     for (int i = 1; i <= m && !q.empty(); i++)       for (int j = 1; j <= k && !q.empty(); j++) {         auto u = q.top();         q.pop();         if (u.first < i) return 0;         c[u.second]++;         if (x + c[u.second] * p - a[u.second] * m < h[u.second])           q.push({(x + c[u.second] * p) / a[u.second], u.second});       }     return q.empty();   }   int main() {     n = read(), m = read(), k = read(), p = read();     for (int i = 1; i <= n; i++) h[i] = read(), a[i] = read();     long long l = 0, r = 1e16, ans = 0;     for (int i = 1; i <= 60; i++) {       long long mid = (l + r) >> 1;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     map<char, int> mp;     string s;     int i, j, n, off;     cin >> n >> s;     for (i = 0; i < s.size(); i++) {       mp[s[i]] = 1;     }     int max = mp.size();     if (n > max) {       cout <<  NO ;     } else {       int c = 0;       cout <<  YES  << endl;       for (i = 0; i < s.size(); i++) {         if (mp[s[i]] == 1 && c < n - 1) {           mp[s[i]] = 0;           c++;           j = i;           while (mp[s[j++]] == 0) {             cout << s[i];             i = j;           }           i--;           cout << endl;         } else {           cout << s[i];         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 2e5 + 5;   const int MAX = 0x7fffffff;   const int MIN = 0x80000000;   int n, k;   struct node {     int num, index;     bool friend operator<(node a, node b) { return a.num > b.num; }   };   node a[N];   char ch[N];   int pos[N] = {0};   int dp[N] = {0};   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i].num);       a[i].index = i;     }     scanf( %s , ch);     long long sum = 0;     sort(a, a + n);     pos[0] = 0;     for (int i = 1; i < n; i++) {       if (ch[i] == ch[i - 1])         pos[i] = pos[i - 1];       else         pos[i] = i;     }     for (int i = 0; i < n; i++) {       if (dp[pos[a[i].index]] < k) {         sum += a[i].num;         dp[pos[a[i].index]]++;       }     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> a[30005];   int main() {     int n, m, p, q, i, j;     vector<int> v;     cin >> n >> m;     for (i = 0; i < m; i++) {       scanf( %d%d , &p, &q);       a[p].push_back(q);     }     for (i = 1; i < n; i++) sort(a[i].begin(), a[i].end());     for (i = 1; i <= n; i++) {       v.push_back(i);       j = i - 2;       while (j >= 0) {         if (binary_search(a[v[j]].begin(), a[v[j]].end(), i)) {           swap(v[j], v[j + 1]);           j--;         } else           break;       }     }     for (i = 0; i < n - 1; i++)       if (binary_search(a[v[i]].begin(), a[v[i]].end(), v[i + 1])) {         cout << -1 << endl;         return 0;       }     for (i = 0; i < n; i++) cout << v[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long xx = 0, yy = 0;     for (int i = 0; i < 2 * n; i++) {       int x, y;       cin >> x >> y;       xx += x;       yy += y;     }     cout << xx / n <<     << yy / n;     return 0;   }
#pragma GCC optimize( O3 )   #include <bits/stdc++.h>   using namespace std;      //#include <ext/pb_ds/assoc_container.hpp>   //#include <ext/pb_ds/tree_policy.hpp>   //using namespace __gnu_pbds;      //template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;   //template<class T> using omultiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;      //find_by_order   //order_of_key      #define x first   #define y second   #define pb push_back   #define all(a) a.begin(),a.end()      typedef long long ll;   typedef long double ld;   typedef unsigned long long ull;   typedef pair<int,int> pii;   typedef pair<ll,ll> pll;   typedef vector<ll> vl;   typedef vector<int> vi;   typedef vector<bool> vb;   typedef vector<vi> vvi;   typedef vector<vl> vvl;   typedef vector<pii> vii;   typedef vector<pll> vll;      mt19937 rnd(time(nullptr));      const int N = 2e5+5;      int t[4*N], p[4*N];   string s, f;      void push(int v, int tl, int tr) {       if (tl == tr || p[v] == -1)           return;       int tm = tl+tr >> 1;       int vv = v << 1;       t[vv] = p[v]*(tm-tl+1);       t[vv+1] = p[v]*(tr-tm);       p[vv] = p[v];       p[vv+1] = p[v];       p[v] = -1;   }      void build(int v, int tl, int tr) {       if (tl == tr) {           t[v] = f[tl]- 0 ;           p[v] = -1;           return;       }       int tm = tl+tr >> 1;       int vv = v << 1;       push(v, tl, tr);       build(vv, tl, tm);       build(vv+1, tm+1, tr);       t[v] = t[vv]+t[vv+1];   }      void upd(int v, int tl, int tr, int l, int r, int val) {       if (tl > r || l > tr)           return;       if (l <= tl && tr <= r) {           t[v] = (tr-tl+1)*val;           p[v] = val;           return;       }       int tm = tl+tr >> 1;       int vv = v << 1;       push(v, tl, tr);       upd(vv, tl, tm, l, r, val);       upd(vv+1, tm+1, tr, l, r, val);       t[v] = t[vv]+t[vv+1];   }      int get(int v, int tl, int tr, int l, int r) {       if (l > tr || tl > r)           return 0;       if (l <= tl && tr <= r)           return t[v];       int tm = tl+tr >> 1;       int vv = v << 1;       push(v, tl, tr);       return get(vv, tl, tm, l, r)+get(vv+1, tm+1, tr, l, r);   }            void solve() {       int n, q; cin >> n >> q;       cin >> s >> f;       s =  # +s, f =  # +f;       vii ask(q);       for (pii& cur : ask)           cin >> cur.x >> cur.y;       reverse(all(ask));       build(1, 1, n);       for (pii cur : ask) {           int sum = get(1, 1, n, cur.x, cur.y);           int len = cur.y-cur.x+1;           if (sum*2 == len) {               cout <<  NO n ;               return;           }           if (sum <= (len-1)/2) {               upd(1, 1, n, cur.x, cur.y, 0);           }           else {               upd(1, 1, n, cur.x, cur.y, 1);           }       }       for (int i=1; i<=n; ++i) {           if (get(1, 1, n, i, i)+ 0  != s[i]) {               cout <<  NO n ;               return;           }       }       cout <<  YES n ;   }            int main() {       ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);       int t; cin >> t;       while(t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int solve(int n, int k, vector<int> &arr, int mn) {     int MX = int(1e6);     if (k >= mn - 1) return mn;     int i, j;     for (i = mn; i >= k + 1; i--) {       int tot = 0;       for (j = 0; j <= MX; j += i) {         int mx = min(j + k, MX);         tot += (arr[mx] - (j > 0 ? arr[j - 1] : 0));       }       if (tot == n) return i;     }     return -33;   }   int main() {     int MX = (1e6) + 2;     vector<int> arr(MX - 1, 0);     int n;     scanf( %d , &n);     int k;     scanf( %d , &k);     int i, j;     int mn = MX;     for (i = 0; i < n; i++) {       int temp;       scanf( %d , &temp);       mn = min(mn, temp);       arr[temp]++;     }     for (i = 1; i < MX; i++) arr[i] += arr[i - 1];     printf( %d n , solve(n, k, arr, mn));   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, a, m, x, tk, i, tr, tl, r, l;     scanf( %d %d %d , &n, &k, &a);     scanf( %d , &m);     tk = (n + 1) / (a + 1);     set<int> ceils;     map<int, pair<int, int> > intv;     ceils.insert(n);     intv[n] = pair<int, int>(1, tk);     for (i = 1; i <= m; i++) {       scanf( %d  , &x);       auto it = ceils.lower_bound(x);       tk -= intv[*it].second;       r = intv[*it].first;       l = *it;       ceils.erase(it);       if (x > r) {         tr = ((x - r) + 1) / (a + 1);         ceils.insert(x - 1);         intv[x - 1] = pair<int, int>(r, tr);         tk += tr;       }       if (x < l) {         tl = ((l - x) + 1) / (a + 1);         ceils.insert(l);         intv[l] = pair<int, int>(x + 1, tl);         tk += tl;       }       if (tk < k) break;     }     if (i > m)       printf( -1 n );     else       printf( %d n , i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool dp[20][10];   int dp4[20][10], dp7[20][10], dpj[20][10];   long long n;   int bit = 1;   long long ten[20];   long long r[6];   int w[20];   int main() {     int tcase;     scanf( %d , &tcase);     ten[0] = 1;     for (int i = 1; i <= 18; i++) ten[i] = ten[i - 1] * 10;     while (tcase--) {       memset(dp, 0, sizeof(dp));       bit = 1;       scanf( %lld , &n);       while (n) {         w[bit++] = n % 10;         n /= 10;       }       bit--;       dp[1][0] = true;       for (int i = 1; i <= bit; i++) {         for (int j = 0; j < 9; j++)           if (dp[i][j]) {             for (int x = 0; x <= 6; x++)               for (int y = 0; x + y <= 6; y++) {                 if ((x * 4 + y * 7 + j - w[i]) % 10 != 0) continue;                 dp[i + 1][(x * 4 + y * 7 + j - w[i]) / 10] = 1;                 dp4[i + 1][(x * 4 + y * 7 + j - w[i]) / 10] = x;                 dp7[i + 1][(x * 4 + y * 7 + j - w[i]) / 10] = y;                 dpj[i + 1][(x * 4 + y * 7 + j - w[i]) / 10] = j;               }           }       }       if (!dp[bit + 1][0]) {         puts( -1 );         continue;       }       int j = 0;       memset(r, 0, sizeof(r));       for (int i = bit + 1; i >= 2; i--) {         int x = dp4[i][j], y = dp7[i][j], jj = dpj[i][j];         for (int k = 0; k < 6; k++) {           if (k < x)             r[k] += 4 * ten[i - 2];           else if (k < x + y)             r[k] += 7 * ten[i - 2];         }         j = jj;       }       for (int i = 0; i < 6; i++) printf( %lld  , r[i]);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   long long n, T, a[maxn], x, y, t1, t2, k;   long long b[maxn];   long long cmp(long long x, long long y) { return x > y; }   long long cmp1(long long x, long long y) { return x > y; }   long long check(long long len) {     for (long long i = 1; i <= len; i++) {       if (i % t1 == 0 && i % t2 == 0)         b[i] = x + y;       else if (i % t1 == 0)         b[i] = x;       else if (i % t2 == 0)         b[i] = y;     }     sort(b + 1, b + 1 + len, cmp1);     long long ans = 0;     for (long long i = 1; i <= len; i++) {       ans += b[i] * a[i];     }     if (ans >= k) return 1;     return 0;   }   int main() {     cin >> T;     while (T--) {       cin >> n;       for (long long i = 1; i <= n; i++) cin >> a[i];       sort(a + 1, a + 1 + n, cmp);       cin >> x >> t1 >> y >> t2 >> k;       k *= 100;       long long l = 0, r = n, ans = 0x7f7f7f7f;       while (l <= r) {         long long mid = (l + r) / 2;         memset(b, 0, sizeof(b));         if (check(mid)) {           r = mid - 1;           ans = mid;         } else {           l = mid + 1;         }       }       if (ans == 0x7f7f7f7f)         cout <<  -1  << endl;       else         cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000 * 1000 * 1000 + 7;   const int INF = 1e9 + 100;   const long long LINF = 1e18 + 100;   long long x, k;   const int n = 1e5;   vector<long long> divs;   vector<long long> ddv[7010];   vector<long long> fk[7010];   void getnxt(const vector<long long> &cur, vector<long long> &res) {     res.clear();     for (int ptr = 0; ptr < (int)cur.size() && (int)res.size() < n; ptr++) {       int p = lower_bound((divs).begin(), (divs).end(), cur[ptr]) - divs.begin();       for (int i = 0; i < (int)ddv[p].size() && (int)res.size() < n; i++)         res.push_back(ddv[p][i]);     }   }   void get2i(const vector<long long> &cur, vector<long long> &res) {     res.clear();     for (int i = (0); i < (7010); i++) fk[i].clear();     int cnum = 0;     for (long long u : cur) {       int p = lower_bound((divs).begin(), (divs).end(), u) - divs.begin();       fk[cnum].push_back(u);       if (p == cnum) cnum++;     }     for (int ptr = 0; ptr < (int)cur.size() && (int)res.size() < n; ptr++) {       int p = lower_bound((divs).begin(), (divs).end(), cur[ptr]) - divs.begin();       for (int i = 0; i < (int)fk[p].size() && (int)res.size() < n; i++)         res.push_back(fk[p][i]);     }     vector<long long> cop;     cop.swap(res);     getnxt(cop, res);   }   void getkth(vector<long long> &res, int k) {     if (k == 1) {       res = divs;       return;     }     getkth(res, k / 2);     vector<long long> cop;     cop.swap(res);     get2i(cop, res);     if (k % 2 == 0) return;     cop.clear();     cop.swap(res);     getnxt(cop, res);   }   int32_t main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> x >> k;     if (k == 0) return cout << x <<   n , 0;     if (x == 1) {       return cout <<  1 n , 0;     }     if (k > n) {       for (int i = (0); i < (n); i++) cout <<  1  ;       cout <<   n ;       return 0;     }     for (long long i = 1; i * i <= x; i++) {       if (x % i == 0) {         divs.push_back(i);         if (i * i != x) divs.push_back(x / i);       }     }     sort((divs).begin(), (divs).end());     for (int i = (0); i < ((int)divs.size()); i++) {       for (int j = (0); j < (i + 1); j++) {         if (divs[i] % divs[j] == 0) ddv[i].push_back(divs[j]);       }     }     vector<long long> ans;     getkth(ans, k);     for (long long u : ans) cout << u <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353, INF = 1e18;   vector<int> f;   int n;   int getsum(int i) {     int sum = 0;     i += 1;     while (i > 0) {       sum += f[i];       i -= (i & (-i));     }     return sum;   }   void update(int i, int val) {     i += 1;     while (i <= n + 1 && i > 0) {       f[i] += val;       i += (i & (-i));     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int q;     cin >> n >> q;     f.resize(n + 2, 0);     for (int i = 0; i < n; i++) {       int d;       cin >> d;       update(d, 1);     }     while (q--) {       int k;       cin >> k;       if (k > 0) {         update(k, 1);       } else {         k *= -1;         int l = 0, r = n;         while (l < r) {           int m = (l + r) / 2;           int p = getsum(m);           if (p >= k)             r = m;           else             l = m + 1;         }         update(l, -1);       }     }     int ans = 0;     for (int i = 2; i <= n + 1; i++)       if (f[i] > 0) {         ans = i - 1;         break;       }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void read_string_to_vector(vector<string> &vec) {     string str;     getline(cin, str);     vec.push_back(str);   }   template <typename T>   inline void read_digit_to_vector(vector<T> &vec) {     T t;     cin >> t;     vec.push_back(t);   }   template <typename T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   long long n;   long long answ;   int main() {     scanf( %lld , &n);     while (n--) {       long long a;       scanf( %lld , &a);       answ ^= (a & 1) ^ 1;       printf(answ ?  1 n  :  2 n );     }     return 0;   }
#pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   #include <bits/stdc++.h>    using namespace std;       typedef long long ll;   #define S second   #define v vector   #define dbg(x)              cout<<#x<< = <<(x)<<endl;   #define dbg2(x,y)           cout<<#x<< = <<(x)<<   <<#y<< = <<(y)<<endl;   #define dbg3(x,y,z)         cout<<#x<< = <<(x)<<   <<#y<< = <<(y)<<   <<#z<< = <<(z)<<endl;   #define dbg4(x,y,z,w)       cout<<#x<< = <<(x)<<   <<#y<< = <<(y)<<   <<#z<< = <<(z)<<   <<#w<< = <<(w)<<endl;   #define mp make_pair   #define pb push_back   #define endl                  n    #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)          int main()   {    fast_cin();    ll t;    cin >> t;    while (t--)    {        ll x;        ll i;        ll n, flag = 0, mx = 0, mn = 1e10 + 1;        ll k;           cin >> n >> k;        set<ll> s1;        for (i = 0; i < n; i++)        {            cin >> x;            s1.insert(x);      }   ll z =-1;   ll mex = 0;   for (auto it = s1.begin(); it != s1.end();it++)   {   if(*it==z+1)       z++;   else   {       mex = z+1;   }      }   mex = z + 1;   if(k==0)       cout << s1.size() << endl;   else if(mex==*s1.rbegin())   {       cout << s1.size() << endl;      }   else   {       if(mex>*s1.rbegin())           cout << s1.size() + k << endl;   else   {       ll a = (mex + *s1.rbegin());   if(a%2)   {       a = a / 2;       a++;   }   else   {       a /= 2;   }   s1.insert(a);   cout << s1.size() << endl;      }   }      }   return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, k;     cin >> n >> k;     string s;     cin >> s;     vector<char> base(k,  ? );     for (long long i = 0; i < n; i++) {       if (s[i] ==  1 ) {         if (base[i % k] ==  1 ) {           continue;         }         if (base[i % k] ==  0 ) {           cout <<  NO  << endl;           return;         }         if (base[i % k] ==  ? ) {           base[i % k] =  1 ;         }       } else if (s[i] ==  0 ) {         if (base[i % k] ==  0 ) {           continue;         }         if (base[i % k] ==  1 ) {           cout <<  NO  << endl;           return;         }         if (base[i % k] ==  ? ) {           base[i % k] =  0 ;         }       } else {       }     }     long long zero = 0, one = 0;     for (long long i = 0; i < k; i++) {       if (base[i] ==  0 )         zero++;       else if (base[i] ==  1 )         one++;     }     if (one <= k / 2 && zero <= k / 2)       cout <<  YES  << endl;     else {       cout <<  NO  << endl;     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     long long x, y;     bool operator<(const point& t) const {       if (x == t.x) return y < t.y;       return x < t.x;     }     bool operator==(const point& t) const { return x == t.x && y == t.y; }   };   const long long INF = 1e18;   const long long mod = 1e9 + 7;   const long long MAXN = 1e6 + 69;   long long q = 1, m, n, x, y, z, k, l;   point a[MAXN];   string s;   set<point> ans;   vector<point> X;   vector<point> solve(const vector<point>& X) {     if (X.size() <= 1) return X;     long long mid = X.size() / 2;     vector<point> a, b;     for (long long i = 0; i < mid; i++) {       a.push_back(X[i]);     }     for (long long i = mid; i < X.size(); i++) {       b.push_back(X[i]);     }     a = solve(a);     b = solve(b);     long long middle = (a.back().x + b[0].x) / 2;     vector<point> res;     for (long long i = 0; i < a.size(); i++) {       res.push_back(a[i]);       res.push_back({middle, a[i].y});     }     for (long long i = 0; i < b.size(); i++) {       res.push_back(b[i]);       res.push_back({middle, b[i].y});     }     sort(res.begin(), res.end());     res.resize(unique(res.begin(), res.end()) - res.begin());     return res;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long i = 1; i <= n; i++)       cin >> a[i].x >> a[i].y, ans.insert({a[i]});     sort(a + 1, a + n + 1);     for (long long i = 1; i <= n; i++) X.push_back(a[i]);     vector<point> ans = solve(X);     cout << ans.size() <<   n ;     for (point u : ans) cout << u.x <<     << u.y <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long n, m, u, v, st, cnt, a[N], check[N], num[N], low[N];   long long sz[N], val[N], sub[N], good[N];   vector<int> adj[N];   vector<pair<int, int> > edge;   map<pair<int, int>, bool> bridge;   void dfs(int u, int p) {     check[u] = 1;     num[u] = low[u] = ++cnt;     for (int v : adj[u]) {       if (check[v] == 0) {         dfs(v, u);         low[u] = min(low[u], low[v]);         if (num[u] < low[v]) {           bridge[{u, v}] = bridge[{v, u}] = 1;         }       } else {         if (v != p) {           low[u] = min(low[u], num[v]);         }       }     }   }   void dfs1(int u) {     check[u] = cnt;     val[cnt] += a[u];     for (int v : adj[u]) {       if (check[v] == 0) {         dfs1(v);       }     }   }   void dfs2(int u, int p) {     good[u] = (sz[u] > 1);     sub[u] = 0;     for (int v : adj[u]) {       if (v != p) {         dfs2(v, u);         good[u] |= good[v];         sub[u] = max(sub[u], sub[v]);       }     }     sub[u] += val[u];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= m; i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);       edge.push_back({u, v});     }     cin >> st;     dfs(st, st);     for (int i = 1; i <= n; i++) {       check[i] = 0;       adj[i].clear();     }     for (auto tmp : edge) {       u = tmp.first;       v = tmp.second;       if (bridge[{u, v}] == 0) {         adj[u].push_back(v);         adj[v].push_back(u);       }     }     cnt = 0;     for (int i = 1; i <= n; i++) {       if (check[i] == 0) {         cnt++;         dfs1(i);       }     }     for (int i = 1; i <= n; i++) {       adj[i].clear();       sz[check[i]]++;     }     for (auto tmp : edge) {       u = tmp.first;       v = tmp.second;       if (bridge[{u, v}] == 1) {         adj[check[u]].push_back(check[v]);         adj[check[v]].push_back(check[u]);       }     }     int root = check[st];     dfs2(root, root);     long long ans = 0, mx = 0;     for (int i = 1; i <= cnt; i++) {       if (good[i] == 1) {         ans += val[i];       } else {         mx = max(mx, sub[i]);       }     }     cout << ans + mx;   }
#include <bits/stdc++.h>   using namespace std;   string str[100];   int func(string s1, string s2) {     int i, j, k;     int l1 = s1.length(), l2 = s2.length();     if (l1 != l2) return -1;     for (i = 0; i < l1; ++i) {       for (j = i, k = 0; k < l1; ++k, ++j) {         j = j % l1;         if (s1[k] != s2[j]) break;       }       if (k == l1) return i;     }     return -1;   }   int main() {     int i, j, k;     int n, cnt;     cin >> n;     for (i = 0; i < n; ++i) cin >> str[i];     int mn = 1000000000;     for (i = 0; i < n; ++i) {       cnt = 0;       for (j = 0; j < n; ++j) {         if (i == j) continue;         k = func(str[i], str[j]);         if (k == -1) {           printf( -1 n );           return 0;         }         cnt += k;       }       mn = min(mn, cnt);     }     cout << mn << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4e4 + 10, M = 32, INF = 1e9 + 10;   int a, b, n;   int dp[N][M];   long long mypw(long long a, int b) {     double ans = pow(a, b);     if (ans > INF) {       return INF;     }     long long ret = 1;     while (b--) ret = ret * a;     return ret;   }   int check(int a, int b) {     if (a < N && b < M && dp[a][b] != -1) return dp[a][b];     if (a == 1 && mypw(a + 1, b) >= n) {       return 2;     }     if (b == 1 && mypw(a, b + 1) >= n) {       return !((n - a) & 1);     }     if (mypw(a, b) >= n) return dp[a][b] = 1;     int a1 = check(a + 1, b);     int a2 = check(a, b + 1);     if (a1 == 0 || a2 == 0) return dp[a][b] = 1;     if (a1 == 2 || a2 == 2) return dp[a][b] = 2;     return dp[a][b] = 0;   }   int main() {     scanf( %d%d%d , &a, &b, &n);     memset(dp, -1, sizeof(dp));     int t = check(a, b);     if (t == 1)       puts( Masha );     else if (t == 0)       puts( Stas );     else       puts( Missing );     return 0;   }