malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   char s[705];   int match[705];   int tmp[705];   long long dp[705][705][3][3];   void getmatch(int len) {     int kk = 0;     for (kk = 0; kk <= 10000; kk++)       ;     int p = 0;     for (int i = 0; i < len; i++) {       if (s[i] ==  ( )         tmp[p++] = i;       else {         match[i] = tmp[p - 1];         match[tmp[p - 1]] = i;         p--;       }     }   }   void dfs(int l, int r) {     int kk = 0;     for (kk = 0; kk <= 10000; kk++)       ;     if (l + 1 == r) {       dp[l][r][0][1] = 1;       dp[l][r][1][0] = 1;       dp[l][r][0][2] = 1;       dp[l][r][2][0] = 1;       return;     }     if (match[l] == r) {       dfs(l + 1, r - 1);       for (int i = 0; i < 3; i++) {         for (int j = 0; j < 3; j++) {           if (j != 1)             dp[l][r][0][1] =                 (dp[l][r][0][1] + dp[l + 1][r - 1][i][j]) % 1000000007;           if (i != 1)             dp[l][r][1][0] =                 (dp[l][r][1][0] + dp[l + 1][r - 1][i][j]) % 1000000007;           if (j != 2)             dp[l][r][0][2] =                 (dp[l][r][0][2] + dp[l + 1][r - 1][i][j]) % 1000000007;           if (i != 2)             dp[l][r][2][0] =                 (dp[l][r][2][0] + dp[l + 1][r - 1][i][j]) % 1000000007;         }       }       return;     } else {       int p = match[l];       dfs(l, p);       dfs(p + 1, r);       for (int i = 0; i < 3; i++) {         for (int j = 0; j < 3; j++) {           for (int k = 0; k < 3; k++) {             for (int q = 0; q < 3; q++) {               if (!((k == 1 && q == 1) || (k == 2 && q == 2)))                 dp[l][r][i][j] =                     (dp[l][r][i][j] +                      (dp[l][p][i][k] * dp[p + 1][r][q][j]) % 1000000007) %                     1000000007;             }           }         }       }     }   }   int main() {     while (scanf( %s , s) != EOF) {       int len = strlen(s);       getmatch(len);       int kk = 0;       for (kk = 0; kk <= 10000; kk++)         ;       memset(dp, 0, sizeof(dp));       dfs(0, len - 1);       long long ans = 0;       for (int i = 0; i < 3; i++) {         for (int j = 0; j < 3; j++) {           ans = (ans + dp[0][len - 1][i][j]) % 1000000007;         }       }       printf( %ld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> s[10];   int n1, n2;   int ok(int a, int b) {     int sum = a + b * 2;     int len = 0;     for (int i = 0; i < n1 - a; i++) len += s[1][i];     for (int i = 0; i < n2 - b; i++) len += s[2][i];     return len <= sum;   }   int main() {     int a, b, n, m, i, j, ans = 99999999;     ;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d%d , &a, &b);       s[a].push_back(b);     }     sort(s[1].begin(), s[1].end());     sort(s[2].begin(), s[2].end());     n1 = s[1].size();     n2 = s[2].size();     for (i = 0; i <= n1; i++)       for (j = 0; j <= n2; j++) {         if (ok(i, j)) {           if (i + j * 2 < ans) ans = i + j * 2;         }       }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 30) - 1;   const int maxn = 100010;   char s[maxn];   int calc(char a, char b) {     int mx = 30;     mx = min(mx, a > b ? a - b : b - a);     mx = min(mx, a > b ? b + 26 - a : a + 26 - b);     return mx;   }   int main() {     scanf( %s , s);     int len = strlen(s);     int ans = 0;     ans += calc( a , s[0]);     for (int i = 0; i < len - 1; i++) ans += calc(s[i], s[i + 1]);     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int q = 30;     if (n == 1 || n == 3 || n == 5 || n == 7 || n == 8 || n == 10 || n == 12) q++;     if (n == 2) q = 28;     q = q - 8 + m;     if (q % 7 == 0)       cout << (q / 7) + 1;     else       cout << (q / 7) + 2;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a * b / gcd(a, b); }   struct data {     int num;     int init;   };   bool byNum(const data &left, const data &right) { return left.num > right.num; }   bool descend(const int &left, const int &right) { return left > right; }   data total[105];   pair<int, int> pile[105];   int sisa[105], card[105];   int main(void) {     int temp, n, i, j;     scanf( %d , &n);     for (i = 0; i <= n - 1; i++) {       scanf( %d , &card[i]);       sisa[i] = 0;       for (j = 0; j <= card[i] / 2 - 1; j++) {         scanf( %d , &temp);         pile[i].first += temp;       }       if (card[i] % 2) {         scanf( %d , &temp);         sisa[i] = temp;       }       for (j = 0; j <= card[i] / 2 - 1; j++) {         scanf( %d , &temp);         pile[i].second += temp;       }       total[i].num = pile[i].first + sisa[i] + pile[i].second;       total[i].init = i;     }     sort(total, total + n, byNum);     sort(sisa, sisa + n, descend);     long long a = 0, b = 0;     for (i = 0; i <= n - 1; i++) {       a += pile[total[i].init].first;       b += pile[total[i].init].second;     }     for (i = 0; i <= n - 1; i++) {       if (i % 2)         b += sisa[i];       else         a += sisa[i];       if (!sisa[i]) break;     }     cout << a <<     << b << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> caps, full;   int main() {     int w, l;     cin >> w >> l;     caps = vector<int>(w + 1, 0);     caps[w] = 2e9;     full = vector<int>(w + 1, 0);     full[0] = 2e9;     for (int i = 1; i < w; i++) cin >> caps[i];     int from = 0;     int to = 1;     while (from != w) {       ;       if (to == from)         to++;       else if (to - from > l) {         ;         from++;       } else if (full[to] == caps[to]) {         ;         to++;       } else if (full[from] == 0) {         ;         from++;       } else {         int k = min(full[from], caps[to] - full[to]);         full[from] -= k;         full[to] += k;         ;       }     }     cout << full[w] << endl;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long T;     cin >> T;     while (T--) {       string s;       cin >> s;       long long ans = (long long)s.size(), curr = 0;       for (long long i = 0; i < s.size(); i++) {         if (s[i] ==  + ) {           curr++;         } else {           curr--;         }         if (curr < 0) {           ans += (i + 1);           curr++;         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int event, ghotona;     cin >> event;     int hired = 0, untreated = 0;     for (int i = 0; i < event; i++) {       cin >> ghotona;       hired += ghotona;       if (hired < 0) {         untreated++;         hired = 0;       }     }     cout << untreated << endl;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   int bit[1100];   int tot = 0;   void GetBinary(int n) {     memset(bit, 0, sizeof bit);     while (n) {       bit[tot++] = n & 1;       n >>= 1;     }   }   int layer[1100][2];   void Construct() {     layer[1][0] = 1;     layer[2][0] = 3;     layer[3][0] = 4;     layer[3][1] = 5;     for (int i = 4; i <= 60; i += 2) {       layer[i][0] = layer[i - 2][0] + 3;       layer[i + 1][0] = layer[i - 1][0] + 3;       layer[i + 1][1] = layer[i - 1][1] + 3;     }   }   int g[1100][1100];   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     GetBinary(n);     Construct();     memset(g, 0, sizeof g);     int total = tot << 1;     layer[total + 1][0] = 2;     for (int i = 2; i <= total; ++i) {       if (i == 2) {         g[layer[i - 1][0]][layer[i][0]] = 1;         continue;       }       if (i % 2 == 1) {         g[layer[i - 1][0]][layer[i][0]] = 1;         g[layer[i - 1][0]][layer[i][1]] = 1;       } else {         g[layer[i - 1][0]][layer[i][0]] = 1;         g[layer[i - 1][1]][layer[i][0]] = 1;       }     }     g[2][layer[total][0]] = 1;     int PathLength = total;     int ind = tot * 3, indd = tot * 3, end = tot * 3;     for (int i = 0; i < tot - 1; ++i) {       if (bit[i]) {         int pre = layer[(i + 1) * 2][0];         indd = ind;         for (int j = 1; j <= PathLength - (i + 1) * 2 - 1; ++j) {           g[pre][j + indd] = 1;           pre = j + indd;           ind++;         }         g[pre][end] = 1;       }     }     cout << ind << endl;     for (int i = 1; i <= ind; ++i) {       for (int j = 1; j <= ind; ++j) {         if (i == j)           cout <<  N ;         else if (g[i][j] || g[j][i])           cout <<  Y ;         else           cout <<  N ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n;     string s;     cin >> n >> s;     for (long long int i = 0; i < n; i++) cout << s[n - 1];     cout << endl;   }   int main() {     int test;     cin >> test;     for (int TEST = 1; TEST <= test; TEST++) solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     char arr[n][n];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> arr[i][j];       }     }     pair<int, int> p[n * n];     int in = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (arr[i][j] ==  C ) {           p[in] = make_pair(i, j);           in++;         }       }     }     int cnt = 0;     for (int i = 0; i < in; i++) {       for (int j = i + 1; j < in; j++) {         if (p[i].first == p[j].first || p[i].second == p[j].second) {           cnt++;         }       }     }     cout << cnt << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 103;   int p[MAXN], c[MAXN];   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       bool check = true;       for (int i = 1; i <= n; i++) {         cin >> p[i] >> c[i];         if (c[i] > p[i] || c[i] < c[i - 1] || p[i] < c[i] ||             p[i] - p[i - 1] < c[i] - c[i - 1])           check = false;       }       if (check)         cout <<  YES               <<   n ;       else         cout <<  NO               <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   double const pi = 3.14159265358979;   int const MAXN = 2000000;   long long const MOD = 1000000007;   long long const INF = 1000000000000000000ll;   int a[2000000], d[2000000];   bool is[2000000];   int main() {     int n, res = 0;     scanf( %d , &n);     for (int i = 0; i < (int)(n); i++) {       scanf( %d , &a[i]);       is[a[i]] = 1;     }     for (int i = (int)1; i <= (int)(1000000); i++) {       d[i] = 1;     }     for (int i = 0; i < (int)(n); i++) {       int k = 2;       while (a[i] * k <= 1000000) {         d[a[i] * k] = max(d[a[i] * k], d[a[i]] + 1);         k++;       }       res = max(res, d[a[i]]);     }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m[100][100];   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(0);     long n, suma = 0;     cin >> n;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         m[i][j] = 1;       }     }     for (int i = 1; i < n; ++i) {       for (int j = 1; j < n; ++j) {         int x = m[i - 1][j], y = m[i][j - 1];         m[i][j] = x + y;       }     }     cout << m[n - 1][n - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     scanf( %i %i %i %i , &a, &b, &c, &d);     int sum1 = max(3 * a / 10, a - a / 250 * c);     int sum2 = max(3 * b / 10, b - b / 250 * d);     if (sum1 > sum2) {       printf( Misha n );     } else if (sum1 == sum2) {       printf( Tie n );     } else {       printf( Vasya n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   const long long INF = 1e18 + 10;   struct node {     int next, v;   } edge[maxn * 2 + 10];   int cnt, head[maxn], vis[maxn], pa[maxn];   long long sum[maxn], cost[maxn], a[maxn], ss[maxn];   queue<int> q;   int find(int x) {     if (x == pa[x]) return x;     return pa[x] = find(pa[x]);   }   void add2(int x, int y) {     x = find(x);     y = find(y);     pa[x] = y;     ss[y] += ss[x];   }   void dfs(int u, int fa) {     int i, v;     sum[u] = a[u];     for (i = head[u]; i != -1; i = edge[i].next) {       v = edge[i].v;       if (v == fa) continue;       dfs(v, u);       if (sum[v] > 0) sum[u] += sum[v];     }   }   void dfs2(int u, int fa) {     int i, v;     if (u == 1) {       cost[u] = sum[u];       for (i = head[1]; i != -1; i = edge[i].next) {         v = edge[i].v;         dfs2(v, u);       }       return;     }     if (sum[u] <= 0) {       cost[u] = max(sum[u], sum[u] + cost[fa]);     } else {       long long tmp = cost[fa] - sum[u];       if (tmp > 0) {         cost[u] = sum[u] + tmp;         add2(u, fa);       } else {         cost[u] = sum[u];       }     }     for (i = head[u]; i != -1; i = edge[i].next) {       v = edge[i].v;       if (fa == v) continue;       dfs2(v, u);     }   }   void add(int x, int y) {     edge[cnt].next = head[x];     edge[cnt].v = y;     head[x] = cnt++;   }   int main() {     int i, n;     long long ans, ret, s, u, v;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);     }     cnt = 0;     memset(head, -1, sizeof(head));     for (i = 1; i <= n - 1; i++) {       scanf( %d%d , &u, &v);       add(u, v);       add(v, u);     }     for (i = 1; i <= n; i++) {       pa[i] = i;       ss[i] = a[i];     }     dfs(1, -1);     dfs2(1, -1);     ans = -INF;     for (i = 1; i <= n; i++) ans = max(ans, cost[i]);     if (ans <= 0) {       ret = 0;       s = 0;       for (i = 1; i <= n; i++) {         if (ans == cost[i]) {           ret++;           s += ans;         }       }       printf( %I64d %I64d n , s, ret);     } else {       ret = 0;       s = 0;       memset(vis, 0, sizeof(vis));       for (i = 1; i <= n; i++) {         if (ans == cost[i]) {           int tt = find(i);           if (!vis[tt] && ss[tt] == ans) {             ret++;             s += ans;             vis[tt] = 1;           }         }       }       printf( %I64d %I64d n , s, ret);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 10;   const char character[] =  ./  ;   int n, a[N], tag[N], type[N][N];   int main() {     scanf( %d , &n);     for (register int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     int o = 0, r = 0;     for (register int i = 1; i <= n; ++i) {       if (tag[i] || a[i] == i) {         continue;       }       vector<int> cycle;       for (int j = i; !tag[j]; j = a[j]) {         cycle.push_back(j), tag[j] = 1;       }       cycle.push_back(i);       if (!o) {         o = i;         for (register int j = 1; j + 1 < cycle.size(); ++j) {           int a = cycle[j], b = cycle[j + 1];           ++r;           type[r][a] = type[r][b] = 2 - (a < b);         }       } else {         ++r;         type[r][o] = type[r][cycle[1]] = 1;         for (register int j = 1; j + 1 < cycle.size(); ++j) {           int a = cycle[j], b = cycle[j + 1];           ++r;           type[r][a] = type[r][b] = 2 - (a < b);         }         type[r][o] = 2;       }     }     printf( %d n , o ? n - 1 : n);     for (register int i = 1; i <= n; ++i) {       for (register int j = 1; j <= n; ++j) {         printf( %c , character[type[i][j]]);       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, r;   int x[105], y[105];   vector<pair<int, int> > pos, neg;   bool cmp(pair<int, int> p1, pair<int, int> p2) {     return p1.first + p1.second > p2.first + p2.second;   }   int main() {     cin >> n >> r;     for (int i = 0; i < n; i++) {       scanf( %d%d , &x[i], &y[i]);       if (y[i] >= 0)         pos.push_back(pair<int, int>(x[i], y[i]));       else         neg.push_back(pair<int, int>(x[i], y[i]));     }     sort(pos.begin(), pos.end());     sort(neg.begin(), neg.end(), cmp);     for (int i = 0; i < pos.size(); i++) {       if (pos[i].first <= r)         r += pos[i].second;       else {         printf( NO n );         return 0;       }     }     for (int i = 0; i < neg.size(); i++) {       if (neg[i].first <= r)         r += neg[i].second;       else {         printf( NO n );         return 0;       }       if (r < 0) {         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long p;   map<long long, int> m[123];   int main() {     int characters_value[26];     long long i;     for (i = 0; i < 26; i++) cin >> characters_value[i];     string s;     cin >> s;     long long ans = 0;     for (i = 0; i < s.size(); i++) {       ans += m[s[i]][p];       p += characters_value[s[i] -  a ];       m[s[i]][p]++;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {     return {l.first + r.first, l.second + r.second};   }   typedef void (*callback_function)(void);   const long long ZERO = 0LL;   const long long INF64 = 1e18;   const long long INF32 = 1e9;   const long long MOD = 1e9 + 7;   const long double PI = acos(-1.0L);   const long double EPS = static_cast<long double>(1e-9);   long long inv(long long a, long long b) {     if (a != 1) {       return b - (inv(b % a, a) * b) / a;     }     return 1;   }   inline long long Pow(long long a, long long k) {     long long s = 1;     for (; k; k >>= 1) {       k& 1 ? s = 1LL * s * a % MOD : 0;       a = 1LL * a * a % MOD;     }     return s;   }   const long long N = 1e6 + 7;   void input() {}   void output() {}   void preprocess() {}   void debug() {     if (true) {     }   }   void solve() {     preprocess();     long long n;     cin >> n;     pair<long long, long long> a[n];     for (long long i = (0); i < (n); i++) {       long long m;       cin >> m;       long long b[m];       for (long long i = (0); i < (m); i++) {         cin >> b[i];       }       a[i] = pair<long long, long long>(*max_element(b, b + m), m);     }     long long mx = (*max_element(a, a + n)).first;     long long res = 0;     for (long long i = (0); i < (n); i++) {       res += (mx - a[i].first) * a[i].second;     }     cout << res << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     {       input();       solve();       output();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool compare(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }   int main() {     int n, k;     cin >> n >> k;     pair<int, int> power[n];     for (int i = 0; i < n; ++i) {       pair<int, int> a;       int p;       cin >> p;       a.first = p;       if (p % 10 == 0)         a.second = 0;       else         a.second = 10 - p % 10;       power[i] = a;     }     sort(power, power + n, compare);     for (int i = 0; i < n; ++i) {       if (power[i].first != 100) {         k = k - power[i].second;         if (k < 0) break;         power[i].first = power[i].first + power[i].second;       }     }     if (k > 0) {       for (int i = 0; i < n; ++i) {         while (power[i].first < 100 && k >= 10) {           k = k - 10;           power[i].first += 10;         }         if (k < 10) break;       }     }     int res = 0;     for (int i = 0; i < n; ++i) {       res += power[i].first / 10;     }     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[200005];     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     int flag = 0;     for (int i = 0; i < n; i++) {       if (a[i] >= 2) a[i] %= 2;       if (a[i] == 0) continue;       if (i == n - 1) {         flag = 1;         break;       } else {         if (a[i + 1] > 0)           a[i + 1] -= 1;         else           flag = 1;       }     }     if (flag == 1)       printf( NO n );     else       printf( YES n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (1 << 18);   struct segment {    private:     static const int maxn = (1 << 18);     int arr[2 * maxn];     int private_sum(int node, int first, int last, int a, int b) {       if (first >= a && last <= b) return arr[node];       if (a >= last || b <= first) return 0;       int mid = (first + last) / 2;       return private_sum(2 * node, first, mid, a, b) +              private_sum(2 * node + 1, mid, last, a, b);     }       public:     void add(int ja, int megh) {       ja += maxn;       while (ja > 0) {         arr[ja] += megh;         ja /= 2;       }     }     int sum(int first, int last) {       return private_sum(1, maxn, 2 * maxn, maxn + first, maxn + last);     }     int nth(int n) {       int node = 1, zir = maxn;       while (zir > 1) {         if (n < zir / 2 - arr[2 * node]) {           node *= 2;         } else {           n -= zir / 2 - arr[2 * node];           node = 2 * node + 1;         }         zir /= 2;       }       return node - maxn;     }   } p_fir, p_sec, s;   int a[maxn], b[maxn], out[maxn];   void find_ab(int x, int n) {     int fir = a[x], sec = b[x];     p_fir.add(fir, 1);     p_sec.add(sec, 1);     a[x] -= p_fir.sum(0, fir);     b[x] -= p_sec.sum(0, sec);   }   void find_out(int n) {     for (int i = 0; i < n; i++) {       find_ab(i, n);     }     int bgh = 0;     for (int i = n - 1; i >= 0; i--) {       out[i] = bgh + a[i] + b[i];       if (out[i] >= n - i) {         bgh = 1;         out[i] -= (n - i);       } else         bgh = 0;     }     for (int i = 0; i < n; i++) {       out[i] = s.nth(out[i]);       s.add(out[i], 1);     }   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     find_out(n);     for (int i = 0; i < n; i++) cout << out[i] <<    ;     cout << endl;     return 0;   }