malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   int n, m[20], r[20], c;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &m[i]);     for (int i = 0; i < n; i++) scanf( %d , &r[i]);     for (int i = 0; i < 720720; i++) {       bool you = false;       for (int j = 0; j < n; j++)         if (i % m[j] == r[j]) you = true;       if (you) c++;     }     printf( %.6lf n , c / 720720.);     scanf(  n );     return 0;   }
#include <bits/stdc++.h>   template <class T>   using pt = std::pair<T, T>;   using namespace std;   struct poledia {     int lx, ly, rx, ry;     int cnt = 0;     poledia() : lx(- -1e9), ly(- -1e9), ry(-1e9), rx(-1e9){};     poledia(bool is_dw) : lx(- -1e9), ly(-1e9), ry(- -1e9), rx(-1e9){};   };   struct poleos {     int x1, y1, x2, y2;     int cnt = 0;     poleos() : x1(0), x2(0), y1(-1e9), y2(- -1e9){};     poleos(bool is_vert) : x1(- -1e9), x2(-1e9), y1(0), y2(0){};   };   struct ferz {     int x, y;   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<ferz> a(m);     vector<poledia> diag1(2 * 1e5 + 1);     vector<poledia> diag2(2 * 1e5 + 1);     vector<poleos> ossx(1e5 + 1);     vector<poleos> ossy(1e5 + 1);     for (int i = 0; i < m; i++) {       cin >> a[i].x >> a[i].y;       int k = a[i].x + a[i].y - 1;       if (diag1[k].cnt == 0) {         diag1[k] = poledia(true);       }       diag1[k].lx = min(a[i].x, diag1[k].lx);       diag1[k].ly = max(a[i].y, diag1[k].ly);       diag1[k].rx = max(a[i].x, diag1[k].rx);       diag1[k].ry = min(a[i].y, diag1[k].ry);       diag1[k].cnt++;       k = n - a[i].x + a[i].y;       diag2[k].lx = min(diag2[k].lx, a[i].x);       diag2[k].ly = min(diag2[k].ly, a[i].y);       diag2[k].rx = max(diag2[k].rx, a[i].x);       diag2[k].ry = max(diag2[k].ry, a[i].y);       diag2[k].cnt++;       k = a[i].y;       if (ossx[k].cnt == 0) {         ossx[k] = poleos(true);       }       ossx[k].x1 = min(ossx[k].x1, a[i].x);       ossx[k].x2 = max(ossx[k].x2, a[i].x);       ossx[k].cnt++;       k = a[i].x;       ossy[k].y1 = max(ossy[k].y1, a[i].y);       ossy[k].y2 = min(ossy[k].y2, a[i].y);       ossy[k].cnt++;     }     vector<int> ans(9);     for (int i = 0; i < m; i++) {       int sum = 0;       int k1 = a[i].x + a[i].y - 1, k2 = n - a[i].x + a[i].y;       if (diag1[k1].cnt != 1) {         if (a[i].x == diag1[k1].lx && a[i].y == diag1[k1].ly ||             a[i].x == diag1[k1].rx && a[i].y == diag1[k1].ry)           sum++;         else           sum += 2;       }       if (diag2[k2].cnt != 1) {         if (a[i].x == diag2[k2].lx && a[i].y == diag2[k2].ly ||             a[i].x == diag2[k2].rx && a[i].y == diag2[k2].ry)           sum++;         else           sum += 2;       }       if (ossx[a[i].y].cnt != 1) {         if (a[i].x == ossx[a[i].y].x1 || a[i].x == ossx[a[i].y].x2)           sum++;         else           sum += 2;       }       if (ossy[a[i].x].cnt != 1) {         if (a[i].y == ossy[a[i].x].y1 || a[i].y == ossy[a[i].x].y2)           sum++;         else           sum += 2;       }       ans[sum]++;     }     for (int i = 0; i < 9; i++) {       cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void read(T& x) {     T res = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       res = (res << 3) + (res << 1) + c -  0 ;       c = getchar();     }     x = res * f;   }   const long long N = 300000 + 10;   long long n, m, mod = 998244353, fac[N], inv[N], mx = 300000;   long long sum[N][55];   int L[N], R[N], cnt[N];   long long fpow(long long x, long long p) {     long long ans = 1;     while (p) {       if (p & 1) ans = ans * x % mod;       x = x * x % mod;       p >>= 1;     }     return ans;   }   long long C(int x, int y) {     if (y < 0 || x < y) return 0;     return (fac[x] * inv[y] % mod) * inv[x - y] % mod;   }   void init() {     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod;     inv[n] = fpow(fac[n], mod - 2);     for (int i = n - 1; i >= 0; i--) {       inv[i] = inv[i + 1] * (i + 1) % mod;     }   }   struct node {     int a, b;   } nod[50];   int main() {     read(n), read(m);     init();     for (int i = 1; i <= n; i++)       read(L[i]), read(R[i]), cnt[L[i]]++, cnt[R[i] + 1]--;     for (int i = 1; i <= n; i++) cnt[i] += cnt[i - 1];     for (int i = 0; i < m; i++) {       read(nod[i].a), read(nod[i].b);     }     for (int i = 0; i <= 2 * m; i++)       for (int j = 1; j <= n; j++)         sum[j][i] = (sum[j - 1][i] + C(cnt[j] - i, j - i)) % mod;     int mx = (1 << m) - 1;     long long ans = 0;     for (int i = 0; i <= mx; i++) {       int l = 1, r = n;       set<int> in;       for (int j = 0; j < m; j++) {         if ((i >> j) & 1) {           in.insert(nod[j].a);           in.insert(nod[j].b);           l = max(l, L[nod[j].a]);           l = max(l, L[nod[j].b]);           r = min(r, R[nod[j].a]);           r = min(r, R[nod[j].b]);         }       }       int num = in.size();       long long temp = 0;       if (l <= r) temp = (sum[r][num] - sum[l - 1][num]) % mod;       if (__builtin_popcount(i) & 1) {         ans = (ans - temp) % mod;       } else {         ans = (ans + temp) % mod;       }     }     printf( %lld n , (ans % mod + mod) % mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int LIM = 200 * 1000, MAXN = 300 * 1000;   int fen[MAXN];   void add(int pos, int val) {     pos++;     while (pos < MAXN) {       fen[pos] += val;       pos += pos & -pos;     }   }   int sum(int pos) {     pos++;     int tot = 0;     while (pos) {       tot += fen[pos];       pos -= pos & -pos;     }     return tot;   }   bool by_id(pair<pair<int, int>, pair<int, int> > a,              pair<pair<int, int>, pair<int, int> > b) {     return a.second.first < b.second.first;   }   vector<int> occ[MAXN];   int pt[MAXN], a[MAXN], n, q;   pair<pair<int, int>, pair<int, int> > seg[MAXN];   int main() {     cin >> n >> q;     for (int i = 0; i < int(n); i++) {       cin >> a[i];       if (a[i] < LIM) occ[a[i]].push_back(i);     }     for (int i = 1; i < int(LIM); i++)       if (i <= (int((occ[i]).size()))) {         pt[i] = i - 1;         add(occ[i][pt[i]], 1);         if (pt[i] + 1 < (int((occ[i]).size()))) add(occ[i][pt[i] + 1], -1);       } else         pt[i] = (int((occ[i]).size()));     cerr <<  Salam :)  << endl;     for (int i = 0; i < int(q); i++) {       seg[i].second.first = i;       cin >> seg[i].first.first >> seg[i].first.second;       seg[i].first.first--;       seg[i].first.second--;     }     sort(seg, seg + q);     int cur = 0;     for (int i = 0; i < int(n); i++) {       while (cur < q && seg[cur].first.first == i) {         seg[cur].second.second = sum(seg[cur].first.second);         cur++;       }       int x = a[i];       if (x < LIM && pt[x] < (int((occ[x]).size()))) {         add(occ[x][pt[x]], -1);         if (pt[x] + 1 < (int((occ[x]).size()))) add(occ[x][pt[x] + 1], +1);         pt[x]++;         if (pt[x] < (int((occ[x]).size()))) {           add(occ[x][pt[x]], 1);           if (pt[x] + 1 < (int((occ[x]).size()))) add(occ[x][pt[x] + 1], -1);         }       }     }     sort(seg, seg + q, by_id);     for (int i = 0; i < int(q); i++) cout << seg[i].second.second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t = 1;     cin >> t;     while (t--) {       long long int n, i, j;       cin >> n;       long long int a = n / 3, b = n / 3;       if (n % 3 == 1)         cout << a + 1 <<     << b;       else if (n % 3 == 2)         cout << a <<     << b + 1;       else         cout << a <<     << b;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<pair<int, int>, int> M;   set<pair<int, int> > tmp;   char s[77777][11];   int main() {     int n;     scanf( %d , &n);     for (int ii = 0; ii < n; ii++) {       scanf( %s , s[ii]);       for (int i = 0; i < 9; i++) {         for (int j = i; j < 9; j++) {           int ans = 0;           for (int k = i; k <= j; k++) ans = ans * 10 + s[ii][k] -  0 ;           tmp.insert(make_pair(j - i + 1, ans));         }       }       for (set<pair<int, int> >::iterator it = tmp.begin(); it != tmp.end();            it++) {         M[*it]++;       }       tmp.clear();     }     for (int ii = 0; ii < n; ii++) {       int di, dj, res = 10;       for (int i = 0; i < 9; i++) {         for (int j = i; j < 9; j++) {           int ans = 0;           for (int k = i; k <= j; k++) ans = ans * 10 + s[ii][k] -  0 ;           if (M[make_pair(j - i + 1, ans)] == 1 && res > j - i + 1) {             res = j - i + 1;             di = i, dj = j;           }         }       }       for (int k = di; k <= dj; k++) putchar(s[ii][k]);       puts(  );     }   }
#include <bits/stdc++.h>   using namespace std;   const int b = 1e4 + 200;   int ans[b];   int n = 0, ez1, ez2;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> ez1 >> ez2;       ans[i] = (ez2 - (ez1 % ez2)) % ez2;     }     for (int i = 0; i < n; i++) {       cout << ans[i] << endl;     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const long long INF = 10000000000000010LL;   const int mod = 1000000007;   const int MAXN = 2010, LOG = 20;   int n, m, k, u, v, x, y, t, a, b, ans;   string S[MAXN];   int lcp[MAXN];   int dp[MAXN][MAXN], N = 1;   int solve(int l, int r) {     if (l == r) return 0;     int id = N++, mid = l;     for (int i = l + 1; i < r; i++)       if (lcp[i] < lcp[mid]) mid = i;     int L = solve(l, mid), sl = mid - l + 1;     int R = solve(mid + 1, r), sr = r - mid;     for (int i = 0; i <= sl; i++)       for (int j = 0; j <= sr; j++)         dp[id][i + j] =             max(dp[id][i + j], dp[L][i] + dp[R][j] + i * j * lcp[mid]);     return id;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> S[i];     sort(S + 1, S + n + 1);     for (int i = 1; i < n; i++)       while (lcp[i] < min(S[i].size(), S[i + 1].size()) &&              S[i][lcp[i]] == S[i + 1][lcp[i]])         lcp[i]++;     solve(1, n);     cout << dp[1][k] <<   n ;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, next = 0;     scanf( %d , &n);     int a[n], b[n];     for (int i = 0; i < n; i++) {       scanf( %d %d , &a[i], &b[i]);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (a[j] == b[i] && j != i) {           next++;           a[j] = 0;         }       }     }     printf( %d , n - next);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   int main() {     int t, n, x;     cin >> n;     vector<pair<int, int>> arr;     vector<int> arr2(n + 2, 0);     set<int, greater<int>> st;     for (int i = 1; i <= n; ++i) {       cin >> x;       arr2[x] = 1;       arr.push_back(make_pair(i, x));     }     for (int i = 1; i < arr2.size() - 1; ++i) {       if (arr2[i] == 0) {         st.insert(i);       }     }     sort(arr.begin(), arr.end(), sortbysec);     for (int i = 0; i < arr.size(); ++i) {       for (auto j = st.begin(); j != st.end(); ++j) {         if (*j == arr[i].first) {           if (i == 0)             swap(arr[i].first, arr[i + 1].first);           else             swap(arr[i].first, arr[i - 1].first);         }         arr[i].second = *j;         st.erase(j);         break;       }     }     sort(arr.begin(), arr.end());     for (int i = 0; i < arr.size(); ++i) {       cout << arr[i].second <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, ans = 0, a, b;     cin >> n;     ans = 1;     for (int i = sqrt(n); i >= 1; i--) {       if (n % i == 0) {         k = i;         break;       }     }     cout << k <<     << n / k << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long a, count = 0;       cin >> a;       for (long long i = 0; i < 31; i++) {         if (a & (1 << i)) {           count++;         }       }       long long c = powl(2, count);       cout << c << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   const ll MAX = 1e18 + 1;   const int NN = 1e5 + 5;   const int mod = 1e9 + 7;   void solve() {     string s1;     cin >> s1;     char vow[] = { a ,  e ,  o ,  u ,  i };     vector<int> ans;     int i = 0;     while (i < s1.size()) {       set<char> s;       for (int j = i; j < min(i + 3, (int)s1.size()); j++) {         s.insert(s1[j]);       }       int cnt = 0;       if (s.size() != 1) {         for (auto ch : s) {           for (int y = 0; y < 5; y++) {             if (ch == vow[y]) cnt++;           }         }         if (cnt == 0) {           ans.push_back(i + 1);           i++;         }       }       i++;     }     int k = 0;     for (int y = 0; y < s1.size(); y++) {       cout << s1[y];       if (k < ans.size() && y == ans[k]) {         cout <<    ;         k++;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tt = 1;     while (tt--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int a, num, res;     while (cin >> n) {       num = 0;       for (int i = 0; i < n; i++) {         cin >> a;         if (a % 2 == 0) {           num++;         }         if (num % 2 == 1) {           res = 1;         } else {           res = 2;         }         if (i == 0) {           cout << res;         } else {           cout <<     << res;         }       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Day12[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int prime100[] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31, 37,  41, 43,                     47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103};   template <typename T>   inline bool isLeap(T y) {     return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false);   }   template <typename T>   inline T BIGMOD(T A, T B, T M = 1000000007) {     T ret = 1;     while (B) {       if (B & 1) ret = (ret * A) % M;       A = (A * A) % M;       B = B >> 1;     }     return ret;   }   template <typename T>   inline T BigMod(T A, T B, T M) {     T ret = 1;     while (B) {       if (B & 1) ret = (ret * A) % M;       A = (A * A) % M;       B = B >> 1;     }     return ret;   }   long long int MySqrt(long long int n) {     long long int p = sqrt(n);     if ((p + 1) * (p + 1) <= n)       return p + 1;     else if (p * p <= n)       return p;     else       return p - 1;   }   long long int MyPow(long long int x, long long int n) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return MyPow(x * x, n / 2);     else       return x * MyPow(x * x, ((n - 1) / 2));   }   long long int modInverse(long long int n) {     return BIGMOD(n, (long long int)1000000007 - 2) % 1000000007;   }   int a[105][105];   int main() {     int n, d;     scanf( %d%d , &(n), &(d));     for (int i = 1; i <= d; i++) {       for (int j = 1; j <= n; j++) {         char ch;         cin >> ch;         a[i][j] = ch -  0 ;       }     }     int mx = INT_MIN;     int cnt = 0;     for (int i = 1; i <= d; i++) {       int present = 1;       for (int j = 1; j <= n; j++) {         present = present & a[i][j];       }       if (!present) {         cnt++;       } else         cnt = 0;       mx = max(mx, cnt);     }     cout << mx <<   n ;   }
#include <bits/stdc++.h>   constexpr const int64_t mod = 998244353;   int64_t dp[1005][2005][4];   int n, k;   int main(int argc, char* argv[]) {     scanf( %d%d , &n, &k);     std::fill(dp[1][0], dp[1][0] + 4, 1LL);     for (int i = 2; i <= n; ++i) {       for (int j = 0; j < k; ++j) {         dp[i][j][0] = dp[i - 1][j][0];         if (j >= 1) {           dp[i][j][0] +=               dp[i - 1][j - 1][1] + dp[i - 1][j - 1][2] + dp[i - 1][j - 1][3];           dp[i][j][0] %= mod;         }         dp[i][j][1] = dp[i - 1][j][0] + dp[i - 1][j][1] + dp[i - 1][j][3];         if (j >= 2) dp[i][j][1] += dp[i - 1][j - 2][2];         dp[i][j][1] %= mod;         dp[i][j][2] = dp[i - 1][j][0] + dp[i - 1][j][2] + dp[i - 1][j][3];         if (j >= 2) dp[i][j][2] += dp[i - 1][j - 2][1];         dp[i][j][2] %= mod;         dp[i][j][3] = dp[i - 1][j][3];         if (j >= 1) {           dp[i][j][3] +=               dp[i - 1][j - 1][0] + dp[i - 1][j - 1][1] + dp[i - 1][j - 1][2];           dp[i][j][3] %= mod;         }       }     }     int64_t ans = dp[n][k - 1][0] + dp[n][k - 1][3];     if (k >= 2) ans += dp[n][k - 2][1] + dp[n][k - 2][2];     ans %= mod;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 5;   int n, m, W, H, a[N][N], b[N][N];   long long s[N][N];   int q[N];   inline long long S(int x1, int y1, int x2, int y2) {     return s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1];   }   struct BIT {     int c[N][N];     inline void add(int x1, int y1, int x2, int y2) {       add(x2, y2);       add(x1, y2);       add(x2, y1);       add(x1, y1);     }     inline void add(int x, int y) {       for (int i = x + 1; i <= n + 1; i += i & -i)         for (int j = y + 1; j <= m + 1; j += j & -j) c[i][j]++;     }     inline int qry(int x, int y) {       int ret = 0;       for (int i = x + 1; i; i -= i & -i)         for (int j = y + 1; j; j -= j & -j) ret += c[i][j];       return ret;     }     inline int qry(int x1, int y1, int x2, int y2) {       return qry(x2, y2) - qry(x1 - 1, y2) - qry(x2, y1 - 1) +              qry(x1 - 1, y1 - 1);     }   } bit;   int tot, X[N * N], Y[N * N];   long long V[N * N];   int main() {     scanf( %d%d%d%d , &n, &m, &W, &H);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         scanf( %d , &a[i][j]),             s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];     for (int i = 1; i <= n; i++) {       int h = 1, t = 0;       for (int j = 1; j <= m; j++) {         while (h <= t && j - q[h] >= H) h++;         while (h <= t && a[i][j] <= a[i][q[t]]) t--;         q[++t] = j;         b[i][j] = a[i][q[h]];       }     }     for (int j = 1; j <= m; j++) {       int h = 1, t = 0;       for (int i = 1; i <= n; i++) {         while (h <= t && i - q[h] >= W) h++;         while (h <= t && b[i][j] <= b[q[t]][j]) t--;         q[++t] = i;         a[i][j] = b[q[h]][j];       }     }     vector<pair<long long, int> > v;     for (int i = W; i <= n; i++)       for (int j = H; j <= m; j++)         v.push_back(pair<long long, int>(             S(i - W + 1, j - H + 1, i, j) - 1ll * W * H * a[i][j],             (i - 1) * m + j));     sort(v.begin(), v.end());     for (int i = 0, sz = v.size(); i < sz; i++) {       int y = (v[i].second - 1) % m + 1, x = (v[i].second - y) / m + 1;       if (bit.qry(x - W + 1, y - H + 1, x, y)) continue;       tot++;       X[tot] = x - W + 1;       Y[tot] = y - H + 1;       V[tot] = v[i].first;       bit.add(x - W + 1, y - H + 1, x, y);     }     printf( %d n , tot);     for (int i = 1; i <= tot; i++) printf( %d %d %lld n , X[i], Y[i], V[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[3005][3005];   long long zkw[3005 << 2], M;   inline long long query(long long l, long long r) {     long long ret = 1234567891;     for (l += M - 1, r += M + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {       if (~l & 1) ret = min(ret, zkw[l ^ 1]);       if (r & 1) ret = min(ret, zkw[r ^ 1]);     }     return ret;   }   long long brr[3005][3005];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n, m, a, b;     cin >> n >> m >> a >> b;     long long x, y, z;     cin >> arr[1][1] >> x >> y >> z;     long long px, py;     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= m; j++) {         if (i != 1 || j != 1) arr[i][j] = (arr[px][py] * x + y) % z;         px = i, py = j;       }     for (M = 1; M - 2 < n; M <<= 1)       ;     for (long long j = 1; j <= m; j++) {       for (long long i = 1; i <= n; i++) zkw[i + M] = arr[i][j];       for (long long i = M - 1; i; i--)         zkw[i] = min(zkw[i << 1], zkw[i << 1 | 1]);       for (long long i = 1; i + a - 1 <= n; i++) brr[i][j] = query(i, i + a - 1);     }     long long ans = 0;     for (M = 1; M - 2 < m; M <<= 1)       ;     for (long long i = 1; i + a - 1 <= n; i++) {       for (long long j = 1; j <= m; j++) zkw[j + M] = brr[i][j];       for (long long j = M - 1; j; j--)         zkw[j] = min(zkw[j << 1], zkw[j << 1 | 1]);       for (long long r = b; r <= m; r++) {         long long l = r - b + 1;         ans += query(l, r);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a == 0 || b == 0) {       return 0;     }     long long s;     while (a != 0) {       b = b % a;       s = a;       a = b;       b = s;     }     return b;   }   int main() {     long long a, b;     cin >> a >> b;     long long g = gcd(a, b);     long long lcm = (a * b) / g;     long long toa = 0;     long long tob = 0;     long long pos = 0;     long long nexta = a;     long long nextb = b;     while (pos < lcm) {       if (nexta == nextb) {         if (a < b) {           tob += (nextb - pos);           pos = nextb;           nextb += b;         } else {           toa += (nexta - pos);           pos = nexta;           nexta += a;         }       } else if (nexta < nextb) {         toa += (nexta - pos);         pos = nexta;         nexta += a;       } else {         tob += (nextb - pos);         pos = nextb;         nextb += b;       }     }     if (toa == tob) {       cout <<  Equal  << endl;     } else if (toa > tob) {       cout <<  Dasha  << endl;     } else {       cout <<  Masha  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, mx = 0, my = (1 << 31) - 1, m2x = 0, m2y = (1 << 31) - 1, a, b;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &a, &b);       mx = max(mx, a);       my = min(my, b);     }     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &a, &b);       m2x = max(m2x, a);       m2y = min(m2y, b);     }     int res = 0;     if (m2x > my) res = max(res, m2x - my);     if (mx > m2y) res = max(res, mx - m2y);     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve(long long tc) {     long long n, m, k;     cin >> n >> m >> k;     vector<long long> v(n);     for (long long i = (0), ed = (n); i < (ed); ++i) {       cin >> v[i];     }     sort(v.begin(), v.end());     unsigned long long mx1 = v[n - 1], mx2 = v[n - 2];     if (0)       cout <<  :>>                <<  mx1             <<   :   << mx1 <<   n ,           cout <<  :>>                    <<  mx2                 <<   :   << mx2 <<   n ;     unsigned long long ans = mx2 * (m / (k + 1));     if (0)       cout <<  :>>                <<  ans             <<   :   << ans <<   n ;     m = m - (m / (k + 1));     ans += mx1 * m;     cout << ans <<   n ;   }   int32_t main() {     solve(1);     return 0;   }