#include "bits/stdc++.h" using namespace std; #define DEBUG(x) cout<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair const int inf = 1000000001; const ll INF = 1e16; #define MOD 1000000007 #define mod 1000000009 #define pi 3.14159265358979323846 #define Sp(p) cout<> n >> k; string s; cin >> s; string s2 = s + s; vector cnst(2 * n + 1); for (i = 0; i < 2 * n; i++) { cnst[i + 1] = cnst[i]; if (cnst[i].second == 0) { cnst[i + 1].first++; } else { cnst[i + 1].second--; } cnst[i + 1].second += s2[i] - '0'; } if (k <= 2 * n) { cout << cnst[k].first << endl; return 0; } int firstcnt = cnst[n].first; int firststock = cnst[n].second; int secondcnt = cnst[2 * n].first; int secondstock = cnst[2 * n].second; // DEBUG(firstcnt); // DEBUG(firststock); // DEBUG(secondcnt); // DEBUG(secondstock); if (firststock == secondstock) { int ans = firstcnt; int nokori = k - n; ans += nokori / n * (secondcnt - firstcnt); nokori %= n; ans += cnst[nokori].first; int stock = secondstock; if (stock > 0) { for (i = 0; i < nokori; i++) { if (cnst[i].second == 0) { ans--; stock--; if (stock == 0) { break; } } } } cout << ans << endl; return 0; } else { string S; for (i = 0; i < 60; i++) { S += s; } int stock = 0, cnt = 0; i = 0; while (stock < 55 && i < k) { if (stock == 0) { cnt++; } else { stock--; } stock += S[i] - '0'; i++; } cout << cnt << endl; return 0; } }