malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   char str[100020];   int len[3] = {0};   int num[100020];   void zhuanhuan(int x) {     if (x >= 3) {       len[2]++;     } else if (x == 2) {       len[1]++;     } else {       len[0]++;     }   }   int main() {     int n, kuan = 1;     scanf( %d , &n);     scanf( %*c );     for (int i = 0; i < n; i = i + 1) scanf( %c , &str[i]);     scanf( %*c );     for (int i = 0; i < n; i = i + 1) num[i] = str[i] -  0 ;     int kuanlen = 1;     for (int i = 1; i < n; i++) {       if (num[i] == num[i - 1]) {         kuanlen++;       } else {         kuan++;         zhuanhuan(kuanlen);         kuanlen = 1;       }     }     zhuanhuan(kuanlen);     if (len[2] > 0) {       printf( %d n , kuan + 2);     } else if (len[1] > 1) {       printf( %d n , kuan + 2);     } else {       if (len[1] == 1)         printf( %d n , kuan + 1);       else         printf( %d n , kuan);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   int main() {     int x, y;     long long int a, b;     cin >> x >> y >> a >> b;     int lcm = (x * y) / (gcd(x, y));     int ans = (b / lcm) - ((a - 1) / lcm);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string s[n + 1];     for (int i = 0; i < n; i++) {       cin >> s[i];     }     long long ans = 1;     for (int i = 0; i < m; i++) {       unordered_set<char> b;       for (int j = 0; j < n; j++) {         b.insert(s[j][i]);       }       ans = (ans * b.size()) % 1000000007;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int t;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> t;     while (t--) {       int a[3];       int b[3];       cin >> a[0] >> a[1] >> a[2];       cin >> b[0] >> b[1] >> b[2];       long long sum = 0;       int aux = 0;       for (int i = 2; i >= 0; i--) {         if (i == 2) {           for (int j : {1, 2, 0}) {             aux = min(a[i], b[j]);             if (i > j)               sum += aux * i * j;             else if (i < j)               sum -= aux * i * j;             a[i] -= aux;             b[j] -= aux;           }         } else if (i == 1) {           for (int j : {1, 0, 2}) {             aux = min(a[i], b[j]);             if (i > j)               sum += aux * i * j;             else if (i < j)               sum -= aux * i * j;             a[i] -= aux;             b[j] -= aux;           }         } else {           for (int j : {0, 1, 2}) {             aux = min(a[i], b[j]);             if (i > j)               sum += aux * i * j;             else if (i < j)               sum -= aux * i * j;             a[i] -= aux;             b[j] -= aux;           }         }       }       cout << sum <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long pw(long long b, long long p) {     if (!p) return 1;     long long sq = pw(b, p / 2);     sq *= sq;     if (p % 2) sq *= b;     return sq;   }   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long sd(long long x) { return x < 10 ? x : x % 10 + sd(x / 10); }   long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }   int n, xs, ys, xd, yd, dp[1010][1010];   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   bool isvalid(int x, int y) {     return (((y == 0 || y == n) && x <= n && x >= 0) ||             ((x == 0 || x == n) && y <= n && y >= 0));   }   int dfs(int x, int y) {     if (x == xd && y == yd) return 0;     if (!isvalid(x, y)) return 1 << 30;     int &ret = dp[x][y];     if (ret != -1) return ret;     ret = 1 << 30;     for (int i = 0; i < 4; ++i) ret = min(ret, dfs(x + dx[i], y + dy[i]) + 1);     return ret;   }   int main() {     cin >> n >> xs >> ys >> xd >> yd;     memset(dp, -1, sizeof dp);     cout << dfs(xs, ys);   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   vector<int> edge[100001];   int val[100001];   vector<int> ans[2];   void dfs(int i, int fi) {     if (val[i] != 0 && fi != val[i]) {       cout <<  -1 n ;       exit(0);     }     if (val[i] != 0 && fi == val[i]) {       return;     }     val[i] = fi;     ans[(fi + 1) / 2].push_back(i);     for (int j = 0; j < edge[i].size(); j++) {       dfs(edge[i][j], -fi);     }   }   int main() {     ios_base::sync_with_stdio(false);     if (fopen( cf688c.in ,  r )) {       freopen( cf688c.in ,  r , stdin);       freopen( cf688c.out ,  w , stdout);     }     cin >> N >> M;     for (int i = 0; i < M; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       edge[a].push_back(b);       edge[b].push_back(a);     }     for (int i = 0; i < N; i++) {       if (val[i] == 0) {         if (ans[0].size() == 0) {           dfs(i, -1);         } else {           dfs(i, 1);         }       }     }     if (ans[0].size() == 0 || ans[1].size() == 0) {       cout <<  -1 n ;       return 0;     }     cout << ans[0].size() <<   n ;     for (int i = 0; i < ans[0].size(); i++) {       cout << ans[0][i] + 1 <<    ;     }     cout <<   n ;     cout << ans[1].size() <<   n ;     for (int i = 0; i < ans[1].size(); i++) {       cout << ans[1][i] + 1 <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long n, s[1 << 10];   vector<long> v[1 << 10];   long spre, slim, found;   long trem, tail;   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> s[i];       for (int j = 0; j < 666; j++) v[i].push_back(0);     }     for (int j = 0; j < 666; j++) v[0].push_back(0);     for (int i = 1; i <= n; i++) {       v[i] = v[i - 1];       spre = s[i - 1];       slim = 0;       found = 0;       for (int j = 665; j >= 0; --j) {         if (found) break;         spre -= v[i][j];         for (int q = v[i][j] + 1; q <= 9 && found == 0; q++) {           trem = spre + q;           tail = s[i] - trem;           if (tail >= 0 && tail <= slim) {             v[i][j] = q;             for (int t = 665; t > j; t--) {               if (tail > 9) {                 v[i][t] = 9;                 tail -= 9;               } else {                 v[i][t] = tail;                 tail = 0;               }             }             found = 1;             v[i][j] = q;           }         }         slim += 9;       }     }     for (int i = 1; i <= n; i++) {       reverse(v[i].begin(), v[i].end());       while (v[i].size() > 1 && v[i].back() == 0) v[i].pop_back();       reverse(v[i].begin(), v[i].end());       for (int j = 0; j < v[i].size(); j++) {         cout << v[i][j];       }       cout << endl;     }     cin.get();     cin.get();     return 0;   }
#include <bits/stdc++.h>   int main(void) {     int a, b, m, n, count = 0;     scanf( %d %d , &n, &m);     for (a = 0; a <= m; a++) {       for (b = 0; b <= n; b++) {         if (n - b != a * a) continue;         if (m - a != b * b) continue;         count++;         break;       }     }     printf( %d n , count);     return 0;   }
#include <bits/stdc++.h>   inline int pidorand() { return ((rand() & 32767) << 15) | (rand() & 32767); }   using namespace std;   inline int nxt() {     int x;     scanf( %d , &x);     return x;   }   using Point = pair<int, int>;   int mydiv(int first, int second) {     if (first % second == 0) {       return first / second;     } else {       return first / second - (first < 0);     }   }   Point convert(int first, int second) {     first += second;     second = first - 2 * second;     return {mydiv(first, 2), mydiv(second, 2)};   }   const int N = 111111;   int up_y[N + N], down_y[N + N];   int left_y[N + N], right_y[N + N];   int main() {     int n = nxt();     vector<Point> ppts[2];     for (int i = 0; i < n; ++i) {       int first = nxt(), second = nxt();       ppts[(abs(first) + abs(second)) % 2].push_back(convert(first, second));     }     for (int i = 0; i < 2; ++i) {       sort((ppts[i]).begin(), (ppts[i]).end());     }     long long ans = 0;     for (auto pts : ppts) {       for (int i = 0; i < N + N; ++i) {         left_y[i] = right_y[i] = -N;       }       for (auto pt : pts) {         left_y[pt.first + N] = max(left_y[pt.first + N], pt.second);         right_y[pt.first + N] = max(right_y[pt.first + N], pt.second);       }       for (int i = 1; i < N + N; ++i) {         left_y[i] = max(left_y[i], left_y[i - 1]);       }       for (int i = N + N - 2; i >= 0; --i) {         right_y[i] = max(right_y[i], right_y[i + 1]);       }       for (int i = 0; i < N + N; ++i) {         up_y[i] = min(left_y[i], right_y[i]);       }       for (int i = 0; i < N + N; ++i) {         left_y[i] = right_y[i] = N;       }       for (auto pt : pts) {         left_y[pt.first + N] = min(left_y[pt.first + N], pt.second);         right_y[pt.first + N] = min(right_y[pt.first + N], pt.second);       }       for (int i = 1; i < N + N; ++i) {         left_y[i] = min(left_y[i], left_y[i - 1]);       }       for (int i = N + N - 2; i >= 0; --i) {         right_y[i] = min(right_y[i], right_y[i + 1]);       }       for (int i = 0; i < N + N; ++i) {         down_y[i] = max(left_y[i], right_y[i]);       }       for (int i = 1; i < N + N; ++i) {         int l = max(down_y[i - 1], down_y[i]);         int r = min(up_y[i - 1], up_y[i]);         if (l >= r) {           continue;         }         ans += r - l;       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   const int INF = (((1 << 30) - 1) << 1) + 1;   const int nINF = 1 << 31;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     double ans = 0;     pair<int, int> res;     for (int i = (n - 2); i >= (0); i--) {       int a = i, b = n - i;       if (a > b) continue;       if (gcd(a, b) == 1 && a / (double)b > ans) {         ans = a / (double)b;         res = {a, b};       }     }     cout << res.first <<     << res.second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int n, res, t;   int main() {     cin >> n >> s;     for (int i = 0; i < n; ++i) {       if (s[i] ==  x )         ++t;       else         t = 0;       if (t >= 3) ++res;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<string> v(n);       for (auto& i : v) cin >> i;       bool state = true;       for (int i = n - 2; i >= 0; i--) {         for (int j = n - 2; j >= 0; --j) {           if (v[i][j] ==  1  && v[i + 1][j] ==  0  && v[i][j + 1] ==  0 )             state = false;         }       }       if (state)         cout <<  Yes  <<   n ;       else         cout <<  No  <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char a[26], b[26], c[26], d[26];     scanf( %s , a);     scanf( %s , b);     int i = 0, m = 0, n = 0, k, q, w, j = 0, flag = 0, t = 0;     while (a[i] !=   0 ) {       if (a[i] ==  | ) m = i;       i++;     }     q = m;     w = i - m - 1;     n = i;     while (b[j] !=   0 ) {       j++;     }     i = 0;     for (i = 0; i < q; i++) c[i] = a[i];     for (i = 0; i < w; i++) d[i] = a[q + i + 1];     i = 0;     while (j > 0) {       if (q < w) {         c[q++] = b[i++];         j--;       } else if (q >= w) {         d[w++] = b[i++];         j--;       }     }     if (q == w) {       for (i = 0; i < q; i++) printf( %c , c[i]);       printf( | );       for (i = 0; i < w; i++) printf( %c , d[i]);     } else {       printf( Impossible );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n, k, ans = 0, fa = 0, c = 0;     cin >> n >> k;     c = (n * (n + 1)) / 2;     c -= k;     c -= n;     while (c > 0) {       fa++;       c -= n;       n--;     }     cout << fa;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b;   int x[105], y[105];   int ans;   bool judge(int x1, int x2, int y1, int y2) {     if (x1 + x2 <= a && max(y1, y2) <= b) {       return 1;     }     if (x1 + x2 <= b && max(y1, y2) <= a) {       return 1;     }     if (x1 + y2 <= a && max(y1, x2) <= b) {       return 1;     }     if (x1 + y2 <= b && max(y1, x2) <= a) {       return 1;     }     if (y1 + x2 <= a && max(x1, y2) <= b) {       return 1;     }     if (y1 + x2 <= b && max(x1, y2) <= a) {       return 1;     }     if (y1 + y2 <= a && max(x1, x2) <= b) {       return 1;     }     if (y1 + y2 <= b && max(x1, x2) <= a) {       return 1;     }     return 0;   }   int main() {     int i, j;     cin >> n >> a >> b;     for (i = 1; i <= n; i++) {       cin >> x[i] >> y[i];     }     for (i = 1; i <= n; i++) {       for (j = 1; j < i; j++) {         if (judge(x[i], x[j], y[i], y[j]) == 1) {           ans = max(ans, x[i] * y[i] + x[j] * y[j]);         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char i = getchar();     long long f = 1, res = 0;     while (i <  0  || i >  9 ) {       if (i ==  - ) f = -1;       i = getchar();     }     while (i >=  0  && i <=  9 ) {       res = res * 10 + i -  0 ;       i = getchar();     }     return f * res;   }   const int N = 50005;   int dp[N];   int n, K;   int a[N], pre[N], pos[N];   int maxn[N << 2], lazy[N << 2];   inline void pushup(int rt) { maxn[rt] = max(maxn[rt << 1], maxn[rt << 1 | 1]); }   inline void pushdown(int rt) {     if (lazy[rt]) {       lazy[rt << 1] += lazy[rt];       lazy[rt << 1 | 1] += lazy[rt];       maxn[rt << 1] += lazy[rt];       maxn[rt << 1 | 1] += lazy[rt];       lazy[rt] = 0;     }   }   inline void update(int L, int R, int l, int r, int rt) {     if (L <= l && r <= R) {       maxn[rt] += 1;       lazy[rt] += 1;       return;     }     int mid = (l + r) >> 1;     pushdown(rt);     if (L <= mid) update(L, R, l, mid, rt << 1);     if (R > mid) update(L, R, mid + 1, r, rt << 1 | 1);     pushup(rt);   }   inline int query(int L, int R, int l, int r, int rt) {     if (L <= l && r <= R) {       return maxn[rt];     }     int mid = (l + r) >> 1;     int res = 0;     pushdown(rt);     if (L <= mid) res = max(res, query(L, R, l, mid, rt << 1));     if (R > mid) res = max(res, query(L, R, mid + 1, r, rt << 1 | 1));     return res;   }   inline void build(int l, int r, int rt) {     lazy[rt] = 0;     if (l == r) {       maxn[rt] = dp[l - 1];       return;     }     int mid = (l + r) >> 1;     build(l, mid, rt << 1);     build(mid + 1, r, rt << 1 | 1);     pushup(rt);   }   int main() {     n = read(), K = read();     for (int i = 1; i <= n; ++i) {       a[i] = read();       pos[i] = pre[a[i]] + 1;       pre[a[i]] = i;     }     memset(pre, -1, sizeof pre);     for (int i = 1; i <= K; ++i) {       build(1, n, 1);       for (int j = 1; j <= n; ++j) {         update(pos[j], j, 1, n, 1);         dp[j] = query(1, j, 1, n, 1);       }     }     cout << dp[n] << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool chkmin(T &first, T second) {     return second < first ? first = second, 1 : 0;   }   template <typename T>   bool chkmax(T &first, T second) {     return first < second ? first = second, 1 : 0;   }   template <typename T>   void readint(T &first) {     first = 0;     int f = 1;     char c;     for (c = getchar(); !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) first = first * 10 + (c -  0 );     first *= f;   }   const int MOD = 1000000007, INV3 = (MOD + 1) / 3;   inline int dmy(int first) { return first >= MOD ? first - MOD : first; }   inline void inc(int &first, int second) { first = dmy(first + second); }   int qmi(int first, int second) {     int ans = 1;     for (; second; second >>= 1, first = 1ll * first * first % MOD)       if (second & 1) ans = 1ll * ans * first % MOD;     return ans;   }   const int MAXN = 6005;   int n;   int cnt[4][4];   int main() {     readint(n);     for (int i = 1, first, second; i <= n; ++i)       readint(first), readint(second), ++cnt[first & 3][second & 3];     long long res = 0;     for (int i = 0; i <= 3; ++i)       for (int j = 0; j <= 3; ++j)         res += 1ll * cnt[i][j] * (cnt[i][j] - 1) / 2 * (n - cnt[i][j]) +                1ll * cnt[i][j] * (cnt[i][j] - 1) * (cnt[i][j] - 2) / 6;     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, head[100000 + 5], sz[100000 + 5], cnt = 1;   double ans[100000 + 5];   struct edges {     int to, next;   } e[2 * 100000 + 5];   inline void insert(int x) {     int u = x, v;     scanf( %d , &v);     e[++cnt] = (edges){u, head[v]};     head[v] = cnt;     e[++cnt] = (edges){v, head[u]};     head[u] = cnt;   }   void dfs(int x, int fa) {     sz[x] = 1;     for (int i = head[x]; i; i = e[i].next) {       if (e[i].to == fa) continue;       dfs(e[i].to, x);       sz[x] += sz[e[i].to];     }   }   void dfs1(int x, int fa) {     for (int i = head[x]; i; i = e[i].next) {       if (e[i].to == fa) continue;       ans[e[i].to] = 1.0 * (sz[x] - 1 - sz[e[i].to]) / 2.0 + 1.0 + ans[x];       dfs1(e[i].to, x);     }   }   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) insert(i);     dfs(1, 0);     ans[1] = 1;     dfs1(1, 0);     for (int i = 1; i <= n; i++) printf( %.7lf n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, c, b;     long ans = 0;     cin >> n >> m;     long a[n + 1];     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 0; i < m; i++) {       cin >> c >> b;       ans += min(a[c], a[b]);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double num, a, b, c, d, e, f, r1, r2;     double m1, m2, m3;     while (cin >> a >> b >> c >> d >> e >> f) {       if (d == 0) {         cout <<  Hermione  << endl;         continue;       }       if (c == 0) {         cout <<  Ron  << endl;         continue;       }       if (b == 0) {         cout <<  Hermione  << endl;         continue;       }       if (a == 0) {         cout <<  Ron  << endl;         continue;       }       if (f != 0 && e == 0) {         cout <<  Ron  << endl;         continue;       }       num = 500;       r1 = 0;       r2 = 0;       m1 = b / a;       m2 = d / c;       m3 = e / f;       r1 = num * m1 * m2;       r2 = num * m3;       if (r1 > r2) {         cout <<  Ron  << endl;       } else {         cout <<  Hermione  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   int dp[5001][5001];   char s[5001];   int main() {     scanf( %s , s);     int n;     scanf( %d , &n);     for (int i = 0; *(s + i); i++) {       dp[i][i] = 1;       for (int j1 = i - 1, j2 = i + 1; j1 >= 0 && *(s + j2); j1--, j2++)         if (s[j1] == s[j2])           dp[j1][j2] = 1;         else           break;       if (s[i] == s[i + 1]) {         dp[i][i + 1] = 3;         for (int j1 = i - 1, j2 = i + 2; j1 >= 0 && *(s + j2) && *(s + j2 - 1);              j1--, j2++)           if (s[j1] == s[j2])             dp[j1][j2] = 1;           else             break;       } else         dp[i][i + 1] = 2;     }     for (int k = 2; *(s + k); k++)       for (int i = 0; *(s + i + k); i++)         dp[i][i + k] +=             dp[i][i + k - 1] + dp[i + 1][i + k] - dp[i + 1][i + k - 1];     while (n--) {       int i, j;       scanf( %d%d , &i, &j);       printf( %d n , dp[i - 1][j - 1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<ll, ll>;   using vi = vector<ll>;   using vii = vector<ii>;   double x;   int main() {     cin >> x;     for (double a = 1; a <= 10; a++) {       for (double h = 1; h <= 10; h++) {         double cr = -h * a / 2;         double r = -cr / sqrt(a * a / 4 + h * h);         if (fabs(r - x) < 1e-5) {           cout << a <<     << h << endl;           return 0;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d , &n);     scanf( %d , &m);     int f[n], b[m], a[m];     map<int, int> x;     for (int i = 0; i < n; i++) {       scanf( %d , &f[i]);       if (x.find(f[i]) != x.end())         x[f[i]] = -1;       else         x[f[i]] = i;     }     for (int i = 0; i < m; i++) scanf( %d , &b[i]);     sort(f, f + n);     bool y = 0, z = 0;     for (int i = 0; i < m; i++) {       if (x.find(b[i]) != x.end()) {         if (x[b[i]] == -1) {           z = 1;         } else {           a[i] = x[b[i]];         }       } else {         printf( Impossible );         y = 1;         break;       }     }     if (!y) {       if (z) {         printf( Ambiguity );       } else {         printf( Possible n );         for (int i = 0; i < m; i++) {           printf( %d , a[i] + 1);           printf(   );         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MXN = 1e5 + 20;   int n, a[MXN], b[MXN], c[MXN];   vector<int> ans;   void IN() {     int tmp;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> tmp;       a[i] = tmp;     }     for (int i = 0; i < n - 1; i++) {       cin >> tmp;       b[i] = tmp;     }     for (int i = 0; i < n - 2; i++) {       cin >> tmp;       c[i] = tmp;     }   }   void SLV() {     sort(a, a + n);     sort(b, b + n - 1);     sort(c, c + n - 2);     for (int i = 0; i < n; i++)       if (b[i] != a[i]) {         ans.push_back(a[i]);         break;       }     for (int i = 0; i < n; i++)       if (c[i] != b[i]) {         ans.push_back(b[i]);         break;       }   }   void OUT() {     for (auto i : ans) cout << i << endl;   }   int main() {     IN();     SLV();     OUT();     return 0;   }