malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   const long long INF = 1e15 + 7;   const long long N = 2e5 + 10;   const long long mod = 998244353;   long long pow(long long x, long long y) {     long long res = 1;     while (y > (long long)0) {       if (y & (long long)1) res = ((res) * (x));       y = y >> (long long)1;       x = ((x) * (x));     }     return res;   }   long long powm(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > (long long)0) {       if (y & (long long)1) res = (res * x) % p;       y >>= (long long)1;       x = (x * x) % p;     }     return res;   }   void solve() {     long long n;     cin >> n;     string s;     cin >> s;     long long w = 0, b = 0;     vector<long long> v;     for (long long i = 0; i < n; i++) {       if (s[i] ==  B )         b++;       else         w++;     }     if (b % 2 != 0 && w % 2 != 0) {       cout << -1 << endl;       return;     }     if (b % 2 == 0) {       for (long long i = 0; i < n - 1; i++) {         if (s[i] ==  B ) {           s[i] =  W ;           if (s[i + 1] ==  B )             s[i + 1] =  W ;           else             s[i + 1] =  B ;           v.push_back(i + 1);         }       }     } else if (w % 2 == 0) {       for (long long i = 0; i < n - 1; i++) {         if (s[i] ==  W ) {           s[i] =  B ;           if (s[i + 1] ==  B )             s[i + 1] =  W ;           else             s[i + 1] =  B ;           v.push_back(i + 1);         }       }     }     cout << v.size() << endl;     for (auto i : v) cout << i <<    ;     cout << endl;     return;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long ts = 1;     while (ts--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   void magic(int n) {     int cnt = 0;     set<vector<vector<int>>> s;     vector<pair<int, string>> ans;     map<int, int> mp;     function<void(vector<vector<int>>)> f = [&](const vector<vector<int>> &x) {       if (s.find(x) != s.end()) return;       s.insert(x);       if (x.size() == 1) {         ++cnt;         ans.push_back({0,   });         for (auto &i : x)           for (auto j : i) {             ans.back().second.push_back( 0  + j);             ans.back().first += j;           }         return;       }       for (size_t i = 1; i < x.size(); ++i) {         vector<vector<int>> y = x;         y.erase(y.begin() + i);         for (auto &z : x[i]) y[i - 1].push_back(z);         for (auto &z : y[i - 1]) z ^= 1;         f(y);       }     };     vector<vector<int>> a(n, vector<int>(1, 1));     f(a);     cout << cnt <<   n ;     sort(ans.begin(), ans.end());     for (auto i : ans) {       cout << i.first <<     << i.second <<   n ;       ++mp[i.first];     }     for (auto i : mp) {       cout << i.first <<     << i.second <<   n ;     }   }   void brute(vector<long long> a) {     long long ans = numeric_limits<long long>::min();     set<vector<long long>> s;     function<void(vector<long long>)> f = [&](const vector<long long> &x) {       if (x.size() == 1) {         ans = max(ans, x[0]);         return;       }       if (s.find(x) != s.end()) return;       s.insert(x);       for (size_t i = 1; i < x.size(); ++i) {         vector<long long> y = x;         y.erase(y.begin() + i);         y[i - 1] = -x[i - 1] - x[i];         f(y);       }     };     f(a);     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n;     cin >> n;     vector<pair<long long, int>> a(n);     for (auto &i : a) cin >> i.first, i.second = &i - &a[0];     long long sum = 0;     for (auto i : a) sum += -i.first;     for (auto &i : a) i.first *= 2;     sort(a.rbegin(), a.rend());     int t = n % 3;     if (t == 2)       t = 0;     else if (t == 0)       t = 2;     a.insert(a.begin(), {0, 0});     for (int i = 1; i <= n; ++i) a[i].first += a[i - 1].first;     auto get = [&](int p) { return a[p].first - a[p - 1].first; };     long long rans = numeric_limits<long long>::min();     for (; t <= n; t += 3) {       if (n > 1 && (n & 1) && t == (n + 1) / 2) {         bool bad = true;         for (int i = 1; i <= t; ++i) bad &= ~a[i].second & 1;         rans = max(rans, sum + a[t].first + bad * (-get(t) + get(t + 1)));       } else         rans = max(rans, sum + a[t].first);     }     cout << rans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long num;     cin >> n;     set<long> s;     while (n > 0) {       cin >> num;       while (num % 2 == 0) {         num = num / 2;       }       while (num % 3 == 0) {         num = num / 3;       }       s.insert(num);       n--;     }     if (s.size() == 1) {       cout <<  Yes ;     } else {       cout <<  No ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   template <typename t1>   t1 gcd(t1 a, t1 b) {     return b == 0 ? a : gcd(b, a % b);   }   template <typename t1>   t1 lcm(t1 a, t1 b) {     return a * (b / gcd(a, b));   }   int main() {     int n, d, h;     while (cin >> n >> d >> h) {       if (h == 1 && d == 1 && n > 2)         cout << -1 << endl;       else if (d < h)         cout << -1 << endl;       else if (n <= d || d > 2 * h)         cout << -1 << endl;       else if (h == d) {         {           int l = h;           int now = 1;           while (l--) {             cout << now <<     << now + 1 << endl;             now++;           }           now++;           int nnn = 2;           int tem = d + 1;           while (now <= n) {             cout << nnn <<     << now++ << endl;           }         }       } else {         int l = h;         int now = 1;         while (l--) {           cout << now <<     << now + 1 << endl;           now++;         }         now++;         int rem = d - h;         while (now <= n) {           int flag = 0;           int noww = 1;           int nrem = rem;           while (nrem--) {             if (now > n) {               flag = 1;               break;             }             cout << noww <<     << now << endl;             noww = now;             now++;           }           if (flag) break;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int start;   int tail;   int head[150500], to[150500], nxt[150500], wei[150500], cost[150500], tot = 1;   int dis[5050], pre[5050], pres[5050];   bool vis[5050];   queue<int> que;   int n, sum, k;   int used, flow;   char str[105];   int numstr[30], numstr1[105][30], num[105];   void add(int x, int y, int z, int w) {     tot++, to[tot] = y, nxt[tot] = head[x], head[x] = tot, cost[tot] = w,            wei[tot] = z;     tot++, to[tot] = x, nxt[tot] = head[y], head[y] = tot, cost[tot] = -w,            wei[tot] = 0;   }   bool spfa() {     memset(dis, inf, sizeof(dis));     memset(vis, 0, sizeof(vis));     dis[start] = 0;     que.push(start);     int now;     do {       now = que.front();       vis[now] = 0;       que.pop();       for (int i = head[now]; i; i = nxt[i]) {         if (dis[to[i]] > dis[now] + cost[i] && wei[i]) {           dis[to[i]] = dis[now] + cost[i];           pre[to[i]] = now;           pres[to[i]] = i;           if (!vis[to[i]]) {             que.push(to[i]);             vis[to[i]] = 1;           }         }       }     } while (!que.empty());     return dis[tail] != inf;   }   void f() {     int now = tail;     int low = inf;     while (now != start) {       low = min(low, wei[pres[now]]);       now = pre[now];     }     used += low * dis[tail];     flow += low;     now = tail;     while (now != start) {       wei[pres[now]] -= low;       wei[pres[now] ^ 1] += low;       now = pre[now];     }   }   int main() {     int len;     cin >> str;     len = strlen(str);     for (int i = 0; i < strlen(str); i++) {       numstr[str[i] -  a  + 1]++;     }     cin >> k;     start = 0, tail = 30;     for (int i = 1; i <= k; i++) {       cin >> str >> num[i];       for (int j = 0; j < strlen(str); j++) {         numstr1[i][str[j] -  a  + 1]++;       }     }     for (int i = 1; i <= 26; i++) {       if (!numstr[i]) continue;       add(start, i, numstr[i], 0);       for (int j = 1; j <= k; j++) {         if (!numstr1[j][i]) continue;         add(i, j + 30, numstr1[j][i], j);       }     }     for (int i = 1; i <= k; i++) {       add(i + 30, tail, num[i], 0);     }     while (spfa()) {       f();     }     if (flow != len) {       cout << -1 << endl;     } else {       cout << used << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   int n, u;   int e[N];   double ans = -1;   int search(int l, int r, int k) {     int m, p = -1;     while (l <= r) {       m = (l + r) / 2;       if (e[m] <= k) {         p = m;         l = m + 1;       } else         r = m - 1;     }     return p;   }   void solve() {     for (int i = 0; i < n - 2; i++) {       int k = search(i + 2, n - 1, e[i] + u);       if (k == -1) continue;       ans = max(ans, 1.0 * (e[k] - e[i + 1]) / (e[k] - e[i]));     }     if (ans > 0)       printf( %.9f n , ans);     else       puts( -1 );   }   int main() {     cin >> n >> u;     for (int i = 0; i < n; i++) {       cin >> e[i];     }     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 600005;   int n, m, l, r, ma, a[N], f[N][22];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &l, &r);       a[l] = max(a[l], r);       ma = max(ma, r);     }     for (int i = 1; i <= ma; i++) a[i] = max(a[i], a[i - 1]);     for (int i = 0; i <= ma; i++) f[i][0] = a[i];     for (int i = 1; i <= 20; i++)       for (int j = 0; j <= ma; j++) f[j][i] = f[f[j][i - 1]][i - 1];     while (m--) {       cin >> l >> r;       int ans = 0;       for (int i = 20; i >= 0; i--)         if (f[l][i] < r) {           ans += 1 << i;           l = f[l][i];         }       if (a[l] >= r)         printf( %d n , ans + 1);       else         cout << -1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1000000 + 5;   const long long MOD = 1000000007;   long long n, m, k;   long long ans;   long long v[N], sum[N];   long long Pow(long long x, long long k) {     long long z = 1;     for (; k; k >>= 1, (x *= x) %= MOD)       if (k & 1) (z *= x) %= MOD;     return z;   }   int main() {     scanf( %I64d %I64d %I64d , &n, &m, &k);     long long a, b, flag = 0, st = 0, ed = 0;     for (long long i = 1; i <= m; i++) {       scanf( %I64d %I64d , &a, &b);       if (a >= b) flag = 1;       if (b - a == 1 || b - a == k + 1)         ;       else         flag = 1;       if (b - a == k + 1) {         v[a] = 1;         if (!st) st = a;         ed = a;       }     }     if (flag || (ed - st >= k + 1))       printf( 0 n );     else {       for (long long i = 1; i <= n; i++) sum[i] = sum[i - 1] + v[i];       n -= ++k;       for (long long i = 1; i <= n; i++)         if (!st || (!v[i] && abs(i - st) + 1 <= k && abs(i - ed) + 1 <= k)) {           long long tmp = st ? ((((i) < (st) ? (i) : (st)) + k - 1) < (n)                                     ? (((i) < (st) ? (i) : (st)) + k - 1)                                     : (n))                              : n;           long long r = ((k - 1) < (tmp - i) ? (k - 1) : (tmp - i));           (ans += Pow(2, r - (sum[i + r] - sum[i]))) %= MOD;         }       printf( %I64d n , ans + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int _ = 1e5 + 7, P = 1e9 + 7;   int N, A[_], prm[_], cprm, phi[_], cnt[_];   bool nprm[_];   vector<int> lst[_];   void sieve() {     phi[1] = 1;     for (int i = 2; i <= 1e5; ++i) {       if (!nprm[i]) {         prm[++cprm] = i;         phi[i] = i - 1;       }       for (int j = 1; prm[j] * i <= 1e5; ++j) {         nprm[prm[j] * i] = 1;         if (i % prm[j] == 0) {           phi[i * prm[j]] = phi[i] * prm[j];           break;         }         phi[i * prm[j]] = phi[i] * (prm[j] - 1);       }     }     for (int i = 1; i <= 1e5; ++i)       for (int j = i; j <= 1e5; j += i) lst[j].push_back(i);   }   int main() {     ios::sync_with_stdio(0);     sieve();     cin >> N;     for (int i = 1; i <= N; ++i) cin >> A[i];     int ans = 0;     vector<int> vis;     for (int d = 1; d <= N; ++d) {       for (int t = d; t <= N; t += d)         for (auto v : lst[A[t]])           if (!(cnt[v]++)) vis.push_back(v);       for (auto t : vis) {         ans = (ans + 1ll * phi[d] * phi[t] % P * cnt[t] * cnt[t]) % P;         cnt[t] = 0;       }       vis.clear();     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     pair<int, int> a[555555];     double n, k, t, l = -1, r = 1e12, c, maxx, yes = 0;     int i;     cin >> n;     for (i = 0; i < n; i++) scanf( %d%d , &a[i].first, &a[i].second);     for (k = 0; k < 300; k++) {       maxx = -1e30;       c = (l + r) * 0.5;       t = 0;       for (i = 0; i < n; i++)         if (a[i].second > 0)           maxx = max(maxx, a[i].first + a[i].second * c);         else if (maxx >= a[i].first + a[i].second * c) {           t = 1;           break;         }       if (t) {         yes = 1;         r = c;       } else         l = c;     }     cout.precision(20);     if (yes == 0) r = -1;     cout << r;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cin.ignore();     string arr;     getline(cin, arr);     int mx = 0;     int cur = 0;     for (int i = 0; i < n; i++) {       if (arr[i] ==    ) {         mx = max(mx, cur);         cur = 0;         continue;       }       if (isupper(arr[i])) {         cur++;       }     }     mx = max(mx, cur);     cout << mx;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, l, x, y, z, m, n, a, b, ans, p, q, r;   int numbers[800000];   int gcd(int x, int y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   int main() {     scanf( %d %d %d , &a, &b, &n);     ans = gcd(a, b);     m = sqrt(ans);     for (i = 1, k = 0; i <= m; i++) {       if (ans % i == 0) {         p = ans / i;         numbers[k] = p;         k++;         numbers[k] = i;         k++;       }     }     sort(numbers, numbers + k);     p = 0;     q = 0;     for (i = 1; i <= n; i++) {       scanf( %d %d , &x, &y);       if (x > ans) {         printf( -1 n );         continue;       }       p = lower_bound(numbers, numbers + k, (x)) - numbers;       q = lower_bound(numbers, numbers + k, (y)) - numbers;       r = 0;       for (j = q + 1; j >= p - 1; j--) {         if (numbers[j] >= x && numbers[j] <= y) {           printf( %d n , numbers[j]);           r = 1;           break;         }       }       if (!r) printf( -1 n );     }     return 0;   }
#include <bits/stdc++.h>   int main(int argc, char *argv[]) {     std::string s;     std::cin >> s;     int yes = 0;     int len = s.length();     if (len < 3) {       std::cout <<  No ;       return 0;     }     for (int i = 0; i < len - 2; i++) {       std::string ss = s.substr(i, 3);       if (ss ==  ABC  || ss ==  ACB  || ss ==  BAC  || ss ==  BCA  ||           ss ==  CAB  || ss ==  CBA ) {         yes = 1;         break;       }     }     if (yes) {       std::cout <<  Yes ;     } else {       std::cout <<  No ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> v(n);       vector<int> ans(n);       for (int i = 0; i < n; i++) cin >> v[i];       int flagie = 1;       for (int i = 1; i < n; i++)         if (v[i] != v[i - 1]) flagie = 0;       if (flagie == 1) {         cout << 1 << endl;         for (auto x : ans) cout << 1 <<    ;         cout << endl;       } else {         if (n % 2 == 0) {           ans[0] = 1;           for (int i = 1; i < n; i++) {             ans[i] = 3 - ans[i - 1];           }           cout << 2 << endl;           for (auto x : ans) cout << x <<    ;           cout << endl;         } else {           if (v[0] == v[n - 1]) {             cout << 2 << endl;             ans[0] = 1;             for (int i = 1; i < n; i++) {               ans[i] = 3 - ans[i - 1];             }             for (auto x : ans) cout << x <<    ;             cout << endl;           } else {             int i;             for (i = 0; i < n - 1; i++) {               if (v[i] == v[i + 1]) break;             }             if (i == n - 1) {               ans[0] = 1;               for (int i = 1; i < n; i++) {                 ans[i] = 3 - ans[i - 1];               }               ans[n - 1] = 3;               cout << 3 << endl;               for (auto x : ans) cout << x <<    ;               cout << endl;             } else {               int flag = 1;               ans[0] = 1;               for (int i = 1; i < n; i++) {                 if (v[i] == v[i - 1] && flag == 1) {                   ans[i] = ans[i - 1];                   flag = 0;                 } else {                   ans[i] = 3 - ans[i - 1];                 }               }               cout << 2 << endl;               for (auto x : ans) cout << x <<    ;               cout << endl;             }           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   namespace patch {   template <typename T>   std::string to_string(const T& n) {     std::ostringstream stm;     stm << n;     return stm.str();   }   }  // namespace patch   int m, lim, len;   long long dp[1 << 18][101];   string s;   long long fac[19];   int freq[10];   long long solve(int mask, int mod) {     if (mask == lim) {       if (mod == 0) return 1;       return 0;     }     if (dp[mask][mod] != -1) return dp[mask][mod];     long long ans = 0;     for (int i = 0; i < len; ++i) {       if (!(mask & (1 << i))) {         if (mask == 0) {           if (s[i] ==  0 ) continue;         }         ans += solve(mask | (1 << i), (mod * 10 + (s[i] -  0 )) % m);       }     }     return dp[mask][mod] = ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     fac[0] = fac[1] = 1;     for (int i = 2; i <= 18; ++i) fac[i] = fac[i - 1] * (long long)i;     memset(dp, -1, sizeof dp);     cin >> s >> m;     len = s.size();     for (int i = 0; i < len; ++i) {       freq[s[i] -  0 ]++;     }     lim = (1 << len) - 1;     long long ans = solve(0, 0);     for (int i = 0; i < 10; ++i) {       if (freq[i]) ans /= fac[freq[i]];     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, a[N];   int cnt[N], odd, neg, sum;   int f[N];   long long res;   bool check(int L, int R) {     for (int i = 1; i <= n; ++i)       if (!(L <= (i) && (i) <= R) && !(L <= (n - i + 1) && (n - i + 1) <= R) &&           a[i] != a[n - i + 1])         return 0;     for (int i = 1; i <= n; ++i) cnt[i] = 0;     for (int i = 1; i <= n; ++i) {       if ((L <= (i) && (i) <= R)) {         ++cnt[a[i]];       } else if ((L <= (n - i + 1) && (n - i + 1) <= R))         --cnt[a[i]];     }     int sum = 0;     for (int i = 1; i <= n; ++i)       if (cnt[i] < 0)         return 0;       else         sum += (cnt[i] & 1);     return sum <= (n & 1);   }   bool ok(int l, int r) {     if (r <= n / 2) return (f[r] - f[l - 1] == sum);     if (l >= (n + 1) / 2 + 1) {       l = n - l + 1;       r = n - r + 1;       return (f[l] - f[r - 1] == sum);     }     r = n - r + 1;     return (f[n / 2] - f[min(l, r) - 1] == sum);   }   void work() {     int i, j, k;     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (i = 1; i <= n / 2; ++i) f[i] = f[i - 1] + (a[i] != a[n - i + 1]);     sum = f[n / 2];     i = 1, j = 0;     while (i <= n) {       while (j <= n && (j < i || (!ok(i, j) || neg || odd > (n & 1)))) {         ++j;         k = n - j + 1;         if (cnt[a[j]] < 0) --neg;         if (cnt[a[j]] & 1) --odd;         if (a[j] != a[k]) {           if (cnt[a[k]] < 0) --neg;           if (cnt[a[k]] & 1) --odd;         }         ++cnt[a[j]];         if (i <= k && k <= j) {           if (j != k) ++cnt[a[j]];         } else           --cnt[a[k]];         if (cnt[a[j]] < 0) ++neg;         if (cnt[a[j]] & 1) ++odd;         if (a[j] != a[k]) {           if (cnt[a[k]] < 0) ++neg;           if (cnt[a[k]] & 1) ++odd;         }       }       k = n - i + 1;       if (cnt[a[i]] < 0) --neg;       if (cnt[a[i]] & 1) --odd;       if (a[i] != a[k]) {         if (cnt[a[k]] < 0) --neg;         if (cnt[a[k]] & 1) --odd;       }       --cnt[a[i]];       if (i < k && k <= j) {         if (i != k) --cnt[a[i]];       } else {         ++cnt[a[k]];       }       if (cnt[a[i]] < 0) ++neg;       if (cnt[a[i]] & 1) ++odd;       if (a[i] != a[k]) {         if (cnt[a[k]] < 0) ++neg;         if (cnt[a[k]] & 1) ++odd;       }       res += n - j + 1;       ++i;     }     cout << res << endl;   }   int main() {     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long Mod = 1e9 + 7;   const long long INF = (long long)(1e18) + 5;   const long long N = 2e5 + 5, M = 18;   int n, m, p;   int a[N];   tuple<long long, long long, long long> b[N];   long long suf_s[N], suf_c[N];   long long dp[N], prev_dp[N];   void solve(int i, int j, int l, int r) {     if (j < i) return;     int mid = i + j >> 1;     long long best = INF, idx = -1;     long long cnt = 0, sum = 0;     if (mid < l) {       sum += suf_s[mid] - suf_s[l];       cnt += suf_c[mid] - suf_c[l];     }     for (int k = max(mid, l); k <= r; k++) {       auto [t, c, s] = b[k];       sum += s;       cnt += c;       long long cur = sum + cnt * t + prev_dp[k + 1];       if (cur < best) best = cur, idx = k;     }     dp[mid] = best;     solve(i, mid - 1, l, idx);     solve(mid + 1, j, idx, r);   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m >> p;     for (int i = 1; i < n; i++) cin >> a[i], a[i] += a[i - 1];     map<long long, long long> cnt, sum;     long long ans2 = 0;     for (int i = 0; i < m; i++) {       int h, t;       cin >> h >> t;       h--;       cnt[t - a[h]]++;       sum[t - a[h]] += a[h] - t;     }     m = 0;     for (auto [i, j] : cnt) b[m++] = {i, j, sum[i]};     for (int i = m; i >= 0; i--) {       auto [t, c, s] = b[i];       suf_s[i] = s + suf_s[i + 1];       suf_c[i] = c + suf_c[i + 1];     }     for (int i = 0; i < m; i++) dp[i] = INF;     while (p--) {       swap(dp, prev_dp);       solve(0, m - 1, 0, m - 1);     }     cout << dp[0] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e9 + 9;   const long long N = 500500;   signed main(void) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.precision(10);     cout << fixed;     long long v;     cin >> v;     if (v == 2) {       cout << 2;       return 0;     }     cout << 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void dfs(bool* visit, vector<int>* am, int n, int sv, vector<int>& v) {     visit[sv] = true;     v.push_back(sv);     for (int p = 0; p < am[sv].size(); ++p) {       if (visit[am[sv][p]] == false) {         dfs(visit, am, n, am[sv][p], v);       }     }     return;   }   int main() {     int n, m;     cin >> n >> m;     int* arr = new int[n];     vector<int>* graph = new vector<int>[n];     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       graph[a - 1].push_back(b - 1);       graph[b - 1].push_back(a - 1);     }     bool* visit = new bool[n]();     long long count = 1;     for (int cur = 0; cur < n; ++cur) {       if (visit[cur] == false) {         vector<int> v;         dfs(visit, graph, n, cur, v);         int p = v.size() - 1;         for (int j = 1; j <= p; ++j) {           count = count * 2;         }       }     }     cout << count << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int n, m;     cin >> n >> m;     char a, b;     int flag1, flag2;     cin >> s;     for (int i = 0; i < m; i++) {       cin >> flag1 >> flag2 >> a >> b;       for (int j = flag1 - 1; j <= flag2 - 1; j++) {         if (s[j] == a) {           s[j] = b;         }       }     }     cout << s << endl;   }