malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int SIZE = 20 + 5;   const int Mod = 1e9 + 7;   int inv[SIZE], n;   long long a[SIZE], m, ans;   inline long long read() {     char ch = getchar();     long long f = 1, x = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline int Qpow(int b, int p) {     long long ans = 1, t = b;     for (; p; p >>= 1, t = t * t % Mod)       if (p & 1) ans = ans * t % Mod;     return ans % Mod;   }   inline int C(long long y, int x) {     if (y < 0 || x < 0 || y < x) return 0;     y %= Mod;     if (y == 0 || x == 0) return 1;     int ans = 1;     for (int i = 0; i < x; i++) ans = (long long)ans * (y - i) % Mod;     for (int i = 1; i <= x; i++) ans = (long long)ans * inv[i] % Mod;     return ans;   }   int main() {     for (int i = 1; i <= 20; i++) inv[i] = Qpow(i, Mod - 2);     std::cin >> n >> m;     for (int i = 1; i <= n; i++) a[i] = read();     for (int x = 0; x < (1 << n); x++) {       if (!x)         ans = (ans + C(n + m - 1, n - 1)) % Mod;       else {         long long t = n + m;         int p = 0;         for (int i = 0; i < n; i++) {           if (x >> i & 1) {             p++;             t -= a[i + 1];           }         }         t -= p + 1;         if (p & 1)           ans = (ans - C(t, n - 1)) % Mod;         else           ans = (ans + C(t, n - 1)) % Mod;       }     }     printf( %lld , (ans + Mod) % Mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 1e5 + 5;   int n;   int M[9][2] = {{0, 0},  {-1, -1}, {1, 1},  {0, 1}, {1, 0},                  {0, -1}, {-1, 0},  {1, -1}, {-1, 1}};   int compute(vector<int> Arr, int A0, int A1, int val) {     Arr[0] = A0;     Arr[1] = A1;     int d = Arr[1] - Arr[0];     int ans = val;     for (int i = 2; i < n; i++) {       if (d + Arr[i - 1] != Arr[i]) {         if (d + Arr[i - 1] != Arr[i] + 1) {           if (d + Arr[i - 1] != Arr[i] - 1) {             return -1;           } else {             Arr[i]--;             ans++;           }         } else {           Arr[i]++;           ans++;         }       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int val;     cin >> n;     vector<int> A;     for (int i = 0; i < n; cin >> val, A.push_back(val), i++)       ;     int ans = -1;     for (int i = 0; i < 9; i++) {       int num =           compute(A, A[0] + M[i][0], A[1] + M[i][1], abs(M[i][0]) + abs(M[i][1]));       if (num != -1) {         if (ans == -1)           ans = num;         else           ans = min(ans, num);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   const int N = 200100;   char a[N], b[N];   int cnt[330];   int main() {     int la, lb, i;     long long ans = 0;     scanf( %s%s , a, b);     la = strlen(a), lb = strlen(b);     for (i = 0; i < lb - la; i++) cnt[b[i]]++;     for (i = 0; i < la; i++) {       cnt[b[lb - la + i]]++;       if (a[i] ==  0 )         ans += cnt[ 1 ];       else         ans += cnt[ 0 ];       cnt[b[i]]--;     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int f[1100000], p[1100000], n, m, a[110], b[30], c[30];   char cc;   bool cmp(int a, int b) { return a > b; }   void init() {     scanf( %d , &n);     for (int i = (1); i <= (n); ++i) scanf( %d , &a[i]);     sort(a + 1, a + 1 + n, cmp);     scanf( %d n , &n);     for (int i = (0); i <= (n - 1); ++i) {       scanf( %c%d n , &cc, &b[i]);       c[i] = (cc ==  p );     }     m = (1 << n) - 1;     p[0] = 0;     for (int i = (1); i <= (m); ++i) p[i] = p[i >> 1] + (i & 1);   }   void work() {     int x, y;     f[m] = 0;     for (int i = (m - 1); i >= (0); --i) {       x = p[i];       f[i] = b[x] == 2 ? 100000000 : -100000000;       for (int j = (1); j <= (n); ++j) {         y = 1 << (j - 1);         if (i & y) continue;         if (b[x] == 1) {           if (c[x])             f[i] = max(f[i], a[j] + f[i ^ y]);           else             f[i] = max(f[i], f[i ^ y]);         } else {           if (c[x])             f[i] = min(f[i], f[i ^ y] - a[j]);           else             f[i] = min(f[i], f[i ^ y]);         }       }     }     cout << f[0];   }   int main() {     init();     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> arr(n);     vector<pair<int, int>> sorted_arr(n);     for (int i = 0; i < n; i++) {       cin >> arr[i];       sorted_arr[i] = {arr[i], i};     }     sort(sorted_arr.begin(), sorted_arr.end());     vector<int> pos(n);     for (int i = 0; i < n; i++) {       pos[i] = sorted_arr[i].second;     }     vector<int> next(n), prev(n);     next[n - 1] = n;     for (int i = n - 2; i >= 0; i--) {       int j = i + 1;       while (j < n && arr[i] > arr[j]) {         j = next[j];       }       next[i] = j;     }     prev[0] = -1;     for (int i = 1; i < n; i++) {       int j = i - 1;       while (j >= 0 && arr[i] > arr[j]) {         j = prev[j];       }       prev[i] = j;     }     int ans = 0;     for (int i = 1; i < n - 1; i++) {       if (i - prev[i] < next[i] - i) {         for (int j = prev[i] + 1; j < i; j++) {           int k = pos[arr[i] - arr[j] - 1];           if (i < k && k < next[i]) ans++;         }       } else {         for (int j = next[i] - 1; j > i; j--) {           int k = pos[arr[i] - arr[j] - 1];           if (prev[i] < k && k < i) ans++;         }       }     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     solve();     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   long long s(long long x) {     long long ans = 0;     while (x) ans += x % 10, x /= 10;     return ans;   }   long long solve(long long x) { return x * x + s(x) * x - n; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     long long sq = sqrt(n);     int i;     for (i = sq - 1000000; i <= sq + 1000000; i++) {       if (i > 0)         if (solve(i) == 0) {           cout << i <<   n ;           return 0;         }     }     cout << -1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double y111, y222, yw, xb, yb, r;   double ASIN(double w) {     if (w < -1.0) w = -1.0;     if (w > 1.0) w = 1.0;     return asin(w);   }   int main() {     cin >> y111 >> y222 >> yw >> xb >> yb >> r;     y111 += 1E-9;     y222 -= 1E-9;     double st = yw - r;     double plo = 2 * st - y111, phi = 2 * st - y222;     if (plo > phi) swap(plo, phi);     double D = sqrt(((xb) * (xb)) + ((plo - yb) * (plo - yb)));     double ang = ASIN(r / D);     complex<double> dir = complex<double>(0, plo) - complex<double>(xb, yb);     dir *= polar(1.0, -ang);     double ty = yb + (fabs(xb / dir.real())) * dir.imag();     if (ty < phi - r + 1E-9) {       double X = xb + ((st - yb) / dir.imag()) * dir.real();       printf( %.18lf n , X);     } else       puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double sn = 1e-6;   int n, k;   char arr[55][10];   string s[55];   string res[55];   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n - k + 1; i++) {       scanf( %s , arr[i]);       string st(arr[i]);       s[i] = st;     }     string val =  Aa ;     for (int i = 0; i < n - k + 1; i++) {       if (s[i] ==  NO ) {         if (res[i] !=   ) {           res[i + k - 1] = res[i];           continue;         }         res[i] = val;         res[i + k - 1] = val;         val[1] = val[1] + 1;         if (val[1] >  z ) {           val[0] = val[0] + 1;           val[1] =  a ;         }       }     }     for (int i = 0; i < n; i++) {       if (res[i] ==   ) {         res[i] = val;         val[1] = val[1] + 1;         if (val[1] >  z ) {           val[0] = val[0] + 1;           val[1] =  a ;         }       }     }     for (int i = 0; i < n; i++) {       printf( %s , res[i].c_str());       if (i != n - 1) printf(   );     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string x;     cin >> x;     int y;     if (x.size() == 1) {       y = x[0] -  0 ;       if (!(y % 4))         cout << 4;       else         cout << 0;       return 0;     }     y = x[x.size() - 1] -  0  + ((x[x.size() - 2] -  0 ) * 10);     if (!(y % 4))       cout << 4;     else       cout << 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int min(int a, int b) {     if (a < b)       return a;     else       return b;   }   int main() {     int n, a, b, c, j;     bool t = false;     cin >> n;     for (int i = 0; i < (4); ++i) {       cin >> a >> b;       if (a < 1 || b < 1)         c = n + 1;       else         c = min(a, b);       cin >> a >> b;       if (a < 1 || b < 1)         j = n + 1;       else         j = min(a, b);       if (n >= c + j) {         t = true;         a = i + 1;         break;       }     }     if (t)       cout << a <<     << c <<     << n - c;     else       cout << -1;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 102;   double dp[N][N][N][3];   int vis[N][N][N][3];   double call(int r, int s, int p, int id) {     if (id == 0) {       if (r == 0) return 0;       if (s + p == 0) return 1;     } else if (id == 1) {       if (s == 0) return 0;       if (r + p == 0) return 1;     } else {       if (p == 0) return 0;       if (r + s == 0) return 1;     }     if (vis[r][s][p][id] == 1) return dp[r][s][p][id];     vis[r][s][p][id] = 1;     double ret = 0;     double total = ((r + s + p - 1) * (r + s + p)) / 2;     double pr = ((r * (r - 1)) / 2) / total;     double ps = ((s * (s - 1)) / 2) / total;     double pp = ((p * (p - 1)) / 2) / total;     double prs = (r * s) / total;     double prp = (r * p) / total;     double psp = (s * p) / total;     double prob = pr + ps + pp;     if (r >= 1 and s >= 1) ret = ret + prs * call(r, s - 1, p, id);     if (r >= 1 and p >= 1) ret = ret + prp * call(r - 1, s, p, id);     if (s >= 1 and p >= 1) ret = ret + psp * call(r, s, p - 1, id);     return dp[r][s][p][id] = ret / (1 - prob);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     int r, s, p;     cin >> r >> s >> p;     cout << fixed << setprecision(9) << call(r, s, p, 0) <<              << call(r, s, p, 1) <<     << call(r, s, p, 2) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 3.141592653589793238;   long long powmod(long long a, long long b) {     long long res = 1;     a %= 1000000007;     for (; b; b >>= 1) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;     }     return res;   }   long long fac[1000005];   void factorial(int mx) {     fac[0] = 1ll;     for (int i = 1; i <= mx; i++) {       fac[i] = fac[i - 1] * (long long)i;       fac[i] %= 1000000007;     }   }   int main() {     factorial(1000005 - 5);     int n, m, vol, type;     long long ans, cnt = 1ll;     scanf( %d , &n);     scanf( %d , &m);     vector<vector<int> > vec(m);     for (int i = 0; i < n; i++) {       scanf( %d , &vol);       while (vol--) {         scanf( %d , &type);         vec[type - 1].push_back(i);       }     }     for (int i = 0; i < m; i++) sort(vec[i].begin(), vec[i].end());     sort(vec.begin(), vec.end());     ans = 1ll;     for (int i = 1; i <= m - 1; i++) {       if (vec[i] == vec[i - 1])         ans *= ++cnt;       else         cnt = 1;       ans %= 1000000007;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int ti = 0; ti < t; ti++) {       int n, k;       cin >> n >> k;       vector<int> arr(n);       for (int i = 0; i < n; i++) cin >> arr[i];       sort(arr.begin(), arr.end());       vector<int> weights(k);       for (int i = 0; i < k; i++) cin >> weights[i];       sort(weights.begin(), weights.end());       long long total = 0;       for (int i = n - 1; i >= n - k; i--) {         total += arr[i];       }       int w = 0;       for (int i = k - 1; i >= 0; i--) {         if (weights[i] <= 1) break;         total += arr[w];         w += weights[i] - 1;       }       for (int i = 0; i < k; i++) {         if (weights[i] > 1) break;         total += arr[n - 1 - i];       }       cout << total << endl;     }     return 0;   }
#include <bits/stdc++.h>   long long ago;   using namespace std;   template <class T = long long int>   T nxt() {     T x;     cin >> x;     return x;   }   long long int pw(long long int a, long long int b, long long int mod) {     if (!b) return 1;     if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;     return pw(a * a % mod, b / 2, mod) % mod;   }   const long long int N = 1000 + 10;   const long long int INF = 8e18;   const long long int MOD = 1e9 + 7;   long long int n, m, mark[N];   double dist[N], S[N], Z[N];   vector<pair<long long int, double>> adj[N];   priority_queue<pair<double, long long int>, vector<pair<double, long long int>>,                  greater<pair<double, long long int>>>       pq;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cout << setprecision(15) << fixed;     cin >> n;     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j <= n; j++) {         long long int p = nxt();         if (i == j || p == 0) continue;         adj[j].emplace_back(i, double(p) / 100);       }     }     fill(Z, Z + N, 1.0);     fill(dist, dist + N, INF);     dist[n] = 0;     pq.push({0, n});     while (!pq.empty()) {       long long int u = pq.top().second;       pq.pop();       if (mark[u]) continue;       mark[u] = 1;       for (auto [v, p] : adj[u]) {         if (mark[v]) continue;         S[v] += Z[v] * p * (dist[u] + 1);         Z[v] *= (1 - p);         dist[v] = (S[v] + Z[v]) / (1 - Z[v]);         pq.push({dist[v], v});       }     }     cout << dist[1] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int n;     cin >> n >> s;     vector<int> vec;     for (int i = 0; i < s.length(); ++i) {       if (s[i] ==  B ) {         int res = 0;         while (i < s.length() && s[i] ==  B ) {           ++res;           ++i;         }         vec.push_back(res);         continue;       }     }     cout << vec.size() <<   n ;     for (int i = 0; i < (int)vec.size(); ++i) {       cout << vec[i] <<    ;     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 1e5;   struct NOOD {     int flag;     int l;     int r;     int v;   } num[MaxN + 5];   int ans[MaxN + 5], p[MaxN + 5];   bool ok[MaxN + 5], flag;   int Max;   int n, m;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d%d , &num[i].flag, &num[i].l, &num[i].r, &num[i].v);     }     for (int i = 1; i <= n; i++) ans[i] = -100000000;     for (int i = m; i >= 1; i--) {       if (num[i].flag == 1) {         for (int j = num[i].l; j <= num[i].r; j++) ans[j] -= num[i].v;       } else {         for (int j = num[i].l; j <= num[i].r; j++) {           if (ok[j] && ans[j] < num[i].v) continue;           ans[j] = num[i].v;           ok[j] = 1;         }       }     }     for (int i = 1; i <= n; i++) p[i] = ans[i];     for (int i = 1; i <= m; i++) {       if (num[i].flag == 1) {         for (int j = num[i].l; j <= num[i].r; j++) p[j] += num[i].v;       } else {         Max = -100000000;         for (int j = num[i].l; j <= num[i].r; j++) Max = max(Max, p[j]);         if (Max != num[i].v) flag = 1;       }     }     if (flag)       printf( NO n );     else {       printf( YES n );       for (int i = 1; i <= n; i++) printf( %d  , ans[i]);       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   long long solve() {     long long n, i, j, k;     cin >> n >> k;     long long arr[n];     for (i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     j = 0;     for (i = 0; i < n && arr[i] < 0; i += k) j += 2 * abs(arr[i]);     for (i = n - 1; i >= 0 && arr[i] > 0; i -= k) j += 2 * arr[i];     j -= max(abs(arr[0]), abs(arr[n - 1]));     return j;   }   int main() {     long long t;     cin >> t;     while (t--) cout << solve() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string a, b, tem;     scanf( %d , &n);     a =  <3 ;     for (int i = 0, j = 0; i < n; ++i) {       cin >> tem;       a += tem;       a +=  <3 ;     }     cin >> b;     int len1 = a.length(), po1 = 0, po2 = 0;     int len2 = b.length();     while (1) {       if (po1 == len1) {         printf( yes n );         return 0;       }       if (po2 == len2) {         printf( no n );         return 0;       }       if (a[po1] == b[po2]) po1++;       po2++;     }   }