malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0;     int x0, y0, x1, y1;     cin >> x0 >> y0 >> x1 >> y1;     int m;     cin >> m;     map<pair<int, int>, bool> mass;     for (int i = 0; i < m; i++) {       int r, a, b;       scanf( %d%d%d , &r, &a, &b);       for (int j = a; j <= b; j++) {         mass[make_pair(r, j)] = true;       }     }     map<pair<int, int>, bool> flag;     queue<pair<int, int> > q;     map<pair<int, int>, int> dist;     dist[make_pair(x0, y0)] = 1;     q.push(make_pair(x0, y0));     flag[make_pair(x0, y0)] = true;     while (!q.empty()) {       int x = q.front().first;       int y = q.front().second;       bool f = false;       q.pop();       if (mass[make_pair(x - 1, y - 1)]) {         if (!flag[make_pair(x - 1, y - 1)]) {           flag[make_pair(x - 1, y - 1)] = true;           q.push(make_pair(x - 1, y - 1));           dist[make_pair(x - 1, y - 1)] = dist[make_pair(x, y)] + 1;         }       }       if (mass[make_pair(x, y - 1)]) {         if (!flag[make_pair(x, y - 1)]) {           flag[make_pair(x, y - 1)] = true;           q.push(make_pair(x, y - 1));           dist[make_pair(x, y - 1)] = dist[make_pair(x, y)] + 1;         }       }       if (mass[make_pair(x + 1, y - 1)]) {         if (!flag[make_pair(x + 1, y - 1)]) {           flag[make_pair(x + 1, y - 1)] = true;           q.push(make_pair(x + 1, y - 1));           dist[make_pair(x + 1, y - 1)] = dist[make_pair(x, y)] + 1;         }       }       if (mass[make_pair(x - 1, y)]) {         if (!flag[make_pair(x - 1, y)]) {           flag[make_pair(x - 1, y)] = true;           q.push(make_pair(x - 1, y));           dist[make_pair(x - 1, y)] = dist[make_pair(x, y)] + 1;         }       }       if (mass[make_pair(x + 1, y)]) {         if (!flag[make_pair(x + 1, y)]) {           flag[make_pair(x + 1, y)] = true;           q.push(make_pair(x + 1, y));           dist[make_pair(x + 1, y)] = dist[make_pair(x, y)] + 1;         }       }       if (mass[make_pair(x - 1, y + 1)]) {         if (!flag[make_pair(x - 1, y + 1)]) {           flag[make_pair(x - 1, y + 1)] = true;           q.push(make_pair(x - 1, y + 1));           dist[make_pair(x - 1, y + 1)] = dist[make_pair(x, y)] + 1;         }       }       if (mass[make_pair(x, y + 1)]) {         if (!flag[make_pair(x, y + 1)]) {           flag[make_pair(x, y + 1)] = true;           q.push(make_pair(x, y + 1));           dist[make_pair(x, y + 1)] = dist[make_pair(x, y)] + 1;         }       }       if (mass[make_pair(x + 1, y + 1)]) {         if (!flag[make_pair(x + 1, y + 1)]) {           flag[make_pair(x + 1, y + 1)] = true;           q.push(make_pair(x + 1, y + 1));           dist[make_pair(x + 1, y + 1)] = dist[make_pair(x, y)] + 1;         }       }     }     int ans = dist[make_pair(x1, y1)];     if (ans) {       cout << ans - 1;     } else {       cout << -1;     }   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> a, b;   map<int, int>::iterator it;   int n, ans = 1000000, k;   int main() {     int i, x, y, k;     cin >> n;     k = n / 2 + n % 2;     for (i = 1; i <= n; i++) {       cin >> x >> y;       a[x]++;       b[x]++;       if (x != y) b[y]++;     }     for (it = b.begin(); it != b.end(); it++) {       x = it->first;       if (a[x] >= k)         ans = 0;       else if (b[x] >= k)         ans = min(ans, min(b[x] - a[x], k - a[x]));     }     if (ans == 1000000)       cout <<  -1 n ;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> a;   long long n;   long long pos1;   double ct1, ct2 = 0;   long long z;   long long fun(long long l, long long r, vector<vector<long long> > dpp) {     if (dpp[l][r] != -1) return dpp[l][r];     long long i, j, sum = 0;     for (i = l; i < r; i++) {       long long z = abs(a[i] - a[i + 1]);       z = z * pow(-1, i - l);       sum += z;     }     return dpp[l][r] = sum;   }   long long solve(long long l, long long r, vector<vector<long long> > dp,                   vector<vector<long long> > dpp) {     if (l > r) return 0;     if (dp[l][r] != -1) return dp[l][r];     long long x, y;     x = solve(l + 1, r, dp, dpp);     long long z = fun(l, r, dpp);     y = solve(l, r - 1, dp, dpp);     return dp[l][r] = max(z, max(x, y));   }   int main() {     long long i, j, k, l, m, t;     t = 1;     while (t--) {       long long a, b;       cin >> n >> a >> b;       vector<long long> v;       for (i = 0; i < n; i++) {         cin >> k;         v.push_back(k);       }       sort(v.begin(), v.end());       m = min(a, b);       b = max(a, b);       a = m;       i = n - 1;       long long sum1 = 0, sum2 = 0;       while (m--) {         sum1 += v[i];         i--;       }       double ans1 = (double)sum1 / a;       m = b;       while (m--) {         sum2 += v[i];         i--;       }       double ans2 = (double)sum2 / b;       ans1 += ans2;       cout << fixed << setprecision(12) << ans1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long a = 1;     for (int i = 1; i <= (3 * n); i++) {       a *= 3;       a %= 1000000007;     }     long long b = 1;     for (int i = 1; i <= n; i++) {       b *= 7;       b %= 1000000007;     }     long long ans = ((a - b) + 1000000007) % 1000000007;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   clock_t __stt;   inline void TStart() { __stt = clock(); }   inline void TReport() {     printf(  nTaken Time : %.3lf sec n ,            (double)(clock() - __stt) / CLOCKS_PER_SEC);   }   template <typename T>   T MIN(T a, T b) {     return a < b ? a : b;   }   template <typename T>   T MAX(T a, T b) {     return a > b ? a : b;   }   template <typename T>   T ABS(T a) {     return a > 0 ? a : (-a);   }   template <typename T>   void UMIN(T &a, T b) {     if (b < a) a = b;   }   template <typename T>   void UMAX(T &a, T b) {     if (b > a) a = b;   }   int n, q, fa[100005], deg[100005];   double p[100005], s[100005], ini;   vector<int> adj[100005];   void dfs(int ver) {     if (!ver) fa[ver] = -1;     int i;     ini += ((double)deg[ver]) * p[ver];     for (i = 0; i < (int)adj[ver].size(); ++i) {       if (adj[ver][i] != fa[ver]) {         fa[adj[ver][i]] = ver;         s[ver] += p[adj[ver][i]];         dfs(adj[ver][i]);       }     }   }   int main() {     int i, j, k;     scanf( %d , &n);     ini = 0;     for (i = 0; i < n; ++i) {       scanf( %lf , p + i);     }     memset(deg, -1, sizeof(deg));     for (i = 0; i < n - 1; ++i) {       int u, v;       scanf( %d%d , &u, &v);       ++deg[u];       ++deg[v];       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(0);     for (i = 0; i < n; ++i) {       ini -= p[i] * s[i];     }     scanf( %d , &q);     while (q--) {       int u;       double d;       scanf( %d%lf , &u, &d);       ini += (d - p[u]) * (double)deg[u];       if (fa[u] != -1) {         ini += p[fa[u]] * s[fa[u]];         s[fa[u]] += d - p[u];         ini -= p[fa[u]] * s[fa[u]];       }       ini += p[u] * s[u];       p[u] = d;       ini -= p[u] * s[u];       printf( %.5lf n , ini + 1.0);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool is_powertwo(long long n) {     long long count = 0;     while (n) {       if ((n & 1) > 0) count++;       n = n >> 1;     }     if (count == 1) return true;     return false;   }   int main() {     long long t;     t = 1;     while (t--) {       long long h1, a1, c1;       cin >> h1;       cin >> a1;       cin >> c1;       long long h2, a2;       cin >> h2;       cin >> a2;       string str =   ;       long long count = 0;       while (h2 > 0) {         count++;         if (h1 > a2) {           str +=  s ;           h1 -= a2;           h2 -= a1;         } else if (h2 <= a1) {           h2 -= a1;           str +=  s ;           h1 -= a2;         } else {           h1 -= a2;           str +=  h ;           h1 += c1;         }       }       cout << count << endl;       for (long long i = 0; i < str.size(); i++) {         if (str[i] ==  s )           cout <<  STRIKE  << endl;         else           cout <<  HEAL  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char str[5003];   int num[5003][2];   int main() {     while (~scanf( %s , str + 1)) {       memset(num, 0, sizeof(num));       int len = strlen(str + 1);       for (int i = 1; i <= len; i++) {         num[i][0] = num[i - 1][0];         num[i][1] = num[i - 1][1];         if (str[i] ==  a )           num[i][0]++;         else           num[i][1]++;       }       int ans = len + 1;       for (int i = 1; i <= len + 1; ++i) {         for (int j = i; j <= len + 1; ++j) {           int x1 = 0, x2 = 0, x3 = 0;           if (i > 1) x1 = num[i - 1][1] - num[0][1];           if (j > i) x2 = num[j - 1][0] - num[i - 1][0];           if (j <= len) x3 = num[len][1] - num[j - 1][1];           ans = min(ans, x1 + x2 + x3);         }       }       printf( %d n , len - ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& s, vector<T>& v) {     s <<  { ;     for (int i = 0; i < int(v.size()); i++) s << (i ?  ,  :   ) << v[i];     return s <<  } ;   }   template <typename S, typename T>   ostream& operator<<(ostream& s, pair<S, T> const& p) {     return s <<  (  << p.first <<  ,  << p.second <<  ) ;   }   const long long INV2 = 500000004;   const long long INV3 = 333333336;   const long long MOD = 1000000007;   long long modexp(long long x, long long n) {     long long result = 1;     while (n) {       if (n % 2) {         result = (result * x) % MOD;         n--;       }       x = (x * x) % MOD;       n /= 2;     }     return result;   }   int main() {     int K;     bool even = false;     scanf( %d , &K);     long long sm = 2;     for (int k = 0; k < int(K); k++) {       long long a;       scanf( %lld , &a);       if (a % 2 == 0) even = true;       sm = modexp(sm, a);     }     sm = (sm * INV2) % MOD;     long long denom = (sm + MOD) % MOD;     if (even)       sm++;     else       sm--;     sm = (sm * INV3) % MOD;     sm = (sm + MOD) % MOD;     printf( %lld/%lld n , sm, denom);   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   void doin() {     cin.tie();     cout.tie();     ios::sync_with_stdio(0);   }   template <typename X, typename Y>   istream& operator>>(istream& in, pair<X, Y>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T>   void getv(T& i) {     cin >> i;   }   template <typename T, typename... Ns>   void getv(vector<T>& v, int n, Ns... ns) {     v.resize(n);     for (auto& i : v) getv(i, ns...);   }   template <typename T>   void getv1(T& i) {     cin >> i;   }   template <typename T, typename... Ns>   void getv1(vector<T>& v, int n, Ns... ns) {     v.resize(n + 1);     for (int i = 1; i <= n; i++) getv(v[i], ns...);   }   inline void getch(char& x) {     while (x = getchar_unlocked(), x < 33) {       ;     }   }   inline void getstr(string& str) {     str.clear();     char cur;     while (cur = getchar_unlocked(), cur < 33) {       ;     }     while (cur > 32) {       str += cur;       cur = getchar_unlocked();     }   }   template <typename T>   inline bool sc(T& num) {     bool neg = 0;     int c;     num = 0;     while (c = getchar_unlocked(), c < 33) {       if (c == EOF) return false;     }     if (c ==  - ) {       neg = 1;       c = getchar_unlocked();     }     for (; c > 47; c = getchar_unlocked()) num = num * 10 + c - 48;     if (neg) num *= -1;     return true;   }   using AntonTsypko = void;   using arsijo = AntonTsypko;   using god = arsijo;   uniform_real_distribution<double> double_dist(0, 1);   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long c, hr, wr, hb, wb;   long long ans = 0;   set<int> a;   void A() {     long long cur = (c / wr) * hr, left = c % wr, t;     while (cur >= 0 && a.insert(left % wb).second) {       ans = max(ans, (t = cur + (left / wb) * hb));       cur -= hr;       left += wr;     }   }   void B() {     long long cur = 0, left = c, t;     while (left >= 0 && a.insert(left % wr).second) {       ans = max(ans, (t = cur + (left / wr) * hr));       if ((t * 11) < 10 * ans) break;       cur += hb;       left -= wb;     }   }   int main() {     doin();     cin >> c >> hr >> hb >> wr >> wb;     float rr = ((float)hr) / (float)wr;     float rb = ((float)hb) / (float)wb;     if (rr < rb) swap(hr, hb), swap(wr, wb);     if (wr * 3 < wb)       B();     else       A();     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2505;   using ll = long long;   int n, m, kk, a[N][N], sum[N][N], b[2][10];   char ch[N][N];   ll ans = 0;   inline int calc(int x1, int x2, int y1, int y2) {     return sum[x2][y2] - sum[x1][y2] - sum[x2][y1] + sum[x1][y1];   }   void solve(int x1, int x2, int y1, int y2, int tp) {     if (x1 == x2 || y1 == y2) return;     if (x1 == x2 - 1 && y1 == y2 - 1) {       ans += calc(x1, x2, y1, y2) == kk;       return;     }     if (tp) {       int mid = (x1 + x2) >> 1;       solve(x1, mid, y1, y2, 0);       solve(mid, x2, y1, y2, 0);       for (int i = y1; i <= y2; i++) {         b[0][0] = b[1][0] = mid;         for (int j = 1; j <= kk + 1; j++) b[0][j] = x1, b[1][j] = x2;         for (int j = i + 1; j <= y2; j++) {           for (int k = 1; k <= kk + 1; k++)             while (calc(b[0][k], mid, i, j) >= k) ++b[0][k];           for (int k = 1; k <= kk + 1; k++)             while (calc(mid, b[1][k], i, j) >= k) --b[1][k];           for (int k = 0; k <= kk; k++)             ans += ll(b[0][k] - b[0][k + 1]) * (b[1][kk - k + 1] - b[1][kk - k]);         }       }     } else {       int mid = (y1 + y2) >> 1;       solve(x1, x2, y1, mid, 1);       solve(x1, x2, mid, y2, 1);       for (int i = x1; i <= x2; i++) {         b[0][0] = b[1][0] = mid;         for (int j = 1; j <= kk + 1; j++) b[0][j] = y1, b[1][j] = y2;         for (int j = i + 1; j <= x2; j++) {           for (int k = 1; k <= kk + 1; k++)             while (calc(i, j, b[0][k], mid) >= k) ++b[0][k];           for (int k = 1; k <= kk + 1; k++)             while (calc(i, j, mid, b[1][k]) >= k) --b[1][k];           for (int k = 0; k <= kk; k++)             ans += ll(b[0][k] - b[0][k + 1]) * (b[1][kk - k + 1] - b[1][kk - k]);         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> kk;     for (int i = 1; i <= n; i++) cin >> (ch[i] + 1);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         sum[i][j] =             sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + ch[i][j] -  0 ;     solve(0, n, 0, m, 0);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool p(long long n) {     for (long long i = 2; i <= sqrt(n); i++) {       if (n % i == 0) return 0;     }     return 1;   }   int main() {     long long m, n, i, j, k;     cin >> n;     if (p(n)) {       cout << 1 << endl << n;     } else {       cout << 3 << endl << 3 <<    ;       for (i = 3, n -= 3; i < n; i += 2) {         if (p(i) && p(n - i)) {           cout << i <<     << n - i << endl;           return 0;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long f[55][2][2], K, d;   int a[55], n;   long long C(int l, int r, int x, int y) {     if (l > r) return 1;     long long& F = f[l][x][y];     if (~F) return F;     F = 0;     for (int i = 0; i <= 1; ++i)       for (int j = 0; j <= 1; ++j)         if (a[l] - !i && a[r] - !j && (l < r || i == j) && (x || i <= j) &&             (y || i <= (!j)))           F += C(l + 1, r - 1, x || (i < j), y || (i < !j));     return F;   }   int main() {     cin >> n >> K;     memset(a, -1, sizeof a);     memset(f, -1, sizeof f);     if (C(1, n, a[1] = 0, 0) < ++K) return cout << -1, 0;     for (int i = 2; i <= n; ++i) {       memset(f, -1, sizeof f);       d = C(1, n, a[i] = 0, 0);       K -= (a[i] = (d < K)) * d;     }     for (int i = 1; i <= n; ++i) cout << a[i];   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int a, b, c;     cin >> a >> b >> c;     long long int x = min(a, min(b, c));     long long int z = max(a, max(b, c));     long long int y = a + b + c - x - z;     long long int xi = a == x ? 1 : b == x ? 2 : 3;     long long int yi = a == y ? 1 : b == y ? 2 : 3;     long long int zi = 6 - xi - yi;     cout <<  First  << endl;     cout.flush();     cout << 2 * z - x - y << endl;     cout.flush();     long long int p;     cin >> p;     if (p == xi) {       cout << z - y << endl;       cout.flush();     } else if (p == yi) {       cout << z - x << endl;       cout.flush();     } else {       long long int r = 3 * z - x - y;       cout << 2 * r - x - y << endl;       cout.flush();       cin >> p;       if (p == xi)         cout << r - y << endl;       else         cout << r - x << endl;       cout.flush();     }     cin >> y;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, l, d;     cin >> n >> d >> m >> l;     long long x = 0;     long long L = -m;     long long R = -m + l;     for (int i = 0; i < n; i++) {       L += m;       R += m;       if (x + d < L) break;       long long o = (R - x) / d;       x = x + d * o;     }     cout << x + d;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g;   int a[100005], b[100005], c[100005];   int n, k;   void solve() {     int i, j, m, ans, cnt;     c[m = 0] = a[0];     for (i = 1; i < n; i++)       if (a[i] != a[i - 1]) c[++m] = a[i];     b[a[0]]--;     for (i = 1; i <= m; i++) {       b[c[i]]--;       if (c[i - 1] == c[i + 1]) b[c[i]]--;     }     j = 1;     for (i = 1; i <= k; i++)       if (b[j] > b[i]) j = i;     cout << j << endl;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 60;   int n, m;   char s[N][N];   bool vis[N][N];   int tmp;   int dx[] = {-1, 0, 1, 0};   int dy[] = {0, -1, 0, 1};   inline bool in(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }   void dfs(int x, int y) {     vis[x][y] = 1;     tmp++;     for (int i = 0; i < 4; ++i) {       int tx = x + dx[i];       int ty = y + dy[i];       if (in(tx, ty) && s[tx][ty] ==  # ) {         if (!vis[tx][ty]) {           dfs(tx, ty);         }       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %s , s[i]);     }     int cnt = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (s[i][j] ==  # ) {           ++cnt;         }       }     }     if (cnt == 1 || cnt == 2) {       printf( -1 n );       return 0;     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (s[i][j] ==  # ) {           s[i][j] =  . ;           memset(vis, 0, sizeof(vis));           for (int a = 0; a < n; ++a) {             for (int b = 0; b < m; ++b) {               if (s[a][b] ==  # ) {                 tmp = 0;                 dfs(a, b);                 if (tmp != cnt - 1) {                   printf( 1 n );                   return 0;                 }                 a = n, b = m;               }             }           }           s[i][j] =  # ;         }       }     }     printf( 2 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long INFF = 0x3f3f3f3f3f3f3f3fll;   const long long M = 998244353;   const long long maxn = 1e6 + 107;   const double pi = acos(-1.0);   const double eps = 0.0000000001;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   template <typename T>   inline void pr2(T x, int k = 64) {     long long i;     for (i = 0; i < k; i++) fprintf(stderr,  %d , (x >> i) & 1);     putchar(   );   }   template <typename T>   inline void add_(T &A, int B, long long MOD = M) {     A += B;     (A >= MOD) && (A -= MOD);   }   template <typename T>   inline void mul_(T &A, long long B, long long MOD = M) {     A = (A * B) % MOD;   }   template <typename T>   inline void mod_(T &A, long long MOD = M) {     A %= MOD;     A += MOD;     A %= MOD;   }   template <typename T>   inline void max_(T &A, T B) {     (A < B) && (A = B);   }   template <typename T>   inline void min_(T &A, T B) {     (A > B) && (A = B);   }   template <typename T>   inline T abs(T a) {     return a > 0 ? a : -a;   }   inline long long powMM(long long a, long long b, long long mod = M) {     long long ret = 1;     for (; b; b >>= 1ll, a = a * a % mod)       if (b & 1) ret = ret * a % mod;     return ret;   }   int startTime;   void startTimer() { startTime = clock(); }   void printTimer() {     fprintf(stderr,  /--- Time: %ld milliseconds ---/ n , clock() - startTime);   }   long long kth[maxn];   long long freq[maxn];   int main() {     int i, n;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       int a, f;       scanf( %d%d , &a, &f);       freq[a] += f;     }     kth[1] = 1;     int ans = 0;     for (i = 1; i <= 100000; i++) {       long long a1 = 0, a2 = 0;       long long cnt = 0;       for (int j = i; j <= 100000; j += i) {         if (j != i) add_(kth[j], M - kth[i]);         add_(a1, freq[j] % M * j % M);         add_(a2, freq[j] % M * j % M * j % M);         cnt += freq[j];       }       if (cnt <= 1) continue;       long long axy = (a1 * a1 % M - a2 + M) % M;       long long nowval = 0;       long long base1 = (cnt - 1) % M * powMM(2, cnt - 2) % M;       long long base2 = (powMM(2, cnt - 2));       if (cnt >= 3) base2 += (cnt - 2) % M * powMM(2, cnt - 3) % M;       add_(nowval, a2 * base1 % M);       add_(nowval, axy * base2 % M);       add_(ans, nowval * kth[i] % M);     }     printf( %d n , ans);   }