malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct vect {     int h, p1, p2;   };   struct point {     int p1, p2;   };   int n, mod, nr, t;   long long solf;   int viz[200005];   point poz[200005];   map<int, vect> h;   vector<int> aib[200005];   void precalc() {     int i, j, x;     for (i = 0; i < n; i++)       if (!viz[i]) {         x = 1;         j = i;         nr++;         do {           viz[j] = nr;           poz[j].p1 = x;           x++;           j = (j + mod) % n;         } while (!viz[j]);         j = i;         do {           poz[j].p2 = poz[j].p1 + x - 1;           j = (j + mod) % n;         } while (!poz[j].p2);         for (j = 0; j <= 2 * x; j++) aib[nr].push_back(0);       }   }   void update(int ind, int poz, int val) {     while (poz < aib[ind].size()) {       aib[ind][poz] += val;       poz += poz & -poz;     }   }   int query(int ind, int poz) {     int sol = 0;     while (poz > 0) {       sol += aib[ind][poz];       poz -= poz & -poz;     }     return sol;   }   int find(int x) {     int st = poz[x].p1, dr = poz[x].p2, m, sol = dr - 1;     int nr = st - query(viz[x], st);     while (st <= dr) {       m = (st + dr) >> 1;       if (m - query(viz[x], m) > nr) {         sol = m;         dr = m - 1;       } else         st = m + 1;     }     solf += sol - poz[x].p1;     sol = ((1LL * (sol - poz[x].p1) * mod) % n + x) % n;     return sol;   }   int main() {     scanf( %d %d %d n , &n, &mod, &t);     precalc();     vect x;     char ch;     int id, hash, y, z;     while (t--) {       scanf( %c , &ch);       if (ch ==  - ) {         scanf( %d n , &id);         x = h[id];         update(x.h, x.p1, -1);         update(x.h, x.p2, -1);         h[id] = (vect){0, 0, 0};       } else {         scanf( %d %d n , &id, &hash);         x.h = viz[hash];         x.p1 = poz[hash].p1;         x.p2 = poz[hash].p2;         y = query(x.h, x.p1);         z = query(x.h, x.p1 - 1);         if (y != z) hash = find(hash);         x.h = viz[hash];         x.p1 = poz[hash].p1;         x.p2 = poz[hash].p2;         h[id] = x;         update(x.h, x.p1, 1);         update(x.h, x.p2, 1);       }     }     printf( %I64d n , solf);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans = 0;   string searchS;   map<string, int> mp;   set<string> st;   void getans(string s, int idx) {     if (idx == searchS.size()) {       if (!st.count(s)) {         ans += mp[s];         st.insert(s);       }       return;     }     if (searchS[idx] ==  ? ) {       for (int i = 0; i < 5; i++) getans(s + char(i +  a ), idx + 1);       getans(s, idx + 1);     } else       getans(s + searchS[idx], idx + 1);   }   void lets_hope_its_right() {     int n, m;     cin >> n >> m;     while (n--) {       string s;       cin >> s;       mp[s]++;     }     while (m--) {       string s;       cin >> s;       ans = 0;       searchS = s;       st.clear();       getans(  , 0);       cout << ans <<   n ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tt = 1;     while (tt--) lets_hope_its_right();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3050;   int a[N];   int b[N];   long long dp[N][N];   int main() {     int n, m, i, j;     long long ans = 0, minPre;     scanf( %d , &n);     set<int> S;     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);       a[i] -= i;       S.insert(a[i]);     }     m = 0;     for (set<int>::iterator iter = S.begin(); iter != S.end(); iter++) {       b[++m] = *iter;     }     for (j = 1; j <= m; j++) {       dp[1][j] = abs(a[1] - b[j]);     }     for (i = 2; i <= n; i++) {       minPre = dp[i - 1][1];       for (j = 1; j <= m; j++) {         minPre = min(minPre, dp[i - 1][j]);         dp[i][j] = minPre + abs(a[i] - b[j]);       }     }     ans = 1e18;     for (j = 1; j <= m; j++) {       ans = min(ans, dp[n][j]);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 150 + 10;   void remax(int& x, int y) {     if (x < y) {       x = y;     }   }   int n;   char s[MAXN];   int a[MAXN];   bool read() {     if (scanf( %d n , &n) < 1) {       return 0;     }     for (int i = 0; i < (int)n; ++i) {       scanf( %d , &a[i + 1]);     }     scanf(  n );     scanf( %s n , s);     assert((int)strlen(s) == n);     return 1;   }   int dp[MAXN][MAXN];   int dp_pal[MAXN][MAXN][MAXN];   int dp_full[MAXN][MAXN];   int solve() {     memset(dp, 0, sizeof dp);     memset(dp_full, -1, sizeof dp_full);     memset(dp_pal, -1, sizeof dp_pal);     for (int len = 1; len <= n; ++len) {       for (int l = 0; l < (int)n - len + 1; ++l) {         int r = l + len - 1;         assert(r < n);         {           for (int m = l; m < r; ++m) {             if (dp_full[l][m] != -1 && dp_full[m + 1][r] != -1) {               remax(dp_full[l][r], dp_full[l][m] + dp_full[m + 1][r]);             }           }           if (s[l] == s[r]) {             if (len <= 2) {               remax(dp_full[l][r], a[len]);             } else {               remax(dp_full[l][r], dp_pal[l + 1][r - 1][2]);             }           }         }         {           for (int m = l; m < r; ++m) {             remax(dp[l][r], dp[l][m] + dp[m + 1][r]);           }           remax(dp[l][r], dp_full[l][r]);         }         {           for (int out = 2; out <= n - len; out += 2) {             if (dp_full[l][r] != -1 && a[out] != -1) {               remax(dp_pal[l][r][out], dp_full[l][r] + a[out]);             }             for (int m = l; m < r; ++m) {               if (dp_pal[l][m][out] != -1 && dp_full[m + 1][r] != -1) {                 remax(dp_pal[l][r][out], dp_pal[l][m][out] + dp_full[m + 1][r]);               }             }             for (int m = l + 1; m <= r; ++m) {               if (dp_full[l][m - 1] != -1 && dp_pal[m][r][out] != -1) {                 remax(dp_pal[l][r][out], dp_full[l][m - 1] + dp_pal[m][r][out]);               }             }             if (s[l] == s[r]) {               if (len <= 2) {                 remax(dp_pal[l][r][out], a[out + len]);               } else {                 remax(dp_pal[l][r][out], dp_pal[l + 1][r - 1][out + 2]);               }             }           }         }       }     }     return dp[0][n - 1];   }   int main() {     while (read()) {       printf( %d n , solve());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long int q;     cin >> q;     while (q--) {       long long int l1, r1, l2, r2;       cin >> l1 >> r1 >> l2 >> r2;       cout << l1 <<     << ((l1 != l2) ? l2 : r2) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 3e5 + 10;   class SegmentTree {    public:     long long addv[N * 4];     int ql, qr, qx;     void set(int l, int r, int x = 0) { ql = l, qr = r, qx = x; }     void add(int l, int r, int o = 1) {       if (ql <= l && r <= qr) {         addv[o] += qx;         return;       }       int mid = (l + r) >> 1;       if (ql <= mid) add(l, mid, o << 1);       if (mid < qr) add(mid + 1, r, o << 1 | 1);     }     long long query(int l, int r, int o = 1) {       long long ret = addv[o];       if (l == r) {         return ret;       }       int mid = (l + r) >> 1;       if (ql <= mid) ret += query(l, mid, o << 1);       if (mid < qr) ret += query(mid + 1, r, o << 1 | 1);       return ret;     }   } st;   vector<int> v[N];   vector<pair<int, int>> qr[N];   int depth[N];   int h = 0;   long long ans[N];   void dfs(int x, int fa = 0) {     depth[x] = depth[fa] + 1;     h = max(h, depth[x]);     for (auto &y : v[x]) {       if (y == fa) continue;       dfs(y, x);     }   }   void solve(int x, int fa = 0) {     int l = depth[x];     for (auto &p : qr[x]) {       int r;       int val;       tie(r, val) = p;       st.set(l, r, val);       st.add(1, h);     }     st.set(l, l);     ans[x] = st.query(1, h);     for (auto &y : v[x]) {       if (y == fa) continue;       solve(y, x);     }     for (auto &p : qr[x]) {       int r;       int val;       tie(r, val) = p;       st.set(l, r, -val);       st.add(1, h);     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     dfs(1);     int q;     scanf( %d , &q);     while (q--) {       int x, d, val;       scanf( %d%d%d , &x, &d, &val);       d = min(h, depth[x] + d);       qr[x].push_back({d, val});     }     solve(1);     for (int i = 1; i <= n; i++) printf( %lld  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 7;   const long long inf = 0x3f3f3f3f;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       double pi = 3.1415926535897932384626433832795028841971, n;       cin >> n;       printf( %.10lf n , 1 / tan(pi / (n * 2)));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, n, x, j, c = 0;     cin >> n >> x;     if (n >= x) {       for (i = 2; i <= n; i++) {         if (x % i == 0 && (x / i) <= n) c++;       }       cout << c + 1 << endl;     } else {       for (i = 2; i <= n; i++) {         if (x % i == 0 && (x / i) <= n) c++;       }       cout << c << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     scanf( %d , &N);     int P;     scanf( %d , &P);     vector<int> As, Bs;     long long SA = 0, SB = 0;     for (decltype(N) _i = 0, _n = (N); _i < _n; _i++) {       int A;       scanf( %d , &A);       int B;       scanf( %d , &B);       As.push_back(A);       Bs.push_back(B);       SA += A;       SB += B;     }     auto check = [&](double t) {       double tmp = 0.0;       for (decltype(N) i = 0, _n = (N); i < _n; i++) {         tmp += max(As[i] * t - Bs[i], 0.0) / P;       }       return tmp <= t;     };     if (SA <= P) {       printf( -1 n );     } else {       double l = 0.0, r = SB * 2.0;       int cnt = 0;       while (1e-10 < (r - l) and cnt < 1000) {         cnt++;         double c = (l + r) / 2;         if (check(c)) {           l = c;         } else {           r = c;         }       }       printf( %f , l);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 9e18;   const long long N = 2e5 + 5;   const long long M = 1e9 + 7;   bool chk(vector<long long> a, long long x, long long y) {     long long A = 0, B = 0;     for (long long i = 2; i < a.size(); i++)       if (a[i] > a[i - 1] && a[i] > a[i + 1])         A++;       else if (a[i] < a[i - 1] && a[i] < a[i + 1])         B++;     if (A == x && B == y) return 1;     return 0;   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0);     long long tests;     cin >> tests;     while (tests--) {       vector<long long> a;       long long n, x, y;       bool ok = 0;       cin >> n >> x >> y;       if (abs(x - y) > 1 || x + y > n - 2) {         cout <<  -1 n ;         continue;       }       if (x >= y) {         long long l = 1;         long long r = n;         while (l <= r) {           a.push_back(l++);           if (l > r) break;           a.push_back(r--);         }         long long idx = 1 + 2 * y;         if (x > y) idx++;         sort(a.begin() + idx, a.begin() + n);         if (x > y) reverse(a.begin() + idx, a.begin() + n);       } else {         long long l = 1;         long long r = n;         while (l <= r) {           a.push_back(r--);           if (l > r) break;           a.push_back(l++);         }         long long idx = 2 * y;         sort(a.begin() + idx, a.begin() + n);       }       for (auto h : a) cout << h <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int q;     std::cin >> q;     while (q--) {       int n;       std::cin >> n;       std::cout << ((n + 6) / 7) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 10, mod = 11092019;   int n, m[2], leaf[N][2], dep[N][2], p[16][2][N], pre[N][2], dist[N][N][2],       dp[N][2];   vector<int> adj[N][2];   void predfs(int u, int pa, int lst, bool st) {     p[0][st][u] = pa;     dep[u][st] = dep[pa][st] + 1;     pre[u][st] = lst;     lst = (adj[u][st].size() > 1 ? u : lst);     for (int v : adj[u][st]) {       predfs(v, u, lst, st);     }   }   pair<int, int> lca(int u, int v, bool st) {     int dis = 0;     if (dep[u][st] > dep[v][st]) swap(u, v);     for (int j = 15; j >= 0; j--) {       if (dep[v][st] - (1 << j) >= dep[u][st]) {         dis += (1 << j);         v = p[j][st][v];       }     }     if (u == v) return {u, dis};     dis += 2;     for (int j = 15; j >= 0; j--) {       if (p[j][st][u] != p[j][st][v]) {         u = p[j][st][u];         v = p[j][st][v];         dis += (2 << j);       }     }     return {p[0][st][u], dis};   }   int main() {     scanf( %d , &n);     for (int s = 0; s < 2; s++) {       scanf( %d , &m[s]);       for (int i = 2; i <= m[s]; i++) {         int x;         scanf( %d , &x);         adj[x][s].push_back(i);       }       for (int i = 1; i <= n; i++) {         int x;         scanf( %d , &x);         leaf[i][s] = x;       }     }     predfs(1, 1, 1, 0);     predfs(1, 1, 1, 1);     for (int j = 1; j < 16; j++) {       for (int st = 0; st < 2; st++) {         for (int i = 1; i <= m[st]; i++)           p[j][st][i] = p[j - 1][st][p[j - 1][st][i]];       }     }     for (int st = 0; st < 2; st++) {       for (int i = 1; i <= n; i++) {         int dis = 0;         vector<int> sum(m[st] + 1, 0);         for (int j = i; j <= n; j++) {           int v = leaf[j][st];           int u = pre[v][st];           dis += dep[v][st] - dep[u][st];           sum[u]++;           while (sum[u] == adj[u][st].size()) {             dis += dep[u][st] - dep[pre[u][st]][st];             u = pre[u][st];             sum[u]++;           }           dist[i][j][st] = dis;         }       }     }     for (int i = 1; i <= n; i++) {       for (int st = 0; st < 2; st++) {         for (int j = i; j >= 1; j--)           dp[i][st] = max(dp[i][st], dp[j - 1][1 - st] + dist[j][i][st]);       }     }     printf( %d n , max(dp[n][0], dp[n][1]));     return 0;   }
#include <bits/stdc++.h>   int n, k, a[100001], is[100001], i, j, sum, ans;   int main() {     scanf( %d %d , &n, &k);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < n; i++) scanf( %d , &is[i]);     for (i = 0; i < k; i++) sum += a[i];     for (i = k; i < n; i++)       if (is[i]) sum += a[i];     ans = sum;     for (i = 0; i < n - k + 1; i++) {       if (is[i] == 0) sum -= a[i];       if (is[i + k] == 0) sum += a[i + k];       if (ans < sum) ans = sum;     }     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   int N, M, ans, S, T, C;   pair<int, int> ap;   struct edge {     int u, v, w, i;     bool operator<(const edge &o) const { return w < o.w; }   } tmp[30300];   vector<edge> e;   vector<pair<int, int>> adj[1100];   int id[1100], lo[1100], tp[1100], ep[1100];   bool art[1100];   struct uf {     int p[1100];     void init() {       for (int i = (1); i < (N + 1); i++) p[i] = i;     }     int g(int i) { return p[i] == i ? i : p[i] = g(p[i]); }     bool c(int i, int j) { return g(i) == g(j); }     void m(int i, int j) { p[g(i)] = g(j); }   } a, b, c;   void clr() {     for (int i = (1); i < (N + 1); i++) {       adj[i].clear();       id[i] = 0, lo[i] = 0, art[i] = 0;       tp[i] = 0, ep[i] = 0;     }     C = 0;   }   void go(int i, int p) {     id[i] = ++C;     lo[i] = id[i];     for (auto j : adj[i]) {       if (j.first == p)         p = -1;       else if (!id[j.first]) {         tp[j.first] = i;         ep[j.first] = j.second;         go(j.first, i);         lo[i] = min(lo[i], lo[j.first]);       } else         lo[i] = min(lo[i], id[j.first]);     }     if (lo[i] == id[i]) art[i] = 1;   }   int main() {     scanf( %d %d %d %d , &N, &M, &S, &T);     a.init(), b.init(), c.init(), ans = 2e9 + 7, ap = {-1, -1};     for (int i = (0); i < (M); i++) {       scanf( %d %d %d , &tmp[i].u, &tmp[i].v, &tmp[i].w);       tmp[i].i = i + 1;     }     sort(tmp, tmp + M);     for (int i = (0); i < (M); i++) {       if (!a.c(tmp[i].u, tmp[i].v)) {         a.m(tmp[i].u, tmp[i].v);         e.push_back(tmp[i]), e.back().i = i;       } else if (!b.c(tmp[i].u, tmp[i].v)) {         b.m(tmp[i].u, tmp[i].v);         e.push_back(tmp[i]), e.back().i = i;       } else if (!c.c(tmp[i].u, tmp[i].v)) {         c.m(tmp[i].u, tmp[i].v);         e.push_back(tmp[i]), e.back().i = i;       }     }     if (!a.c(S, T)) return puts( 0 n0 ), 0;     clr();     for (int i = (0); i < ((int)e.size()); i++) {       adj[e[i].u].push_back({e[i].v, e[i].i}),           adj[e[i].v].push_back({e[i].u, e[i].i});     }     go(S, -1);     int x = T;     while (x != S) {       if (art[x]) {         if (tmp[ep[x]].w < ans) {           ans = tmp[ep[x]].w;           ap = {tmp[ep[x]].i, -1};         }       }       x = tp[x];     }     for (int rem = (0); rem < ((int)e.size()); rem++) {       int extra = 0, rid = -1;       clr();       for (int i = (0); i < ((int)e.size()); i++) {         if (i != rem) {           adj[e[i].u].push_back({e[i].v, e[i].i}),               adj[e[i].v].push_back({e[i].u, e[i].i});         } else           extra = e[i].w, rid = tmp[e[i].i].i;       }       go(S, -1);       if (!id[T]) continue;       x = T;       while (x != S) {         if (art[x]) {           if (tmp[ep[x]].w + extra < ans) {             ans = tmp[ep[x]].w + extra;             ap = {tmp[ep[x]].i, rid};           }         }         x = tp[x];       }     }     if (ans == 2e9 + 7)       puts( -1 );     else {       printf( %d n , ans);       if (ap.second == -1) {         printf( 1 n%d n , ap.first);       } else {         printf( 2 n%d %d n , ap.first, ap.second);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long part[4001];   unsigned long long pmod(unsigned long long n, int exp) {     unsigned long long x = 1, y = n;     while (exp > 0) {       if (1 == (exp % 2)) {         x = x * y;         if (x > 1000000007) x = x % 1000000007;       }       y = y * y;       if (y > 1000000007) y = y % 1000000007;       exp /= 2;     }     return x;   }   unsigned long long inv(unsigned long long x) { return pmod(x, 1000000007 - 2); }   unsigned long long Rfact[4001];   unsigned long long Ifact[4001];   unsigned long long fact(int x) {     if (!Rfact[x]) {       unsigned long long ret = 1;       for (int i = x; i >= 2; i--) {         ret = (ret * i) % 1000000007;       }       Rfact[x] = ret;     }     return Rfact[x];   }   unsigned long long inv_fact(int x) {     if (!Ifact[x]) {       Ifact[x] = inv(fact(x));     }     return Ifact[x];   }   unsigned long long com(int n, int r) {     unsigned long long ret = fact(n);     ret = (ret * inv_fact(n - r)) % 1000000007;     ret = (ret * inv_fact(r)) % 1000000007;     return ret;   }   int main() {     part[0] = part[1] = 1;     for (int i = 2; i <= 4000; i++) {       for (int j = 0; j < i; j++) {         unsigned long long tadd = (com(i - 1, j) * part[j]) % 1000000007;         part[i] = (part[i] + tadd) % 1000000007;       }     }     int n;     cin >> n;     unsigned long long ret = 0;     for (int i = 1; i <= n; i++) {       unsigned long long tadd = (com(n, i) * part[n - i]) % 1000000007;       ret = (ret + tadd) % 1000000007;     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, last = 1;     cin >> n >> a >> b;     if (a > 0 && a > n - 2) {       cout << -1;       return 0;     }     cout << last;     for (int i = 1; i < n; i++) {       cout <<    ;       if (b) {         last <<= 1;         cout << last;         b--;       } else if (a && i >= 2) {         last++;         cout << last;         a--;       } else         cout << last;     }     cin >> n;   }
#include <bits/stdc++.h>   using namespace std;   int sz[100005];   long long pw[100005];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       sz[a]++;       sz[b]++;     }     int lf = 0;     for (int i = 1; i <= n; i++)       if (sz[i] == 1) lf++;     pw[0] = 1LL;     for (int i = 1; i <= 100000; i++) pw[i] = (pw[i - 1] * 2) % 1000000007;     long long res = lf * pw[n - lf + 1] + (n - lf) * pw[n - lf];     res %= 1000000007;     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     long long ss4 = 0, ss7 = 0, swap = 0;     string s, t;     cin >> s >> t;     for (long long i = 0; i < s.length(); i++) {       if (s[i] != t[i] && s[i] ==  4 ) {         if (ss7)           ss7--, swap++;         else           ss4++;       } else if (s[i] != t[i] && s[i] ==  7 )         if (ss4)           ss4--, swap++;         else           ss7++;     }     cout << swap + ss7 + ss4 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     set<int> ase;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       if (ase.size() >= x) {         ase.insert(x);       } else {         cout << i << endl;         return 0;       }     }     cout << -1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, half;   long long k, ans = 0, a[25][25];   map<long long, int> mp[20][20];   void calcf(int x, int y, long long val, int cnt) {     val ^= a[x][y];     if (cnt == half) {       mp[x][y][val]++;       return;     }     if (x + 1 < n) calcf(x + 1, y, val, cnt + 1);     if (y + 1 < m) calcf(x, y + 1, val, cnt + 1);   }   void calcb(int x, int y, long long val, int cnt) {     if (cnt == n + m - 2 - half) {       if (mp[x][y].count(val ^ k)) ans += mp[x][y][val ^ k];       return;     }     val ^= a[x][y];     if (x > 0) calcb(x - 1, y, val, cnt + 1);     if (y > 0) calcb(x, y - 1, val, cnt + 1);   }   int main() {     int i, j;     cin >> n >> m >> k;     half = (n + m - 2) / 2;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) cin >> a[i][j];     calcf(0, 0, 0, 0);     calcb(n - 1, m - 1, 0, 0);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T sqr(T x) {     return x * x;   }   inline unsigned long long bit(int num) { return 1ull << num; }   long long FindXor(long long r) {     long long rem = r % 4;     switch (rem) {       case 0:         return r;       case 1:         return 1;       case 2:         return r + 1;       case 3:         return 0;     }   }   long long FindXor(long long l, long long r) {     return FindXor(r) ^ FindXor(l - 1);   }   int main() {     int n;     cin >> n;     long long res = 0;     for (int i = 0; i < int(n); ++i) {       long long x, m;       cin >> x >> m;       res ^= FindXor(x, x + m - 1);     }     cout << (res ?  tolik  :  bolik ) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gi() {     char ch =  ! ;     int res = 0, f = 0;     while (ch <  0  || ch >  9 ) {       ch = getchar();       if (ch ==  - ) f = 1;     }     while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar();     return f ? -res : res;   }   const int N = 1e5 + 7;   int n, Q, arr[N], cur[N];   double f[N][110], ans;   int main() {     n = gi();     for (int i = 1; i <= n; ++i) {       arr[i] = gi(), f[i][arr[i]] = 1, cur[i] = arr[i];       ans += f[i][0];     }     Q = gi();     for (int i = 1; i <= Q; ++i) {       int u = gi(), v = gi(), x = gi();       ans -= f[u][0];       for (int k = 1; k <= x; ++k) {         for (int j = 0; j <= arr[u]; ++j) {           if (j > cur[u])             f[u][j] = 0;           else {             f[u][j] = (cur[u] - j) / (double)cur[u] * f[u][j];             if (j + 1 <= cur[u])               f[u][j] += (j + 1) / (double)cur[u] * f[u][j + 1];           }         }         --cur[u];       }       cur[v] += x;       ans += f[u][0];       printf( %.10lf n , ans);     }     return 0;   }