malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int M = (int)1e5 + 5;   int n;   int a[M];   int q, ans[M];   vector<pair<int, int> > ps[M];   int pas[M], las[M], llas[M], mfr[M];   struct SEGMENT1 {     int val[M * 4];     void update(int L, int R, int p, int l, int r, int v) {       if (L == l && R == r) {         val[p] += v;         return;       }       int mid = (L + R) >> 1;       if (mid >= r)         update(L, mid, p << 1, l, r, v);       else if (mid < l)         update(mid + 1, R, p << 1 | 1, l, r, v);       else         update(L, mid, p << 1, l, mid, v),             update(mid + 1, R, p << 1 | 1, mid + 1, r, v);     }     int query(int L, int R, int p, int x) {       if (L == R) return val[p];       int mid = (L + R) >> 1;       if (mid >= x)         return val[p] + query(L, mid, p << 1, x);       else         return val[p] + query(mid + 1, R, p << 1 | 1, x);     }   } T1;   struct SEGMENT2 {     int val[M * 4];     void update(int L, int R, int p, int x, int v) {       val[p] += v;       if (L == R) return;       int mid = (L + R) >> 1;       if (mid >= x)         update(L, mid, p << 1, x, v);       else         update(mid + 1, R, p << 1 | 1, x, v);     }     int query(int L, int R, int p, int l, int r) {       if (L == l && R == r) return val[p];       int mid = (L + R) >> 1;       if (mid >= r)         return query(L, mid, p << 1, l, r);       else if (mid < l)         return query(mid + 1, R, p << 1 | 1, l, r);       else         return query(L, mid, p << 1, l, mid) +                query(mid + 1, R, p << 1 | 1, mid + 1, r);     }   } T2;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     scanf( %d , &q);     for (int i = 1, l, r; i <= q; i++)       scanf( %d %d , &l, &r), ps[r].push_back(pair<int, int>(l, i));     for (int i = 1, x, len; i <= n; i++) {       x = a[i];       len = i - las[x];       if (len != pas[x] && pas[x] != las[x]) {         if (mfr[x] < llas[x]) T1.update(1, n, 1, mfr[x] + 1, llas[x], 1);         mfr[x] = llas[x];       }       pas[x] = len;       if (las[x] != 0) T2.update(1, n, 1, las[x], -1);       T2.update(1, n, 1, i, 1);       llas[x] = las[x];       las[x] = i;       for (int j = 0, up = ps[i].size(), c1, c2, l, id; j < up; j++) {         l = ps[i][j].first;         id = ps[i][j].second;         c1 = T2.query(1, n, 1, l, i);         c2 = T1.query(1, n, 1, l);         if (c1 != c2)           ans[id] = c1;         else           ans[id] = c1 + 1;       }     }     for (int i = 1; i <= q; i++) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e4 + 10, K = 256, B = 16;   int a[N], parent[N], depth[N], up[N], ans[N][K];   vector<int> g[N];   bitset<(1 << (B + 1)) + 10> trie;   void make_tries(int i, int par);   void trie_insert(int val);   void trie_clear(int val);   int trie_max(int val);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, q;     cin >> n >> q;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     make_tries(1, 0);     while (q--) {       int u, v;       cin >> u >> v;       int dist = 0, res = 0;       while (depth[v] - depth[u] >= K - 1) {         res = max(res, ans[v][dist]);         v = up[v];         ++dist;       }       dist <<= 8;       while (depth[v] >= depth[u]) {         res = max(res, dist xor a[v]);         v = parent[v];         ++dist;       }       cout << res << endl;     }   }   void make_tries(int i, int par) {     parent[i] = par;     depth[i] = 1 + depth[par];     if (depth[i] >= K) {       int u = i;       int dist = 0;       while (depth[i] - depth[u] <= K - 1) {         trie_insert(dist xor a[u]);         u = parent[u];         ++dist;       }       for (int d = 0; d < K; ++d) {         ans[i][d] = trie_max(d << 8);       }       up[i] = u;       dist = 0;       u = i;       while (depth[i] - depth[u] <= K - 1) {         trie_clear(dist xor a[u]);         u = parent[u];         ++dist;       }     }     for (auto &j : g[i]) {       if (j != par) {         make_tries(j, i);       }     }   }   void trie_insert(int val) {     int pos = 1;     for (int b = B - 1; b >= 0; --b) {       pos = (pos << 1) | ((val & (1 << b)) >> b);       trie[pos] = 1;     }   }   void trie_clear(int val) {     int pos = 1;     for (int b = B - 1; b >= 0; --b) {       pos = (pos << 1) | ((val & (1 << b)) >> b);       trie[pos] = 0;     }   }   int trie_max(int val) {     int pos = 1, res = 0;     for (int b = B - 1; b >= 0; --b) {       pos = (pos << 1) | (((val & (1 << b)) >> b) ^ 1);       if (trie[pos]) {         res |= (1 << b);       } else {         pos ^= 1;       }     }     return res;   }
#include <bits/stdc++.h>   using namespace std;   long long int arr[100001], done[100001], cnt0[100001], cnte[100001],       cnto[100001];   long long int dp[105][105][2];   int main() {     ios::sync_with_stdio(false);     ;     cin.tie(0);     ;     long long int i, j, n, k, l, x, y, evenLeft = 0, oddLeft = 0, z;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> arr[i];       if (arr[i] != 0) done[arr[i]] = 1;     }     oddLeft = 0;     evenLeft = 0;     for (i = 1; i <= n; i++) {       if (done[i]) continue;       if (i & 1)         oddLeft++;       else         evenLeft++;     }     for (i = 1; i <= n; i++) cnt0[i] = cnt0[i - 1] + (arr[i] == 0);     for (i = 1; i <= n; i++) {       cnte[i] = cnte[i - 1];       if (arr[i] != 0 && arr[i] % 2 == 0) cnte[i]++;     }     for (i = 1; i <= n; i++) {       cnto[i] = cnto[i - 1];       if (arr[i] != 0 && arr[i] & 1) cnto[i]++;     }     for (i = 0; i <= n; i++) {       for (j = 0; j <= n; j++) {         for (k = 0; k <= 1; k++) dp[i][j][k] = 1000000000000;       }     }     if (arr[1] != 0) {       if (arr[1] & 1)         dp[1][evenLeft][1] = 0;       else         dp[1][evenLeft][0] = 0;     } else {       if (evenLeft > 0) dp[1][evenLeft - 1][0] = 0;       if (oddLeft > 0) dp[1][evenLeft][1] = 0;     }     for (i = 1; i < n; i++) {       for (j = 0; j <= evenLeft; j++) {         for (k = 0; k <= 1; k++) {           if (dp[i][j][k] == 1000000000000) continue;           x = cnt0[i];           y = evenLeft - j;           z = oddLeft - (x - y);           if (arr[i + 1] != 0) {             if (arr[i + 1] % 2 == k)               dp[i + 1][j][arr[i + 1] % 2] =                   min(dp[i + 1][j][arr[i + 1] % 2], dp[i][j][k]);             else               dp[i + 1][j][arr[i + 1] % 2] =                   min(dp[i + 1][j][arr[i + 1] % 2], dp[i][j][k] + 1);           } else {             if (j > 0) {               if (k == 0)                 dp[i + 1][j - 1][0] = min(dp[i + 1][j - 1][0], dp[i][j][k]);               else                 dp[i + 1][j - 1][0] = min(dp[i + 1][j - 1][0], dp[i][j][k] + 1);             }             if (z > 0) {               if (k == 0)                 dp[i + 1][j][1] = min(dp[i + 1][j][1], dp[i][j][k] + 1);               else                 dp[i + 1][j][1] = min(dp[i + 1][j][1], dp[i][j][k]);             }           }         }       }     }     cout << min(dp[n][0][0], dp[n][0][1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int t, n;     cin >> t;     string s;     for (int k = 0; k < t; k++) {       cin >> n;       cin >> s;       if (s.size() == 2) {         if (s[0] < s[1]) {           cout <<  YES                 <<   n ;           cout << 2 <<   n ;           cout << s[0] <<     << s[1] << endl;         } else           cout <<  NO                 <<   n ;       } else {         cout <<  YES               <<   n ;         cout << 2 <<   n ;         cout << s[0] <<    ;         for (int i = 1; i < s.size(); i++) cout << s[i];         cout << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long int powmod(long long int a, int b, int n) {     long long int rm = 1;     while (b) {       if (b % 2) {         rm = (rm * a) % n;       }       a = (a * a) % n;       b /= 2;     }     return rm;   }   int main() {     int n;     long long int a[110];     cin >> n;     for (int i = (int)1; i <= (int)n; i++) cin >> a[i];     long long int cost = 0;     for (long long int i = 1; i <= n; ++i) {       cost = cost + (a[i] - 1) * i + 1;     }     cout << cost << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s, t;   int arr1[2222], arr2[2222];   char ans[999999];   long long int i, j, lo, hi, mid, cnt, sum, nd;   queue<int> q;   int main() {     cin >> s >> t;     for (i = 0; i < t.size(); i++) {       arr2[(int)(t[i] -  a )]++;     }     cnt = 0;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  ? ) {         cnt++;         q.push(i);       } else         arr1[(int)(s[i] -  a )]++;     }     lo = 0;     hi = 10000000;     while (lo <= hi) {       mid = (lo + hi) / 2;       sum = 0;       for (i = 0; i < 26; i++) {         nd = arr2[i] * mid;         nd -= arr1[i];         if (nd < 0) nd = 0;         sum = sum + nd;       }       if (sum >= cnt)         hi = mid - 1;       else         lo = mid + 1;     }     mid++;     sum = 0;     for (i = 0; i < 26; i++) {       nd = arr2[i] * mid;       nd -= arr1[i];       if (nd < 0) nd = 0;       sum = sum + nd;     }     if (sum > cnt) {       mid--;       sum = 0;       for (i = 0; i < 26; i++) {         nd = arr2[i] * mid;         nd -= arr1[i];         if (nd < 0) nd = 0;         sum = sum + nd;       }       if (sum > cnt) mid--;     }     for (i = 0; i < 26; i++) {       arr2[i] = arr2[i] * mid;       if (arr2[i]) {         while (arr2[i]--) {           if (arr1[i])             arr1[i]--;           else {             int u = q.front();             q.pop();             s[u] = (char)i +  a ;             cnt--;           }         }       }     }     while (cnt--) {       int u = q.front();       q.pop();       s[u] =  z ;     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b);   long long mpower(long long x, long long y, long long c);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     map<long long, long long> M;     vector<long long> aa;     set<long long> st;     set<long long>::iterator itr;     long long n, i, j, k;     cin >> n;     string s;     cin >> s;     long long cnt = 0;     for (i = n - 1; i >= 0; i--) {       long long flag = -1;       if (2 * (i + 1) <= n) {         for (j = i + 1; j < (2 * (i + 1)); j++) {           if (s[j] == s[j - 1 - i]) {             flag = 1;           } else {             flag = -1;             break;           }         }       }       if (flag == 1) {         i = -1;       }       cnt++;     }     cout << cnt;     return 0;   }   long long gcd(long long a, long long b) {     if (b == 0) {       return a;     } else {       return gcd(b, a % b);     }   }   long long mpower(long long x, long long y, long long c) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % c;       y = y >> 1;       x = (x * x) % c;     }     return res;   }
#include <bits/stdc++.h>   using namespace std;   double shortestDisSq(double x1, double y1, double x2, double y2, double x,                        double y) {     double magSq = pow(abs(x2 - x1), 2) + pow(abs(y2 - y1), 2);     double proj = ((x - x1) * (x2 - x1) + (y - y1) * (y2 - y1)) / magSq;     if (proj > 1) proj = 1;     if (proj < 0) proj = 0;     return pow(abs((x1 + proj * (x2 - x1)) - x), 2) +            pow(abs((y1 + proj * (y2 - y1)) - y), 2);   }   int main() {     int n;     double x, y;     cin >> n >> x >> y;     double p, q;     double op, oq, ip, iq;     const double PI = 3.141592653589793238463;     double dis;     double R2 = 0;     double r2 = 100000000000000;     for (int i = 0; i < n; i++) {       cin >> p >> q;       if (i == 0) {         ip = p;         iq = q;       }       if (i > 0) r2 = min(r2, shortestDisSq(p, q, op, oq, x, y));       if (i == n - 1) r2 = min(r2, shortestDisSq(ip, iq, p, q, x, y));       op = p;       oq = q;       dis = pow(abs(x - p), 2) + pow(abs(y - q), 2);       R2 = max(R2, dis);     }     double res = PI * (R2 - r2);     printf( %.8lf n , res);     return 0;   }
#include <bits/stdc++.h>   const int MAXN = 1100000;   char s[MAXN];   int n;   bool check(int o) {     int p = 0;     int mx = 0;     bool uni = true;     for (int i = 0; i < n; i++) {       if (s[i] ==  L )         p--;       else {         if (p < o - 1) p++;       }       if (p < mx) {         mx = p;         uni = true;       } else {         uni = false;       }     }     return uni;   }   int main() {     scanf( %s , s);     n = strlen(s);     if (s[n - 1] ==  R ) {       for (int i = 0; i < n; i++) {         s[i] = (s[i] ==  L ) ?  R  :  L ;       }     }     if (check(n + 1)) {       printf( 1 );       return 0;     }     int a = 1, b = n;     while (a <= b) {       int m = (a + b) / 2;       if (check(m)) {         a = m + 1;       } else {         b = m - 1;       }     }     printf( %d , a - 1);   }
#include <bits/stdc++.h>   using namespace std;   bool primecheck(long long int a) {     bool check = true;     for (long long int i = 2; i <= sqrt(a); i++) {       if (a % i == 0) {         check = false;         break;       }     }     return (check);   }   vector<long long int> printDivisors(long long int n) {     vector<long long int> sol;     for (long long int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i) {           sol.push_back(i);         } else {           sol.push_back(i);           sol.push_back(n / i);         }       }     }     return (sol);   }   long long int digits(long long int a) { return (floor(log10(a)) + 1); }   long long binpow(long long a, long long b, long long m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   int gcd(int a, int b) {     if (a == 0) return b;     if (b == 0) return a;     if (a == b) return a;     if (a > b) return gcd(a - b, b);     return gcd(a, b - a);   }   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   bool check(string a, string b) {     long long int freq1[26] = {0};     long long int i;     for (i = 0; i < a.size(); i++) {       freq1[a[i] -  a ]++;     }     for (i = 0; i < b.size(); i++) {       freq1[b[i] -  a ]--;     }     bool sol = true;     for (i = 0; i < 26; i++)       if (freq1[i] != 0) sol = false;     return (sol);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int a, b, c, i, j, k, l, m, n, t;     cin >> t;     while (t--) {       string num1, num2;       cin >> num1 >> num2;       bool sol;       long long int size1 = num1.size();       long long int size2 = num2.size();       if (size2 < size1) {         cout <<  NO               <<   n ;       } else {         sol = false;         for (i = 0; i <= size2 - size1; i++) {           string fresh = num1;           for (j = 0; j < size1; j++) {             fresh[j] = num2[i + j];           }           if (check(num1, fresh)) {             cout <<  YES                   <<   n ;             sol = true;             break;           }         }         if (!sol)           cout <<  NO                 <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   const int INF = 0x3f3f3f3f;   const double pi = acos(-1.0);   const double eps = 1e-9;   template <class T>   inline void read(T &x) {     int c;     for (c = getchar(); c < 32 && ~c; c = getchar())       ;     for (x = 0; c > 32; x = x * 10 + c -  0 , c = getchar())       ;   }   int n, m;   int chu[maxn];   vector<int> g[maxn];   priority_queue<int> q;   int ind;   int lab[maxn];   int main() {     read(n), read(m);     int u, v;     for (int i = 0; i < m; i++) {       read(v), read(u);       g[u].emplace_back(v);       chu[v]++;     }     ind = n;     for (int i = 1; i <= n; i++) {       if (chu[i] == 0) {         q.emplace(i);       }     }     while (!q.empty()) {       int x = q.top();       q.pop();       lab[x] = ind--;       for (auto &i : g[x]) {         chu[i]--;         if (chu[i] == 0) q.emplace(i);       }     }     for (int i = 1; i <= n; i++) {       cout << lab[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007LL;   long long dp[64];   long long solve(long long k) {     if (dp[k] != -1) return dp[k];     if (k == 0) return 1LL;     return ((16LL * solve(k - 1) % mod) * (solve(k - 1) % mod) % mod + mod) % mod;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long k;     cin >> k;     for (int i = (0); i < (64); i++) dp[i] = -1;     cout << ((6LL * solve(k - 1)) % mod + mod) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, A[100], B[100], t, r, x;   string s =   ;   int main() {     cin >> n;     for (int i = 0; i <= n; i++) {       r = 0;       for (int j = 0; j <= n; j++) {         if ((t + r) == n) {           x = 1;           break;         }         r = r + 7;       }       if (x == 1) break;       t = t + 4;     }     if (x == 1) {       for (int i = 0; i < t / 4; i++) s +=  4 ;       for (int i = 0; i < r / 7; i++) s +=  7 ;     } else {       s =  -1 ;     }     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265;   void fastInOut();   const int N = 5003;   const long long OO = (long long)1e18;   int n, m, k;   long long cum[N], memo[N][N];   long long go(int i, int c) {     if (i == n + 1) return c == k ? 0 : -OO;     long long &ret = memo[i][c];     if (ret != -1) return ret;     ret = go(i + 1, c);     if (i + m <= n + 1)       ret = max(ret, cum[i + m - 1] - cum[i - 1] + go(i + m, c + 1));     return ret;   }   int main() {     fastInOut();     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       cin >> cum[i];       cum[i] += cum[i - 1];     }     memset(memo, -1, sizeof(memo));     cout << go(1, 0);     return 0;   }   void fastInOut() {     ios_base::sync_with_stdio(0);     cin.tie(NULL), cout.tie(NULL);   }
#include <bits/stdc++.h>   using namespace std;   long long int arr[100005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     long long int sum = 0;     for (int i = 0; i < n; ++i) {       cin >> arr[i];       sum = sum + arr[i];     }     if (sum & 1) {       cout <<  NO  << endl;       return 0;     }     sum = sum / 2;     multiset<long long int> m1, m2;     for (int i = 0; i < n; ++i) {       m2.insert(arr[i]);     }     for (int i = 0; i < n; ++i) {       m1.insert(arr[i]);       m2.erase(m2.find(arr[i]));       sum = sum - arr[i];       if (sum == 0 || m1.find(-sum) != m1.end() || m2.find(sum) != m2.end()) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int powmod(int a, int p, int m) {     int64_t ans = 1, cp = a;     for (int i = 0; (1ll << i) <= p; ++i, cp = cp * cp % m)       if ((1ll << i) & p) ans = ans * cp % m;     return ans;   }   int divmod(int64_t a, int b, int m) { return a * powmod(b, m - 2, m) % m; }   const int N = 200000;   int a[N], t[N], b[N], n, m;   unordered_set<int> pres;   vector<int> s;   double et;   pair<int, int> solve() {     {       if (n > 2)         if (rand() & 1)           swap(a[0], a[rand() % (n - 2) + 2]),               swap(a[1], a[rand() % (n - 2) + 2]);         else           swap(a[1], a[rand() % (n - 2) + 2]),               swap(a[0], a[rand() % (n - 2) + 2]);       s.clear();       for (int i = 0; i < n; ++i) s.push_back((a[i] - a[0] + m) % m);       sort(begin(s), end(s));       int dst = 0;       for (int i = 0; i < n; ++i) {         auto t = lower_bound(begin(s), end(s), (a[i] - a[1] + m) % m);         if (t == s.end() || *t != (a[i] - a[1] + m) % m) dst++;       }       int d = divmod((a[1] - a[0] + m) % m, dst, m), heads = 0;       for (int i = 0; i < n; ++i) heads += !pres.count((a[i] + d) % m);       if (!~-heads)         for (int i = 0; i < n; ++i)           if (!pres.count((a[i] + d) % m)) return {a[i], (m - d) % m};     }     return {-1, -1};   }   int main() {     srand(101);     cin.tie(0), ios::sync_with_stdio(0);     int comp = 0;     cin >> m >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     if (n == 1 || n == m) return cout << a[0] <<     << 1, 0;     if (n > m - n) {       sort(a, a + n);       for (int i = 0; i < m; ++i) t[i] = i;       memcpy(a, b, (set_difference(t, t + m, a, a + n, b) - b) * sizeof *b);       comp = 1;       n = m - n;     }     for (int i = 0; i < n; ++i) pres.insert(a[i]);     random_shuffle(a, a + n);     auto ans = solve();     if (!~ans.first)       cout <<  -1 ;     else if (!comp)       cout << ans.first <<     << ans.second <<   n ;     else       cout << (ans.first - ans.second + m) % m <<     << (m - ans.second) % m            <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       vector<int> p(n);       int id = -1;       for (int i = 0; i < n; ++i) {         cin >> p[i];         if (p[i] == 1) id = i;       }       bool f1 = 0, f2 = 0;       int val = 0;       for (int i = id, j = 0; j < n; ++i, ++j) {         ++val;         if (p[i % n] != val) f1 = 1;       }       val = 0;       for (int i = id, j = 0; j < n; --i, ++j) {         ++val;         if (i < 0) i += n;         if (p[i % n] != val) f2 = 1;       }       if (f1 == 0 || f2 == 0)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int f[11][11][4][maxn];   int n;   char s[maxn];   char c[maxn];   int lowbit(int x) { return x & (-x); }   int ch(char s) {     if (s ==  A )       return 1;     else if (s ==  T )       return 2;     else if (s ==  G )       return 3;     else if (s ==  C )       return 4;     return -1;   }   void Add(int *tr, int x, int d) {     for (; x <= n; x += lowbit(x)) {       tr[x] += d;     }   }   int Sum(int *tr, int x) {     if (x == 0) return 0;     int s = 0;     while (x) {       s += tr[x];       x -= lowbit(x);     }     return s;   }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= 10; j++) Add(f[j][i % j][ch(s[i])], i, 1);     int q, x, d, l, r;     scanf( %d , &q);     while (q--) {       scanf( %d , &x);       if (x == 1) {         scanf( %d%s , &d, c);         for (int i = 1; i <= 10; i++) {           Add(f[i][d % i][ch(s[d])], d, -1);         }         s[d] = c[0];         for (int i = 1; i <= 10; i++) Add(f[i][d % i][ch(s[d])], d, 1);       } else {         scanf( %d %d %s , &l, &r, c);         int len = strlen(c);         int ans = 0;         for (int i = 0; i < len; i++) {           ans += Sum(f[len][(l + i) % len][ch(c[i])], r) -                  Sum(f[len][(l + i) % len][ch(c[i])], l - 1);         }         printf( %d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[55][55];   double comb[55];   int a[55];   int main(int argc, char **argv) {     int n, p;     int tot = 0;     double res = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       tot += a[i];     }     cin >> p;     if (tot <= p) {       cout << n << endl;       return 0;     }     comb[0] = 1;     for (int i = 1; i <= n; i++) comb[i] = comb[i - 1] * i;     for (int block = 0; block < n; block++) {       memset(dp, 0, sizeof(dp));       dp[0][0] = 1;       for (int i = 0; i < n; i++) {         if (i == block) continue;         for (int j = p - a[i]; j >= 0; j--) {           for (int k = 0; k < n - 1; k++) {             dp[j + a[i]][k + 1] += dp[j][k];           }         }       }       for (int i = 0; i <= p; i++) {         if (a[block] + i > p) {           for (int j = 1; j <= n - 1; j++) {             res += j * dp[i][j] * comb[j] * comb[n - 1 - j] / comb[n];           }         }       }     }     cout << res << endl;   }