malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 105;   int M127;   string s;   int S, k, n;   int e[N][N];   int f[N][N][N];   int conv(char c) { return c -  a  + 1; }   int main() {     cin >> s;     S = s.size();     s =     + s;     memset(f, -127, sizeof(f));     M127 = f[0][0][0];     k = ({       long long first = 0;       int c = getchar(), n = 0;       for (; !isdigit(c); c = getchar()) n = (c ==  - );       for (; isdigit(c); c = getchar()) first = first * 10 + c -  0 ;       n ? -first : first;     });     n = ({       long long first = 0;       int c = getchar(), n = 0;       for (; !isdigit(c); c = getchar()) n = (c ==  - );       for (; isdigit(c); c = getchar()) first = first * 10 + c -  0 ;       n ? -first : first;     });     for (int i(1); i <= n; i++)       e[conv(({         char c = getchar();         while (c ==     || c ==   n ) c = getchar();         c;       }))][conv(({         char c = getchar();         while (c ==     || c ==   n ) c = getchar();         c;       }))] = ({         long long first = 0;         int c = getchar(), n = 0;         for (; !isdigit(c); c = getchar()) n = (c ==  - );         for (; isdigit(c); c = getchar()) first = first * 10 + c -  0 ;         n ? -first : first;       });     for (int i(1); i <= 26; i++) f[1][i][i != conv(s[1])] = 0;     for (int i(2); i <= S; i++)       for (int j(1); j <= 26; j++)         for (int kk(0); kk <= k; kk++) {           int ok = j != conv(s[i]);           if (kk < ok) continue;           for (int j2(1); j2 <= 26; j2++)             if (f[i - 1][j2][kk - ok] != M127)               f[i][j][kk] = max(f[i - 1][j2][kk - ok] + e[j2][j], f[i][j][kk]);         }     int res = M127;     for (int j(1); j <= 26; j++)       for (int kk(0); kk <= k; kk++) res = max(res, f[S][j][kk]);     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   long long int MOD = 1000000007;   void solve() {     int p, f;     cin >> p >> f;     if (f > p) swap(p, f);     int cs, cw;     cin >> cs >> cw;     int s, w;     cin >> s >> w;     if (w > s) {       swap(w, s);       swap(cs, cw);     }     int maxv = 0;     for (int x = 0; x <= min(cw, f / w); x++) {       int curr = x;       int fr = f - x * w;       int pr = p;       int csr = cs;       int cwr = cw - x;       int t = min(csr, fr / s);       curr += t;       csr -= t;       curr += min(cwr, pr / w);       pr -= min(cwr, pr / w) * w;       curr += min(csr, pr / s);       maxv = max(maxv, curr);     }     cout << maxv << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tt = 1;     cin >> tt;     for (int ttt = 1; ttt <= tt; ttt++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, n, m, l, a[100001], i, check, p, d;   bool b[100001];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> l;     t = 0;     fill(b + 1, b + 1 + n, false);     for (i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] > l) {         if (i - 1 == 0 || (i - 1 > 0 && b[i - 1] == false)) t++;         b[i] = true;       }     }     for (i = 1; i <= m; i++) {       cin >> check;       if (check == 0)         cout << t <<   n ;       else {         cin >> p >> d;         a[p] += d;         if (a[p] > l && b[p] == false) {           if (p > 1 && p < n) {             if (b[p - 1] == true && b[p + 1] == true) {               if (t > 1) t--;             } else if (b[p - 1] == false && b[p + 1] == false) {               if (t < n) t++;             }           } else if (p == 1) {             if (b[p + 1] == false) {               if (t < n) t++;             }           } else if (p == n) {             if (b[p - 1] == false) {               if (t < n) t++;             }           }           b[p] = true;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-6;   vector<int> mp[105], ans;   char s[105][105];   int len[105], tmp[30];   queue<int> q;   bool solve(int x, int y) {     for (int i = 0; i < len[x] && i < len[y]; i++) {       if (s[x][i] != s[y][i]) {         mp[s[x][i] -  a ].push_back(s[y][i] -  a );         tmp[s[y][i] -  a ]++;         return true;       }     }     if (len[x] > len[y]) return false;   }   bool ok() {     for (int i = 0; i < 26; i++)       if (tmp[i] == 0) {         ans.push_back(i);         q.push(i);       }     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < mp[u].size(); i++) {         int v = mp[u][i];         tmp[v]--;         if (tmp[v] == 0) {           q.push(v);           ans.push_back(v);         }       }     }     return ans.size() == 26;   }   int main() {     int n;     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; i++) {         scanf( %s , s[i]);         len[i] = strlen(s[i]);       }       bool flag = 0;       for (int i = 1; i <= n; i++)         for (int j = i + 1; j <= n; j++)           if (!solve(i, j)) flag = 1;       if ((!flag) && ok()) {         for (int i = 0; i < 26; i++) printf( %c , ans[i] +  a );         printf(  n );       } else         printf( Impossible n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double a, b, c, delta, x1, x2;     cin >> a >> b >> c;     delta = b * b - 4.0 * a * c;     delta = sqrt(delta);     x1 = (-b + delta) / (2.0 * a);     x2 = (-b - delta) / (2.0 * a);     if (x1 < x2) swap(x1, x2);     cout << fixed << setprecision(8) << x1 << endl          << fixed << setprecision(8) << x2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long gcd(unsigned long long a, unsigned long long b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   int main() {     unsigned long long n, m, k;     cin >> n >> m >> k;     unsigned long long h = 2 * n * m;     if (h % k == 0) {       cout <<  YES  << endl;       bool isKEven = false;       if (k % 2 == 0) {         isKEven = true;         k /= 2;       }       int y1 = 0, x2 = 0, x3 = 0, y3 = 0;       unsigned long long gx = gcd(n, k);       k /= gx;       unsigned long long x1 = n / gx;       unsigned long long gy = gcd(m, k);       k /= gy;       unsigned long long y2 = m / gy;       if (!isKEven) {         if (x1 < n) {           x1 *= 2;         } else {           y2 *= 2;         }       }       cout << x1 <<     << y1 << endl;       cout << x2 <<     << y2 << endl;       cout << x3 <<     << y3 << endl;     } else {       cout <<  NO ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d%d , &n, &m);     int c[n];     memset(c, 0, sizeof(c));     while (m--) {       int x, y = 0, p = 0;       for (int i = 0; i < n; i++) {         scanf( %d , &x);         if (x > y) {           y = x;           p = i;         }       }       c[p]++;     }     int y = 0, p;     for (int i = 0; i < n; i++) {       if (c[i] > y) {         y = c[i];         p = i;       }     }     printf( %d , p + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp(int a, int b, int row) {     if (row == 1 && a < 3 && b >= 3) {       return -1;     }     if (row == 0 && a < 3 && b >= 3) {       return 0;     }     if (row == 1 && a < 3 && b < 3) {       return 1;     }     if (row == 0 && a < 3 && b < 3) {       return 0;     }     if (row == 1 && a >= 3 && b >= 3) {       return 0;     }     if (row == 0 && a >= 3 && b >= 3) {       return 1;     }     if (row == 1 && a >= 3 && b < 3) {       return 1;     }     if (row == 0 && a >= 3 && b < 3) {       return -1;     } else {       return -1;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string arr, brr;       cin >> arr;       cin >> brr;       int x = dp(arr[0] -  0 , brr[0] -  0 , 0);       for (int i = 1; i < n; i++) {         x = dp(arr[i] -  0 , brr[i] -  0 , x);         if (x == -1) {           break;         }       }       if (x != 1) {         cout <<  NO  <<   n ;       } else {         cout <<  YES  <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   const long long linf = 1LL << 62;   const int mod = 1e9 + 7;   const int MAX = 510000;   const int V = 100005;   struct UnionFind {     vector<long long> p;     vector<long long> rank;     vector<long long> cnt;     UnionFind(long long n) {       rank.resize(n, 0);       p.resize(n, 0);       cnt.resize(n, 1);       for (long long i = 0; i < (n); i++) {         p[i] = i;         rank[i] = 0;         cnt[i] = 1;       }     }     long long find(long long x) {       if (x != p[x]) p[x] = find(p[x]);       return p[x];     }     bool same(long long x, long long y) { return find(x) == find(y); }     void unite(long long x, long long y) {       x = find(x);       y = find(y);       if (x == y) return;       if (rank[x] > rank[y]) {         p[y] = x;         cnt[x] += cnt[y];       } else {         p[x] = y;         cnt[y] += cnt[x];         if (rank[x] == rank[y]) rank[y]++;       }     }     long long getcnt(long long x) { return cnt[find(x)]; }   };   int main() {     long long q;     cin >> q;     while (q--) {       long long n;       cin >> n;       UnionFind uf(n);       for (long long i = 0; i < (n); i++) {         long long a;         cin >> a;         a--;         uf.unite(i, a);       }       for (long long i = 0; i < (n); i++) cout << uf.getcnt(i) <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int fx[] = {+1, -1, +0, +0}, fy[] = {+0, +0, +1, -1};   const long long mod = 1e9 + 7, INF = 1e18, mx = 1e6;   int Case = 1, cas = 0;   string S;   struct exo {     int Open, Close, SubLen;     exo() {}     exo(int a, int b, int c) { Open = a, Close = b, SubLen = c; }   } tree[3 * mx + 5];   exo Combine(exo p, exo q) {     int mn = min(p.Open, q.Close);     int a = p.Open + q.Open - mn;     int b = p.Close + q.Close - mn;     int c = p.SubLen + q.SubLen + 2 * mn;     return exo(a, b, c);   }   void build(int node, int L, int R) {     if (L > R) return;     if (L == R) {       if (S[L] ==  ( )         tree[node] = exo(1, 0, 0);       else         tree[node] = exo(0, 1, 0);       return;     }     int mid = (L + R) >> 1;     int Left = node << 1;     int Right = Left | 1;     build(Left, L, mid);     build(Right, mid + 1, R);     tree[node] = Combine(tree[Left], tree[Right]);   }   exo query(int node, int L, int R, int i, int j) {     if (i > R || j < L) return exo(0, 0, 0);     if (i <= L && R <= j) return tree[node];     int mid = (L + R) >> 1;     int Left = node << 1;     int Right = Left | 1;     exo p = query(Left, L, mid, i, j);     exo q = query(Right, mid + 1, R, i, j);     return Combine(p, q);   }   int main() {     ios_base ::sync_with_stdio(0), cin.tie(0);     ;     cin >> S;     int n = S.size();     build(1, 0, n - 1);     int Q;     cin >> Q;     while (Q--) {       int L, R;       cin >> L >> R;       L--, R--;       cout << query(1, 0, n - 1, L, R).SubLen << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, ans;   vector<int> v[100010];   int main() {     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       int x, y;       scanf( %d%d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= n; ++i) ans += v[i].size() % 2;     ans /= 2;     for (int i = 1; i <= n; ++i) {       if (v[i].size() != 2) continue;       int x = v[i][0], y = v[i][1];       if (x == y) {         v[x].clear();         ++ans;         continue;       }       v[x][v[x][1] == i] = y;       v[y][v[y][1] == i] = x;     }     cout << ans <<     << m << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s =   , s1 =   , tmp;     cin >> tmp;     s += tmp;     cin >> tmp;     reverse(tmp.begin(), tmp.end());     s += tmp;     cin >> tmp;     s1 += tmp;     cin >> tmp;     reverse(tmp.begin(), tmp.end());     s1 += tmp;     s.erase(s.find( X ), 1);     s1.erase(s1.find( X ), 1);     s += s;     int i = 0;     while (s[i] != s1[0]) i++;     if (s.substr(i, 3) == s1) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 150001;   int t[MAX_N];   int main() {     int n, k, q;     cin >> n >> k >> q;     for (int i = 0; i < n; ++i) {       cin >> t[i];     }     set<int> s;     for (int i = 0; i < q; ++i) {       int x, y;       cin >> x >> y;       if (x == 1) {         s.insert(-t[y - 1]);         if (s.size() > k) {           auto it = s.begin();           for (int j = 0; j < k; ++j) it++;           s.erase(it);         }       } else {         cout << (s.find(-t[y - 1]) == s.end() ?  NO  :  YES ) << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int v, w;   } a[100005];   bool cmp(node a, node b) { return a.v > b.v; }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d%d , &a[i].v, &a[i].w);     sort(a, a + n, cmp);     int ma = a[0].w;     for (int i = 1; i < n; i++) {       if (a[i].w > ma) {         printf( Happy Alex n );         return 0;       }       ma = min(ma, a[i].w);     }     printf( Poor Alex n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ll(long double x) { return x; }   int main() {     int n;     cin >> n;     while (n--) {       long long a, b;       cin >> a >> b;       if (ceil((2 * a - b) / 3.0) == floor((2 * a - b) / 3.0) and           ceil((2 * b - a) / 3.0) == floor((2 * b - a) / 3.0) and           ceil((2 * b - a) / 3.0) >= 0 and ((2 * a - b) / 3.0) >= 0)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   bool SR(int &x) { return scanf( %d , &x) == 1; }   bool SR(long long &x) { return scanf( %lld , &x) == 1; }   bool SR(double &x) { return scanf( %lf , &x) == 1; }   bool SR(char *s) { return scanf( %s , s) == 1; }   bool RI() { return true; }   template <typename I, typename... T>   bool RI(I &x, T &...tail) {     return SR(x) && RI(tail...);   }   void SP(const int x) { printf( %d , x); }   void SP(const long long x) { printf( %lld , x); }   void SP(const double x) { printf( %.16lf , x); }   void SP(const char *s) { printf( %s , s); }   void PL() { puts(  ); }   template <typename I, typename... T>   void PL(const I x, const T... tail) {     SP(x);     if (sizeof...(tail)) putchar(   );     PL(tail...);   }   const int maxn = 1e2 + 2;   vector<bool> a[maxn];   int n, m, k;   void read() {     RI(n, m, k);     for (int i = 0; i < int(n); i++) a[i].resize(m);     for (int i = 0; i < int(n); i++)       for (int j = 0; j < int(m); j++) {         int x;         RI(x);         a[i][j] = (x == 1);       }   }   void build() {}   int doo(const vector<bool> &v) {     int ans = 0;     for (int i = 0; i < int(n); i++) {       int c[2] = {0, 0};       for (int j = 0; j < int(m); j++) c[v[j] ^ a[i][j]]++;       ans += min(c[0], c[1]);     }     return ans;   }   void sol() {     int ans = k + 1;     if (n > 10) {       for (int i = 0; i < int(n); i++) ans = min(ans, doo(a[i]));     } else {       vector<bool> c[maxn];       for (int i = 0; i < int(m); i++) c[i].resize(n);       for (int i = 0; i < int(n); i++)         for (int j = 0; j < int(m); j++) c[j][i] = a[i][j];       swap(n, m);       for (int i = 0; i < int(n); i++) a[i] = c[i];       vector<bool> v(m);       for (int i = 0; i < int((1 << m)); i++) {         for (int j = 0; j < int(m); j++) v[j] = ((i >> j) & 1);         ans = min(ans, doo(v));       }     }     if (ans <= k)       PL(ans);     else       PL(-1);   }   int main() {     read();     build();     sol();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dx[] = {0, 0, 1, -1};   const int dy[] = {1, -1, 0, 0};   int s[505][505];   queue<pair<int, int> > q;   char c[505][505];   bitset<505> b[505];   int main(void) {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> (c[i] + 1);     int x1, y1, first, second;     cin >> first >> second >> x1 >> y1;     s[first][second] = 1;     q.push(make_pair(first, second));     while (q.size()) {       int k = q.front().first, l = q.front().second;       q.pop();       for (int p = 0; p < 4; ++p) {         int f = k + dx[p];         int g = l + dy[p];         if ((c[f][g] ==  . ) && !s[f][g])           s[f][g] = s[k][l] + 1, q.push(make_pair(f, g));       }     }     int p = 0, g = 0;     for (int l = 0; l < 4; ++l)       p += c[x1 + dx[l]][y1 + dy[l]] ==  . , g |= s[x1 + dx[l]][y1 + dy[l]];     if (c[x1][y1] ==  X ) return cout << (g ?  YES  :  NO ) <<   n , 0;     if (!s[x1][y1]) return cout <<  NO n , 0;     if (p > 1 || (abs(first - x1) + abs(second - y1) == 1 && p >= 1))       return cout <<  YES n , 0;     return cout <<  NO n , 0;   }
#include <bits/stdc++.h>   using ll = long long;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int t, n, x;     cin >> t;     int sum = 0;     int cnt = 0;     int item = 0;     int s = 0;     while (t--) {       cin >> n >> x;       cnt = 0;       s = 0;       for (int i = 0; i < n; ++i) {         cin >> item;         if (item == x) {           ++cnt;         }         s += item;         sum += (x - item);       }       if (cnt == n) {         cout << 0 <<   n ;       } else if (cnt > 0 or s == n * x or sum == 0) {         cout << 1 <<   n ;       } else {         cout << 2 <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[9], aa[9];   int c[9], cc[9];   int n;   int ans;   void dfs(int u, int cnt, int self) {     if (u == n) {       ans = min(ans, cnt + (self > 1));       return;     }     dfs(u + 1, cnt + cc[u] + (c[u] != 1), self + 1);     for (int i = u + 1; i < n; i++)       if (aa[i] % a[u] == 0) {         aa[i] /= a[u];         cc[i] -= c[u];         dfs(u + 1, cnt + cc[u] + (c[u] != 1), self);         aa[i] *= a[u];         cc[i] += c[u];       }   }   int main() {     int i, j;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %I64d , &a[i]);     sort(a, a + n);     for (i = 0; i < n; i++) {       long long x = a[i];       long long m = sqrt(x + 0.5);       for (j = 2; j <= m; j++)         while (x % j == 0) {           c[i]++;           x /= j;         }       if (x > 1) c[i]++;       aa[i] = a[i];       cc[i] = c[i];     }     ans = 1e9;     dfs(0, 0, 0);     printf( %d n , ans);     return 0;   }
#include<bits/stdc++.h>   #define pii pair<int,int>   #define fi first   #define sc second   #define pb push_back   #define ll long long   #define trav(v,x) for(auto v:x)   using namespace std;   const int N = 1e6 + 100;   const ll mod = 998244353;      int n, m, need;   int sa[N], rnk[N];   ll fac[N], ifac[N];      ll C(ll x, ll y)   {return 1LL * fac[x] * ifac[y] % mod * ifac[x - y] % mod;}      ll qpow(ll x, ll y = mod - 2)   {       ll res = 1;       while(y)       {           if(y & 1)res = res * x % mod;           x = x * x % mod, y >>= 1;       }       return res;   }      signed main()   {    ios::sync_with_stdio(0);    cin.tie(0);    cin >> n >> m;    for(int i = 1; i <= n; i++)           cin >> sa[i], ++sa[i], rnk[sa[i]] = i;       need = 1;       sa[n + 1] = 0;       for(int i = 2; i <= n; i++)       {           int bf_ps = sa[i - 1], nw_ps = sa[i];           if(rnk[bf_ps + 1] < rnk[nw_ps + 1]);           else ++need;       }       m -= need;    //   cerr << !!  << m <<   n ;       ll ans = 0;       fac[0] = 1;       for(int i = 1; i < N; i++)fac[i] = fac[i - 1] * i % mod;       ifac[N - 1] = qpow(fac[N - 1]);       for(int i = N - 2; i >= 0; i--)ifac[i] = ifac[i + 1] * (i + 1) % mod;       for(ll x = 0; x <= m; x++)           ans = (ans + C(x + n - 1, n - 1)) % mod;       cout << ans  <<   n ;    return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long g(long long n, long long m) {     long long ans = 0;     for (long long x = 1; x <= n; x++) {       long long minY = 5 - (x % 5);       if (minY <= m) ans += (m - minY) / 5 + 1;     }     return ans;   }   long long gs(long long n, long long m) {     long long ans = 0;     for (long long x = 1; x <= n; x++) {       for (long long y = 1; y <= m; y++) {         if ((x + y) % 5 == 0) ans++;       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     long long n, m;     cin >> n >> m;     cout << g(n, m) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 101;   int N, Q, freq[11];   char commands[MAXN], commands2[MAXN];   void solve(int l, int r) {     l--;     r--;     for (int i = 0; i < N; i++) commands2[i] = commands[i];     for (int i = 0; i < 10; i++) freq[i] = 0;     int cur = l;     int dir = 1;     int prev;     while (cur >= l && cur <= r) {       if (commands2[cur] == 0)         cur += dir;       else if (commands2[cur] ==  > ) {         prev = cur;         dir = 1;         cur += dir;         while (cur >= l && cur <= r && commands2[cur] == 0) cur += dir;         if (cur < l || cur > r) break;         if (commands2[cur] ==  <  || commands2[cur] ==  > ) commands2[prev] = 0;       } else if (commands2[cur] ==  < ) {         prev = cur;         dir = -1;         cur += dir;         while (cur >= l && cur <= r && commands2[cur] == 0) cur += dir;         if (cur < l || cur > r) break;         if (commands2[cur] ==  <  || commands2[cur] ==  > ) commands2[prev] = 0;       } else {         freq[commands2[cur] -  0 ]++;         commands2[cur]--;         if (commands2[cur] <  0 ) commands2[cur] = 0;         cur += dir;       }     }     for (int i = 0; i < 10; i++) {       printf( %d , freq[i]);       if (i == 9)         printf(  n );       else         printf(   );     }   }   int main() {     scanf( %d %d , &N, &Q);     scanf( %s , commands);     for (int i = 0; i < Q; i++) {       int L, R;       scanf( %d %d , &L, &R);       solve(L, R);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100;   int n, x, a;   int f[MAXN + 1];   int main() {     cin >> n >> x;     memset(f, 0, sizeof f);     for (int i = 0; i < n; i++) {       cin >> a;       f[a] = 1;     }     int ans = 0;     for (int i = 0; i < x; i++) {       if (f[i] == 0) ans++;     }     if (f[x] == 1) ans++;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   const int maxx = 2e5 + 7;   const int maxn = 1e9 + 7;   using namespace std;   inline int read() {     int s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   long long n, h, l, r;   int dp[2005][2005], a[2006];   int check(int op) {     if (op <= r && op >= l)       return 1;     else       return 0;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> h >> l >> r;     memset(dp, -1, sizeof dp);     dp[0][0] = 0;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       for (int j = 0; j < h; j++) {         if (dp[i - 1][(j - a[i] + h) % h] < 0 &&             dp[i - 1][(j - a[i] + 1 + h) % h] < 0)           continue;         dp[i][j] = max(dp[i - 1][(j - a[i] + h) % h],                        dp[i - 1][(j - a[i] + 1 + h) % h]) +                    check(j);       }     }     int ans = 0;     for (int i = 0; i < h; i++) {       ans = max(ans, dp[n][i]);     }     cout << ans << endl;     return 0;   }