malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct S {     int a, b;     S() {}     S(int _a, int _b) {       a = _a;       b = _b;     }     const bool operator<(const S &o) const { return a < o.a; }   };   string exm;   inline void exf(void) {     cout << exm <<   n ;     exit(0);   }   template <typename T>   inline void showAll(vector<T> &v, string sep =   ) {     for (T &here : v) cout << here << sep;   }   template <typename T>   inline void showAll(T arr[], int st, int end, string sep =   ) {     for (int i = st; i <= end; i++) cout << arr[i] << sep;   }   template <typename T>   inline vector<int> int_seperation(T N, int d = 10) {     vector<int> v;     while (N) {       v.push_back(N % d);       N /= d;     }     reverse(v.begin(), v.end());     return v;   }   const int SIZE = 500009;   char s[SIZE], t[SIZE];   int main() {     int n, k;     scanf( %d %d , &n, &k);     scanf( %s %s , s + 1, t + 1);     long long INF = 1e18, ans = 0, diff = 0;     for (int i = 1; i <= n; i++) {       diff = 2 * diff + (t[i] - s[i]);       diff = min(diff, INF);       ans += min(diff + 1, (long long)k);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void qmax(int &x, int y) {     if (x < y) x = y;   }   void qmin(int &x, int y) {     if (x > y) x = y;   }   inline long long read() {     char s;     long long k = 0, base = 1;     while ((s = getchar()) !=  -  && s != EOF && !(isdigit(s)))       ;     if (s == EOF) exit(0);     if (s ==  - ) base = -1, s = getchar();     while (isdigit(s)) {       k = k * 10 + (s ^  0 );       s = getchar();     }     return k * base;   }   inline void write(int x) {     static char cnt, num[15];     cnt = 0;     if (!x) {       printf( 0 );       return;     }     for (; x; x /= 10) num[++cnt] = x % 10;     for (; cnt; putchar(num[cnt--] + 48))       ;   }   const int maxn = 2020;   int n, k;   char ch[maxn][maxn];   int a[maxn][maxn], Max;   char d[maxn + maxn];   bool vis[maxn][maxn];   int main() {     n = read();     k = read();     for (int i = 1; i <= n; i++) {       scanf( %s , ch[i] + 1);     }     if (k >= (2 * n - 1)) {       for (int i = 1; i <= n + n - 1; i++) putchar( a );       return 0;     }     memset(a, 0x3f3f, sizeof(a));     a[1][1] = 1;     if (ch[1][1] ==  a ) a[1][1] = 0;     for (int l = 2; l <= n + n; l++) {       for (int i = 1, j; i <= n; i++) {         j = l - i;         if (j <= 0) break;         if (j > n) continue;         if (i > n) continue;         if (j + 1 <= n) qmin(a[i][j + 1], a[i][j] + (ch[i][j + 1] !=  a ));         if (i + 1 <= n) qmin(a[i + 1][j], a[i][j] + (ch[i + 1][j] !=  a ));         if (a[i][j] <= k) Max = max(Max, l);       }     }     if (Max == n + n) {       for (int i = 1; i <= n + n - 1; i++) putchar( a );       return 0;     }     bool flag = false;     if (!Max) Max = 2, vis[1][1] = true, d[2] = ch[1][1], flag = true;     for (int i = 1, j; i <= n; i++) {       j = Max - i;       if (j <= 0) break;       if (j > n) continue;       if (a[i][j] <= k) vis[i][j] = true;     }     for (int l = Max; l <= n + n; l++) {       char z =  z ;       for (int i = 1, j; i <= n; i++) {         j = l - i;         if (j <= 0) break;         if (j > n) continue;         if (!vis[i][j]) continue;         if (j + 1 <= n) z = min(z, ch[i][j + 1]);         if (i + 1 <= n) z = min(z, ch[i + 1][j]);       }       d[l + 1] = z;       for (int i = 1, j; i <= n; i++) {         j = l - i;         if (j <= 0) break;         if (j > n) continue;         if (!vis[i][j]) continue;         if (j + 1 <= n && ch[i][j + 1] == z) vis[i][j + 1] = true;         if (i + 1 <= n && ch[i + 1][j] == z) vis[i + 1][j] = true;       }     }     if (flag) Max--;     for (int i = 2; i <= Max; i++) d[i] =  a ;     for (int i = 2; i <= n + n; i++) {       putchar(d[i]);     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   using ii = pair<int, int>;   using ll = long long;   const int N = 1e5 + 5;   const int mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int a, b;     cin >> a >> b;     vector<int> ans1, ans2;     ll limit = 0;     for (; limit * (limit + 1) / 2 <= a + b; limit++)       ;     cerr << limit <<   n ;     for (int i = --limit; i >= 1; i--) {       if (a >= b)         ans1.push_back(i), a -= i;       else         ans2.push_back(i), b -= i;     }     cout << ans1.size() <<   n ;     for (auto x : ans1) cout << x <<    ;     cout <<   n ;     cout << ans2.size() <<   n ;     for (auto x : ans2) cout << x <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int t;   int n;   struct node {     long long id, val;     bool flag;     friend bool operator<(node a, node b) {       if (a.val == b.val) return a.flag == false;       return a.val > b.val;     }   };   int main() {     while (~scanf( %d , &n)) {       priority_queue<node> q;       long long num;       scanf( %lld , &num);       node nxt;       nxt.id = 1, nxt.val = num, nxt.flag = false;       q.push(nxt);       long long ans = 0;       for (int i = 2; i <= n; ++i) {         scanf( %lld , &num);         nxt.flag = false;         if (q.top().val < num) {           node now = q.top();           q.pop();           ans = ans + num - now.val;           if (now.flag) {             now.flag = false;             q.push(now);           }           nxt.flag = true;         }         nxt.id = i;         nxt.val = num;         q.push(nxt);       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, inf = 1061109567;   const long long infll = 4557430888798830399;   const int N = 2e5 + 5;   int n, q, a[N], cnt[N];   bool last[N], first[N];   vector<int> app[N];   bool start[N];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> q;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) app[a[i]].push_back(i);     for (int i = 0; i < N; i++)       if (app[i].size()) {         first[app[i][0]] = 1;         last[app[i].back()] = 1;       }     int thing = 0;     memset(start, 0, sizeof start);     start[0] = 1;     for (int i = 0; i < n; i++) {       if (first[i]) thing++;       if (last[i]) thing--;       if (!thing) start[i + 1] = 1;     }     int ans = 0;     int cur = 0;     while (cur < n) {       int nxt = n - 1;       for (int i = cur + 1; i < n; i++)         if (start[i]) {           nxt = i - 1;           break;         }       int lolMax = 0;       for (int i = cur; i < nxt + 1; i++) {         cnt[a[i]]++;         lolMax = max(lolMax, cnt[a[i]]);       }       ans += lolMax;       for (int i = cur; i < nxt + 1; i++) cnt[a[i]]--;       cur = nxt + 1;     }     cout << n - ans;     return 0;   }
#include <bits/stdc++.h>   const int MAXN = (int)1e5 + 5;   const int MODN = (int)1e9 + 7;   int inf = 0x3f3f3f3f;   using namespace std;   char str[MAXN];   int num[MAXN];   int a[MAXN];   int vis[MAXN];   int main() {     int n, m;     while (scanf( %d , &n) != EOF) {       memset(vis, 0, sizeof(vis));       int sum = 0;       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);         sum += a[i];       }       int it = sum * 2 / n;       for (int i = 0; i < n; i++) {         if (vis[i] == 0) {           vis[i] = 1;           printf( %d  , i + 1);           for (int j = 0; j < n; j++) {             if (vis[j] == 0 && a[j] + a[i] == it) {               vis[j] = 1;               printf( %d n , j + 1);               break;             }           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int cntinv(vector<int> &a) {     int n = a.size();     int ans = 0;     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         if (a[j] < a[i]) ans++;       }     }     return ans;   }   int main(int argc, char const *argv[]) {     int n;     scanf( %d , &n);     vector<int> a(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     int pv = (cntinv(a) & 1);     int m;     scanf( %d , &m);     while (m--) {       int l, r, swaps;       scanf( %d , &l);       scanf( %d , &r);       l--;       r--;       swaps = (r - l + 1) >> 1;       int cur = pv;       if (swaps & 1) cur = 1 - cur;       if (cur)         printf( odd n );       else         printf( even n );       pv = cur;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[100010], d[100010];   int main() {     int ans = 1, i, j;     int temp;     int dlen = 0, mx = 0;     while (~scanf( %d , &n)) {       for (i = 0; i != n; ++i) {         dlen = mx = 0;         scanf( %d , &temp);         for (j = 2; j * j <= temp; j++) {           if (temp % j == 0) {             d[dlen++] = j;             if (a[j] + 1 > mx) mx = a[j] + 1;             while (temp % j == 0) temp /= j;           }         }         if (temp > 1) {           d[dlen++] = temp;           if (a[temp] + 1 > mx) mx = a[temp] + 1;         }         for (j = 0; j != dlen; j++) a[d[j]] = mx;         if (ans < mx) ans = mx;       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct UF {     vector<int> par, sz;     UF(int n) {       sz.resize(n);       par.resize(n);       for (int i = 0; i < n; i++) sz[i] = 1, par[i] = i;     }     int find(int x) {       if (par[x] == x) return x;       return par[x] = find(par[x]);     }     void unite(int x, int y) {       x = find(x);       y = find(y);       if (x == y) return;       if (sz[x] > sz[y]) swap(x, y);       sz[y] += sz[x];       par[x] = y;     }     bool same(int x, int y) { return find(x) == find(y); }   };   int main() {     int i, j, n, m1, m2;     cin >> n >> m1 >> m2;     UF uf1(n), uf2(n);     for (i = 0; i < m1; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       uf1.unite(a, b);     }     for (i = 0; i < m2; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       uf2.unite(a, b);     }     vector<pair<int, int>> p;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (!uf1.same(i, j)) p.push_back({i, j});       }     }     int ans = 0;     vector<pair<int, int>> ansv;     for (i = 0; i < p.size(); i++) {       int x = p[i].first, y = p[i].second;       if (!uf1.same(x, y) && !uf2.same(x, y)) {         uf1.unite(x, y);         uf2.unite(x, y);         ans++;         ansv.push_back({x, y});       }     }     cout << ans << endl;     for (auto p : ansv) cout << p.first + 1 <<     << p.second + 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e6 + 100;   const long long inf = (1ll << 60);   const int mod2 = (int)998244353;   const int mod = (int)1e9 + 7;   int n, m;   vector<long long> b;   vector<long long> c;   void add(long long x) {     for (int i = 0; i < b.size(); i++) {       if (c[i] & x) {         x ^= b[i];       }     }     if (x > 0) {       long long y = 1;       while (!(x & y)) y *= 2;       for (int i = 0; i < b.size(); i++) {         if (b[i] & y) {           b[i] ^= x;         }       }       b.push_back(x);       c.push_back(y);     }   }   long long d[maxn];   int u[maxn];   vector<pair<long long, long long> > g[maxn];   vector<int> ord;   void dfs(int v) {     u[v] = 1;     ord.push_back(v);     for (auto to : g[v]) {       if (u[to.first] == 0) {         d[to.first] = d[v] ^ to.second;         dfs(to.first);       } else if (u[to.first] == 1) {         add(d[v] ^ d[to.first] ^ to.second);       }     }     u[v] = 2;   }   void solve() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       long long x, y, z;       cin >> x >> y >> z;       g[x].push_back({y, z});       g[y].push_back({x, z});     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (u[i]) continue;       b.clear();       c.clear();       ord.clear();       dfs(i);       long long sz = ord.size();       long long C = sz * (sz - 1) / 2;       C %= mod;       for (int j = 1; j < b.size(); j++) C = (C * 2) % mod;       for (int j = 0; j <= 60; j++) {         int ok = 0;         long long cur = (1ll << j);         for (long long x : b) {           if (x & cur) {             ok = 1;           }         }         if (ok) {           ans = (ans + cur % mod * C % mod) % mod;         } else {           long long cnt = 0;           for (int v : ord) {             if (d[v] & cur) {               cnt++;             }           }           long long cur_ans = cnt * (sz - cnt) % mod;           cur_ans = (cur % mod * cur_ans) % mod;           for (int j = 0; j < b.size(); j++) {             cur_ans = (cur_ans * 2) % mod;           }           ans += cur_ans;           ans %= mod;         }       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int X = 0, w = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) w = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) X = X * 10 + c -  0 , c = getchar();     return X * w;   }   const int N = 1000 + 10;   int n, m, a[N];   double f[N][N];   int main() {     n = read(), m = read();     for (register int i = 1; i <= n; ++i) a[i] = read();     for (register int i = 1; i <= n; ++i)       for (register int j = 1; j <= n; ++j) f[i][j] = (a[i] > a[j]);     while (m--) {       int x = read(), y = read();       for (register int i = 1; i <= n; ++i) {         f[x][i] = f[y][i] = (f[x][i] + f[y][i]) / 2;         f[i][x] = f[i][y] = 1 - f[x][i];       }       f[x][y] = f[y][x] = 0.5;     }     double ans = 0;     for (register int i = 1; i <= n; ++i)       for (register int j = i + 1; j <= n; ++j) ans += f[i][j];     printf( %.9lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char orz[500001];   int gg[500001];   int t;   int main() {     cin >> t;     while (t--) {       int n, q;       scanf( %d%d , &n, &q);       scanf( %s , orz + 1);       int rrr = 1;       for (int i = 1; i <= n; i++) {         if (orz[i] ==  + )           gg[i] = gg[i - 1] + 1 * rrr;         else           gg[i] = gg[i - 1] - 1 * rrr;         rrr *= -1;       }       while (q--) {         int l, r;         scanf( %d%d , &l, &r);         int eee = abs(gg[r] - gg[l - 1]);         if (eee != 0) {           if (eee % 2 == 1) eee = 1;           if (eee % 2 == 0) eee = 2;         }         cout << eee << endl << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   void solve() {     int n, m;     cin >> n >> m;     for (int i = 0; i < 200; i++) cout <<  9 ;     cout << endl;     for (int i = 0; i < 200; i++) cout <<  9 ;     for (int i = 0; i < 199; i++) cout <<  0 ;     cout <<  1 ;   }   int main() {     ios_base::sync_with_stdio(false);     int t = 1, num = 1;     while (t--) {       ;       ;       solve();       ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   vector<vector<long long>> mul(vector<vector<long long>> A,                                 vector<vector<long long>> B) {     int n = A.size();     vector<vector<long long>> res(n, vector<long long>(n));     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         for (int k = 0; k < n; k++) {           res[i][j] = (res[i][j] + A[i][k] * B[k][j]) % MOD;         }       }     }     return res;   }   vector<vector<long long>> mexp(vector<vector<long long>> M, long long e) {     if (e == 1) return M;     if (e % 2) return mul(M, mexp(M, e - 1));     vector<vector<long long>> R = mexp(M, e / 2);     return mul(R, R);   }   int main() {     long long n, m;     cin >> n >> m;     if (m > n) {       cout << 1 << endl;       return 0;     }     vector<vector<long long>> M(m, vector<long long>(m));     M[0][0] = M[0][m - 1] = 1;     for (int i = 1; i < m; i++) M[i][i - 1] = 1;     vector<vector<long long>> R = mexp(M, n - m + 1);     long long res = 0;     for (int i = 0; i < m; i++) res = (res + R[0][i]) % MOD;     cout << res << endl;   }
#include <bits/stdc++.h>   using vi = std::vector<long long int>;   using vvi = std::vector<vi>;   using pii = std::pair<long long int, long long int>;   using vpii = std::vector<pii>;   using vvpii = std::vector<vpii>;   using namespace std;   const long long int N = 2e6 + 10;   const long long int inf = 1e18 + 10;   const long double Pi = 3.14159265;   long long int n;   vi a;   long long int f(vi &a) {     long long int n = a.size();     if (a.empty() == 1) return 0;     if (a.back() == 0) return a.size();     long long int hig = 0;     for (long long int i = 0; i <= n - 1; i++) {       hig = max(hig, (long long int)log2(a[i]));     }     vi l, r;     for (long long int i = 0; i <= n - 1; i++) {       if ((long long int)log2(a[i]) < hig)         l.emplace_back(a[i]);       else         r.emplace_back(a[i] ^ (1 << (long long int)log2(a[i])));     }     if (!(l.size() < r.size())) swap(l, r);     a = vi();     if (l.size() == 0) return f(r);     return 1 + max(f(l), f(r));   }   void solve() {     cin >> n;     a.resize(n);     for (long long int i = 1; i <= n; i++) cin >> a[i - 1];     sort(a.begin(), a.end());     cout << (a.size() - f(a));   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;     long long int xx = 0;     long long int t;     cin >> t;     while (t--) {       ;       solve();       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[610000], i, j, k, l, n, m, p[610000], t, last, o, r, mid;   char c[610000];   bool check(int mid) {     int tmp = 1e9, res = 0;     p[0] = mid;     m = last;     for (i = 1; i <= n; ++i) {       p[i] = p[i - 1] + a[i];       if (p[i] == 0 && p[i - 1] == -1) m = max(m, i);     }     if (m == 0) return 1;     for (i = 1; i <= m; ++i) {       if (p[i - 1] == 0 && p[i] == -1) {         o = i;         tmp = min(tmp, res + (m - i) * 2);       }       if (p[i - 1] == -1 && p[i] == 0) {         if (i == m) tmp = min(tmp, res + m - o);         res += (i - o) * 2;       }       res++;     }     tmp = min(tmp, res - 1);     return tmp + 1 <= t;   }   int main() {     scanf( %d%d%s , &n, &t, c + 1);     for (i = 1; i <= n; ++i) a[i] = c[i] ==  H  ? -1 : c[i] ==  S  ? 1 : 0;     for (i = 1; i <= n; ++i) {       if (a[i] == -1) r++, last = i;       if (a[i] == 1) l--;     }     l += r;     if (l < 0) l = 0;     if (last > t) {       printf( -1 n );       exit(0);     }     while (l <= r) {       mid = (l + r) / 2;       if (check(mid))         r = mid - 1;       else         l = mid + 1;     }     printf( %d n , r + 1);   }
#include <bits/stdc++.h>   using namespace std;   const int max_n = 2005;   string str[max_n];   int dp[max_n][max_n][4];   inline void solve() {     register int n, m, i, j, k;     long long ans = 0;     cin >> n >> m;     for (i = 0; i < n; ++i) cin >> str[i];     for (i = 0; i < n; ++i) {       dp[i][0][0] = 1;       for (j = 1; j < m; ++j) {         if (str[i][j] == str[i][j - 1])           dp[i][j][0] = dp[i][j - 1][0] + 1;         else           dp[i][j][0] = 1;       }     }     for (i = 0; i < n; ++i) {       dp[i][m - 1][1] = 1;       for (j = m - 2; j >= 0; --j) {         if (str[i][j] == str[i][j + 1])           dp[i][j][1] = dp[i][j + 1][1] + 1;         else           dp[i][j][1] = 1;       }     }     for (j = 0; j < m; ++j) dp[0][j][2] = 1;     for (i = 1; i < n; ++i) {       for (j = 0; j < m; ++j) {         if (str[i][j] == str[i - 1][j])           dp[i][j][2] = min(dp[i][j][0], min(dp[i][j][1], dp[i - 1][j][2] + 1));         else           dp[i][j][2] = 1;       }     }     for (j = 0; j < m; ++j) dp[n - 1][j][3] = 1;     for (i = n - 2; i >= 0; --i) {       for (j = 0; j < m; ++j) {         if (str[i][j] == str[i + 1][j])           dp[i][j][3] = min(dp[i][j][2], dp[i + 1][j][3] + 1);         else           dp[i][j][3] = 1;         ans += dp[i][j][3];       }     }     ans += m;     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[111111], b[111111];   vector<int> id[111111];   int main() {     int N, M;     cin >> N >> M;     for (int i = 1; i <= N; i++) id[i].clear();     for (int i = 0; i < M; i++) scanf( %d , a + i);     long long tot = 0;     for (int i = 1; i < M; i++) {       if (a[i] == a[i - 1]) continue;       id[a[i]].push_back(a[i - 1]);       id[a[i - 1]].push_back(a[i]);       tot += abs(a[i] - a[i - 1]);     }     long long d = 0;     for (int i = 1; i <= N; i++) {       sort(id[i].begin(), id[i].end());       long long s = 0;       int k = id[i].size() / 2;       for (int j = 0; j < id[i].size(); j++)         s += abs(id[i][j] - id[i][k]) - abs(id[i][j] - i);       if (d > s) d = s;     }     cout << tot + d << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   vector<long long> tim(N), pos(N), cur(N);      int main() {       long long T, n, act, start, des, dir, ans, startTime;       cin>>T;       for(long long t = 1; t <= T; ++t) {           tim[0] = pos[0] = start = des = act = ans = startTime = 0;           cin>>n;           for(long long i = 1; i <= n; ++i) {               cin>>tim[i]>>pos[i];               if(tim[i] >= act) {                   cur[i] = des;                   startTime = tim[i];                   act = tim[i] + abs(des - pos[i]);                   start = des;                   des = pos[i];               } else {                   dir = (start <= des) ? 1 : -1;                   cur[i] = start + dir * (tim[i] - startTime);               }           }           cur[n+1] = des;           for(long long i = 1; i <= n; ++i) {               if(min(cur[i],cur[i+1]) <= pos[i] && pos[i] <= max(cur[i],cur[i+1])) {                   ans += 1;               }           }           cout<<ans<<endl;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int max_can;   pair<int, int> red, blue;   int main() {     scanf( %d%d%d%d%d , &max_can, &red.first, &blue.first, &red.second,           &blue.second);     long long ans = 0;     int sq = (int)sqrt(max_can);     if (red.second >= sq) {       for (int cnt = 0;; ++cnt) {         if (red.second * cnt > max_can) break;         int can = max_can - red.second * cnt;         ans = max(ans,                   cnt * 1ll * red.first + (can / blue.second) * 1ll * blue.first);       }       printf( %I64d n , ans);       return 0;     } else if (blue.second >= sq) {       for (int cnt = 0;; ++cnt) {         if (blue.second * cnt > max_can) break;         int can = max_can - blue.second * cnt;         ans = max(ans,                   cnt * 1ll * blue.first + (can / red.second) * 1ll * red.first);       }       printf( %I64d n , ans);       return 0;     } else {       if (red.first * 1ll * blue.second < blue.first * 1ll * red.second)         swap(red, blue);       for (int cnt = 0; cnt <= sq; ++cnt) {         int weight = blue.second * cnt;         if (weight > max_can) break;         int can = max_can - weight;         ans = max(ans,                   blue.first * 1ll * cnt + (can / red.second) * 1ll * red.first);       }       printf( %I64d n , ans);       return 0;     }     return 0;   }