malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 55;   long long f[maxn][maxn][maxn][maxn];   long long pw[maxn];   int c[maxn];   void init() {     f[0][0][0][0] = 1;     pw[0] = 1;     for (int i = 1; i < maxn; i++) pw[i] = (pw[i - 1] * 2ll) % mod;   }   long long cal(int x, bool xx) { return x ? pw[x - 1] : xx; }   void cal_ans(int ew, int ow, int eb, int ob, int now, long long& ret) {     if (now != 0 && ew)       (ret += f[ew - 1][ow][eb][ob] * pw[ew + ow - 1 + eb] % mod * cal(ob, 0) %               mod) %= mod;     if (now != 0 && ow)       (ret += f[ew][ow - 1][eb][ob] * pw[ew + ow - 1 + eb] % mod * cal(ob, 1) %               mod) %= mod;     if (now != 1 && eb)       (ret += f[ew][ow][eb - 1][ob] * pw[eb + ob - 1 + ew] % mod * cal(ow, 0) %               mod) %= mod;     if (now != 1 && ob)       (ret += f[ew][ow][eb][ob - 1] * pw[eb + ob - 1 + ew] % mod * cal(ow, 1) %               mod) %= mod;   }   int main(int argc, const char** argv) {     init();     int n, p;     cin >> n >> p;     for (int i = 1; i <= n; i++) scanf( %d , c + i);     long long ans = 0;     for (int i = 1; i <= n; i++)       for (int ew = 0; ew <= i; ew++)         for (int ow = 0; ow + ew <= i; ow++)           for (int eb = 0; ow + ew + eb <= i; eb++) {             int ob = i - ow - ew - eb;             cal_ans(ew, ow, eb, ob, c[i], f[ew][ow][eb][ob]);             if (i == n && ((ow + ob) & 1) == p) (ans += f[ew][ow][eb][ob]) %= mod;           }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 6;   vector<int> G[N];   int d[N];   void dfs(int u, int f, int dep) {     d[u] = dep;     for (int i = 0, iend = G[u].size(); i < iend; ++i) {       int v = G[u][i];       if (v != f) dfs(v, u, dep + 1);     }   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, a, b, da, db;       scanf( %d%d%d%d%d , &n, &a, &b, &da, &db);       for (int i = 1; i <= n; ++i) G[i].clear();       for (int i = 1; i <= n - 1; ++i) {         int u, v;         scanf( %d%d , &u, &v);         G[u].push_back(v), G[v].push_back(u);       }       if (2 * da >= db) {         puts( Alice );         continue;       }       dfs(1, 0, 0);       int u = 0;       for (int i = 1; i <= n; ++i)         if (d[i] > d[u]) u = i;       dfs(u, 0, 0);       int mx = 0;       for (int i = 1; i <= n; ++i) mx = max(mx, d[i]);       if (da >= (mx + 1) / 2) {         puts( Alice );         continue;       }       dfs(a, 0, 0);       puts(da >= d[b] ?  Alice  :  Bob );     }     return 0;   }
#include<bits/stdc++.h>   #define int long long   #define f first   #define s second   #define N 1010   #define M 1010   #define MOD 998244353   #define oo 1e18   using namespace std;   typedef pair<int,int> ii;   int v[N][N], estado[N];   set<int>freq[N][N];   int n;   void eraseLine(int line, queue<int>&unique) {       for(int c=0; c<n; c++) {           int val = v[line][c];           freq[c][val].erase(line);           if(freq[c][val].size() == 1) {               int line = *freq[c][val].begin();               unique.push(line);               freq[c][val].clear();           }       }   }   int32_t main() {       int t; cin >> t;       while(t--) {           cin >> n;           for(int l=0; l<2*n; l++) {               estado[l] = 0;               for(int i=0; i<=n; i++) {                   freq[l][i].clear();               }           }                      for(int l=0; l<2*n; l++) {               for(int c=0; c<n; c++) {                   cin >> v[l][c];                   freq[c][v[l][c]].insert(l);               }           }           queue<int>unique;           for(int c=0; c<n; c++) {               for(int i=1; i<=n; i++) {                   if(freq[c][i].size() == 1) {                       int line = *freq[c][i].begin();                       unique.push(line);                       freq[c][i].clear();                   }               }           }              int quantityAnswers = 1;           vector<int>example;              while(example.size() != n) {               int choosenLine = -1;               if(unique.size()) {                   choosenLine = unique.front();                   unique.pop();                   if(estado[choosenLine]) continue;               } else {                   quantityAnswers *= 2;                   quantityAnswers %= MOD;                                      choosenLine = -1;                   for(int l=0; l<=2*n; l++) {                       if(estado[l]) continue;                       choosenLine = l;                       break;                   }               }                  estado[choosenLine] = 2;               example.push_back(choosenLine);               for(int curLine=0; curLine<2*n; curLine++) {                   if(estado[curLine]) continue;                   for(int c=0; c<n; c++) {                       if(v[choosenLine][c] == v[curLine][c]) {                           estado[curLine] = 1;                           break;                       }                   }                      if(estado[curLine]) {                       eraseLine(curLine, unique);                   }               }               eraseLine(choosenLine, unique);           }              sort(example.begin(), example.end());           cout << quantityAnswers << endl;           for(int val:example) cout << val + 1 <<    ;           cout << endl;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ii = pair<ll, ll>;   using vi = vector<ll>;   using vb = vector<bool>;   using vvi = vector<vi>;   using vii = vector<ii>;   using vvii = vector<vii>;   constexpr int INF = 2000000000;   constexpr ll LLINF = 9000000000000000000;   struct abc {     ll a, b, c;   };   ll remove_from_front(map<ll, ll> &pareto, ll a, ll b, ll ma, ll mb) {     auto ait = pareto.find(a);     pareto.erase(ait);     auto it = pareto.lower_bound(a);     mb = max(mb, it->second);     --it;     ma = max(ma, it->first);     return max(0LL, a - ma) * max(0LL, b - mb);   }   ll insert_in_front(map<ll, ll> &pareto, ll a, ll b, ll ma, ll mb) {     ll ret = 0LL;     while (true) {       auto it = pareto.lower_bound(a);       if (it->second >= b) return 0LL;       while (it->first > a) --it;       if (it->second > b) break;       ll ra = it->first, rb = it->second;       ret += remove_from_front(pareto, ra, rb, ma, mb);     }     auto it = pareto.lower_bound(a);     mb = max(mb, it->second);     --it;     ma = max(ma, it->first);     ret -= max(0LL, a - ma) * max(0LL, b - mb);     pareto.insert({a, b});     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n;     ll p, q, r;     cin >> n >> p >> q >> r;     vector<abc> vs(n, {0, 0, 0});     for (abc &v : vs) cin >> v.a >> v.b >> v.c;     sort(vs.begin(), vs.end(),          [](const abc &l, const abc &r) { return l.c < r.c; });     vi amax(n, 0LL), bmax(n, 0LL);     amax.back() = vs.back().a;     bmax.back() = vs.back().b;     for (int i = n - 2; i >= 0; --i)       amax[i] = max(amax[i + 1], vs[i].a), bmax[i] = max(bmax[i + 1], vs[i].b);     ll cur = (p - amax[0]) * (q - bmax[0]), ans = 0LL;     map<ll, ll> pareto;     pareto.insert({0LL, q + 1LL});     pareto.insert({p + 1LL, 0LL});     int i = 0;     for (ll c = 1LL; c <= r; ++c) {       ans += cur;       for (; i < n && vs[i].c == c; ++i) {         ll ai = vs[i].a, bi = vs[i].b;         cur += insert_in_front(pareto, ai, bi, amax[i], bmax[i]);         ll af = amax[i], bf = bmax[i];         ll at = (i + 1 < n ? amax[i + 1] : 0LL),            bt = (i + 1 < n ? bmax[i + 1] : 0LL);         if (af == at && bf == bt) continue;         auto it = pareto.lower_bound(af);         while (it->first > at) {           auto it2 = it;           --it2;           ll h = it->second;           cur += (min(af, it->first) - max(at, it2->first)) * (q - max(h, bf));           it = it2;         }         ll l = 0LL, r = p;         while (l < r) {           ll m = (l + r + 1) / 2LL;           auto it = pareto.lower_bound(m);           if (it->second > bf)             l = m;           else             r = m - 1;         }         it = pareto.lower_bound(l);         while (it->second > bt) {           auto it2 = it;           ++it2;           ll h = it->first;           cur += (min(bf, it->second) - max(bt, it2->second)) * (p - max(h, at));           it = it2;         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     std::cin >> n;     int a[n][n];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) std::cin >> a[i][j];     int sum = 0;     int l = (n - 1) / 2, j = n - 1;     for (int i = 0; i < n; i++) {       sum = sum + a[i][l] + a[l][i] + a[i][i] + a[i][j--];     }     sum = sum - 3 * a[l][l];     std::cout << sum;   }
#include <bits/stdc++.h>   const int mxn = 1 << 19, mod = 998244353;   inline int qpow(int x, int n) {     int ans = 1;     for (; n; n >>= 1, x = 1LL * x * x % mod)       if (n & 1) ans = 1LL * ans * x % mod;     return ans;   }   int r[mxn], w[mxn];   void fft_init(int n) {     for (int i = 1; i < n - 1; ++i) r[i] = r[i >> 1] >> 1 | (i & 1 ? n >> 1 : 0);     for (int h = 1; h < n; h <<= 1) {       int temp = qpow(3, (mod - 1) / (h << 1));       for (int i = 0; i < (int)(h); ++i)         w[h + i] = i ? 1LL * temp * w[h + i - 1] % mod : 1;     }   }   void fft(int a[], int n, bool flag = false) {     fft_init(n);     for (int i = 1; i < n - 1; ++i)       if (i < r[i]) std::swap(a[i], a[r[i]]);     for (int h = 1; h < n; h <<= 1)       for (int i = 0; i < n; i += h << 1)         for (int j = 0; j < h; ++j) {           int v = 1LL * a[i + h + j] * w[h + j] % mod;           a[i + h + j] = a[i + j] - v >= 0 ? a[i + j] - v : a[i + j] + mod - v;           a[i + j] = a[i + j] + v < mod ? a[i + j] + v : a[i + j] + v - mod;         }     if (flag) {       std::reverse(a + 1, a + n);       int in = qpow(n, mod - 2);       for (int i = 0; i < (int)(n); ++i) a[i] = 1LL * a[i] * in % mod;     }   }   struct poly : std::vector<int> {     poly(int n, int x = 0) { assign(n, x); }     poly(std::initializer_list<int> l) {       clear();       for (int x : l) push_back(x);     }     friend inline poly operator*(const poly &a, const poly &b) {       int sz = 1;       while (sz < (int)a.size() + (int)b.size() - 1) sz <<= 1;       static int A[mxn], B[mxn];       for (int i = 0; i < (int)(sz); ++i) A[i] = i < (int)a.size() ? a[i] : 0;       for (int i = 0; i < (int)(sz); ++i) B[i] = i < (int)b.size() ? b[i] : 0;       fft(A, sz), fft(B, sz);       for (int i = 0; i < (int)(sz); ++i) A[i] = 1LL * A[i] * B[i] % mod;       fft(A, sz, true);       poly c(a.size() + b.size() - 1);       for (int i = 0; i < (int)(c.size()); ++i) c[i] = A[i];       return c;     }   };   int n;   int deg[mxn];   int fac[mxn];   poly calc(int l, int r) {     if (l + 1 == r) return {1, deg[l]};     int m = (l + r) >> 1;     return calc(l, m) * calc(m, r);   }   int main() {     for (int i = 0; i < (int)(mxn); ++i)       fac[i] = i ? 1LL * i * fac[i - 1] % mod : 1;     scanf( %d , &n);     for (int i = 0; i < (int)(n - 1); ++i) {       int u, v;       scanf( %d %d , &u, &v);       --u, --v;       ++deg[u];       ++deg[v];     }     for (int i = 0; i < (int)(n); ++i)       if (i) --deg[i];     poly p = calc(0, n);     int ans = 0;     for (int i = 0; i < (int)(p.size()); ++i) {       int cur = 1LL * p[i] * fac[n - i] % mod;       if (i & 1)         ans = (ans + mod - cur) % mod;       else         ans = (ans + cur) % mod;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 40;   long long int dp[maxn][maxn], P[maxn], par[maxn][maxn];   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     P[0] = 1;     for (int i = 1; i < maxn; i++) P[i] = P[i - 1] * 10;     cin >> s >> s;     for (int i = ((int)(s).size()) - 1; i >= 0; i--) {       for (int j = 0; j <= ((int)(s).size()) - i; j++) {         long long int pnt1, pnt2;         if (j == 0)           dp[i][j] = dp[i + 1][j] + (s[i] -  0 ) * P[((int)(s).size()) - i - 1],           par[i][j] = j;         else if (j == ((int)(s).size()) - i)           dp[i][j] = dp[i + 1][j - 1] + (s[i] -  0 ) * P[j - 1],           par[i][j] = j - 1;         else if ((pnt1 = dp[i + 1][j - 1] + (s[i] -  0 ) * P[j - 1]) >                  (pnt2 = dp[i + 1][j] +                          (s[i] -  0 ) * P[((int)(s).size()) - i - j - 1]))           dp[i][j] = pnt1, par[i][j] = j - 1;         else           dp[i][j] = pnt2, par[i][j] = j;       }     }     int row = 0, col = ((int)(s).size()) / 2;     while (row < ((int)(s).size())) {       if (par[row][col] == col)         cout <<  H ;       else         cout <<  M ;       col = par[row][col];       row++;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   int b[5005], cnt, pr[800], f[800][5001], n, at[5005], sum[800][5001];   long long ans;   int ss[5005], tmp[5005], sa, st;   int main() {     for (int i = 2; i <= 5000; i++) {       if (b[i]) continue;       for (int j = 2; j * i <= 5000; j++) b[i * j] = 1;     }     for (int i = 2; i <= 5000; i++)       if (b[i] == 0) pr[++cnt] = i;     for (int i = 1; i <= cnt; i++) {       for (int j = 1; j <= 5000; j++) {         if (j >= pr[i]) f[i][j] = j / pr[i] + f[i][j / pr[i]];         sum[i][j] = sum[i - 1][j] + f[i][j];       }     }     scanf( %d , &n);     for (int i = 1, x; i <= n; i++) {       scanf( %d , &x);       if (x == 0) x = 1;       ++at[x];       ans += sum[cnt][x];     }     for (int i = 1; i <= 5000; i++)       if (at[i]) ss[++sa] = i;     for (int i = cnt; i >= 1;) {       int s = 0, minn = 0x7fffffff;       st = 0;       for (int j = 1, a; j <= sa; j++) {         a = ss[j];         if (f[i][a]) s += at[a], minn = min(minn, f[i][a]);       }       if (s > n - s) {         ans -= 1ll * minn * (s - n + s);         for (int j = 1, a; j <= sa; j++) {           a = ss[j];           if (f[i][a]) f[i][a] -= minn, tmp[++st] = a;         }         for (int i = 1; i <= st; i++) ss[i] = tmp[i];         sa = st;       } else if (n - s > s) {         for (int j = 1, a; j <= sa; j++) {           a = ss[j];           if (!f[i][a]) tmp[++st] = a;         }         for (int i = 1; i <= st; i++) ss[i] = tmp[i];         sa = st;         --i;       } else {         break;       }     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 200100;   long long b[M];   long long fre[M];   int main() {     long long n;     cin >> n;     vector<long long> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       b[a[i]]++;       fre[b[a[i]]]++;     }     long long q;     cin >> q;     while (q--) {       char s;       long long x;       cin >> s >> x;       if (s ==  + ) {         b[x]++;         fre[b[x]]++;       } else {         assert(b[x] > 0);         fre[b[x]]--;         b[x]--;       }       if ((fre[8] > 0) || (fre[4] >= 2) || (fre[2] >= 2 && fre[6] > 0) ||           (fre[2] >= 3 && fre[4] > 0))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   #define int long long int   const int INF = 1e9 + 7;   using namespace std;   const int m = 1e9 + 7;      signed main()   {    ios_base::sync_with_stdio(false);    cin.tie(0);    int t;    cin >> t;    while (t--)    {     int n;     cin >> n;     string a[n], b[n];     for (int i = 0; i < n; i++)      cin >> a[i];     for (int i = 0; i < n; i++)      cin >> b[i];     for (int j = 0; j < n; j++)     {      if (a[0][j] != b[0][j])      {       for (int i = 0; i < n; i++)       {        a[i][j] ^= 1;       }      }     }     for (int i = 1; i < n; i++)     {      for (int j = 1; j < n; j++)      {       if (a[i][j] != b[i][j])       {        for (int j = 0; j < n; j++)         a[i][j] ^= 1;       }      }     }     bool ans = true;     for (int i = 0; i < n; i++)     {      for (int j = 0; j < n; j++)       if (a[i][j] != b[i][j])       {        ans = false;        break;       }      if (ans == false)       break;     }     if (ans)      cout <<  YES n ;     else      cout <<  NO n ;    }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxlen = 81;   char s[maxlen];   int base;   long long int greedy(int r) {     if (!r) return 0;     int l = r;     long long val = 0, t = 1;     for (int i = r; i >= 1 && t < base; --i, t *= 10)       if (val + (s[i] -  0 ) * t < base) {         val += (s[i] -  0 ) * t;         if (s[i] !=  0 ) l = i;       } else         break;     return greedy(l - 1) * base + val;   }   int main() {     scanf( %d%s , &base, s + 1);     cout << greedy(strlen(s + 1)) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 100000;   long long l[MX], a[MX + 1], mn[MX + 1];   char s[MX + 1];   int main() {     int n;     ignore = scanf( %d , &n);     for (int i = 0; i < n; i++) ignore = scanf( %lld , l + i);     ignore = scanf( %s , s);     long long e = 0, ans = 0;     for (int i = 0, p = 5; i < n; i++) {       a[i] = e;       if (s[i] ==  G ) {         ans += 5 * l[i];         e += l[i];       } else if (s[i] ==  W ) {         ans += 3 * l[i];         e += l[i];         p = 3;       } else {         long long f = min(l[i], e);         ans += l[i] + (l[i] - f) * p;         e -= f;       }       a[i + 1] = e;     }     auto opt = [&](char c, int t) {       mn[n] = a[n];       for (int i = n - 1; i >= 0; i--) mn[i] = min(mn[i + 1], a[i]);       long long delta = 0;       for (int i = 0; i < n; i++) {         if (s[i] == c) {           long long x = min(mn[i + 1] - delta, 2 * l[i]);           ans -= x * (t - 1) / 2;           delta += x;         }         a[i + 1] -= delta;       }     };     opt( G , 5);     opt( W , 3);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ax, ay, bx, by, tx, ty;   int n;   long long x[110000];   long long y[110000];   long double solve(int cnt) {     long double res = 0;     int p = 0;     long double v = sqrt((x[0] - ax) * (x[0] - ax) + (y[0] - ay) * (y[0] - ay)) -                     sqrt((x[0] - tx) * (x[0] - tx) + (y[0] - ty) * (y[0] - ty));     for (int i = 1; i < n; ++i) {       long double cur =           sqrt((x[i] - ax) * (x[i] - ax) + (y[i] - ay) * (y[i] - ay)) -           sqrt((x[i] - tx) * (x[i] - tx) + (y[i] - ty) * (y[i] - ty));       if (cur < v) v = cur, p = i;     }     res += v;     if (cnt == 1) return res;     int q = 0;     v = sqrt((x[0] - bx) * (x[0] - bx) + (y[0] - by) * (y[0] - by)) -         sqrt((x[0] - tx) * (x[0] - tx) + (y[0] - ty) * (y[0] - ty));     for (int i = 1; i < n; ++i) {       if (i == p) continue;       long double cur =           sqrt((x[i] - bx) * (x[i] - bx) + (y[i] - by) * (y[i] - by)) -           sqrt((x[i] - tx) * (x[i] - tx) + (y[i] - ty) * (y[i] - ty));       if (cur < v || p == q) v = cur, q = i;     }     res += v;     return res;   }   int main() {     ios::sync_with_stdio(0);     cin >> ax >> ay >> bx >> by >> tx >> ty;     cin >> n;     for (int i = 0; i < n; ++i) cin >> x[i] >> y[i];     if (n == 1) {       long double v = sqrt((x[0] - tx) * (x[0] - tx) + (y[0] - ty) * (y[0] - ty));       cout << setprecision(10) << fixed            << min(sqrt((x[0] - ax) * (x[0] - ax) + (y[0] - ay) * (y[0] - ay)),                   sqrt((x[0] - bx) * (x[0] - bx) + (y[0] - by) * (y[0] - by))) +                   v            <<   n ;       return 0;     }     long double ans = 0;     for (int i = 0; i < n; ++i)       ans += 2.0 * sqrt((x[i] - tx) * (x[i] - tx) + (y[i] - ty) * (y[i] - ty));     long double res = ans + solve(1);     res = min(res, ans + solve(2));     swap(ax, bx);     swap(ay, by);     res = min(res, ans + solve(1));     res = min(res, ans + solve(2));     cout << setprecision(10) << fixed << res <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     int result = a;     int temp = 0;     while ((a + temp) >= b) {       int t1 = temp;       result += (a + temp) / b;       temp = (a + temp) % b;       a = (a + t1) / b;     }     cout << result << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   struct node {     int x, h;     int num;     int ans;   };   node a[maxn];   int ans[maxn];   stack<int> s;   int n;   void init() {     cin >> n;     for (int i = 1; i <= n; i++) {       a[i].num = i;       cin >> a[i].x >> a[i].h;     }   }   bool cmp1(const node &a, const node &b) { return a.x < b.x; }   bool cmp2(const node &a, const node &b) { return a.num < b.num; }   void solve() {     s.push(n);     a[n].ans = 1;     for (int i = n - 1; i >= 1; i--) {       int j = i;       while (!s.empty() && a[i].x + a[i].h > a[s.top()].x) {         j = s.top();         s.pop();       }       s.push(i);       if (j == i)         a[i].ans = 1;       else         a[i].ans = j - i + a[j].ans;     }     sort(a + 1, a + 1 + n, cmp2);     for (int i = 1; i < n; i++) cout << a[i].ans <<    ;     cout << a[n].ans << endl;   }   int main() {     init();     sort(a + 1, a + 1 + n, cmp1);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 50;   const int X = 1024;   int n, k, x;   int arr[N];   int freq[X], freq2[X];   inline void brute() {     int seen_till = 0;     for (int i = 0; i < X; i++) {       if (freq[i] != 0) {         if (!seen_till) {           int dec = (freq[i] + 1) / 2;           freq2[i ^ x] += dec;           freq2[i] += (freq[i] - dec);         } else {           int dec = (freq[i]) / 2;           freq2[i ^ x] += dec;           freq2[i] += (freq[i] - dec);         }       }       seen_till += freq[i];       seen_till %= 2;     }     for (int i = 0; i < X; i++) {       freq[i] = freq2[i];     }     memset(freq2, 0, sizeof freq2);   }   int main() {     ios ::sync_with_stdio(false);     cin >> n >> k >> x;     for (int i = 1; i <= n; i++) {       cin >> arr[i];       freq[arr[i]]++;     }     while (k--) {       brute();     }     int mn = 1e9, mx = -1;     for (int i = 0; i < X; i++) {       if (freq[i] != 0) {         if (i < mn) mn = i;         if (i > mx) mx = i;       }     }     cout << mx <<     << mn << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, OO = 1e8;   int dp[100001];   int solve(int x) {     if (x <= 0 || x > 1e5) return OO;     if (x == m) return 0;     int &ret = dp[x];     if (ret != -1) return ret;     ret = OO;     if (x > m)       ret = min(ret, 1 + solve(x - 1));     else {       ret = min(ret, 1 + solve(x * 2));       ret = min(ret, 1 + solve(x - 1));     }     return ret;   }   int main() {     cin >> n >> m;     memset(dp, -1, sizeof(dp));     cout << solve(n) << endl;     return 0;   }