malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   const int maxm = 15;   const long long INF = 1e18;   int n, m, k;   int a[maxn];   long long dp[maxn][maxm];   void ReadInput() {     cin >> n >> m >> k;     for (int i = 1; i <= n; ++i) cin >> a[i];   }   void Solve() {     fill_n(&dp[0][0], sizeof(dp) / sizeof(dp[0][0]), -INF);     for (int i = 0; i <= n; ++i) dp[i][10] = 0;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         if (j == 1)           dp[i][j] = max((long long)a[i] - k, dp[i - 1][m] + a[i] - k);         else           dp[i][j] = dp[i - 1][j - 1] + a[i];       }     long long ans = 0;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) ans = max(ans, dp[i][j]);     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     ReadInput();     Solve();   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   char s[maxn], t[maxn];   int nxt[maxn];   void getNxt(int m) {     int i = 1, j = 0;     nxt[0] = 0;     while (i < m) {       if (t[i] == t[j])         nxt[i++] = ++j;       else if (!j)         i++;       else         j = nxt[j - 1];     }   }   int main() {     scanf( %s%s , s, t);     int len1 = strlen(s), len2 = strlen(t);     int len1_0 = 0, len1_1 = 0, len2_0 = 0, len2_1 = 0;     for (int i = 0; i < len1; i++) {       int k = s[i] -  0 ;       if (k == 0)         len1_0++;       else         len1_1++;     }     for (int i = 0; i < len2; i++) {       int k = t[i] -  0 ;       if (k == 0)         len2_0++;       else         len2_1++;     }     getNxt(len2);     int k = nxt[len2 - 1];     if (len1 < len2) {       for (int i = 0; i < len1; i++) cout << s[i];     } else if (len1 == len2) {       if (len1_0 != len2_0 || len1_1 != len2_1) {         for (int i = 0; i < len1; i++) cout << s[i];       } else {         for (int i = 0; i < len1; i++) cout << t[i];       }     } else {       if (len2_0 == 0) {         for (int i = 1; i <= len1_1; i++) {           cout <<  1 ;         }         for (int i = 1; i <= len1_0; i++) {           cout <<  0 ;         }         return 0;       } else if (len2_1 == 0) {         for (int i = 1; i <= len1_1; i++) {           cout <<  1 ;         }         for (int i = 1; i <= len1_0; i++) {           cout <<  0 ;         }         return 0;       }       if (len1_0 < len2_0 || len1_1 < len2_1) {         for (int i = 0; i < len1; i++) cout << s[i];       } else {         if (k == 0) {           int p = min(len1_0 / len2_0, len1_1 / len2_1);           for (int j = 1; j <= p; j++) {             for (int i = 0; i < len2; i++) {               cout << t[i];             }           }           len1_0 = len1_0 - len2_0 * p;           len1_1 = len1_1 - len2_1 * p;           for (int i = 1; i <= len1_0; i++) {             cout <<  0 ;           }           for (int i = 1; i <= len1_1; i++) {             cout <<  1 ;           }         } else {           int f0 = 0, f1 = 0;           for (int i = k; i < len2; i++) {             int p = t[i] -  0 ;             if (p == 0)               f0++;             else               f1++;           }           for (int i = 0; i < len2; i++) {             cout << t[i];           }           len1_0 -= len2_0;           len1_1 -= len2_1;           int p = min(len1_0 / f0, len1_1 / f1);           len1_0 = len1_0 - f0 * p;           len1_1 = len1_1 - f1 * p;           for (int j = 1; j <= p; j++) {             for (int i = k; i < len2; i++) {               cout << t[i];             }           }           for (int i = 1; i <= len1_0; i++) {             cout <<  0 ;           }           for (int i = 1; i <= len1_1; i++) {             cout <<  1 ;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize(2)   #pragma GCC optimize(3)   inline int read() {     int x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = 10 * x + ch -  0 , ch = getchar();     return f ? -x : x;   }   inline long long llread() {     long long x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = 10 * x + ch -  0 , ch = getchar();     return f ? -x : x;   }   long long fact[110], c[110][110];   long long f[110][110][110];   long long n, m, k, P;   signed main() {     n = llread(), m = llread(), k = llread(), P = llread();     c[0][0] = fact[0] = 1;     for (long long i = (1); i <= (n); i++) {       c[i][0] = c[i][i] = 1;       for (long long j = (1); j <= (i - 1); j++)         c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % P;     }     for (long long i = (1); i <= (n); i++) fact[i] = (fact[i - 1] * i) % P;     for (long long i = (0); i <= (n); i++) f[0][i][0] = 1;     for (long long i = (1); i <= (n); i++) {       f[i][1][1] = fact[i];       for (long long j = (i + 1); j <= (n); j++) f[i][j][0] = fact[i];       for (long long j = (2); j <= (min(i, m)); j++) {         for (long long p = (0); p <= (min(i - j + 1, k)); p++) {           f[i][j][p] = (f[i][j][p] + (f[i - 1][j - 1][p - (j == 1)] * 2)) % P;           for (long long q = (2); q <= (i - 1); q++) {             for (long long w = (0); w <= (p - (j == 1)); w++) {               if (f[q - 1][j - 1][w] && f[i - q][j - 1][p - (j == 1) - w]) {                 f[i][j][p] = (f[i][j][p] + f[q - 1][j - 1][w] *                                                f[i - q][j - 1][p - (j == 1) - w] %                                                P * c[i - 1][q - 1]) %                              P;               }             }           }         }       }     }     printf( %lld n , f[n][m][k]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     char now =    ;     int count = 0, sum = 0, n;     n = s.size();     for (int i = 0; i < n; i++) {       if (now == s[i] and count < 5)         count++;       else         sum++, now = s[i], count = 1;     }     cout << sum <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int t[N];   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     t[0] = 0;     t[n + 1] = 0;     for (int i = 1; i <= n; ++i) {       cin >> t[i];       t[i] = min(t[i - 1] + 1, t[i]);     }     for (int i = n; i > 0; --i) {       t[i] = min(t[i + 1] + 1, t[i]);     }     int res = 0;     for (int i = 1; i <= n; ++i) res = max(res, t[i]);     cout << res <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5050;   int c, d;   char ch[N];   int Calc(int b, int e) {     c = 0, d = 0;     int ret = 0, i;     for (i = b; i <= e; i++) {       if (ch[i] ==  ( ) c++;       if (ch[i] ==  ) ) {         if (c)           c--;         else {           if (d > 0)             d--, c++;           else             return ret;         }       }       if (ch[i] ==  ? ) {         if (c)           c--, d++;         else           c++;       }       if (c == 0) {         ret++;       }     }     return ret;   }   int main() {     int n, i, sol = 0;     scanf( %s , ch + 1);     n = strlen(ch + 1);     for (i = 1; i <= n; i++) sol += Calc(i, n);     printf( %i n , sol);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tt = 1;     cin >> tt;     while (tt--) {       int n;       cin >> n;       int A[n];       for (int i = 0; i < n; i++) {         cin >> A[i];       }       int cnt = 0;       sort(A, A + n);       int left, right;       if (n % 2 == 0) {         left = n / 2 - 1;         right = n / 2;       } else {         left = n / 2;         right = n / 2 + 1;       }       while (cnt < n) {         cout << A[left] <<    ;         left--;         cnt++;         if (cnt == n) {           break;         }         cout << A[right] <<    ;         right++;         cnt++;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int INT_MAX_VAL = (int)0x3F3F3F3F;   int INT_MIN_VAL = (int)-0x3F3F3F3F;   long long LONG_MAX_VAL = (long long)0x3F3F3F3F3F3F3F3F;   long long LONG_MIN_VAL = (long long)-0x3F3F3F3F3F3F3F3F;   long long vx, vy, wx, wy;   long long R;   long double t;   bool solve(long double s, long double dx, long double dy) {     if (s <= t) {       dx -= vx * s;       dy -= vy * s;     } else {       dx -= wx * (s - t) + vx * t;       dy -= wy * (s - t) + vy * t;     }     return (dx * dx + dy * dy) <= (R * R * s * s);   }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     cin >> R >> t;     cin >> vx >> vy >> wx >> wy;     long double l = 0;     long double r = 1.0e9;     while ((abs(r - l) / max(1.l, l)) > 1e-9) {       double c = (l + r) / 2;       if (solve(c, x2 - x1, y2 - y1)) {         r = c;       } else {         l = c;       }     }     cout << setprecision(15) << fixed << l <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, c, p[55], t[55], x = 0, L = 0, R = 0;     cin >> n >> c;     for (int i = 0; i < n; i++) {       cin >> p[i];     }     for (int i = 0; i < n; i++) {       cin >> t[i];     }     for (int i = 0; i < n; i++) {       x += t[i];       L += max(0, p[i] - c * x);     }     x = 0;     for (int i = n - 1; i > -1; i--) {       x += t[i];       R += max(0, p[i] - c * x);     }     if (L > R) {       cout <<  Limak  << endl;     } else if (L < R) {       cout <<  Radewoosh  << endl;     } else       cout <<  Tie  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[200005], b[200005];   bool cmp(int a, int b) { return a > b; }   int main() {     long long n;     cin >> n;     for (int i = 0; i < n; ++i) scanf( %I64d , &a[i]);     for (int i = 0; i < n; ++i) scanf( %I64d , &b[i]);     for (long long i = 1; i <= n; ++i) a[i - 1] *= i * (n - i + 1);     sort(a, a + n);     sort(b, b + n, cmp);     long long ans = 0;     for (int i = 0; i < n; ++i) {       ans = (ans + (a[i] % 998244353) * b[i] % 998244353) % 998244353;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> vct;   void DFS(int d, int num) {     if (d == 9) {       return;     } else {       int a = num * 10 + 4;       vct.push_back(a);       DFS(d + 1, a);       int b = num * 10 + 7;       vct.push_back(b);       DFS(d + 1, b);     }   }   long long calc(int a, int b, int l, int r) {     int x = max(a, l);     int y = min(b, r);     if (x > y) {       return 0;     } else {       return y - x + 1;     }   }   int main() {     vct.clear();     DFS(0, 0);     vct.push_back(-1);     vct.push_back(1000000009);     sort(vct.begin(), vct.end());     int ss = vct.size();     int p1, p2, v1, v2;     int k;     while (scanf( %d %d %d %d %d , &p1, &p2, &v1, &v2, &k) != EOF) {       long long ans = 0;       for (int i = 1; i + k < ss; i++) {         int x = vct[i - 1] + 1;         int a = vct[i];         int b = vct[i + k - 1];         int y = vct[i + k] - 1;         long long tmp = 0;         tmp += calc(x, a, p1, p2) * calc(b, y, v1, v2);         tmp += calc(x, a, v1, v2) * calc(b, y, p1, p2);         if (k == 1 && v1 <= a && a <= p2 && tmp > 0) {           tmp--;         }         ans += tmp;       }       double a = 1.0 * ans / (p2 - p1 + 1) / (v2 - v1 + 1);       printf( %.20f n , a);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string a =        What are you doing at the end of the world? Are you busy? Will you save          us? ;   string pref =  What are you doing while sending   ;   string suff =   ? Are you busy? Will you send   ;   string last =   ? ;   long long f[100001];   long long q, n, k, n1, n2, n3, n4;   const long long inf = 1e18 + 10;   char solution(long long n, long long k) {     if (k > f[n]) return  . ;     if (n == 0) return a[k - 1];     if (k <= n2) return pref[k - 1];     k = k - n2;     if (k <= f[n - 1]) return solution(n - 1, k);     k = k - f[n - 1];     if (k <= n3) return suff[k - 1];     k = k - n3;     if (k <= f[n - 1]) return solution(n - 1, k);     k = k - f[n - 1];     if (k <= n4) return last[k - 1];   }   int main() {     n1 = a.length();     n2 = pref.length();     n3 = suff.length();     n4 = last.length();     f[0] = n1;     for (int i = 1; i <= 100000; i++)       f[i] = min(inf, n2 + f[i - 1] + n3 + f[i - 1] + n4);     cin >> q;     while (q > 0) {       cin >> n >> k;       q = q - 1;       cout << solution(n, k);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e9 + 8;   const long double pi = 3.14159265359;   template <class T>   T fac(T n) {     T res = 1, i;     for (i = 2; i <= n; i++) res *= i;     return res;   }   template <class T>   T lcm(T a, T b) {     return (a * b) / __gcd(a, b);   }   template <class T>   T digitsum(T x) {     T sum = 0;     while (x) {       sum += x % 10;       x /= 10;     }     return sum;   }   string tostring(long long a) {     string ans;     while (a) {       ans += char(a % 10 +  0 );       a /= 10;     }     return ans;   }   void nPermute(string str, long long n) {     sort((str).begin(), (str).end());     long long i = 1;     do {       if (i == n) break;       i++;     } while (next_permutation(str.begin(), str.end()));     cout << str << endl;   }   vector<long long> factors(long long n) {     vector<long long> f;     for (long long x = 2; x * x <= n; x++) {       while (n % x == 0) {         f.push_back(x);         n /= x;       }     }     if (n > 1) f.push_back(n);     return f;   }   bool prime(long long n) {     if (n < 2) return false;     for (long long x = 2; x * x <= n; x++)       if (n % x == 0) return false;     return true;   }   long long ncr(long long n, long long k) {     long long res = 1;     if (k > n - k) k = n - k;     for (long long i = 0; i < k; i++) {       res *= (n - i);       res /= (i + 1);     }     return res;   }   tuple<long long, long long, long long> Gcd(long long a, long long b) {     if (b == 0)       return {1, 0, a};     else {       long long x, y, g;       tie(x, y, g) = Gcd(b, a % b);       return {y, x - (a / b) * y, g};     }   }   const long long mod = 1e5;   long long binpow(long long a, long long b, long long m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res % m;   }   void solve() {     long double n, r;     cin >> n >> r;     long double ang1 = 1 / (tan(pi / (2 * n))), ang2 = 1 / (tan(pi / n));     long double ans = (n * r * r) / (ang1 + ang2);     cout << fixed << setprecision(50) << ans << endl;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     solve();     cerr <<  Time elapsed :   << 1.0 * clock() / CLOCKS_PER_SEC <<   sec  n ;   }
#include <bits/stdc++.h>   using namespace std;   int getV(char c) {     if (c >=  0  && c <=  9 ) return c -  0 ;     if (c >=  A  && c <=  Z ) return 10 + c -  A ;     if (c >=  a  && c <=  z ) return 36 + c -  a ;     if (c ==  - ) return 62;     if (c ==  _ ) return 63;   }   int main() {     string s;     cin >> s;     int N = s.length();     long long p3[6 * N + 1];     p3[0] = 1;     for (int i = 1; i < 6 * N + 1; i++) p3[i] = (p3[i - 1] * 3) % 1000000007;     int cnt = 0;     for (int i = 0; i < N; i++) {       int v = getV(s[i]);       for (int j = 0; j < 6; j++)         if ((v & (1 << j)) == 0) cnt++;     }     cout << p3[cnt];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   struct edge   {    int u, v, w;    bool operator < (const edge &oth) const    {     return w < oth.w;    }   } e[N << 1];   int n, m, x, mn = INT_MAX;   long long ans, rem;   struct disjoint_sets_union   {    int fa[N];    int Query(int p)    {     if(fa[p] == p) return p;     return fa[p] = Query(fa[p]);    }       } dsu;   queue<int> que;   set<int> unvised, G[N];   bool vis[N], type[N];   void FindBlocks()   {    for(int i = 1; i <= n; i++) if(!vis[i])    {     que.push(i);     vis[i] = true;     unvised.erase(i);     dsu.fa[i] = i;     while(!que.empty())     {      int u = que.front();      que.pop();      for(set<int>::iterator it = unvised.begin(); it != unvised.end();)      {       int v = *it;       it++;       if(G[u].count(v)) continue;       dsu.fa[v] = u;       unvised.erase(v);       vis[v] = true;       que.push(v);       rem--;      }     }    }   }   int main()   {    ios::sync_with_stdio(false);    cin >> n >> m;    rem = 1LL * n * (n - 1) / 2 - m;    for(int i = 1; i <= n; i++) unvised.insert(i);    for(int i = 1; i <= m; i++)    {     cin >> e[i].u >> e[i].v >> e[i].w;     G[e[i].u].insert(e[i].v);     G[e[i].v].insert(e[i].u);     x ^= e[i].w;    }    sort(e + 1, e + m + 1);    FindBlocks();     for(int i = 1; i <= m; i++)    {     int fau = dsu.Query(e[i].u), fav = dsu.Query(e[i].v);     if(fau != fav)     {      dsu.fa[fau] = fav;      ans += e[i].w;      type[i] = 1; // type 1     }    }    if(rem > 0) return printf( %lld n , ans) && 0;    for(int i = 1; i <= n; i++) dsu.fa[i] = i;    for(int i = 1; i <= m; i++)    {     int fau = dsu.Query(e[i].u), fav = dsu.Query(e[i].v);     if(fau == fav) continue; // type 2     dsu.fa[fau] = fav;     if(!type[i]) { mn = e[i].w; break; } // type 3    }    printf( %lld n , ans + min(x, mn));    return 0;    }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     int n, k, left = 0, i;     long long int temp;     cin >> n >> k;     vector<int> task(k, 0);     vector<pair<int, int>> idl(n, make_pair(0, 0));     for (i = 0; i < n; i++) {       cin >> temp;       task[temp - 1]++;       idl[i].first = temp;     }     for (i = 0; i < k; i++) left += (int)(task[i] == 0);     for (i = 0; i < n; i++) {       cin >> temp;       if (task[idl[i].first - 1] == 1) temp = INT_MAX;       idl[i].second = temp;     }     if (!left) {       cout << 0 << endl;       return 0;     }     sort(idl.begin(), idl.end(),          [](const pair<int, int> &left, const pair<int, int> &right) {            return left.second < right.second;          });     temp = 0;     for (i = 0; i < n && left; i++) {       if (task[idl[i].first - 1] > 1) {         temp += idl[i].second;         task[idl[i].first - 1]--;         left--;       }     }     cout << temp << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  Possible  :  Impossible );     exit(0);   }   void addmod(int &x, int y, int mod = 1000000007) {     x += y;     if (x >= mod) x -= mod;   }   void et() {     puts( -1 );     exit(0);   }   int x[4], y[4];   pair<int, int> ans[4];   int ansVal = (1 << 30);   void ckeck(int len, int bx, int by) {     int d[4];     pair<int, int> tar[4];     for (int(i) = 0; (i) < (int)(4); (i)++) d[i] = i;     tar[0] = {bx, by};     tar[1] = {bx + len, by};     tar[2] = {bx, by + len};     tar[3] = {bx + len, by + len};     do {       bool ok = 1;       int tmp = 0;       for (int(i) = 0; (i) < (int)(4); (i)++) {         int id = d[i];         if (x[id] != tar[i].first && y[id] != tar[i].second) {           ok = 0;           break;         } else if (x[id] == tar[i].first) {           tmp = max(tmp, abs(y[id] - tar[i].second));         } else           tmp = max(tmp, abs(x[id] - tar[i].first));       }       if (!ok) continue;       if (tmp < ansVal) {         ansVal = tmp;         for (int(i) = 0; (i) < (int)(4); (i)++) ans[d[i]] = tar[i];       }     } while (next_permutation(d, d + 4));   }   void fmain() {     ansVal = (1 << 30);     for (int(i) = 0; (i) < (int)(4); (i)++) scanf( %d%d , x + i, y + i);     set<int> ds;     set<int> px, py;     for (int(i) = 0; (i) < (int)(4); (i)++)       for (int j = i + 1; j < 4; j++) {         if (x[i] != x[j]) ds.insert(abs(x[i] - x[j]));         if (y[i] != y[j]) ds.insert(abs(y[i] - y[j]));       }     for (int d : ds) {       for (int(i) = 0; (i) < (int)(4); (i)++) {         for (int j = -d; j <= d; j += d) {           px.insert(x[i] + j);           py.insert(y[i] + j);         }       }     }     for (int d : ds) {       int id[4];       for (int(i) = 0; (i) < (int)(4); (i)++) id[i] = i;       do {         int mxX = -(1 << 30), miX = (1 << 30), mxY = -(1 << 30), miY = (1 << 30);         int tx[4], ty[4];         tx[0] = x[id[0]];         ty[0] = y[id[0]];         tx[1] = x[id[1]] - d;         ty[1] = y[id[1]];         tx[2] = x[id[2]];         ty[2] = y[id[2]] - d;         tx[3] = x[id[3]] - d;         ty[3] = y[id[3]] - d;         for (int(i) = 0; (i) < (int)(4); (i)++) {           mxX = max(mxX, tx[i]);           miX = min(miX, tx[i]);           mxY = max(mxY, ty[i]);           miY = min(miY, ty[i]);         }         px.insert((mxX + miX) / 2);         py.insert((mxY + miY) / 2);       } while (next_permutation(id, id + 4));     }     for (int d : ds)       for (int xx : px)         for (int yy : py) ckeck(d, xx, yy);     if (ansVal == (1 << 30))       puts( -1 );     else {       printf( %d n , ansVal);       for (int(i) = 0; (i) < (int)(4); (i)++)         printf( %d %d n , ans[i].first, ans[i].second);     }   }   int main() {     int t;     cin >> t;     while (t--) fmain();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   void subMain() {     double a, b;     cin >> a >> b;     cout << fixed << (b * b - a * a) / (2 * a);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     subMain();     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;     return 0;   }