malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   inline bool mina(A &first, B second) {     return (first > second) ? (first = second, 1) : 0;   }   template <class A, class B>   inline bool maxa(A &first, B second) {     return (first < second) ? (first = second, 1) : 0;   }   const int MAXN = 150005;   int N;   int in[MAXN];   bool good(int a, int b) {     swap(in[a], in[b]);     bool bad = false;     for (int(i) = 0; (i) < (N - 1); ++(i)) {       if (i % 2 == 0) {         if (in[i] >= in[i + 1]) {           bad = true;           break;         }       } else {         if (in[i] <= in[i + 1]) {           bad = true;           break;         }       }     }     swap(in[a], in[b]);     return !bad;   }   bool check2(int p) {     if (p < 0 || p >= N) return true;     if (p % 2 == 0) {       if (p + 1 < N && in[p] >= in[p + 1]) return false;       if (p - 1 >= 0 && in[p] >= in[p - 1]) return false;     } else {       if (p + 1 < N && in[p] <= in[p + 1]) return false;       if (p - 1 >= 0 && in[p] <= in[p - 1]) return false;     }     return true;   }   bool check_local(int a, int b) {     swap(in[a], in[b]);     bool g1 = true;     for (int i = -1; i <= 1; i++) {       g1 &= check2(a + i);       g1 &= check2(b + i);     }     swap(in[a], in[b]);     return g1;   }   int main() {     scanf( %d , &N);     for (int(i) = 0; (i) < (N); ++(i)) {       scanf( %d , &in[i]);     }     set<int> bad;     int num_bad_local = 0;     int xx = -1;     for (int(i) = 0; (i) < (N - 1); ++(i)) {       if (i % 2 == 0) {         if (in[i] >= in[i + 1]) {           bad.insert(i);           bad.insert(i + 1);           num_bad_local++;           xx = i;           i++;         }       } else {         if (in[i] <= in[i + 1]) {           bad.insert(i);           bad.insert(i + 1);           num_bad_local++;           xx = i;           i++;         }       }     }     if (((int)(bad).size()) > 10) {       printf( 0 n );       return 0;     }     set<pair<int, int> > ans;     for (int first : bad) {       for (int second : bad) {         if (first < second) {           if (good(first, second)) {             ans.insert(pair<int, int>(first, second));           }         }       }     }     if (num_bad_local == 1) {       for (int(g) = 0; (g) < (N); ++(g)) {         if (g != xx && g != xx + 1) {           if (check_local(g, xx)) {             int a = g;             int b = xx;             if (a > b) swap(a, b);             ans.insert(pair<int, int>(a, b));           }           if (check_local(g, xx + 1)) {             int a = g;             int b = xx + 1;             if (a > b) swap(a, b);             ans.insert(pair<int, int>(a, b));           }         }       }     }     cout << ((int)(ans).size()) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9 + 7;   const double pi = 3.14159265358979323846;   template <class T>   T sqr(T x) {     return x * x;   }   double len(const pair<int, int> &p1, const pair<int, int> &p2) {     return sqrt(sqr((long long)p1.first - p2.first) +                 sqr((long long)p1.second - p2.second));   }   double foo(const vector<pair<int, int>> &pol, int l, int r, bool side) {     static vector<vector<vector<double>>> dp(         2, vector<vector<double>>(2500, vector<double>(2501, -1)));     if (r <= l + 1) return 0;     if (l > (int)pol.size() / 2)       return foo(pol, l - (pol.size() + 1) / 2, r - (pol.size() + 1) / 2, side);     if (dp[side][l][r - l] == -1)       if (side)         dp[side][l][r - l] =             max(len(pol[r - 1], pol[l]) + foo(pol, l, r - 1, 0),                 len(pol[r - 1], pol[r - 2]) + foo(pol, l, r - 1, 1));       else         dp[side][l][r - l] = max(len(pol[l], pol[l + 1]) + foo(pol, l + 1, r, 0),                                  len(pol[l], pol[r - 1]) + foo(pol, l + 1, r, 1));     return dp[side][l][r - l];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<pair<int, int>> pol(n);     for (auto &it : pol) cin >> it.first >> it.second;     for (int i = 0; i < n - 1; i++) pol.push_back(pol[i]);     double best = numeric_limits<double>::lowest();     for (int i = 0; i < n - 1; i++)       best = max(best, max(foo(pol, i, i + n, 0), foo(pol, i, i + n, 1)));     cout.precision(20);     cout << fixed << best << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 4;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     ;     cin >> s;     long long n = s.size();     long long sub = 0;     for (int k = 1; k <= 8; k++) {       for (int i = 0; i + k <= n; i++) {         bool flag = false;         for (int j = 1; 2 * j < k; j++) {           for (int st = i; st + 2 * j < i + k; st++) {             if (s[st] == s[st + j] && s[st] == s[st + 2 * j]) {               flag = true;             }           }         }         if (!flag) sub++;       }     }     cout << n * (n + 1) / 2 - sub <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3E4 + 7;   int x[N], y[N];   void solve() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     x[0] = a[0], y[0] = 0;     for (int i = 1; i < n; i++) {       x[i] = min(x[i - 1], a[i]), y[i] = a[i] - x[i];       if (y[i] >= y[i - 1]) continue;       y[i] = y[i - 1], x[i] = a[i] - y[i];       if (x[i] < 0) {         cout <<  NO n ;         return;       }     }     cout <<  YES n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   struct Tree {     int tl, tr;     int mx;   } tree[maxn << 2];   set<int> st[maxn];   int ve[maxn], n, m;   void build(int id, int l, int r) {     tree[id].tl = l;     tree[id].tr = r;     tree[id].mx = -1;     if (l == r) return;     int mid = (l + r) >> 1;     build(id << 1, l, mid);     build(id << 1 | 1, mid + 1, r);   }   void update(int id, int pos, int val, int y) {     int l = tree[id].tl, r = tree[id].tr;     if (l == r) {       if (st[pos].size())         tree[id].mx = *(--st[pos].end());       else         tree[id].mx = -1;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid)       update(id << 1, pos, val, y);     else       update(id << 1 | 1, pos, val, y);     tree[id].mx = max(tree[id << 1].mx, tree[id << 1 | 1].mx);   }   int query(int id, int ql, int qr, int y) {     int l = tree[id].tl, r = tree[id].tr;     if (tree[id].mx <= y || ql > qr) {       return -1;     }     int mid = (l + r) >> 1;     if (l == r) return l;     if (qr <= mid)       return query(id << 1, ql, qr, y);     else if (ql > mid)       return query(id << 1 | 1, ql, qr, y);     else {       int tmp = query(id << 1, ql, mid, y);       if (tmp != -1) return tmp;       return query(id << 1 | 1, mid + 1, qr, y);     }   }   struct Point {     int x, y;     char op[5];     void init() { scanf( %s%d%d , op, &x, &y); }   } q[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       q[i].init();       ve[i] = q[i].x;     }     sort(ve + 1, ve + 1 + n);     int m = unique(ve + 1, ve + 1 + n) - (ve + 1);     build(1, 1, m);     for (int i = 1; i <= n; i++) {       int pos = lower_bound(ve + 1, ve + 1 + m, q[i].x) - ve;       if (q[i].op[0] ==  a ) {         st[pos].insert(q[i].y);         update(1, pos, 1, q[i].y);       } else if (q[i].op[0] ==  r ) {         st[pos].erase(q[i].y);         update(1, pos, 1, q[i].y);       } else {         int ans = query(1, pos + 1, m, q[i].y);         if (ans == -1)           printf( -1 n );         else           printf( %d %d n , ve[ans], *st[ans].upper_bound(q[i].y));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, k;     cin >> n >> k;     string s[n + 1];     set<string> ar;     for (int x = 0; x < n; x++) {       cin >> s[x];       ar.insert(s[x]);     }     char a[3] = { S ,  E ,  T };     long long int ans = 0;     for (int x = 0; x < n; x++) {       for (int y = x + 1; y < n; y++) {         string d;         for (int z = 0; z < k; z++) {           if (s[x][z] == s[y][z]) {             d += s[x][z];           } else {             for (int i = 0; i < 3; i++) {               if (a[i] != s[x][z] && a[i] != s[y][z]) {                 d += a[i];                 break;               }             }           }         }         if (d.length() != 0)           if (ar.count(d)) ++ans;       }     }     cout << ans / 3 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }   long long power(long long a, long long n) {     long long p = 1;     while (n > 0) {       if (n & 1) {         p = p * a;       }       n >>= 1;       a *= a;     }     return p;   }   long long power(long long a, long long n, long long mod) {     long long p = 1;     while (n > 0) {       if (n & 1) {         p = p * a;         p %= mod;       }       n >>= 1;       a *= a;       a %= mod;     }     return p % mod;   }   const int N = 300005;   long long x[N];   long long d[N], a[N];   long long find(int i, int j) {     if (i == 0) return x[j];     return (x[j] - x[i - 1] + 1000000007) % 1000000007;   }   int main() {     int i, j;     int n;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %lld , &a[i]);     sort(a, a + n);     x[0] = 1;     for (i = 1; i < n; i++) {       d[i] = a[i] - a[i - 1];       x[i] = (power(2ll, i, 1000000007) + x[i - 1]) % 1000000007;     }     long long ans = 0;     for (i = 1; i < n; i++) {       ans += (d[i] * find(i - 1, n - 2)) % 1000000007;     }     long long z = ans;     for (i = 2; i < n; i++) {       z = (z - (d[i - 1] * x[n - i]) % 1000000007 + 1000000007) % 1000000007;       z = (z * power(2, 1000000007 - 2, 1000000007)) % 1000000007;       ans = (ans + z) % 1000000007;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x, y;   int n, m, k;   int main() {     cin >> n >> m >> k;     for (int i = 0; i < k; i++) {       cin >> x >> y;       if (x <= 5 || y <= 5 || n - x <= 4 || m - y <= 4) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:100000000 )   using namespace std;   const int N = 155;   const int INF = 1000000000;   struct Edge {     int to, flow, cap, cost;     Edge() {}     Edge(int to, int flow, int cap, int cost)         : to(to), flow(flow), cap(cap), cost(cost) {}   };   vector<Edge> g[N];   void add_edge(int from, int to, int cap, int cost) {     g[from].push_back(Edge(to, 0, cap, cost));     g[to].push_back(Edge(from, cap, cap, -cost));   }   int* count_letters(string s) {     int* a = new int[26];     memset(a, 0, 26 * sizeof(int));     for (int(i) = 0; (i) < ((int)(s).size()); (i)++) a[s[i] -  a ]++;     return a;   }   int d[N], p[N], id[N];   void find_flow(int src, int goal, int need) {     int flow = 0, n = goal + 1, cost = 0;     while (flow < need) {       for (int(i) = 0; (i) < (n); (i)++) d[i] = INF, p[i] = id[i] = -1;       d[src] = 0;       for (int(i) = 0; (i) < (n - 1); (i)++) {         for (int(a) = 0; (a) < (n); (a)++) {           for (int(j) = 0; (j) < ((int)(g[a]).size()); (j)++) {             int b = g[a][j].to;             if (g[a][j].flow < g[a][j].cap && d[b] > d[a] + g[a][j].cost) {               d[b] = d[a] + g[a][j].cost;               p[b] = a;               id[b] = j;             }           }         }       }       if (d[goal] == INF) {         puts( -1 );         return;       }       int push = INF, cur = goal;       while (cur != src) {         push = min(push, g[p[cur]][id[cur]].cap - g[p[cur]][id[cur]].flow);         cur = p[cur];       }       cur = goal;       flow += push;       while (cur != src) {         g[p[cur]][id[cur]].flow += push;         cost += push * g[p[cur]][id[cur]].cost;         for (int(i) = 0; (i) < ((int)(g[cur]).size()); (i)++) {           if (g[cur][i].to == p[cur]) {             g[cur][i].flow -= push;             break;           }         }         cur = p[cur];       }     }     printf( %d n , cost);   }   int main() {     string t;     cin >> t;     int* a = count_letters(t);     int n;     cin >> n;     for (int(i) = 0; (i) < (26); (i)++) add_edge(n + 1 + i, n + 27, a[i], 0);     for (int(i) = 0; (i) < (n); (i)++) {       string s;       int cap;       cin >> s >> cap;       int* b = count_letters(s);       add_edge(0, i + 1, cap, i + 1);       for (int(j) = 0; (j) < (26); (j)++) add_edge(i + 1, n + 1 + j, b[j], 0);     }     find_flow(0, n + 27, (int)(t).size());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, t, c, sum = 0;     cin >> t;     long long int a[t];     for (i = 0; i < t; i++) {       cin >> a[i];     }     for (i = 0; i < t; i++) {       sum += a[i];     }     if (sum % 2 == 0) {       cout << sum << endl;     } else {       long long int min = 1000000001;       for (i = 0; i < t; i++) {         if (a[i] <= min && a[i] % 2 != 0) {           min = a[i];         }       }       sum = sum - min;       cout << sum << endl;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, s[10001], ss[10001];     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &s[i]);     for (int i = 1; i < n; i++) {       ss[i] = abs(s[i] - s[i + 1]);     }     ss[n] = abs(s[n] - s[1]);     int t, min = 999999;     for (int i = 1; i <= n; i++) {       if (min > ss[i]) {         min = ss[i];         t = i;       }     }     if (t != n)       printf( %d %d n , t, t + 1);     else       printf( %d %d n , t, 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 132700;   int n;   tuple<int, int, int, int> esq[N], dir[N];   vector<tuple<int, int, int, int>> v;   int main(void) {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       int a, b, c, d;       cin >> a >> b >> c >> d;       v.emplace_back(a, b, c, d);     }     esq[0] = make_tuple(-0x3f3f3f3f, -0x3f3f3f3f, +0x3f3f3f3f, +0x3f3f3f3f);     for (int i = 1; i <= n; i++) {       int xb, yb, xu, yu;       tie(xb, yb, xu, yu) = v[i - 1];       get<0>(esq[i]) = max(get<0>(esq[i - 1]), xb);       get<1>(esq[i]) = max(get<1>(esq[i - 1]), yb);       get<2>(esq[i]) = min(get<2>(esq[i - 1]), xu);       get<3>(esq[i]) = min(get<3>(esq[i - 1]), yu);     }     dir[n + 1] = make_tuple(-0x3f3f3f3f, -0x3f3f3f3f, +0x3f3f3f3f, +0x3f3f3f3f);     for (int i = n; i >= 1; i--) {       int xb, yb, xu, yu;       tie(xb, yb, xu, yu) = v[i - 1];       get<0>(dir[i]) = max(get<0>(dir[i + 1]), xb);       get<1>(dir[i]) = max(get<1>(dir[i + 1]), yb);       get<2>(dir[i]) = min(get<2>(dir[i + 1]), xu);       get<3>(dir[i]) = min(get<3>(dir[i + 1]), yu);     }     for (int i = 1; i <= n; i++) {       int xb, yb, xu, yu;       xb = max(get<0>(esq[i - 1]), get<0>(dir[i + 1]));       yb = max(get<1>(esq[i - 1]), get<1>(dir[i + 1]));       xu = min(get<2>(esq[i - 1]), get<2>(dir[i + 1]));       yu = min(get<3>(esq[i - 1]), get<3>(dir[i + 1]));       if (xb <= xu and yb <= yu) {         cout << xb <<     << yb << endl;         return 0;       }     }     assert(0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[2010][2010];   int a[2010];   int p[2010];   bool used[2010];   bool ok[2010];   int main() {     int n;     cin >> n;     dp[0][0] = 1;     int rem = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] != -1) {         used[a[i] - 1] = true;         rem++;       } else         p[i] = i - rem + 1;     }     int cnt = 0;     for (int i = 0; i < n; i++)       if (used[i]) ok[p[i]] = true;     for (int i = 1; i <= n; i++) {       dp[i][0] = dp[i - 1][1] + dp[i - 1][0] * (i - 1);       if (ok[i]) dp[i][0] += dp[i - 1][0];       dp[i][0] %= 1000000007;       for (int j = 1; j <= i; j++) {         dp[i][j] = dp[i - 1][j + 1] * (j + 1) + dp[i - 1][j] * (i - 1 - j);         if (ok[i])           dp[i][j] += dp[i - 1][j];         else           dp[i][j] += dp[i - 1][j - 1];         dp[i][j] %= 1000000007;       }     }     long long ans = 0;     for (int j = 0; j <= cnt; j++) ans = (dp[n - rem][j] + ans) % 1000000007;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   void Q_Q() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);   }   map<int, bool> mp;   int main() {     Q_Q();     int n, k;     double t;     cin >> n >> k >> t;     int arr[n];     long long int sum = 0;     for (int i = 0; i < n; i++) {       arr[i] = k;       sum += k;     }     int j = n - 1;     while ((sum * 1.0 / ((n * k) * 1.0)) > t / 100) {       arr[j]--;       if (arr[j] == 0) j--;       sum--;     }     for (int i = 0; i < n; i++) cout << arr[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 2;   long long d, k, a, b, t;   int main() {     cin >> d >> k >> a >> b >> t;     if (d <= k) {       cout << d * a;     } else if (t + k * a > k * b) {       cout << k * a + (d - k) * b;     } else {       long long cnt = d / k;       long long ans =           k * a * cnt + (cnt - 1) * t + min(t + (d % k) * a, (d % k) * b);       cout << ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i;     scanf( %I64d , &n);     if (n <= 3) {       printf( 1 );       return 0;     }     if (n == 4) {       printf( 2 );       return 0;     }     if (n % 2 == 0)       printf( 2 );     else {       bool u = 1;       for (i = 2; i * i <= n; i++)         if (n % i == 0) {           u = 0;           break;         }       if (u)         printf( 1 );       else {         n = n - 2;         bool v = 1;         for (i = 2; i * i <= n; i++)           if (n % i == 0) {             v = 0;             break;           }         if (v)           printf( 2 );         else           printf( 3 );       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long inf = 4e18;   const long long N = 2e5 + 5;   long long ans[N];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long tt = 1;     while (tt--) {       long long n;       cin >> n;       long long l, r;       map<long long, long long> mp;       for (long long i = 0; i < n; ++i) {         cin >> l >> r;         ++mp[l];         --mp[r + 1];       }       long long cnt = 0;       l = -1;       for (auto it : mp) {         if (l == -1) {           l = it.first;           cnt += it.second;         } else {           ans[cnt] += (it.first - l);           l = it.first;           cnt += it.second;         }       }       for (long long i = 1; i <= n; ++i) cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int a[6] = {3, 3, 3, 2, 2, 1};   const int b[6] = {2, 1, 0, 1, 0, 0};   const int inf = 1000000000;   const double eps = 1e-6;   int Dist[6];   double X[7];   int Round(double X) {     int T = (int)X;     if (T + 1 - X < eps) T++;     return T;   }   bool Check(int Len) {     static double G[7][7], A[7];     memset(G, 0, sizeof(G));     for (int i = 0; i < 6; i++)       for (int j = 0; j < 7; j++) {         bool F0 = (j + 1) & (1 << a[i]);         bool F1 = (j + 1) & (1 << b[i]);         G[i][j] = F0 ^ F1;       }     for (int i = 0; i < 7; i++) G[6][i] = 1;     for (int i = 0; i < 6; i++) A[i] = Dist[i];     A[6] = Len;     for (int i = 0; i < 7; i++) {       if (!G[i][i]) {         int P = i + 1;         while (!G[P][i]) P++;         for (int j = i; j < 7; j++) swap(G[i][j], G[P][j]);         swap(A[i], A[P]);       }       for (int j = i + 1; j < 7; j++)         if (G[j][i]) {           double T = G[j][i] / G[i][i];           for (int k = i; k < 7; k++) G[j][k] -= G[i][k] * T;           A[j] -= A[i] * T;         }     }     for (int i = 6; i >= 0; i--) {       X[i] = A[i] / G[i][i];       for (int j = 0; j < i; j++) A[j] -= X[i] * G[j][i];     }     for (int i = 0; i < 7; i++)       if (fabs(X[i] - Round(X[i])) > eps || X[i] < -eps) return false;     return true;   }   int main() {     for (int i = 0; i < 6; i++) scanf( %d , &Dist[i]);     int Ans = -1, Sum = 0;     for (int i = 0; i < 6; i++) Sum += Dist[i];     for (int i = Sum / 4; Ans == -1 && i <= Sum / 3; i++)       if (Check(i)) Ans = i;     printf( %d n , Ans);     if (Ans == -1) return 0;     string S[4];     for (int i = 0; i < 7; i++) {       int M = Round(X[i]);       for (int j = 0; j < M; j++) {         S[0] +=  a ;         for (int k = 1; k < 4; k++)           S[k] += ((i + 1) & (1 << (3 - k))) ?  b  :  a ;       }     }     for (int i = 0; i < 4; i++) cout << S[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MO = 1e9 + 7;   int n, K;   long long dp[105][44], tt[44];   vector<int> e[105];   void add(long long &x, long long y) { x = (x + y) % MO; }   void mul(long long &x, long long y) { x = x * y % MO; }   void dfs(int u, int f) {     dp[u][K + 1] = 1;     dp[u][0] = 1;     for (auto v : e[u])       if (v != f) {         dfs(v, u);         for (int i = 0; i <= 2 * K; ++i)           for (int j = 0; j <= 2 * K; ++j)             add(tt[i + j <= 2 * K ? min(i, j + 1) : max(i, j + 1)],                 dp[u][i] * dp[v][j]);         memcpy(dp[u], tt, sizeof tt);         memset(tt, 0, sizeof tt);       }   }   int main() {     cin >> n >> K;     for (int i = 1, x, y; i < n; ++i) {       cin >> x >> y;       e[x].push_back(y);       e[y].push_back(x);     }     dfs(1, 0);     long long ans = 0;     for (int i = 0; i <= K; ++i) add(ans, dp[1][i]);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, val[105], c[105][105], pref[105][105], calc[105][105],       dp[105][10005];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (long long i = 1; i <= n; ++i) {       cin >> val[i];       for (long long j = 1; j <= val[i]; ++j)         cin >> c[i][j], pref[i][j] = pref[i][j - 1] + c[i][j];     }     for (long long i = 1; i <= n; ++i)       for (long long j = 1; j <= min(m, val[i]); ++j)         for (long long k = 0; k <= j; ++k)           calc[i][j] = max(calc[i][j], pref[i][k] + pref[i][val[i]] -                                            pref[i][val[i] - (j - k)]);     long long tot = 0;     for (long long i = 1; i <= n; ++i) {       tot += val[i];       for (long long j = 1; j <= min(tot, m); ++j) {         for (long long k = 0; k <= min(j, val[i]); ++k) {           dp[i][j] = max(dp[i][j], dp[i - 1][j - k] + calc[i][k]);         }       }     }     cout << dp[n][m] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t[90];     bool ans = false;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> t[i];     }     if (t[0] > 15) {       cout << 15;       ans = true;     }     for (int i = 0; i < n - 1 && ans == false; i++) {       t[i] += 15;       if (t[i] < t[i + 1]) {         cout << t[i];         ans = true;       }     }     t[n - 1] += 15;     if (t[n - 1] >= 90 && ans == false) {       cout << 90;     }     if (t[n - 1] < 90 && ans == false) {       cout << t[n - 1];     }   }