malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const int MAXN = 1e5 * 5;   const int INF = 1e9 + 7;   using namespace std;   long long f[501][501];   long long a[501][501];   int n, p[501];   long long ans[501];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) cin >> a[i][j];     for (int i = 1; i <= n; i++) cin >> p[i];     for (int t = n; t >= 1; --t) {       int u = p[t];       long long res = 0;       for (int i = t + 1; i <= n; i++) {         int x = p[i];         f[u][x] = a[u][x];         f[x][u] = a[x][u];         for (int j = t + 1; j <= n; j++)           if (i != j) {             int y = p[j];             f[u][x] = min(f[u][x], a[u][y] + f[y][x]);             f[x][u] = min(f[x][u], f[x][y] + a[y][u]);           }       }       for (int i = t + 1; i <= n; i++)         for (int j = t + 1; j <= n; j++) {           int x = p[i], y = p[j];           f[x][y] = min(f[x][y], f[x][u] + f[u][y]);         }       for (int i = t; i <= n; i++)         for (int j = t; j <= n; j++) res += f[p[i]][p[j]];       ans[t] = res;     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mn = 100010;   long long x[mn], y[mn];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld %lld , &x[i], &y[i]);     if (n <= 4) {       printf( YES n );       return 0;     }     bool flag = 0;     for (int i = 1; i <= 2; i++) {       for (int j = i + 1; j <= 3; j++) {         long long a = y[j] - y[i];         long long b = x[i] - x[j];         long long c = y[i] * x[j] - y[j] * x[i];         long long xa, ya, xb, yb;         int t = 0;         int k = 1;         for (k = 1; k <= n; k++) {           if (a * x[k] + b * y[k] + c == 0)             continue;           else {             t++;             if (t == 1)               xa = x[k], ya = y[k];             else if (t == 2)               xb = x[k], yb = y[k];             else               break;           }         }         if (t <= 2) {           flag = 1;           break;         }         long long ta = yb - ya;         long long tb = xa - xb;         long long tc = ya * xb - yb * xa;         bool q = 0;         for (int p = k; p <= n; p++) {           if ((a * x[p] + b * y[p] + c == 0) || ta * x[p] + tb * y[p] + tc == 0)             continue;           else             q = 1;           if (q) break;         }         if (!q) {           flag = 1;           break;         }       }       if (flag) break;     }     if (!flag)       printf( NO n );     else       printf( YES n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   vector<int> divs[N];   vector<int> mult[N];   int mu[N], a[N], n;   int cnt[N];   long long res = 0;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     mu[1] = 1;     for (int i = 1; i < N; i++) {       divs[i].push_back(i);       for (int j = 2 * i; j < N; j += i) {         divs[j].push_back(i);         mu[j] -= mu[i];       }     }     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       for (int e : divs[a[i]]) mult[e].push_back(a[i] / e);     }     for (int i = 1; i < N; i++) {       sort(mult[i].begin(), mult[i].end(),            [](int first, int second) { return first > second; });       stack<int> st;       for (int e : mult[i]) {         int ans = 0;         for (int div : divs[e]) {           ans -= mu[div] * cnt[div];         }         while (ans != 0) {           int u = st.top();           st.pop();           for (int div : divs[u]) {             cnt[div]--;             if (e % div == 0) ans += mu[div];           }           if (ans == 0) res = max(res, 1LL * i * e * u);         }         st.push(e);         for (int div : divs[e]) cnt[div]++;       }       for (int e : mult[i]) {         for (int div : divs[e]) cnt[div] = 0;       }     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   const double PI = acos(-1.0);   int main() {     double n, r;     scanf( %lf%lf , &n, &r);     double p1 = PI / n, p2 = PI / (2 * n), p3 = PI - p1 - p2;     double l3 = r, l2 = l3 / sin(p3) * sin(p2);     double s = l3 * l2 * sin(p1);     printf( %.15f n , n * s);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     int tas[101], cal[101];     int dp1[10001], dp2[10001];     int w1[101][3], w2[101][3];     while ((cin >> n >> k)) {       int s = 0, t = 0;       int sum1 = 0, sum2 = 0, sum = 0;       for (int i = 1; i <= n; ++i) cin >> tas[i];       for (int j = 1; j <= n; ++j) cin >> cal[j];       for (int i = 1; i <= n; ++i) {         int data;         data = tas[i] - k * cal[i];         if (data > 0) {           w1[++s][1] = data;           w1[s][2] = tas[i];           sum1 += data;         } else if (data < 0) {           data = -data;           w2[++t][1] = data;           w2[t][2] = tas[i];           sum2 += data;         } else           sum += tas[i];       }       int max = sum1 <= sum2 ? sum1 : sum2;       int temp = 0;       for (int i = 1; i <= max; ++i) {         memset(dp1, -10000000, sizeof(dp1));         memset(dp2, -10000000, sizeof(dp2));         dp1[0] = dp2[0] = 0;         for (int j = 1; j <= s; ++j) {           for (int v = i; v >= w1[j][1]; --v) {             if (dp1[v] < dp1[v - w1[j][1]] + w1[j][2])               dp1[v] = dp1[v - w1[j][1]] + w1[j][2];           }         }         for (int j = 1; j <= t; ++j) {           for (int v = i; v >= w2[j][1]; --v) {             if (dp2[v] < dp2[v - w2[j][1]] + w2[j][2])               dp2[v] = dp2[v - w2[j][1]] + w2[j][2];           }         }         if (dp1[i] > 0 && dp2[i] > 0) {           if (dp1[i] + dp2[i] > temp) temp = dp1[i] + dp2[i];         }       }       sum += temp;       if (sum == 0)         cout <<  -1  << endl;       else         cout << sum << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, m, k, t, mx;     cin >> t;     while (t--) {       cin >> n >> m >> k;       mx = min(n / k, m);       cout << (m >= mx ? mx - ceil((long double)(m - mx) / (k - 1)) : mx) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   string s =  FESTIVAL ;   long long dp[1010][10];   int a[1010];   int main(void) {     int i, j, k;     dp[0][0] = 1;     for ((i) = 0; (i) < (int)(1000); (i)++)       for ((j) = 0; (j) < (int)(8); (j)++)         for ((k) = 0; (k) < (int)(8); (k)++)           if (j <= k) dp[i + 1][k] = min(dp[i + 1][k] + dp[i][j], (1ll << 60));     long long K;     cin >> K;     for (i = 25; i >= 1; i--) {       a[i] = K / dp[i][7];       K %= dp[i][7];     }     string s;     for ((i) = 0; (i) < (int)(25); (i)++) {       s +=  FESTIVA ;       for ((j) = 0; (j) < (int)(a[i + 1]); (j)++) s +=  L ;     }     cout << s <<     <<  FESTIVAL  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 , c = getchar();     }     return x * f;   }   const int MAXN = 1e5 + 10;   const long long INF = 3e18;   int n;   long long x[MAXN], y[MAXN], z[MAXN], foo, bar, baz;   inline void Min(long long &x, long long y) {     if (x > y) x = y;   }   inline void Max(long long &x, long long y) {     if (x < y) x = y;   }   inline bool check(long long mid) {     static long long L[5], R[5];     for (int i = 1; i <= 4; i++) L[i] = -INF, R[i] = INF;     for (int i = 1; i <= n; i++) {       long long A = x[i], B = y[i], C = z[i];       Max(L[1], A + B + C - mid);       Min(R[1], A + B + C + mid);       Max(L[2], -A + B + C - mid);       Min(R[2], -A + B + C + mid);       Max(L[3], A - B + C - mid);       Min(R[3], A - B + C + mid);       Max(L[4], A + B - C - mid);       Min(R[4], A + B - C + mid);     }     for (int i = 0; i < 2; i++) {       static long long l[5], r[5];       for (int j = 1; j <= 4; j++)         l[j] = ((L[j] & 1) == i) ? L[j] : L[j] + 1,         r[j] = ((R[j] & 1) == i) ? R[j] : R[j] - 1;       long long low = l[2] + l[3] + l[4];       long long high = r[2] + r[3] + r[4];       for (int j = 1; j <= 4; j++)         if (l[j] > r[j]) goto finish;       if (low > r[1] || high < l[1]) goto finish;       l[1] -= low, r[1] -= low;       if (l[1] <= 0) {         foo = l[2];         bar = l[3];         baz = l[4];         return 1;       }       for (int j = 2; j <= 4; j++) r[j] -= l[j];       if (l[1] <= r[2]) {         foo = l[2] + l[1];         bar = l[3];         baz = l[4];         return 1;       }       l[1] -= r[2];       if (l[1] <= r[3]) {         foo = l[2] + r[2];         bar = l[3] + l[1];         baz = l[4];         return 1;       }       l[1] -= r[3];       if (l[1] <= r[4]) {         foo = l[2] + r[2];         bar = l[3] + r[3];         baz = l[4] + l[1];         return 1;       }     finish:;     }     return 0;   }   int main() {     int t = read();     while (t--) {       n = read();       for (int i = 1; i <= n; i++) x[i] = read(), y[i] = read(), z[i] = read();       long long l = 0, r = 3e18, ans = -1;       while (l <= r) {         long long mid = (l + r) >> 1;         if (check(mid))           r = mid - 1, ans = mid;         else           l = mid + 1;       }       assert(ans != -1);       printf( %lld %lld %lld n , (bar + baz) / 2, (foo + baz) / 2,              (foo + bar) / 2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf(101010101010101010LL);   int n;   struct uf {     int par[1005];     uf() {       for (int i(0); i < (n); i++) par[i] = i;     }     int ff(int x) { return par[x] == x ? x : par[x] = ff(par[x]); }     void uu(int x, int y) {       x = ff(x), y = ff(y);       if (x - y) par[x] = y;     }   };   vector<pair<int, int> > edges;   vector<int> eA, eB;   char col[20];   int main() {     cin >> n;     int m;     cin >> m;     edges.resize(m);     uf fA, fB;     for (int id(0); id < (m); id++) {       int x, y;       scanf( %d%d%s , &x, &y, col);       x--, y--;       edges[id] = make_pair(x, y);       if (col[0] ==  S ) {         if (fA.ff(x) == fA.ff(y)) continue;         eA.push_back(id), fA.uu(x, y);       } else {         if (fB.ff(x) == fB.ff(y)) continue;         eB.push_back(id), fB.uu(x, y);       }     }     uf fAB_1;     for (__typeof((eA).end()) it((eA).begin()); it != (eA).end(); ++it) {       int id(*it), x(edges[id].first), y(edges[id].second);       fAB_1.uu(x, y);     }     vector<int> eB_selected;     for (__typeof((eB).end()) it((eB).begin()); it != (eB).end(); ++it) {       int id(*it), x(edges[id].first), y(edges[id].second);       if (fAB_1.ff(x) != fAB_1.ff(y)) {         eB_selected.push_back(id);         fAB_1.uu(x, y);       }     }     uf fAB_2;     int nA(0), nB(((int)(eB_selected).size()));     for (__typeof((eB_selected).end()) it((eB_selected).begin());          it != (eB_selected).end(); ++it) {       int id(*it), x(edges[id].first), y(edges[id].second);       fAB_2.uu(x, y);     }     for (__typeof((eB).end()) it((eB).begin()); it != (eB).end(); ++it)       if (nB < (n - 1) / 2) {         int id(*it), x(edges[id].first), y(edges[id].second);         if (fAB_2.ff(x) != fAB_2.ff(y)) {           eB_selected.push_back(id);           fAB_2.uu(x, y);           nB++;         }       }     vector<int> eA_selected;     for (__typeof((eA).end()) it((eA).begin()); it != (eA).end(); ++it) {       int id(*it), x(edges[id].first), y(edges[id].second);       if (fAB_2.ff(x) != fAB_2.ff(y)) {         eA_selected.push_back(id);         fAB_2.uu(x, y);         nA++;       }     }     if (nA != (n - 1) / 2 || nB != (n - 1) / 2) {       puts( -1 );       return 0;     }     cout << (n - 1) << endl;     vector<int> selected;     for (__typeof((eA_selected).end()) it((eA_selected).begin());          it != (eA_selected).end(); ++it)       selected.push_back(*it);     for (__typeof((eB_selected).end()) it((eB_selected).begin());          it != (eB_selected).end(); ++it)       selected.push_back(*it);     for (__typeof((selected).end()) it((selected).begin());          it != (selected).end(); ++it) {       if (it != (selected).begin()) cout <<    ;       cout << (*it) + 1;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   class SegmentTree {    private:     vector<long long> tree;     vector<long long> lazy;     vector<long long> num;     long long build(long long ind, long long l, long long r) {       if (l == r) {         tree[ind] = num[l];         return tree[ind];       }       tree[ind] = min(build(2 * ind, l, (l + r) / 2),                       build(2 * ind + 1, (l + r) / 2 + 1, r));       return tree[ind];     }     long long rngq(long long ind, long long l, long long r, long long ql,                    long long qr) {       if (lazy[ind] != 0) {         tree[ind] += lazy[ind];         if (l != r) {           lazy[2 * ind + 1] += lazy[ind];           lazy[2 * ind] += lazy[ind];         }         lazy[ind] = 0;       }       if (ql > r || qr < l) return (long long)1e18;       if (ql <= l && qr >= r) {         return tree[ind];       }       return min(rngq(2 * ind, l, (l + r) / 2, ql, qr),                  rngq(2 * ind + 1, (l + r) / 2 + 1, r, ql, qr));     }     long long update(long long ind, long long l, long long r, long long ql,                      long long qr, long long val) {       if (lazy[ind] != 0) {         tree[ind] += lazy[ind];         if (l != r) {           lazy[2 * ind + 1] += lazy[ind];           lazy[2 * ind] += lazy[ind];         }         lazy[ind] = 0;       }       if (ql > r || qr < l) return tree[ind];       if (ql <= l && qr >= r) {         tree[ind] += val;         if (l != r) {           lazy[2 * ind + 1] += val;           lazy[2 * ind] += val;         }         return tree[ind];       }       return tree[ind] =                  min(update(2 * ind, l, (l + r) / 2, ql, qr, val),                      update(2 * ind + 1, (l + r) / 2 + 1, r, ql, qr, val));     }       public:     void buildTree(vector<long long> arr) {       long long n = arr.size();       tree.resize(4 * n);       lazy.resize(4 * n, 0);       num = arr;       build(1, 0, n - 1);     }     long long query(long long l, long long r) {       return rngq(1, 0, num.size() - 1, l, r);     }     void rngup(long long l, long long r, long long val) {       update(1, 0, num.size() - 1, l, r, val);     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     vector<long long> arr(n);     for (int i = 0; i < n; i++) cin >> arr[i];     SegmentTree segtree;     segtree.buildTree(arr);     long long q;     cin >> q;     while (q--) {       long long l, r;       cin >> l >> r;       if (cin.peek() ==   n ) {         if (r < l) {           cout << min(segtree.query(l, n - 1), segtree.query(0, r)) << endl;         } else           cout << segtree.query(l, r) << endl;       } else {         long long val;         cin >> val;         if (r < l) {           segtree.rngup(l, n - 1, val);           segtree.rngup(0, r, val);         } else           segtree.rngup(l, r, val);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   pair<int, int> t[500050];   bitset<2020> P[2020], B[2020];   void solve() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       t[i] = pair<int, int>(x, y);       P[x][y] = 1;     }     for (int i = 1; i <= n; i++) B[i][i] = 1;     for (int i = 1; i <= n; i++) {       int f = -1;       for (int j = i; j <= n; j++)         if (P[j].test(i)) {           f = j;           break;         }       swap(P[f], P[i]);       swap(B[f], B[i]);       for (int j = 1; j <= n; j++)         if (i != j && P[j][i]) {           P[j] ^= P[i];           B[j] ^= B[i];         }     }     for (int i = 0; i < m; i++) {       if (B[t[i].second][t[i].first])         puts( NO );       else         puts( YES );     }   }   int main() {     int Tc = 1;     for (int tc = 1; tc <= Tc; tc++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007;   const int N = 100003;   int ld[N];   int a[N];   void sieve() {     for (int i = 2; i * i < N; ++i)       if (ld[i] == 0)         for (int j = i * i; j < N; j += i)           if (ld[j] == 0) ld[j] = i;     for (int i = 2; i < N; ++i)       if (ld[i] == 0) ld[i] = i;   }   vector<int> p;   vector<int> k;   vector<int> d;   void genDivisors(int i, int x) {     if (i == (int)p.size()) {       d.push_back(x);       return;     }     for (int c = 0; c <= k[i]; ++c) {       genDivisors(i + 1, x);       x *= p[i];     }   }   int expMod(int a, int n) {     int res = 1;     while (n > 0) {       if (n & 1) res = (long long)res * a % M;       n >>= 1;       a = (long long)a * a % M;     }     return res;   }   int main() {     sieve();     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , a + i);     sort(a, a + n);     int res = 0;     for (int x = 1; x <= a[n - 1]; ++x) {       p.clear();       k.clear();       d.clear();       int y = x;       while (y > 1) {         int z = ld[y];         p.push_back(ld[y]);         k.push_back(1);         y /= z;         while (y % z == 0) {           y /= z;           ++k.back();         }       }       genDivisors(0, 1);       sort(d.begin(), d.end());       k.clear();       k.resize(d.size());       for (int i = 0; i < (int)d.size(); ++i)         k[i] = n - (lower_bound(a, a + n, d[i]) - a);       y = 1;       for (int i = 0; i < (int)d.size() - 1; ++i) {         k[i] -= k[i + 1];         y = (long long)y * expMod(i + 1, k[i]) % M;       }       int z =           (expMod(d.size(), k.back()) - expMod((int)d.size() - 1, k.back()) + M) %           M;       y = (long long)y * z % M;       res = (res + y) % M;     }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s;   struct str {     int len;     bool vis;     string pre, suf;     void push_front(char ch) {       if (!len)         vis = 0;       else if (ch ^ pre[0])         vis = ch < pre[0];       pre = ch + pre;       if (len < 2)         suf = ch + suf;       else if (pre.length() > 10)         pre.pop_back();       len++;     }   } ans[100005];   int main() {     int i;     cin >> s;     n = s.length();     ans[n].len = ans[n].vis = 0;     ans[n].pre = ans[n].suf =   ;     s +=  # ;     for (i = n - 1; i >= 0; i--)       if (s[i] ^ s[i + 1])         ans[i] = ans[i + 1], ans[i].push_front(s[i]);       else {         ans[i] = ans[i + 2];         if (s[i] < ans[i].pre[0] || s[i] == ans[i].pre[0] && ans[i].vis) {           ans[i].push_front(s[i]);           ans[i].push_front(s[i]);         }       }     for (i = 0; i < n; i++) {       cout << ans[i].len <<    ;       if (ans[i].len <= 10)         cout << ans[i].pre << endl;       else         cout << ans[i].pre.substr(0, 5) <<  ...  << ans[i].suf << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   long long int n, k;   string s, s1;   void hi() {     for (int i = k; i < s.length(); i++) {       s[i] = s[i - k];     }   }   int main() {     cout.precision(10);     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k >> s;     s1 = s;     hi();     if (s >= s1) {       cout << n << endl;       cout << s;     } else {       bool ok = true;       int i = k - 1;       if (s[i] !=  9 ) {         s[i] = s[i] + 1;         hi();         cout << n << endl;         cout << s;       } else {         s[i] =  0 ;         for (int j = i - 1; j >= 0; j--) {           if (s[j] !=  9 ) {             s[j]++;             ok = false;             hi();             cout << n << endl;             cout << s;             break;           } else {             s[j] =  0 ;           }         }         if (ok) {           cout << n + 1 << endl;           cout << s1[0] + 1;           for (int i = 0; i < n; i++) {             cout <<  0 ;           }         }       }     }     return 0;   }   long long int nChooseR(long long int n, long long int k) {     if (k > n) return 0;     if (k * 2 > n) k = n - k;     if (k == 0) return 1;     long long int result = n;     for (int i = 2; i <= k; ++i) {       result *= (n - i + 1);       result /= i;     }     return result;   }   long long int power(long long int a, long long int b) {     if (b == 1) {       return a % M;     } else {       if (b % 2 == 0)         return (power(a, b / 2) % M * power(a, b / 2) % M) % M;       else         return (((power(a, b / 2) % M * power(a, b / 2) % M) % M) * a % M) % M;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1E5 + 10;   const int inf = 1 << 30;   long long read() {     long long a = 0;     char b = 1, c;     do       if ((c = getchar()) == 45) b = -1;     while (c < 48 || c > 57);     do a = (a << 3) + (a << 1) + (c & 15);     while ((c = getchar()) > 47 && c < 58);     return a * b;   }   void write(long long x, char c) {     if (x < 0) putchar(45), x = -x;     char a[20], s = 0;     do a[++s] = x % 10 | 48;     while (x /= 10);     do putchar(a[s]);     while (--s);     putchar(c);   }   int fa[N], _fa[N];   int find(int x) { return fa[x] ^ x ? fa[x] = find(fa[x]) : x; }   int _find(int x) { return _fa[x] ^ x ? _fa[x] = _find(_fa[x]) : x; }   vector<int> q, _q;   int main() {     int n = read(), y = read(), z = read();     write(n - 1 - max(y, z),   n );     for (int i = 1; i <= n; ++i) fa[i] = _fa[i] = i;     while (y--) {       int u = find(read()), v = find(read());       if (u > v) swap(u, v);       fa[v] = u;     }     while (z--) {       int u = _find(read()), v = _find(read());       if (u > v) swap(u, v);       _fa[v] = u;     }     for (int i = 2; i <= n; ++i) {       int u = find(i), v = _find(i);       if (u ^ 1 && v ^ 1) {         fa[u] = _fa[v] = 1;         printf( %d 1 n , i);       }     }     for (int i = 2; i <= n; ++i) {       if (find(i) == i) q.push_back(i);       if (_find(i) == i) _q.push_back(i);     }     for (int i = min(q.size(), _q.size()); i--;) printf( %d %d n , q[i], _q[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     while (~scanf( %d %d %d , &a, &b, &c)) {       int ans = a + b + c;       ans = max(ans, a * b * c);       ans = max((a + b) * c, ans);       ans = max(a * (b + c), ans);       printf( %d n , ans);     }     return 0;   }