malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while ( 0  <= ch && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x;   }   int t;   int main() {     t = read();     while (t--) {       int n = read(), d = read();       int ans = d;       d--;       int x = sqrt(d);       if (x + d / (x + 1) + 1 < ans) ans = x + d / (x + 1) + 1;       if (x + 1 + d / (x + 2) + 1 < ans) ans = x + 1 + d / (x + 2) + 1;       if (ans <= n)         puts( Yes );       else         puts( No );     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 100;   long long x[maxn];   char type[maxn], t;   vector<long long> B, R, G;   long long szR, szB, n, pos;   void Put(long long st, long long en) {     R.clear();     B.clear();     for (int i = st; i <= en; ++i) {       if (type[i] == 1)         R.push_back(i);       else if (type[i] == 2)         B.push_back(i);     }     szR = R.size();     szB = B.size();   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> pos >> t;       x[i] = pos;       if (t ==  P )         type[i] = 0, G.push_back(i);       else if (t ==  R )         type[i] = 1;       else         type[i] = 2;     }     long long ans = 0;     int sz = G.size();     if (sz == 0) {       Put(1, n);       if (szR > 0) ans += x[R[szR - 1]] - x[R[0]];       if (szB > 0) ans += x[B[szB - 1]] - x[B[0]];     } else {       Put(1, G[0] - 1);       if (szR > 0) ans += x[G[0]] - x[R[0]];       if (szB > 0) ans += x[G[0]] - x[B[0]];       Put(G[sz - 1] + 1, n);       if (szR > 0) ans += x[R[szR - 1]] - x[G[sz - 1]];       if (szB > 0) ans += x[B[szB - 1]] - x[G[sz - 1]];       for (int i = 0; i < sz - 1; ++i) {         long long x1 = G[i], x2 = G[i + 1];         long long tmp1 = 0, tmp2 = 0;         Put(x1 + 1, x2 - 1);         if (szR > 0) {           tmp1 = x[R[0]] - x[x1];           for (int p = 1; p < szR; ++p) tmp1 = max(tmp1, x[R[p]] - x[R[p - 1]]);           tmp1 = max(tmp1, x[x2] - x[R[szR - 1]]);         } else           tmp1 = x[x2] - x[x1];         if (szB > 0) {           tmp2 = x[B[0]] - x[x1];           for (int p = 1; p < szB; ++p) tmp2 = max(tmp2, x[B[p]] - x[B[p - 1]]);           tmp2 = max(tmp2, x[x2] - x[B[szB - 1]]);         } else           tmp2 = x[x2] - x[x1];         ans += min((x[x2] - x[x1]) * 2, (x[x2] - x[x1]) * 3 - tmp1 - tmp2);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n;   vector<int> a;   long long inv[32][2];   void solve(vector<int> &a, int depth) {     if (depth < 0) return;     if (a.size() == 0) return;     vector<int> left, right;     long long cnt0 = 0, cnt1 = 0, sum01 = 0, sum10 = 0;     for (int i = 0; i < a.size(); ++i) {       if (a[i] >> depth & 1) {         cnt1++;         sum01 += cnt0;         right.push_back(a[i]);       } else {         cnt0++;         sum10 += cnt1;         left.push_back(a[i]);       }     }     inv[depth][0] += sum01;     inv[depth][1] += sum10;     solve(left, depth - 1);     solve(right, depth - 1);   }   int main() {     scanf( %d , &n);     a.resize(n);     for (auto &x : a) cin >> x;     solve(a, 31);     long long ans = 0, x = 0;     for (int i = 0; i <= 31; ++i) {       if (inv[i][0] >= inv[i][1])         ans += inv[i][1];       else         ans += inv[i][0], x |= (1 << i);     }     printf( %lld %lld n , ans, x);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = (int)1e9 + 7;   char s[5010], t[5010];   int n, m;   int d[2][5010], ans, cs;   int main() {     int i, j;     gets(s + 1);     n = strlen(s + 1);     gets(t + 1);     m = strlen(t + 1);     d[1][m + 1] = 1;     for (i = n; i >= 1; i--) {       cs = 0;       for (j = m + 1; j >= 1; j--) {         if (s[i] == t[j])           d[0][j] = cs;         else           d[0][j] = 0;         cs += d[1][j];         cs %= mod;       }       for (j = 1; j <= m; j++) {         ans += d[0][j];         ans %= mod;       }       for (j = 1; j <= m; j++) d[1][j] = d[0][j];     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, ans = 0;   const long long maxn = 1e6 + 5;   long long p[maxn];   int main() {     cin >> a >> b >> c >> d;     long long mx = min(b - a, c - b) + 1;     for (long long i = a + b, t = 1; i <= b + c; ++i) {       p[i] = t;       t = min(t + 1, mx);     }     for (long long i = b + c - mx + 1, t = mx; i <= b + c; ++i) {       p[i] = t;       --t;     }     for (long long i = a + b; i <= b + c; ++i) {       p[i] = p[i - 1] + p[i];     }     ans = p[b + c] * (d - c + 1);     for (long long i = c; i <= d; ++i) {       long long ind = min(b + c, i);       ans -= p[ind];     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long int n, k;     cin >> n >> k;     long long int q = 8 * (n + k) + 9;     long long int y = (-3 + sqrt(q)) / 2;     cout << (y * (y + 1)) / 2 - k <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   int a[300005];   bool notprime[8000005];   map<int, int> prims;   vector<int> primes;   void factor(int num) {     for (int i = 0; i < primes.size() && primes[i] * primes[i] <= num; i++) {       if (num % primes[i] == 0) {         prims[primes[i]]++;         while (num % primes[i] == 0) {           num /= primes[i];         }         if (num == 1) {           break;         }       }     }     if (num != 1) prims[num]++;   }   int main() {     std::ios_base::sync_with_stdio(false);     notprime[0] = true;     notprime[1] = true;     int i;     for (i = 2; i * i <= 8000005; i++) {       if (!notprime[i]) {         primes.push_back(i);         for (int j = i * i; j < 8000005; j += i) {           notprime[j] = true;         }       }     }     for (; i < 8000005; i++) {       if (!notprime[i]) primes.push_back(i);     }     int n;     cin >> n;     int commgcd;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (i == 0)         commgcd = a[i];       else         commgcd = gcd(a[i], commgcd);     }     for (int i = 0; i < n; i++) {       factor(a[i] / commgcd);     }     int maxprim = -1;     for (auto par : prims) {       if (par.second > maxprim) {         maxprim = par.second;       }     }     if (maxprim == -1)       cout << -1 << endl;     else       cout << n - maxprim << endl;   }
#include <bits/stdc++.h>   int t1, t2;   inline int get() {     char c[10];     scanf( %s , &c);     if (!strcmp(c,  monday )) return 1;     if (!strcmp(c,  tuesday )) return 2;     if (!strcmp(c,  wednesday )) return 3;     if (!strcmp(c,  thursday )) return 4;     if (!strcmp(c,  friday )) return 5;     if (!strcmp(c,  saturday )) return 6;     if (!strcmp(c,  sunday )) return 0;   }   int main() {     t1 = get(), t2 = get();     if ((t1 == t2) || ((t1 + 2) % 7 == t2) || ((t1 + 3) % 7 == t2))       puts( YES );     else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long i, j, a, n = 0;     string s, str;     cin >> a;     cin >> s >> str;     for (long long i = 0; i < s.size() - 1; i++) {       if (s[i] == str[i]) continue;       if (s[i] != str[i] and s[i + 1] != str[i + 1]) {         swap(s[i], s[i + 1]);         n++;         continue;       }       n++;     }     if (s[a - 1] != str[a - 1]) n++;     cout << n;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b;   char str[100005];   int main() {     scanf( %d %d %d , &n, &a, &b);     scanf( %s , str + 1);     if (str[a] == str[b]) {       puts( 0 );       return 0;     }     puts( 1 );   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     cin >> n >> m;     int bagi = (n / m);     if (bagi * m == n) {       for (int i = 0; i < m; i++) {         printf( %d  , bagi);       }     } else {       int sisa = (n - (m * bagi));       for (int i = 0; i < m; i++) {         int now = 0;         if (sisa > 0) {           now = bagi + 1;           sisa--;         } else {           now = bagi;         }         printf( %d  , now);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       pair<int, int> p[n];       for (int i = 0; i < n; i++) {         cin >> p[i].first >> p[i].second;       }       bool check = true;       for (int i = 0; i < n; i++) {         if (p[i].first < p[i].second) check = false;         if (i > 0) {           if (p[i].first == p[i - 1].first) {             if (p[i].second != p[i - 1].second) check = false;           } else if (p[i].first > p[i - 1].first) {             if (p[i].second < p[i - 1].second) check = false;           } else             check = false;           if (p[i].first - p[i - 1].first < p[i].second - p[i - 1].second)             check = false;         }       }       if (check)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mxn = 100003;   long long f[20 * mxn + 10], rs[2 * mxn], ar[mxn + 10];   long long sum = 0;   int n, m, k;   struct data {     int l, r, id;   } query[mxn];   int bs = sqrt(mxn * 14);   bool operator<(data a, data b) {     return a.l / bs == b.l / bs ? a.r < b.r : a.l < b.l;   }   void add(int pos) {     sum += f[ar[pos] ^ k];     f[ar[pos]]++;   }   void rmv(int pos) {     f[ar[pos]]--;     sum -= f[ar[pos] ^ k];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) cin >> ar[i];     for (int i = 1; i <= n; i++) {       ar[i] = ar[i - 1] ^ ar[i];     }     for (int i = 0; i < m; i++) {       cin >> query[i].l >> query[i].r;       query[i].l--;       query[i].id = i;     }     sort(query, query + m);     int left = 1, right = 1;     add(1);     for (int i = 0; i < m; i++) {       while (left < query[i].l) {         rmv(left);         left++;       }       while (left > query[i].l) {         left--;         add(left);       }       while (right < query[i].r) {         right++;         add(right);       }       while (right > query[i].r) {         rmv(right);         right--;       }       rs[query[i].id] = sum;     }     for (int i = 0; i < m; i++) {       cout << rs[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a[3];       for (int i = 0; i < 3; i++) {         a[i].assign(n, 0);         for (auto &x : a[i]) cin >> x;       }       vector<int> res;       for (int i = 0; i < n; i++) {         for (int j = 0; j < 3; j++) {           if (!res.empty() && res.back() == a[j][i]) continue;           if (i == n - 1 && !res.empty() && res[0] == a[j][i]) continue;           res.push_back(a[j][i]);           break;         }       }       for (auto &x : res) cout << x <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int N = 2e5 + 5;   const int SZ = 1e6 + 5;   const long long INF = 2e9 + 5;   int n, m, p;   pair<int, long long> a[N], b[N];   pair<int, pair<int, long long> > mon[N];   long long tree[4 * SZ], lazy[4 * SZ], cost[SZ];   void Build(int c, int ss, int se) {     if (ss == se) {       tree[c] = cost[ss];       return;     }     int mid = (ss + se) >> 1;     Build(c << 1, ss, mid);     Build(c << 1 | 1, mid + 1, se);     tree[c] = max(tree[c << 1], tree[c << 1 | 1]);   }   void Push(int c, int ss, int se) {     if (lazy[c]) {       tree[c] += lazy[c];       if (ss != se) {         lazy[c << 1] += lazy[c];         lazy[c << 1 | 1] += lazy[c];       }       lazy[c] = 0;     }   }   void Set(int c, int ss, int se, int qs, int qe, long long val) {     Push(c, ss, se);     if (ss > se || qs > se || qe < ss) return;     if (qs <= ss && se <= qe) {       lazy[c] += val;       Push(c, ss, se);       return;     }     int mid = (ss + se) >> 1;     Set(c << 1, ss, mid, qs, qe, val);     Set(c << 1 | 1, mid + 1, se, qs, qe, val);     tree[c] = max(tree[c << 1], tree[c << 1 | 1]);   }   long long Get(int c, int ss, int se, int qs, int qe) {     Push(c, ss, se);     if (ss > se || qs > se || qe < ss) return -INF;     if (qs <= ss && se <= qe) return tree[c];     int mid = (ss + se) >> 1;     return max(Get(c << 1, ss, mid, qs, qe),                Get(c << 1 | 1, mid + 1, se, qs, qe));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> p;     for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;     for (int i = 1; i <= m; i++) cin >> b[i].first >> b[i].second;     for (int i = 1; i <= p; i++)       cin >> mon[i].first >> mon[i].second.first >> mon[i].second.second;     for (int i = 1; i < SZ; i++) cost[i] = -INF;     for (int i = 1; i <= m; i++) {       cost[b[i].first] = max(cost[b[i].first], -b[i].second);     }     sort(a + 1, a + 1 + n);     sort(mon + 1, mon + 1 + p);     Build(1, 1, SZ - 1);     int j = 0;     long long ans = -2 * INF;     for (int i = 1; i <= n; i++) {       while (j + 1 <= p && a[i].first > mon[j + 1].first) {         j++;         Set(1, 1, SZ - 1, mon[j].second.first + 1, SZ, mon[j].second.second);       }       ans = max(ans, -a[i].second + Get(1, 1, SZ - 1, 1, SZ - 1));     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10, mod = 1e9 + 7;   int a[N];   int qmi(int a, int b) {     int res = 1;     while (b) {       if (b & 1) res = (long long)res * a % mod;       b >>= 1;       a = (long long)a * a % mod;     }     return res;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, k;       scanf( %d%d , &n, &k);       for (int i = 1; i <= n; i++) scanf( %d , a + i);       if (k == 1) {         printf(n & 1 ?  1  :  0 );         puts(  );         continue;       }       sort(a + 1, a + 1 + n);       int sum = 1, ans = 0, t = 1;       bool flag = true;       for (int i = n - 1; i >= 1; i--) {         int d = a[i + 1] - a[i];         if (sum > 0) {           while (sum < N && d) {             if ((long long)sum * k > N)               sum = N * 2;             else               sum = sum * k;             d--;             t = (long long)t * k % mod;           }         }         t = (long long)t * qmi(k, d) % mod;         if (sum)           sum--, t = ((long long)t + mod - 1) % mod;         else           sum = 1, t = 1;       }       printf( %lld n , (long long)qmi(k, a[1]) * t % mod);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 1000;   char s1[maxn];   char s2[maxn];   int judge(int st1, int en1, int st2, int en2) {     int sign = 0;     for (int i = st1, j = st2; i <= en1; i++, j++) {       if (s1[i] != s2[j]) {         sign = 1;         break;       }     }     if (sign == 0)       return 1;     else {       if ((en1 - st1 + 1) % 2 == 0) {         int mid1 = st1 + (en1 - st1 + 1) / 2 - 1;         int mid2 = st2 + (en2 - st2 + 1) / 2 - 1;         if (judge(st1, mid1, st2, mid2) && judge(mid1 + 1, en1, mid2 + 1, en2))           return 1;         if (judge(st1, mid1, mid2 + 1, en2) && judge(mid1 + 1, en1, st2, mid2))           return 1;       }     }     return 0;   }   int main() {     int len1, len2;     scanf( %s%s , s1, s2);     len1 = strlen(s1);     len2 = strlen(s2);     if (len1 != len2)       cout <<  NO n  << endl;     else {       int sign;       sign = judge(0, len1 - 1, 0, len1 - 1);       if (sign)         printf( YES n );       else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string st;   set<string> S;   map<string, int> mp;   map<string, string> mp2;   int n, q;   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       S.clear();       cin >> st;       int len = st.length();       for (int fr = 0; fr < len; fr++)         for (int ed = fr; ed < len; ed++) {           string sb = st.substr(fr, ed - fr + 1);           if (S.count(sb)) {           } else {             S.insert(sb);             mp[sb]++;             mp2[sb] = st;           }         }     }     cin >> q;     while (q--) {       cin >> st;       string attr2 =  - ;       if (mp2.count(st)) attr2 = mp2[st];       int attr1 = 0;       if (mp.count(st)) attr1 = mp[st];       cout << attr1 <<     << attr2 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int tot;   int num[1008];   int is[1005];   int n, pos[1005][5];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < 5; j++) {         scanf( %d , pos[i] + j);       }     }     int flag = 0;     int yes = 0;     if (n < 3) {       if (n == 1) {         printf( 1 n1 n );       } else {         printf( 2 n1 2 n );       }       return 0;     }     for (int i = 0; i < n; i++) {       flag = 1;       if (is[i]) continue;       is[i] = 1;       for (int j = 0; j < n && flag; j++) {         for (int k = 0; k < n && flag; k++) {           if (i == j || i == k || k == j) {             continue;           }           int x[5] = {0}, y[5] = {0};           for (int m = 0; m < 5; m++) {             x[m] = pos[j][m] - pos[i][m];           }           for (int m = 0; m < 5; m++) {             y[m] = pos[k][m] - pos[i][m];           }           int temp = 0;           for (int m = 0; m < 5; m++) {             temp += x[m] * y[m];           }           if (temp <= 0) {             is[j] = 1;             is[k] = 1;           } else {             is[i] = 1;             flag = 0;           }         }       }       if (flag == 1) {         printf( 1 n%d , i + 1);         yes = 1;         break;       }     }     if (yes == 0) {       printf( 0 n );     }     return 0;   }
#include <bits/stdc++.h>   int x[200010], check[200010];   long long int ans[200010];   long long int size[200010];   int next[200010];   int find(int k) {     if (next[k] == k)       return k;     else       return next[k] = find(next[k]);   }   std::vector<int> V[200010];   int height[200010];   long long int func(int k, int prev, int h) {     height[k] = h;     long long int ans = x[k];     for (int i = 0; i < V[k].size(); i++) {       if (V[k][i] == prev) continue;       ans += func(V[k][i], k, h + 1);     }     return size[k] = ans;   }   std::pair<int, int> edge[200010];   int main() {     int a;     scanf( %d , &a);     for (int i = 1; i <= a; i++) scanf( %d , &x[i]);     for (int i = 1; i <= a; i++) next[i] = i;     int b;     scanf( %d , &b);     for (int i = 1; i <= b; i++) {       int c, d;       scanf( %d%d , &c, &d);       edge[i] = std::make_pair(c, d);       if (find(c) == find(d))         check[i] = 1, ans[i] = 0;       else {         V[c].push_back(d);         V[d].push_back(c);         next[find(c)] = find(d);       }     }     func(1, 0, 1);     long long int sum = 0;     for (int i = 1; i <= a; i++) sum += x[i];     if (sum != 0) {       printf( Impossible );       return 0;     }     for (int i = 1; i <= b; i++) {       if (check[i] == 0) {         long long int s, t;         int c = edge[i].first;         int d = edge[i].second;         if (height[d] < height[c])           ans[i] = size[c];         else           ans[i] = -size[d];       }     }     printf( Possible n );     for (int i = 1; i <= b; i++) printf( %lld n , -ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, *a, q, sum = 0;     cin >> n;     a = new long long int[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     sort(a, a + n);     cin >> m;     for (int i = 0; i < m; i++) {       cin >> q;       cout << sum - a[n - q] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   multiset<pair<int, int> > st;   int main() {     int n, k;     cin >> n >> k;     int cnt = 0;     for (int i = 0; i < n; i++) {       int num;       cin >> num;       cnt += num / 10;       if (num < 100) st.insert(make_pair(num % 10, num));     }     while (st.size() > 0 && (*st.rbegin()).first != 0 && k > 0) {       pair<int, int> num = *st.rbegin();       st.erase(st.find(num));       num.first++;       num.second++;       if (num.first == 10) cnt++;       num.first %= 10;       if (num.second < 100) st.insert(num);       k--;     }     while (st.size() > 0) {       pair<int, int> num = *st.begin();       st.erase(st.find(num));       while (num.second < 100 && k > 0) {         k--;         num.second++;         num.first = (num.first + 1) % 10;         if (num.first == 0) cnt++;       }     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   long long n, t[N], m, res, ans[N];   int dd[N];   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> t[i];     sort(t + 1, t + n + 1);     long long sum = 0;     int j = 1;     for (int i = 1; i <= 200000; i++) {       if (sum + i > m) {         res = i - 1;         break;       }       if (j <= n && t[j] == i)         j++;       else         sum += i;     }     int dem = 0;     j = 1;     for (int i = 1; i <= res; i++) {       if (j > n || i != t[j]) {         dem++;         ans[dem] = i;       } else         j++;     }     cout << dem << endl;     for (int i = 1; i <= dem; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long poww(long long x, long long y) {     if (x == 0) return 0;     if (x == 1) return 1;     if (y == 0) return 1;     if (y == 1) return x;     long long d = poww(x, y / 2);     if (y % 2) return x * d * d;     return d * d;   }   int main() {     long long n, m;     cin >> n >> m;     for (int i = 0; i < (n + m) * 2; i++) {       long long aa;       cin >> aa;     }     if (n == m) {       cout <<  Yes  << endl;     } else {       cout <<  No  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int one[100007], zero[100007];   const int mod = 1e9 + 7;   long long FastPow(long long x, long long n, long long mod) {     long long s = 1;     while (n) {       if (n & 1) s = s * x % mod;       x = x * x % mod;       n >>= 1;     }     return s % mod;   }   int main() {     int n, q;     cin >> n >> q;     string s;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (i > 0) {         zero[i + 1] = zero[i];         one[i + 1] = one[i];       }       if (s[i] ==  0 ) {         zero[i + 1]++;       } else {         one[i + 1]++;       }     }     while (q--) {       int l, r;       cin >> l >> r;       long long ans = (FastPow(2, one[r] - one[l - 1], mod) - 1 + mod) % mod *                       FastPow(2, zero[r] - zero[l - 1], mod) % mod;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long int power(unsigned long long int n,                                unsigned long long int p) {     unsigned long long int m = 1;     while (p > 0) {       m *= n;       p--;     }     return m;   }   void sieveOfEratosthenes(int n, bool prime[]) {     int i, p;     for (i = 2; i * i <= n; i++) {       if (prime[i]) {         for (p = i * i; p <= n; p += i) prime[p] = false;       }     }   }   long long int coins(int n, int a[]) {     int res, mn = INT_MAX;     res = mn = -a[0];     for (int i = 0; i < n - 1; ++i) {       mn = min(mn, res);       res += a[i] - a[i + 1];     }     return max(abs(res), abs(mn));   }   int main() {     int t, i, n, m, d, k, p;     long long int l, r, ret;     cin >> n;     int arr[n];     for (i = 0; i < n; i++) cin >> arr[i];     cout << coins(n, arr);     return 0;   }