malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int nn = 100005;   const double eps = 1e-10;   struct point {     double x, y;   } a[nn], b[nn];   int n, m, t, l[nn], r[nn];   int h[nn], p[nn];   double R, c[nn];   inline double cp(const point &x, const point &y, const point &z) {     return (x.x - z.x) * (y.y - z.y) - (x.y - z.y) * (y.x - z.x);   }   inline double dis(const point &x, const point &y) {     return sqrt((x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y));   }   inline bool cmp(const point &x, const point &y) {     double z = cp(x, y, a[1]);     if (z > eps) return 1;     if (z < -eps) return 0;     return dis(x, a[1]) < dis(y, a[1]);   }   void init() {     scanf( %d%lf , &n, &R);     for (int i = 1; i <= n; ++i) {       scanf( %lf%lf , &a[i].x, &a[i].y);       if (a[i].y < a[1].y || (a[i].y < a[1].y + eps && a[i].x < a[1].x))         swap(a[i], a[1]);     }     sort(a + 2, a + n + 1, cmp);     b[m = 1] = a[1];     for (int i = 2; i <= n; ++i) {       for (; m > 1 && cp(a[i], b[m], b[m - 1]) > -eps; --m)         ;       b[++m] = a[i];     }   }   inline void change(int x, int y) {     swap(p[h[x]], p[h[y]]);     swap(h[x], h[y]);   }   void up(int x) {     for (; x > 1 && c[h[x]] > c[h[x >> 1]]; x >>= 1) change(x, x >> 1);   }   void down(int x) {     for (int y = x << 1; y <= t; x = y, y = x << 1) {       if (y < t && c[h[y]] < c[h[y + 1]]) ++y;       if (c[h[x]] < c[h[y]])         change(x, y);       else         break;     }   }   inline void calc(int x) {     point y = b[l[x]], z = b[r[x]];     c[x] = dis(y, z) * dis(b[x], y) * dis(b[x], z) / (2 * abs(cp(y, z, b[x])));     up(p[x]);   }   inline double count(int x, int y) {     double z = 2 * asin(dis(b[x], b[y]) / (2 * R));     return R * R / 2 * (z - sin(z));   }   void work() {     for (int i = 1; i <= m; ++i) {       h[i] = p[i] = i;       l[i] = i - 1, r[i] = i + 1;     }     t = m;     l[1] = m;     r[m] = 1;     for (int i = 1; i <= m; ++i) calc(i);     while (c[h[1]] > R) {       int i = h[1];       l[r[i]] = l[i];       r[l[i]] = r[i];       change(1, t--);       down(1);       calc(l[i]);       calc(r[i]);     }     int j = h[1];     double s = count(j, l[j]) + count(j, r[j]);     for (int i = r[j]; r[i] != j; i = r[i])       s += abs(cp(b[i], b[r[i]], b[j])) / 2 + count(i, r[i]);     printf( %.10lf n , s);   }   int main() {     init();     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int k;       cin >> k;       int days[14];       int ones = 0;       for (int i = 0; i < 7; i++) {         cin >> days[i];         if (days[i]) ones++;         days[i + 7] = days[i];       }       int ans = 0;       int left = 0;       if (k % ones == 0) {         ans = 7 * (k / ones - 1);         left = ones;       } else {         ans = 7 * (k / ones);         left = k % ones;       }       int c = 0, mini = INT_MAX;       for (int i = 0; i < 14; i++) {         if (!days[i]) continue;         int c = 0, c2 = 0;         for (int j = i; j < 14; j++) {           if (days[j] == 1) c++;           c2++;           if (c == left) {             mini = min(mini, c2);             break;           }         }       }       cout << mini + ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int c[10000007];   vector<pair<int, int> > x;   int temp;   vector<int> vt;   int main() {     scanf( %d %d %d , &m, &k, &n);     for (int i = 0; i < m; i++) {       scanf( %d , &temp);       c[temp]++;       if (c[temp] > n) {         printf( -1 n );         return 0;       }     }     for (int i = 0; i < k; i++) {       scanf( %d , &temp);       x.push_back(make_pair(temp, i));     }     sort(x.begin(), x.end());     int cur = 0;     int remain = 0;     for (int i = 0; i < k; i++) {       while (cur <= x[i].first) {         remain += n - c[cur];         cur++;       }       if (remain) {         remain--;         vt.push_back(x[i].second);       }     }     printf( %d n , vt.size());     for (int i = 0; i < vt.size(); i++) printf( %d  , vt[i] + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[55][55];   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   int n, T, m;   inline int valid(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }   int cyc[55][55][4][2] = {};   int main(void) {     scanf( %d%d , &n, &T);     for (int i = 0; i < n; i++) scanf( %s , a[i]);     m = strlen(a[0]);     int x = 0, y = 0, DP = 0, CP = 0;     int Cx = -dy[DP] * (CP ? -1 : 1), Cy = dx[DP] * (CP ? -1 : 1);     int Dx = dx[DP], Dy = dy[DP];     for (int step = 1; step <= T; step++) {       while (valid(x + Dx, y + Dy) && a[x + Dx][y + Dy] == a[x][y])         x += Dx, y += Dy;       while (valid(x + Cx, y + Cy) && a[x + Cx][y + Cy] == a[x][y])         x += Cx, y += Cy;       if (cyc[x][y][DP][CP]) {         int ii = step - cyc[x][y][DP][CP];         while (step + ii <= T) step += ii;       } else         cyc[x][y][DP][CP] = step;       if (!valid(x + Dx, y + Dy) || a[x + Dx][y + Dy] ==  0 ) {         if (CP == 0)           CP = 1;         else if (CP == 1) {           DP = (DP + 1) % 4;           CP = 0;         }         Cx = -dy[DP] * (CP ? -1 : 1), Cy = dx[DP] * (CP ? -1 : 1);         Dx = dx[DP], Dy = dy[DP];       } else         x += Dx, y += Dy;     }     printf( %c n , a[x][y]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int f = 1, r = 0;     char ch = getchar();     while (!isdigit(ch)) f ^= ch ==  - , ch = getchar();     while (isdigit(ch)) r = (r << 1) + (r << 3) + (ch ^ 48), ch = getchar();     return f ? r : -r;   }   const int N = 3005, M = 305;   int n, m, cnt[N];   double f[M][N], g[N], d[N], sv[N], siv[N], val[N];   double ans, p[N][M];   inline void upd(int x) {     memcpy(g, f[x], sizeof(g));     f[x][0] = 0;     for (int i = 1; i <= n; i++)       f[x][i] = f[x][i - 1] * (1 - p[i][x]) + g[i - 1] * p[i][x];     cnt[x]++, sv[x] += f[x][n];     siv[x] += f[x][n] * cnt[x];     double E = siv[x] + cnt[x] * (1 - sv[x]);     d[x] = E - val[x], val[x] = E;   }   int main() {     n = read(), m = read();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) p[i][j] = read() / 1000.;     for (int i = 1; i <= m; i++) {       f[i][0] = 1;       for (int j = 1; j <= n; j++) f[i][j] = f[i][j - 1] * (1 - p[j][i]);       sv[i] = f[i][n], upd(i);     }     for (int i = 1; i <= n; i++) {       int k = 0;       for (int j = 1; j <= m; j++)         if (d[k] < d[j]) k = j;       if (!k) break;       ans += d[k], upd(k);     }     return printf( %.12lf n , ans), 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[101], b[101], z[101], x, s, k, i, j;   int main() {     cin >> n >> m;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= m; i++) {       cin >> b[i];       s += b[i];     }     for (i = 1; i <= n - s + 1; i++) {       for (k = i; k <= i + s - 1; k++) z[a[k]]++;       for (j = 1; j <= 100; j++)         if (z[j] != b[j]) {           x = 1;           break;         }       if (x == 0) {         cout <<  YES ;         return 0;       }       x = 0;       memset(z, 0, 101 * sizeof(int));     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   long long cacu(long long l, long long r) {     return (r + l) / 2 * ((r - l) / 2 + 1);   }   int main() {     int q, l, r;     scanf( %d , &q);     while (q--) {       long long ans;       scanf( %d%d , &l, &r);       ans = cacu(l + (l & 1), r - (r & 1));       ans -= cacu(l | 1, r - !(r & 1));       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   template <typename T>   void chmin(T &x, const T &y) {     if (x > y) x = y;   }   template <typename T>   void chmax(T &x, const T &y) {     if (x < y) x = y;   }   template <typename T>   T gcd(T x, T y) {     return y ? gcd(y, x % y) : x;   }   const int mod = 998244353;   template <typename T>   void Mod(T &x) {     while (x >= mod) x -= mod;   }   long long qk(long long x, long long y) {     long long r = 1;     for (; y; y >>= 1) {       if (y & 1) r = (r * x) % mod;       x = (x * x) % mod;     }     return r;   }   map<int, vector<int>> dps;   int cal(int a, int b, int c, int d) {     int x = d + b - a;     if (x < 0) return 0;     int k = d + c;     chmin(x, k);     if (dps.count(k)) return dps[k][x];     auto &dp = dps[k];     dp.resize(k + 1);     int t = 0, w = 1;     for (int i = 0; i <= k; ++i) {       Mod(t += w);       dp[i] = t;       w = (long long)w * (k - i) % mod;       w = (long long)w * qk(i + 1, mod - 2) % mod;     }     return dp[x];   }   void solve(int times) {     string s;     cin >> s;     int n = s.length();     int a = 0, b = 0, c = 0, d = 0;     for (int i = 0; i < n; ++i) {       if (s[i] ==  ) )         ++b;       else if (s[i] ==  ? )         ++d;     }     long long ans = 0;     for (int i = 0; i < n; ++i) {       if (s[i] ==  ( ) {         ++a;       } else if (s[i] ==  ? ) {         ++c;         --d;       } else if (s[i] ==  ) ) {         --b;       }       if (s[i] ==  ( ) {         Mod(ans += cal(a, b, c, d));       } else if (s[i] ==  ? ) {         ++a;         --c;         Mod(ans += cal(a, b, c, d));         ++c;         --a;       }     }     cout << ans << endl;   }   void Init() {}   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int times = 1;     {       solve(times++);       Init();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   const double EPS = 1e-10;   const double PI = acos(-1.0);   const int INF = 1 << 29;   const int mod = 1000000007;   const int MAX_V = 1000 + 10;   const int MAX_M = 10000 + 10;   const int maxm = 1 + 5;   const int maxn = 50000 + 5;   int used[20];   int n;   int main() {     scanf( %d , &n);     int i, j, sum = 0, a;     memset(used, 0, sizeof(used));     for (int i = 0; i < n; i++) {       scanf( %d , &a);       sum += a;       used[a]++;     }     if (used[0] == 0)       cout << -1 << endl;     else {       int flag = 0;       if (sum % 3 == 1) {         if (used[1] + used[4] + used[7]) {           for (int i = 1; i <= 7; i += 3) {             if (used[i]) {               used[i]--, sum -= i;               break;             }           }         } else if (used[2] + used[5] + used[8] >= 2) {           for (j = 1, i = 2; i <= 8; i += 3) {             while (used[i] && j <= 2) used[i]--, sum -= i, j++;           }         }       }       if (sum % 3 == 2) {         if (used[2] + used[5] + used[8]) {           for (i = 2; i <= 8; i += 3)             if (used[i]) {               used[i]--, sum -= i;               break;             }         } else if (used[1] + used[4] + used[7] >= 2) {           for (j = 1, i = 1; i <= 7; i += 3)             while (used[i] && j <= 2) used[i]--, sum -= i, j++;         } else           flag = 1;       }       if (!flag) {         if (used[1] + used[2] + used[3] + used[4] + used[5] + used[6] + used[7] +             used[8] + used[9]) {           for (i = 9; i >= 0; i--)             while (used[i]--) printf( %d , i);           printf(  n );         } else           printf( 0 n );       } else         printf( 0 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   list<int> adj[1000005];   int T[1000005];   bool visited[1000005];   bool uniq[1000005];   int rev[10000005];   void dfs(int v) {     visited[v] = true;     for (list<int>::iterator it = adj[v].begin(); it != adj[v].end(); it++) {       if (!visited[*it]) dfs(*it);     }   }   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main() {     scanf( %d , &N);     for (int i = 0; i < (N); i++) scanf( %d , &T[i]);     sort(T, T + N);     T[N] = -1;     for (int i = 0; i < (10000001); i++) rev[i] = N;     for (int i = 0; i < (N); i++) rev[T[i]] = i;     int temp[3];     int v[3];     for (int i = 1; i <= 5000; i += 2)       for (int j = 2; i * i + j * j <= T[N - 1]; j += 2) {         if (gcd(i, j) > 1) continue;         temp[0] = abs(i * i - j * j);         temp[1] = i * i + j * j;         temp[2] = 2 * i * j;         for (int t = 0; t < (3); t++) v[t] = rev[temp[t]];         for (int u = 0; u < (3); u++)           for (int s = 0; s < (u); s++) {             if ((T[v[u]] == temp[u]) && (T[v[s]] == temp[s])) {               adj[v[u]].push_back(v[s]);               adj[v[s]].push_back(v[u]);             }           }       }     for (int i = 1; i <= T[N - 1]; i += 2)       for (int j = 2; i * j <= T[N - 1]; j += 2) {         if (gcd(i, j) > 1) continue;         long long int L1 = abs(i * (long long int)i - j * (long long int)j);         long long int L2 = 2 * i * j;         if (L1 > 10000000 || L2 > 10000000) continue;         int v1 = rev[L1];         int v2 = rev[L2];         if ((T[v1] == L1) && (T[v2] == L2)) {           adj[v1].push_back(v2);           adj[v2].push_back(v1);         }       }     for (int i = 0; i < (N); i++) visited[i] = false;     int result = 0;     for (int i = 0; i < (N); i++)       if (!visited[i]) {         result++;         dfs(i);       }     printf( %d n , result);   }
#include <bits/stdc++.h>   using namespace std;   int n;   void solve() {     if (n <= 3)       printf( NO n );     else if (n == 4) {       printf( YES n );       printf( 2 * 3 = 6 n );       printf( 6 * 4 = 24 n );       printf( 24 * 1 = 24 n );     } else if (n == 5) {       printf( YES n );       printf( 1 + 5 = 6 n );       printf( 3 - 2 = 1 n );       printf( 6 * 1 = 6 n );       printf( 6 * 4 = 24 n );     } else if (n >= 6) {       printf( YES n );       printf( 3 - 2 = 1 n );       printf( 1 - 1 = 0 n );       printf( 4 * 6 = 24 n );       printf( 5 * 0 = 0 n );       int i = 7;       while (i <= n) {         printf( %d * 0 = 0 n , i);         i++;       }       printf( 24 + 0 = 24 n );     } else       printf( NO n );   }   int main() {     while (scanf( %d , &n) != EOF) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = LONG_LONG_MAX;   const long long NINF = LONG_LONG_MIN;   const long long mmod = 1000000007;   int32_t main() {     long long k;     cin >> k;     while (k-- > 0) {       long long n;       cin >> n;       string s, t;       cin >> s >> t;       vector<long long> cnt(26, 0);       for (long long i = 0; i < n; i++) {         cnt[s[i] -  a ]++;         cnt[t[i] -  a ]++;       }       bool found = true;       for (long long i = 0; i < 26; i++)         if (cnt[i] & 1) found = false;       if (found) {         vector<pair<long long, long long>> ans;         for (long long i = 0; i < n - 1; i++) {           if (s[i] != t[i]) {             bool f = false;             for (long long j = i + 1; j < n; j++) {               if (t[j] == t[i]) {                 swap(s[i], t[j]);                 f = true;                 ans.emplace_back(i + 1, j + 1);                 break;               }             }             if (!f) {               for (long long j = i + 1; j < n; j++) {                 if (s[j] == t[i]) {                   swap(s[j], t[j]);                   swap(s[i], t[j]);                   ans.emplace_back(j + 1, j + 1);                   ans.emplace_back(i + 1, j + 1);                   break;                 }               }             }           }         }         cout <<  YES  << endl;         cout << (long long)ans.size() << endl;         for (pair<long long, long long> x : ans)           cout << x.first <<     << x.second << endl;       } else {         cout <<  No  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long p, k;   vector<int> v;   int main() {     cin >> p >> k;     v.push_back(p % k);     long long a0 = -p / k;     while (1) {       long long a1 = -a0 / k;       while (a1 * k + a0 < 0) a1++;       while (a1 * k + a0 >= k) a1--;       if (a1 < k && a1 >= 0) {         v.push_back(a0 + k * a1);         v.push_back(a1);         break;       }       v.push_back(a0 + k * a1);       a0 = a1;     }     while (v.back() == 0) v.pop_back();     printf( %d n , v.size());     for (int i = 0; i < v.size(); ++i) printf( %d  , v[i]);   }
#include <bits/stdc++.h>   using namespace std;   long long a[200010];   long long vis[200010];   long long cnt[200010];   long long n;   long long max_n = 0;   void solve(long long pos) {     vis[pos]++;     long long temp1 = pos;     long long temp2 = pos;     long long step1 = 0;     long long step2 = 0;     while (temp1 <= max_n) {       temp1 <<= 1;       step1++;       vis[temp1]++;       cnt[temp1] += step1;     }     while (temp2) {       if ((temp2 & 1) && (temp2 != 1)) {         temp2 >>= 1;         step2++;         vis[temp2]++;         cnt[temp2] += step2;         long long temp3 = temp2;         long long step3 = step2;         while (temp3 <= max_n) {           temp3 <<= 1;           step3++;           vis[temp3]++;           cnt[temp3] += step3;         }       } else {         temp2 >>= 1;         step2++;         vis[temp2]++;         cnt[temp2] += step2;       }     }   }   int main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       max_n = max(a[i], max_n);     }     memset(vis, 0, sizeof(vis));     memset(cnt, 0, sizeof(cnt));     for (long long i = 1; i <= n; i++) solve(a[i]);     long long ans = 1 << 29;     for (long long i = 1; i <= 2 * max_n - 1; i++) {       if (vis[i] == n) ans = min(ans, cnt[i]);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   int read() {     int x = 0, y = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) y = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 )       x = (x << 3) + (x << 1) + ch -  0 , ch = getchar();     return x * y;   }   void print(int x) {     if (x < 0) {       putchar( 0 );       return;     }     if (x < 10) {       putchar(x +  0 );       return;     }     print(x / 10);     putchar(x % 10 +  0 );   }   int n, x, maxx;   int main() {     n = read();     for (int _ = 0; _ < n; _++) x = read(), maxx = maxx > x ? maxx : x;     print(maxx - 25);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int x, y, tx, ty, vis[N];   int chk(int x, int y) {     for (int i = 0; i < 7; i++) vis[i] = 0;     for (int i = 1; i <= tx; i++) ++vis[x % 7], x /= 7;     for (int i = 1; i <= ty; i++) ++vis[y % 7], y /= 7;     for (int i = 0; i < 7; i++)       if (vis[i] > 1) return 0;     return 1;   }   int main() {     scanf( %d%d , &x, &y), --x, --y;     if ((long long)x * y > 6543210) return puts( 0 ), 0;     for (int i = x; i; i /= 7) ++tx;     for (int i = y; i; i /= 7) ++ty;     tx = max(tx, 1), ty = max(ty, 1);     int ans = 0;     for (int i = 0; i <= x; i++)       for (int j = 0; j <= y; j++) ans += chk(i, j);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 207;   const int M = 1507;   const int inf = INT_MAX;   int nx[M], to[M], head[N], cap[M], fl[M], who[N][N], vis[N], es = 2;   int a[N], b[N];   int n, m, s, t, turn = 1;   int dfs(int u, int mini) {     vis[u] = turn;     if (u == t) return mini;     for (int e = head[u]; e; e = nx[e]) {       int v = to[e];       if (vis[v] != turn && cap[e] - fl[e]) {         int k = dfs(v, min(mini, cap[e] - fl[e]));         if (k != inf) {           fl[e] += k;           fl[e ^ 1] -= k;           return k;         }       }     }     return inf;   }   int maxflow() {     int mf = 0, k;     while ((k = dfs(s, inf)) != inf) {       turn++;       mf += k;     }     return mf;   }   int addedge(int u, int v, int _cap) {     who[u][v] = es;     to[es] = v;     nx[es] = head[u];     head[u] = es;     cap[es] = _cap;     fl[es++] = 0;     to[es] = u;     nx[es] = head[v];     head[v] = es;     cap[es] = 0;     fl[es++] = 0;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , a + i);     for (int i = 0; i < n; i++) scanf( %d , b + i);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d %d , &u, &v);       u--;       v--;       addedge(u, v + n, inf);       addedge(v, u + n, inf);     }     s = 2 * n;     t = 2 * n + 1;     int sa = 0, sb = 0;     for (int i = 0; i < n; i++) {       sa += a[i];       sb += b[i];       addedge(i, i + n, inf);       addedge(s, i, a[i]);       addedge(i + n, t, b[i]);     }     int res = maxflow();     if (res == sa && res == sb) {       printf( YES n );       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++)           printf( %d%c , fl[who[i][j + n]],    n [j == n - 1]);     } else       puts( NO );   }
#include <bits/stdc++.h>   int main() {     int n, t, pos = 0;     std::cin >> n >> t;     std::vector<std::pair<int, int> > vec;     for (int i = 0; i < n; i++) {       int x, y;       std::cin >> x >> y;       vec.push_back(std::make_pair(x, y));     }     std::sort(vec.begin(), vec.end());     for (int i = 0; i < n - 1; i++) {       int temp = 2 * vec[i + 1].first - 2 * vec[i].first - vec[i + 1].second -                  vec[i].second;       if (temp >= 2 * t) {         pos++;       }       if (temp > 2 * t) {         pos++;       }     }     std::cout << pos + 2;     return 0;   }