malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 42;   int n, m;   char s[N];   long long dp[N][N][2], nex[N];   void kmp_init() {     int j = 0;     nex[1] = 0;     nex[0] = -1;     for (int i = 1; i < n; i++) {       while (j >= 0 && s[i + 1] != s[j + 1]) j = nex[j];       if (j == -1 || s[i + 1] == s[j + 1]) j++;       nex[i + 1] = j;     }   }   int getNex(int pos, int val) {     if (pos == 0) return val == s[1] -  0  ? 1 : 0;     if (s[pos + 1] ==  0  + val) return pos + 1;     return getNex(nex[pos], val);   }   long long dfs(int pre, int now, int matched_len, int isok) {     if (now == m + 1) {       return matched_len == pre && isok;     }     if (dp[now][matched_len][isok] != -1) return dp[now][matched_len][isok];     long long ans = 0;     ans += dfs(pre, now + 1, getNex(matched_len, 0),                isok | (getNex(matched_len, 0) == n));     ans += dfs(pre, now + 1, getNex(matched_len, 1),                isok | (getNex(matched_len, 1) == n));     return dp[now][matched_len][isok] = ans;   }   int main() {     scanf( %d %s , &m, s + 1);     n = strlen(s + 1);     kmp_init();     long long ans = 0;     for (int i = 0; i <= n; i++) {       memset(dp, -1, sizeof(dp));       ans += dfs(i, 1, i, 0);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 100;   int n, p, k;   int dp[2][maxn][55][55];   int maks[2][2][maxn][55];   int tmaks[2][maxn];   int question[2][maxn];   int main() {     scanf( %d %d %d , &n, &p, &k);     int cnt, x;     int res = 0;     for (int i = 0; i < 2; ++i) {       scanf( %d , &cnt);       while (cnt--) {         scanf( %d , &x);         question[i][x] = 1;       }     }     if (p > 2 * ceil(n / k)) {       for (int i = 1; i <= n; ++i) res += (question[0][i] || question[1][i]);       cout << res << endl;       return 0;     }     int now = 0;     memset(dp, 0xc0, sizeof dp);     memset(maks, 0xc0, sizeof maks);     memset(tmaks, 0xc0, sizeof tmaks);     maks[1][0][0][0] = maks[1][1][0][0] = tmaks[1][0] = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= p; ++j) {         tmaks[now][j] = -0x3f3f3f3f;         for (int r = 0; r <= k; ++r) {           maks[now][0][j][r] = maks[now][1][j][r] = -0x3f3f3f3f;           for (int r1 = 0; r1 <= k; ++r1) dp[now][j][r][r1] = -0x3f3f3f3f;         }       }       for (int j = 0; j <= p; ++j) {         for (int r1 = 0; r1 <= k; ++r1) {           for (int r2 = 0; r2 <= k; ++r2) {             int &cur = dp[now][j][r1][r2];             if (r1 > 1 && r2 > 1 && j >= 2)               cur = max(cur, dp[!now][j][r1 - 1][r2 - 1] +                                  (question[0][i] || question[1][i]));             if ((r1 == 0 || r1 == 1) && j >= r1 && !(r2 == 0 || r2 == 1))               cur = max(cur, maks[!now][0][j - r1][r2 - 1] +                                  (question[1][i] || (question[0][i] && r1)));             if ((r2 == 0 || r2 == 1) && j >= r2 && !(r1 == 0 || r1 == 1))               cur = max(cur, maks[!now][1][j - r2][r1 - 1] +                                  ((question[1][i] && r2) || question[0][i]));             if ((r1 == 0 || r1 == 1) && (r2 == 0 || r2 == 1) && j >= r1 + r2)               cur = max(cur, tmaks[!now][j - r1 - r2] + ((question[0][i] && r1) ||                                                          (question[1][i] && r2)));             tmaks[now][j] = max(tmaks[now][j], cur);             maks[now][0][j][r2] = max(maks[now][0][j][r2], cur);             maks[now][1][j][r1] = max(maks[now][1][j][r1], cur);             res = max(res, cur);           }         }       }       now = !now;     }     printf( %d n , res);   }
#include <bits/stdc++.h>   using namespace std;   typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;   const int INF = INT_MAX;   const long long LINF = LLONG_MAX;   const int MOD = 1000000000 + 7;   const double EPS = 1e-9;   const double PI = acos(-1);   const int di[]{0, -1, 0, 1, -1, -1, 1, 1};   const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     long long n, m;     cin >> n;     vector<long long> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     cin >> m;     vector<long long> q(m);     for (int i = 0; i < m; ++i) {       cin >> q[i];     }     vector<long long> sum(n + 1, 0);     for (int i = 0; i < n; ++i) {       sum[i + 1] = sum[i] + a[i];     }     sort((a).begin(), (a).end(), greater<long long>());     for (int i = 0; i < m; ++i) {       long long ans = sum[n] - a[q[i] - 1];       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e18 + 7;   const long long N = 2e6 + 5;   int main() {     long long i, j, k, l = 0;     long long n, m, t;     cin >> n;     for (long long i = 0; i < n; i++) cin >> k, l += k;     if (l % n)       cout << n - 1 << endl;     else       cout << n << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int num[100005];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &num[i]);     }     sort(num, num + n);     if (n < k) {       printf( %d n , num[n - 1]);       return 0;     } else {       vector<int> ans;       for (int i = 0; i < n - k; i++) {         ans.push_back(num[i] + num[2 * n - 2 * k - 1 - i]);       }       for (int i = 2 * n - 2 * k; i < n; i++) ans.push_back(num[i]);       sort(ans.begin(), ans.end());       printf( %d n , ans[ans.size() - 1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int m5 = 100042;   int main(void) {     string s, ans =   ;     getline(cin, s);     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  . ) {         if (i == 0) {           ans +=  ... ;         } else {           ans +=   ... ;         }         i += 2;       } else if (s[i] ==  , ) {         ans +=  ,  ;       } else {         ans += s[i];       }     }     while (true) {       int pos = ans.find(    );       if (pos == string::npos) {         break;       }       ans.erase(ans.begin() + pos, ans.begin() + pos + 1);     }     if (ans[ans.size() - 1] ==    ) {       ans.erase(ans.begin() + ans.size() - 1);     }     string ans2 =   ;     for (int i = 0; i < ans.size(); i++) {       if (ans[i] ==     && isdigit(ans[i - 1]) && ans[i + 1] ==  , ) {         continue;       } else if (ans[i] ==     && isdigit(ans[i + 1]) && ans[i - 1] ==  . ) {         continue;       } else if (ans[i] ==     && ans[i + 1] ==  ,  && ans[i - 1] ==  . ) {         continue;       } else {         ans2 += ans[i];       }     }     cout << ans2;     return 0;   }
#include <bits/stdc++.h>   int main(void) {     int n, i, j;     scanf( %d , &n);     int a[n], h[3] = {0}, c[3] = {0};     for (i = 0; i < n; i++) {       scanf( %1d , &a[i]);       h[a[i]]++;     }     for (i = 0; i < n; i++) {       if (h[a[i]] > n / 3) {         c[a[i]]++;         for (j = 0; j < 3; j++) {           if (a[i] != j && h[j] < n / 3) break;         }         if (j > a[i] && c[a[i]] > n / 3) {           h[a[i]]--;           a[i] = j;           h[j]++;         } else if (j < a[i]) {           c[a[i]]--;           h[a[i]]--;           a[i] = j;           h[j]++;         }       }     }     for (i = 0; i < n; i++) printf( %d , a[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int minn(int, int, int);   int main() {     int x1, x2, x3;     cin >> x1 >> x2 >> x3;     int d1 = abs(x2 - x1) + abs(x3 - x1);     int d2 = abs(x1 - x2) + abs(x3 - x2);     int d3 = abs(x3 - x1) + abs(x3 - x2);     cout << minn(d1, d2, d3) << endl;     return 0;   }   int minn(int a, int b, int c) {     int m = a;     if (b < m) m = b;     if (c < m) m = c;     return m;   }
#include <bits/stdc++.h>   using namespace std;   long long sqr(long long x) { return x * x; }   int mysqrt(long long x) {     int l = 0, r = 1e9 + 1;     while (r - l > 1) {       int m = (l + r) / 2;       if (m * (long long)m <= x)         l = m;       else         r = m;     }     return l;   }   mt19937 rnd(1227);   mt19937_64 rndll(12365);   long long AR = 19, BR = 13, CR = 23, XR = 228, YR = 322, MODR = 1e9 + 993;   long long myrand() {     long long ZR = (XR * AR + YR * BR + CR) % MODR;     XR = YR;     YR = ZR;     return ZR;   }   int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }   int gcdex(int a, int b, int &x, int &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     int x1, y1;     int ret = gcdex(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return ret;   }   const int Mod = 1e9 + 7;   int Bpow(int x, int y) {     int ret = 1;     int w = x;     while (y) {       if (y & 1) ret = (ret * (long long)w) % Mod;       w = (w * (long long)w) % Mod;       y >>= 1;     }     return ret;   }   int Bdiv(int x) {     int a, b;     gcdex(x, Mod, a, b);     if (a < 0) a += Mod;     return a;   }   int Bdiv(int x, int y) { return (x * (long long)Bpow(y, Mod - 2)) % Mod; }   void setmin(int &x, int y) { x = min(x, y); }   void setmax(int &x, int y) { x = max(x, y); }   void setmin(long long &x, long long y) { x = min(x, y); }   void setmax(long long &x, long long y) { x = max(x, y); }   const long long llinf = 2e18 + 100;   const double eps = 1e-9;   const int maxn = 1e5 + 100, maxw = 1e6 + 100, inf = 2e9 + 100, sq = 300,             mod = 1e9 + 7, LG = 17;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int w = 1;     for (int i = 2; i <= n; i++)       if (i + (n + i - 1) / i < w + (n + w - 1) / w) w = i;     for (int i = n; i > 0; i -= w) {       for (int j = max(1, i - w + 1); j <= i; j++) cout << j <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     scanf( %d%d , &m, &n);     int t[m][n];     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) scanf( %d , &t[i][j]);     }     int latest[m];     fill(latest, latest + m, 0);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         latest[j] += t[j][i];         if (j != m - 1) latest[j + 1] = max(latest[j], latest[j + 1]);       }     }     for (int i = 0; i < m; i++) {       printf( %d , latest[i]);       if (i != m - 1) putchar(   );     }     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     map<int, vector<int>> mp;     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       mp[a].push_back(i);     }     vector<pair<int, int>> ans;     int cnt = 0;     for (auto ele : mp) {       int a = ele.first;       vector<int> pos = ele.second;       if (pos.size() == 1) {         ans.push_back({a, 0});       } else {         int diff = pos[1] - pos[0];         bool can = true;         for (int i = 2; i <= pos.size() - 1; i++) {           if (pos[i] - pos[i - 1] != diff) {             can = false;             break;           }         }         if (can) {           ans.push_back({a, diff});         }       }     }     cout << ans.size() << endl;     for (auto& ele : ans) {       cout << ele.first <<     << ele.second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, w, nm;   char ls[1000][10][10];   int _d[1000][1000];   int used[1000], res[1000], sz = 0, c = 0;   int main() {     cin >> n >> m >> k >> w;     nm = n * m;     c = nm;     for (int i = 0; i < k; i++)       for (int y = 0; y < n; y++)         for (int x = 0; x < m; x++) cin >> ls[i][y][x];     for (int a = 0; a < k; a++)       for (int b = 0; b < k; b++) {         int res = 0;         for (int i = 0; i < n; i++)           for (int j = 0; j < m; j++)             if (ls[a][i][j] != ls[b][i][j]) res++;         _d[a][b] = res;       }     res[0] = 0;     used[0] = 1;     sz = 1;     stringstream ss;     ss <<  1 0  << endl;     while (sz < k) {       int mini = -1, minval = -1, minj = -1, type = 0;       for (int j = 0; j < sz; j++) {         for (int i = 0; i < k; i++) {           if (used[i]) continue;           int a = _d[res[j]][i] * w, t = min(a, nm);           if (t < minval || mini < 0) {             mini = i;             minval = t;             minj = -1;             if (a < nm) {               minj = res[j];               type = 1;             }           }         }       }       res[sz++] = mini;       used[mini] = 1;       ss << mini + 1 <<     << minj + 1 << endl;       c += minval;     }     cout << c << endl << ss.str();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 15e4 + 5;   int n, b[N];   long long a[N];   int prev(int x) {     int y = x - 1;     if (y == 0) y = n;     return y;   }   int nxt(int x) { return x % n + 1; }   int main() {     scanf( %d , &n);     bool f = true;     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     for (int i = 2; i <= n; i++)       if (b[i] != b[i - 1]) f = false;     if (f) {       if (b[1] != 0) return !printf( NO );       puts( YES );       for (int i = 1; i <= n; i++) printf( %d  , 3122002);       return 0;     }     int pos;     for (int i = 1; i <= n; i++) {       if (b[i] > b[prev(i)]) {         pos = i;         break;       }     }     a[pos] = b[pos];     for (int i = pos - 1; i >= 1; i--) {       int k = max(1LL, (b[prev(i)] - b[i] + a[nxt(i)]) / a[nxt(i)]);       a[i] = 1LL * a[nxt(i)] * k + b[i];     }     for (int i = n; i > pos; i--) {       int k = max(1LL, (b[prev(i)] - b[i] + a[nxt(i)]) / a[nxt(i)]);       a[i] = 1LL * a[nxt(i)] * k + b[i];     }     puts( YES );     for (int i = 1; i <= n; i++) printf( %lld  , a[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string str;   int main() {     long long int i, j, t, n;     cin >> t;     while (t--) {       cin >> str;       int ar[4];       for (i = 0; i < 4; i++) {         ar[i] = 0;       }       int l = str.length();       int count = 0;       int mn = l + 1;       for (i = 0, j = 0; i <= j && j < l; j++) {         ar[str[j] -  1 ]++;         if (ar[str[j] -  1 ] == 1) {           count++;         }         if (count == 3) {           if (j - i + 1 < mn) {             mn = j - i + 1;           }           while (i <= j && count == 3) {             ar[str[i] -  1 ]--;             if (ar[str[i] -  1 ] == 0) {               count--;             }             i++;             if (count == 3 && j - i + 1 < mn) {               mn = j - i + 1;             }           }         }       }       if (mn > l) {         cout << 0 <<   n ;       } else {         cout << mn <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, c[6][223456], child[223456];   double ans[223456], res = 0.0;   vector<pair<int, double> > ke[223456];   pair<pair<int, int>, double> way[223456];   int dad[223456];   void dfs1(int u, int par) {     child[u] = 1;     dad[u] = par;     for (int i = 0; i < ke[u].size(); i++) {       int v = ke[u][i].first;       if (v == par) continue;       dfs1(v, u);       child[u] += child[v];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     int u, v;     double w;     for (int i = 1; i < n; i++) {       cin >> u >> v >> w;       ke[u].push_back(make_pair(v, w));       ke[v].push_back(make_pair(u, w));       way[i] = make_pair(make_pair(u, v), w);     }     dfs1(1, 0);     res = 0;     for (int i = 1; i < n; i++) {       int u1 = way[i].first.first;       int u2 = way[i].first.second;       if (dad[u2] == u1) swap(u1, u2);       double we = way[i].second;       res += we * (child[u1] * (n - child[u1]));     }     int q;     cin >> q;     while (q--) {       cin >> u >> w;       int u1 = way[u].first.first;       int u2 = way[u].first.second;       if (dad[u2] == u1) swap(u1, u2);       double we = way[u].second;       res -= (we - w) * double(child[u1] * (n - child[u1]));       way[u].second = w;       cout << fixed << setprecision(8) << res / double(n * (n - 1) / 6.0) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   void query(int x) {     cout <<  ? ;     for (int i = 1; i <= k + 1; ++i)       if (i != x) cout <<     << i;     cout << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     int x, y, px, py;     query(k + 1);     cin >> px >> x;     query(px);     cin >> py >> y;     int m = 1;     if (y > x) {       for (int i = 1; i <= k; ++i) {         if (i != px) {           query(i);           int pa, a;           cin >> pa >> a;           if (a > x) ++m;         }       }     } else {       for (int i = 1; i <= k; ++i) {         if (i != px) {           query(i);           int pa, a;           cin >> pa >> a;           if (a > y) ++m;         }       }     }     cout <<  !   << m << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265358979323846;   void solve() {     long long n, m, a, b, k, x, y, queries;     string s;     cin >> n >> s;     s =  G  + s;     long long i = 1;     while (i <= n) {       if (s[i] ==  8 ) break;       i++;     }     if (i + 10 <= n)       cout <<  YES ;     else       cout <<  NO ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       solve();       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   inline long long read() {     char c;     long long x;     for (c = getchar(); !isdigit(c); c = getchar())       ;     for (x = 0; isdigit(c); c = getchar()) {       x = x * 10 + c -  0 ;     }     return x;   }   const int N = 2e5 + 5;   int n, q, d[N], f[N];   long long a[N], b[N], c[N], s[N];   std::multiset<long long> set[N], all;   void modify(int u, int sgn, int flag) {     int v = f[u];     if (!set[v].empty()) {       if (flag || sgn < 0) {         all.erase(all.find(*set[v].begin() + c[v]));         all.erase(all.find(*set[v].rbegin() + c[v]));       }     }     if (sgn == 1) {       set[v].insert(b[u] + s[u]);     }     if (sgn == -1) {       set[v].erase(set[v].find(b[u] + s[u]));     }     if (!set[v].empty()) {       if (flag || sgn > 0) {         assert(!set[v].empty());         all.insert(*set[v].begin() + c[v]);         all.insert(*set[v].rbegin() + c[v]);       }     }   }   int main() {     n = read();     q = read();     for (int u = 1; u <= n; u++) {       a[u] = read();       d[u] = 1;     }     for (int u = 1; u <= n; u++) {       f[u] = read();       d[f[u]]++;     }     for (int u = 1; u <= n; u++) {       c[u] = a[u] / (d[u] + 1);       b[u] = a[u] - c[u] * d[u];       s[f[u]] += c[u];     }     for (int u = 1; u <= n; u++) {       modify(u, 1, 1);     }     for (int i = 0; i < q; i++) {       int opt = read();       if (opt == 1) {         int u = read(), v = read();         modify(u, -1, 0);         modify(f[u], -1, 0);         modify(f[f[u]], -1, 0);         d[f[u]]--;         s[f[u]] -= c[u];         s[f[f[u]]] -= c[f[u]];         c[f[u]] = a[f[u]] / (d[f[u]] + 1);         b[f[u]] = a[f[u]] - c[f[u]] * d[f[u]];         s[f[f[u]]] += c[f[u]];         modify(u, 2, 0);         modify(f[u], 1, 0);         modify(f[f[u]], 1, 0);         f[u] = v;         modify(u, -2, 0);         modify(f[u], -1, 0);         modify(f[f[u]], -1, 0);         d[f[u]]++;         s[f[u]] += c[u];         s[f[f[u]]] -= c[f[u]];         c[f[u]] = a[f[u]] / (d[f[u]] + 1);         b[f[u]] = a[f[u]] - c[f[u]] * d[f[u]];         s[f[f[u]]] += c[f[u]];         modify(u, 1, 0);         modify(f[u], 1, 0);         modify(f[f[u]], 1, 0);       } else if (opt == 2) {         int u = read();         printf( %lld n , b[u] + c[f[u]] + s[u]);       } else {         printf( %lld %lld n , *all.begin(), *all.rbegin());       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000000 )   using namespace std;   int n, l[30], m[30], w[30];   int tw[30], P1, P2;   map<pair<long long, long long>, pair<long long, long long> > mp;   long long best = -(1ll << 58), msk1, msk2;   void rec(int p, int msk, long long L, long long M, long long W) {     if (p == P1) {       pair<long long, long long> tmp = make_pair(L - M, L - W);       if (mp.find(tmp) == mp.end())         mp[tmp] = make_pair(L, msk);       else if (mp[tmp].first < L) {         mp[tmp] = make_pair(L, msk);       }       return;     }     rec(p + 1, msk * 3, L, M + m[p], W + w[p]);     rec(p + 1, msk * 3 + 1, L + l[p], M, W + w[p]);     rec(p + 1, msk * 3 + 2, L + l[p], M + m[p], W);   }   void rec2(int p, int msk, long long L, long long M, long long W) {     if (p == n) {       pair<long long, long long> tmp = make_pair(-(L - M), -(L - W));       if (mp.find(tmp) == mp.end()) return;       pair<long long, long long> tmp2 = mp[tmp];       long long sum = L + tmp2.first;       if (sum < best) return;       best = sum;       msk1 = tmp2.second;       msk2 = msk;       return;     }     rec2(p + 1, msk * 3, L, M + m[p], W + w[p]);     rec2(p + 1, msk * 3 + 1, L + l[p], M, W + w[p]);     rec2(p + 1, msk * 3 + 2, L + l[p], M + m[p], W);   }   void print(int x, int msk) {     if (x == 0) return;     print(x - 1, msk / 3);     if (msk % 3 == 0)       printf( MW n );     else if (msk % 3 == 1)       printf( LW n );     else       printf( LM n );   }   int main() {     for (int i = 0; i < 30; i++) tw[i] = 1 << i;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d %d , &l[i], &m[i], &w[i]);     }     P1 = n / 2, P2 = n - P1;     rec(0, 0, 0, 0, 0);     rec2(P1, 0, 0, 0, 0);     if (best == -(1ll << 58))       printf( Impossible n );     else {       print(P1, msk1);       print(P2, msk2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0)->sync_with_stdio(0);     long long n, r1, r2, r3, d;     cin >> n >> r1 >> r2 >> r3 >> d;     long long a[n];     for (int i = 0; i < n; i++) cin >> a[i];     long long adv[n + 1], ret[n + 1];     adv[0] = ret[n] = 0;     ret[n - 1] = min(         {a[n - 1] * r1 + r3, a[n - 1] * r1 + 2 * r1 + 2 * d, r2 + r1 + 2 * d});     for (int i = 1; i <= n; i++) {       adv[i] = adv[i - 1] + a[i - 1] * r1 + r3 + d;       if (i - 2 >= 0)         adv[i] = min(adv[i], adv[i - 2] + min(a[i - 2] * r1 + r1, r2) +                                  min(a[i - 1] * r1 + r1, r2) + 2 * r1 + 4 * d);     }     adv[n] -= d;     for (int i = n - 2; i >= 0; i--) {       ret[i] = ret[i + 1] + min(a[i] * r1 + 2 * r1, r2 + r1) + 2 * d;     }     long long sol = LLONG_MAX;     for (int i = 0; i <= n; i++) sol = min(sol, adv[i] + ret[i]);     cout << sol <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int t;     cin >> t;     for (int _ = 0; _ < (t); ++_) {       int n;       cin >> n;       if (n < 4) {         cout << -1 <<   n ;         continue;       }       deque<int> p{3, 1, 4};       vector<int> nums{2};       for (int i = 5; i <= n; ++i) {         nums.push_back(i);       }       for (int i = 0; i < (((int)(nums).size())); ++i) {         if (abs(p.front() - nums[i]) >= 2 && abs(p.front() - nums[i]) <= 4) {           p.push_front(nums[i]);         } else {           p.push_back(nums[i]);         }       }       for (int i = 0; i < (((int)(p).size())); ++i) {         if (i) {           cout <<    ;         }         cout << p[i];       }       cout <<   n ;     }   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int c = 102;   int kezd[c][c], veg[c][c], dp[c][c], n, m, sum;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       int db;       cin >> db;       for (int j = 1; j <= db; j++) {         int a, b;         cin >> a >> b;         for (int k = a; k <= b; k++) kezd[i][k] = a, veg[i][k] = b;       }     }     for (int j = 0; j < m; j++)       for (int i = 1; i + j <= m; i++) {         int maxi = 0;         for (int k = i; k <= i + j; k++) {           int cnt = 0;           for (int l = 1; l <= n; l++)             cnt += (i <= kezd[l][k] && veg[l][k] <= i + j);           maxi = max(maxi, cnt * cnt + dp[i][k - 1] + dp[k + 1][i + j]);         }         dp[i][i + j] = maxi;       }     cout << dp[1][m] <<   n ;     return 0;   }