malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int inf = 0x3f3f3f3f;   const int mod = 998244353;   using ll = long long;   using vi = vector<int>;   using pii = pair<int, int>;   inline int read() {     int x = 0, f = 1, c = getchar();     for (; !isdigit(c); c = getchar())       if (c == 45) f ^= 1;     for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;     return f ? x : -x;   }   int qp(int x, int n) {     return !n ? 1 : 1LL * qp(1LL * x * x % mod, n >> 1) * (n & 1 ? x : 1) % mod;   }   int inv(int x) { return qp(x, mod - 2); }   int n, m;   int a[55], w[55];   int dp[55][55][55][55];   int main() {     n = read(), m = read();     for (int i = 0; i < (int)(n); ++i) a[i] = read();     int sum = 0, like = 0;     for (int i = 0; i < (int)(n); ++i)       w[i] = read(), sum += w[i], like += w[i] * a[i];     for (int i = 0; i < (int)(n); ++i) dp[0][0][i][0] = 1;     for (int i = 0; i < (int)(m); ++i)       for (int j = 0; j < (int)(i + 1); ++j) {         int nwsum = sum + j - (i - j);         int invnwsum = inv(nwsum);         for (int k = 0; k < (int)(n); ++k)           for (int l = 0; l < (int)(i + 1); ++l) {             if (!dp[i][j][k][l]) continue;             int nwlike = like + j;             for (int sel = 0; sel < (int)(2); ++sel) {               int nj = j + sel;               int ful = sel ? nwlike : nwsum - nwlike;               int nwk = l * (a[k] ? 1 : -1) + w[k];               if (nwk <= 0) continue;               if (sel == a[k]) ful -= nwk;               (dp[i + 1][nj][k][l] +=                1LL * dp[i][j][k][l] * ful % mod * invnwsum % mod) %= mod;               if (sel == a[k])                 (dp[i + 1][nj][k][l + 1] +=                  1LL * dp[i][j][k][l] * nwk % mod * invnwsum % mod) %= mod;             }           }       }     for (int i = 0; i < (int)(n); ++i) {       int ans = 0;       for (int j = 0; j < (int)(m + 1); ++j)         for (int l = 0; l < (int)(m + 1); ++l) {           (ans += 1LL * (l * (a[i] ? 1 : -1) + w[i]) * dp[m][j][i][l] % mod) %=               mod;         }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int d[(1 << 17) + 20][100], par[(1 << 17) + 20][100];   int prime[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};   int sum[70], a[100];   int ret, temp;   int ans = 10000000;   void pre() {     for (int i = 1; i < 59; i++) {       for (int j = 0; j < 17; j++) {         if (prime[j] > 1 && i % prime[j] == 0) sum[i] += (1 << j);       }     }   }   void pp(int mask, int ind) {     if (ind > 0) pp(mask - sum[par[mask][ind]], ind - 1);     cout << par[mask][ind] <<    ;     return;   }   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     pre();     for (int mask = 0; mask < (1 << 17); mask++) {       ret = ans;       for (int val = 1; val < 59; val++) {         temp = ret;         if ((sum[val] & mask) == sum[val]) ret = min(ret, abs(val - a[0]));         if (temp > ret) par[mask][0] = val;       }       d[mask][0] = ret;     }     for (int mask = 0; mask < (1 << 17); mask++) {       for (int ind = 0; ind < n; ind++) {         ret = ans;         for (int val = 1; val < 59; val++) {           temp = ret;           if ((sum[val] & mask) == sum[val])             ret = min(d[mask - sum[val]][ind - 1] + abs(val - a[ind]), ret);           if (temp > ret) {             par[mask][ind] = val;           }         }         d[mask][ind] = ret;       }     }     pp((1 << 17) - 1, n - 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 1, i, j = 0;     string s, t;     getline(cin, s);     getline(cin, t);     for (i = 0; i < t.length(); i++) {       if (s[j] == t[i]) {         n++;         j++;       }     }     cout << n;   }
#include <bits/stdc++.h>   using namespace std;   int n, ma, a1;   long long ans;   char ch;   struct point {     int a, b;   } s[1000005];   struct node {     int l, r;     long long add, sum, ma;     node *ch[2];   } * nil, *root;   long long gets() {     long long v = 0;     bool f = 0;     char ch;     while (!isdigit(ch)) {       f |= ch ==  - ;       ch = getchar();     }     while (isdigit(ch)) {       v = (v << 3) + (v << 1) + ch - 48;       ch = getchar();     }     return f ? -v : v;   }   void init() {     nil = new node();     nil->ch[0] = nil->ch[1] = nil;     nil->add = nil->ma = nil->sum = 0;   }   void pushup(node *x) {     x->ma = max(x->ch[0]->ma + x->ch[1]->sum, x->ch[1]->ma);     x->sum = x->ch[0]->sum + x->ch[1]->sum;   }   void build(node *&x, int l, int r) {     x = new node();     x->l = l, x->r = r;     x->ma = x->sum = 0;     if (l == r) {       x->ma = x->l;       return;     }     int mid = l + r >> 1;     build(x->ch[0], l, mid);     build(x->ch[1], mid + 1, r);     pushup(x);   }   void insert(node *x, int pos, long long v) {     if (x->r == x->l && x->r == pos) {       x->ma += v, x->sum += v;       return;     }     int mid = x->l + x->r >> 1;     if (pos <= mid)       insert(x->ch[0], pos, v);     else       insert(x->ch[1], pos, v);     pushup(x);   }   void ask(node *x, int l, int r) {     if (l == x->l && r == x->r) {       ans = max(ans + x->sum, x->ma);       return;     }     int mid = x->l + x->r >> 1;     if (r <= mid)       ask(x->ch[0], l, r);     else if (l > mid)       ask(x->ch[1], l, r);     else       ask(x->ch[0], l, mid), ask(x->ch[1], mid + 1, r);   }   int main() {     n = gets();     ma = 1000000;     init();     build(root, 1, ma);     for (int i = 1; i <= n; i++) {       scanf( %c , &ch);       if (ch ==  ? ) {         a1 = gets();         ans = 0;         ask(root, 1, a1);         ans -= a1;         printf( %I64d n , ans);       }       if (ch ==  + ) {         s[i].a = gets(), s[i].b = gets();         insert(root, s[i].a, s[i].b);       }       if (ch ==  - ) {         a1 = gets();         insert(root, s[a1].a, -s[a1].b);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     n--;     k--;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     int count = 0;     int flag = 0;     while (count <= k) {       if (count == k) {         flag = 1;         break;       }       count += arr[count];     }     if (flag == 1)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int team1, team2;     std::string s;     std::cin >> s;     team1 = s.find( 1111111 );     team2 = s.find( 0000000 );     if (team1 >= 0 || team2 >= 0) {       std::cout <<  YES ;     } else       std::cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   const int M = 1 << 18;   int n, m;   string s;   set<int> S[256];   int sub[2 * M];   void insert(int a) {     a += M - 1;     while (a) {       --sub[a];       a /= 2;     }   }   int kth(int k, int v = 1, int l = 1, int r = M) {     if (l == r) return l;     if (sub[2 * v] >= k)       return kth(k, 2 * v, l, (l + r) / 2);     else       return kth(k - sub[2 * v], 2 * v + 1, (l + r) / 2 + 1, r);   }   void build(int v = 1, int l = 1, int r = M) {     sub[v] = r - l + 1;     if (l == r) return;     build(2 * v, l, (l + r) / 2);     build(2 * v + 1, (l + r) / 2 + 1, r);   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> m >> s;     s =  #  + s;     for (int i = 1; i <= n; ++i) {       S[s[i]].insert(i);     }     build();     while (m--) {       int l, r;       char c;       cin >> l >> r >> c;       l = kth(l);       r = kth(r);       auto it = S[c].lower_bound(l);       while (it != S[c].end() && *it <= r) {         insert(*it);         S[c].erase(it);         it = S[c].lower_bound(l);       }     }     for (int i = 1; i <= n; ++i) {       if (S[s[i]].find(i) != S[s[i]].end()) cout << s[i];     }     cout <<   n ;   }
#include <bits/stdc++.h>   int main() {     char a[100009], c;     int j = 0, i;     while ((c = getchar()) !=   n ) {       if (j == 0) {         a[j] = c;         j++;       } else {         if (a[j - 1] == c) {           j--;         } else {           a[j] = c;           j++;         }       }     }     if (j == 0) {       printf( Yes n );     } else {       printf( No n );     }   }
#include <bits/stdc++.h>   using namespace std;   int ans = 123422412;   int n, a, b, x, y;   void dfs(int r, int x, int y, int ret) {     if (x < 0 || y < 0) return;     if (r < 0) return;     if (x == 0 && y == 0) {       ans = min(ans, ret);       return;     }     dfs(r - a, x - 1, y, ret);     dfs(n - a, x - 1, y, ret + 1);     dfs(r - b, x, y - 1, ret);     dfs(n - b, x, y - 1, ret + 1);   }   int main() {     cin >> n >> a >> b;     dfs(n, 4, 2, 1);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005;   const int mod = 1e9 + 7;   struct Node {     int x, y, z;     Node() {}     Node(int _x, int _y, int _z) {       x = _x;       y = _y;       z = _z;       if (x < y) swap(x, y);       if (x < z) swap(x, z);       if (y < z) swap(y, z);     }     bool operator<(const Node& a) const {       if (x != a.x) return x < a.x;       if (y != a.y) return y < a.y;       return z < a.z;     }   };   Node a[10];   int A, B, C;   set<pair<int, int> > s;   set<pair<int, int> >::iterator it;   int v[MAXN];   int vis[MAXN];   int n;   void solve() {     s.clear();     memset(vis, 0, sizeof vis);     scanf( %d%d%d , &A, &B, &C);     for (int i = 1; i <= n; ++i) {       scanf( %d , &v[i]);     }     sort(v + 1, v + n + 1);     for (int i = 1; i <= n; ++i) {       s.insert(make_pair(v[i], i));     }     a[0] = Node(A, B, C);     a[1] = Node(A + B, C, 0);     a[2] = Node(A + C, B, 0);     a[3] = Node(B + C, A, 0);     a[4] = Node(A + B + C, 0, 0);     sort(a, a + 5);     int ans = 0;     for (int i = n; i >= 1; --i)       if (!vis[i]) {         int ok = 0;         ++ans;         for (int j = 0; j < 5; ++j) {           if (a[j].x >= v[i]) {             ok = 1;             vis[i] = 1;             s.erase(make_pair(v[i], i));             int t = 0;             if (s.begin() == s.end()) break;             it = s.lower_bound(make_pair(a[j].y, 0x3f3f3f3f));             if (it != s.begin()) {               --it;               vis[it->second] = 1;               s.erase(*it);               ++t;             }             if (s.begin() == s.end()) break;             it = s.lower_bound(make_pair(a[j].z, 0x3f3f3f3f));             if (it != s.begin()) {               --it;               vis[it->second] = 1;               s.erase(*it);               ++t;             }             if (t == 0) {               it = s.lower_bound(make_pair(a[j].y + a[j].z, 0x3f3f3f3f));               if (it != s.begin()) {                 --it;                 vis[it->second] = 1;                 s.erase(*it);                 ++t;               }             }             break;           }         }         if (!ok) {           printf( -1 n );           return;         }       }     printf( %d n , ans);   }   int main() {     while (~scanf( %d , &n)) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n, p, w, d;     cin >> n >> p >> w >> d;     bool been[int(1e5)] = {}, can = 0;     long long cnt = p / w, dif = 0;     while (cnt >= 0) {       dif = p - cnt * w;       if (been[dif % d]) break;       if (dif % d == 0) {         if (cnt + dif / d <= n) {           can = 1;           break;         }       }       been[dif % d] = 1;       cnt--;     }     if (can)       cout << cnt <<     << dif / d <<     << n - cnt - dif / d <<   n ;     else       cout <<  -1 n ;     return 0;   }
#include<bits/stdc++.h>   #define maxn 20010   using namespace std;      int n, m, a[maxn];   int lg[maxn], mx[maxn][21], f[maxn][35][21], s[35], t[35];   int mxx(int x,int y){return x+a[x]>y+a[y]?x:y;}   int qry(int x,int y){return mxx(mx[x][lg[y-x+1]],mx[y-(1<<lg[y-x+1])+1][lg[y-x+1]]);}       int main()   {    lg[0]=-1;    scanf( %d%d ,&n,&m);    for(int i=1;i<=n;i++) scanf( %d ,&a[i]),lg[i]=lg[i>>1]+1,mx[i][0]=i;    for(int j=1;j<=14;j++) for(int i=1;i<=n-(1<<j)+1;i++) mx[i][j]=mxx(mx[i][j-1],mx[i+(1<<(j-1))][j-1]);    for(int i=1;i<=n;i++) for(int j=0;j<31;j++) f[i][j][0]=min(n,i+a[i]+j);    for(int j=1;j<15;j++) for(int i=1;i<=n;i++) for(int x=0;x<31;x++) for(int y=0;x+y<31;y++) f[i][x+y][j]=max(f[i][x+y][j],f[qry(i,f[i][x][j-1])][y][j-1]);    while(m--)    {     int l,r,k;     scanf( %d%d%d ,&l,&r,&k);     if(l==r){puts( 0 );continue;}     for(int i=0;i<=k;i++) s[i]=t[i]=l;     int ans=0;     for(int j=14;j>=0;j--)     {      for(int i=0;i<=k;i++) t[i]=s[i];      for(int x=0;x<=k;x++) for(int y=0;x+y<=k;y++) t[x+y]=std::max(t[x+y],f[qry(l,s[x])][y][j]);      bool flg=0;      for(int i=0;i<=k;i++) if(t[i]>=r) flg=1;      if(flg) continue;      ans+=(1<<j);      for(int i=0;i<=k;i++) s[i]=t[i];     }     printf( %d n ,ans+1);    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100001];   long long b[100001];   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     map<int, int> cnt;     vector<int> q;     int loc = 0;     for (int i = n - 1; i >= 0; i--) {       cnt[a[i]]++;       if (cnt[a[i]] == 1) loc++;       b[i] = loc;     }     cnt.clear();     long long ans = 0;     for (int i = 0; i < n - 1; i++) {       cnt[a[i]]++;       if (cnt[a[i]] == 1) ans += b[i + 1];     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cal(int a, int b, int ba) {     int x[100], xl, y[100], yl, i, z[100];     memset(x, 0, sizeof x);     memset(y, 0, sizeof y);     memset(z, 0, sizeof z);     xl = yl = 0;     while (a > 0) {       x[xl++] = a % 10;       a /= 10;     }     while (b > 0) {       y[yl++] = b % 10;       b /= 10;     }     for (i = 0; i < max(xl, yl); i++) {       z[i] += x[i] + y[i];       if (z[i] >= ba) {         z[i + 1] += z[i] / ba;         z[i] %= ba;       }     }     i = max(xl, yl) + 10;     while (z[i] == 0) i--;     return i + 1;   }   int main() {     int a, b, i, t, m, ans;     while (scanf( %d %d , &a, &b) != EOF) {       m = 0;       t = a;       while (t > 0) {         if (t % 10 > m) m = t % 10;         t /= 10;       }       t = b;       while (t > 0) {         if (t % 10 > m) m = t % 10;         t /= 10;       }       ans = 0;       for (i = m + 1; i <= 1000; i++) {         t = cal(a, b, i);         if (t > ans) ans = t;       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 50;   const long long oo = 1e18;   const long long mod = 1e9 + 7;   int a[N], sum[2 * N];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     int cur = n;     long long ans = 0;     sum[cur] = 1;     long long q = 0;     for (int i = 0; i < n; i++) {       if (a[i] < m) {         cur--;         q -= sum[cur];       } else {         q += sum[cur];         cur++;       }       ans += q;       sum[cur]++;     }     memset(sum, 0, sizeof(sum));     cur = n;     sum[cur] = 1;     q = 0;     for (int i = 0; i < n; i++) {       if (a[i] < m + 1) {         cur--;         q -= sum[cur];       } else {         q += sum[cur];         cur++;       }       ans -= q;       sum[cur]++;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   int arr[300009], b[300009];   vector<pair<int, int> > adj[300009], query[300009];   const int N = 500;   long long ans[300009], par[300009];   int main() {     int n, q, k;     scanf( %d%d%d , &n, &q, &k);     deque<pair<int, int> > deq;     for (int i = 1; i <= n; i++) {       scanf( %d , arr + i);       while (!deq.empty() and deq.back().first >= arr[i]) deq.pop_back();       while (!deq.empty() and i - deq.front().second > k) deq.pop_front();       deq.push_back(make_pair(arr[i], i));       b[i] = deq.front().first;     }     for (int i = 1; i <= n; i++) adj[i % k].push_back(make_pair(i, b[i]));     if (k > N) {       while (q--) {         int l, r;         scanf( %d%d , &l, &r);         int mn = 1000000007;         long long res = arr[l];         int pos = upper_bound(adj[l % k].begin(), adj[l % k].end(),                               make_pair(l, 1000000007)) -                   adj[l % k].begin();         while (pos < (int)adj[l % k].size() and adj[l % k][pos].first <= r)           umin(mn, adj[l % k][pos++].second), res += mn;         printf( %lld n , res);       }       return 0;     }     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d%d , &l, &r);       query[l].push_back(make_pair(r, i));       ans[i] = arr[l];     }     for (int i = 0; i < k; i++) {       memset(par, 0, sizeof par);       int sz = adj[i].size();       vector<pair<int, int> > v;       for (int j = sz - 1; j >= 0; j--) {         int l = adj[i][j].first, val = adj[i][j].second;         if (!v.empty()) {           for (int h = 0; h < int(query[l].size()); h++) {             int r = query[l][h].first;             int idx = query[l][h].second;             int R = upper_bound(adj[i].begin(), adj[i].end(),                                 make_pair(r, 1000000007)) -                     adj[i].begin();             int st = 0, en = v.size() - 1;             while (st + 1 < en) {               int mid = (st + en) >> 1;               if (v[mid].second < R)                 en = mid;               else                 st = mid;             }             if (v[st].second < R) en = st;             int who = v[en].second;             int me = v[en].first;             if (who < R)               ans[idx] += par[v.back().second] - par[who] + (R - who) * 1LL * me;           }         }         while (!v.empty() and v.back().first >= val) v.pop_back();         if (!v.empty()) {           int next_ind = v.back().second;           par[j] = par[next_ind] + (next_ind - j) * 1LL * val;         }         v.push_back(make_pair(val, j));       }     }     for (int i = 1; i <= q; i++) printf( %lld n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   int main() {     int n, k, sol = 0;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     sort(a.begin(), a.end());     int maxB = (a[n - 1] - a[0]) / (k - 1);     vector<int> ble(maxB + 2);     vector<vector<int>> b(n + 1);     for (int i = 1; i <= maxB; i++) {       b[0] = vector<int>(k + 1);       b[0][0] = 1;       int p = 0;       for (int j = 1; j <= n; j++) {         while (a[p] <= a[j - 1] - i) p++;         b[j] = b[j - 1];         for (int l = 0; l < k; l++) {           b[j][l + 1] = (b[j][l + 1] + b[p][l]) % mod;           if (b[j][l + 1] == 0) break;         }       }       ble[i] = b[n][k];     }     for (int i = 0; i <= maxB; i++)       sol = (sol + i * (long long)(ble[i] - ble[i + 1]) + mod) % mod;     cout << sol << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ans;   long long arr[300005][8];   long long a, b;   bool ok(long long mid, long long n, long long m) {     long long mx = (1LL << m) - 1;     long long cnt[mx + 1];     for (int i = 0; i <= mx; i++) cnt[i] = 0;     for (int i = 0; i < n; i++) {       long long tem = 0;       for (int j = 0; j < m; j++) {         if (arr[i][j] >= mid) {           tem = tem | (1LL << j);         }       }       cnt[tem] = i + 1;     }     for (int i = 0; i <= mx; i++) {       for (int j = i; j <= mx; j++) {         if (cnt[i] && cnt[j]) {           long long tem = i | j;           if (tem == mx) {             a = cnt[i];             b = cnt[j];             return true;           }         }       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     ;     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cin >> arr[i][j];     }     long long lo = 0;     long long hi = 1e9;     a = 1;     b = 1;     while (lo <= hi) {       long long mid = (lo + hi) / 2;       if (ok(mid, n, m)) {         ans = mid;         lo = mid + 1;       } else {         hi = mid - 1;       }     }     cout << a <<     << b << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long best;   int n, m, k;   int main() {     cin >> n >> m >> k;     if (k > n + m - 2)       cout << -1 << endl;     else {       for (int area = 1; area <= (int)sqrt(n); area++) {         int x = n / area;         if (n / x == area) {           int cut = min(k, x - 1);           int remainCut = k - cut;           if (remainCut + 1 != 0)             best = max(best, (long long)area * (long long)(m / (remainCut + 1)));         }         int _area = n / area;         x = n / _area;         if (n / x == _area) {           int cut = min(k, x - 1);           int remainCut = k - cut;           if (remainCut + 1 != 0)             best = max(best, (long long)_area * (long long)(m / (remainCut + 1)));         }       }       cout << best << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   long long dyn[5001][5001];   int A[300000];   int main() {     int n, k;     scanf( %d , &(n));     scanf( %d , &(k));     for (int(i) = 0; (i) < n; (i)++) scanf( %d , &(A[i]));     sort(A, A + n);     int rem = n % k;     int q = n / k;     for (int i = 0; i <= k; i++) {       if (i == 0) {         dyn[0][0] = 0;         dyn[0][1] = -1;         continue;       }       int j = min(i, rem);       for (int t = 0; t <= j; t++) {         dyn[i][t] = 2000000000;         if (t > 0) {           dyn[i][t] = min(dyn[i][t], dyn[i - 1][t - 1] + A[i * q + t - 1] -                                          A[(i - 1) * q + t - 1]);         }         if (dyn[i - 1][t] != -1) {           dyn[i][t] = min(dyn[i][t],                           dyn[i - 1][t] + A[i * q + t - 1] - A[(i - 1) * q + t]);         }       }       dyn[i][j + 1] = -1;     }     printf( %I64d , dyn[k][rem]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int MAX = 1e9 + 5;   long long i, j, k, n, m, RIGHT[N], LEFT[N], ans, a[N];   long long _RIGHT[N], _LEFT[N];   int main() {     scanf( %lld , &n);     for (int i = 1; i <= n - 1; i++) scanf( %lld , &a[i]);     for (int i = n; i >= 1; i--) {       if (a[i] != 1) RIGHT[i] = RIGHT[i + 1] + a[i] - (a[i] & 1);       _RIGHT[i] = max(RIGHT[i + 1], _RIGHT[i + 1]) + a[i] - (!(a[i] & 1));     }     for (int i = 1; i <= n; i++) {       if (a[i - 1] != 1) LEFT[i] = LEFT[i - 1] + a[i - 1] - (a[i - 1] & 1);       _LEFT[i] = max((a[i] != 1) * LEFT[i - 1], (_LEFT[i - 1])) + a[i - 1] -                  (!(a[i - 1] & 1));     }     for (int i = 1; i <= n; i++) {       ans = max(ans, max(_LEFT[i], LEFT[i]) + RIGHT[i]);       ans = max(ans, max(_RIGHT[i], RIGHT[i]) + LEFT[i]);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, c0, d0;     cin >> n >> m >> c0 >> d0;     long long a[m + 4], b[m + 5], c[m + 5], d[m + 5];     for (int i = 1; i <= m; i++) {       cin >> a[i] >> b[i] >> c[i] >> d[i];       a[i] /= b[i];     }     c[0] = c0;     a[0] = 1005;     long long dp[n + 4][m + 4];     memset(dp, 0, sizeof(dp));     for (long long i = 1; i <= n; i++) {       for (long long j = 0; j <= m; j++) {         for (long long k = 0; k <= a[j]; k++) {           if (i - c[j] * k < 0) break;           if (j == 0) {             dp[i][j] = k * d0;           } else {             dp[i][j] = max(dp[i - c[j] * k][j - 1] + k * d[j], dp[i][j]);           }         }       }     }     cout << dp[n][m] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int mohin, a, b, c;     cin >> a >> b >> c;     mohin = 0;     for (int i = 1; i <= c; i++) {       mohin += 2 * ((a - 4 * (i - 1)) + (b - 4 * (i - 1))) - 4;     }     cout << mohin << endl;     return 0;   }