using System; using System.Linq; public class MyClass { public static void Main() { var array = Array.ConvertAll(Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries), int.Parse); int N = array[0]; int K = array[1]; var str = Console.ReadLine(); var strNew = str; int cnt = 0; for (int i = 0; i < str.Length; i++) { cnt--; cnt = Math.Max(cnt, 0); cnt += str[i] - '0'; }//for i for (int i = 0; i < strNew.Length; i++) { if (cnt > 0 && strNew[i] == '0' || strNew[i] == '2') { if (strNew[i] == '0') { cnt--; }//if else { cnt++; }//else strNew = strNew.Substring(0, i) + "1" + strNew.Substring(i + 1); }//if }//for i long res = Count(str, Math.Min(str.Length, K)); res += (K - str.Length) / str.Length * strNew.Count(x => x == '0'); res += Count(strNew, (K - str.Length > 0 ? K % str.Length : 0)); Console.WriteLine(res); } private static int Count(string str, int need) { int res = 0; int cnt = 0; for (int i = 0; i < need; i++) { cnt--; if (cnt < 0) { res++; cnt++; }//if cnt += str[i] - '0'; }//for i return res; } }