malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 100, inf = 0x3f3f3f3f;   const int mod97 = 1e9 + 7, mod33 = 998244353;   const int drc[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};   struct edge {     int to, cap, dis, nt;   } e[MAX];   int tot, head[555];   int MinCost, MaxFlow;   int n, m, K, Q, H;   int ans[205][205];   int a[105][105];   int b[105];   void add(int x, int y, int cap, int dis) {     e[tot].to = y;     e[tot].cap = cap;     e[tot].dis = dis;     e[tot].nt = head[x];     head[x] = tot;     tot++;   }   bool Bellman_Ford(int S, int T) {     int pre[T + 1], flow[T + 1], dis[T + 1];     bool in[T + 1];     memset(dis, 0x3f, sizeof(dis));     memset(in, 0, sizeof(in));     dis[S] = 0;     flow[S] = inf;     pre[S] = -1;     queue<int> q;     q.push(S);     in[S] = 1;     while (q.size()) {       int tmp = q.front();       q.pop();       in[tmp] = 0;       for (int i = head[tmp]; ~i; i = e[i].nt) {         int j = e[i].to;         if (e[i].cap > 0 && dis[j] > dis[tmp] + e[i].dis) {           dis[j] = dis[tmp] + e[i].dis;           flow[j] = min(flow[tmp], e[i].cap);           pre[j] = i ^ 1;           if (!in[j]) {             q.push(j);             in[j] = 1;           }         }       }     }     if (dis[T] == inf) return 0;     MinCost += dis[T] * flow[T];     MaxFlow += flow[T];     for (int i = T; i > 0; i = e[pre[i]].to) {       if (i > 0 && i < (n << 1 | 1)) {         ans[e[pre[i]].to][i] += flow[T];       }       e[pre[i]].cap += flow[T];       e[pre[i] ^ 1].cap -= flow[T];     }     return 1;   }   void Solve() {     MaxFlow = MinCost = tot = 0;     while (Bellman_Ford(0, n << 1 | 1))       ;     int sum = 0;     for (int i = 1; i <= n; ++i) sum += b[i];     if (sum != MaxFlow) {       puts( NO );       return;     }     puts( YES );     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         printf( %d  , ans[i][j + n] - ans[j + n][i]);       }       puts(  );     }     return;   }   int Main() {     int t = 1;     while (t--) {       while (~scanf( %d%d , &n, &m)) {         memset(head, -1, sizeof(head));         int sum1 = 0;         for (int i = 1; i <= n; ++i) {           int x;           scanf( %d , &x);           sum1 += x;           add(0, i, x, 0);           add(i, 0, 0, 0);           add(i, i + n, inf, 0);           add(i + n, i, 0, 0);         }         for (int i = 1; i <= n; ++i) {           int x;           scanf( %d , &x);           sum1 -= x;           b[i] = x;           add(i + n, n << 1 | 1, x, 0);           add(n << 1 | 1, i + n, 0, 0);         }         for (int i = 1; i <= m; ++i) {           int x, y;           scanf( %d%d , &x, &y);           add(x, y + n, inf, 0);           add(y + n, x, 0, 0);           add(y, x + n, inf, 0);           add(x + n, y, 0, 0);         }         if (sum1) {           puts( NO );           continue;         }         Solve();       }     }     return 0;   }   int main() { return Main(); }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int k = 0, l;     int n = s.length();     if (n <= 20) {       cout <<  1             <<     << n << endl;       cout << s;     } else {       int m;       if (n % 20 == 0)         m = n / 20;       else         m = (n / 20) + 1;       if (n % m == 0) {         cout << m <<     << (n / m) << endl;         for (int i = 0; i < m; i++) {           for (int j = k; j < (n / m) + k; j++) {             cout << s[j];           }           cout <<   n ;           k = k + (n / m);         }       } else {         cout << m <<     << (n / m) + 1 << endl;         l = n % m;         for (int i = 0; i < l; i++) {           for (int j = k; j <= (n / m) + k; j++) {             cout << s[j];           }           cout <<    << endl;           k = k + (n / m) + 1;         }         for (int y = 0; y < (m - l); y++) {           for (int z = k; z < k + (n / m); z++) {             cout << s[z];           }           k = k + n / m;           cout <<  *  << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     string s;     cin >> s;     stack<char> stack;     int left = 0, right = 0, size = 0;     for (int i = 0; i < s.length(); i++) {       stack.push(s[i]);       if (s[i] ==  ( ) {         left++;         continue;       }       if (s[i] ==  )  && left != 0) {         left--;         stack.pop();         continue;       }       if (s[i] ==  )  && left == 0) {         right++;         continue;       }     }     cout << left <<   n ;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   const int maxn = 1000000 + 100;   long long n, ans;   long long inv[maxn], pro[maxn], invpro[maxn];   void Prepare_C() {     inv[1] = 1;     for (int i = 2; i < maxn; ++i) {       inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;     }     pro[0] = invpro[0] = 1;     for (int i = 1; i < maxn; ++i) {       pro[i] = pro[i - 1] * i % MOD;       invpro[i] = invpro[i - 1] * inv[i] % MOD;     }   }   long long get_C(long long n, long long m) {     if (n < m) {       return 0;     }     return pro[n] * invpro[m] % MOD * invpro[n - m] % MOD;   }   long long Lucas(long long n, long long m) {     if (n < MOD && m < MOD) {       return get_C(n, m);     }     long long tmp = get_C(n % MOD, m % MOD);     if (tmp == 0) {       return 0;     }     return tmp * Lucas(n / MOD, m / MOD) % MOD;   }   long long fast_pow(long long x, long long n) {     long long ans;     for (ans = 1; n != 0; n >>= 1) {       if ((n & 1) == 1) {         ans = (ans * x) % MOD;       }       x = (x * x) % MOD;     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     Prepare_C();     while (scanf( %I64d , &n) != EOF) {       ans = 0;       for (long long i = 1; i <= n; ++i) {         long long first = 1;         long long second = 1;         if (i % 2 == 0) {           first = (-1 * first % MOD + MOD) % MOD;           second = first;         }         first = 2 * first % MOD * Lucas(n, i) % MOD *                 fast_pow(3, (n - i) * n + i) % MOD;         long long tmp = ((fast_pow(3, n - i) - 1) % MOD + MOD) % MOD;         tmp = ((fast_pow(tmp, n) - fast_pow(3, (n - i) * n)) % MOD + MOD) % MOD;         second = 3 * second % MOD * Lucas(n, i) % MOD * tmp % MOD;         ans = (ans + first + second) % MOD;       }       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool myfunction(int i, int j) { return (i < j); }   void solve() {     long long n;     cin >> n;     set<long long> st;     long long a;     for (long long int i = 0; i < n; i++) {       cin >> a;       st.insert(a);     }     if (st.size() > 3) {       cout << -1;       return;     } else if (st.size() == 1) {       cout << 0;       return;     } else if (st.size() == 2) {       auto it = st.begin();       int a = *it;       it++;       int b = *it;       if ((a + b) % 2 == 0) {         cout << (b - a) / 2;       } else         cout << (b - a);       return;     } else {       auto it = st.begin();       int a = *it;       it++;       int b = *it;       it++;       int c = *it;       if (c - b != b - a) {         cout <<  -1 ;         return;       } else         cout << b - a;       return;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int test = 1;     while (test--) solve();     return 0;   }
#include <bits/stdc++.h>      using namespace std;      typedef long long ll;   typedef long double ld;   #define int ll      set<int> s;   const int N = 200000 + 7;   const int M = 998244353;      int n;   int a[N], pre[2][N], total[N];      int getsumx(int mod, int l, int r) {     if (l > r) return 0;     return pre[mod][r] - pre[mod][l - 1];   }      int get(int pre, int fin) {     int in = 0;     in = getsumx((pre + 2) % 2, pre + 2, fin + 1);     if (fin + 2 <= n) {       in += total[n] - total[fin + 1];     }     return in;   }      int megasmart(int nn, int vec[]) {     n = nn;     int sol = 0;     int lim = 0;     for (int i = 0; i < n; i++) {       a[i] = vec[i + 1];       lim += a[i];     }     reverse(a, a + n);     for (int i = 1; i <= n; i++) {       for (int m = 0; m <= 1; m++) {         pre[m][i] = pre[m][i - 1];       }       pre[i % 2][i] += a[i - 1];       total[i] = total[i - 1] + a[i - 1];     }     lim--;     lim /= 2;     for (int it = 0; it < 2; it++) {       for (int pre = it; pre < n; pre++) {         int lo = 0, hi = (n - 1 - pre) / 2, first = n + 1;         while (lo <= hi) {           int j = (lo + hi) / 2;           int fin = pre + 2 * j;           bool ok = 0;           if (get(pre, fin) <= lim) {             ok = 1;           }           if (ok) {             first = j;             hi = j - 1;           } else {             lo = j + 1;           }         }         hi = (n - 1 - pre) / 2;         if (first <= hi) {           sol += hi - first + 1;         }         if (n - 4 - pre >= 0) {           lo = 0, hi = (n - 4 - pre) / 2;           first = n + 1;           while (lo <= hi) {             int j = (lo + hi) / 2;             int fin = pre + 2 * j;             bool ok = 0;             if (get(pre, fin) - a[n - 1] <= lim) {               ok = 1;             }             if (ok) {               first = j;               hi = j - 1;             } else {               lo = j + 1;             }           }           hi = (n - 4 - pre) / 2;           if (first <= hi) {             sol += hi - first + 1;           }         }       }       lim -= a[0];     }     lim += 2 * a[0];     {       int in = a[0];       for (int i = 1; i < n; i++) {         in += a[i];         sol += (in <= lim);       }     }     return sol % M;   }      int vec[N];      signed main() {     ios::sync_with_stdio(0); cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 1LL; i <= n; i++) {         cin >> vec[i];       }       cout << megasmart(n, vec) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int in;   int a[105][105];   int b[100000];   int max(int l, int n) {     int m = a[l][0];     int in = 0;     for (int x = 0; x < n; x++) {       if (m < a[l][x]) {         m = a[l][x];         in = x;       }     }     return in;   }   int main() {     int n, m;     cin >> n >> m;     int i, j;     for (i = 0; i < m; ++i)       for (j = 0; j < n; ++j) cin >> a[i][j];     for (j = 0; j < m; ++j) {       b[max(j, n)] += 1;     }     int m1 = b[0];     if (m != 1)       for (i = 1; i < m; ++i) {         if (m1 < b[i]) {           m1 = b[i];           in = i;         }       }     else       in = max(0, n);     cout << (in + 1);   }
#include <bits/stdc++.h>   using namespace std;   int a[51];   int b[51];   int d1[51];   int d2[51];   int main() {     int n, l;     int i, j, k;     cin >> n >> l;     for (i = 1; i <= n; i++) {       cin >> a[i];       if (i >= 2) d1[i] = a[i] - a[i - 1];     }     d1[1] = a[1] + l - a[n];     for (i = 1; i <= n; i++) {       cin >> b[i];       if (i >= 2) d2[i] = b[i] - b[i - 1];     }     d2[1] = b[1] + l - b[n];     int same = 0;     for (i = 1; i <= n; i++) {       int flag = 1;       for (k = 1, j = i; k <= n; j++, k++) {         if (j > n) j = 1;         if (d1[j] != d2[k]) {           flag = 0;           break;         }       }       if (flag == 1) {         same = 1;         break;       }     }     if (same == 1)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i;     cin >> n;     long long int a[n], b[n], c[n + 1], x = n - 1;     for (i = 0; i < n; i++) {       b[i] = 0;       c[i + 1] = 1;     }     c[0] = 1;     for (i = 0; i < n; i++) {       cin >> a[i];       a[i]--;       b[a[i]]++;       if (a[i] == x) {         while (b[x]) {           if (x == 0 && b[x]) {             x = -1;             break;           }           x--;           if (x == 0 && b[x]) {             x = -1;             break;           }         }       }       c[i + 1] += i + 1 - (n - 1 - x);     }     for (i = 0; i <= n; i++) cout << c[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200010, M = 1000010, P = 1e9 + 7;   const int inf = 0x3f3f3f3f;   const int INF = 0xcfcfcfcf;   const double eps = 1e-9, pi = asin(1) * 2;   long long read();   int ADD(int a, int b) { return a + b >= P ? a + b - P : a + b; }   int MINUS(int a, int b) { return a - b < 0 ? a - b + P : a - b; }   int n, k, odd = 0, even = 0;   long long read() {     long long s = 0;     bool flag = false;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) flag = true;     for (;  0  <= ch && ch <=  9 ; ch = getchar())       s = (s << 3) + (s << 1) + (ch ^  0 );     if (flag) return -s;     return s;   }   int main() {     n = read(), k = read();     for (int i = 1; i <= n; i++) {       int x = read();       if (x & 1)         odd++;       else         even++;     }     if (k == 0) {       printf( Daenerys n );       return 0;     }     if (k == n) {       if (odd & 1)         printf( Stannis n );       else         printf( Daenerys n );       return 0;     }     if (n - k & 1) {       if (odd > even) {         if (even <= n - k >> 1) {           if ((odd + even) - (n - k) & 1)             printf( Stannis n );           else             printf( Daenerys n );         } else           printf( Stannis n );       } else {         if (odd <= n - k >> 1)           printf( Daenerys n );         else           printf( Stannis n );       }     } else {       if (odd >= even) {         if (even <= (n - k >> 1)) {           if ((odd + even) - (n - k) & 1)             printf( Stannis n );           else             printf( Daenerys n );         } else           printf( Daenerys n );       } else         printf( Daenerys n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     vector<int> h(n * m + 1), v(m * n + 1);     vector<vector<int> > A(n, vector<int>(m));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> A[i][j];       }     }     for (int i = 0; i < n; i++) {       int a = 0;       for (int j = 0; j < m; j++) {         a = max(a, A[i][j]);       }       h[a] = 1;     }     for (int j = 0; j < m; j++) {       int a = 0;       for (int i = 0; i < n; i++) {         a = max(a, A[i][j]);       }       v[a] = 1;     }     vector<vector<int> > ans(n, vector<int>(m));     int x = -1, y = -1;     queue<pair<int, int> > q;     for (int i = n * m; i >= 1; i--) {       x += h[i];       y += v[i];       if (h[i] || v[i]) {         ans[x][y] = i;       } else {         pair<int, int> v = q.front();         q.pop();         ans[v.first][v.second] = i;       }       if (h[i]) {         for (int j = y - 1; j >= 0; j--) {           q.push({x, j});         }       }       if (v[i]) {         for (int j = x - 1; j >= 0; j--) {           q.push({j, y});         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << ans[i][j] <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long int n, m, a;     cin >> n >> m >> a;     long int colNum = ceil((double)a / (double)(2 * m));     a -= (colNum - 1) * m * 2;     long int rowNum = ceil((double)a / 2);     a -= rowNum * 2;     if (a == 0)       cout << colNum <<     << rowNum <<   R ;     else       cout << colNum <<     << rowNum <<   L ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int pas = 0, tem, tem1;     int n;     cin >> n;     vector<int> parent(n + 1, 0);     int x, y;     vector<vector<int> > s(n + 1, (vector<int>(3)));     for (int i = 1; i <= n; i++) {       cin >> s[i][1] >> s[i][2];     }     for (int i = 1; i <= n; i++) {       if (parent[i] == 0) {         parent[i] = i;         pas++;       }       for (int j = i + 1; j <= n; j++) {         if ((s[i][1] == s[j][1]) || (s[i][2] == s[j][2]))           if (parent[j] == 0)             parent[j] = parent[i];           else {             if (parent[i] != parent[j]) {               tem = parent[j];               tem1 = parent[i];               for (int h = 1; h <= n; h++)                 if (parent[h] == tem) parent[h] = tem1;               pas--;             }           }       }     }     pas--;     cout << pas;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long inf = (1LL << 60);   const double pi = acos(-1);   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   inline void pcas(int ca) { printf( Case %d:  , ca); }   const int maxn = 1e5 + 10;   int nex[maxn];   char s[maxn], t[maxn];   int dp[maxn], cnt[maxn];   int lens, lent;   void kmp() {     nex[0] = -1;     int j = -1;     int i = 0;     while (i < lent) {       while (j != -1 && t[i] != t[j]) j = nex[j];       nex[++i] = ++j;     }   }   int main() {     scanf( %s , s);     scanf( %s , t);     lens = strlen(s), lent = strlen(t);     kmp();     if (lens < lent) {       cout << 0;       return 0;     }     bool flag;     for (int i = lent - 1; i < lens; ++i) {       flag = 1;       for (int j = 0; j < lent; ++j) {         if (s[i - j] != t[lent - j - 1] && s[i - j] !=  ? ) {           flag = 0;           break;         }       }       dp[i] = dp[i - 1];       if (flag) {         cnt[i] = dp[i - lent];         for (int j = nex[lent]; ~j; j = nex[j]) {           cnt[i] = max(cnt[i], cnt[i - lent + j]);         }         cnt[i]++;         dp[i] = max(cnt[i], dp[i]);       }     }     printf( %d n , dp[lens - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const long long INF = 1e9 + 5;   const long long mod = 1e9 + 7;   const double pi = 3.1415926536;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     ios_base::sync_with_stdio(0);     ;     int n, m;     cin >> n >> m;     bool valid = false;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int x;         cin >> x;         if (x == 1 && (i == 0 || j == 0 || i == (n - 1) || j == (m - 1)))           valid = true;       }     }     if (valid)       cout <<  2 n ;     else       cout <<  4 n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, q;       cin >> n >> q;       vector<long long> a(n);       for (long long i = 0; i < n; i++) {         cin >> a[i];       }       long long x = 0, y = 0;       for (long long i = 0; i < n; i++) {         y = max(y, x + a[i]);         x = max(x, y - a[i]);       }       cout << max(x, y) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 100005;   string A;   void solve() {     long long n, mi = 0, pl = 0;     cin >> A;     A =  +  + A;     n = A.size() - 1;     stack<char> s;     for (__typeof((n)) i = (1); i <= (n); i++) {       if (s.empty())         s.push(A[i]);       else if (s.top() == A[i])         s.pop();       else         s.push(A[i]);     }     if (s.empty())       cout <<  Yes  <<   n ;     else       cout <<  No  <<   n ;   }   signed main() {     long long t;     ios_base::sync_with_stdio(false);     t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-7;   double L, R, m1, m2, a, b, l;   double calc(double alp) {     return a * sin(alp) + b * cos(alp) - l * sin(alp) * cos(alp);   }   int main() {     scanf( %lf%lf%lf , &a, &b, &l);     if (a > b) swap(a, b);     if (l <= b) {       printf( %.8lf n , min(l, a));       return 0;     }     L = 0;     R = acos(-1) / 2;     while (R - L > eps) {       m1 = (2 * L + R) / 3;       m2 = (L + 2 * R) / 3;       if (calc(m1) > calc(m2))         L = m1;       else         R = m2;     }     L = min(calc(L), l);     if (L < eps)       puts( My poor head =( );     else       printf( %.8lf n , L);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<vector<int>> v;     v.resize(n, vector<int>(7));     for (int i = 0; i < n; i++) {       for (int j = 0; j < 7; j++) {         scanf( %1d , &v[i][j]);       }     }     int max_rooms = 0, cur = 0;     for (int i = 0; i < 7; i++) {       for (int j = 0; j < n; j++) {         cur += v[j][i];       }       max_rooms = max(max_rooms, cur);       cur = 0;     }     cout << max_rooms << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     long long x[] = {         1,          2,          4,          8,          16,          32,         64,         128,        256,        512,        1024,        2048,         4096,       8092,       16184,      32368,      64736,       129472,         258944,     517888,     1035776,    2071552,    4143104,     8286208,         16572416,   33144832,   66289664,   132579328,  265158656,   530317312,         1060634624, 2121269248, 4242538496, 8485076992, 16970153984, 33940307968};     cin >> a;     cout << x[a] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;   int n, m, g[405][405];   int in[405], dpv[405], dpb[405];   int bfs() {     queue<int> q;     q.push(1);     memset(dpv, 0x3f, sizeof dpv);     dpv[1] = 0;     while (q.size()) {       int u = q.front();       q.pop();       for (int i = 1; i <= n; ++i) {         if (!g[u][i]) continue;         if (dpv[i] == INF) {           dpv[i] = dpv[u] + 1;           q.push(i);         }       }     }     return dpv[n];   }   int bfs2() {     queue<int> q;     q.push(1);     memset(dpb, 0x3f, sizeof dpb);     dpb[1] = 0;     while (q.size()) {       int u = q.front();       q.pop();       in[u] = false;       for (int i = 1; i <= n; ++i) {         if (g[u][i] || dpb[u] + 1 == dpv[i]) continue;         if (dpb[i] == INF) {           dpb[i] = dpb[u] + 1;           q.push(i);         }       }     }     return dpb[n];   }   int main() {     ios_base::sync_with_stdio(0);     while (scanf( %d%d , &n, &m) == 2) {       memset(g, 0, sizeof g);       while (m--) {         int u, v;         scanf( %d%d , &u, &v);         g[u][v] = g[v][u] = 1;       }       int vehicle = bfs();       if (vehicle == INF)         puts( -1 );       else {         int bus = bfs2();         if (bus == INF)           puts( -1 );         else           printf( %d n , max(vehicle, bus));       }     }     return 0;   }