#include #include #include #include #include #include #include #include #include // require sort next_permutation count __gcd reverse etc. #include // require abs exit atof atoi #include // require scanf printf #include #include // require accumulate #include // require fabs #include #include #include #include // require setw #include // require stringstream #include // require memset #include // require tolower, toupper #include // require freopen #include // require srand #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() using namespace std; typedef long long ll; typedef pair P; // シミュレーションで求める string smulation (int & lucky, int & eaten, int & buy, string S, int N, int K ){ string res = ""; for (int i = 0; i < N; i++ ){ int curr = (S[i] - '0' ); // 現在のアイスバーの判定 if (lucky > 0 ){ res += 'x';//cerr << 'x'; アイスバーを買わなくて良い lucky--; }else{ res += 'o';//cerr << 'o'; アイスバーを買う必要がある buy++; } // end if eaten++; if (eaten == K ){ return res; } // end if lucky += curr; } // end for return res; } int solve (int N, int K, string S ){ int lucky = 0, eaten = 0, buy = 0; int res = 0; string t = smulation (lucky, eaten, buy, S, N, K ); res += buy; // cerr << t << " buy: " << buy << " lucky: " << lucky << endl; if (N < K ){ rep (i, N ) if (t[i] == 'o' && lucky ) t[i] = 'x', lucky--; // cerr << t << endl; res += (int)count (ALL (t ), 'o' )*(K/N-1); if(K % N != 0 ){ res += (int)count (t.begin(), t.begin()+(K%N), 'o' ); } // end if } // end if return res; } int main() { ios_base::sync_with_stdio(0); int N, K; cin >> N >> K; string S; cin >> S; int res = solve (N, K, S ); cout << res << endl; return 0; }