malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n;   int query(string s) {     cout <<  ?           <<     << s << endl;     cout.flush();     int ans;     cin >> ans;     ans = n - ans;     return ans;   }   string str(int k) {     string s;     s.resize(n);     for (int i = 0; i < k; i++) s[i] =  0 ;     for (int i = k; i < n; i++) s[i] =  1 ;     return s;   }   int main() {     cin >> n;     int a;     a = query(str(0));     if (query(str(1)) > a) {       int p = 1, k = n - 1, x;       while (p != k) {         x = (p + k + 1) / 2;         if (query(str(x)) < x + a)           k = x - 1;         else           p = x;       }       cout <<  !             <<     << 1 <<     << p + 1 << endl;       cout.flush();     } else {       int p = 1, k = n - 1, x;       while (p != k) {         x = (p + k + 1) / 2;         if (query(str(x)) > a - x)           k = x - 1;         else           p = x;       }       cout <<  !             <<     << p + 1 <<     << 1 << endl;       cout.flush();     }   }
#include <bits/stdc++.h>   int n;   long long x, y, z = 2;   int main() {     scanf( %d , &n);     for (long long k = 1; k <= n; k++) {       y += 2;       x += y;       double a = x;       double b = z;       a = (double)(a / k);       b = (double)(b / k);       a = (double)a * x;       printf( %.0lf n , (double)a - b);       z = x;     }   }
#include <bits/stdc++.h>   using namespace std;   const int L = 2000;   const int AB = 26;   int cnt[AB];   char s1[L + 2], s2[L + 2];   int n;   char tmp[L + 2];   vector<int> ans;   void shift(int);   int main() {     scanf( %d , &n);     scanf( %s%s , s1 + 1, s2 + 1);     for (int i = 1; i <= n; ++i) {       ++cnt[s1[i] -  a ];       --cnt[s2[i] -  a ];     }     for (int i = 0; i < AB; ++i) {       if (cnt[i] != 0) {         printf( -1 n );         exit(EXIT_SUCCESS);       }     }     for (int i = n; i >= 1; --i) {       if (s1[i] == s2[1]) {         shift(n - i);         break;       }     }     for (int i = 1; i < n; ++i) {       for (int j = 1; j <= n - i; ++j) {         if (s1[j] == s2[i + 1]) {           shift(n - j);           shift(1);           shift(n);           break;         }       }     }     printf( %d n , (int)ans.size());     for (int x : ans) {       printf( %d  , x);     }     printf(  n );     exit(EXIT_SUCCESS);   }   void shift(int x) {     if (x == 0) {       return;     }     for (int i = 0; i < x; ++i) {       tmp[i] = s1[n - i];     }     for (int i = n; i > x; --i) {       s1[i] = s1[i - x];     }     for (int i = 1; i <= x; ++i) {       s1[i] = tmp[i - 1];     }     ans.push_back(x);   }
#include <bits/stdc++.h>   using namespace std;   ifstream fin( input );   void init() {     cin.tie(NULL);     ios_base::sync_with_stdio(false);   }   struct operation {     int i, j, x;   };   int n;   vector<int> v;   vector<int> cpy;   vector<operation> ops;   void simul() {     for (operation x : ops) {       cpy[x.i] -= x.i * x.x;       cpy[x.j] += x.i * x.x;     }     for (int i = 1; i <= n; i++) cout << cpy[i] <<    ;     cout << endl;   }   void read() {     cin >> n;     v.resize(n + 1);     for (int i = 1; i <= n; i++) cin >> v[i];     cpy = v;   }   void solve() {     int sum = 0;     for (int i = 1; i <= n; i++) sum += v[i];     if (sum % n != 0) {       cout << -1 << endl;       return;     }     for (int i = 2; i <= n; i++) {       if (v[i] != 0) {         int remaining = v[i] % i;         if (remaining) {           int required = i - remaining;           ops.push_back({1, i, required});           v[i] += required;         }         ops.push_back({i, 1, v[i] / i});       }     }     for (int i = 2; i <= n; i++) {       ops.push_back({1, i, sum / n});     }     cout << ops.size() << endl;     for (operation& x : ops) {       cout << x.i <<     << x.j <<     << x.x << endl;     }     ops.clear();   }   int main() {     init();     int t;     cin >> t;     while (t--) {       read();       solve();     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   using ll = long long int;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using vi = vector<int>;   using vl = vector<ll>;   using vpii = vector<pii>;   using vpll = vector<pll>;   using vvi = vector<vi>;   using vvl = vector<vl>;   using vvpii = vector<vpii>;   using vvpll = vector<vpll>;   using dd = double;   using ldd = long double;   using vd = vector<dd>;   inline void IO() {     fclose(stderr);     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << setiosflags(ios::fixed) << setprecision(15);     cerr << setiosflags(ios::fixed) << setprecision(15);   }   const ll MOD = 1e9 + 7;   const int INF = 2e9;   const ll INF64 = 9e18;   const double PI = 3.1415926535897932;   pll A[4], B[4];   bool same(pll &a, pll &c, pll &d) {     ;     if (a == c) return true;     if (a == d) {       swap(c, d);       return true;     }     return false;   }   bool sames() {     if (!same(B[0], A[1], B[1])) {       if (same(B[0], A[2], B[2])) {         swap(A[2], A[1]);         swap(B[2], B[1]);       } else if (same(B[0], A[3], B[3])) {         swap(A[3], A[1]);         swap(B[3], B[1]);       } else         return false;     }     if (!same(B[1], A[2], B[2])) {       if (same(B[1], A[3], B[3])) {         swap(A[2], A[3]);         swap(B[2], B[3]);       } else         return false;     }     if (!same(B[2], A[3], B[3])) return false;     return B[3] == A[0];   }   bool side(pll &a, pll b) { return a.first == b.first || a.second == b.second; }   bool sides() {     for (ll i = (0); i < (4); ++i)       if (!side(A[i], B[i])) return false;     return true;   }   bool check() {     if (!sames()) {       ;       return false;     }     if (!sides()) {       ;       return false;     }     if ((A[0].first - A[2].first) * (A[0].second - A[2].second) == 0 ||         (A[1].first - A[3].first) * (A[1].second - A[3].second) == 0) {       ;       return false;     }     return true;   }   int main() {     IO();     for (ll i = (0); i < (4); ++i)       cin >> A[i].first >> A[i].second >> B[i].first >> B[i].second;     if (check())       cout <<  YES n ;     else       cout <<  NO n ;     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool one(string s);   bool two(string s);   void c(string s);   void c2(string s);   int main() {     string str;     int i;     cin >> str;     if (one(str)) {       c(str);     } else if (two(str)) {       c2(str);     } else {       cout << str << endl;     }     return 0;   }   bool one(string s) {     int i;     int len = s.length();     for (i = 0; i < len; i++) {       if (i == 0) {         if (isupper(s[i])) {           return false;         }       } else {         if (!isupper(s[i])) return false;       }     }     return true;   }   bool two(string s) {     int i;     int len = s.length();     for (i = 0; i < len; i++) {       if (!isupper(s[i])) return false;     }     return true;   }   void c(string s) {     int i;     int len = s.length();     s[0] = toupper(s[0]);     for (i = 1; i < len; i++) {       s[i] = tolower(s[i]);     }     cout << s << endl;   }   void c2(string s) {     int i;     int len = s.length();     for (i = 0; i < len; i++) {       s[i] = tolower(s[i]);     }     cout << s << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline int SIZE(T& n) {     return n.size();   }   template <class T>   void OUT(const T& n) {     for (unsigned int i = 0; i < n.size(); ++i) {       cout << n[i] <<    ;     }     cout << endl;   }   int toInt(string s) {     int r = 0;     stringstream sin(s);     sin >> r;     return r;   }   template <class T>   string toString(T n) {     ostringstream ost;     ost << n;     ost.flush();     return ost.str();   }   class PacifistFrogs {    public:     vector<int> frogs(int N, vector<int> frogs, vector<int> mosquitoes) {       int number = 0, res = 1234567890;       vector<pair<int, int> > ans;       vector<int> output;       for (int i = 0; i < frogs.size(); ++i) {         int number = 0;         for (int j = 0; j < mosquitoes.size(); ++j) {           if (mosquitoes[j] % frogs[i] == 0) {             number++;           }         }         ans.push_back(make_pair(number, i + 1));         res = min(res, number);       }       for (int i = 0; i < ans.size(); ++i) {         if (ans[i].first == res) output.push_back(ans[i].second);       }       return output;     }   };   int n, m, k, a;   int main() {     cin >> n >> m >> k;     vector<int> frogs, mosquitoes, res;     for (int i = 0; i < m; ++i) {       cin >> a;       frogs.push_back(a);     }     for (int i = 0; i < k; ++i) {       cin >> a;       mosquitoes.push_back(a);     }     PacifistFrogs FROG;     res = FROG.frogs(n, frogs, mosquitoes);     cout << res.size() << endl;     OUT(res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mp[2010][2010];   long long sum1[2010][2010], sum2[2010][2010];   int n;   int check(int x, int y, int xx, int yy) {     int remy = abs(yy - y);     int remx = abs(xx - x);     if (remy == remx) return 0;     return 1;   }   long long getsum(int i, int j) {     long long s1 = 0, s2 = 0;     int x1 = j - 1 + i, y1 = 1;     if (x1 <= n) s1 = sum2[x1][y1];     int x2 = n, y2 = j - n + i;     if (y2 >= 1) s1 = sum2[x2][y2];     x1 = n - j + i, y1 = n;     if (x1 <= n) s2 = sum1[x1][y1];     x2 = n, y2 = j + n - i;     if (y2 <= n) s2 = sum1[x2][y2];     return s1 + s2 - mp[i][j];   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %I64d , &mp[i][j]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) sum1[i][j] = sum1[i - 1][j - 1] + mp[i][j];     for (int i = 1; i <= n; i++)       for (int j = n; j >= 1; j--) sum2[i][j] = sum2[i - 1][j + 1] + mp[i][j];     long long maxv1 = sum2[1][1] + sum1[n][n] - 1;     long long maxv2 = sum2[2][1] + sum1[n - 1][n] - 1;     int x = 1, y = 1, xx = 1, yy = 2;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         long long sum = getsum(i, j);         if ((i + j) % 2 == 1 && sum > maxv2) {           x = i;           y = j;           maxv2 = sum;         }         if ((i + j) % 2 == 0 && sum > maxv1) {           maxv1 = sum;           xx = i;           yy = j;         }       }     }     printf( %I64d n%d %d %d %d n , maxv1 + maxv2, x, y, xx, yy);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, j = 0, i, s, t;     cin >> n;     int a[n + 1];     for (i = 1; i <= n; i++) cin >> a[i];     s = a[1] + 2 * n - 1;     for (i = 1; i < n; i++) s += abs(a[i] - a[i + 1]);     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int n;   int main() {     cin >> n;     for (int i = 2; i * i <= n; i++) {       if (n % i != 0) continue;       int m1 = i;       for (int z1 = 1; z1 < m1; z1++) {         int val = n - 1 - z1 * (n / i);         if (val > 0 && val % m1 == 0) {           cout <<  YES  << endl                << 2 << endl                << z1 <<     << m1 << endl                << val / m1 <<     << n / m1 << endl;           return 0;         }       }     }     puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long add(int a, int b) {     return (a % 1000000007 + b % 1000000007 +             ((8000000000000000064LL) / 1000000007) * 1000000007) %            1000000007;   }   long long sub(long long a, long long b) {     return (a % 1000000007 - b % 1000000007 +             ((8000000000000000064LL) / 1000000007) * 1000000007) %            1000000007;   }   long long mul(long long a, long long b) {     return ((a % 1000000007) * (b % 1000000007) +             ((8000000000000000064LL) / 1000000007) * 1000000007) %            1000000007;   }   long long binpow(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   int const N = 1e3 + 9;   long long const INF = 2e18 + 5;   long long dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};   long long dy[8] = {1, -1, 0, 0, -1, 1, -1, 1};   char dr[4] = { R ,  L ,  D ,  U };   vector<vector<long long>> v;   void solve() {     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     v = vector<vector<long long>>(n + 1);     queue<long long> q;     q.push(1);     long long i = 1;     while (!q.empty()) {       if (i == n) {         break;       }       long long t = a[i], k = q.front();       q.pop();       while (a[i] >= t && i < n) {         q.push(a[i]);         v[k].push_back(a[i]);         t = a[i];         i++;       }     }     queue<pair<long long, long long>> Q;     Q.push({1, 0});     long long ans = 0;     while (!Q.empty()) {       long long k = Q.front().first, t = Q.front().second;       ans = max(ans, t);       Q.pop();       for (auto x : v[k]) {         Q.push({x, t + 1});       }     }     cout << ans <<   n ;   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1.e9 + 7;   const int MAXN = 1000000;   int fact[MAXN + 5], inv[MAXN + 5];   int lgput(int a, int b) {     int ans = 1;     for (; b; b >>= 1) {       if (b & 1) ans = 1LL * ans * a % MOD;       a = 1LL * a * a % MOD;     }     return ans;   }   void prec() {     fact[0] = 1;     for (int i = 1; i <= MAXN; ++i) fact[i] = 1LL * fact[i - 1] * i % MOD;     inv[MAXN] = lgput(fact[MAXN], MOD - 2);     for (int i = MAXN; i >= 1; --i) inv[i - 1] = 1LL * inv[i] * i % MOD;   }   int comb(int n, int k) {     return 1LL * fact[n] * inv[k] % MOD * inv[n - k] % MOD;   }   int f(int n, int k) {     if (k == 0) return 1;     return 1LL * n * lgput(n + k, k - 1) % MOD;   }   int main() {     prec();     int n, m, a, b;     scanf( %d%d%d%d , &n, &m, &a, &b);     int ans = 0;     for (int i = 0; i <= n - 2; ++i) {       if (m < i + 1) break;       int aux = 1LL * comb(m - 1, i) * comb(n - 2, i) % MOD * fact[i] % MOD;       aux = 1LL * aux * lgput(m, n - 2 - i) % MOD * f(i + 2, n - i - 2) % MOD;       ans += aux;       if (ans >= MOD) ans -= MOD;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   const int MOD = 1000000007;   bool ispalindrome(string &s) {     for (int i = 0; i < (int)s.size() / 2; i++) {       if (s[i] == s[(s.size() - i - 1)])         continue;       else         return false;     }     return 1;   }   int main(int argc, char *argv[]) {     string s;     cin >> s;     if (ispalindrome(s)) {       cout << 0 <<   n ;     } else {       cout << 3 <<   n ;       cout <<  R  <<     << s.size() - 1 <<   n ;       cout <<  L  <<     << s.size() <<   n ;       cout <<  L  <<     << 2 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long dp[1020][600], mod = (1000000007);   long long solve(int n, int m, int k) {     if (n < 2 * k - 1 or m < 2 * k - 1) return 0;     if (n <= 0 or m <= 0) return !k;     if (!k) return 1;     if (n == 2 * k - 1) {       if (dp[m][k] != -1) return dp[m][k];       long long ans = 0;       for (int dy = 1; dy <= m; dy++) {         long long aux = (solve(2 * k - 3, dy - 2, k - 1) * (m - dy + 1)) % mod;         ans += aux;         if (ans > mod) ans -= mod;       }       return dp[m][k] = ans;     } else if (m == 2 * k - 1)       return dp[n][k] = solve(2 * k - 1, n, k);     else       return (solve(n, 2 * k - 1, k) * solve(2 * k - 1, m, k)) % mod;   }   int n, m, k;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m >> k;     memset(dp, -1, sizeof dp);     cout << solve(n - 2, m - 2, k) <<   n ;   }
#include <bits/stdc++.h>   const int MAX = 1e5 + 10;   using namespace std;   char x[MAX], y[MAX];   int func[MAX][26], f[MAX], xlen, ylen;   int dp[2][MAX];   int main() {     scanf( %s %s , x, y);     xlen = strlen(x);     ylen = strlen(y);     int k = 0;     f[0] = 0;     if (xlen < ylen) {       printf( 0 n );       return 0;     }     for (int i = 1; i < ylen; ++i) {       while (k > 0 && y[i] != y[k]) k = f[k - 1];       if (y[i] == y[k]) k++;       f[i] = k;     }     for (int i = 0; i < ylen; ++i) {       for (int c =  a ; c <=  z ; ++c) {         k = i;         while (k > 0 && y[k] != c) k = f[k - 1];         if (y[k] == c) k++;         func[i][c -  a ] = k;       }     }     for (int i = xlen - 1; i >= 0; i--) {       for (int j = 0; j < ylen; j++) {         dp[(i & 1)][j] = 0;         if (x[i] ==  ? ) {           for (int k = 0; k < 26; k++) {             int nsuff = func[j][k];             if (nsuff == ylen) {               nsuff = f[ylen - 1];               dp[(i & 1)][j] = max(dp[(i & 1)][j], 1 + dp[!(i & 1)][nsuff]);             } else               dp[(i & 1)][j] = max(dp[(i & 1)][j], dp[!(i & 1)][nsuff]);           }         } else {           int nsuff = func[j][x[i] -  a ];           if (nsuff == ylen) {             nsuff = f[ylen - 1];             dp[(i & 1)][j] = 1 + dp[!(i & 1)][nsuff];           } else             dp[(i & 1)][j] = dp[!(i & 1)][nsuff];         }       }     }     printf( %d n , dp[0][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     for (int t = 0; t < T; t++) {       int n;       cin >> n;       int a[n], b[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       for (int i = 0; i < n; i++) {         cin >> b[i];       }       int difference = 0;       bool used = false, possible = true;       for (int i = 0; i < n; i++) {         if (a[i] > b[i]) {           possible = false;           break;         } else if (a[i] == b[i]) {           continue;         } else {           if (used) {             possible = false;             break;           }           difference = b[i] - a[i];           while (i < n) {             if (b[i] - a[i] == difference) {               i++;               continue;             }             if (b[i] == a[i]) {               used = true;               break;             }             if (b[i] - a[i] != difference) {               possible = false;               break;             }           }         }       }       if (possible)         cout <<  YES n ;       else         cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, res = pow(10, 18);     cin >> n;     vector<long long int> v(n);     for (long long int i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     for (long long int i = 0; i < n / 2; i++) res = min(res, v[i + n / 2] - v[i]);     cout << res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int qc = 1;     for (long long int i = 1; i <= qc; i++) solve();   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<  :   << arg1 << endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<  :   << arg1 <<   | ;     __f(comma + 1, args...);   }   const int INF = 1 << 29;   const int MOD = 1e9 + 7;   double sqr(double x) { return x * x; }   int main() {     double R, x1, y1, x2, y2;     scanf( %lf%lf%lf%lf%lf , &R, &x1, &y1, &x2, &y2);     double d = sqrt(sqr(x1 - x2) + sqr(y1 - y2));     double r = (d + R) / 2;     double x, y;     if (d > R) {       x = x1;       y = y1;       r = R;     } else if (d < 1e-10) {       x = x2;       y = y2 + r;     } else {       x = (x1 - x2) / d * r + x2;       y = (y1 - y2) / d * r + y2;     }     printf( %.10f %.10f %.10f n , x, y, r);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   int N;   char S[1010][20202];   int len[1010];   int cmp[20202];   int tmp[20202];   int D[2][20202];   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf( %s , S[i] + 1);       len[i] = strlen(S[i] + 1);     }     for (int i = 0; i <= len[1]; i++) D[1][i] = 1;     for (int i = 2; i <= N; i++) {       for (int j = 0; j <= len[i]; j++) D[i & 1][j] = 0;       tmp[max(len[i], len[i - 1]) + 1] = 0;       for (int j = max(len[i], len[i - 1]); j >= 1; j--) {         if (S[i - 1][j] < S[i][j])           tmp[j] = 1;         else if (S[i - 1][j] > S[i][j])           tmp[j] = -1;         else           tmp[j] = tmp[j + 1];       }       cmp[len[i] + 1] = cmp[len[i] + 2] = 0;       for (int j = len[i]; j > len[i - 1]; j--) {         if (S[i - 1][j] < S[i][j + 1])           cmp[j] = 1;         else if (S[i - 1][j] > S[i][j + 1])           cmp[j] = -1;         else           cmp[j] = cmp[j + 1];       }       for (int jj = len[i - 1] + 1; jj > 0; jj--) {         int j = (jj > len[i - 1] ? 0 : jj);         if (jj <= len[i]) {           if (S[i - 1][j + 1] < S[i][j + 1])             cmp[j] = 1;           else if (S[i - 1][j + 1] > S[i][j + 1])             cmp[j] = -1;           else             cmp[j] = tmp[j + 1];         }         for (int k = jj - 1; k >= 1; k--) {           if (S[i - 1][k] < S[i][k + 1])             cmp[k] = 1;           else if (S[i - 1][k] > S[i][k + 1])             cmp[k] = -1;           else             cmp[k] = cmp[k + 1];         }         int state = 0;         int p = 1;         if (j == p) p++;         for (int k = 1; k <= len[i]; k++) {           if (state == 0) {             if (cmp[k] >= 0) D[i & 1][k] = (D[i & 1][k] + D[i + 1 & 1][j]) % MOD;           } else if (state == 1) {             D[i & 1][k] = (D[i & 1][k] + D[i + 1 & 1][j]) % MOD;           }           if (!state) {             if (S[i - 1][p] < S[i][k])               state = 1;             else if (S[i - 1][p] > S[i][k])               state = -1;           }           p++;           if (p == j) p++;         }         if (state == 1 || (state == 0 && (len[i - 1] - !!j) == len[i]))           D[i & 1][0] = (D[i & 1][0] + D[i + 1 & 1][j]) % MOD;       }     }     int ans = 0;     for (int i = 0; i <= len[N]; i++) ans = (ans + D[N & 1][i]) % MOD;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[2005][2005] = {0};   long long int n, t, m, h, l, r;   int check(int v) { return v >= l && v <= r; }   void solve() {     cin >> n >> h >> l >> r;     vector<int> v;     for (int i = 0; i < n; i++) {       cin >> t;       v.push_back(t);     }     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= h; j++) dp[i][j] = INT32_MIN;     }     dp[0][0] = 0;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < h; j++) {         dp[i][j] = max(dp[i - 1][(j - v[i - 1] + h) % h],                        dp[i - 1][(j - v[i - 1] + 1 + h) % h]) +                    (j >= l && j <= r);       }     }     int mx = 0;     for (int i = 0; i < h; i++) {       mx = max(mx, dp[n][i]);     }     cout << mx <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     { solve(); }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     queue<string> q;     set<string> st;     int ans = 0;     q.push(s);     st.insert(s);     while (!q.empty() && int(st.size()) < k) {       string v = q.front();       q.pop();       for (int i = 0; i < v.length(); i++) {         string nv = v;         nv.erase(i, 1);         if (st.count(nv) == 0 && int(st.size()) + 1 <= k) {           q.push(nv);           st.insert(nv);           ans += n - nv.size();         }       }     }     if (int(st.size()) < k)       cout <<  -1  << endl;     else       cout << ans << endl;     return 0;   }