malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   char s[1010000];   int main() {     int i, j, k, m, n;     scanf( %s , s);     n = strlen(s);     if (n % 2 == 1) {       n = (n + 1) / 2;       for (i = 1; i <= n; i++) putchar( 4 );       for (i = 1; i <= n; i++) putchar( 7 );       puts(  );     } else {       char u =  7 ;       int flag = 0;       for (i = 0; i < n; i++) {         if (i + i == n) u =  4 ;         if (s[i] > u) {           flag = -1;           break;         } else if (s[i] < u) {           flag = 1;           break;         }       }       if (flag == -1) {         n = (n + 2) / 2;         for (i = 1; i <= n; i++) putchar( 4 );         for (i = 1; i <= n; i++) putchar( 7 );         puts(  );       } else {         int pos = -1;         int c4 = 0, c7 = 0;         int f = 0;         for (i = 0; i < n; i++) {           if (f || s[i] <=  4 ) {             if (s[i] <  4 ) f = 1;             s[i] =  4 ;             pos = i;             c4++;           } else if (s[i] <=  7 ) {             if (s[i] <  7 ) f = 1;             s[i] =  7 ;             c7++;           } else {             s[i] =  4 ;             s[pos] =  7 ;             pos = i;             c7++;             f = 1;           }         }         if (c7 > c4) {           int cnt = 0;           for (i = n - 1; i >= 0; i--) {             if (s[i] ==  7 ) cnt++;             if (cnt >= (c7 - c4) / 2 + 1) break;           }           for (; i >= 0; i--)             if (s[i] ==  4 ) {               c7++;               c4--;               s[i] =  7 ;               break;             }           for (i = i + 1; i < n; i++)             if (s[i] ==  7 ) {               s[i] =  4 ;               c7--;               c4++;             }         }         if (c7 < c4) {           for (i = n - 1; i >= 0; i--) {             if (c4 > c7 && s[i] ==  4 ) {               s[i] =  7 ;               c4--;               c7++;             }           }         }         puts(s);       }     }     scanf( %*d );   }
#include <bits/stdc++.h>   using namespace std;   inline void solve() {     int d, m;     scanf( %d%d , &d, &m);     int ans = 1;     for (int i = 0; (1 << i) <= d; ++i) {       ans = 1ll * ans * ((1 << i) + 1) % m;       d -= (1 << i);     }     if (d) ans = 1ll * ans * (d + 1) % m;     printf( %d n , (ans - 1 + m) % m);   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200100;   const int mod = 1e9 + 7;   int add(int a, int b) {     a += b;     if (a >= mod) a -= mod;     if (a < 0) a += mod;     return a;   }   int mul(int a, int b) { return 1ll * a * b % mod; }   int N;   int F[maxn];   int Ans[maxn];   vector<int> pre[maxn];   vector<int> suf[maxn];   vector<int> G[maxn];   void DFS(int u, int p = 0) {     F[u] = 1;     vector<int> ch;     for (int v : G[u])       if (v != p) {         DFS(v, u);         F[u] = mul(F[u], add(F[v], 1));         ch.push_back(v);       }     pre[u].resize((int)ch.size());     suf[u].resize((int)ch.size());     for (int i = 0; i < (int)ch.size(); ++i) {       int v = ch[i];       if (i)         pre[u][i] = pre[u][i - 1];       else         pre[u][i] = 1;       pre[u][i] = mul(pre[u][i], add(F[v], 1));     }     for (int i = (int)ch.size() - 1; i >= 0; --i) {       int v = ch[i];       if (i < (int)ch.size() - 1)         suf[u][i] = suf[u][i + 1];       else         suf[u][i] = 1;       suf[u][i] = mul(suf[u][i], add(F[v], 1));     }   }   void dfs(int u, int p = 0, int buf = 1) {     Ans[u] = F[u];     vector<int> ch;     for (int v : G[u])       if (v != p) {         ch.push_back(v);       }     for (int i = 0; i < (int)ch.size(); ++i) {       int v = ch[i];       int nFu = buf;       if (i) nFu = mul(nFu, pre[u][i - 1]);       if (i < (int)ch.size() - 1) nFu = mul(nFu, suf[u][i + 1]);       int tm = F[v];       F[v] = mul(F[v], add(nFu, 1));       dfs(v, u, add(nFu, 1));       F[v] = tm;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> N;     for (int p, i = 2; i <= N; ++i) {       cin >> p;       G[p].push_back(i);       G[i].push_back(p);     }     F[1] = 1;     DFS(1);     dfs(1);     for (int i = 1; i <= N; ++i) cout << Ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300000 + 9;   const int Mod = 1000000007;   int A[N], n, B[N];   multiset<int> S;   bool ok(int l, int r) {     if (l == r) {       auto it = S.find(l);       return it != S.end();     }     auto it = S.lower_bound(l);     auto it2 = S.lower_bound(r);     if (it == it2) {       if (it2 != S.end() && (*it2) == r) return true;       return false;     } else {       return true;     }   }   const int Maxint = 29;   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , A + i);     for (int i = 0; i < n; i++) {       int t;       scanf( %d , &t);       S.insert(t);     }     for (int i = 0; i < n; i++) {       int tmp = 0;       for (int j = Maxint; j >= 0; j--) {         if (A[i] & (1 << j)) {           int Tp = tmp | 1 << j;           if (ok(Tp, Tp + (1 << j) - 1)) {             tmp = Tp;           } else {             ;           }         } else {           if (ok(tmp, tmp + (1 << j) - 1)) {             ;           } else {             tmp |= 1 << j;           }         }       }       B[i] = tmp;       S.erase(S.lower_bound(tmp));     }     for (int i = 0; i < n; i++) printf( %d  , B[i] ^ A[i]);   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, ans;   void gcd(long long a, long long b) {     if (a == 0 || b == 0) return;     if (a > b) swap(a, b);     ans += (b / a);     gcd(b % a, a);   }   int main() {     cin >> a >> b;     gcd(a, b);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9;   const long long mod = 1e9 + 7;   const long long N = 1e5 + 5;   const long long Sz = 1e6 + 5;   string to_string(const string& s) { return     + s +    ; }   void DBG() { cerr <<  ]  << endl; }   template <class H, class... T>   void DBG(H h, T... t) {     cerr << to_string(h);     if (sizeof...(t)) cerr <<  ,  ;     DBG(t...);   }   void setIO() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (fopen(                  .inp ,                r )) {       freopen(                         .inp ,            r , stdin);       freopen(                         .out ,            w , stdout);     }   }   long long n, a[200];   void test_case() {     cin >> n;     long long result = 0, pre = 0;     for (long long i = (1); i <= (n); ++i) {       cin >> a[i];       if (a[i] <= i + result) {         ++pre;         continue;       }       result += a[i] - pre - 1;       pre = a[i];     }     cout << result <<   n ;   }   signed main() {     setIO();     long long TC = 1;     cin >> TC;     while (TC--) {       test_case();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxx = 5e5 + 7;   long long a[maxx], prime[maxx], cnt[maxx], sum, tedad;   bool mark[maxx];   int main() {     int n, q;     cin >> n >> q;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 2; i < maxx; i++) {       if (prime[i] == 0)         for (int j = i; j < maxx; j += i) prime[j] = i;     }     while (q--) {       int ind, adad, ans = 0;       cin >> ind;       ind--;       adad = a[ind];       vector<int> v;       while (adad > 1) {         int p = prime[adad];         v.push_back(p);         while (adad % p == 0) adad /= p;       }       int sz = (int)v.size();       for (int mask = 0; mask < (1 << sz); mask++) {         if (!mark[ind]) {           int t = 1;           for (int i = 0; i < sz; i++)             if ((mask >> i) & 1) t *= v[i];           if (__builtin_popcount(mask) % 2 == 0)             ans += cnt[t];           else             ans -= cnt[t];           cnt[t]++;         } else {           int t = 1;           for (int i = 0; i < sz; i++)             if ((mask >> i) & 1) t *= v[i];           cnt[t]--;           if (__builtin_popcount(mask) % 2 == 0)             ans += cnt[t];           else             ans -= cnt[t];         }       }       if (!mark[ind]) {         mark[ind] = true;         sum += ans;         tedad++;       } else {         mark[ind] = false;         sum -= ans;         tedad--;       }       cout << sum <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, n, x = (int)(1e7 + 1);     cin >> n;     vector<bool> p(x, true);     p[0] = p[1] = false;     int c = 0;     for (i = 2; i <= x; i++) {       if (p[i]) {         c++;         cout << i <<    ;         if (c == n) break;         for (j = i; (long long)i * j <= x; j++) {           p[i * j] = false;         }       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<bool> isthere(2000010, false);   vector<int> nextmax(2000010);   int main() {     ios::sync_with_stdio(false);     int n, i;     cin >> n;     vector<int> a(n);     for (i = 0; i < n; i++) {       cin >> a[i];       isthere[a[i]] = true;     }     sort(a.begin(), a.end());     for (i = 1; i < 2000005; i++) {       if (isthere[i - 1])         nextmax[i] = i - 1;       else         nextmax[i] = nextmax[i - 1];     }     int ans = 0, range;     for (i = 0; i < a.size(); i++) {       if (i && a[i] == a[i - 1]) continue;       range = (a[a.size() - 1] / a[i]) + 1;       for (int j = 2; j <= range; j++) {         int temp = a[i] * j;         ans = max(ans, nextmax[temp] % a[i]);       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x0, y0, x1, y1;     cin >> x0 >> y0 >> x1 >> y1;     int n;     cin >> n;     multimap<int, pair<long long int, long long int> > sections;     for (long long int i = 0; i < n; i++) {       int r, a, b;       cin >> r >> a >> b;       sections.insert(make_pair(r, make_pair(a, b)));     }     map<pair<long long int, long long int>, bool> visited;     map<pair<long long int, long long int>, int> dist;     pair<long long int, long long int> start = make_pair(x0, y0);     pair<long long int, long long int> target = make_pair(x1, y1);     queue<pair<long long int, long long int> > que;     que.push(start);     visited[start] = true;     dist[start] = 0;     int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};     int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};     while (que.size()) {       pair<long long int, long long int> cur = que.front();       que.pop();       if (cur == target) {         break;       };       for (long long int i = 0; i < 8; i++) {         long long int nr = cur.first + dy[i];         long long int nc = cur.second + dx[i];         bool ok = false;         if (visited[make_pair(nr, nc)]) continue;         auto range = sections.equal_range(nr);         for (auto it = range.first; it != range.second; it++) {           pair<long long int, long long int> sec = it->second;           if (nc <= sec.second && nc >= sec.first) {             ok = true;             break;           }         }         if (ok) {           visited[make_pair(nr, nc)] = true;           dist[make_pair(nr, nc)] = dist[cur] + 1;           que.push(make_pair(nr, nc));         }       }     }     if (dist.find(target) == dist.end()) {       cout << -1 << endl;     } else {       cout << dist[target] << endl;     }   }
#include <bits/stdc++.h>   const int maxn = 2222;   using namespace std;   char s1[maxn], s2[maxn];   int dp[maxn][maxn];   int n, m;   int solve(int i) {     int top = m;     int rq = 0;     if (i < m) return maxn;     while (top && i) {       if (s1[i] == s2[top])         top--;       else         rq++;       i--;     }     if (top)       return maxn;     else       return rq;   }   int main() {     scanf( %s%s , s1 + 1, s2 + 1);     n = strlen(s1 + 1);     m = strlen(s2 + 1);     for (int i = 0; i <= n; i++)       for (int j = i + 1; j <= n; j++) dp[i][j] = -maxn;     for (int i = 1; i <= n; i++) {       int k = solve(i);       for (int j = 0; j <= i; j++) {         dp[i][j] = max(dp[i - 1][j], dp[i][j]);         if (j >= k) {           dp[i][j] = max(dp[i][j], dp[i - m - k][j - k] + 1);         }       }     }     for (int i = 0; i <= n; i++) {       printf( %d  , dp[n][i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<long double, long double> A[200666];   int st[200666], ind[200666];   long double val[200666];   bool comp(int i1, int i2) { return A[i1] < A[i2]; }   bool eql(long double v1, long double v2) {     return (v1 - v2 > -((long double)0.00000000000001) &&             v1 - v2 < ((long double)0.00000000000001));   }   long double bs(long double vmax, pair<long double, long double> v1,                  pair<long double, long double> v2) {     long double pos, step;     for (step = 1; step <= vmax; step *= (long double)2.0)       ;     for (pos = 0; step > ((long double)0.0000000000000000001);          step /= (long double)2.0)       if (pos + step <= vmax) {         long double val_1 = 1.0 / v1.first + (pos + step) / (v1.second);         long double val_2 = 1.0 / v2.first + (pos + step) / (v2.second);         if (val_2 < val_1 || eql(val_2, val_1)) pos += step;       }     return pos;   }   int main() {     int n, i;     scanf( %d , &n);     for (i = 1; i <= n; ++i) {       int v1, v2;       scanf( %d%d , &v1, &v2);       A[i].first = v1;       A[i].second = v2;       ind[i] = i;     }     sort(ind + 1, ind + n + 1, comp);     int k = 1;     st[1] = ind[1];     val[1] = ((long double)1000000000000000);     for (i = 2; i <= n; ++i) {       int l = ind[i];       while (true && k > 0) {         long double v1 = 1.0 / A[st[k]].first + val[k] / (A[st[k]].second);         long double v2 = 1.0 / A[l].first + val[k] / (A[l].second);         if (eql(v1, v2)) break;         if (v2 < v1) {           --k;           continue;         }         break;       }       if (k == 0) {         st[++k] = l;         continue;       }       st[++k] = l;       val[k] = bs(val[k - 1], A[st[k - 1]], A[l]);     }     sort(st + 1, st + k + 1);     for (i = 1; i <= k; ++i) cout << st[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <typename T>   ostream &operator<<(ostream &o, const vector<T> &v) {     for (size_t i = 0; i < v.size(); i++)       o << v[i] << (i + 1 != v.size() ?     :   );     return o;   }   template <int n, class... T>   typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &,                                                     tuple<T...> const &) {}   template <int n, class... T>   typename enable_if<(n < sizeof...(T))>::type _ot(ostream &os,                                                    tuple<T...> const &t) {     os << (n == 0 ?    :  ,  ) << get<n>(t);     _ot<n + 1>(os, t);   }   template <class... T>   ostream &operator<<(ostream &o, tuple<T...> const &t) {     o <<  ( ;     _ot<0>(o, t);     o <<  ) ;     return o;   }   template <class T, class U>   ostream &operator<<(ostream &o, pair<T, U> const &p) {     o <<  (  << p.first <<  ,   << p.second <<  ) ;     return o;   }   int n;   int cnt = 0;   int ask(int y1, int x1, int y2, int x2) {     cnt++;     assert(cnt <= 4 * n);     assert(abs(y2 - y1) + abs(x2 - x1) >= n - 1);     if (y1 > y2) swap(y1, y2);     if (x1 > x2) swap(x1, x2);     cout <<  ?   << y1 + 1 <<     << x1 + 1 <<     << y2 + 1 <<     << x2 + 1          << endl;     string s;     cin >> s;     assert(s !=  BAD );     return s[0] ==  Y ;   }   string ans;   int yy, xx;   int dfs(int y1, int x1, int y2, int x2, int i, int ok, int rev) {     if (!ok && !ask(y1, x1, y2, x2)) return 0;     if (abs(y2 - y1) + abs(x2 - x1) == n - 1) return 1;     int sg = y2 - y1 < 0 ? -1 : 1;     if (rev) {       if (dfs(y1, x1, y2 - sg, x2, i - sg, 0, rev)) {         ans[i] =  D ;       } else if (dfs(y1, x1, y2, x2 - sg, i - sg, 1, rev)) {         ans[i] =  R ;       }     } else {       if (dfs(y1, x1, y2, x2 - sg, i - sg, 0, rev)) {         ans[i] =  R ;       } else if (dfs(y1, x1, y2 - sg, x2, i - sg, 1, rev)) {         ans[i] =  D ;       }     }     return 1;   }   int main() {     std::ios::sync_with_stdio(false), std::cin.tie(0);     cin >> n;     ans = string(2 * n - 2,  - );     dfs(0, 0, n - 1, n - 1, 2 * n - 3, 1, 0);     dfs(n - 1, n - 1, 0, 0, 0, 1, 1);     assert((int)ans.find( - ) == -1);     cout <<  !   << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[1024], n, m, c1, c2, c3, c4, an[1024], am[1024];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> c1 >> c2 >> c3 >> c4;     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> an[i];     for (int i = 0; i < m; ++i) cin >> am[i];     int mini = INT_MAX;     mini = min(mini, c4);     mini = min(mini, 2 * c3);     int s1 = 0;     for (int i = 0; i < n; ++i) {       s1 += min(c1 * an[i], c2);     }     mini = min(mini, c3 + s1);     int s2 = 0;     for (int i = 0; i < m; ++i) {       s2 += min(c1 * am[i], c2);     }     mini = min(mini, c3 + s2);     mini = min(mini, s1 + s2);     cout << mini << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<pair<long long, long long>, bool> blocked;   vector<vector<pair<long long, long long> > > graph;   vector<bool> used;   int part(int v) {     vector<long long> adj;     for (int i = 0; i < graph[v].size(); i++) {       long long w = graph[v][i].first;       long long ui = graph[v][i].second;       if (!used[ui]) {         adj.push_back(w);         used[ui] = true;       }     }     long long lst = 0;     for (int i = 0; i < adj.size(); i++) {       long long w = part(adj[i]);       if (w == 0) {         if (lst == 0) {           lst = adj[i];         } else {           cout << lst <<     << v <<     << adj[i] <<   n ;           lst = 0;         }       } else {         cout << v <<     << adj[i] <<     << w <<   n ;       }     }     return lst;   }   int main() {     int n, m;     cin >> n >> m;     graph.resize(n + 1);     used.resize(m);     for (int i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       graph[a].push_back(make_pair(b, i));       graph[b].push_back(make_pair(a, i));     }     if (m % 2 == 1) {       cout <<  No solution             <<   n ;     } else {       part(1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool acompare(int lhs, int rhs) { return lhs > rhs; }   struct t {     int a, pos;   };   int b[1000];   struct t aa[1000];   int main() {     int i, j, k, l, m, n;     vector<int> a;     string s, s1, s2, s3, s4;     cin >> n;     cin >> k;     for (i = 0; i < n; i++) cin >> m, a.push_back(m);     for (i = 0; i < k; i++) cin >> b[i];     sort(b, b + 1000, acompare);     j = 0;     for (i = 0; i < n; i++) {       if (a[i] == 0) a[i] = b[j++];     }     for (i = 0; i < n - 1; i++)       if (a[i] > a[i + 1]) {         cout <<  Yes ;         return 0;       }     cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200100;   vector<pair<int, int> > d[2];   vector<int> S[2];   int n, v;   int main() {     cin >> n >> v;     int sum = 0;     for (int i = 0; i < n; i++) {       int t, s;       cin >> t >> s;       sum += s;       d[t - 1].push_back(make_pair(s, i + 1));     }     for (int i = 0; i < 2; i++) {       sort(d[i].begin(), d[i].end());       reverse(d[i].begin(), d[i].end());       S[i].push_back(0);       for (auto x : d[i]) {         S[i].push_back(S[i].back() + x.first);       }     }     int ans = 0;     int I = 0;     for (int i = 0; i * 2 <= v && i <= d[1].size(); i++) {       int cur = S[1][i];       if (v - 2 * i >= d[0].size()) {         cur += S[0].back();       } else {         cur += S[0][v - 2 * i];       }       if (cur > ans) {         ans = cur;         I = i;       }     }     cout << ans <<   n ;     for (int i = 0; i < I; i++) {       cout << d[1][i].second <<    ;     }     for (int i = 0; i < v - 2 * I && i < d[0].size(); i++) {       cout << d[0][i].second <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, n, m, d, f, x, d1, ans = 1e9;     cin >> n >> m;     long long a[n], b[n];     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) cin >> b[i];     sort(a, a + n);     sort(b, b + n);     for (i = 0; i < n; i++) {       x = i;       d = (b[0] - a[i % n] + m) % m;       f = 1;       for (j = 1; j < n; j++) {         x++;         d1 = (b[j] - a[x % n] + m) % m;         if (d1 != d) {           f = 0;           break;         }       }       if (f) ans = min(ans, d);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e6 + 1;   const int INF = (int)1e9;   const int logN = 20;   int n, k, a[N], Log2[N];   int maxValue[N][21];   int getMax(int l, int r) {     int k = Log2[r - l + 1];     return max(maxValue[l][k], maxValue[r - (1 << k) + 1][k]);   }   void solve() {     cin >> n >> k;     int minV = INF;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       maxValue[a[i]][0] = a[i];       minV = min(minV, a[i]);     }     for (int j = 1; (1 << j) < N; ++j) {       for (int i = 1; i + (1 << j) - 1 < N; ++i) {         maxValue[i][j] =             max(maxValue[i][j - 1], maxValue[i + (1 << (j - 1))][j - 1]);       }     }     for (int i = 0; (1 << i) < N; ++i) Log2[(1 << i)] = i;     for (int i = 1; i < N; ++i) Log2[i] = max(Log2[i], Log2[i - 1]);     int res = 1;     for (int i = 2; i <= minV; ++i) {       bool check = 1;       for (int j = i; j < N; j += i) {         int d = getMax(j, min(N - 1, j + i - 1)) - j;         if (d > k) {           check = 0;         }       }       if (check) res = i;     }     cout << res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   map<int, int> euler;   long long w[maxn];   int phi(int n) {     int now = n;     int ret = n;     if (euler.count(now)) return euler[now];     for (int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         ret = ret / i * (i - 1);         while (n % i == 0) n /= i;       }     }     if (n > 1) ret = ret / n * (n - 1);     euler[now] = ret;     return ret;   }   long long MOD(long long n, int mod) { return n < mod ? n : (n % mod + mod); }   long long quick_mod(long long base, long long p, int mod) {     long long ret = 1;     do {       if (p & 1) ret = MOD(base * ret, mod);       base = MOD(base * base, mod);     } while (p >>= 1);     return ret;   }   long long solve(int l, int r, int mod) {     if (l == r || mod == 1) return MOD(w[l], mod);     return quick_mod(w[l], solve(l + 1, r, phi(mod)), mod);   }   int main() {     int n, mod;     scanf( %d%d , &n, &mod);     for (int i = 1; i <= n; i++) scanf( %lld , &w[i]);     int q;     scanf( %d , &q);     while (q--) {       int l, r;       scanf( %d%d , &l, &r);       long long ans = solve(l, r, mod) % mod;       printf( %lld n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char s[55], t[55], i = 0, j = 0;     scanf( %s , s);     scanf( %s , t);     while (t[i] !=   0 ) {       if (t[i] == s[j]) j++;       i++;       if (j >= strlen(s)) break;     }     cout << j + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(pair<long long, long long> a, pair<long long, long long> b) {     if (a.first > a.second && a.first > b.first) return 1;     return 0;   }   void solve() {     long long n;     cin >> n;     vector<pair<double, pair<long long, long long>>> v(n);     for (long long i = (0); i < (n); ++i) {       cin >> v[i].second.first >> v[i].second.second;       v[i].first = v[i].second.first - v[i].second.second;     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     long long s = 0;     for (long long i = (0); i < (n); ++i) {       s += v[i].second.first * i + v[i].second.second * (n - i - 1);     }     cout << s;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t1 = 1;     while (t1--) {       solve();       cout <<   n ;       ;     }   }