#ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG //[]で配列外参照をするとエラーにしてくれる。上下のやつがないとTLEになるので注意 ABC311Eのサンプル4みたいなデバック中のTLEは防げないので注意 #endif #include #include #include // M_PIを使用するため #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rrep(i, n) for (ll i = (ll)n - 1; i >= 0; --i) const ll INF = (1LL << 62); const ll null = -1LL; template using vc = vector; // prioriy_queueに必要なのでここにこれ書いてます template using vv = vc>; template using vvv = vv>; using vl = vc; using vvl = vv; using vvvl = vv; using vvvvl = vv; using vs = vc; using vvs = vv; using vb = vc; using vvb = vc; using P = pair; template istream &operator>>(istream &i, vc &v) { rep(j, size(v)) i >> v[j]; return i; } // それぞれ「下,上,右,左」に対応 int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; #define nall(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() template bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } #define pb push_back #define eb emplace_back #define em emplace #define pob pop_back #define next_p(v) next_permutation(v.begin(), v.end()) void solve() { ll n, a; cin >> n >> a; string s; cin >> s; vl cnt(2,0); ll start = 1200; ll sum = 0; rep(i,n) { cnt[(ll)(s[i] - '0')]++; if (s[i] == '1') { if (start < 1200ll) ++sum; start = min(start + 1ll, 1200ll); } else --start; if (sum == a) { cout << i + 1ll << endl; return; } } ll num = (a - sum - 1ll) / min(cnt[0],cnt[1]); ll ans = (num + 1ll) * n, rest = a - sum - min(cnt[0],cnt[1]) * num; if (cnt[0] < cnt[1]) { for (char c : s) { ++ans; if (c == '1') { if (start < 1200ll) --rest; start = min(start + 1ll, 1200ll); } else --start; if (rest <= 0) { break; } } } else { for (char c : s) { ++ans; if (c == '1') --rest; if (rest <= 0) { break; } } } cout << ans << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll testcases = 1ll; // cin >> testcases; rep(_, testcases) solve(); return 0; }