malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long NR = 5e5 + 100;   const long long oo = 2e9 + 100;   const long long MOD = 998244353;   long long n;   string s;   long long a[NR];   long long dp[5];   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long i;     cin >> n;     cin >> s;     for (i = 0; i < n; ++i) {       cin >> a[i];     }     for (i = 0; i < s.size(); ++i) {       if (s[i] ==  h ) {         dp[0] += a[i];       }       if (s[i] ==  a ) {         dp[1] = min(dp[1] + a[i], dp[0]);       }       if (s[i] ==  r ) {         dp[2] = min(a[i] + dp[2], dp[1]);       }       if (s[i] ==  d ) {         dp[3] = min(a[i] + dp[3], dp[2]);       }     }     cout << dp[3] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long A[100010];   long long B[100010];   priority_queue<long long> pq;   set<int> S;   int P[100010];   long long ans[100010];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &A[i]);     B[0] = 0LL;     for (int i = 1; i <= n; i++) B[i] = B[i - 1] + A[i];     for (int i = 0; i < n; i++) scanf( %d , &P[i]);     ans[n - 1] = 0;     for (int i = 1; i <= n; i++) S.insert(i);     S.insert(0);     S.insert(n + 1);     set<int>::iterator L, R;     long long best = 0;     for (int i = n - 2; i >= 0; i--) {       int p = P[i + 1];       S.erase(p);       R = S.lower_bound(p);       L = R;       L--;       long long v = B[(*R) - 1] - B[*L];       best = max(best, v);       ans[i] = best;     }     for (int i = 0; i < n; i++) printf( %I64d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class X, class Y>   bool minimize(X &x, const Y &y) {     X eps = 1e-9;     if (x > y + eps) {       x = y;       return true;     } else       return false;   }   template <class X, class Y>   bool maximize(X &x, const Y &y) {     X eps = 1e-9;     if (x + eps < y) {       x = y;       return true;     } else       return false;   }   template <class T>   T Abs(const T &x) {     return (x < 0 ? -x : x);   }   char s[300300];   int n;   bool ok(int l, int r) {     for (int k = (1), _b = ((r - l + 1) / 2); k <= _b; k++)       for (int i = (l + k), _b = (r - k); i <= _b; i++)         if (s[i] == s[i - k] && s[i] == s[i + k]) return true;     return false;   }   void process(void) {     scanf( %s , s + 1);     n = strlen(s + 1);     long long res = 0;     for (int i = (1), _b = (n); i <= _b; i++) {       if (i + 11 <= n) res += n - (i + 11) + 1;       for (int j = (i), _b = (n); j <= _b; j++) {         if (j > i + 10) break;         if (ok(i, j)) res++;       }     }     cout << res << endl;   }   int main(void) {     process();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) cin >> a[i];     vector<long long> pref(n + 1);     for (long long i = 0; i < n; i++) pref[i + 1] = pref[i] + a[i];     long long ans = lower_bound(pref.begin(), pref.end(), (pref[n] + 2 - 1) / 2) -                     pref.begin();     cout << ans <<   n ;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     std::string s;     std::cin >> s;     std::string_view view = s;     size_t n = 0;     while (!view.empty()) {       const size_t id = view.find( > ) + 1;       const auto tag = view.substr(0, id);       view.remove_prefix(id);       if (tag[1] ==  / ) {         n -= 2;       }       std::cout << std::string(n,    ) << tag <<   n ;       if (tag[1] !=  / ) {         n += 2;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     if (n > m) {       swap(n, m);     }     if (n > 3) {       cout << ((n * m / 2) * 2);     } else {       if (n == 3) {         cout << m * n / 2 * 2;         return 0;       } else {         if (n == 2) {           if (m == 2) {             cout << 0;             return 0;           }           if (m == 3) {             cout << 4;             return 0;           }           if (m == 7) {             cout << 12;             return 0;           }           cout << n * m;         } else {           long long x = m % 6;           long long c = m / 6 * 6;           if (x == 4) {             c += 2;           }           if (x == 5) {             c += 4;           }           cout << c;           return 0;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100010], b[100010];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %1d , &a[i]);       b[i] = b[i - 1] + a[i];     }     for (int i = 1; i + k - 1 <= n; i++) {       int sum = b[i - 1] + b[n] - b[i + k - 1];       if (sum == 0 || sum == (i - 1 + n - (i + k - 1))) {         puts( tokitsukaze );         return 0;       }     }     if (2 * k >= n && k != 1) {       bool flag = true;       for (int i = 2; i + k - 1 < n; i++) {         int sum1 = b[i - 1];         int sum2 = b[n] - b[i + k - 1];         if (sum1 == 0 && sum2 == (n - (i + k - 1))) {           continue;         }         if (sum2 == 0 && sum1 == (i - 1)) {           continue;         }         flag = false;       }       if (flag) {         puts( quailty );         return 0;       }     }     puts( once again );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, j, s;   int k[100000], a[100000], b[100000];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> k[i];     for (int i = 0; i < m; i++) {       int x, y, z;       cin >> x >> y;       if (x == 1) {         cin >> z;         k[y - 1] = z;         a[y - 1] = s;       }       if (x == 2) s += y;       if (x == 3) {         b[j] = k[y - 1] + s - a[y - 1];         j++;       }     }     for (int i = 0; i < j; i++) cout << b[i] << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   char s[N];   int a[N], sta[N], tp;   int main() {     scanf( %s , s + 1);     int n = strlen(s + 1);     for (int i = 1; i <= n; ++i)       if (s[i] ==  0 ) {         if (tp) a[sta[tp--]] = 1;       } else         sta[++tp] = i;     for (int i = 1; i <= n; ++i) printf( %d , a[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, n1, n2;     cin >> n >> n1 >> n2;     int A[n], i;     for (i = 0; i < n; ++i) cin >> A[i];     sort(A, A + n, std::greater<int>());     int a, b;     if (n1 < n2) {       a = n1;       b = n2;     } else {       a = n2;       b = n1;     }     double ans1 = 0, ans2 = 0;     for (i = 0; i < a; ++i) ans1 += A[i];     ans1 = ans1 / (double)a;     for (; i < a + b; ++i) ans2 += A[i];     ans2 = ans2 / (double)b;     printf( %.8lf n , ans1 + ans2);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string x;     cin >> x;     long long step[101];     step[0] = 1;     for (int i = 1; i < 101; i++) step[i] = (step[i - 1] * 2) % ((int)1e9 + 7);     long long ans = 0;     for (int i = 0; i < x.size(); i++)       if (x[i] ==  1 ) ans = (ans + step[x.size() - i - 1]) % ((int)1e9 + 7);     for (int i = 0; i < x.size() - 1; i++) ans = (ans * 2) % ((int)1e9 + 7);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:1024000000,1024000000 )   const int INF = 0x3f3f3f;   const long long mod = 1e9 + 7;   const int MAXN = 1055;   const double eps = 1e-6;   const double pi = acos(-1.0);   using namespace std;   int main() {     long long n, t;     cin >> n >> t;     double x = 1.000000011;     double ans = 1.0;     for (long long i = t; i; i = i >> 1, x *= x)       if (i & 1) ans *= x;     printf( %.6f n , ans * n);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,inline,unroll-loops,fast-math )   #pragma GCC optimize( O3 )   using namespace std;   using namespace std::chrono;   long long mod_exp(long long x, long long n) {     long long res = 1;     while (n > 0) {       if (n & 1) res = (res * x) % 1000000007;       x = (x * x) % 1000000007;       n >>= 1;     }     return res;   }   void inout() {     freopen( in.txt ,  r , stdin);     freopen( out.txt ,  w , stdout);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long k;     cin >> k;     long long x = 9;     for (long long i = 1;; i++) {       if (k <= (i * x)) {         x = (x / 9) + (--k / i);         while (++k % i) x /= 10;         cout << x % 10;         exit(0);       }       k -= (i * x);       x *= 10;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n;     map<int, int> uchs;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (uchs.find(x) != uchs.end()) {         (uchs.at(x))++;       } else         uchs.insert(pair<int, int>(x, 1));     }     cin >> m;     vector<int> films;     films.reserve(m);     int max = 0;     for (int j = 0; j < m; j++) {       int x;       cin >> x;       if (uchs.find(x) != uchs.end()) {         if (uchs.at(x) > max) {           films.clear();           max = uchs.at(x);           films.push_back(j);         } else if (uchs.at(x) == max) {           films.push_back(j);         }       } else if (max == 0) {         films.push_back(j);       }     }     int kinco = films[0] + 1;     int newmax = 0;     int r = 0;     for (int j = 0; j < m; j++) {       int x;       cin >> x;       if (films[r] == j) {         r++;         if (uchs.find(x) != uchs.end()) {           if (uchs.find(x)->second > newmax) {             kinco = j + 1;             newmax = uchs.find(x)->second;           }         }         if (r == films.size()) break;       }     }     cout << kinco;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int T, n, head[300005], cnt, in[300005], ans, rt;   struct edge {     int to, nxt;   } e[300005 << 1];   void add(int u, int v) {     e[++cnt] = (edge){v, head[u]};     head[u] = cnt;   }   void dfs(int u, int fa, int tot) {     if (tot > ans) ans = tot, rt = u;     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (v == fa) continue;       dfs(v, u, tot + in[v]);     }   }   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       cnt = 0;       for (int i = 1; i <= n; i++) head[i] = 0, in[i] = -1;       for (int i = 1, u, v; i < n; i++) {         scanf( %d%d , &u, &v);         add(u, v);         add(v, u);         in[u]++;         in[v]++;       }       ans = -1;       dfs(1, 0, in[1]);       ans = -1;       dfs(rt, 0, in[rt]);       printf( %d n , ans + 2);     }   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 1e5 + 10;   int n, a[MX], out[MX], mn[MX];   int bs(int L, int R, int val) {     if (R - L == 1) return L;     int mid = (R + L) / 2;     if (val <= mn[mid])       return bs(L, mid, val);     else       return bs(mid, R, val);   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     mn[n - 1] = a[n - 1];     for (int i = n - 2; i >= 0; --i) mn[i] = min(mn[i + 1], a[i]);     for (int i = n - 1; i >= 0; --i) {       if (mn[i] == a[i])         out[i] = -1;       else {         int x = bs(i + 1, n, a[i]);         out[i] = x - i - 1;       }     }     for (int i = 0; i < n; ++i) cout << out[i] <<    ;   }
#include <bits/stdc++.h>   int main() {     int i, j, l, n, k, good;     static int a[6][1001], dp0[1001], dp1[1001], pp[6][1001];     scanf( %d%d , &n, &k);     for (i = 1; i <= k; i++)       for (j = 1; j <= n; j++) {         scanf( %d , &a[i][j]);         if (i == 1)           pp[1][a[i][j]] = j;         else {           a[i][j] = pp[1][a[i][j]];           pp[i][a[i][j]] = j;         }       }     dp0[1] = 0;     dp1[1] = 1;     for (i = 2; i <= n; i++) {       dp0[i] = dp0[i - 1] > dp1[i - 1] ? dp0[i - 1] : dp1[i - 1];       dp1[i] = 1;       for (j = 0; j < i; j++) {         good = 1;         for (l = 2; l <= k; l++)           if (pp[l][j] > pp[l][i]) {             good = 0;             break;           }         if (good && dp1[i] < dp1[j] + 1) dp1[i] = dp1[j] + 1;       }     }     printf( %d n , dp0[n] > dp1[n] ? dp0[n] : dp1[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long dx[] = {-1, 0, 1, 0};   long long dy[] = {0, -1, 0, 1};   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     vector<pair<long long, long long> > v(m);     for (long long i = 0; i < m; i++) {       cin >> v[i].second >> v[i].first;     }     sort(v.rbegin(), v.rend());     long long ans = v[0].first;     for (long long k = 2; k <= m; k++) {       if (max((k * (k - 1)) / 2 + 1, k * (k / 2)) <= n)         ans += v[k - 1].first;       else         break;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e6 + 3;   const long long INFF = (long long)1e18;   int cnt[N];   bool ck[N];   int main() {     for (int i = 2; i < N; i++) {       if (ck[i]) continue;       for (int j = i; j < N; j += i) ck[j] = true;       cnt[i]++;       if (i <= 1000) {         cnt[i * i]--;       }     }     cnt[1] = 1;     for (int i = 1; i < N; i++) cnt[i] += cnt[i - 1];     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       printf( %d n , cnt[n]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string b;       cin >> b;       if (b.length() < 4) {         cout << b <<   n ;         continue;       }       cout << b[0];       for (int i = 1; i < b.length(); i += 2) {         cout << b[i];       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       string s;       int n, s2 = 0, ans = 0, s1 = 0;       cin >> s;       n = s.size() - 1;       for (int i = n; i >= 0; i--)         if (s[i] ==  1 ) {           s2 = i;           break;         }       for (int i = 0; i <= n; i++)         if (s[i] ==  1 ) {           s1 = i;           break;         }       for (int i = 0; i <= n; i++) {         if (i > s1 && i < s2 && s[i] ==  0 ) ans++;       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   queue<int> que;   vector<bool> init, goal;   vector<bool> visited;   vector<vector<int>> nodes;   void calculate(int root, bool flip1, bool flip2) {     const vector<int> &children = nodes[root];     visited[root] = true;     if (init[root] ^ flip1 != goal[root]) {       que.push(root + 1);       for (auto c : children) {         if (visited[c]) continue;         calculate(c, flip2, !flip1);       }     } else {       for (auto c : children) {         if (visited[c]) continue;         calculate(c, flip2, flip1);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     nodes.resize(n);     for (int i = 0; i < n - 1; ++i) {       int p, c;       cin >> c >> p;       nodes[p - 1].push_back(c - 1);       nodes[c - 1].push_back(p - 1);     }     init.resize(n);     for (int i = 0; i < n; ++i) {       int b;       cin >> b;       init[i] = b;     }     goal.resize(n);     for (int i = 0; i < n; ++i) {       int b;       cin >> b;       goal[i] = b;     }     visited.resize(n, false);     calculate(0, false, false);     cout << que.size() << endl;     while (!que.empty()) {       cout << que.front() << endl;       que.pop();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     for (; b; a %= b, swap(a, b))       ;     return a;   }   int n, m;   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     cin >> n >> m;     vector<vector<int> > board(n, vector<int>(m));     for (auto& it : board)       for (auto& jt : it) cin >> jt;     long long ans = 0;     for (int j = 0; j < m; j++) {       map<int, int> mp;       for (int i = 0; i < n; i++) {         if (board[i][j] % m != (j + 1) % m) continue;         if (board[i][j] > n * m) continue;         int orgin = m * i + j + 1;         int dif = orgin - board[i][j];         if (dif < 0) dif += n * m;         dif /= m;         mp[dif]++;       }       int minVal = n;       for (auto& it : mp) {         minVal = min(minVal, it.first + n - it.second);       }       ans += minVal;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int k, n;     cin >> n >> k;     if (n == 2) return cout << 2 <<     << 1 <<     << 2 << endl, 0;     int ans1, ans2;     int l = 1, r = n;     while (l < r) {       int mid = (l + r) / 2;       cout << 1 <<     << mid <<     << mid + 1 << endl;       string s;       cin >> s;       if (s ==  NIE )         l = mid + 1;       else         r = mid;     }     ans1 = l;     if (ans1 != n) {       l = ans1 + 1, r = n;       bool good = 0;       while (l < r) {         int mid = (l + r) / 2;         cout << 1 <<     << mid <<     << mid + 1 << endl;         string s;         cin >> s;         if (s ==  NIE )           l = mid + 1;         else {           r = mid;         }       }       ans2 = r;       cout << 1 <<     << ans2 <<     << ans1 << endl;       string s;       cin >> s;       if (s !=  NIE ) return cout << 2 <<     << ans1 <<     << ans2 << endl, 0;     }     l = 1, r = ans1 - 1;     while (l < r) {       int mid = (l + r) / 2;       cout << 1 <<     << mid <<     << mid + 1 << endl;       string s;       cin >> s;       if (s ==  NIE )         l = mid + 1;       else {         r = mid;       }     }     ans2 = r;     cout << 2 <<     << ans1 <<     << ans2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int const sz = 2 * 1e5;   int const oo = 1e9;   bool comp(int i, int j) { return i < j; }   long long num[1000000], kk[101];   void fill(int n, int m) {     long long arr[4] = {0, 1, 2, 3};     int l = 0;     num[0] = 1;     num[1] = 2;     num[2] = 3;     for (int i = 3; i < n; i++) {       arr[(l % 3) + 1] = ((arr[1] + arr[2] + arr[3]) % m) + 1;       num[i] = arr[(l++ % 3) + 1];       if (num[i] < 101) kk[num[i]]++;     }   }   long long check(long long m, int k) {     long long a = 1;     long long sum = 0;     while (m / a > 0) {       sum = sum + (m / a);       a *= k;     }     return sum;   }   void solve() {     long long n, k;     cin >> n >> k;     long long l = 0, r = n;     while (l < r - 1) {       long long m = (l + r) / 2;       if (check(m, k) >= n)         r = m;       else         l = m;     }     cout << r;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     solve();   }
#include <bits/stdc++.h>   using namespace std;   int f[100005], s[100005];   int main() {     int n, k, inp;     scanf( %d %d , &n, &k);     for (int i = 1; i < k + 1; i++) {       scanf( %d , &inp);       s[inp] = i;       if (!f[inp]) f[inp] = i;     }     int ans = 0;     for (int i = 1; i < n + 1; i++) {       if (!f[i]) {         ans += 3;         if (i == 1 || i == n) ans--;         continue;       }       int b = i - 1;       if (b >= 1 && s[b] < f[i]) ans++;       b = i + 1;       if (b <= n && s[b] < f[i]) ans++;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, m, k;       cin >> n >> m >> k;       long long cnt = n / k;       if (m <= cnt)         cout << m <<   n ;       else {         long long cntt = (m - cnt + k - 2) / (k - 1);         cout << (cnt - cntt) <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   const int N = 1001002;   int a, b, c, d, i, j, n, m, k, tot, now, last;   int nx[N][26], sib[N], pr[N], fir[N];   int cnt[N], en[N];   char str[502];   int num[2][N];   int dp[2][2002][2002];   vector<int> lev[503];   int dfs(int v, int h = 0) {     lev[h].push_back(v);     for (int _n((26) - 1), i(0); i <= _n; i++) {       if (nx[v][i] != -1) cnt[v] += dfs(nx[v][i], h + 1);     }     return cnt[v];   }   inline int g(int v, int c) {     if (c < 0) return -1000000000;     if (v == -1 && !c) return 0;     if (v == -1) return -1000000000;     if (!c) return 0;     return dp[last][num[last][v]][c];   }   inline int f(int v, int c) {     if (c < 0) return -1000000000;     if (v == -1 && !c) return 0;     if (v == -1) return -1000000000;     if (!c) return 0;     return dp[now][num[now][v]][c];   }   int rec(int v, int c) {     if (c < 0) return -1000000000;     if (v == -1 && !c) return 0;     if (v == -1) return -1000000000;     if (!c) return 0;     int ans = 0, fr = cnt[v] - en[v];     for (int i = (min(cnt[v], c)), _b = (0); i >= _b; i--) {       int lf = c - i;       if (lf && sib[v] == -1) break;       int v1 = g(fir[v], min(fr, i));       if (v1 < 0) continue;       int v2 = f(sib[v], lf);       if (v2 < 0) continue;       ans = max(ans, i * (i - 1) / 2 + v1 + v2);     }     return dp[now][num[now][v]][c] = ans;   }   int main() {     memset(nx, -1, sizeof(nx));     pr[0] = -1;     k = 1;     scanf( %d%d , &n, &tot);     for (int _n((n)-1), i(0); i <= _n; i++) {       scanf( %s , str);       m = (int)strlen(str);       a = 0;       for (int _n((m)-1), i(0); i <= _n; i++) {         if (nx[a][str[i] -  a ] == -1) {           nx[a][str[i] -  a ] = k++;           pr[k - 1] = a;         }         a = nx[a][str[i] -  a ];       }       ++cnt[a];       ++en[a];     }     for (int _n((k)-1), i(0); i <= _n; i++) {       fir[i] = -1;       for (int j = (25), _b = (0); j >= _b; j--) {         if (nx[i][j] == -1) continue;         sib[nx[i][j]] = fir[i];         fir[i] = nx[i][j];       }     }     dfs(0);     memset((dp), 0, sizeof(dp));     now = 0, last = 1;     for (int h = (500), _b = (1); h >= _b; h--) {       if (lev[h].empty()) continue;       now ^= 1;       last ^= 1;       for (int _n(((int)((lev[h]).size())) - 1), i(0); i <= _n; i++)         num[now][lev[h][i]] = i;       for (int i = ((int)((lev[h]).size()) - 1), _b = (0); i >= _b; i--) {         int v = lev[h][i], p = pr[v];         for (int _n((k + 1) - 1), j(0); j <= _n; j++) {           if (j > cnt[p]) break;           rec(v, j);         }       }     }     int ans = dp[now][0][tot];     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     string n;     int k;     cin >> n >> k;     int ans = 0;     int p = 0;     for (auto it = n.rbegin(); p < k && it != n.rend();) {       if (*it !=  0 ) {         ++ans;         n.erase((++it).base());       } else {         ++it;         ++p;       }     }     for (auto it = n.begin(); it != n.end() && it + 1 != n.end(); ++it) {       if (*it ==  0 ) {         ++ans;       } else {         break;       }     }     cout << ans << endl;     return 0;   }