malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int adj[8][2] = {{-1, 0},  {0, -1}, {1, 0}, {0, 1},                          {-1, -1}, {-1, 1}, {1, 1}, {1, -1}};   const long long int LLINF = 9e18;   const int INF = 2e9;   const int MOD = 1e9 + 7;   const double EPS = 1e-10;   const double PI = acos(-1);   const int SIZE = 100011;   int N;   int cnt[SIZE];   map<string, int> Mp;   string ts[8] = { S ,  M ,  L ,  XL ,  XXL ,  XXXL };   string s;   struct edge {     int v, f, c, u;   };   vector<edge> E[SIZE];   int st[SIZE], lvl[SIZE];   void init() {     for (int i = 0; i < SIZE; i++) {       cnt[i] = 0;       E[i].clear();     }   }   void addedge(int a, int b, int ca, int cb) {     edge A = {a, 0, ca, (int)E[a].size()};     edge B = {b, 0, cb, (int)E[b].size()};     E[a].push_back(B);     E[b].push_back(A);   }   bool BFS(int S, int T) {     memset(lvl, -1, sizeof(lvl));     queue<int> q;     q.push(S);     lvl[S] = 0;     while (!q.empty()) {       int indx = q.front();       q.pop();       for (unsigned int i = 0; i < E[indx].size(); i++) {         edge &t = E[indx][i];         int idx = t.v;         if (lvl[idx] < 0 && t.c > t.f) {           lvl[idx] = lvl[indx] + 1;           q.push(idx);         }       }     }     return lvl[T] >= 0;   }   int DFS(int indx, int T, int flow) {     if (indx == T) return flow;     for (int &i = st[indx]; i < (int)E[indx].size(); i++) {       edge &t = E[indx][i];       int idx = t.v;       if (lvl[idx] == lvl[indx] + 1 && t.c > t.f) {         int cur = min(flow, t.c - t.f);         int ret = DFS(idx, T, cur);         if (ret > 0) {           t.f += ret;           E[t.v][t.u].f -= ret;           return ret;         }       }     }     return 0;   }   int Dinic(int S, int T) {     int ret = 0;     while (BFS(S, T)) {       memset(st, 0, sizeof(st));       while (int flow = DFS(S, T, INF)) {         ret += flow;       }     }     return ret;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int S = 0, T = SIZE - 1, a;     init();     for (int i = 1; i <= 6; i++) {       cin >> a;       Mp[ts[i - 1]] = i;       addedge(i, T, 0, a);     }     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> s;       s +=  , ;       string temp =   ;       for (unsigned int j = 0; j < s.size(); j++) {         if (s[j] ==  , ) {           addedge(i + 6, Mp[temp], 0, 1);           temp.clear();           cnt[i + 6]++;         } else           temp.push_back(s[j]);       }       addedge(S, i + 6, 0, 1);     }     int ans = Dinic(S, T);     if (ans != N)       cout <<  NO  << endl;     else {       cout <<  YES  << endl;       for (int i = 1; i <= N; i++) {         edge t1, t2;         if (cnt[i + 6] == 1) {           t1 = E[i + 6][0];           cout << ts[t1.v - 1] << endl;         } else {           t1 = E[i + 6][0];           t2 = E[i + 6][1];           if (t1.f == 1)             cout << ts[t1.v - 1] << endl;           else if (t2.f == 1)             cout << ts[t2.v - 1] << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[101];   int b[101];   int storage[200001];   int storage2[200001];   int* value = storage + 100000;   int* prevalue = storage2 + 100000;   int n, k;   int main() {     scanf( %d%d , &n, &k);     int gtzero = 0, lezero = 0;     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n; i++) scanf( %d , &b[i]), b[i] *= k;     for (int i = 0; i < n; i++) {       b[i] = a[i] - b[i];       if (b[i] > 0)         gtzero += b[i];       else         lezero += b[i];     }     for (int i = 0; i < sizeof(storage) / sizeof(int); i++) {       storage[i] = -19200000;       storage2[i] = -19200000;     }     value[0] = prevalue[0] = 0;     for (int i = 0; i < n; i++) {       int C = b[i];       for (int j = -10000; j <= 10000; j++) {         value[j] = max(prevalue[j], prevalue[j - b[i]] + a[i]);       }       memcpy(storage2, storage, sizeof(storage));     }     if (value[0] > 0)       printf( %d n , value[0]);     else       printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int num, a1, a2, b1, b2, c1, c2, d, a, b, c;     cin >> num >> a1 >> a2 >> b1 >> b2 >> c1 >> c2;     a = a2;     b = b2;     c = c2;     if (a + b + c == num)       cout << a <<     << b <<     << c;     else {       d = a + b + c - num;       if (c - d >= c1) {         c = c - d;         d = 0;       } else {         d = d - c + c1;         c = c1;       }       if (d > 0)         if (b - d >= b1) {           b = b - d;           d = 0;         } else {           d = d - b + b1;           b = b1;         }       if (d > 0)         if (a - d >= a1) {           a = a - d;           d = 0;         } else {           d = d - a + a1;           a = a1;         }       cout << a <<     << b <<     << c;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500005;   const int maxx = 1000005;   int n, x, y, q, l, r;   int a[N];   struct Tree {     int ans, m, tag;   } tr[maxx * 6];   void pushdown(int rt) {     int lson = rt << 1;     int rson = rt << 1 | 1;     tr[lson].m += tr[rt].tag;     tr[rson].m += tr[rt].tag;     tr[lson].tag += tr[rt].tag;     tr[rson].tag += tr[rt].tag;     tr[rt].tag = 0;   }   void updata(int rt) {     int lson = rt << 1;     int rson = rt << 1 | 1;     if (tr[lson].m == tr[rson].m) {       tr[rt].m = tr[lson].m;       tr[rt].ans = tr[lson].ans + tr[rson].ans;     } else if (tr[lson].m < tr[rson].m) {       tr[rt].m = tr[lson].m;       tr[rt].ans = tr[lson].ans;     } else {       tr[rt].m = tr[rson].m;       tr[rt].ans = tr[rson].ans;     }   }   void change(int rt, int l, int r, int cl, int cr, int C) {     if (cl <= l && r <= cr) {       tr[rt].m += C;       tr[rt].tag += C;       return;     }     pushdown(rt);     int mid = (l + r) >> 1;     if (cl <= mid) change(rt << 1, l, mid, cl, cr, C);     if (cr > mid) change(rt << 1 | 1, mid + 1, r, cl, cr, C);     updata(rt);   }   void change2(int rt, int l, int r, int x, int C) {     if (l == r) {       tr[rt].ans += C;       return;     }     pushdown(rt);     int mid = (l + r) >> 1;     if (x <= mid) change2(rt << 1, l, mid, x, C);     if (x > mid) change2(rt << 1 | 1, mid + 1, r, x, C);     updata(rt);   }   int query(int rt, int l, int r, int ql, int qr) {     if (ql <= l && r <= qr) {       if (tr[rt].m == 1) return tr[rt].ans;       return 0;     }     pushdown(rt);     int mid = (l + r) >> 1, summ = 0;     if (ql <= mid) summ += query(rt << 1, l, mid, ql, qr);     if (qr > mid) summ += query(rt << 1 | 1, mid + 1, r, ql, qr);     updata(rt);     return summ;   }   int main() {     scanf( %d %d , &n, &q);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     a[0] = maxx;     a[n + 1] = 0;     for (int i = 1; i <= n; ++i) change2(1, 0, maxx, a[i], 1);     for (int i = 1; i <= n + 1; ++i) {       int l = a[i - 1];       int r = a[i];       if (l == r) continue;       if (l > r) swap(l, r);       change(1, 0, maxx, l, r - 1, 1);     }     for (int i = 1; i <= q; ++i) {       scanf( %d %d , &x, &y);       l = a[x];       r = a[x + 1];       if (l != r) {         if (l > r) swap(l, r);         change(1, 0, maxx, l, r - 1, -1);       }       l = a[x - 1];       r = a[x];       if (l != r) {         if (l > r) swap(l, r);         change(1, 0, maxx, l, r - 1, -1);       }       change2(1, 0, maxx, a[x], -1);       change2(1, 0, maxx, y, 1);       a[x] = y;       l = a[x];       r = a[x + 1];       if (l != r) {         if (l > r) swap(l, r);         change(1, 0, maxx, l, r - 1, 1);       }       l = a[x - 1];       r = a[x];       if (l != r) {         if (l > r) swap(l, r);         change(1, 0, maxx, l, r - 1, 1);       }       printf( %d n , query(1, 0, maxx, 1, maxx - 1));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int inf = 1e9 + 7;   const ll longinf = 1LL << 60;   const ll mod = 1e9 + 7;   int main() {     int h, w, n, q;     cin >> h >> w >> n >> q;     vector<int> v[h];     for (int i = (int)(0); i < (int)(n); ++i) {       int x, y;       cin >> x >> y;       --x;       --y;       v[x].push_back(y);     }     for (int i = (int)(0); i < (int)(h); ++i) sort(v[i].begin(), v[i].end());     vector<ll> ok;     ok.push_back(-longinf);     ok.push_back(longinf);     for (int i = (int)(0); i < (int)(q); ++i) {       int x;       cin >> x;       --x;       ok.push_back(x);     }     sort(ok.begin(), ok.end());     ll pl = 0, pr = 0;     ll dp[2][202020];     for (int i = (int)(0); i < (int)(2); ++i)       for (int j = (int)(0); j < (int)(202020); ++j) dp[i][j] = longinf;     dp[0][1] = dp[1][1] = 0;     if (v[0].size()) {       pl = v[0][0];       pr = v[0].back();       dp[0][1] = 2 * pr - pl;       dp[1][1] = pr;     }     int maxh = 1;     for (int i = (int)(1); i < (int)(h); ++i) {       if (v[i].empty()) {         dp[0][i + 1] = dp[0][i] + 1;         dp[1][i + 1] = dp[1][i] + 1;         continue;       }       int nl = v[i][0], nr = v[i].back();       auto itr = lower_bound(ok.begin(), ok.end(), pl);       dp[0][i + 1] = min(dp[0][i + 1], dp[0][i] + abs(*itr - pl) +                                            abs(nr - *itr) + abs(nr - nl) + 1);       dp[1][i + 1] = min(dp[1][i + 1], dp[0][i] + abs(*itr - pl) +                                            abs(nl - *itr) + abs(nr - nl) + 1);       --itr;       dp[0][i + 1] = min(dp[0][i + 1], dp[0][i] + abs(*itr - pl) +                                            abs(nr - *itr) + abs(nr - nl) + 1);       dp[1][i + 1] = min(dp[1][i + 1], dp[0][i] + abs(*itr - pl) +                                            abs(nl - *itr) + abs(nr - nl) + 1);       itr = lower_bound(ok.begin(), ok.end(), pr);       dp[0][i + 1] = min(dp[0][i + 1], dp[1][i] + abs(*itr - pr) +                                            abs(nr - *itr) + abs(nr - nl) + 1);       dp[1][i + 1] = min(dp[1][i + 1], dp[1][i] + abs(*itr - pr) +                                            abs(nl - *itr) + abs(nr - nl) + 1);       --itr;       dp[0][i + 1] = min(dp[0][i + 1], dp[1][i] + abs(*itr - pr) +                                            abs(nr - *itr) + abs(nr - nl) + 1);       dp[1][i + 1] = min(dp[1][i + 1], dp[1][i] + abs(*itr - pr) +                                            abs(nl - *itr) + abs(nr - nl) + 1);       pl = nl;       pr = nr;       maxh = max(i + 1, maxh);     }     cout << min(dp[0][maxh], dp[1][maxh]) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int cnt = 0;     cin >> n;     string a;     for (int i = 0; i < n; i++) {       cin >> a;       if (a ==  Tetrahedron )         cnt += 4;       else if (a ==  Cube )         cnt += 6;       else if (a ==  Octahedron )         cnt += 8;       else if (a ==  Dodecahedron )         cnt += 12;       else         cnt += 20;     }     cout << cnt;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:20000000 )   string problem_name =  a ;   void init() { freopen((problem_name +  .in ).c_str(),  rt , stdin); }   long long res = 0;   int ms[300100];   int len;   void mul(int val) {     int p = 0;     for (int i = 0; i < 300000; i++) {       p += ms[i] *= val;       ms[i] = p % 10;       p /= 10;     }   }   int main() {     string s;     cin >> s;     vector<int> u(255, 0);     res = 1;     int zero = 0;     long long col = 10;     int c = 0;     int c2 = 0;     for (int i = 0; i < int((s).size()); i++) {       if (s[i] ==  ? ) {         c++;       } else if (isalpha(s[i])) {         if (u[s[i]]) continue;         u[s[i]] = 1;         if (col <= 0) {           res = 0;           zero = 1;           break;         }         c2++;         col--;       }     }     if (zero) {       cout << 0;       return 0;     }     if (c) {       if (s[0] ==  ? )         ms[c - 1] = 9;       else         ms[c] = 1;     } else       ms[0] = 1;     if (c2) {       for (int i = 10; i > 10 - c2; i--) {         if (i == 10 && isalpha(s[0]))           mul(9);         else           mul(i);       }     }     int len = 300000;     while (!ms[len]) len--;     for (int i = len; i >= 0; i--) printf( %d , ms[i]);     return 0;   }
#include <bits/stdc++.h>   const long long mod = 1e9 + 7;   using namespace std;   const long long N = 102;   const long long M = 1e4 + 2;   long long dp[N][M], c[N][N], cnt[N];   signed main() {     long long n, i, j, k, l, ans = 0, type = 0;     cin >> n;     dp[0][0] = 1;     c[0][0] = 1;     for (i = 1; i <= n; i++) {       cin >> j;       if (!cnt[j]) {         type++;       }       cnt[j]++;       for (l = i; l >= 1; l--) {         for (k = 10000; k >= j; k--) {           dp[l][k] += dp[l - 1][k - j];           if (dp[l][k] > mod) {             dp[l][k] -= mod;           }         }       }     }     if (type <= 2) {       cout << n;       return 0;     }     for (i = 1; i <= 100; i++) {       for (j = 0; j <= i; j++) {         c[j][i] = c[j][i - 1];         if (j) {           c[j][i] += c[j - 1][i - 1];         }         c[j][i] %= mod;       }     }     for (i = 1; i <= 100; i++) {       for (j = 1; j <= cnt[i]; j++) {         if (c[j][cnt[i]] == dp[j][i * j]) {           ans = max(ans, j);         }       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int dx[] = {0, 1, -1, 0, 1, -1, -1, 1};   const int dy[] = {-1, 0, 0, 1, 1, 1, -1, -1};   const int N = 0;   const int MOD = 0;   const int INF = 1e9 + 10;   const long long int LLINF = 1e18 + 10;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     int v[10010];     int l, r, x;     for (int i = 1; i <= n; i++) {       cin >> v[i];     }     int aux;     bool mudou;     int cnt = 0;     while (m--) {       cin >> l >> r >> x;       aux = x - l;       cnt = 0;       for (int i = l; i <= r; i++) {         if (v[i] < v[x]) cnt++;       }       if (cnt == aux)         cout <<  Yes n ;       else         cout <<  No n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int suma = 0, sumg = 0, a, g;     char *arr = new char[n];     for (int i = 0; i < n; i++) {       scanf( %d %d , &a, &g);       if (abs(suma + a - sumg) < abs(sumg + g - suma)) {         suma += a;         arr[i] =  A ;       } else {         sumg += g;         arr[i] =  G ;       }     }     if (abs(suma - sumg) > 500)       cout <<  -1 ;     else       for (int i = 0; i < n; i++) cout << arr[i];     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isPowerOfTwo(int x) { return (x && !(x & (x - 1))); }   bool is_prime(int n) {     if (n == 1) return false;     for (int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   void solve() {     int n;     cin >> n;     long long int a, b;     cin >> a >> b;     set<long long int> st;     st.insert(a);     st.insert(b);     for (int i = 2; i * i <= a; i++) {       if (a % i == 0) {         st.insert(i);         st.insert(a / i);       }     }     for (int i = 2; i * i <= b; i++) {       if (b % i == 0) {         st.insert(i);         st.insert(b / i);       }     }     map<pair<long long int, long long int>, long long int> ch;     ch[{a, b}]++;     for (int i = 1; i < n; i++) {       cin >> a >> b;       if (ch[{a, b}] >= 1) continue;       ch[{a, b}]++;       for (auto it = st.begin(); it != st.end();) {         long long int k = *it;         if (a % k == 0 || b % k == 0) {           it++;         } else {           it = st.erase(it++);         }       }     }     if (st.empty())       cout <<  -1 ;     else       cout << (*st.begin());   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using int64 = long long;   int64 bit_count(int64 n) {     int64 a{};     while (n) {       a += 1;       n >>= 1;     }     return a;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int T;     cin >> T;     while (T--) {       int64 n, m;       cin >> n >> m;       vector<int64> P(m);       for (auto &p : P) cin >> p;       auto s = accumulate(begin(P), end(P), 0ll);       if (s < n) {         cout << -1 <<   n ;         continue;       }       vector<int64> F(65);       for (auto p : P) F[bit_count(p) - 1]++;       int64 ans{};       for (int i = 0, j = -1; i < 64; i++) {         if (j >= 0 and F[i]) {           ans += i - j;           j = -1;           F[i]--;         }         if (n & (1 << i)) {           if (F[i]) {             F[i]--;           } else {             if (j == -1) j = i;           }         }         F[i + 1] += F[i] / 2;       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       if (i == 1)         printf( 14 n );       else {         if (i == 2)           printf( 16 n );         else           printf( %lld n , (1LL * i * (i + 1) * (i + 1) - (i - 1)));       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx )   #pragma GCC target( avx,tune=native )   using namespace std;   const int inf = 0x3f3f3f3f;   const double eps = 1e-6;   const int mod = 1000000007;   inline string getstr(string &s, int l, int r) {     string ret =   ;     for (int i = l; i <= r; i++) ret.push_back(s[i]);     return ret;   }   int modpow(int x, int y, int md = mod) {     if (y == 0) return 1;     int ret = modpow(x, y >> 1, md);     ret = (long long)ret * ret % md;     if (y & 1) ret = (long long)ret * x % md;     return ret;   }   int n, m, t, ans;   int a[10001];   int cnt[10005];   int in[11];   inline int calc(int use) {     int ret = 1;     for (int i = 1; i <= use; i++) {       ret = (long long)ret * cnt[in[i]] % mod;     }     return ret;   }   void dfs(int use, int last, bitset<128> now) {     ans += calc(use);     if (ans >= mod) ans -= mod;     for (int i = last + 1; i <= m / 2; i++) {       if (cnt[i]) {         if (now[i] || now[m - i]) continue;         bitset<128> bs =             now | (now >> i) | (now << i) | (now >> (m - i)) | (now << (m - i));         in[use + 1] = i;         dfs(use + 1, i, bs);       }     }   }   bitset<128> bs;   int main() {     bs.reset();     bs.set(0);     cin >> n >> m >> t;     for (int i = 0; i < t; i++) cin >> a[i], cnt[min(m - a[i] % m, a[i] % m)]++;     dfs(0, 0, bs);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       int n;       string a, b;       cin >> n >> a >> b;       vector<int> res;       for (int i = 0; i < n; i++) {         if (a[i] != b[i]) {           if (i != 0) res.push_back(i + 1);           res.push_back(1);           if (i != 0) res.push_back(i + 1);         }       }       cout << res.size() <<    ;       for (int x : res) {         cout << x <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 2 * 1e5 + 5;   const int INF = 1e9;   const int MOD = 1e9 + 7;   int N, K, A[MAX], table[20][MAX];   int main() {     cin >> N >> K;     for (int i = 0; i < (N); ++i) cin >> A[i];     for (int i = 0; i < (N); ++i) table[0][i] = A[i];     vector<int> b(N, 0);     for (int i = 0; i < (N); ++i) {       for (int j = 0; j < (19); ++j) {         table[j + 1][i] = table[j][i] / 2;         b[i]++;         if (table[j + 1][i] == 0) break;       }     }     map<int, int> m, cost;     int ans = INF;     for (int i = 0; i < (20); ++i) {       for (int j = 0; j < (N); ++j) {         if (b[j] < i) continue;         int num = table[i][j];         m[num]++;         cost[num] += i;         if (m[num] >= K) ans = min(ans, cost[num]);       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int r, g, b, ck, maximum = 0, temp;     scanf( %d %d %d , &r, &g, &b);     if (r % 2 == 1) r++;     r = r / 2;     if (g % 2 == 1) g++;     g = g / 2;     if (b % 2 == 1) b++;     b = b / 2;     temp = 27 + r * 3;     if (temp > maximum) maximum = temp;     temp = 28 + g * 3;     if (temp > maximum) maximum = temp;     temp = 29 + b * 3;     if (temp > maximum) maximum = temp;     printf( %d n , maximum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       for (char a =  a ; a <=  z ; a++) {         string t =   ;         for (int j = 0; j < i; j++) {           t += s[j];         }         t += a;         for (int j = i; j < s.size(); j++) {           t += s[j];         }         string r = t;         reverse(t.begin(), t.end());         if (r == t) {           cout << r;           return 0;         }       }     }     for (char a =  a ; a <=  z ; a++) {       string t = s;       t += a;       string r = t;       reverse(t.begin(), t.end());       if (r == t) {         cout << r;         return 0;       }     }     cout <<  NA ;   }
#include <bits/stdc++.h>   using namespace std;   inline void output(long long int x) {     if (x % 2)       cout << x / 2 <<   n ;     else       cout << x / 2 - 1 <<   n ;     return;   }   long long int N, K;   int main() {     cin >> N >> K;     if (N >= K)       output(K);     else {       if ((N << 1) - 1 < K)         cout << 0 <<   n ;       else         output(N - (K - N) + 2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   const int mod = 1000000007;   int n, a, b, k;   int dp[N][N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> a >> b >> k;     for (long long i = 1; i <= n; ++i) {       dp[0][i] = i;     }     for (int trip = 1; trip <= k; trip++) {       for (int floor = 1; floor <= n; floor++) {         int d = abs(b - floor);         dp[trip][floor] = dp[trip - 1][min(n, floor + d - 1)] -                           dp[trip - 1][max(0, floor - d)] - dp[trip - 1][floor] +                           dp[trip - 1][floor - 1];         while (dp[trip][floor] < 0) dp[trip][floor] += mod;         dp[trip][floor] %= mod;         dp[trip][floor] = (dp[trip][floor] + dp[trip][floor - 1]) % mod;       }     }     cout << (dp[k][a] - dp[k][a - 1] + mod) % mod;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mdc(int a, int b) { return !b ? a : mdc(b, a % b); }   int main() {     int n, m, x, y, a, b, p, d, x1, y1, x2, y2;     cin >> n >> m >> x >> y >> a >> b;     d = mdc(a, b);     a /= d;     b /= d;     p = min(n / a, m / b);     a *= p;     b *= p;     if (x + a / 2 > n) {       x2 = n;       x1 = n - a;     } else if (x - a / 2 < 0) {       x1 = 0;       x2 = a;     } else {       x2 = x + a / 2;       x1 = x2 - a;     }     if (y + b / 2 > m) {       y2 = m;       y1 = m - b;     } else if (y - b / 2 < 0) {       y1 = 0;       y2 = b;     } else {       y2 = y + b / 2;       y1 = y2 - b;     }     cout << x1 <<     << y1 <<     << x2 <<     << y2 << endl;     return 0;   }