malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n;   double first[10005], second[10005], w, u, v;   double eps = 1e-9;   signed main() {     ios::sync_with_stdio(0);     cin.tie(NULL), cout.tie(NULL);     cin >> n >> w >> u >> v;     for (int i = 0; i < n; i++) cin >> first[i] >> second[i];     double ans = w / v;     int fl = 0;     for (int i = 0; i < n; i++) {       if (first[i] > eps) fl = 1;     }     if (!fl) {       cout << fixed << setprecision(15) << ans;       return 0;     }     fl = 0;     for (int i = 0; i < n; i++) {       if (first[i] < eps) {         fl = 1;         break;       }       if (w - second[i] < eps) continue;       double ti = first[i] / u;       double hi = second[i] / v;       if (hi - ti < eps) continue;       fl = 1;       break;     }     if (!fl) {       cout << fixed << setprecision(15) << ans;       return 0;     }     for (int i = 0; i < n; i++) {       if (first[i] < eps) continue;       if (w - second[i] < eps) continue;       double j = first[i] / u;       if (second[i] - w > eps) continue;       double f = second[i] / v;       if (f - j > eps) j = f;       j += (w - second[i]) / v;       ans = max(ans, j);     }     cout << fixed << setprecision(15) << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[110];   bool a[10];   int main() {     int x, y, pow = 1, t, k, b = 0;     gets(s);     k = strlen(s);     for (int i = 0; i < k; i++) {       for (int j = 0; j < 8; j++) a[j] = 0;       x = (int)s[i];       for (int j = 0; j < 8; j++) {         if (x % 2 == 1)           a[j] = 1;         else           a[j] = 0;         x /= 2;       }       t = 0;       pow = 1;       for (int j = 7; j >= 0; j--) {         t += pow * a[j];         pow *= 2;       }       y = (256 - t + b) % 256;       b = t;       cout << y << endl;     }     scanf(   );   }
#include <bits/stdc++.h>   using namespace std;   int n;   int pow2[50];   int l[50];   int level(long long p) {     long long comp = 1;     int ans = 0;     while (comp <= p) {       comp <<= 1;       ans++;     }     return ans - 1;   }   bool ispow2(long long p) {     long long comp = 1;     while (comp < p) {       comp <<= 1;     }     return comp == p;   }   bool viable(int cnt) {     int le[50];     for (int i = 0; i < 50; i++) le[i] = l[i];     int slot[50];     for (int i = 0; i < 50; i++) slot[i] = 0;     for (int i = 0; i < 50; i++) {       if (i == 0) {         if (pow2[i] > cnt) {           slot[i] = cnt;           le[i] += pow2[i] - cnt;         } else {           slot[i] = pow2[i];         }       } else {         if (pow2[i] > slot[i - 1]) {           slot[i] = slot[i - 1];           le[i] += pow2[i] - slot[i];         } else {           slot[i] = pow2[i];         }       }     }     int sum = 0;     for (int i = 49; i >= 0; i--) {       sum += le[i];       if (sum > slot[i]) return false;     }     return true;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       long long a;       cin >> a;       if (ispow2(a))         pow2[level(a)]++;       else         l[level(a)]++;     }     if (!viable(pow2[0])) {       cout << -1 << endl;       return 0;     }     int ansl = pow2[0];     while (ansl > 1 && viable(ansl - 1)) ansl--;     for (int i = ansl; i <= pow2[0]; i++) {       if (viable(i)) cout << i <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int K = 103, N = 30005;   double f[K], sum[K];   double pr[N][K];   double mem[N][K];   int main() {     string s;     cin >> s;     int n, H;     cin >> n >> H;     H++;     if (s ==  Bob ) {       cout << n << endl;       return 0;     }     for (int i = 1; i <= H; i++) {       if (i == H)         f[i] = pow(2, -(i - 1));       else         f[i] = pow(2, -i);       sum[i] = sum[i - 1] + f[i];     }     for (int i = 1; i <= n; i++)       for (int t = 1; t <= H; t++)         mem[i][t] = pow(sum[t], i - 1) - pow(sum[t - 1], i - 1);     memset(pr, 0, sizeof pr);     pr[1][0] = 1;     for (int i = 2; i <= n; i++) {       for (int h = 1; h <= H; h++) {         double leftbigger = 1 - pow(sum[h], i - 1);         double rightbigger = 1 - pow(sum[h], n - i);         double skipped = leftbigger * rightbigger;         double dd = skipped * f[h];         pr[i][0] += dd;         double sm = dd;         for (int t = 1; t < h; t++) {           double left = mem[i][t];           pr[i][t] += left * f[h];           sm += left * f[h];         }         pr[i][h] += f[h] - sm;       }     }     double ans = 1;     for (int i = 1; i <= n; i++)       for (int h = 1; h <= H; h++) ans += pr[i][h] * pow(2, h - 1);     cout << setprecision(15) << ans << endl;   }
#include <bits/stdc++.h>   int p[100100];   void solve(int n, int m) {     int i, j, k, x, s = 0, l = 0, r = n;     for (i = 0; i < 100100; i++) p[i] = 0;     for (i = 0; i <= n; i++) p[i] = i;     for (k = 0; k < m; k++) {       scanf( %d , &x);       if (x == 1) {         scanf( %d , &x);         if (s == 0) {           if (2 * x <= r - l) {             for (i = l + x; i <= l + 2 * x; i++)               p[i] = p[i] - p[2 * l + 2 * x - i];             l += x;           } else {             for (i = l + x; i >= 2 * l + 2 * x - r; i--)               p[i] = p[i] + n - p[2 * l + 2 * x - i];             r -= r - l - x;             s = 1;           }         } else {           if (2 * x <= r - l) {             x = r - l - x;             for (i = l + x; i >= 2 * l + 2 * x - r; i--)               p[i] = p[i] + n - p[2 * l + 2 * x - i];             r -= r - l - x;           } else {             x = r - l - x;             for (i = l + x; i <= l + 2 * x; i++)               p[i] = p[i] - p[2 * l + 2 * x - i];             l += x;             s = 0;           }         }       } else {         scanf( %d%d , &i, &j);         if (s == 0) {           printf( %d n , p[j + l] - p[i + l]);         } else {           printf( %d n , p[r - i] - p[r - j]);         }       }     }   }   int main() {   #pragma comment(linker,  /STACK:134217728 )     int n, m;     while (scanf( %d%d , &n, &m) != EOF) {       solve(n, m);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000 )   #pragma GCC ostarimize( O500 )   using namespace std;   const bool db = false;   set<pair<int, int>> s;   int a[200100];   int main() {     int n, k, q;     scanf( %d %d %d n , &n, &k, &q);     for (int i = 1; i <= n; i++) scanf( %d  , &a[i]);     scanf(  n );     int type, num;     set<pair<int, int>>::iterator it;     while (q--) {       scanf( %d %d n , &type, &num);       if (type == 1) {         s.insert({-a[num], num});         if (s.size() > k) {           it = s.end();           it--;           s.erase(it);         }       } else {         if (s.count({-a[num], num}))           puts( YES );         else           puts( NO );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Point {     long long x, y;     int id;     Point() {}     Point(long long a, long long b, int c) : x(a), y(b), id(c) {}     Point operator-(Point b) { return Point(x - b.x, y - b.y, 0); }     bool operator<(const Point &b) const {       return (x != b.x) ? x < b.x : y < b.y;     }   };   long long cross(Point x, Point y) { return x.x * y.y - x.y * y.x; }   bool in[2005];   int gethull(Point *p, int n, int s, bool v) {     static Point st[2005], hull[2005];     int top = 0, cnt = 0;     for (int i = 1; i <= n; i++) {       while (top > 1 && cross(p[i] - st[top], st[top] - st[top - 1]) >= 0) top--;       st[++top] = p[i];     }     for (int i = 1; i < top; i++) hull[++cnt] = st[i];     top = 0;     for (int i = 1; i <= n; i++) {       while (top > 1 && cross(p[i] - st[top], st[top] - st[top - 1]) <= 0) top--;       st[++top] = p[i];     }     for (int i = top; i > 1; i--) hull[++cnt] = st[i];     for (int i = 1; i <= cnt; i++)       if (hull[i].id == s) {         in[hull[i].id] = 1;         return (v) ? hull[(i - 1 + cnt - 1) % cnt + 1].id : hull[i % cnt + 1].id;       }   }   Point p[2005], q[2005];   char str[2005];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x, y;       scanf( %d%d , &x, &y);       p[i] = Point(x, y, i);     }     scanf( %s , str + 1);     str[n - 1] =  L ;     sort(p + 1, p + n + 1);     int cur = p[1].id;     for (int i = 1; i < n; i++) {       int cnt = 0;       for (int j = 1; j <= n; j++)         if (!in[p[j].id]) q[++cnt] = p[j];       printf( %d  , cur);       cur = gethull(q, cnt, cur, (str[i] ==  R ));     }     printf( %d n , cur);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int N = 1e6 + 5;   int n, m, k;   bool vis[N];   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> k;     int h;     for (int i = 1; i <= m; i++) {       cin >> h;       vis[h] = 1;     }     bool fg = 0;     int bone = 1;     if (vis[bone]) fg = 1;     for (int i = 1; i <= k; i++) {       int u, v;       cin >> u >> v;       if ((u == bone || v == bone) && !fg) {         bone = (bone == u) ? v : u;         if (vis[bone]) fg = 1;       }     }     cout << bone << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MIN = numeric_limits<long long>::min();   class WindowHeap {    public:     WindowHeap() {}     long long top() {       if (_i >= _h.size()) return MIN;       return _h[_i].first;     }     void erase(int idx) {       if (!_h.empty() && _h[_i].second == idx) ++_i;     }     void insert(long long val, int idx) {       if (val == MIN) return;       while (!_h.empty() && val > _h.rbegin()->first) _h.pop_back();       if (_h.empty() || val < _h.rbegin()->first)         _h.emplace_back(val, idx);       else         _h.rbegin()->second = idx;       if (_i >= _h.size()) _i = _h.size() - 1;     }       private:     vector<pair<long long, int>> _h;     size_t _i;   };   int main() {     int n, k, x;     cin >> n >> k >> x;     vector<int> a(n);     for (int& ai : a) cin >> ai;     vector<long long> dp(n + 1, MIN);     dp[0] = 0;     for (int xi = 0; xi < x; ++xi) {       WindowHeap wh;       for (int i = n - 1; i > max(n - k, -1); --i) {         wh.insert(dp[i], i);       }       for (int i = n; i > xi; --i) {         if (i - k >= 0) wh.insert(dp[i - k], i - k);         long long p = wh.top();         if (p > MIN) dp[i] = p + a[i - 1];         wh.erase(i - 1);       }       dp[xi] = MIN;     }     long long best = -1;     for (int i = n; i > n - k; --i) best = max(best, dp[i]);     cout << best << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   vector<int> v[100000];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     map<int, int> m;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       for (int j = 2; j <= sqrt(a); j++) {         if (a % j == 0) {           m[j]++;           while (a % j == 0) a /= j;         }       }       if (a != 1) m[a]++;     }     int ans = 1;     for (auto i : m) ans = max(ans, i.second);     cout << ans;     return 0;   }
#include <iostream>   #include <queue>   #include <algorithm>   #include <cstring>   #include <cmath>   #include <vector>   using namespace std;   typedef long long LL;   const LL mod = 1e9 + 7;   const int N = 1e6 + 10;      LL l[N], r[N];   LL c[N], a[N], b[N];   int main()   {    int T;cin >> T;    while (T--)    {     int n;     cin >> n;     for (int i = 1; i <= n; i++)scanf( %lld ,&c[i]);     for (int i = 1; i <= n; i++)scanf( %lld , &a[i]);     for (int i = 1; i <= n; i++)scanf( %lld , &b[i]);        LL res = 0;     for (int i = 1; i < n;i++)     {      LL t = abs(a[i+1] - b[i+1]);      LL t2 = abs(a[i + 1] - b[i + 1]);            l[i] =t+1;      if (a[i+1] != b[i+1]&&i>1)       l[i] = max(l[i], l[i - 1] + c[i] - t + 1);      res = max(res, l[i] + c[i + 1]);           }        cout << res << endl;    }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 20;   const int V = (1 << 20) + 10;   const int P = 1000000007;   int Pow(int x, int y) {     int ret = 1;     while (y) {       if (y & 1) ret = (long long)ret * x % P;       x = (long long)x * x % P;       y /= 2;     }     return ret;   }   void utf(int *a, int l, int r) {     if (l + 1 != r) {       int mid = (l + r) / 2;       for (int i = 0; i < mid - l; i++) {         a[l + i] -= a[mid + i];         if (a[l + i] < 0) a[l + i] += P;       }       utf(a, l, mid);       utf(a, mid, r);     }   }   void tf(int *a, int l, int r) {     if (l + 1 != r) {       int mid = (l + r) / 2;       tf(a, l, mid);       tf(a, mid, r);       for (int i = 0; i < mid - l; i++) {         if (((l + i) & (mid + i)) != (l + i))           while (1)             ;         a[l + i] += a[mid + i];         if (a[l + i] >= P) a[i + l] -= P;       }     }   }   int cnt[V], q[V];   int n, x, pro[V];   int pt[V];   int main() {     pt[0] = 1;     for (int i = 1; i < (1 << N); i++) pt[i] = pt[i - 1] * 2 % P;     while (~scanf( %d , &n)) {       memset(cnt, 0, sizeof(cnt));       for (int i = 0; i < n; i++) {         scanf( %d , &x);         cnt[x]++;       }       tf(cnt, 0, (1 << N));       for (int i = 0; i < (1 << N); i++) pro[i] = pt[cnt[i]];       utf(pro, 0, (1 << N));       printf( %d n , pro[0]);     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, i, j, ans = 0;     char c[101];     scanf( %d , &n);     scanf( %s , c);     int l;     for (l = 1; l <= n; l++) {       for (i = 0; i < n - 4 * l; i++) {         if (c[i] ==  *  && c[i + l] ==  *  && c[i + 2 * l] ==  *  &&             c[i + 3 * l] ==  *  && c[i + 4 * l] ==  * ) {           ans = 1;           break;         }       }       if (ans == 1) break;     }     if (ans == 1)       printf( yes n );     else       printf( no n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, l, r, k, i, ans;   int main() {     scanf( %I64d%I64d%I64d%I64d , &n, &l, &r, &k);     r = (r + n - l + 1) % n;     if (k < r) {       printf( -1 );       return 0;     }     if (2 * r >= k) {       ans = min(k + n - r * 2 + 1, n);       if (ans >= k - r) {         printf( %I64d , ans);         return 0;       }     }     for (i = 1; i <= k; i++) {       l = max((k - n * i - r - 1) / (i + 1), (k - n * i - r * 2 - 1) / i) + 1;       ans = min(min((k - n * (i - 1) - r * 2 + 1) / (i + 1), (k - n * i - r) / i),                 n);       if (ans >= l) {         printf( %I64d , ans);         return 0;       }       if (i * i >= k) break;     }     i = min(i, n);     for (; i >= 0; i--) {       l = k % (n + i) - r;       if ((l <= min(i, r)) && (l >= max(i + r - n - 1, 0ll))) {         if (n + i >= k)           printf( %I64d , min(i + 1, n));         else           printf( %I64d , i);         return 0;       }     }     printf( -1 );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int count = 2;       while (n % ((1 << count) - 1) != 0) {         count++;       }       cout << n / ((1 << count) - 1) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<long long, string> mp;   long long n;   int main() {     scanf( %I64d , &n);     for (long long i = 2; i * i <= n; i++) {       for (long long j = i * i, k = 2; j <= n; j *= i, k++) {         string tmp = to_string(i) +  ^  + to_string(k);         if (!mp.count(j)) mp[j] = to_string(j);         if (tmp.size() < mp[j].size()) mp[j] = tmp;       }     }     string ans = to_string(n);     for (auto x : mp) {       string tmp =   ;       long long k = n / x.first, b = n % x.first;       if (k > 1) tmp = (mp.count(k) ? mp[k] : to_string(k)) +  * ;       tmp += x.second;       if (b) tmp +=  +  + (mp.count(b) ? mp[b] : to_string(b));       if (tmp.size() < ans.size()) ans = tmp;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char ch[100010];   int flag[26];   int main() {     while (~scanf( %s , ch)) {       memset(flag, 0, sizeof(flag));       flag[0] = 1;       flag[ H  -  A ] = 1;       flag[ I  -  A ] = 1;       flag[ M  -  A ] = 1;       flag[ O  -  A ] = 1;       flag[ T  -  A ] = 1;       flag[ U  -  A ] = 1;       flag[ V  -  A ] = 1;       flag[ W  -  A ] = 1;       flag[ X  -  A ] = 1;       flag[ Y  -  A ] = 1;       int len = strlen(ch);       int flag1 = 0;       for (int i = 0; i < len; i++) {         if (!flag[ch[i] -  A ]) {           flag1 = 1;           break;         }       }       if (flag1) {         printf( NO n );       } else {         string str;         str = ch;         reverse(str.begin(), str.end());         for (int i = 0; i < len; i++) {           if (str[i] != ch[i]) {             flag1 = 1;             break;           }         }         if (flag1) {           printf( NO n );         } else {           printf( YES n );         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   const mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());   const int MOD = 998244353;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       vector<int> a(n);       for (int &i : a) cin >> i;       map<int, int> pos;       for (int i = 0; i < n; i++) pos[a[i]] = i;       vector<int> b(k);       for (int &i : b) cin >> i;       long long ans = 1;       set<int> sb(b.begin(), b.end());       for (int i : b) {         int p = pos[i];         long long nxt = 0;         if (p != 0) {           int vl = a[p - 1];           if (sb.count(vl) == 0) nxt += ans;         }         if (p != n - 1) {           int vr = a[p + 1];           if (sb.count(vr) == 0) nxt += ans;         }         sb.erase(i);         if (nxt >= MOD) nxt -= MOD;         ans = nxt;       }       cout << ans <<   n ;     }     exit(0);   }
#include <bits/stdc++.h>   using namespace std;   bool solve(int x) {     if (x == 0) return true;     if (x % 1000 == 144) {       return solve(x / 1000);     } else if (x % 100 == 14) {       return solve(x / 100);     } else if (x % 10 == 1) {       return solve(x / 10);     }     return false;   }   int main() {     int x;     cin >> x;     if (solve(x))       cout <<  YES n ;     else       cout <<  NO n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n;     cin >> n;     map<double, int> mp2;     map<string, double> mp1;     vector<string> S;     while (n--) {       string x;       cin >> x;       S.push_back(x);       int plus = 0, end = 0;       double a, b, c;       for (int i = 1; i < x.size(); i++) {         if (x[i] ==  + ) plus = i;         if (x[i] ==  ) ) end = i;       }       a = stod(x.substr(1, plus - 1));       b = stod(x.substr(plus + 1, end - plus - 1));       c = stod(x.substr(end + 2, x.size() - end + 2));       mp1[x] = (a + b) / c;       mp2[(a + b) / c]++;     }     for (auto i : S) {       cout << mp2[mp1[i]] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     std::ios_base::sync_with_stdio(false);     std::cout.tie(nullptr);     std::cin.tie(nullptr);     std::cerr.tie(nullptr);     int64_t n, k;     std::cin >> n >> k;     if (k == 1) std::cout <<  1 n ;     if (k == 2) {       int64_t res = (n * (n - 1)) / 2 + 1;       std::cout << res <<   n ;     }     if (k == 3) {       int64_t res = (n * (n - 1) * (n - 2)) / 3 + (n * (n - 1)) / 2 + 1;       std::cout << res <<   n ;     }     if (k == 4) {       int64_t res = (n * (n - 1) * (n - 2)) / 3 + (n * (n - 1)) / 2 +                     9 * (n * (n - 1) * (n - 2) * (n - 3)) / 24 + 1;       std::cout << res <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   ,  ;     __f(comma + 1, args...);   }   const int N = 1e3 + 10;   vector<vector<int>> g;   vector<int> par, height;   int n;   int bfs(int root) {     int last = root;     par[root] = -1;     height[root] = 0;     queue<int> q;     q.push(root);     while (!q.empty()) {       int u = q.front();       q.pop();       last = u;       for (auto v : g[u])         if (v != par[u]) {           par[v] = u;           height[v] = height[u] + 1;           q.push(v);         }     }     return last;   }   void dfs(int u, int par, int tar) {     for (int v : g[u])       if (v != par) {         if (v == tar) {           g[u].erase(find(g[u].begin(), g[u].end(), v));           g[v].erase(find(g[v].begin(), g[v].end(), u));         } else           dfs(v, u, tar);       }   }   int main() {     int i, j, k, n, m;     cin >> n;     g.resize(n);     par.resize(n);     height.resize(n);     for (i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       u--, v--;       g[u].push_back(v);       g[v].push_back(u);     }     int x, y, q;     x = bfs(0);     y = bfs(x);     cout <<  ?   << x + 1 <<     << y + 1 << endl;     cin >> q;     q--;     while (1) {       dfs(x, -1, q);       dfs(y, -1, q);       if (g[q].size() == 0) {         cout <<  !   << q + 1 << endl;         return 0;       };       x = bfs(q);       y = bfs(x);       cout <<  ?   << x + 1 <<     << y + 1 << endl;       cin >> q;       q--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 96;   const int MAXN = 1e6 + 5;   const int MAXK = 8e6 + 5;   const int MOD = 1e9 + 7;   const int MAX_ASCII_CODE = 26;   const int MAX_NUMBER_OF_NODES = 1e5 + 5;   int n, m;   int arr[MAXN];   int rea[MAXK];   int foo(int v) {     if (v == 0) return -2;     if (rea[v] != -1) return rea[v];     if (rea[v] == -2) return -2;     int ho = -2;     for (int i = (int)0; i < (int)(22); i++) {       if ((v & (1 << i)) > 0) {         ho = max(foo((v ^ (1 << i))), ho);       }     }     rea[v] = ho;     return rea[v];   }   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(NULL);     cout << fixed << setprecision(11);     int t = 1;     while (t--) {       cin >> n;       memset(rea, -1, sizeof(rea));       for (int i = (int)0; i < (int)(n); i++) {         cin >> arr[i];         rea[arr[i]] = arr[i];       }       int t;       int no = (1 << 22) - 1;       for (int i = (int)0; i < (int)(n); i++) {         t = arr[i];         t = (no ^ arr[i]);         cout << max(-1, foo(t)) <<    ;       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int N = 100000 + 100;   const int inf = 0x7fffffff;   int n, a, b, c;   int f[N];   int main() {     scanf( %d%d%d%d , &n, &a, &b, &c);     f[a] = 1;     f[b] = 1;     f[c] = 1;     for (int i = min(a, min(b, c)); i <= n; i++) {       if (f[i]) {         f[i + a] = max(f[i + a], f[i] + 1);         f[i + b] = max(f[i + b], f[i] + 1);         f[i + c] = max(f[i + c], f[i] + 1);       }     }     printf( %d n , f[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m, n, a[2000100], b[2000100], d[2000100], ans = 1, pos[2000100];   int between(int x, int y, int z) {     if (z < y) return x < z || x > y;     return x > y && x < z;   }   int main() {     memset(d, -1, sizeof(d));     cin >> m >> n;     for (int i = 0; i < m; i++) scanf( %d , &a[i]);     for (int i = 0; i < n; i++) scanf( %d , &b[i]), d[b[i]] = i;     int M = 0;     for (int i = 0; i < m; i++)       if (d[a[i]] >= 0) a[M] = a[i], pos[M++] = i;     swap(m, M);     if (!m) {       puts( 0 );       return 0;     }     for (int i = 0; i < m; i++) a[m + i] = a[i], pos[m + i] = pos[i] + M;     int x = 1, bor = 0;     for (int i = 1; i <= m * 2 - 1; i++)       if (pos[i] == pos[i - 1] + 1) {         x++;         while (x > 2 && !between(d[a[i]], d[a[i - 1]], d[a[bor]])) bor++, x--;         ans = max(ans, x);       } else         x = 1, bor = i;     cout << min(m, ans) << endl;   }