malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, m, k;     cin >> n >> m >> k;     int mn = INT_MAX;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       if (i != m && x != 0 && x <= k) {         mn = min(mn, abs(i - m));       }     }     cout << mn * 10;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 7;   const long long INF = 1LL << 60;   const long long mod = 1e9 + 7;   const long double eps = 1e-8;   const long double pi = acos(-1.0);   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   struct P {     long long x, y;   };   long double ex(P s, P t, P r) {     long double x1 = (long double)t.x - (long double)s.x;     long double y1 = (long double)t.y - (long double)s.y;     long double x2 = (long double)r.x - (long double)s.x;     long double y2 = (long double)r.y - (long double)s.y;     return x1 * y2 - x2 * y1;   }   bool cross(P a, P b, P s, P t) {     if (ex(a, b, s) * ex(a, b, t) > 0) return false;     if (ex(b, a, s) * ex(b, a, t) > 0) return false;     if (ex(t, s, a) * ex(t, s, b) > 0) return false;     return ex(s, t, a) * ex(s, t, b) < eps;   }   pair<bool, pair<long double, long double>> intersection_ls(P a1, P a2, P b1,                                                              P b2) {     long double d1 = abs(ex(b1, a1, b2));     long double d2 = abs(ex(b1, a2, b2));     if (!cross(a1, a2, b1, b2)) {       return {false, {0.0, 0.0}};     }     return {true,             {a1.x + (a2.x - a1.x) * d1 / (d1 + d2),              a1.y + (a2.y - a1.y) * d1 / (d1 + d2)}};   }   long long gcd(long long x, long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   void solve() {     long long n;     cin >> n;     vector<pair<P, P>> vec;     long long ans = 0;     for (long long i = 0; i < n; i++) {       long long ax, ay, bx, by;       cin >> ax >> ay >> bx >> by;       vec.push_back({P{ax, ay}, P{bx, by}});       ans += gcd(abs(ax - bx), abs(ay - by)) + 1;     }     map<pair<long long, long long>, long long> mp;     for (long long i = 0; i < n; i++) {       for (long long j = i + 1; j < n; ++j) {         auto res = intersection_ls(vec[i].first, vec[i].second, vec[j].first,                                    vec[j].second);         if (!res.first) continue;         long double X = res.second.first, Y = res.second.second;         if (floor(X + eps) < X + 2 * eps && floor(X + eps) > X - 2 * eps) {           if (floor(Y + eps) < Y + 2 * eps && floor(Y + eps) > Y - 2 * eps) {             mp[{floor(X + eps), floor(Y + eps)}]++;           }         }       }     }     for (auto p : mp) {       long long k = 2;       while (k * (k - 1) / 2 <= p.second) {         if (k * (k - 1) / 2 == p.second) {           ans -= (k - 1);           break;         }         ++k;       }     }     cout << ans << endl;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[20], st, tp, i;   int main() {     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     for (st = 0; st < (1 << n); st++) {       tp = 0;       for (i = 0; i < n; i++) {         if (st & (1 << i)) {           tp += a[i];           tp %= 360;         } else {           tp -= a[i];           tp += 360;           tp %= 360;         }       }       if (tp == 0) {         cout <<  yes ;         return 0;       }     }     cout <<  no ;   }
#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   long long rootans = 0;   vector<long long> dp1(200001, 1);   vector<long long> dp2(200001, 1);   vector<int> adj[200001];   void dfs(int u, int p) {     for (int i : adj[u]) {       if (i != p) {         dfs(i, u);         dp1[u] += dp1[i];       }     }   }   void dfs2(int u, int p) {     rootans += dp1[u];     for (int i : adj[u]) {       if (i != p) {         dfs2(i, u);       }     }   }   void dfs3(int u, int p) {     for (int i : adj[u]) {       if (i != p) {         dp2[i] = dp2[u] - dp1[i] + dp1[1] - dp1[i];         ans = max(ans, dp2[i]);         dfs3(i, u);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int a, b;     for (int i = 1; i < n; i++) {       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs(1, 0);     dfs2(1, 0);     dp2[1] = rootans;     dfs3(1, 0);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   static const int maxn = 100012;   int K1, K2, K3;   int T1, T2, T3;   int N;   int C[maxn];   void Read() {     int i;     scanf( %d%d%d , &K1, &K2, &K3);     scanf( %d%d%d , &T1, &T2, &T3);     scanf( %d , &N);     for (i = 0; i < N; ++i) {       scanf( %d , &C[i]);     }   }   inline bool Greater(long long x, long long y) { return x > y; }   long long Result;   long long X[maxn];   long long Y[maxn];   long long Z[maxn];   void Work() {     int i;     Result = 0;     memset(X, 0, sizeof(X));     memset(Y, 0, sizeof(Y));     memset(Z, 0, sizeof(Z));     if (K1 > N) K1 = N;     if (K2 > N) K2 = N;     if (K3 > N) K3 = N;     make_heap(X, X + K1, Greater);     make_heap(Y, Y + K2, Greater);     make_heap(Z, Z + K3, Greater);     for (i = 0; i < N; ++i) {       long long t = C[i];       pop_heap(X, X + K1, Greater);       if (t < X[K1 - 1]) t = X[K1 - 1];       t += T1;       X[K1 - 1] = t;       push_heap(X, X + K1, Greater);       pop_heap(Y, Y + K2, Greater);       if (t < Y[K2 - 1]) t = Y[K2 - 1];       t += T2;       Y[K2 - 1] = t;       push_heap(Y, Y + K2, Greater);       pop_heap(Z, Z + K3, Greater);       if (t < Z[K3 - 1]) t = Z[K3 - 1];       t += T3;       Z[K3 - 1] = t;       push_heap(Z, Z + K3, Greater);       if (Result < t - C[i]) Result = t - C[i];     }   }   void Write() { printf( %I64d n , Result); }   int main() {     Read();     Work();     Write();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[100005];   long long int V[256];   map<pair<int, long long int>, int> M;   int main() {     int i, n;     long long int prefixSum = 0, ans = 0;     for (i = 0; i < 26; i++) scanf( %lld , &V[ a  + i]);     scanf( %s , s);     n = strlen(s);     for (i = 0; i < n; i++) {       ans += M[make_pair(s[i], prefixSum)];       prefixSum += V[(int)s[i]];       M[make_pair(s[i], prefixSum)]++;     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int n, k;   char g[3][100005];   bool f;   bool isval(int i, int j) {     if (j >= n) return true;     if (j < 0) return false;     if (g[i][j] ==  X ) return false;     return true;   }   void dfs(int i, int j, int t) {     if (j >= n)       f = true;     else {       g[i][j] =  X ;       if (j + k > t && isval((i + 1) % 2, j + k))         dfs((i + 1) % 2, (j + k), t + 1);       if (j + 1 > t && isval(i, j + 1)) dfs(i, j + 1, t + 1);       if (j - 1 > t && isval(i, j - 1)) dfs(i, (j - 1), t + 1);     }   }   int main() {     cin >> n >> k;     for (int i = 0; i < 2; i++) cin >> g[i];     f = 0;     dfs(0, 0, 0);     if (!f)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n,i,j,k,a[5050],x[5050],y[5050];   long long scp(int i, int j, int k) {     long long xa=x[i]-x[j];     long long ya=y[i]-y[j];     long long xb=x[k]-x[j];     long long yb=y[k]-y[j];     return xa*xb+ya*yb;   }   int main() {     scanf( %d ,&n);     for (i=0; i<n; i++) scanf( %d%d ,&x[i],&y[i]);     a[0]=0;     a[1]=1;     for (i=2; i<n; i++) {       for (j=i; j>=0; --j) {         if (j>=2 && scp(a[j-2],a[j-1],i)<=0) continue;         if (j>=1 && j<i && scp(a[j-1],i,a[j])<=0) continue;         if (j+1<i && scp(i,a[j],a[j+1])<=0) continue;         for (k=i; k>j; --k) a[k]=a[k-1];         a[j]=i;         break;       }       if (j<0) { puts( -1 ); return 0; }     }     for (i=0; i<n; i++) printf( %d  ,a[i]+1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans[16];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     if (!(n & 1)) {       cout << 0 <<   n ;       return 0;     }     ans[1] = 1;     ans[3] = 18;     ans[5] = 1800;     ans[7] = 670320;     ans[9] = 734832000;     ans[11] = 890786230;     ans[13] = 695720788;     ans[15] = 150347555;     cout << ans[n] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long infL = LLONG_MAX;   struct psychotronic_induction {     int electromagnetic_wave = 7;   };   const int nmax = 1e5 + 10;   int n, m, a[nmax];   ;   int s[nmax], used[nmax];   vector<int> g[nmax];   pair<int, int> edge[nmax];   int second_node(int idx, int node) {     return (edge[idx].first == node) ? edge[idx].second : edge[idx].first;   }   bool dfs(int node, int curr = 0) {     s[node] ^= curr;     used[node] = 1;     for (auto &it : g[node]) {       if (used[second_node(it, node)]) {         if (s[second_node(it, node)] != 1 ^ a[it] ^ s[node]) return 0;         continue;       }       s[second_node(it, node)] = 1 ^ a[it] ^ s[node];       if (!dfs(second_node(it, node))) return 0;     }     return 1;   }   void mark(int node, int s) {     used[node] = s;     for (auto &it : g[node]) {       if (used[second_node(it, node)] == s) continue;       mark(second_node(it, node), s);     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= m; ++i) {       int nr;       scanf( %d , &nr);       for (int j = 1; j <= nr; ++j) {         int x;         scanf( %d , &x);         if (!edge[x].first)           edge[x].first = i;         else           edge[x].second = i;       }     }     swap(n, m);     for (int i = 1; i <= m; ++i)       g[edge[i].first].push_back(i), g[edge[i].second].push_back(i);     for (int i = 1; i <= n; ++i) {       if (used[i]) continue;       if (!dfs(i, 0)) {         mark(i, 0);         if (!dfs(i, 1)) {           printf( NO n );           return 0;         }       }       mark(i, 1);     }     printf( YES n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Nmax = 1e5 + 5;   string s, t;   int n, m, pos, l, r;   int pre[Nmax];   int suf[Nmax];   int main() {     cin >> s;     cin >> t;     n = s.size();     m = t.size();     s =     + s;     t =     + t;     pos = 1;     for (int i = 1; i <= m; i++) {       while (pos <= n && s[pos] != t[i]) pos++;       if (pos > n) break;       pre[pos++] = i;     }     for (int i = 1; i <= n; i++) {       if (pre[i] == 0) pre[i] = pre[i - 1];     }     pos = n;     for (int i = m; i >= 1; i--) {       while (pos > 0 && s[pos] != t[i]) pos--;       if (pos == 0) break;       suf[pos--] = m - i + 1;     }     for (int i = n; i >= 1; i--) {       if (suf[i] == 0) suf[i] = suf[i + 1];     }     for (int i = 0; i <= n; i++) {       if (pre[i] + suf[i + 1] > l + r) {         l = pre[i];         r = suf[i + 1];       }     }     if (l + r == 0)       cout <<  - ;     else {       if (l + r > m) {         for (int i = 1; i <= m; i++) cout << t[i];         return 0;       }       for (int i = 1; i <= l; i++) cout << t[i];       for (int i = m - r + 1; i <= m; i++) cout << t[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int depth;     cin >> depth;     int n = (1 << (depth + 1)) - 1;     vector<int> pre(n + 1, 0), add(n + 1, 0);     for (int i = 2; i <= n; ++i) {       cin >> pre[i];     }     vector<int> way(n + 1, 0);     for (int i = 2; i <= n; ++i) {       way[i] = way[i / 2] + pre[i];     }     int target = *max_element((way).begin(), (way).end());     for (int i = n / 2 + 1; i <= n; ++i) {       add[i] = target - way[i];     }     for (int i = n / 2; i >= 2; --i) {       add[i] = min(add[2 * i], add[2 * i + 1]);       add[2 * i] -= add[i];       add[2 * i + 1] -= add[i];     }     cout << accumulate((add).begin(), (add).end(), 0) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   bool ispos(long long x, long long y, long long n, long long m) {     if (x < 0 or x >= n or y < 0 or y >= m)       return false;     else       return true;   }   signed solve() {     long long n, m;     cin >> n >> m;     string s[n];     for (long long i = 0; i < n; i++) cin >> s[i];     char a[n][m];     vector<pair<pair<long long, long long>, long long>> v;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) a[i][j] =  . ;     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         long long sz = 0;         if (s[i][j] ==  * ) {           for (long long k = 1; k <= max(n, m); k++) {             if (ispos(i - k, j, n, m) and s[i - k][j] ==  *  and                 ispos(i, j - k, n, m) and s[i][j - k] ==  *  and                 ispos(i + k, j, n, m) and s[i + k][j] ==  *  and                 ispos(i, j + k, n, m) and s[i][j + k] ==  * ) {               sz++;             } else               break;           }         }         if (sz > 0) {           a[i][j] =  * ;           v.push_back({{i + 1, j + 1}, sz});           for (long long k = 1; k <= sz; k++) {             a[i - k][j] =  * ;             a[i + k][j] =  * ;             a[i][j - k] =  * ;             a[i][j + k] =  * ;           }         }       }     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         if (s[i][j] != a[i][j]) {           cout <<  -1                 <<   n ;           return 0;         }       }     }     cout << v.size() <<   n ;     for (long long i = 0; i < v.size(); i++) {       cout << v[i].first.first <<     << v[i].first.second <<     << v[i].second            <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tests = 1;     while (tests--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 100005;   const int N = 200005;   int from[N], to[N];   stack<pair<int, int> > G[MAX];   stack<int> res;   bool visited[2 * N];   void dfs(int src, int ind = -1) {     if (ind != -1) {       visited[ind] = true;     }     while (!G[src].empty()) {       int v = G[src].top().first, e = G[src].top().second;       G[src].pop();       if (!visited[e]) {         dfs(v, e);       }     }     res.push(src);   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d %d , &from[i], &to[i]);       from[i]--;       to[i]--;       G[from[i]].push(make_pair(to[i], i));       G[to[i]].push(make_pair(from[i], i));     }     int pre = -1, cnt = 0;     for (int i = 0; i < n; i++) {       if (G[i].size() % 2) {         if (pre == -1) {           pre = i;         } else {           G[pre].push(make_pair(i, cnt + m));           G[i].push(make_pair(pre, cnt++ + m));           pre = -1;         }       }     }     if ((cnt + m) % 2) {       G[0].push(make_pair(0, cnt + m));     }     dfs(0);     pre = res.top();     res.pop();     printf( %d n , res.size());     while (!res.empty()) {       if (res.size() % 2) {         printf( %d %d n , 1 + pre, 1 + res.top());       } else {         printf( %d %d n , 1 + res.top(), 1 + pre);       }       pre = res.top();       res.pop();     }     return 0;   }
#include <bits/stdc++.h>   const long long mod = 1000000007;   long long qpow(long long v, long long st) {     long long r = 1;     while (st) {       if (st & 1) {         r *= v;         r %= mod;       }       v = v * v;       v %= mod;       st = st / 2;     }     return r;   }   long long f[1024];   long long dp[1024][1024];   long long sdp[1024][1024];   long long getDP(int, int);   long long getSdp(int b1, int b2) {     if (sdp[b1][b2] != -1) return sdp[b1][b2];     if (b2 == 0) return getDP(b1 - 2, 0);     sdp[b1][b2] = getSdp(b1, b2 - 1) + getDP(b1 - 2, b2) * qpow(f[b2], mod - 2);     sdp[b1][b2] %= mod;     return sdp[b1][b2];   }   long long getDP(int b1, int b2) {     if (dp[b1][b2] != -1) return dp[b1][b2];     if (!b1) return f[b2];     long long sol = 0;     if (b1 >= 2) {       long long p = getSdp(b1, b2);       p *= f[b2];       p %= mod;       p *= (b1 - 1);       p %= mod;       sol += p;       sol %= mod;     }     if (b2 > 0) {       sol += getDP(b1, b2 - 1) * b2;       sol %= mod;     }     sol += getDP(b1 - 1, b2);     if (sol >= mod) sol %= mod;     dp[b1][b2] = sol;     return dp[b1][b2];   }   int main() {     int i, j, k;     f[0] = 1;     for (i = 1; i <= 1000; i++) {       f[i] = f[i - 1] * i;       f[i] %= mod;     }     j = k = 0;     int n, l;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &l);       if (l == 1)         j++;       else         k++;     }     memset(dp, -1, sizeof(dp));     memset(sdp, -1, sizeof(sdp));     printf( %d n , (int)getDP(j, k));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int frombase(int x, int base) {     int i = 0;     int ans = 0;     while (x) {       ans += ((x % base) * pow((double)10, i));       i++;       x /= base;     }     return ans;   }   int tobase(int x, int base) {     int i = 0;     int ans = 0;     while (x) {       ans += ((x % 10) * pow((double)base, i));       i++;       x /= 10;     }     return ans;   }   int main() {     int a, b;     cin >> a >> b;     int maxi = 0;     int x = a;     while (x) {       maxi = max(x % 10, maxi);       x /= 10;     }     x = b;     while (x) {       maxi = max(x % 10, maxi);       x /= 10;     }     maxi++;     int sum = tobase(a, maxi) + tobase(b, maxi);     sum = frombase(sum, maxi);     x = 0;     while (sum) {       sum /= 10;       x++;     }     cout << x << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int i, j, k, p, r, n, c = 0;     scanf( %d , &n);     char s[1000000];     scanf( %s , s);     for (i = 0; i < n - 2; i++) {       if (s[i] == s[i + 1]) {         c++;         if (s[i] ==  G ) {           if (s[i + 2] ==  R )             s[i + 1] =  B ;           else if (s[i + 2] ==  B )             s[i + 1] =  R ;           else if (s[i + 2] ==  G )             s[i + 1] =  B ;         } else if (s[i] ==  R ) {           if (s[i + 2] ==  G )             s[i + 1] =  B ;           else if (s[i + 2] ==  B )             s[i + 1] =  G ;           else if (s[i + 2] ==  R )             s[i + 1] =  B ;         } else if (s[i] ==  B ) {           if (s[i + 2] ==  R )             s[i + 1] =  G ;           else if (s[i + 2] ==  G )             s[i + 1] =  R ;           else if (s[i + 2] ==  B )             s[i + 1] =  G ;         }       }     }     if (s[n - 1] == s[n - 2]) {       c++;       if (s[n - 2] ==  R )         s[n - 1] =  G ;       else if (s[n - 2] ==  G )         s[n - 1] =  R ;       else if (s[n - 2] ==  B )         s[n - 1] =  G ;     }     printf( %d n , c);     puts(s);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, sum = 0;     cin >> n >> k;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int j = 0; j < k; j++) {       int c1 = 0, c2 = 0;       for (int i = j; i < n; i += k) {         if (a[i] == 1)           c1++;         else           c2++;       }       (c1 > c2) ? (sum += c2) : (sum += c1);     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     if ((int)s.size() < 26) {       cout << -1;       return 0;     }     char cur =  a ;     bool fg = 0;     for (int i = 0; i < (int)s.size(); i++) {       if (s[i] <= cur) {         if (cur ==  z ) {           s[i] = cur;           fg = 1;           break;         } else           s[i] = cur;         cur++;       }     }     if (cur ==  z  && fg)       cout << s;     else       cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5500;   char s[N];   int ans[N], dp[N][N];   int main() {     scanf( %s , s + 1);     int n = strlen(s + 1);     for (int i = 1; i <= n; i++) {       dp[i][i] = 1;       ans[1]++;       if (i < n && s[i] == s[i + 1]) {         dp[i][i + 1] = 2;         ans[1]++;         ans[2]++;       }     }     for (int k = 3; k <= n; k++) {       for (int i = 1; i + k - 1 <= n; i++) {         if (dp[i + 1][i + k - 2] && s[i] == s[i + k - 1]) {           dp[i][i + k - 1] = dp[i][i + k / 2 - 1] + 1;           for (int j = 1; j <= dp[i][i + k - 1]; j++) ans[j]++;         }       }     }     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T nextInt() {     T x = 0, p = 1;     char ch;     do {       ch = getchar();     } while (ch <=    );     if (ch ==  - ) {       p = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + (ch -  0 );       ch = getchar();     }     return x * p;   }   const int maxN = (int)4e5 + 10;   const int INF = (int)1e9;   const int mod = (int)1e9 + 7;   const long long LLINF = (long long)1e15;   int fw[maxN];   int answer[maxN];   vector<pair<int, int> > g[maxN];   int get(int r) {     int ret = 0;     for (; r >= 0; r = (r & (r + 1)) - 1) {       ret += fw[r];     }     return ret;   }   void update(int r) {     for (; r < maxN; r |= r + 1) {       fw[r]++;     }   }   int l[maxN];   int r[maxN];   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<int> x;     for (int i = 0; i < n; ++i) {       cin >> l[i] >> r[i];       x.push_back(l[i]);       x.push_back(r[i]);     }     sort(x.begin(), x.end());     for (int i = 0; i < n; ++i) {       l[i] = lower_bound(x.begin(), x.end(), l[i]) - x.begin();       r[i] = lower_bound(x.begin(), x.end(), r[i]) - x.begin();       g[r[i]].push_back(make_pair(l[i], i));     }     for (int i = 0; i < maxN; ++i) {       for (auto x : g[i]) {         int l = x.first;         int idx = x.second;         answer[idx] = get(maxN - 1) - get(l);         update(l);       }     }     for (int i = 0; i < n; ++i) {       cout << answer[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int q = 0;     char ch =    ;     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) q = q * 10 + ch -  0 , ch = getchar();     return q;   }   const int N = 100005;   double P[N][110], ans;   int n, m, a[N], b[N];   double C(int d, int u) {     if (d < u || d < 0 || u < 0) return 0;     double ans = 1;     for (register int i = d - u + 1; i <= d; ++i) ans *= i;     for (register int i = 1; i <= u; ++i) ans /= i;     return ans;   }   int main() {     n = read();     for (register int i = 1; i <= n; ++i)       a[i] = b[i] = read(), P[i][a[i]] = 1, ans += (a[i] == 0);     m = read();     while (m--) {       int x = read(), y = read(), k = read();       ans -= P[x][0];       for (register int i = 0; i <= a[x]; ++i) {         double tmp = 0, all = C(b[x], k);         for (register int j = 0; j <= k; ++j)           tmp += P[x][i + j] * C(b[x] - i - j, k - j) * C(i + j, j);         P[x][i] = tmp / all;       }       ans += P[x][0], b[x] -= k, b[y] += k;       printf( %.10lf n , ans);     }     return 0;   }
#include <bits/stdc++.h>   int const INF = 2e9;   int const MOD = 1000000007;   int const MAXN = 100010;   using namespace std;   int n, m, sum1, sum2, ans;   int a[MAXN], b[MAXN];   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int j = 0; j < m; j++) cin >> b[j];     int i = 1, j = 1;     sum1 = a[0], sum2 = b[0];     while (true) {       if (sum1 < sum2)         sum1 += a[i], i++;       else if (sum2 < sum1)         sum2 += b[j], j++;       else {         if (i == n && j == m) {           ans++;           break;         } else           sum1 = a[i], sum2 = b[j], i++, j++, ans++;       }     }     cout << ans;     return 0;   }