malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int N, K;   struct Level {     int lo[10 + 5], hi[10 + 5], sz;     bool operator<(const Level &l) const {       for (int i = 0; i < K; i++) {         if (hi[i] >= l.lo[i]) return false;       }       return true;     }   };   Level s[50000 + 5];   set<Level> ps;   void merge(Level &tar, const Level &src) {     for (int i = 0; i < K; i++) {       tar.lo[i] = min(tar.lo[i], src.lo[i]);       tar.hi[i] = max(tar.hi[i], src.hi[i]);     }     tar.sz += src.sz;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> N >> K;     for (int i = 0; i < N; i++) {       s[i].sz = 1;       for (int j = 0; j < K; j++) {         cin >> s[i].lo[j];         s[i].hi[j] = s[i].lo[j];       }       auto it1 = ps.lower_bound(s[i]), it2 = ps.upper_bound(s[i]);       while (!ps.empty() && it1 != it2) {         merge(s[i], *it1);         ps.erase(it1);         it1 = ps.lower_bound(s[i]);         it2 = ps.upper_bound(s[i]);       }       ps.insert(s[i]);       cout << (--ps.end())->sz <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 50;   int x[N][N], y[N], True[N], False[N], ans;   int n, m;   bool flag = false;   void dfs(int pos) {     if (pos > n) {       ans++;       return;     }     bool f = true;     for (int i = 1; i <= m; i++) {       if (!x[i][pos])         True[i]++;       else         False[i]++;       if (True[i] > y[i] || False[i] > n - y[i]) f = false;     }     if (f) dfs(pos + 1);     f = true;     for (int i = 1; i <= m; i++) {       if (!x[i][pos])         True[i]--, False[i]++;       else         False[i]--, True[i]++;       if (True[i] > y[i] || False[i] > n - y[i]) f = false;     }     if (f) dfs(pos + 1);     for (int i = 1; i <= m; i++) {       if (!x[i][pos])         False[i]--;       else         True[i]--;     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) scanf( %1d , &x[i][j]);       scanf( %d , &y[i]);     }     dfs(1);     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300010, mod = 998244353;   int a[N];   int n;   int fac[N], inv[N];   inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }   inline int del(int a, int b) { return a < b ? a - b + mod : a - b; }   inline int mul(int a, int b) { return a * 1ll * b % mod; }   inline int qpow(int a, int b) {     int s = 1;     while (b) {       if (b & 1) s = mul(s, a);       a = mul(a, a);       b >>= 1;     }     return s;   }   int main() {     scanf( %d , &n);     int m = 2 * n;     fac[0] = fac[1] = 1;     for (int i = 2; i <= m; ++i) fac[i] = mul(fac[i - 1], i);     inv[m] = qpow(fac[m], mod - 2);     for (int i = m - 1; i >= 1; --i) inv[i] = mul(inv[i + 1], i + 1);     inv[0] = 1;     for (int i = 1; i <= m; ++i) scanf( %d , &a[i]);     sort(a + 1, a + 1 + m);     for (int i = 1; i <= m; ++i)       if (a[i] >= mod) a[i] %= mod;     int ans = 0;     for (int i = 1; i <= n; ++i) ans = del(ans, a[i]);     for (int i = n + 1; i <= m; ++i) ans = add(ans, a[i]);     printf( %d n , mul(ans, mul(fac[m], mul(inv[n], inv[n]))));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> return_digit(long long num) {     vector<long long> arr;     while (num != 0) {       long long rem = num % 10;       arr.push_back(rem);       num /= 10;     }     return arr;   }   long long product_minmax(vector<long long> v) {     long long max_val = v[0];     long long min_val = v[0];     for (long long i = 1; i < v.size(); i++) {       max_val = max(max_val, v[i]);       min_val = min(min_val, v[i]);     }     return max_val * min_val;   }   long long compute(long long num) {     return num + product_minmax(return_digit(num));   }   int main() {     long long t;     cin >> t;     while (t--) {       long long a1, k;       cin >> a1 >> k;       long long temp = a1;       long long i = 0;       long long prev = a1;       while (i < k - 1) {         prev = temp;         temp = compute(temp);         if (prev == temp) {           break;         }         i += 1;       }       cout << temp << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, T, a, b;       cin >> n >> T >> a >> b;       vector<pair<int, int>> qstn(n);       int totA = 0, totB = 0;       for (auto& i : qstn) {         cin >> i.second;         totB += i.second;       }       totA = n - totB;       for (auto& i : qstn) {         cin >> i.first;       }       sort(qstn.begin(), qstn.end());       int sol = 0, ctA = 0, ctB = 0, i = -1;       do {         if (i >= 0 && i < n) {           if (qstn[i].second) {             ++ctB;           } else {             ++ctA;           }         }         int t = (i + 1 < n ? qstn[i + 1].first - 1 : T);         if ((long long)ctA * a + (long long)ctB * b > t) continue;         t -= ctA * a + ctB * b;         int xtra = min(totA - ctA, t / a);         t -= xtra * a;         xtra += min(totB - ctB, t / b);         sol = max(sol, xtra + ctA + ctB);       } while (++i < n);       cout << sol <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int s[1000 * 1000];   int main() {     int cnt = 1;     for (int i = 1; i <= 1005; i++) {       int t = i;       int a[10];       int cnt1 = 1;       while (t) {         int tmp = t % 10;         a[cnt1++] = tmp;         t = t / 10;       }       for (cnt1--; cnt1; cnt1--) s[cnt++] = a[cnt1];     }     int n;     while (scanf( %d , &n) != EOF) printf( %d , s[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[100001];   int n, f = 1, x, ans;   int main() {     cin >> a;     n = strlen(a);     for (int i = 0; i < n; i++) {       if (a[i] <  0  || a[i] >  9 ) {         ans += x * f;         x = 0;         if (a[i] ==  - ) f = -1;         if (a[i] ==  + ) f = 1;         x = x * 10 + a[i] -  0 ;       }       if (a[i] >=  0  && a[i] <=  9 ) {         x *= 10;         x += a[i] -  0 ;       }     }     ans += x * f;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void solve() {     int n, m;     cin >> n >> m;     map<vector<int>, int> tiles;     for (int i = 0; i < n; i++) {       vector<int> temp;       for (int j = 0; j < 4; j++) {         int a;         cin >> a;         temp.push_back(a);       }       tiles[temp]++;     }     if (m & 1) {       cout <<  NO n ;       return;     }     for (auto &i : tiles) {       if (i.first[1] == i.first[2]) {         cout <<  YES n ;         return;       }     }     cout <<  NO n ;   }   int main() {     fast();     int t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   long long ans;   int n, m, k;   long long C[1100][1100];   long long s1[1100][1100];   long long p[1100][1100];   long long f[1100100];   long long Pow(long long i, int x) {     long long tmp = 1;     while (x) {       if (x & 1) tmp = tmp * i % (1000000007LL);       i = i * i % (1000000007LL);       x >>= 1;     }     return tmp;   }   void work() {     memset(s1, 0, sizeof(s1));     int i = n;     for (int j = 1; j <= i; j++) {       s1[i][j] = Pow(j, i);       for (int k = 1; k < j; k++) {         s1[i][j] += (1000000007LL) - C[j][k] * s1[i][k] % (1000000007LL);         s1[i][j] %= (1000000007LL);       }     }   }   void pre() {     memset(C, 0, sizeof(C));     for (int i = 0; i <= 1000; i++) C[i][0] = 1;     for (int i = 1; i <= 1000; i++)       for (int j = 1; j <= i; j++)         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % (1000000007LL);     f[0] = 1;     for (int i = 1; i <= 1000000; i++) f[i] = f[i - 1] * i % (1000000007LL);     for (int i = 1; i <= 1000; i++) p[i][0] = 1;     for (int i = 1; i <= 1000; i++)       for (int j = 1; j <= 1000; j++) {         p[i][j] = (p[i][j - 1] * i) % (1000000007LL);       }   }   long long Inv(long long x) { return Pow(x, (1000000007LL) - 2LL); }   long long C_(int x, int y) {     return f[x] * Inv(f[y]) % (1000000007LL) * Inv(f[x - y]) % (1000000007LL);   }   int main() {     pre();     while (~scanf( %d%d%d , &n, &m, &k)) {       ans = 0;       work();       long long tt;       if (m == 1) {         ans = Pow(k, n);       } else if (m > 2) {         for (int i = 1; i <= min(n, k); i++)           for (int j = 0; j + i <= min(n, k); j++) {             if ((i | j) && i + 2 * j <= k) {               tt = C_(k, i) * C_(k - i, j) % (1000000007LL) * C_(k - i - j, j) %                    (1000000007LL);               ans += ((s1[n][i + j] * s1[n][i + j]) % (1000000007LL) *                       Pow(i, (m - 2) * n) % (1000000007LL)) *                      tt % (1000000007LL);               ans %= (1000000007LL);             }           }       } else {         for (int i = 1; i <= min(n, k); i++) {           ans += C_(k, i) * s1[n][i] % (1000000007LL) * C_(k, i) %                  (1000000007LL) * s1[n][i] % (1000000007LL);           ans %= (1000000007LL);         }       }       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       long long ar[n];       for (int i = 0; i < n; i++) cin >> ar[i];       int maxi = -1000000001;       long long sum = 0;       for (int i = 0; i < n; i++) {         if (ar[i] > maxi) maxi = ar[i];         sum += ar[i];       }       float ans = (sum - maxi) / (float)(n - 1) + maxi;       printf( %.9f , ans);       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int m = 1;     while (m * (m - 1) <= 2 * n) m++;     m = m - 1;     cout << m <<   n ;     int arr[m + 4][m + 3];     long long k = 1;     for (int i = 0; i < m; i++) {       long long count = 0;       for (int j = i; j < m - 1; j++) {         arr[i][j] = k + count++;       }       count = 0;       for (long long j = i + 1; j < m; j++) {         arr[j][i] = k + count++;       }       k = k + m - i - 1;     }     for (long long i = 0; i < m; i++) {       for (long long j = 0; j < m - 1; j++) {         cout << arr[i][j] <<    ;       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename F, typename S>   ostream &operator<<(ostream &os, const pair<F, S> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     typename vector<T>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  } ;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     os <<  [ ;     typename set<T>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename F, typename S>   ostream &operator<<(ostream &os, const map<F, S> &v) {     os <<  [ ;     typename map<F, S>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << it->first <<   =   << it->second;     }     return os <<  ] ;   }   int dx[4] = {1, -1, 0, 0};   int dy[4] = {0, 0, 1, -1};   const long long N = 1e6 + 1, M = 1e5 + 5, mod = 1e9 + 7, MOD = 1e9 + 7,                   inf = 5e18, MAX = 2e5;   string alphabet =  abcdefghijklmnopqrstuvwxyz ,          capital =  ABCDEFGHIJKLMNOPQRSTUVWXYZ , dig =  0123456789 ;   vector<bool> taken(N, false);   vector<int> ar;   void solve(int tt) {     int n, i, h, j, k, m, a, b;     cin >> n;     int sm = 0;     for (int i = 1; i <= n; i++) {       cin >> a;       ar.push_back(a);       taken[a] = true;       sm += a - 1;     }     vector<int> ans;     int cnt = 0;     for (int i = 0; i < n; i++) {       int cur = ar[i];       if (!taken[N - cur])         ans.push_back(N - cur);       else         ++cnt;       taken[N - cur] = true;     }     for (int i = 1; i < N && cnt > 0; i++) {       if (taken[i]) continue;       int now = N - i;       if (!taken[now]) {         taken[i] = taken[now] = true;         ans.push_back(i);         ans.push_back(N - i);         cnt -= 2;       }     }     cout << ans.size() <<   n ;     for (auto z : ans) {       sm -= (N - z - 1);       cout << z <<    ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long i;     long long T = 1, K;     for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true);          blockTime.second;          fprintf(stderr,  %s: %d ms n ,  Exec Time :  ,                  (int)chrono::duration_cast<chrono::milliseconds>(                      chrono::high_resolution_clock::now() - blockTime.first)                      .count()),               fflush(stderr), blockTime.second = false) {       long long x = 1;       while (x <= T) {         solve(x);         x++;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2510;   int sum[maxn][maxn];   char s[maxn][maxn];   int n, m, K;   long long ans;   int p1[10], p2[10];   int cal(int x1, int y1, int x2, int y2) {     return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];   }   void div(int x1, int y1, int x2, int y2, bool flag) {     if (x1 > x2 || y1 > y2) return;     if (x1 == x2 && y1 == y2) {       ans += (cal(x1, y1, x2, y2) == K);       return;     }     if (flag) {       int mid = (x1 + x2) >> 1;       div(x1, y1, mid, y2, !flag);       div(mid + 1, y1, x2, y2, !flag);       for (int i = y1; i <= y2; i++) {         for (int k = 0; k <= K; k++) {           p1[k] = mid, p2[k] = mid + 1;         }         for (int j = y2; j >= i; j--) {           for (int k = 0; k <= K; k++) {             while (p1[k] >= x1 && cal(p1[k], i, mid, j) <= k) p1[k]--;             while (p2[k] <= x2 && cal(mid + 1, i, p2[k], j) <= k) p2[k]++;           }           for (int k = 1; k < K; k++) {             ans += (p1[k - 1] - p1[k]) * (p2[K - k] - p2[K - k - 1]);           }           if (K > 0) {             ans += (mid - p1[0]) * (p2[K] - p2[K - 1]);             ans += (p2[0] - mid - 1) * (p1[K - 1] - p1[K]);           } else if (K == 0) {             ans += (mid - p1[0]) * (p2[0] - mid - 1);           }         }       }     } else {       int mid = (y1 + y2) >> 1;       div(x1, y1, x2, mid, !flag);       div(x1, mid + 1, x2, y2, !flag);       for (int i = x1; i <= x2; i++) {         for (int k = 0; k <= K; k++) {           p1[k] = mid, p2[k] = mid + 1;         }         for (int j = x2; j >= i; j--) {           for (int k = 0; k <= K; k++) {             while (p1[k] >= y1 && cal(i, p1[k], j, mid) <= k) p1[k]--;             while (p2[k] <= y2 && cal(i, mid + 1, j, p2[k]) <= k) p2[k]++;           }           for (int k = 1; k < K; k++) {             ans += (p1[k - 1] - p1[k]) * (p2[K - k] - p2[K - k - 1]);           }           if (K > 0) {             ans += (mid - p1[0]) * (p2[K] - p2[K - 1]);             ans += (p2[0] - mid - 1) * (p1[K - 1] - p1[K]);           } else if (K == 0) {             ans += (mid - p1[0]) * (p2[0] - mid - 1);           }         }       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &K);     for (int i = 1; i <= n; i++) {       scanf( %s , s[i] + 1);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         sum[i][j] =             sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + (s[i][j] ==  1 );       }     div(1, 1, n, m, 0);     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   long long n, s, h;   string s2, s1;   long long gw(long long n, long long x) {     long long rs = 0;     for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - 2 * ((0) > (n))) {       for (__typeof(n) j = (0) - ((0) > (n)); j != (n) - ((0) > (n));            j += 1 - 2 * ((0) > (n))) {         if ((i + j) % 2 == x) {           rs++;         }       }     }     return rs;   }   int main() {     ios_base::sync_with_stdio(false);     cout.precision(30);     cout.tie(0);     cin.tie(0);     cin >> n;     for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - 2 * ((0) > (n))) {       cin >> s1 >> s2;       if (s2 ==  hard )         h++;       else         s++;     }     for (__typeof(1001) i = (1) - ((1) > (1001)); i != (1001) - ((1) > (1001));          i += 1 - 2 * ((1) > (1001))) {       long long w = gw(i, 0), b = gw(i, 1);       if (h <= b && s <= w || h <= w && s <= b) {         cout << i << endl;         return 0;       }     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;   long long q,n,c[400005],z,ans,mn=1e14,d,x;   map<long long,long long>las,ll;   vector<long long>v;   struct am{   long long va,ind;   };   am a[400005];   bool cmp(am zz,am y){   return zz.ind<y.ind;   }   set<long long>st;   int main(){   ios::sync_with_stdio(NULL);   cin.tie(0);   cout.tie(0);   cin>>q;      while (q--){   cin>>n;   st.clear();   v.clear();   las.clear();   ll.clear();   mn=1e14;   for (long long i=1;i<=n;i++){       cin>>x;       las[x]++;   }   z=1;   for (auto it=las.begin();it!=las.end();it++){   a[z].va=it->first;   a[z].ind=it->second;   z++;   }      sort (a+1,a+z,cmp);   for (long long i=z-1;i>=1;i--){           x=st.size();       mn=min(mn,n-(a[i].ind + a[i].ind*x));   st.insert(a[i].va);   }         cout<<mn<<  n ;   }         }
#include <bits/stdc++.h>   using namespace std;   const int N = 200009;   int n, a[N], cnt[N], mode, fsm[N], tmp[N], ans;   void larg(int x) {     int sm = 0, res = 0;     memset(fsm, 0, sizeof(fsm));     for (int i = 1; i <= n; i++) {       if (a[i] == mode)         sm++;       else if (a[i] == x)         sm--;       if (sm && !fsm[sm]) fsm[sm] = i;       res = max(res, i - fsm[sm]);     }     ans = max(ans, res);   }   void smal(int x) {     int l = 1, p = 0, res = 0;     memset(tmp, 0, sizeof(tmp));     for (int i = 1; i <= n; i++) {       tmp[a[i]]++;       if (tmp[a[i]] == x) p++;       while (l <= i && tmp[a[i]] > x) {         if (tmp[a[l]] == x) --p;         tmp[a[l++]]--;       }       if (p >= 2) res = max(res, i - l + 1);     }     ans = max(ans, res);   }   int main() {     scanf( %d , &n);     if (n == 1) {       puts( 0 );       return 0;     }     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       cnt[a[i]]++;     }     for (int i = 1; i <= n; i++) {       if (cnt[a[i]] > cnt[mode]) mode = a[i];     }     for (int i = 1; i <= 200000; i++) {       if (!cnt[i]) continue;       if (i != mode && cnt[i] == cnt[mode]) {         printf( %d n , n);         return 0;       }       if (cnt[i] > sqrt(n)) larg(i);     }     for (int i = 1; i <= sqrt(n); i++) smal(i);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300;   map<int, int> m;   int main() {     ios_base::sync_with_stdio(false);     int i, j, n;     cin >> n;     int p = 0;     int k = 0;     for (i = 1; i <= n; ++i) {       cin >> j;       if (m[j] == 0)         ++k;       else         m[j]--;       m[i]++;     }     cout << k << endl;   }
#include <bits/stdc++.h>   using namespace std;   int N, R;   int result = INT_MAX;   char opt[] =  TB ;   int turns;   int sLast;   char rChar[1000001];   int main() {     int x, y;     cin >> N >> R;     if (N == 1 && R == 1) {       cout << 0 << endl <<  T  << endl;       return 0;     }     for (int i = 1; i < R; i++) {       x = i;       y = R;       int *smaller, *larger;       int mistakes = 0;       int times = 0;       int turn_over = 0;       while (x > 0 && y > 0) {         if (x > y) {           larger = &x;           smaller = &y;         } else {           larger = &y;           smaller = &x;         }         mistakes += *larger / *smaller - 1;         times += *larger / *smaller;         turn_over++;         *larger %= *smaller;       }       if (x + y == 1 && times == N) {         mistakes--;         turn_over++;         if (mistakes < result) {           result = mistakes;           sLast = i;           turns = turn_over;         }       }     }     if (result == INT_MAX) {       cout <<  IMPOSSIBLE  << endl;     } else {       cout << result << endl;       if (turns & 1) {         x = R;         y = sLast;       } else {         x = sLast;         y = R;       }       for (int i = N - 1; i > 0; i--) {         if (x > y) {           rChar[i] =  T ;           x -= y;         } else {           rChar[i] =  B ;           y -= x;         }       }       rChar[0] =  T ;       cout << rChar << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   long long PRIME = 999727999;   long long PRIME2 = 999999937;   long long INF = LLONG_MAX / 4;   template <class F1, class F2>   ostream& operator<<(ostream& os, const pair<F1, F2>& p) {     return os << p.first <<     << p.second;   }   template <class F1, class F2>   istream& operator>>(istream& is, pair<F1, F2>& p) {     return is >> p.first >> p.second;   }   template <class F>   ostream& operator<<(ostream& os, const std::vector<F>& v) {     for (int i = 0; i < (int)v.size(); i++) os << v[i] <<    ;     return os;   }   template <class F>   istream& operator>>(istream& is, std::vector<F>& v) {     for (int i = 0; i < (int)v.size(); i++) is >> v[i];     return is;   }   vector<string> split(const std::string& s, char delim) {     vector<string> e;     stringstream ss(s);     string item;     while (getline(ss, item, delim)) e.push_back(item);     return e;   }   long long Pow(long long a, long long b, long long Mo) {     long long ans = 1;     for (; b; b >>= 1, a = a * a % Mo)       if (b & 1) ans = ans * a % Mo;     return ans;   }   long long _div(long long a, long long b) {     return (a * Pow(b, MOD - 2, MOD)) % MOD;   }   long long nCr(long long n, long long r) {     static long long MAXF = 1e6;     static std::vector<long long> fact(MAXF, 1);     for (int i = 1; i < MAXF; ++i) fact[i] = (fact[i - 1] * i) % MOD;     MAXF = 0;     return (fact[n] * Pow((fact[r] * fact[n - r]) % MOD, MOD - 2, MOD)) % MOD;   }   vector<int> Zfunc(string& s) {     int n = s.length();     vector<int> z(n, 0);     for (int i = 1, l = 0, r = 0; i < n; i++) {       if (i <= r) z[i] = min(z[i - l], r - i + 1);       while (i + z[i] < n && s[i + z[i]] == s[z[i]]) z[i]++;       if (r < i + z[i] - 1) l = i, r = i + z[i] - 1;     }     return z;   }   string s;   int l;   std::vector<std::vector<long long> > DP;   long long getWaysAny(int c, int left) {     if (c > left) return 0;     return nCr(left, c);   }   long long getWays(int c, int takencare) {     if (takencare == l) {       if (c == 0) return 1;       return 0;     }     long long& w = DP[c][takencare];     if (w != -1) return w;     w = 0;     if (s[takencare] ==  1 ) {       if (c > 0) w = (w + getWays(c - 1, takencare + 1)) % MOD;       w = (w + getWaysAny(c, l - (takencare + 1))) % MOD;     } else {       w = (w + getWays(c, takencare + 1)) % MOD;     }     return w;   }   long long solve() {     int k;     cin >> s >> k;     l = s.length();     if (k == 0) {       return 1;     }     DP.resize(1002, std::vector<long long>(1002, -1));     if (k == 1) {       return (getWays(1, 0) + MOD - 1) % MOD;     }     long long w = 0;     for (int i = 2; i <= 1000; ++i) {       long long needk = 0;       long long i2 = i;       while (i2 > 1) {         i2 = __builtin_popcount(i2);         needk++;       }       if (needk == k - 1) {         w = (w + getWays(i, 0)) % MOD;       }     }     return w;   }   int main(int argc, char const* argv[]) {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout << solve();     return 0;   }