malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int N, M;   const double EPS = 1E-9;   double solve(int r, int c) {     vector<double> res(M, 0);     for (int y = N - 2; y >= r; y--) {       if (M == 1) {         res[0] = 2 + res[0];       } else {         vector<double> a(M), b(M);         a[0] = 1 / 2.0;         b[0] = (3 + res[0]) / 2;         for (int j = 1; j < M; j++) {           a[j] = 1.0 / (3 - a[j - 1]);           b[j] = (4 + res[j] + b[j - 1]) / (3 - a[j - 1]);         }         res[M - 1] = (b[M - 2] + 3 + res[M - 1]) / (2 - a[M - 2]);         for (int j = M - 2; j >= 0; j--) {           res[j] = a[j] * res[j + 1] + b[j];         }       }     }     return res[c];   }   int main(int argc, char* argv[]) {     scanf( %d %d , &N, &M);     int r, c;     scanf( %d %d , &r, &c);     double res = solve(r - 1, c - 1);     printf( %9lf n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, s;   int dp[2][155][155 * 155 / 4];   int num[155];   int main() {     while (~scanf( %d%d%d , &n, &k, &s)) {       for (int i = 1; i <= n; i++) {         scanf( %d , &num[i]);       }       int all = (n - k) * k;       if (s >= all) {         sort(num + 1, num + n + 1);         int sum = 0;         for (int i = 1; i <= k; i++) {           sum += num[i];         }         printf( %d n , sum);         continue;       }       for (int j = 0; j <= k; j++) {         for (int r = 0; r <= s; r++) {           dp[0][j][r] = 1000000000;         }       }       dp[0][0][0] = 0;       int pre = 0, now = 1;       for (int i = 0; i < n; i++) {         for (int j = 0; j <= k; j++) {           for (int r = 0; r <= s; r++) {             dp[now][j][r] = 1000000000;           }         }         int x = min(i, k);         for (int j = 0; j <= x; j++) {           for (int r = 0; r <= s; r++) {             if (dp[pre][j][r] == 1000000000) continue;             dp[now][j][r] = min(dp[now][j][r], dp[pre][j][r]);             if (j + 1 <= k && r + i - j <= s)               dp[now][j + 1][r + i - j] =                   min(dp[now][j + 1][r + i - j], dp[pre][j][r] + num[i + 1]);           }         }         now ^= 1;         pre ^= 1;       }       int ans = 1000000000;       for (int i = 0; i <= s; i++) {         ans = min(ans, dp[pre][k][i]);       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   int n, a[maxn], deep[maxn], head[maxn], to[maxn * 2], nextt[maxn * 2],       tot = 1, ans[maxn], anss;   void add(int x, int y) {     to[tot] = y;     nextt[tot] = head[x];     head[x] = tot++;   }   void dfs(int u, int fa) {     deep[u] = deep[fa] + 1;     ans[deep[u]]--;     for (int i = head[u]; i; i = nextt[i]) {       int v = to[i];       if (v == fa) continue;       dfs(v, u);     }   }   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       scanf( %d , &a[i]);       add(a[i], i);     }     dfs(1, 0);     for (int i = 1; i <= n; i++)       if (ans[i] & 1) anss++;     printf( %d n , anss);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k, m, p, t = 0;     cin >> n >> m >> k;     vector<long long int> v;     for (long long int i = 0; i < m; i++) {       cin >> p;       v.push_back(p);     }     sort(v.begin(), v.end());     long long int c = 0, s = 0;     while (s != m) {       long long int y;       if ((v[s] - t) % k == 0)         y = (v[s] - t) / k;       else         y = (v[s] - t) / k + 1;       long long int q = t;       for (long long int i = s; i < m; i++) {         long long int x;         if ((v[i] - q) % k == 0)           x = (v[i] - q) / k;         else           x = (v[i] - q) / k + 1;         if (y == x) {           s++;           t++;         } else {           break;         }       }       c++;     }     cout << c << endl;   }
#include <bits/stdc++.h>   clock_t t = clock();   namespace my_std {   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <typename T>   inline T rnd(T l, T r) {     return uniform_int_distribution<T>(l, r)(rng);   }   template <typename T>   inline bool chkmax(T& x, T y) {     return x < y ? x = y, 1 : 0;   }   template <typename T>   inline bool chkmin(T& x, T y) {     return x > y ? x = y, 1 : 0;   }   template <typename T>   inline void read(T& t) {     t = 0;     char f = 0, ch = getchar();     double d = 0.1;     while (ch >  9  || ch <  0 ) f |= (ch ==  - ), ch = getchar();     while (ch <=  9  && ch >=  0 ) t = t * 10 + ch - 48, ch = getchar();     if (ch ==  . ) {       ch = getchar();       while (ch <=  9  && ch >=  0 ) t += d * (ch ^ 48), d *= 0.1, ch = getchar();     }     t = (f ? -t : t);   }   template <typename T, typename... Args>   inline void read(T& t, Args&... args) {     read(t);     read(args...);   }   char __sr[1 << 21], __z[20];   int __C = -1, __zz = 0;   inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; }   inline void print(register int x) {     if (__C > 1 << 20) Ot();     if (x < 0) __sr[++__C] =  - , x = -x;     while (__z[++__zz] = x % 10 + 48, x /= 10)       ;     while (__sr[++__C] = __z[__zz], --__zz)       ;     __sr[++__C] =   n ;   }   void file() {}   inline void chktime() {}   long long ksm(long long x, int y) {     long long ret = 1;     for (; y; y >>= 1, x = x * x)       if (y & 1) ret = ret * x;     return ret;   }   }  // namespace my_std   using namespace my_std;   int n;   vector<int> V[101010];   int D[101010];   void dfs1(int x) {     for (auto v : V[x]) dfs1(v), chkmax(D[x], D[v]);     ++D[x];     for (int i = (0); i <= ((int)V[x].size() - 1); i++)       if (D[V[x][i]] == D[x] - 1) {         V[x].push_back(V[x][i]);         V[x].erase(V[x].begin() + i);         break;       }   }   stack<int> ans;   int Ans;   void dfs2(int x) {     if (!V[x].size()) {       for (int i = 0; printf( %d  , i), V[i].size(); i = V[i][0])         ;       printf(  n%d n , (int)ans.size());       while (ans.size()) printf( %d  , ans.top()), ans.pop();       return;     }     int s = V[x].back();     V[x].pop_back();     while (V[x].size())       V[V[x].back()].push_back(s), ans.push(s), s = V[x].back(), V[x].pop_back();     V[x].push_back(s);     dfs2(s);   }   int main() {     file();     read(n);     int x;     for (int i = (1); i <= (n - 1); i++) read(x), V[x].push_back(i);     dfs1(0);     Ans = n - D[0];     dfs2(0);     return 0;   }
#include <bits/stdc++.h>   int s[401000], lazy[401000];   int b[401000], N;   int n, s1, s2;   int v[401000];   int Abs(int x) { return x > 0 ? x : -x; }   void add(int x) {     s[x] = 0;     lazy[x] = 1;   }   void pd(int x) {     if (lazy[x]) add(x << 1), add(x << 1 | 1), lazy[x] = 0;   }   void pu(int x) { s[x] = s[x << 1] | s[x << 1 | 1]; }   void modify(int x, int l, int r, int L, int R, int v) {     if (l == L && r == R) {       if (v == 1)         s[x] = 1;       else         add(x);       return;     }     pd(x);     int mid = l + r >> 1;     if (R <= mid)       modify(x << 1, l, mid, L, R, v);     else if (L > mid)       modify(x << 1 | 1, mid + 1, r, L, R, v);     else       modify(x << 1, l, mid, L, mid, v),           modify(x << 1 | 1, mid + 1, r, mid + 1, R, v);     pu(x);   }   int L(int x) { return std::lower_bound(b + 1, b + N + 1, x) - b; }   int U(int x) { return std::upper_bound(b + 1, b + N + 1, x) - b; }   bool solve(int x) {     memset(s, 0, sizeof(s));     memset(lazy, 0, sizeof(lazy));     modify(1, 1, N, L(s1), L(s1), 1);     for (int i = 1; i <= n; i++) {       if (Abs(v[i] - v[i - 1]) <= x && s[1])         modify(1, 1, N, L(v[i - 1]), L(v[i - 1]), 1);       if (L(v[i] - x) - 1 >= 1) modify(1, 1, N, 1, L(v[i] - x) - 1, 0);       if (U(v[i] + x) <= N) modify(1, 1, N, U(v[i] + x), N, 0);     }     return s[1];   }   int main() {     scanf( %d%d%d , &n, &s1, &s2);     for (int i = 1; i <= n; i++) scanf( %d , &v[i]), b[++N] = v[i];     v[0] = s2;     b[++N] = s1;     b[++N] = s2;     std::sort(b + 1, b + N + 1);     N = std::unique(b + 1, b + N + 1) - b - 1;     int l = Abs(s2 - s1), r = (int)1e9 + 1;     while (l < r) {       int mid = l + r >> 1;       if (solve(mid))         r = mid;       else         l = mid + 1;     }     printf( %d n , r);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     t = 1;     while (t--) {       long long n, m;       cin >> n;       cin >> m;       string s[n];       for (long long i = 0; i < n; i++) {         string cur =   ;         for (long long i = 0; i < m; i++) {           long long k;           cin >> k;           cur += to_string(k);         }         s[i] = cur;       }       if (n & 1)         cout << n << endl;       else {         long long ans = n;         while (n % 2 == 0) {           n = n / 2;           bool flag = 1;           for (long long i = 0; i < n; i++) {             if (s[i] != s[2 * n - i - 1]) {               flag = 0;               break;             }           }           if (!flag)             break;           else             ans = n;         }         cout << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     queue<long long> qR, qD;     string second;     cin >> second;     for (int i = 0; i < second.length(); i++) {       if (second[i] ==  R )         qR.push(i);       else         qD.push(i);     }     while (1) {       if (qD.empty()) {         cout <<  R  << endl;         break;       }       if (qR.empty()) {         cout <<  D  << endl;         break;       }       if (qD.front() > qR.front()) {         qD.pop();         int x = qR.front();         qR.pop();         qR.push(x + n);       } else {         qR.pop();         int x = qD.front();         qD.pop();         qD.push(x + n);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( -ffloat-store )   #pragma GCC optimize( -fno-defer-pop )   long long int power(long long int a, long long int b, long long int m) {     if (b == 0) return 1;     if (b == 1) return a % m;     long long int t = power(a, b / 2, m) % m;     t = (t * t) % m;     if (b & 1) t = ((t % m) * (a % m)) % m;     return t;   }   long long int modInverse(long long int a, long long int m) {     return power(a, m - 2, m);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int i, j, k, l, n;     cin >> n;     long long int ar[n + 1];     for (i = 1; i <= n; i++) {       cin >> ar[i];     }     long long int L[n + 2], R[n + 2];     memset(L, 0, sizeof(L));     memset(R, 0, sizeof(R));     L[1] = 1;     for (i = 2; i <= n; i++) {       L[i] = min(ar[i], L[i - 1] + 1);     }     R[n] = 1;     for (i = n - 1; i > 0; i--) {       R[i] = min(ar[i], 1 + R[i + 1]);     }     long long int an = -1e18;     for (i = 1; i <= n; i++) {       an = max(an, min(L[i], R[i]));     }     cout << an;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char ini[101], des[101];   int main() {     int i, L = strlen(ini), j;     gets(ini);     gets(des);     for (i = 0; ini[i]; i++) {       for (j = i + 1; ini[j]; j++) {         if (ini[i] > ini[j]) {           swap(ini[i], ini[j]);         }       }     }     for (i = 0; ini[i]; i++) {       if (ini[i] !=  0 ) break;     }     if (ini[i]) {       swap(ini[i], ini[0]);     }     if (!strcmp(ini, des)) {       puts( OK );     } else {       puts( WRONG_ANSWER );     }   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   long double DP[1010][1010];   int i, j;   int total, X;   int main() {     cin >> N >> M;     DP[0][0] = 1.0;     for (int i = 1; i <= N; i++)       for (int j = 0; j <= M && j <= N; j++) {         total = N * M - (i - 1);         X = M - j;         DP[i][j] += DP[i - 1][j] * (1.0 * total - X) / (1.0 * total);         if (j > 0) {           total = N * M - (i - 1);           X = M - j + 1;           DP[i][j] += DP[i - 1][j - 1] * (1.0 * X) / (1.0 * total);         }       }     long double ans = 0;     for (int i = 1; i <= N; i++)       ans += (1.0 * i) * (1.0 * i) / (1.0 * N) * DP[N][i];     cout << fixed << setprecision(20) << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, c, p, y, k, x, h, t, q;   string s;   vector<long long> v;   map<long long, long long> ma;   void input() {}   struct node {     map<string, node*> child;     map<string, long long> ispresent;     string name;     bool isfile = 0;   };   pair<long long, long long> dfs(node* root) {     pair<long long, long long> p = {0, 0};     if (root->isfile == 1) {       p = {0, 1};       return p;     }     pair<long long, long long> res = {0, 0};     for (auto i : root->child) {       p = dfs(i.second);       res.first += p.first;       res.second += p.second;     }     res.first++;     return res;   }   void solve() {     string s;     map<char, node*> roots;     roots[ C ] = new node();     roots[ D ] = new node();     roots[ E ] = new node();     roots[ F ] = new node();     roots[ G ] = new node();     while (cin >> s) {       long long n = s.size();       char disk = s[0];       node* temp = roots[disk];       for (long long i = 3; i < n; i++) {         long long j;         string names =   ;         bool file = 0;         for (j = i; s[j] !=      && j < n; j++) {           names += s[j];           if (s[j] ==  . ) file = 1;         }         i = j;         if (temp->ispresent[names] != 0) {           temp = temp->child[names];         } else {           node* newnode = new node();           if (file == 1) {             newnode->isfile = true;           }           newnode->name = names;           temp->child[names] = newnode;           temp->ispresent[names]++;           temp = temp->child[names];         }       }     }     long long maxfiles = 0;     long long maxfolder = 0;     for (auto i : roots[ C ]->child) {       pair<long long, long long> p = dfs(i.second);       maxfolder = max(maxfolder, p.first);       maxfiles = max(maxfiles, p.second);     }     for (auto i : roots[ D ]->child) {       pair<long long, long long> p = dfs(i.second);       maxfolder = max(maxfolder, p.first);       maxfiles = max(maxfiles, p.second);     }     for (auto i : roots[ E ]->child) {       pair<long long, long long> p = dfs(i.second);       maxfolder = max(maxfolder, p.first);       maxfiles = max(maxfiles, p.second);     }     for (auto i : roots[ F ]->child) {       pair<long long, long long> p = dfs(i.second);       maxfolder = max(maxfolder, p.first);       maxfiles = max(maxfiles, p.second);     }     for (auto i : roots[ G ]->child) {       pair<long long, long long> p = dfs(i.second);       maxfolder = max(maxfolder, p.first);       maxfiles = max(maxfiles, p.second);     }     cout << maxfolder - 1 <<     << maxfiles;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long T = 1;     while (T--) {       input();       solve();     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long a[100005], b[100005], l[100005], l2[100005];   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 1; i <= n; i++) cin >> b[i];     for (long long i = 2; i <= n; i++) {       l[i] = a[i - 1] - a[i];       l2[i] = b[i - 1] - b[i];     }     sort(l + 2, l + n + 1);     sort(l2 + 2, l2 + n + 1);     for (long long i = 2; i <= n; i++) {       if (l[i] != l2[i]) {         cout <<  No ;         return 0;       }     }     if (a[1] != b[1] || a[n] != b[n]) {       cout <<  No ;     } else       cout <<  Yes ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     ;     string s;     long long m, x = 0, k = 0;     long long a[3];     for (long long i = 0; i < 3; i++) {       cin >> a[i];     }     sort(a, a + 3);     k = a[2] - a[1] + a[1] - a[0];     cout << k;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   template <typename T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T, class T1>   inline void gn(T &first, T1 &second) {     gn(first);     gn(second);   }   template <class T, class T1, class T2>   inline void gn(T &first, T1 &second, T2 &z) {     gn(first);     gn(second);     gn(z);   }   template <typename T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   template <typename T>   inline void println(T first) {     print(first), putchar(  n );   }   template <typename T>   inline void printsp(T first) {     print(first), putchar(   );   }   template <class T, class T1>   inline void print(T first, T1 second) {     printsp(first), println(second);   }   template <class T, class T1, class T2>   inline void print(T first, T1 second, T2 z) {     printsp(first), printsp(second), println(z);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int main() {     int n;     gn(n);     if (n == 3) {       puts( >vv );       puts( ^<. );       puts( ^.< );       puts( 1 3 );       return 0;     }     if (n == 5) {       puts( >...v );       puts( v.<.. );       puts( ..^.. );       puts( >.... );       puts( ..^.< );       puts( 1 1 );       return 0;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == 1) {           if (j == n)             putchar( v );           else if (j <= n / 3)             putchar( > );           else if (j - n / 3 & 1)             putchar( > );           else             putchar( . );           continue;         }         if (i == n) {           if (j == 1)             putchar( ^ );           else if (j > n - n / 3)             putchar( < );           else if (n - n / 3 - j & 1)             putchar( < );           else             putchar( . );           continue;         }         if (j == 1) {           putchar( ^ );           continue;         }         if (i & 1) {           if (j == n)             putchar( v );           else if (j <= n / 3)             putchar( > );           else if (j - n / 3 & 1)             putchar( > );           else             putchar( . );         } else {           if (j == 2)             putchar( v );           else if (j > n - n / 3)             putchar( < );           else if (j & 1)             putchar( < );           else             putchar( . );         }       }       puts(  );     }     puts( 1 1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 2e18 + 5;   vector<long long> adj[1000001];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long r, c;     cin >> r >> c;     vector<string> a(r);     for (long long i = (0); i < (r); i++) cin >> a[i];     long long cnt = 0;     unordered_map<long long, long long> mikemon;     long long dest, sourc, x;     for (long long i = (0); i < (r); i++) {       for (long long j = (0); j < (c); j++) {         ++cnt;         if (a[i][j] ==  T ) continue;         if (i != 0) {           if (a[i - 1][j] !=  T ) {             adj[cnt].push_back(cnt - c);             adj[cnt - c].push_back(cnt);           }         }         if (i != r - 1) {           if (a[i + 1][j] !=  T ) {             adj[cnt].push_back(cnt + c);             adj[cnt + c].push_back(cnt);           }         }         if (j != 0) {           if (a[i][j - 1] !=  T ) {             adj[cnt].push_back(cnt - 1);             adj[cnt - 1].push_back(cnt);           }         }         if (j != c - 1) {           if (a[i][j + 1] !=  T ) {             adj[cnt].push_back(cnt + 1);             adj[cnt + 1].push_back(cnt);           }         }         if (a[i][j] ==  E )           dest = cnt;         else if (a[i][j] ==  S )           sourc = cnt;         else {           mikemon.insert({cnt, a[i][j] -  0 });         }       }     }     queue<long long> q;     vector<long long> vis(cnt + 1, 0), d(cnt + 1, inf);     vis[dest] = 1;     d[dest] = 1;     q.push(dest);     while (!q.empty()) {       x = q.front();       q.pop();       for (auto v : adj[x]) {         if (vis[v] == 0) {           vis[v] = 1;           q.push(v);           d[v] = d[x] + 1;         }       }     }     long long ans = 0;     long long y = d[sourc];     for (long long i = (1); i < (cnt + 1); i++) {       if (d[i] <= y) ans += mikemon[i];     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int v[200100], cnt[200020];   int n, s;   int main(void) {     ios::sync_with_stdio(false);     cin >> n >> s;     --s;     int er = 0;     int ans = 0;     for (int(i) = (0); (i) < (n); ++(i)) {       cin >> v[i];       cnt[v[i]]++;     }     if (v[s] != 0) {       ans++;       cnt[v[s]]--;       cnt[0]++;     }     int e = n - 1;     while (cnt[e] == 0) e--;     er = cnt[0] - 1;     ans += er;     for (int i = 1; i < e; i++) {       if (!cnt[i]) {         if (er)           er--;         else {           cnt[e]--;           cnt[i]++;           ans++;           while (cnt[e] == 0) e--;         }       }     }     cout << ans <<   n ;     return 0;   }