malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 35, L = 10005;   int T, k, i, j, n, m;   int a[2][N], b[N * 2], bb[N * 2];   char cc[5], ans[L], *ass, out[26][L], *pp[26];   inline void getseq() {     int xb = 0;     for (j = 0; j < n; ++j)       if (a[0][j]) b[xb++] = a[0][j];     for (j = n - 1; j >= 0; --j)       if (a[1][j]) b[xb++] = a[1][j];   }   inline void push(char c1, char c2) { *pp[c1 -  A ]++ = c2; }   inline void opt(char c) { *ass++ = c; }   inline void get_rot2(int x, char c) {     int i;     x -= k;     if (x < 0) x += m;     for (i = 0; i < x; ++i) push(c,  R );     for (i = 0; i < k; ++i) push(c,  l );     push(c,  u );     for (i = 0; i < k; ++i) push(c,  r );     push(c,  d );     for (i = x; i < m; ++i) push(c,  R );   }   inline void rot2(int x) {     int i;     x -= k;     if (x < 0) x += m;     for (i = 0; i < x; ++i) opt( R );     for (i = 0; i < k; ++i) opt( l );     opt( u );     for (i = 0; i < k; ++i) opt( r );     opt( d );     for (i = x; i < m; ++i) opt( R );   }   inline void rot3(int x) {     swap(b[x], b[x + 1]);     swap(b[x + 1], b[x + 2]);     if (k == 1) return rot2(x);     int i;     if (x >= 8) opt(x / 8 - 1 +  A );     if (x % 8) opt(x % 8 - 1 +  I );     opt( U );     x = m - x;     if (x >= 8) opt(x / 8 - 1 +  A );     if (x % 8) opt(x % 8 - 1 +  I );   }   int calcI(int* b) {     int ass = 0;     for (i = 0; i < m; ++i)       for (j = i + 1; j < m; ++j) ass += b[i] > b[j];     return ass;   }   int main() {     for (scanf( %d , &T); T--;) {       scanf( %d , &k);       n = k * 2 + 1;       m = n * 2 - 1;       ass = ans;       for (i = 0; i < 2; ++i)         for (j = 0; j < n; ++j)           scanf( %s , cc), *cc ==  E  ? a[i][j] = 0 : sscanf(cc,  %d , a[i] + j);       for (j = 0; j + 1 < n; ++j)         for (i = 0; i < 2; ++i)           if (a[i][j] == 0) opt( r ), swap(a[i][j], a[i][j + 1]);       if (a[0][n - 1] == 0) opt( d ), swap(a[0][n - 1], a[1][n - 1]);       ;       int i1, i2;       getseq();       i1 = calcI(b);       for (i = 0; i < m; ++i) bb[i] = i + 1;       reverse(bb + n, bb + m);       i2 = calcI(bb);       if ((i2 - i1) & 1) {         puts( SURGERY FAILED );         continue;       }       for (i = 0; i < 26; ++i) pp[i] = out[i];       for (i = n - 1; i; --i) push( R ,  l );       push( R ,  u );       for (i = 0; i < n - 1; ++i) push( R ,  r );       push( R ,  d );       for (i = 1; i <= 8; ++i) push( A ,  R );       for (i = 2; i <= 8; ++i)         push( A  + i - 1,  A  + i - 2), push( A  + i - 1,  A );       push( I ,  R );       for (i = 1; i < 8; ++i) push( I  + i,  I  + i - 1), push( I  + i,  R );       get_rot2(0,  S );       get_rot2(1,  T );       push( U ,  T );       push( U ,  T );       for (i = 1; i <= 2 * k; i += 2) push( U ,  T ), push( U ,  S );       for (i = 0; i + 2 < m; ++i) {         for (j = i; b[j] != bb[i]; ++j)           ;         for (; j > i + 1; rot3(j - 2), --j)           ;         if (j > i) rot3(j - 1);       }       puts( SURGERY COMPLETE );       *ass = 0;       puts(ans);       for (i = 0; i < 26; ++i)         if (pp[i] != out[i]) *pp[i] = 0, printf( %c %s n , i +  A , out[i]);       puts( DONE );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   using pll = pair<ll, ll>;   const int N = 100010;   int m, n, q[N], a[N];   int main() {     scanf( %d , &m);     for (int i = 0; i < m; i++) scanf( %d , &q[i]);     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     int mn = *min_element(q, q + m) + 2;     int ans = 0;     for (int i = 0; i < n; i++) ans += a[i];     sort(a, a + n);     reverse(a, a + n);     for (int i = mn - 2; i < n; i += mn) {       ans -= a[i];       if (i + 1 < n) ans -= a[i + 1];     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, tc;     cin >> tc;     while (tc-- != 0) {       cin >> n;       if (n & 1) {         cout <<  7 ;         for (int i = 1; i < n / 2; i++) {           cout <<  1 ;         }       } else {         for (int i = 1; i <= n / 2; i++) {           cout <<  1 ;         }       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5, inf = 1e9 + 7;   long long n, k, i, j;   long long A[N], l[N], r[N], len[N];   set<pair<long long, long long> > st;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long i, j, a, b, ans = 0, cur;     cin >> n;     for (i = 1; i < n + 1; i++) cin >> A[i];     i = 1;     while (i <= n) {       j = i;       while (j <= n && A[j] == A[i]) j++;       r[i] = j;       l[j] = i;       len[i] = j - i;       st.insert(pair<long long, long long>(i - j, i));       i = j;     }     while (!st.empty()) {       cur = st.begin()->second;       st.erase(st.begin());       ans++;       len[cur] = 0;       a = l[cur];       b = r[cur];       if (st.empty()) break;       if (A[a] == A[b] && a > 0 && b <= n) {         st.erase(pair<long long, long long>(-len[a], a));         st.erase(pair<long long, long long>(-len[b], b));         r[a] = r[b];         l[r[a]] = a;         len[a] += len[b];         len[b] = 0;         st.insert(pair<long long, long long>(-len[a], a));       } else {         r[a] = b;         l[b] = a;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   struct M {     int t, x[4];     M(int s, int a, int b, int c, int d = 0) {       t = s;       x[0] = a;       x[1] = b;       x[2] = c;       x[3] = d;     }     void p() {       printf( %d , t);       for (int i = 0; i < (int)(t); ++i) printf(  %d , x[i]);       printf(  n );     }   };   vector<M> an;   int main() {     int n;     scanf( %d , &n);     while (n > 4) {       int a = n, b = n - 1;       an.push_back(M(3, 1, a, b));       an.push_back(M(3, 1, a, b));       for (int i = 3; i < (int)(b); ++i) an.push_back(M(4, i - 1, a, i, b));       an.push_back(M(4, b - 1, a, 2, b));       n -= 2;     }     if (n == 4) {       an.push_back(M(4, 1, 2, 3, 4));       an.push_back(M(4, 1, 3, 4, 2));       an.push_back(M(4, 1, 4, 2, 3));     } else {       an.push_back(M(3, 1, 2, 3));       an.push_back(M(3, 1, 2, 3));     }     printf( %d n , (int)an.size());     for (int i = 0; i < (int)(an.size()); ++i) an[i].p();   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     ios_base ::sync_with_stdio(false), cin.tie(NULL);     int test;     cin >> test;     while (test--) {       int n, k;       string s;       cin >> s;       int a = 1, poss = true;       while (poss) {         poss = false;         string t;         int len = s.size();         for (int i = 0; i < len - 1; ++i) {           if ((s[i] ==  1  && s[i + 1] ==  0 ) ||               (s[i] ==  0  && s[i + 1] ==  1 )) {             i += 2;             poss = true;             a = (a == 1) ? 0 : 1;             while (i < len) {               t += s[i];               i++;             }           } else             t += s[i];         }         s = t;       }       if (a == 0)         cout <<  DA n ;       else         cout <<  NET n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int mid = 0;   int num = 0;   int e[21][21];   int flag[21];   void dfs(int x, int sum) {     if (x > n) {       num = num + 1;       return;     }     dfs(x + 1, sum);     for (int y = 1; y <= n; y++) {       if (num > k) {         break;       }       if (flag[y] == 0 && e[x][y] != 0 && sum + e[x][y] <= mid) {         flag[y] = 1;         dfs(x + 1, sum + e[x][y]);         flag[y] = 0;       }     }     return;   }   int main() {     int u, v, w;     cin >> n >> m >> k;     int l = 0;     int h = 1000 * n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         e[i][j] = 0;       }     }     for (int i = 0; i < m; i++) {       cin >> u >> v >> w;       e[u][v] = w;     }     while (l < h) {       mid = (l + h) / 2;       num = 0;       dfs(1, 0);       if (num < k) {         l = mid + 1;       } else {         h = mid;       }     }     cout << l << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double a1, a2;     double b1, b2;     double c1, c2;     cin >> a1 >> b1 >> c1;     cin >> a2 >> b2 >> c2;     if (fabs(a1) < 1e-14 && fabs(b1) < 1e-14 && fabs(c1) > 1e-14 ||         fabs(a2) < 1e-14 && fabs(b2) < 1e-14 && fabs(c2) > 1e-14) {       cout << 0;       return 0;     }     if (fabs(a1) < 1e-14 && fabs(b1) < 1e-14 && fabs(c1) < 1e-14 ||         fabs(a2) < 1e-14 && fabs(b2) < 1e-14 && fabs(c2) < 1e-14) {       cout << -1;       return 0;     }     if ((fabs(b1) < 1e-14 && fabs(b2) > 1e-14) ||         (fabs(b2) < 1e-14 && fabs(b1) > 1e-14))       cout << 1;     else if (fabs(b1) < 1e-14 && fabs(b2) < 1e-14) {       a1 /= c1;       a2 /= c2;       if (fabs(a1 - a2) < 1e-14 || (fabs(a1) == INFINITY && fabs(a2) == INFINITY))         cout << -1;       else         cout << 0;     } else {       a1 /= b1;       a2 /= b2;       c1 /= b1;       c2 /= b2;       if (fabs(a1 - a2) < 1e-14) {         if (fabs(c1 - c2) < 1e-14)           cout << -1;         else           cout << 0;       } else         cout << 1;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, a[12], b[20], c[5], u[15], vs, hh;   string v[2033333];   void add(int o, int s, int k) {     if (s > k) return;     if (o == 4) {       if (k - s > 2) return;       if (k - s && b[s] == 0) return;       if (k - s == 2 && b[s] * 100 + b[s + 1] * 10 + b[k] >= 256) return;       string st =   ;       for (int i = 1; i <= c[1]; i++) st += char(b[i] + 48);       st +=  . ;       for (int i = c[1] + 1; i <= c[1] + c[2]; i++) st += char(b[i] + 48);       st +=  . ;       for (int i = c[1] + c[2] + 1; i < s; i++) st += char(b[i] + 48);       st +=  . ;       for (int i = s; i <= k; i++) st += char(b[i] + 48);       v[++vs] = st;       return;     }     c[o] = 1;     add(o + 1, s + 1, k);     if (!b[s]) return;     c[o] = 2;     add(o + 1, s + 2, k);     if (b[s] * 100 + b[s + 1] * 10 + b[s + 2] >= 256) return;     c[o] = 3;     add(o + 1, s + 3, k);   }   void cty(int k) {     for (int i = 1; i <= n; i++) {       b[k] = a[i];       if (!u[i]) hh++;       u[i]++;       if (k >= 2) {         do {           if (hh != n) break;           for (int j = 1; j <= k; j++) b[(k << 1) - j + 1] = b[j];           add(1, 1, k << 1);           if (k != 2) {             for (int j = 1; j < k; j++) b[(k << 1) - j] = b[j];             add(1, 1, (k << 1) - 1);           }         } while (0);       }       if (k < 6) cty(k + 1);       u[i]--;       if (!u[i]) hh--;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     cty(1);     sort(v + 1, v + vs + 1);     printf( %d n , vs);     for (int i = 1; i <= vs; i++) {       int l = v[i].size();       for (int j = 0; j < l; j++) printf( %c , v[i][j]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool win(long long A, long long B) {     if (A == 0 || B == 0) return false;     if (A > B) swap(A, B);     if (!win(A, B % A)) return true;     long long N = B / A;     long long MOD = A + 1;     return ((N % MOD) % 2 == 0);   }   int main(void) {     int T, t;     long long A, B;     cin >> T;     for ((t) = 0; (t) < (int)(T); (t)++) {       cin >> A >> B;       bool ans = win(A, B);       cout << (ans ?  First  :  Second ) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int *b = new int[n];     int max_val = 0;     for (int i = 0; i < n; i++) {       cin >> b[i];       if (i == 0) {       } else if (i == 1) {         b[i] = b[0] + b[1];         max_val = (b[0] > b[1]) ? b[0] : b[1];       } else {         b[i] = max_val + b[i];         if (max_val < b[i]) max_val = b[i];       }       cout << b[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, cnt = 1;     cin >> n;     int x[n];     for (int i = 0; i < n; i++) {       cin >> x[i];     }     for (int i = 0; i < n - 1; i++) {       if (x[i] != x[i + 1]) {         cnt++;       }     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   const long long mod = 1e9 + 7;   const long long maxn = 1e5 + 10;   long long n, x, y;   long long money[maxn];   pair<long long, long long> show[maxn];   multiset<pair<long long, long long> > s;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int main() {     long long ans = 0;     n = read(), x = read(), y = read();     for (long long i = 1; i <= n; i++) {       show[i].first = read(), show[i].second = read();       s.insert({show[i].second, show[i].first});     }     sort(show + 1, show + 1 + n);     for (long long i = 1; i <= n; i++) {       money[i] = (x + y * (show[i].second - show[i].first));       if (!s.size() || (*s.begin()).first >= show[i].first) continue;       multiset<pair<long long, long long> >::iterator iter =           s.lower_bound({show[i].first, 0});       long long tmp = (*(--iter)).first;       if (y * (show[i].second - tmp) >= money[i]) continue;       money[i] = y * (show[i].second - tmp);       s.erase(iter);     }     for (long long i = 1; i <= n; i++) {       ans += money[i];       ans %= mod;     }     ans %= mod;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 9;   long long Pow(long long a, long long x) {     long long res = 1;     while (x) {       if (x & 1) res = res * a % mod;       a = a * a % mod;       x >>= 1;     }     return res;   }   long long inv(long long a) { return Pow(a, mod - 2); }   long long n, a, b, k;   string s;   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> a >> b >> k;     cin >> s;     long long ans = 0;     for (int i = 0; i < k; ++i) {       int f = s[i] ==  -  ? -1 : 1;       ans = (ans + (f * Pow(a, n - i) * Pow(b, i) % mod + mod) % mod) % mod;     }     long long q = Pow(inv(a) * b % mod, k);     if (q == 1) {       long long res = (n + 1) / k;       ans = ans * res % mod;     } else {       long long res = Pow(q, (n + 1) / k);       res--;       if (res < 0) res += mod;       res = res * inv(q - 1) % mod;       ans = res * ans % mod;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     if (a == 0) return b;     return gcd(b % a, a);   }   template <typename T>   T pow(T a, T b, long long m) {     T ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans % m;   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first > b.first);   }   int main() {     long long i, t, a;     cin >> t;     while (t--) {       cin >> a;       double z = abs(a - 180);       z = (double)360 / z;       if (floor(z) == ceil(z)) {         cout <<  YES ;       } else {         cout <<  NO ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   multiset<long long> mset;   void add(long long k) { mset.insert(k); }   long long getmin() { return *mset.begin(); }   long long getmax() { return *prev(mset.end()); }   long long lower(long long k) {     if (mset.size() == 0) return -1;     if (k < getmin()) return -1;     if (mset.count(k)) return k;     auto it = mset.lower_bound(k);     return *prev(it);   }   long long uper(long long k) {     if (mset.size() == 0) return -1;     auto it = mset.lower_bound(k);     if (it == mset.end()) return -1;     return *it;   }   void erase(long long k) { mset.erase(mset.find(k)); }   long long t, n;   const long long inf = 0x3f3f3f3f;   long long dp[200005][2], a[200005];   signed main() {     ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       cin >> n;       for (long long i = 0; i < n; i++) {         cin >> a[i];         dp[i][1] = inf;         dp[i][0] = inf;       }       dp[0][0] = a[0];       dp[1][0] = dp[0][0] + a[1];       dp[1][1] = dp[0][0];       for (long long i = 2; i < n; i++) {         dp[i][0] = min(dp[i - 1][1] + a[i], dp[i - 2][1] + a[i - 1] + a[i]);         dp[i][1] = min(dp[i - 1][0], dp[i - 2][0]);       }       cout << min(dp[n - 1][0], dp[n - 1][1]) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   size_t solve(const std::vector<std::string>& c) {     const size_t n = c.size();     size_t count = 0;     for (size_t i = 0; i < n; ++i) {       for (size_t j = 0; j < n; ++j) {         for (size_t k = j + 1; k < n; ++k) {           if (c[i][j] ==  C  && c[i][k] ==  C ) ++count;           if (c[j][i] ==  C  && c[k][i] ==  C ) ++count;         }       }     }     return count;   }   int main() {     size_t n;     std::cin >> n;     std::vector<std::string> c(n);     for (size_t i = 0; i < n; ++i) std::cin >> c[i];     std::cout << solve(c) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5;   int main() {     vector<int> goh_nakhor[maxn];     int n, k, ans = 0;     cin >> n >> k;     for (int i = 0; i < k; i++) {       int num, tmp;       cin >> num >> tmp;       if (tmp != 1) ans += num - 1;       for (int i = 0; i < num - 1; i++) {         int val;         cin >> val;         goh_nakhor[tmp].push_back(val);       }     }     int cnt = 0;     for (int i = 0; i < goh_nakhor[1].size(); i++) {       if (goh_nakhor[1][i] == i + 2) cnt++;     }     cout << ans + (goh_nakhor[1].size() - cnt - 1) + n - cnt <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   char color[16];   int r[16], b[16];   int redCount[1 << 16], blueCount[1 << 16];   int dp[1 << 16][2][257];   int calc(int mask, bool noRed, int other) {     other = min(other, n * n);     if (dp[mask][noRed][other] != -1) return dp[mask][noRed][other];     if (mask == (1 << n) - 1) return dp[mask][noRed][other] = 0;     dp[mask][noRed][other] = 1000000000;     for (int i = 0; i < n; ++i) {       if (mask & (1 << i)) continue;       int nextMask = mask | (1 << i);       int payRed = max(0, r[i] - redCount[mask]),           payBlue = max(0, b[i] - blueCount[mask]);       int haveRed = 0, haveBlue = 0;       if (noRed)         haveBlue = other;       else         haveRed = other;       int add = max(max(payRed - haveRed, payBlue - haveBlue), 0);       haveRed += add, haveBlue += add;       haveRed -= payRed, haveBlue -= payBlue;       if (haveRed == 0)         dp[mask][noRed][other] =             min(dp[mask][noRed][other], add + calc(nextMask, 1, haveBlue));       else if (haveBlue == 0)         dp[mask][noRed][other] =             min(dp[mask][noRed][other], add + calc(nextMask, 0, haveRed));     }     return dp[mask][noRed][other];   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> color[i] >> r[i] >> b[i];     for (int i = 0; i < 1 << n; ++i) {       for (int j = 0; j < n; ++j) {         if ((i & (1 << j)) == 0) continue;         if (color[j] ==  R )           redCount[i]++;         else           blueCount[i]++;       }       for (int j = 0; j < 2; ++j)         for (int k = 0; k <= 256; ++k) dp[i][j][k] = -1;     }     int needRed = 0, needBlue = 0;     for (int i = 0; i < n; ++i) {       needRed += max(0, r[i] - n);       needBlue += max(0, b[i] - n);       r[i] = min(r[i], n);       b[i] = min(b[i], n);     }     if (needRed >= needBlue)       cout << needRed + n + calc(0, 1, needRed - needBlue);     else       cout << needBlue + n + calc(0, 0, needBlue - needRed);     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int c1, c2, c3, c4, n, m;   int rs1, rs2, rs3, rs4, rs;   int a, b;   int main() {     ios_base::sync_with_stdio(0);     ;     cin.tie(0);     ;     cin >> c1 >> c2 >> c3 >> c4;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> a;       rs1 += min(a * c1, c2);     }     rs2 = min(rs1, c3);     for (int i = 1; i <= m; i++) {       cin >> b;       rs3 += min(b * c1, c2);     }     rs4 = min(rs3, c3);     cout << min(rs2 + rs4, c4);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   const int MOD = 1000000007;   const int INF = 0x3f3f3f3f;   void add(int &x, int y) {     x += y;     if (x >= MOD) x -= MOD;   }   int n, h[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &h[i]);       h[i]--;     }     h[n + 1] = INF;     int ans = h[1], sum = min(h[1], h[2]);     for (int i = 2; i <= n; i++) {       add(ans, h[i]);       add(ans, 1LL * sum * min(h[i - 1], h[i]) % MOD);       sum = 1LL * sum * min(min(h[i - 1], h[i]), h[i + 1]) % MOD;       add(sum, min(h[i], h[i + 1]));     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   inline long long int min(long long int a, long long int b) {     return (a < b) ? a : b;   }   long long int dp[303][303], cost[303][303];   int main() {     int n, m, k, o, j, i;     scanf( %d %d %d , &n, &m, &o);     for (i = 0; i <= n; i++)       for (j = 0; j <= n; j++) dp[i][j] = cost[i][j] = 10000000000000LL;     for (i = 0; i < m; i++) {       int l, r, c;       scanf( %d %d %d , &l, &r, &c);       cost[l][r] = min(cost[l][r], c);     }     for (i = 1; i <= n; i++)       for (j = 1; j <= i; j++)         for (k = i; k <= n; k++) {           cost[j][i] = min(cost[j][i], cost[j][k]);           cost[i][k] = min(cost[i][k], cost[j][k]);         }     for (i = 0; i <= n; i++) {       dp[i][0] = 0;       for (j = 1; j <= i; j++) {         dp[i][j] = min(cost[i - j + 1][i], dp[i - 1][j]);         for (k = 1; k < j; k++)           dp[i][j] = min(dp[i][j], cost[i - k + 1][i] + dp[i - k][j - k]);       }     }     if (dp[n][o] != 10000000000000LL)       printf( %I64d n , dp[n][o]);     else       printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast ,  unroll-loops )   using namespace std;   const long long inf = 1ll << 60;   const long long iinf = 2147483647;   const long long mod = 998244353;   const long long maxn = 1e3 + 5;   long long pw(long long x, long long p) {     long long ret = 1;     while (p > 0) {       if (p & 1) {         ret *= x;         ret %= mod;       }       x *= x;       x %= mod;       p >>= 1;     }     return ret;   }   long long inv(long long x) { return pw(x, mod - 2); }   long long dp[5005][5005];   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     long long n;     cin >> n;     vector<long long> vc(n);     for (long long i = (0); i < (n); i++) {       cin >> vc[i];     }     for (long long i = (1); i < (n + 1); i++) {       for (long long j = (1); j < (n - i + 1 + 1); j++) {         if (i == 1) {           dp[i][j] = vc[j - 1];           continue;         }         dp[i][j] = dp[i - 1][j] ^ dp[i - 1][j + 1];       }     }     for (long long i = (1); i < (n + 1); i++) {       for (long long j = (1); j < (n - i + 1 + 1); j++) {         dp[i][j] = max({dp[i][j], dp[i - 1][j], dp[i - 1][j + 1]});       }     }     long long q;     cin >> q;     for (long long i = (0); i < (q); i++) {       long long l, r;       cin >> l >> r;       cout << dp[r - l + 1][l] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     cin >> n >> m >> k;     deque<int> items;     int tmp;     for (int i = 0; i < k; i++) {       cin >> tmp;       items.push_back(tmp);     }     int ans = 0;     for (int i = 0; i < n * m; i++) {       cin >> tmp;       for (int j = 0; j < items.size(); j++) {         if (items[j] == tmp) {           ans += j + 1;           items.erase(items.begin() + j);           items.push_front(tmp);           break;         }       }     }     cout << ans << endl;     return 0;   }