malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m;   int f[50][50], mn[50], mx[50];   const int INF = 1e9;   int gm, gg, sm, ss;   long long d[51][51] = {}, nd[51][51];   bool cang[50], cans[50], canb[50];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < (int)(n); ++i)       for (int j = 0; j < (int)(n); ++j) f[i][j] = INF;     for (int i = 0; i < (int)(n); ++i) f[i][i] = 0;     for (int i = 0; i < (int)(m); ++i) {       int from, to, w;       scanf( %d%d%d , &from, &to, &w), --from, --to;       f[from][to] = min(f[from][to], w);       f[to][from] = min(f[to][from], w);     }     scanf( %d%d%d%d , &gm, &gg, &sm, &ss);     for (int k = 0; k < (int)(n); ++k)       for (int i = 0; i < (int)(n); ++i)         for (int j = 0; j < (int)(n); ++j) {           f[i][j] = min(f[i][j], f[i][k] + f[k][j]);         }     for (int i = 0; i < (int)(n); ++i) {       mn[i] = INF, mx[i] = -INF;       for (int j = 0; j < (int)(n); ++j)         if (i != j) {           mn[i] = min(mn[i], f[i][j]);           mx[i] = max(mx[i], f[i][j]);         }     }     long long ans = 0;     for (int gco = 0; gco < (int)(n); ++gco)       for (int bco = 0; bco < (int)(n); ++bco)         if (mn[gco] < mx[bco] || (mn[gco] == mx[bco] && gco < bco)) {           if (gco == bco) continue;           bool ok = true;           for (int i = 0; i < (int)(n); ++i) {             if (i == gco) {               cang[i] = true;               cans[i] = canb[i] = false;             } else if (i == bco) {               canb[i] = true;               cang[i] = cans[i] = false;             } else {               cang[i] = mn[i] < mn[gco] || (mn[i] == mn[gco] && i < gco);               canb[i] = mx[i] > mx[bco] || (mx[i] == mx[bco] && i > bco);               cans[i] = false;               for (int j = 0; j < (int)(n); ++j)                 if (j != i &&                     (f[i][j] > mn[gco] || (f[i][j] == mn[gco] && i > gco)) &&                     (f[i][j] < mx[bco] || (f[i][j] == mx[bco] && i < bco))) {                   cans[i] = true;                   break;                 }               if (!cang[i] && !cans[i] && !canb[i]) {                 ok = false;                 break;               }             }           }           if (!ok) continue;           memset(d, 0, sizeof d);           d[0][0] = 1;           for (int i = 0; i < (int)(n); ++i) {             memset(nd, 0, sizeof nd);             for (int g = 0; g < (int)(gg + 1); ++g)               for (int s = 0; s < (int)(ss + 1); ++s)                 if (d[g][s] != 0) {                   if (cang[i]) {                     nd[g + 1][s] += d[g][s];                   }                   if (cans[i]) {                     nd[g][s + 1] += d[g][s];                   }                   if (canb[i]) {                     nd[g][s] += d[g][s];                   }                 }             memcpy(d, nd, sizeof nd);           }           for (int g = gm; g <= gg; ++g)             for (int s = sm; s <= ss; ++s) {               ans += d[g][s];             }           d[gg][ss] -= ans;         }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool Check(long long A, long long B, long long T1, long long T2) {     if (!A && !B) return !T1 && !T2;     return !((T1 * A + T2 * B) % (A * A + B * B)) &&            !((T2 * A - T1 * B) % (A * A + B * B));   }   int main() {     long long X0, Y0, X1, Y1, X2, Y2;     cin >> X0 >> Y0 >> X1 >> Y1 >> X2 >> Y2;     cout << ((Check(X2, Y2, X1 - X0, Y1 - Y0) ||               Check(X2, Y2, Y1 - X0, -X1 - Y0) ||               Check(X2, Y2, -X1 - X0, -Y1 - Y0) ||               Check(X2, Y2, -Y1 - X0, X1 - Y0))                  ?  YES                   :  NO )          << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     ;     cin.tie(NULL);     ;     int n, b;     double total = 0, maxx = 0;     cin >> n >> b;     double ar[n];     for (int i = 0; i < n; i++) {       cin >> ar[i];       total += ar[i];       maxx = max(maxx, ar[i]);     }     if (b + total < maxx * n) {       cout << -1 << endl;     } else {       double e = (b + total) / n;       for (int i = 0; i < n; i++) {         cout << fixed << setprecision(6) << e - ar[i] << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long n, m;   char s[111111], t[111111];   bool ar[111111];   long long fail[111111], f[111111], ff[111111], dp[111111];   void kmp() {     int i = 0, j = -1;     fail[0] = -1;     while (i < m) {       while (j > -1 && t[i] != t[j]) j = fail[j];       i++, j++;       fail[i] = j;     }     i = 1, j = 0;     while (i <= n) {       while (j > -1 && s[i] != t[j]) j = fail[j];       j++;       if (j == m) ar[i] = 1, j = fail[j];       i++;     }   }   int main() {     scanf( %s , s + 1);     scanf( %s , t);     n = strlen(s + 1);     m = strlen(t);     kmp();     for (int i = 1; i <= n; i++) dp[i] = (ar[i] ? i - m + 1 : dp[i - 1]);     for (int i = 1; i <= n; i++) {       int l = dp[i];       if (l) {         f[i] = (f[i - 1] + l) % mod;         f[i] = (f[i] + ff[l - 1]) % mod;         ff[i] = (ff[i - 1] + f[i]) % mod;       }     }     cout << f[n] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9;   const long long inf64 = 1e18;   const long long MOD = inf + 7;   long long a[100005], p[100005];   long long n, m;   bool check(long long mid) {     long long last = 0;     for (long long i = 0; i < (long long)n; i++) {       if (last == m) return true;       if (p[last] > a[i]) {         while (last < m && p[last] - a[i] <= mid) last++;         continue;       }       long long mn = a[i] - mid;       if (mn > p[last]) return false;       long long id1 =           upper_bound(p, p + m, a[i] + mid - 2 * (a[i] - p[last])) - p;       long long id2 =           upper_bound(p, p + m, a[i] + (mid - (a[i] - p[last])) / 2) - p;       last = max(last, id1);       last = max(last, id2);     }     return (last == m);   }   int32_t main() {     ios::sync_with_stdio(false), cin.tie(nullptr);     ;     cin >> n >> m;     for (long long i = 0; i < (long long)n; i++) cin >> a[i];     for (long long i = 0; i < (long long)m; i++) cin >> p[i];     long long ans, low = 0, high = 1e18, mid;     while (low <= high) {       mid = (low + high) / 2;       if (check(mid)) {         ans = mid;         high = mid - 1;       } else {         low = mid + 1;       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1007, K = 1007, INF = LONG_MAX;   int i, j, n, x, y;   int gcd(int x, int y) {     while (x && y) {       if (x > y)         x %= y;       else         y %= x;     }     return x | y;   }   multiset<int> m;   vector<int> ans;   int main() {     cin >> n;     for (i = 0; i < n * n; i++) {       cin >> x;       m.insert(x);     }     ans.push_back(*--m.end());     m.erase(--m.end());     while (!m.empty()) {       x = *--m.end();       m.erase(--m.end());       for (j = 0; j < ans.size(); j++) {         int v = gcd(x, ans[j]);         m.erase(m.find(v));         m.erase(m.find(v));       }       ans.push_back(x);     }     for (i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e7 + 5;   const int M = 25;   int A[M], B[M], n, m, x, y, cnt;   int dp[M * 4][M * 4];   void Min(int &x, int y) { x = min(x, y); }   int main() {     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> A[i];     for (int i = 0; i < n; ++i) cin >> B[i];     memset(dp, 0x3f, sizeof(dp));     dp[0][0] = 0;     for (int i = 0; i < n * 4; ++i) {       for (int j = 0; j <= n + n; ++j)         if (dp[i][j] <= 1e9) {           Min(dp[i + 1][j + 1], dp[i][j] + A[i % n]);           if (j) Min(dp[i + 1][j - 1], dp[i][j] + B[i % n]);         }     }     if (m <= 3)       cout << dp[n * m][0] << endl;     else       cout << dp[n * 4][0] + (m - 4) / 2 * (dp[n * 4][0] - dp[n * 2][0]) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = 2 * acos(0.0);   const int INF = 0x3f3f3f3f;   const double inf = 1.0 / 0.0;   void solve();   void Adi() {     ios::sync_with_stdio(false);     cin.tie(0);   }   int main() {     Adi();     solve();     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs           <<   n ;     return 0;   }   void solve() {     long long n, x, tt = 0, dis = 0, rem = 0;     char s;     cin >> n >> x;     vector<long long> v;     for (int i = 0; i < n; i++) {       long long q;       cin >> s >> q;       if (s ==  - ) q = -q;       v.push_back(q);     }     for (int i = 0; i < n; i++) {       if (v[i] >= 0)         x += v[i];       else if (v[i] < 0) {         if (x >= abs(v[i]))           x += v[i];         else           dis++;       }     }     cout << x <<     << dis;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, z, t1, t2, t3;     cin >> x >> y >> z >> t1 >> t2 >> t3;     unsigned long long xy, xz;     if (x > y) {       xy = x - y;     } else {       xy = y - x;     }     if (x > z) {       xz = x - z;     } else {       xz = z - x;     }     unsigned long long stair = xy * t1;     unsigned long long lift = (xz + xy) * t2 + t3 * 3;     if (lift > stair) {       cout <<  NO ;     } else {       cout <<  YES ;     }     return 0;   }
#include <bits/stdc++.h>   int mat[1010][1010];   int counts = 0;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) scanf( %d , &mat[i][j]);     }     counts = 0;     for (int i = 1; i <= n; i++) counts += mat[i][i];     counts %= 2;     int m;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int a;       scanf( %d , &a);       if (a == 1 || a == 2) {         int b;         scanf( %d , &b);         mat[b][b] = 1 - mat[b][b];         counts = 1 - counts;       } else         printf( %d , counts);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 20;   int x[maxn], y[maxn];   int main() {     int n, m;     while (cin >> n >> m) {       for (int i = 1; i <= n; i++) scanf( %d , &x[i]);       for (int j = 1; j <= m; j++) scanf( %d , &y[j]);       int ans = 0;       int p1 = 1, p2 = 1;       long long sum1 = 0, sum2 = 0;       while (p1 <= n || p2 <= m) {         if (sum1 <= sum2) {           if (p1 > n) break;           sum1 += x[p1++];         } else {           if (p2 > m) break;           sum2 += y[p2++];         }         if (sum1 == sum2) ans++;       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long w[100005], mon[305], droz[305], wlazi[305], t;   long long dfs(long long co) {     long long x;     if (!droz[co]) return mon[co];     x = dfs(droz[co]);     t -= x;     mon[co] += x;     return mon[co];   }   int main() {     long long n, q, a, b, c, mod = 1000000007;     scanf( %I64d%I64d%I64d , &n, &q, &t);     for (a = 1; a <= n; a++) scanf( %I64d , &mon[a]);     while (q--) {       scanf( %I64d%I64d , &a, &b);       droz[b] = a;       wlazi[a] = 1;     }     for (a = 1; a <= n; a++) {       for (b = droz[a]; b && b != a; b = droz[b])         ;       if (b == a) {         printf( 0 n );         return 0;       }     }     for (a = 1; a <= n; a++)       if (!wlazi[a]) dfs(a);     if (t < 0) {       printf( 0 n );       return 0;     }     w[0] = 1;     for (a = 1; a <= n; a++) {       for (b = mon[a]; b <= t; b++) {         w[b] += w[b - mon[a]];         w[b] %= mod;       }     }     printf( %I64d n , w[t]);     getchar();     getchar();     return 0;   }
#include <bits/stdc++.h>   const bool DEBUG = false;   using namespace std;   const long long maxn = 2e5 + 5;   const long long INF = 1e18 + 1;   const long long M = 1e9 + 7;   const int lg = 21;   int n, m, x[maxn], b[maxn], a[maxn], y[maxn];   vector<pair<int, int> > v;   set<int> s;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> x[i] >> y[i];     for (int i = 0; i < m; i++) cin >> a[i] >> b[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[j] == b[j] or x[i] == y[i]) continue;         if (a[j] == x[i] and b[j] == y[i]) continue;         if (a[j] == y[i] and b[j] == x[i]) continue;         if (a[j] != x[i] and a[j] != y[i] and b[j] != x[i] and b[j] != y[i])           continue;         if (a[j] == x[i] or a[j] == y[i])           s.insert(a[j]);         else           s.insert(b[j]);       }     }     if (s.size() == 1) return cout << (*s.begin()) << endl, 0;     for (int i = 0; i < n; i++) {       vector<int> v;       set<int> s;       for (int j = 0; j < m; j++) {         if (a[j] == b[j] or x[i] == y[i]) continue;         if (a[j] == x[i] and b[j] == y[i]) continue;         if (a[j] == y[i] and b[j] == x[i]) continue;         if (a[j] != x[i] and a[j] != y[i] and b[j] != x[i] and b[j] != y[i])           continue;         if (x[i] == a[j] or x[i] == b[j])           s.insert(x[i]);         else           s.insert(y[i]);       }       if (s.size() > 1) return cout << -1 << endl, 0;     }     for (int i = 0; i < m; i++) {       vector<int> v;       set<int> s;       for (int j = 0; j < n; j++) {         if (a[i] == b[i] or x[j] == y[j]) continue;         if (a[i] == x[j] and b[i] == y[j]) continue;         if (a[i] == y[j] and b[i] == x[j]) continue;         if (a[i] != x[j] and a[i] != y[j] and b[i] != x[j] and b[i] != y[j])           continue;         if (x[j] == a[i] or a[i] == y[j])           s.insert(a[i]);         else           s.insert(b[i]);       }       if (s.size() > 1) return cout << -1 << endl, 0;     }     cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int list[100000];     for (int i = 0; i < n; i++) {       cin >> list[i];     }     int max = 1;     int temp = 1;     for (int i = 0; i < n - 1; i++) {       if (list[i] < list[i + 1]) {         temp++;       } else {         if (max < temp) {           max = temp;         }         temp = 1;       }     }     if (max < temp) {       max = temp;     }     cout << max <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long T, A, B, res;   vector<long long> P;   int main() {     cin >> T >> A >> B;     if (T == 1) {       if (A == 1) {         if (B == 1) {           res = -1;         }       } else {         if (B % A == 0) {           ++res;         }         while (B > 0) {           P.push_back(B % A);           B /= A;         }         long long cp = 1;         for (int i = 0; i < ((int)P.size()); i++) {           A -= P[i] * cp;           cp *= T;         }         if (A == 0) {           ++res;         }       }     } else {       if (A < T) {         if (B == A) {           res = 1;         }       } else if (A == T) {         if (B == A) {           res = 2;         }       } else {         if (A == B) {           ++res;         }         while (B > 0) {           P.push_back(B % A);           B /= A;         }         long long cp = 1;         for (int i = 0; i < ((int)P.size()); i++) {           A -= P[i] * cp;           cp *= T;         }         if (A == 0) {           ++res;         }       }     }     if (res == -1) {       cout <<  inf n ;     } else {       cout << res <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1000 * 1000 * 1000 + 7;   const int N = 1000 * 1000 + 7;   long long a[N];   multiset<long long> st;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) scanf( %I64d , a + i);     long long ans = 0;     for (int i = 0; i < n; ++i) {       if (st.size() > 0) {         if (*st.begin() < a[i]) {           ans += a[i] - *st.begin();           st.erase(st.begin());           st.insert(a[i]);         }       }       st.insert(a[i]);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[200010], cnt, id, k[200010];   double ans = -1, pre[200010];   double f(long long x, long long mid) {     return ((pre[n] - pre[n - x]) + (pre[mid] - pre[mid - x - 1])) / (x * 2 + 1);   }   signed main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     sort(a + 1, a + 1 + n);     for (long long i = 1; i <= n; i++) {       pre[i] = pre[i - 1] + a[i];     }     for (long long i = 1; i <= n; i++) {       long long l = 1, r = min(i - 1, n - i);       long long num = 0;       while (l <= r) {         long long mid = (l + r) / 2;         if (f(mid, i) >= f(mid - 1, i))           l = mid + 1, num = mid;         else           r = mid - 1;       }       if (f(num, i) - (pre[i] - pre[i - 1]) > ans) {         ans = f(num, i) - (pre[i] - pre[i - 1]);         cnt = num, id = i;       }     }     printf( %lld n , 2 * cnt + 1);     for (long long i = id - cnt; i <= id; i++) printf( %lld  , a[i]);     for (long long i = n - cnt + 1; i <= n; i++) printf( %lld  , a[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   const int MAX = 1e5;   const long long MOD = 1e9 + 7;   const long long inf = 1e18;   int a[MAX + 5];   int main() {     ios_base::sync_with_stdio(false);     int n, m, r, i, j;     long long ans = 0;     cin >> n >> m;     a[0] = 1;     for ((i) = (1); (i) <= (m); ++i) cin >> a[i];     i = 0;     while (i < m) {       if (a[i + 1] > a[i])         ans += (a[i + 1] - a[i]);       else if (a[i + 1] < a[i])         ans += (n - a[i] + a[i + 1]);       i++;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   long long n, mx, now, ans;   int main() {     scanf( %lld , &n);     mx = 2 * n - 1;     while (now * 10 + 9 <= mx) now = now * 10 + 9;     for (long long k = now; k <= mx; k += now + 1) {       long long d = max(k - n, 1ll), u = max(k - d, d);       ans += (u - d + 1) / 2;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream &operator<<(ostream &os, pair<T1, T2> &p);   template <class T>   ostream &operator<<(ostream &os, vector<T> &v);   template <class T>   ostream &operator<<(ostream &os, set<T> &v);   template <class T1, class T2>   ostream &operator<<(ostream &os, map<T1, T2> &v);   const long long mod = 100000007;   const int N = 15;   int n, k;   bool check(vector<int> &a, int x) {     bool flag = true;     vector<int> v;     for (int i = 0; i < n; i++) {       if (v.size() == k) break;       if ((int)v.size() % 2) {         v.push_back(a[i]);       } else if (a[i] <= x) {         v.push_back(a[i]);       }     }     if (v.size() == k) {       return true;     }     v.clear();     for (int i = 0; i < n; i++) {       if (v.size() == k) break;       if ((int)v.size() % 2 == 0) {         v.push_back(a[i]);       } else if (a[i] <= x) {         v.push_back(a[i]);       }     }     if (v.size() == k) {       return true;     }     return false;   }   void TEST_CASES(int cas) {     scanf( %d %d , &n, &k);     vector<int> a(n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     int low = *min_element(a.begin(), a.end()),         high = *max_element(a.begin(), a.end());     int ans = -1;     while (low <= high) {       int mid = (low + high) / 2;       ;       ;       if (check(a, mid)) {         high = mid - 1;         ans = mid;       } else {         low = mid + 1;       }     }     printf( %d n , ans);   }   int main() {     int t = 1, cas = 0;     while (t--) {       TEST_CASES(++cas);     }     return 0;   }   template <class T1, class T2>   ostream &operator<<(ostream &os, pair<T1, T2> &p) {     os <<  {  << p.first <<  ,   << p.second <<  }  ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, vector<T> &v) {     os <<  [  ;     for (int i = 0; i < v.size(); i++) {       os << v[i] <<    ;     }     os <<   ] ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, set<T> &v) {     os <<  [  ;     for (T i : v) {       os << i <<    ;     }     os <<   ] ;     return os;   }   template <class T1, class T2>   ostream &operator<<(ostream &os, map<T1, T2> &v) {     for (auto i : v) {       os <<  Key :   << i.first <<   , Value :   << i.second << endl;     }     return os;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int num[maxn];   long long ret;   int n;   void init() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &num[i]);   }   void print() {     for (int i = 1; i < n; i++) {       int j = 0;       for (; j < 30; j++)         if (i + (1 << j) > n) break;       j--;       ret += num[i];       num[i + (1 << j)] += num[i];       printf( %I64d n , ret);     }   }   int main() {     init();     print();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, cont = 0, z = 0, x, n;     int a[] = {1, 3, 6};     cin >> t;     for (int i = 0; i < t; i++) {       cin >> n;       x = n;       while (x > 0) {         x = x / 10;         z++;       }       if (z == 4) {         for (int k = 1; k <= 9; k++) {           if (n % 10 == k) {             cout << k * 10 << endl;           }         }       } else {         for (int j = 0; j < 3; j++) {           if (z == (j + 1)) {             cont += a[j];           }         }         for (int l = 1; l <= 9; l++) {           if (n % 10 == l) {             cout << ((l - 1) * 10) + cont << endl;           }         }       }       cont = 0;       z = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int T = 1;     cin >> T;     while (T--) {       int64_t w, h;       cin >> w >> h;       vector<int64_t> hor1, hor2, ver1, ver2;       int64_t k;       int64_t q;       cin >> k;       for (int i = 0; i < k; ++i) cin >> q, hor1.push_back(q);       cin >> k;       for (int i = 0; i < k; ++i) cin >> q, hor2.push_back(q);       cin >> k;       for (int i = 0; i < k; ++i) cin >> q, ver1.push_back(q);       cin >> k;       for (int i = 0; i < k; ++i) cin >> q, ver2.push_back(q);       cout << max({(hor1.back() - hor1[0]) * h, (hor2.back() - hor2[0]) * h,                    (ver1.back() - ver1[0]) * w, (ver2.back() - ver2[0]) * w})            <<   n ;     }   }