malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[300004];   int n, nr, r, Min, poz, f1, f2, ch1, ch2, sol, soli, sol2, i, j, l, v[300004],       m[300004];   char s[300004], b[300004];   bool ok1, ok2;   int main() {     scanf( %d , &n);     scanf( %s , &s);     nr = 0;     Min = 1000000000;     for (i = 0; i < n; i++) {       if (s[i] ==  ( )         nr++;       else         nr--;       v[i] = nr;       Min = min(Min, v[i]);       m[i] = Min;     }     if (v[n - 1] != 0) {       printf( %d n%d %d n , 0, 1, 1);       return 0;     }     poz = 0;     if (m[n - 1] < 0) {       nr = 0;       poz = -1;       for (i = (n - 1); i > 0; i--) {         if (s[i] ==  ( )           nr++;         else           nr--;         if ((nr + m[i - 1]) >= 0) {           poz = i;           break;         }       }       nr = -1;       for (j = poz; j < n; j++) b[++nr] = s[j];       for (j = 0; j < poz; j++) b[++nr] = s[j];     } else {       for (i = 0; i < n; i++) b[i] = s[i];     }     l = 0;     r = 0;     sol = 0;     ch1 = 1;     ch2 = 1;     nr = 0;     for (i = 0; i < n; i++) {       if (b[i] ==  ( )         nr++;       else         nr--;       v[i] = nr;       Min = min(Min, v[i]);       m[i] = Min;       if (nr == 0) {         sol++;         a[++r].first = l;         a[r].second = i;         l = i + 1;       }     }     soli = sol;     for (i = 1; i <= r; i++) {       sol2 = 0;       nr = 0;       ok1 = false;       ok2 = false;       for (j = a[i].first + 1; j < a[i].second; j++) {         if (b[j] ==  ( ) {           nr++;           if (!ok1) {             f1 = j;             ok1 = true;           }         } else {           nr--;           if (!ok2) {             f2 = j;             ok2 = true;           }         }         if (nr == 0) sol2++;       }       if ((sol2 + 1) > sol) {         sol = sol2 + 1;         ch1 = a[i].first;         ch2 = a[i].second;       }       sol2 = 0;       nr = 0;       f2 = a[i].first + 1;       for (j = a[i].first + 1; j < a[i].second; j++) {         if (b[j] ==  ( ) {           nr++;           if (!ok1) {             f1 = j;             ok1 = true;           }         } else {           nr--;           if (!ok2) {             f2 = j;             ok2 = true;           }         }         if (nr == 0) {           if ((sol2 + soli) > sol) {             sol = sol2 + soli;             ch1 = f2;             ch2 = j;           }           sol2 = 0;           f2 = j + 1;         }         if (nr == 1) sol2++;       }     }     ch1 = (ch1 + poz) % n + 1;     ch2 = (ch2 + poz) % n + 1;     printf( %d n%d %d , sol, ch1, ch2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long A[200005], dp[300005];   int main() {     long long a, b, h, w;     scanf( %lld%lld%lld%lld , &a, &b, &h, &w);     long long n;     scanf( %lld , &n);     long long i, j;     for (i = 1; i <= n; i++) {       scanf( %lld , A + i);     }     if (h >= a && w >= b) {       printf( 0 );       return 0;     }     if (h >= b && w >= a) {       printf( 0 );       return 0;     }     sort(A + 1, A + n + 1);     reverse(A + 1, A + n + 1);     dp[1] = 1;     long long prod = 1;     for (i = 1; i <= min(n, 40LL); i++) {       prod *= A[i];       for (j = 1; j <= 300000; j++) {         if ((long long)j * A[i] <= 300000) {           dp[j * A[i]] |= dp[j];         }       }       for (j = 1; j <= 300000; j++) {         if (!dp[j]) continue;         if (prod % j != 0) continue;         long long rem = prod / j;         if (h * j >= a && w * rem >= b) {           printf( %lld , i);           return 0;         }         if (h * j >= b && w * rem >= a) {           printf( %lld , i);           return 0;         }       }       if (prod >= 2e10) break;     }     printf( -1 );   }
#include <bits/stdc++.h>   int main() {     char string[101];     int i = 0;     while (scanf( %c , &string[i]) && string[i++] !=   n )       if (string[i - 1] ==  H  || string[i - 1] ==  Q  || string[i - 1] ==  9 ) {         printf( YES );         exit(0);       }     printf( NO );   }
#include <bits/stdc++.h>   using namespace std;   const int N = 111;   const int INFI = 2147483627;   int a[N], b[N];   int main() {     int n, ans = -1, flag, t;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 1; i < n; i++) {       b[i - 1] = a[i] - a[i - 1];       if (ans < b[i - 1]) ans = b[i - 1];     }     flag = 0;     t = INFI;     for (int i = 0; i < n - 2; i++) {       if (b[i] + b[i + 1] <= ans) {         flag = 1;         printf( %d n , ans);         break;       }       if (t > b[i] + b[i + 1]) t = b[i] + b[i + 1];     }     if (!flag) printf( %d n , t);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long j;   long long ix, iy;   int mx[100100], my[100100];   inline void reflect(int in, long long ax, long long ay, long long& bx,                       long long& by) {     bx = ax + ((mx[in] - ax) << 1);     by = ay + ((my[in] - ay) << 1);     return;   }   int main() {     cin >> n >> j;     int i, cnt = 0;     long long a, b;     memset((mx), (0), sizeof((mx)));     memset((my), (0), sizeof((my)));     j = j % ((long long)(2 * n));     cin >> ix >> iy;     for (i = 0; i < n; i++) {       cin >> mx[i] >> my[i];     }     a = ix;     b = iy;     while (cnt < j) {       for (i = 0; i < n && cnt < j; i++) {         reflect(i, ix, iy, a, b);         ix = a;         iy = b;         cnt++;       }     }     cout << ix <<     << iy <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int mod = 1e9 + 7;   long long a[N], b, c, d, dis;   pair<int, int> p;   bool mark = true;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t, n, m, k, ans = 0, sum = 0, mn = 1e8, mx = 0, x, y;     cin >> t;     string s;     while (t--) {       cin >> n >> k >> s;       sum = 0;       bool h = true;       for (int i = 0; i < n; i++) {         if (s[i] ==  1 ) h = false;       }       if (h) {         if (n == k)           cout << 1 << endl;         else           cout << (n + k) / (k + 1) << endl;       } else {         ans = 0;         for (int i = 0; i < n; i++) {           if (s[i] ==  1 ) {             x = i;             break;           } else             ans++;         }         sum += ans / (k + 1);         ans = 0;         for (int i = n - 1; i >= 0; i--) {           if (s[i] ==  1 ) {             y = i;             break;           } else             ans++;         }         sum += ans / (k + 1);         ans = 0;         for (int i = x; i <= y; i++) {           if (s[i] ==  0 )             ans++;           else {             sum += (ans - k) / (k + 1);             ans = 0;           }         }         cout << sum << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> q[100002];   int ans[100002];   int flag, v[100002];   int k;   void dfs(int len, int x, int f) {     int i;     v[x] = len;     ans[len] = x;     for (i = 0; i < q[x].size(); i++) {       int j = q[x][i];       if (j == f) continue;       if (v[j] != -1) {         if (flag) break;         if (len + 1 - v[j] >= k + 1) {           printf( %d n , len + 1 - v[j]);           for (i = v[j]; i <= len; i++) {             if (i != v[j]) printf(   );             printf( %d , ans[i]);           }           printf(  n );           flag = 1;           return;         }         continue;       }       dfs(len + 1, j, x);     }   }   int main() {     int n, m;     while (scanf( %d%d%d , &n, &m, &k) != EOF) {       while (m--) {         int a, b;         scanf( %d%d , &a, &b);         q[a].push_back(b);         q[b].push_back(a);       }       memset(v, -1, sizeof(v));       dfs(0, 1, -1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long a, b, c, n, sum = 0, Max, Min;       cin >> a >> b >> c >> n;       Max = max(max(a, b), c);       sum = a + b + c;       if (3 * Max - sum > n)         cout <<  NO  << endl;       else {         sum += n;         if (sum % 3 == 0)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double dp[105][105 * 1005];   int a[105];   int main(void) {     int n, m;     scanf( %d%d , &n, &m);     int sum = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       sum += a[i];     }     if (m == 1) {       printf( %.10f n , 1.0);       return 0;     }     dp[0][0] = m - 1;     for (int i = 1; i <= n; ++i) {       double sum = 0;       for (int j = i; j <= i * m; ++j) {         sum += dp[i - 1][j - 1] / (m - 1);         if (j - 1 - m >= 0) sum -= dp[i - 1][j - m - 1] / (m - 1);         dp[i][j] = sum;         if (j - a[i - 1] >= 0) dp[i][j] -= dp[i - 1][j - a[i - 1]] / (m - 1);       }     }     double ans = 1;     for (int i = 0; i < sum; i++) ans += dp[n][i];     printf( %.10f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int solve() {     int n, m, tx = 0;     cin >> n >> m;     vector<int> t(m), a(m), b(m), g[n], c(n), tout(n);     for (int i = 0; i < m; i++) {       cin >> t[i] >> a[i] >> b[i];       --a[i], --b[i];       if (t[i]) g[a[i]].push_back(b[i]);     }     function<bool(int v)> dfs = [&](int v) {       c[v] = 1;       for (int u : g[v]) {         if (c[u] == 1)           return true;         else if (!c[u])           if (dfs(u)) return true;       }       c[v] = 2;       tout[v] = tx++;       return false;     };     for (int i = 0; i < n; i++)       if (!c[i] && dfs(i)) return cout <<  NO  <<   n , 0;     cout <<  YES  <<   n ;     for (int i = 0; i < m; i++) {       if (!t[i])         if (tout[a[i]] < tout[b[i]]) swap(a[i], b[i]);       cout << a[i] + 1 <<     << b[i] + 1 <<   n ;     }     return 0;   }   signed main() {     std::ios::sync_with_stdio(0);     std::cout.tie(0);     std::cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     register int x = 0;     register bool f = 0;     register char ch = getchar();     while (!isdigit(ch)) {       f ^= !(ch ^  - );       ch = getchar();     }     while (isdigit(ch)) {       x = ((x + (x << 2)) << 1) + (ch ^  0 );       ch = getchar();     }     return f ? -x : x;   }   inline void print(int x) {     register int sc[30] = {0}, tot = 0;     do {       sc[++tot] = x % 10;       x /= 10;     } while (x);     while (tot) putchar( 0  + sc[tot--]);   }   int n, maxn, k, ans;   int peo[510 * 510], tot[510 * 510], h[510];   int dp[5010][5010];   int main() {     n = read();     k = read();     for (register int i = 1; i <= n * k; i++) {       int tmp = read();       tot[tmp]++;       maxn = max(maxn, tmp);     }     for (register int i = 1; i <= n; i++) {       int tmp = read();       peo[tmp]++;     }     for (register int i = 1; i <= k; i++) h[i] = read();     for (register int i = 1; i <= n; i++)       for (register int j = 1; j <= n * k; j++)         for (register int l = 1; l <= min(j, k); l++)           dp[i][j] = max(dp[i][j], dp[i - 1][j - l] + h[l]);     for (register int i = 1; i <= maxn; i++)       if (peo[i]) ans += dp[peo[i]][tot[i]];     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int p = 0, t = 1;     if (s.substr(0, 4) ==  http ) {       p = 1;       cout <<  http:// ;     } else       cout <<  ftp:// ;     int i = p + 3;     while (!(s[i] ==  r  && s[i + 1] ==  u ) || t) {       cout << s[i];       i++;       t = 0;     }     cout <<  .ru ;     if (s.size() - i - 2 > 0) cout <<  / ;     cout << s.substr(i + 2, s.size() - (i + 2));   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   const long long inf = 1e17;   long long overFlow(long long a, long long b) {     if ((inf / a) < b) return 1;     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long x0, y0, ax, ay, bx, by;     cin >> x0 >> y0 >> ax >> ay >> bx >> by;     long long xs, ys, t;     cin >> xs >> ys >> t;     vector<pair<long long, long long> > v;     v.push_back({x0, y0});     while (true) {       if (overFlow(x0, ax) || overFlow(y0, ay)) break;       x0 = ax * x0 + bx, y0 = ay * y0 + by;       v.push_back({x0, y0});     }     if (v.size() > 100) assert(0);     int ans = 0;     for (int i = 0; i < v.size(); i++) {       int cnt = 0;       long long ds = abs(v[i].first - xs) + abs(v[i].second - ys);       if (ds > t) continue;       cnt++;       for (int j = i - 1; j >= 0; j--) {         ds += v[j + 1].first - v[j].first + v[j + 1].second - v[j].second;         if (ds > t) break;         cnt++;       }       if (ds > t) {         ans = max(ans, cnt);         continue;       }       int pr = 0;       for (int j = i + 1; j < v.size(); j++) {         ds += v[j].first - v[pr].first + v[j].second - v[pr].second;         if (ds > t) break;         cnt++;         pr = j;       }       ans = max(ans, cnt);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, i, zer = -1, one;       cin >> n;       string s;       string ans =   ;       cin >> s;       for (i = 0; i < n; i++) {         if (s[i] ==  1 ) break;         zer = i;       }       one = n;       for (i = n - 1; i >= 0; i--) {         if (s[i] ==  0 ) break;         one = i;       }       for (i = 0; i <= zer; i++) ans = ans +  0 ;       if (zer + 1 != one) ans = ans +  0 ;       for (i = n - 1; i >= one; i--) ans = ans +  1 ;       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j;     long long int prod = 1;     char mat[105][105];     cin >> n >> m;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cin >> mat[i][j];       }     }     for (i = 0; i < m; i++) {       unordered_set<char> s;       for (j = 0; j < n; j++) {         if (s.find(mat[j][i]) == s.end()) s.insert(mat[j][i]);       }       prod = (prod * (s.size() % 1000000007)) % 1000000007;     }     cout << prod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, m;   int a[111];   int c[111][111];   long long dp[111][111][111];   long long f(int idx, int cnt, int last) {     if (idx > n) return cnt == k ? 0 : 1e13;     if (dp[idx][cnt][last] != -1) return dp[idx][cnt][last];     long long ans = 1e13;     if (a[idx])       ans = min(ans, f(idx + 1, cnt + (a[idx] == last ? 0 : 1), a[idx]));     else {       for (int i = 1; i <= m; i++)         ans = min(ans, f(idx + 1, cnt + (last == i ? 0 : 1), i) + c[idx][i]);     }     return dp[idx][cnt][last] = ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     memset(dp, -1, sizeof dp);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     a[0] = 111;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> c[i][j];     long long ans = f(1, 0, 111);     if (ans > 1e12)       cout << -1;     else       cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   const int mod = 998244353;   int up(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }   int a[1010], dp[1010][1010], pos[100010], n, k;   int cal(int x) {     for (int i = 0; i <= k; ++i)       for (int j = 0; j <= n; ++j) dp[i][j] = 0;     for (int i = 1; i <= n; ++i) dp[1][i] = 1;     for (int i = 2; i <= k + 1; ++i) {       for (int j = 1; j <= n; ++j)         dp[i - 1][j] = up(dp[i - 1][j - 1], dp[i - 1][j]);       for (int j = 1; j <= n; ++j)         dp[i][j] = dp[i - 1][a[j] >= x ? pos[a[j] - x] : 0];     }     return dp[k][n];   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     sort(a + 1, a + 1 + n);     for (int i = n; i >= 1; --i)       pos[a[i]] = (a[i] == a[i + 1] ? pos[a[i + 1]] : i);     for (int i = 1; i <= 100000; ++i) pos[i] = max(pos[i], pos[i - 1]);     int ans = 0;     for (int i = 1; i * (k - 1) <= 100000; ++i) ans = up(ans, cal(i));     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v;     int n, x, temp, cntr = 0;     cin >> n >> x;     while (n--) {       cin >> temp;       v.push_back(temp);     }     sort(v.begin(), v.end());     while (v[(v.size() - 1) / 2] != x) {       cntr++;       v.push_back(x);       sort(v.begin(), v.end());     }     cout << cntr;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   double DIS(T va, T vb) {     return sqrt((double)(va.x - vb.x) * (va.x - vb.x) +                 (va.y - vb.y) * (va.y - vb.y));   }   template <class T>   inline T INT_LEN(T v) {     int len = 1;     while (v /= 10) ++len;     return len;   }   char ar[100005], br[100005];   bool cmp(char va, char vb) { return va > vb; }   void solve(char *s, char *s2) {     int n = (int)strlen(s);     int m = (int)strlen(s2);     sort(s2, s2 + m, cmp);     int i, j;     for (i = j = 0; i < n && j < m; i++) {       if (s[i] < s2[j]) {         s[i] = s2[j];         j++;       }     }     puts(s);   }   int main(void) {     while (2 == scanf( %s%s , ar, br)) {       solve(ar, br);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans = 0;     cin >> n;     pair<int, int> arr[n];     for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second;     sort(arr, arr + n);     for (int i = 0; i < n; i++) {       if (arr[i].second >= ans) {         ans = arr[i].second;       } else {         ans = arr[i].first;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n - 1);     vector<int> b(n - 1);     for (auto &d : a) cin >> d;     for (auto &d : b) cin >> d;     for (int u = 0; u <= 3; ++u) {       vector<int> ans;       ans.push_back(u);       bool flagg = true;       for (int i = 0; i < n - 1; ++i) {         bool flag = false;         int t = -1;         for (int j = 0; j <= 3; ++j) {           if (((j & *ans.rbegin()) == b[i]) && ((j | *ans.rbegin()) == a[i])) {             flag = true;             t = j;             break;           }         }         if (!flag) {           flagg = false;           break;         }         ans.push_back(t);       }       if (flagg) {         cout <<  YES  << endl;         for (auto s : ans) cout << s <<    ;         return 0;       }     }     cout <<  NO ;   }
#include <bits/stdc++.h>   int modExp(long long a, long long n, int p) {     int ret = 1;     for (a = (a % p + p) % p; n; n >>= 1, a = 1LL * a * a % p)       if (n & 1) ret = 1LL * ret * a % p;     return ret;   }   int main() {     long long n, m;     scanf( %lld%lld , &n, &m);     printf( %lld n , (modExp(3, n, m) + m - 1) % m);   }
//naveen mall   #include<bits/stdc++.h>   using namespace std;   #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);   #define pb               push_back   #define sz(c)            (int)c.size()   #define len(c)           (int)c.length()   #define vec              vector   #define int              long long int   #define all(c)           c.begin(), c.end()   #define rall(c)          c.rbegin(), c.rend()   #define trav(a,i)        for(auto i: a)   #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))   #define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}   #define inset(s,n)        rep(i,0,n){int aset;cin>>aset;s.insert(aset);}   #define display(c)        trav(c,i) cout<<i<<   ;cout<<  n ;   #define F                 first   #define S                 second   #define pii               pair<int,int>   #define PB                pop_back   #define endl                n    #define what(x) cerr <<  #x <<   is   << x << endl;   int sum() { return 0; }template<typename T,typename... Args>T sum(T a, Args... args) { return a + sum(args...); }   #define kyra   1000000007   #define N 300003   const long long INF=1e18;   vector<int> v[26];   int n,k;   int a[N];   int temp[N];         bool good(int m)    {      rep(i,0,n)        {         if(a[i]>=m)             {               temp[i]=1;                }             else               temp[i]=-1;                if(i!=0)                temp[i]+=temp[i-1];        }        // for(int i=0;i<n;i++)        //    cout<<temp[i]<<   ;        int mi=INF;        rep(i,k-1,n)         {            mi=min(mi, temp[i-k]);            if(temp[i]-mi>0)              {               return true;              }                        }         return false;       }      void solve()   {             cin>>n>>k;      rep(i,0,n)        cin>>a[i];          int l=-1;       int r=N;          while(r>l+1)          {           int m=(l+r)/2;           if(good(m))              {               l=m;              }              else                r=m;          }   cout<<l<<endl;             }      signed main()   {fast           #ifdef NCR           init();      #endif           int t=1;     // cin>>t;            while(t--)        {         solve();        }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, k;     cin >> n >> k;     string A, B;     cin >> A >> B;     long long ret = 0;     long long ways = 1;     bool isinf = false;     for (auto i = (0); i != (n); ++i) {       if (!isinf) {         ways *= 2;         if (B[i] ==  a ) ways--;         if (A[i] ==  b ) ways--;       }       isinf |= ways > 1e11;       ret += isinf ? k : min(ways, k);     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int a[10];   map<string, int> mp;   map<int, string> p;   string s;   int main() {     int i, j, k;     int n, m;     for (i = 1; i <= 5; i++) cin >> a[i];     mp[ S ] = 1;     mp[ M ] = 2;     mp[ L ] = 3;     mp[ XL ] = 4;     mp[ XXL ] = 5;     p[1] =  S ;     p[2] =  M ;     p[3] =  L ;     p[4] =  XL ;     p[5] =  XXL ;     cin >> k;     for (i = 0; i < k; i++) {       cin >> s;       if (!a[mp[s]]) {         if (mp[s] == 3) {           if (a[4])             cout << p[4] << endl, a[4]--;           else if (a[2])             cout << p[2] << endl, a[2]--;           else if (a[5])             cout << p[5] << endl, a[5]--;           else if (a[1])             cout << p[1] << endl, a[1]--;           continue;         }         if (mp[s] == 2) {           if (a[3])             cout << p[3] << endl, a[3]--;           else if (a[1])             cout << p[1] << endl, a[1]--;           else if (a[4])             cout << p[4] << endl, a[4]--;           else if (a[5])             cout << p[5] << endl, a[5]--;           continue;         }         for (j = mp[s]; j <= 5; j++)           if (a[j]) {             cout << p[j] << endl, a[j]--;             break;           }         if (j > 5) {           for (j = mp[s]; j >= 1; j--)             if (a[j]) {               cout << p[j] << endl, a[j]--;               break;             }         }       } else         cout << s << endl, a[mp[s]]--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 10;   const int LCM = 840;   const int n = 8;   long long w;   long long cnt[MAXN], f[MAXN][MAXN * LCM];   int main() {     scanf( %lld , &w);     for (int i = 1; i <= n; i++) scanf( %lld , &cnt[i]);     memset(f, -1, sizeof(f));     f[0][0] = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j <= LCM * 8; j++) {         if (f[i][j] != -1) {           long long limit = min(cnt[i + 1], (long long)LCM / (i + 1));           for (int k = 0; k <= limit; k++)             f[i + 1][j + (i + 1) * k] =                 max(f[i + 1][j + (i + 1) * k],                     f[i][j] + (cnt[i + 1] - k) / (LCM / (i + 1)));         }       }     }     long long ans = 0;     for (int i = 0; i <= min((long long)LCM * 8, w); i++) {       if (f[8][i] != -1) ans = max(ans, min(f[8][i], (w - i) / LCM) * LCM + i);     }     printf( %lld n , ans);     return 0;   }