malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int tot[100100];   int maxd = 0;   vector<vector<int> > g;   void dfs(int v, int d, int p) {     maxd = ((maxd < d) ? (d) : (maxd));     tot[d]++;     for (int i = (0); i < (g[v].size()); ++i) {       int to = g[v][i];       if (to != p) {         dfs(to, d + 1, v);       }     }   }   int use[100100];   inline bool check(int k, int w) {     int l = 1, r = 1;     int sum = tot[l];     while (sum < k) {       r++;       sum += tot[r];     }     long long price = 0;     int need = k;     for (int i = r; i >= l; --i) {       int v = ((need < tot[i]) ? (need) : (tot[i]));       use[i] = v;       price += v * 1ll * (r - i);       need -= v;     }     if (price <= w) return true;     while (1) {       if (r == maxd) break;       sum += tot[r + 1];       while (1) {         if (l == r) break;         if (sum - tot[l] >= k) {           price -= (r - l) * 1ll * use[l];           sum -= tot[l];           l++;         } else {           int v = k - (sum - tot[l]);           price -= (r - l) * 1ll * (use[l] - v);           use[l] = v;           break;         }       }       r++;       use[r] = ((tot[r] < k) ? (tot[r]) : (k));       price += k - use[r];       if (price <= w) return true;     }     return false;   }   int main() {     int n, k, p;     scanf( %d%d%d , &n, &k, &p);     g.resize(n);     for (int i = (0); i < (n - 1); ++i) {       int v1, v2;       scanf( %d%d , &v1, &v2);       v1--;       v2--;       g[v1].push_back(v2);       g[v2].push_back(v1);     }     dfs(0, 0, -1);     int res = 0;     int le = 1, ri = ((n - 1 < k) ? (n - 1) : (k));     while (le <= ri) {       int m = (le + ri) / 2;       if (check(m, p)) {         res = m;         le = m + 1;       } else {         ri = m - 1;       }     }     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, e = 0, o = 0;       long long i, j;       long long ans = 0;       string str;       cin >> str;       for (i = 0; i < str.size(); i++) {         if (str[i] ==  0 )           e++;         else           o++;       }       ans = min(o, e);       if (ans % 2 == 1)         cout <<  DA  << endl;       else         cout <<  NET  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2 == 1) {       cout << 0;       return 0;     }     n = n / 2;     if (n % 2 == 0)       cout << n / 2 - 1;     else       cout << n / 2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int mod = 1e9 + 7;   const long long inf = 1e18;   int d, n, m, x[N], p[N], cur, r[N];   long long ans = inf, carry;   pair<int, int> a[N];   int main() {     ios_base::sync_with_stdio(0);     cin >> d >> n >> m;     for (int i = 1; i <= m; i++) cin >> a[i].first >> a[i].second;     vector<int> st;     sort(a + 1, a + m + 1);     for (int i = 1; i <= m; i++) x[i] = a[i].first, p[i] = a[i].second;     for (int i = m; i >= 0; i--) {       r[i] = i;       while (st.size() && p[st.back()] >= p[i]) {         r[i] = r[st.back()];         st.pop_back();       }       st.push_back(i);     }     for (int i = 0, j = 0; i <= m; i++) {       if (cur < 0) {         ans = inf;         break;       }       while (j + 1 <= m && x[j + 1] - x[i] <= n) j++;       if (n >= d - x[i]) {         long long dist = d - x[i];         long long cost = carry;         if (dist > cur) cost += 1ll * (dist - cur) * p[i];         ans = min(ans, cost);       }       if (j < r[i] + 1) {         carry += 1ll * (n - cur) * p[i];         cur = n;       } else {         long long dist = x[r[i] + 1] - x[i];         if (dist > n) dist = n;         if (dist > cur) {           carry += 1ll * (dist - cur) * p[i];           cur = dist;         }       }       cur -= (x[i + 1] - x[i]);     }     if (ans == inf) ans = -1;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 100;   int c[maxn], a[maxn];   int main() {     int n, m, l = 0, ans = 0;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> c[i];     for (int i = 0; i < m; i++) cin >> a[i];     for (int i = 0; i < n; i++)       if (a[l] >= c[i]) {         ans++;         l++;       }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     string s;     cin >> s;     int x = 0, y = 0, pos = 0, coin = 0;     if (s[0] ==  R )       x++;     else       y++;     if (y > x) pos = 2;     if (x > y) pos = 1;     for (int i = 1; i < s.length(); i++) {       if (s[i] ==  R )         x++;       else         y++;       int npos = 0;       if (y > x) npos = 2;       if (x > y) npos = 1;       if (npos != 0 && npos != pos) {         coin++;         pos = npos;       }     }     cout << coin;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int r, x, y, x1, y1;     cin >> r >> x >> y >> x1 >> y1;     double d;     d = pow((((x - x1) * (x - x1)) + ((y - y1) * (y - y1))), 0.5);     cout << ceil(d / (2 * r)) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n, min1, min2, a, b;     cin >> t;     while (t--) {       cin >> n;       long long arr1[n];       long long arr2[n];       for (long long c = 0; c < n; c++) {         cin >> arr1[c];       }       for (long long d = 0; d < n; d++) {         cin >> arr2[d];       }       min1 = arr1[0];       for (long long i = 0; i < n; i++) {         if (min1 > arr1[i]) {           min1 = arr1[i];         }       }       min2 = arr2[0];       for (long long j = 0; j < n; j++) {         if (min2 > arr2[j]) {           min2 = arr2[j];         }       }       long long count = 0;       for (long long k = 0; k < n; k++) {         a = arr1[k] - min1;         b = arr2[k] - min2;         if (a > b) {           count = count + a;         } else {           count = count + b;         }       }       cout << count << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   int a[maxn];   long long s[maxn], ss[maxn];   pair<int, long long> que[maxn];   int tot;   pair<int, long long> operator-(pair<int, long long> b, pair<int, long long> a) {     pair<int, long long> c;     c.first = b.first - a.first;     c.second = b.second - a.second;     return c;   }   bool operator>(pair<int, long long> b, pair<int, long long> a) {     double x = 1.0 * a.second / a.first;     double y = 1.0 * b.second / b.first;     return x > y;   }   int main() {     int i, j, n;     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[n - i + 1]);     }     for (i = 1; i <= n; i++) {       s[i] = s[i - 1] + a[i];       ss[i] = ss[i - 1] + s[i];     }     long long ans = 0;     for (i = n; i >= 1; i--) {       ans = max(ans, (long long)a[i]);       while (tot > 1 && (que[tot - 1] - make_pair(i, ss[i])) >                             (que[tot - 2] - que[tot - 1])) {         tot--;       }       que[tot++] = make_pair(i, ss[i]);       if (tot == 1) {         continue;       }       int le = 0, ri = tot - 2;       int mid;       while (le <= ri) {         mid = (le + ri) / 2;         double x = (que[mid].second - que[mid + 1].second) * 1.0 /                    (que[mid].first - que[mid + 1].first);         if (x >= s[i - 1]) {           ri = mid - 1;         } else           le = mid + 1;       }       ans = max(ans,                 que[le].second - ss[i - 1] - (que[le].first - i + 1) * s[i - 1]);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int row[] = {0, 1, 0, -1, -1, -1, 1, 1};   int col[] = {1, 0, -1, 0, 1, -1, -1, 1};   const long long N = 2e5 + 10;   const long long M = 1e18 + 7;   const long long H = 1e9 + 7;   const long long base = 131;   long long logx(long long a, long long bs) { return log(a) / log(bs); }   long long Max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long Min(long long a, long long b) {     if (a > b) return b;     return a;   }   long long big_mul(long long a, long long b, long long m) {     long long x = 0, y = a % m;     while (b > 0) {       if (b & 1) x = (x + y) % m;       y = (2 * y) % m;       b >>= 1;     }     return x % m;   }   long long big_mod(long long a, long long b, long long m) {     long long x = 1, y = a % m;     while (b > 0) {       if (b & 1) x = (x * y) % m;       y = (y * y) % m;       b >>= 1;     }     return x % m;   }   long long Big_mod(long long a, long long b, long long m) {     long long x = 1, y = a % m;     while (b > 0) {       if (b & 1) x = big_mul(x, y, m);       y = big_mul(y, y, m);       b >>= 1;     }     return x % m;   }   long long mod_inverse(long long a, long long m) { return big_mod(a, m - 2, m); }   long long GCD(long long a, long long b) {     if (!a) return b;     return GCD(b % a, a);   }   double l, r;   vector<double> vec1;   vector<double> vec2;   double fnct(double total, double value) { return total / value; }   bool possible(double x, double m) {     double total = m + x;     double need = fnct(total, vec1[0]);     if (need > x) return false;     x -= need;     total = m + x;     for (int i = 1; i < vec1.size(); i++) {       need = fnct(total, vec2[i]);       if (need > x) return false;       x -= need;       total = m + x;       need = fnct(total, vec1[i]);       if (need > x) return false;       x -= need;       total = m + x;     }     need = fnct(total, vec2[0]);     if (need > x) return false;     return true;   }   void bs(double m) {     l = 0;     r = (double)H;     int cnt = 0;     while (cnt++ <= 100) {       double mid = (l + r) / 2.0;       if (possible(mid, m) == true)         r = mid;       else         l = mid;     }     if (l == H || r == H)       cout <<  -1  << endl;     else       printf( %0.10lf n , l);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     double m;     cin >> m;     for (int i = 0; i < n; i++) {       double a;       cin >> a;       vec1.push_back(a);     }     for (int i = 0; i < n; i++) {       double a;       cin >> a;       vec2.push_back(a);     }     bs(m);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 11;   const long long MOD0 = 1e9 + 7;   const long long P0 = 37;   const long long MOD1 = 1e9 + 9;   const long long P1 = 49;   long long a[N], b[N];   long long h1[2][N], h2[2][N], s[2][N];   long long m, n;   map<int, bool> ans;   int getnext(int pos) {     if (pos > a[n]) return 1e9;     int l = 1, r = n;     while (r - l > 1) {       int mid = (l + r) / 2;       if (a[mid] >= pos)         r = mid;       else         l = mid;     }     if (a[l] >= pos) return l;     return r;   }   int getprev(int pos) {     if (pos < a[1]) return -1e9;     int l = 1, r = n;     while (r - l > 1) {       int mid = (l + r) / 2;       if (a[mid] <= pos)         l = mid;       else         r = mid;     }     if (a[r] <= pos) return r;     return l;   }   bool good0(int l, int r) {     long long hash1 = h1[0][r] - h1[0][l - 1] + MOD0;     hash1 *= s[0][n - r];     hash1 %= MOD0;     long long hash2 = h2[0][l] - h2[0][r + 1] + MOD0;     hash2 *= s[0][l];     hash2 %= MOD0;     if (hash1 == hash2) return true;     return false;   }   bool good1(int l, int r) {     long long hash1 = h1[1][r] - h1[1][l - 1] + MOD1;     hash1 *= s[1][n - r];     hash1 %= MOD1;     long long hash2 = h2[1][l] - h2[1][r + 1] + MOD1;     hash2 *= s[1][l];     hash2 %= MOD1;     if (hash1 == hash2) return true;     return false;   }   bool good(long long x, long long y) {     if (x > y) return true;     if (y < a[1]) return true;     int l = getnext(x), r = getprev(y);     if (l > r) return true;     if (a[l] - x != y - a[r]) return false;     if (l == r) return true;     if (good1(l, r - 1) && good0(l, r - 1)) return true;     return false;   }   bool good(long long p) {     if (ans[p]) return false;     ans[p] = 1;     if (good(0, p) && good(p + 1, m - 1)) return true;     return false;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     for (int i = 1; i < n; i++) b[i] = a[i + 1] - a[i];     s[0][0] = 1;     s[1][0] = 1;     for (int i = 1; i <= n * 2; i++) {       s[0][i] = (s[0][i - 1] * P0) % MOD0;       s[1][i] = (s[1][i - 1] * P1) % MOD1;     }     for (int i = 1; i < n; i++) {       h1[0][i] = (h1[0][i - 1] + b[i] * s[0][i]) % MOD0;       h1[1][i] = (h1[1][i - 1] + b[i] * s[1][i]) % MOD1;     }     for (int i = n - 1; i >= 1; i--) {       h2[0][i] = (h2[0][i + 1] + b[i] * s[0][n - i]) % MOD0;       h2[1][i] = (h2[1][i + 1] + b[i] * s[1][n - i]) % MOD1;     }     vector<int> vv;     for (int i = 1; i <= n; i++) {       long long x = (a[1] + a[i]) % m;       if (good(x)) vv.push_back(x);     }     sort(vv.begin(), vv.end());     cout << vv.size() << endl;     for (int j = 0; j < vv.size(); j++) cout << vv[j] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       vector<int> v;       long long res, me = 0, mf = 0;       for (int i = 0; i < n; i++) {         int c;         cin >> c;         v.push_back(c);       }       long long res1 = 1000000 - v[0];       res = 1000007;       v.push_back(1000000);       for (int i = 0; i < v.size() - 1; i++) {         me = v[i] - 1;         mf = 1000000 - v[i + 1];         if (i == n - 1) {           res = min(res, me);           continue;         }         res = min(res, max(me, mf));       }       cout << min(res, res1) << endl;     }     return 0;   }
#include <bits/stdc++.h>   int n, m, l, x, oo = 1000000007, c[100005], a[100005], b[100005];   long long res = 1, ans;   long long Exp(long long x, long long y) {     long long res = 1;     for (; y; y >>= 1, x = x * x % oo)       if (y & 1) res = res * x % oo;     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &x), c[x]++;     for (int i = 100005 - 5; i; i--) c[i - 1] += c[i];     for (int i = 1; c[i]; i++) {       m = l = 0, res = 1;       for (int j = 1; j * j <= i; j++)         if (i % j == 0) {           a[m++] = j;           if (j * j - i) b[l++] = i / j;         }       while (l--) a[m++] = b[l];       for (int j = 1; j < m; j++) res = res * Exp(j, c[a[j - 1]] - c[a[j]]) % oo;       ans = (ans + res * (Exp(m, c[i]) - Exp(m - 1, c[i]))) % oo;     }     printf( %d n , (ans + oo) % oo);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double EXP = 1e-11;   const int maxn = 2e5 + 10;   int n;   double a[maxn];   double a2[maxn];   double Judge(double x) {     double sum1 = 0.0, sum2 = 0.0, sum3 = 0.0;     for (int i = 1; i <= n; i++) a2[i] = a[i] - x;     for (int i = 1; i <= n; i++) {       sum1 = max(sum1 + a2[i], a2[i]);       sum3 = max(sum3, sum1);     }     for (int i = 1; i <= n; i++) a2[i] = a2[i] * (-1.0);     for (int i = 1; i <= n; i++) {       sum2 = max(sum2 + a2[i], a2[i]);       sum3 = max(sum3, sum2);     }     return sum3;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lf , &a[i]);     double l = -40000.0, r = 40000.0;     while (r - l > EXP) {       double mid = (l + l + r) / 3.0;       double mmid = (l + r + r) / 3.0;       if (Judge(mid) >= Judge(mmid))         l = mid;       else         r = mmid;     }     printf( %.13lf n , min(Judge(l), Judge(r)));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   vector<bitset<7>> score;   vector<bitset<7>> bvec(10);   map<unsigned long, int> bmap;   bool flag = false;   long long ans = 0;   vector<string> anss;   int ccc = 0;   int ans_tab[2001][10][2001];   bool valid(vector<bitset<7>>& s, int cur, int dig, int cnt) {     if (ans_tab[cur][dig][cnt] != -1) return ans_tab[cur][dig][cnt];     ccc++;     bool vld = (score[cur] & bvec[dig]).to_ulong() == score[cur].to_ulong();     if (vld) {       int x = __builtin_popcount((char)(score[cur] ^ bvec[dig]).to_ulong());       if (cnt - x >= 0) {         if (cur == n - 1 && cnt - x == 0) {           flag = true;           return ans_tab[cur][dig][cnt] = true;         } else {           for (int j = 9; j >= 0; j--) {             if (ans_tab[cur][dig][cnt] = valid(s, cur + 1, j, cnt - x)) {               return true;             }           }         }       } else {         return ans_tab[cur][dig][cnt] = false;       }     }     return ans_tab[cur][dig][cnt] = false;   }   void solve() {     memset(ans_tab, -1, sizeof(ans_tab));     cin >> n >> k;     string in;     for (int i = 0; i < n; ++i) {       cin >> in;       score.emplace_back(in);     }     bvec = {bitset<7>( 1110111 ), bitset<7>( 0010010 ), bitset<7>( 1011101 ),             bitset<7>( 1011011 ), bitset<7>( 0111010 ), bitset<7>( 1101011 ),             bitset<7>( 1101111 ), bitset<7>( 1010010 ), bitset<7>( 1111111 ),             bitset<7>( 1111011 )};     for (int i = 0; i < (int)bvec.size(); ++i) {       bmap[bvec[i].to_ulong()] = i;     }     string test =   ;     test =   ;     int cc = k;     for (int j = 9; j >= 0; --j) {       valid(score, 0, j, cc);     }     if (flag) {       for (int i = 0; i < n; ++i) {         for (int j = 9; j >= 0; --j) {           bool vld = (score[i] & bvec[j]).to_ulong() >= score[i].to_ulong();           if (vld) {             int x = __builtin_popcount((char)(score[i] ^ bvec[j]).to_ulong());             if (cc - x >= 0) {               if (ans_tab[i][j][cc]) {                 test += to_string(j);                 cc -= x;                 break;               }             }           }         }       }       cout << test << endl;     } else       cout << -1 << endl;   }   int main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   const int N = 110;   long long dp[N][N][N];   char s[N];   int a[N];   long long f[N];   void update(long long &x, long long y) {     if (y == -1) return;     if (x == -1 || x < y) x = y;   }   bool vis[N][N][N];   long long dfs(int l, int r, int p) {     if (l > r) return a[p];     if (vis[l][r][p]) return dp[l][r][p];     vis[l][r][p] = true;     if (l == r) {       return dp[l][r][p] = f[p + 1];     }     dp[l][r][p] = dfs(l, r - 1, 0) + f[p + 1];     for (int k = l; k < r; k++)       if (s[k] == s[r]) {         update(dp[l][r][p], dfs(l, k, p + 1) + dfs(k + 1, r - 1, 0));       }     return dp[l][r][p];   }   int main() {     int n;     cin >> n;     cin >> (s + 1);     for (int i = 1; i <= n; i++) cin >> a[i];     f[0] = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= i; j++) f[i] = max(f[i], f[i - j] + a[j]);     memset(dp, -1, sizeof(dp));     cout << dfs(1, n, 0) << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   void test_case() {     int n;     cin >> n;     vector<int> arr(n);     for (int i = 0; i < n; i++) cin >> arr[i];     vector<int> l(n), r(n);     l[0] = 1;     for (int i = 1; i < n; i++) {       if (arr[i] > arr[i - 1])         l[i] = l[i - 1] + 1;       else         l[i] = 1;     }     r[n - 1] = 1;     for (int i = n - 2; i >= 0; i--) {       if (arr[i] < arr[i + 1])         r[i] = r[i + 1] + 1;       else         r[i] = 1;     }     int ans = 1;     for (int i = 0; i < n; i++) {       if (i > 0 && i < n - 1 && arr[i + 1] >= arr[i - 1] + 2) {         ans = max(ans, l[i - 1] + r[i + 1] + 1);       }       if (i > 0 && arr[i] <= arr[i - 1]) {         ans = max(ans, 1 + l[i - 1]);       }       if (i < n - 1 && arr[i] >= arr[i + 1]) {         ans = max(ans, 1 + r[i + 1]);       }     }     ans = max(ans, l[n - 1]);     ans = max(ans, r[0]);     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t = 1;     while (t--) test_case();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int sq[504][504], sum[504][504], dp[2][504][504];   int main() {     int n, m;     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     for (int i = 1; i < n + 1; ++i)       for (int j = 1; j < m + 1; ++j) cin >> sq[i][j];     for (int i = 1; i < n + 1; ++i)       for (int j = 1; j < m + 1; ++j)         sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + sq[i][j];     int mx = -1000000000;     for (int i = 1; i < n + 1; ++i) {       for (int j = 1; j < m + 1; ++j) {         int n = i % 2, p = (i - 1) % 2,             len = min(2 * ((i - 1) / 2) + 1, 2 * ((j - 1) / 2) + 1);         dp[n][j][1] = sq[i][j];         for (int k = 3; k <= len; k += 2) {           dp[n][j][k] = sum[i][j] - sum[i - k][j] - sum[i][j - k] +                         sum[i - k][j - k] - dp[p][j - 1][k - 2] -                         sq[i - k + 2][j - k + 1];           mx = max(dp[n][j][k], mx);         }       }     }     cout << mx <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k;     scanf( %lld , &n);     scanf( %lld , &k);     long long int i, j;     long long int val = 0, val1 = 0, val2 = 1;     for (i = 1; i < k; i++) {       val = (val * 10) + 9;       val2 = val2 * 10;     }     val1 = (val * 10) + 9;     long long int arr[n + 5];     long long int brr[n + 5];     long long int m = n / k;     for (i = 0; i < m; i++) {       scanf( %lld , &arr[i]);     }     for (i = 0; i < m; i++) {       scanf( %lld , &brr[i]);     }     long long int tot = 1;     long long int mod = 1e9 + 7;     for (i = 0; i < m; i++) {       long long int t1 = val1 / arr[i];       if (brr[i] != 0) t1++;       long long int t2 = (brr[i] * val2) + val;       long long int t3 = t2 / arr[i];       long long int t4 = (max(0LL, brr[i] * val2 - 1)) / arr[i];       t3 = t3 - t4;       long long int t5 = t1 - t3;       tot *= t5;       tot %= mod;     }     cout << tot <<   n ;   }