malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   const long long N = 5e5 + 1;   bool prime[N];   void solve() {     long long n, k;     cin >> n >> k;     string s;     cin >> s;     vector<vector<long long>> v(k);     long long cnt = 0, c = 0;     string t = s;     bool f = 0;     while (1) {       bool b = 0;       for (long long i = 0; i < n; i++) {         if (t[i] ==  R  && t[i + 1] ==  L ) {           if (cnt >= k) {             f = 1;             break;           }           b = 1;           t[i] =  L ;           t[i + 1] =  R ;           i++;           v[cnt].push_back(i);           c++;         }       }       if (f) break;       if (b == 0) break;       cnt++;     }     if (cnt > k || c < k || f) {       cout << -1 <<   n ;       return;     } else if (cnt == k) {       for (auto i : v) {         cout << i.size() <<    ;         for (auto j : i) cout << j <<    ;         cout <<   n ;       }     } else {       long long t = cnt - 1, b = k - 1;       while (t < b) {         long long m = v[t].size();         while (!v[t].empty()) {           v[b].push_back(v[t].back());           b--;           v[t].pop_back();           if (t >= b) break;         }         if (t == b && v[t].size()) break;         t--;       }       for (auto i : v) {         cout << i.size() <<    ;         for (auto j : i) cout << j <<    ;         cout <<   n ;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     sort(begin(v), end(v));     v.erase(unique(begin(v), end(v)), end(v));     n = v.size();     for (int i = 2; i < n; i++) {       int a = v[i - 2];       int b = v[i - 1];       int c = v[i];       if (a + 1 == b && b + 1 == c) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int a[maxn], b[maxn];   int main() {     int n, x, T;     cin >> T;     while (T--) {       cin >> n;       set<int> s;       s.clear();       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       for (int i = 1; i <= n; i++) {         scanf( %d , &b[i]);       }       int l = 1, r = n;       while (l <= n && a[l] == b[l]) l++;       while (r >= 1 && a[r] == b[r]) r--;       if (l > r) {         cout <<  YES n ;         continue;       }       int flag = 1;       if (a[l] - b[l] > 0) flag = 0;       for (int i = l + 1; i <= r; i++) {         if (a[l] - b[l] != a[i] - b[i]) flag = 0;       }       if (flag)         cout <<  YES n ;       else         cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, sum, ans, a[100005];   inline long long read() {     long long q = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = 0;       ch = getchar();     }     while (isdigit(ch)) {       q = (q << 3) + (q << 1) + (ch ^ 48);       ch = getchar();     }     return f ? q : -q;   }   inline void print(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) print(x / 10);     putchar(x % 10 + 48);   }   signed main() {     n = read();     for (register long long i = 1; i <= n; ++i) a[i] = read(), sum += a[i];     sort(a + 1, a + n + 1, greater<long long>());     for (register long long i = 1; i <= (sum % n); ++i)       ans += abs(a[i] - sum / n - 1);     for (register long long i = (sum % n) + 1; i <= n; ++i)       ans += abs(a[i] - sum / n);     print(ans >> 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > T;   int n, sum;   vector<pair<int, int> > loc;   void input();   void solve();   int main() {     input();     solve();     return 0;   }   void input() {     assert(scanf( %d , &n) == 1);     T.resize(n);     for (int i = 0; i < n; i++) {       int c;       assert(scanf( %d , &c) == 1);       sum += c;       T[i].resize(c);     }     loc.resize(sum);     for (int i = 0; i < n; i++)       for (int j = 0; j < ((int)(T[i].size())); j++) {         assert(scanf( %d , &T[i][j]) == 1);         loc[T[i][j] - 1] = make_pair(i, j);       }   }   void solve() {     vector<int> ans[4];     int cnt = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < ((int)(T[i].size())); j++) {         int x = loc[cnt].first, y = loc[cnt].second;         if (i != x || j != y) {           ans[0].push_back(i + 1);           ans[1].push_back(j + 1);           ans[2].push_back(x + 1);           ans[3].push_back(y + 1);           swap(T[i][j], T[x][y]);           swap(loc[T[i][j] - 1], loc[T[x][y] - 1]);         }         cnt++;       }     cout << ((int)(ans[0].size())) << endl;     for (int i = 0; i < ((int)(ans[0].size())); i++) {       for (int j = 0; j < 4; j++) cout << ans[j][i] <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[200000], money, energy, i;     scanf( %d , &n);     for (i = 0; i <= n - 1; i++) {       scanf( %d , &a[i]);     }     energy = 0;     money = a[0];     for (i = 0; i <= n - 2; i++) {       if (energy + a[i] - a[i + 1] < 0) {         money += a[i + 1] - a[i] - energy;         energy = 0;       } else {         energy += a[i] - a[i + 1];       }     }     printf( %d n , money);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 6;   int n, l, r, h[N], b[N], ans[N], S;   vector<int> X, Y;   int main() {     scanf( %d%d%d , &n, &l, &r);     for (int i = 1; i <= n; ++i) scanf( %d , h + i), S += h[i];     for (int i = 1; i <= n; ++i) scanf( %d , b + i);     int _l = S - r, _r = S - l;     for (int i = 1; i <= n; ++i) (b[i] ? Y : X).push_back(h[i]);     sort(X.rbegin(), X.rend()), sort(Y.rbegin(), Y.rend());     for (int i = 1; i <= 10000; ++i) ans[i] = -1e9;     for (int s : X)       for (int i = 10000; i >= s; --i)         if (ans[i - s] >= 0) ans[i] = max(ans[i], ans[i - s]);     for (int s : Y)       for (int i = 10000; i >= s; --i)         if (ans[i - s] >= 0)           ans[i] = max(ans[i], ans[i - s] + (_l <= i && i <= _r));     printf( %d n , *max_element(ans, ans + 10001));   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000100;   int n, p[N];   int mx1[N], mx2[N], ans[N];   int main() {     scanf( %d , &n);     for (int v, best, i = 2; i <= n + 1; i++) {       scanf( %d , p + i);       v = i;       while (v != 0) {         best = max(mx1[v], mx2[v] + 1);         if (best <= ans[v]) break;         ans[v] = best;         if (mx2[p[v]] < best) mx2[p[v]] = best;         if (mx1[p[v]] < mx2[p[v]]) swap(mx1[p[v]], mx2[p[v]]);         v = p[v];       }       printf( %d  , max(mx1[1], mx2[1]));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxD = 1001;   vector<int> temp;   int main() {     int n, w[MaxD] = {0}, h[MaxD] = {0}, maximum = 0, minimum = MaxD, ilgis;     unsigned long long ats = 1e18;     bool ar;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> w[i] >> h[i];       if (max(w[i], h[i]) > maximum) maximum = max(w[i], h[i]);       if (min(w[i], h[i]) < minimum) minimum = min(w[i], h[i]);     }     for (int i = minimum; i <= maximum; i++) {       ilgis = 0;       int vietos = n / 2;       ar = true;       temp.clear();       for (int j = 1; j <= n; j++) {         if (min(w[j], h[j]) > i) {           ar = false;           break;         }         if (h[j] > i && w[j] <= i) {           vietos--;           ilgis += h[j];         } else if (w[j] > i && h[j] <= i) {           ilgis += w[j];         } else {           ilgis += w[j];           if (w[j] > h[j] && w[j] <= i) temp.push_back(h[j] - w[j]);         }         if (vietos < 0) {           ar = false;           break;         }       }       sort(temp.begin(), temp.end());       if (ar) {         for (int j = 0; j < temp.size() && vietos; j++) {           ilgis += temp[j];           vietos--;         }       }       if (ar && (ilgis * i) < ats) ats = ilgis * i;     }     cout << ats;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, dp[300005], k = 0, b[300005];   vector<int> ke[300005];   void dfs(int u, int par) {     if (ke[u].size() == 1 && u != 1) {       dp[u] = 1;       k++;       return;     }     if (b[u])       dp[u] = 1e9;     else       dp[u] = 0;     for (int v : ke[u])       if (v != par) {         dfs(v, u);         if (b[u])           dp[u] = min(dp[u], dp[v]);         else           dp[u] += dp[v];       }   }   int main() {     ios::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n;     for (int i = 1; i <= n; i++) cin >> b[i];     int u;     for (int i = 2; i <= n; i++) {       cin >> u;       ke[u].push_back(i);       ke[i].push_back(u);     }     dfs(1, 0);     cout << k - dp[1] + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.14159265359;   const long long MOD = (long long)1e9 + 7;   const long long MAXN = (long long)2e3 + 10;   const long long INF = (long long)2242545357980376863;   const long double EPS = (long double)1e-8;   long long dp[MAXN][2048];   long long pw[MAXN], cnt[MAXN];   long long a[MAXN];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     pw[0] = 1;     for (int i = 1; i < MAXN; i++) pw[i] = (pw[i - 1] << 1) % MOD;     long long n, k;     cin >> n >> k;     k = (1ll << k);     for (int i = 1; i <= n; i++) cin >> a[i];     long long c0 = 0;     for (int i = n; i >= 0; i--) {       cnt[i] = c0;       if (a[i] == 0) c0++;     }     if (a[1] == 2) {       dp[1][2] = 1;     }     if (a[1] == 4) {       dp[1][4] = 1;     }     if (a[1] == 0) {       dp[1][2] = dp[1][4] = 1;     }     long long ans = 0;     for (int i = 1; i < n; i++) {       for (int j = 2; j < 2048; j++) {         if (dp[i][j] == 0) continue;         long long nx = a[i + 1];         if (nx != 4) {           long long sm = j + 2;           if (sm >= k) {             ans += (pw[cnt[i + 1]] * dp[i][j]);             ans %= MOD;           } else {             dp[i + 1][sm] += dp[i][j];             dp[i + 1][sm] %= MOD;           }         }         if (nx != 2) {           if (j % 4 == 2) {             dp[i + 1][4] += dp[i][j];           } else {             long long sm = j + 4;             if (sm >= k) {               ans += (pw[cnt[i + 1]] * dp[i][j]);               ans %= MOD;             } else {               dp[i + 1][sm] += dp[i][j];               dp[i + 1][sm] %= MOD;             }           }         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       long long a, b, c;       cin >> a >> b >> c;       long long ans = (a + b + c) / 2;       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using pii = pair<int, int>;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<int> A(n);     vector<int> P(n + 1);     for (auto &x : A) cin >> x;     for (int i = 0; i < n; ++i) P[A[i]] = i;     int cnt = 0;     vector<vector<int>> sol;     for (int kk = 0; kk < n; ++kk) {       if (is_sorted(A.begin(), A.end())) break;       ++cnt;       int goal = -1;       for (int i = 1; i <= n - 1; ++i) {         if (P[i] > P[i + 1]) {           goal = i;           break;         }       }       vector<vector<int>> G;       G.push_back({});       int state = 0;       for (int i = 0; i < n; ++i) {         if (state == 0) {           if (A[i] != goal + 1) {             G.back().push_back(A[i]);           } else {             G.push_back({A[i]});             state = 1;           }         } else if (state == 1) {           if (A[i] == goal) {             G.push_back({A[i]});             state = 3;             G.push_back({});           } else if (A[i] == A[i - 1] + 1)             G.back().push_back(A[i]);           else {             G.push_back({A[i]});             state = 2;           }         } else if (state == 2) {           G.back().push_back(A[i]);           if (A[i] == goal) {             state = 3;             G.push_back({});           }         } else {           G.back().push_back(A[i]);         }       }       sol.push_back({});       for (auto &x : G) {         if (!x.empty()) sol.back().push_back(x.size());       }       reverse(G.begin(), G.end());       {         int i = 0;         for (auto &g : G)           for (auto x : g) A[i++] = x;       }       for (int i = 0; i < n; ++i) P[A[i]] = i;     }     assert(is_sorted(A.begin(), A.end()));     cout << cnt <<   n ;     for (auto &s : sol) {       cout << s.size() <<    ;       for (auto &x : s) cout << x <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long p = 1e9 + 7;   int n, a[2505], mx, s, ch, ans;   long long f[100005];   long long ksm(long long x, int y) {     long long sun = 1;     x %= p;     while (y) {       if (y & 1) sun = sun * x % p;       y >>= 1;       x = x * x % p;     }     return sun;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++)       scanf( %d , &a[i]), mx = max(a[i], mx), s += a[i];     f[1] = ksm(s - 1, 2) * ksm(s, p - 2) % p;     ch = f[1];     for (int i = 2; i <= mx; i++) {       ch = (ch - ksm(s - i + 1, p - 2) * (s - 1) % p + p) % p;       f[i] = (f[i - 1] + ch) % p;     }     for (int i = 1; i <= n; i++) ans = (ans + f[a[i]]) % p;     cout << ans;   }
#include <cstdio>   #include <cstring>   #include <queue>   #include <cmath>   #include <set>   #include <cstdlib>   #include <iostream>   #include <map>   #include <algorithm>   using namespace std;   typedef long long ll;   typedef unsigned long long ull;   typedef unsigned int uii;   typedef pair<int, ll> pii;   template<typename T>   inline void rd(T& x)   {    int tmp = 1; char c = getchar(); x = 0;    while (c >  9  || c <  0 ) { if (c ==  - )tmp = -1; c = getchar(); }    while (c >=  0  && c <=  9 ) { x = x * 10 + c -  0 ; c = getchar(); }    x *= tmp;   }   const int N = 2e5 + 10;   const int M = 1e6 + 10;   const int mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   const double eps = 1e-5;   int sgn(double x) {    if (fabs(x) < eps) return 0;    if (x > 0) return 1;    return -1;   }   int n, m, k;   int head[N], cntE;   struct edge {    int to, next;    int w;   }e[M];   void add(int u, int v, int w = 0) {    e[cntE].to = v;    e[cntE].next = head[u];    e[cntE].w = w;    head[u] = cntE++;   }   bool vis[N];   int stk[N], top;   bool dfs(int x) {    if (vis[x ^ 1]) return false;    if (vis[x]) return true;    vis[x] = true;    stk[++top] = x;    for (int i = head[x]; ~i; i = e[i].next) {     int v = e[i].to;     if (!dfs(v)) return false;    }    return true;   }   bool two_sat() {    memset(vis, false, sizeof(bool) * (2 * n + 10));    for (int i = 0; i < n; ++i) {     if (vis[i << 1] || vis[i << 1 | 1]) continue;     top = 0;     if (!dfs(i << 1)) {      while (top) vis[stk[top--]] = false;      if (!dfs(i << 1 | 1)) return false;     }    }    return true;   }   ll a[N], b[N], c[N], maxn[N];   ll solve() {    maxn[n] = c[n] - 1 + 2;    ll ans = 0;    for (int i = n - 1; i > 0; --i) {     ans = max(ans, maxn[i + 1] + b[i + 1] - a[i + 1]);     maxn[i] = c[i] - 1;     if (b[i+1] == a[i+1]) {     // maxn[i] = c[i] + 1;     }     else {      maxn[i] = max(maxn[i], maxn[i + 1] + (c[i] - 1 - (b[i + 1] - a[i + 1])));     }     maxn[i] += 2;    }    return ans;   }   int main() {   #ifdef _DEBUG    FILE* _INPUT = freopen( input.txt ,  r , stdin);    // FILE* _OUTPUT = freopen( output.txt ,  w , stdout);   #endif // !_DEBUG    int cas = 0, T;    rd(T);    while (T--) {   // while (~scanf( %d , &n)) {     rd(n);     for (int i = 1; i <= n; ++i) rd(c[i]);     for (int i = 1; i <= n; ++i) rd(a[i]);     for (int i = 1; i <= n; ++i) rd(b[i]);     for (int i = 1; i <= n; ++i) if (a[i] > b[i]) swap(a[i], b[i]);     printf( %lld n , solve());    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   void printv(vector<long long int> v) {     long long int sz = v.size();     for (long long int i = 0; i < sz; i++) {       if (i == sz - 1)         cout << v[i] <<   n ;       else         cout << v[i] <<    ;     }   }   void input(long long int a[], long long int sz) {     for (long long int i = 0; i < sz; i++) cin >> a[i];   }   void print(long long int a[], long long int sz) {     for (long long int i = 0; i < sz; i++) {       if (i == sz - 1)         cout << a[i] <<   n ;       else         cout << a[i] <<    ;     }   }   long long int dx1[] = {1, 1, 0, -1, -1, -1, 0, 1};   long long int dy1[] = {0, 1, 1, 1, 0, -1, -1, -1};   long long int dx2[] = {1, 0, -1, 0};   long long int dy2[] = {0, 1, 0, -1};   long long int mul(long long int a, long long int b,                     long long int p = 1000000007) {     return ((a % p) * (b % p)) % p;   }   long long int add(long long int a, long long int b,                     long long int p = 1000000007) {     return (a % p + b % p) % p;   }   long long int power(long long int x, long long int y,                       long long int p = 1000000007) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int modInverse(long long int n, long long int p = 1000000007) {     return power(n, p - 2, p);   }   long long int ncrMod(long long int n, long long int r,                        long long int p = 1000000007) {     if (r == 0) return 1;     long long int fac[n + 1];     fac[0] = 1;     for (long long int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p;     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %            p;   }   bool ispeed2ime(long long int n) {     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   bool isPowerof2(long long int n) {     while (n > 1) {       if (n % 2 != 0) {         return true;       }       n /= 2;     }     return false;   }   string reverse(string str, int len, int l, int r) {     if (l < 0 || r >= len || l > r) return str;     while (l < r) {       char c = str[l];       str[l] = str[r];       str[r] = c;       l++;       r--;     }     return str;   }   void solve() {     long long int n;     cin >> n;     string s;     cin >> s;     string temp =   ;     long long int maxi1 = 0, maxi2 = 0;     for (int i = 0; i < n - 1; i++) {       temp += s[i];       temp += s[i + 1];       if (temp ==  10 ) {         maxi1++;       } else if (temp ==  01 ) {         maxi2++;       }       temp =   ;     }     long long int maxi = max(maxi1, maxi2);     long long int cnt = n / 2 - (maxi);     cout << cnt <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   bool QQQQ;   const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};   const int dy[] = {0, 0, -1, 1, 1, -1, 1, -1};   using namespace std;   int ttt = 1;   int n, k, res = 100256, z, cnt;   string s, t, ans;   void solve() {     cin >> n >> k >> s;     ans = s;     for (int i = 0; i < n; i++) ans[i] =  9 ;     for (int i = 0; i < 10; i++) {       t = s;       z = k;       cnt = 0;       for (int j = 0; j < 10; j++) {         for (int l = 0; l < n; l++)           if (z && t[l] -  0  == i + j) {             z--;             t[l] = i +  0 ;             cnt += j;           }         if (j)           for (int l = n - 1; l >= 0; l--)             if (z && t[l] -  0  == i - j) {               z--;               t[l] = i +  0 ;               cnt += j;             }       }       if (cnt < res) res = cnt, ans = t;       if (cnt == res) ans = min(ans, t);     }     cout << res << endl << ans;   }   int main() {     for (int tt = 1; tt <= (ttt = ttt); tt++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio();     cin.tie();     int t, n, a, b;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       int c = abs(a - b);       int ans = 0;       int tmp = c / 5;       ans += tmp;       c -= tmp * 5;       tmp = c / 2;       ans += tmp;       c -= tmp * 2;       tmp = c / 1;       ans += tmp;       c -= tmp * 1;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long int dist[1150][1150], visited[1150][1150];   char ans[1050][1050];   void solve() {     long long n, i, j, m;     cin >> n >> m;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) cin >> ans[i][j];     }     int startx, starty, endx, endy;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (ans[i][j] ==  E ) {           endx = i;           endy = j;         }         if (ans[i][j] ==  S ) {           startx = i;           starty = j;         }       }     }     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) {         dist[i][j] = INT_MAX;         visited[i][j] = 0;       }     int rowcol[] = {0, 0, 1, -1};     int colcol[] = {1, -1, 0, 0};     dist[endx][endy] = 0;     visited[endx][endy] = 1;     queue<pair<int, int> > q;     q.push({endx, endy});     while (q.empty() == 0) {       pair<int, int> point = q.front();       q.pop();       int x = point.first;       int y = point.second;       for (i = 0; i < 4; i++) {         int x1 = x + rowcol[i];         int y1 = y + colcol[i];         if (x1 >= 0 && y1 >= 0 && x1 < n && y1 < m && ans[x1][y1] !=  T ) {           if (visited[x1][y1] == 0) {             dist[x1][y1] = dist[x][y] + 1;             visited[x1][y1] = 1;             q.push({x1, y1});           }         }       }     }     unsigned long long int count = 0;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (startx == i && starty == j) {           continue;         }         if (dist[startx][starty] >= dist[i][j] && ans[i][j] !=  0  &&             ans[i][j] !=  T  && ans[i][j] !=  E )           count += ans[i][j] -  0 ;       }     }     cout << count << endl;   }   int main() {     long long n = 1, x1, y1, x2, y2, i;     while (n--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k, p[3005], d[3005][3005], p0[3005], p50[3005], p100[3005], ans;   queue<int> x, y;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , p + i);       if (p[i] == 0)         p0[1]++;       else if (p[i] == 100)         p100[1]++;       else         p50[1]++;     }     if (n == 1) {       printf( 1 n );       return 0;     }     for (int i = 2; i <= n; i++) {       p0[i] = p0[i - 1], p50[i] = p50[i - 1], p100[i] = p100[i - 1];       if (p[i - 1] == 0)         p0[i]--;       else if (p[i - 1] == 100)         p100[i]--;       else         p50[i]--;     }     d[1][2] = 1;     x.push(1), y.push(2);     while (!x.empty()) {       int a = x.front(), b = y.front();       x.pop(), y.pop();       ans++;       if (b > n || d[a][b] > k) continue;       if (p[a] > 0 && (p50[b] || p100[b]) && !d[b + 1][b + 2])         d[b + 1][b + 2] = d[a][b] + 1, x.push(b + 1), y.push(b + 2);       if (p[a] > 0 && (!p100[b]) && !d[a][b + 1])         d[a][b + 1] = d[a][b] + 1, x.push(a), y.push(b + 1);       if (p[a] < 100 && (p50[b] || p100[b]) && !d[b][b + 1])         d[b][b + 1] = d[a][b] + 1, x.push(b), y.push(b + 1);     }     printf( %d n , ans);     return 0;   }