description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) a = [char for char in input()] pointer_esquerda = 0 pointer_direita = 0 mov = k len_maior = 0 len_atual = 0 while pointer_esquerda <= n - 1: while mov >= 0 and pointer_direita <= n - 1: if a[pointer_direita] == "b" and mov - 1 >= 0: mov -= 1 pointer_direita += 1 len_atual += 1 if len_atual > len_maior: len_maior = len_atual elif a[pointer_direita] == "a": pointer_direita += 1 len_atual += 1 if len_atual > len_maior: len_maior = len_atual elif mov - 1 < 0: break if a[pointer_esquerda] == "b": mov += 1 len_atual -= 1 if len_atual > len_maior: len_maior = len_atual pointer_esquerda += 1 len_atual = 0 pointer_esquerda = 0 pointer_direita = 0 mov = k while pointer_esquerda <= n - 1: while mov >= 0 and pointer_direita <= n - 1: if a[pointer_direita] == "a" and mov - 1 >= 0: mov -= 1 pointer_direita += 1 len_atual += 1 if len_atual > len_maior: len_maior = len_atual elif a[pointer_direita] == "b": pointer_direita += 1 len_atual += 1 if len_atual > len_maior: len_maior = len_atual elif mov - 1 < 0: break if a[pointer_esquerda] == "a": mov += 1 len_atual -= 1 if len_atual > len_maior: len_maior = len_atual pointer_esquerda += 1 print(len_maior)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR STRING BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR STRING BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = [int(i) for i in input().split()] s = input() def beauty(x): ret = 0 cnt = 0 r = 0 for l in range(n): while r < n and (cnt < k or s[r] != x): if s[r] == x: cnt += 1 r += 1 if s[l] == x: cnt -= 1 ret = max(ret, r - l) return ret print(max(beauty("a"), beauty("b"))) exit(0)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
MOD = 1000000007 MOD2 = 998244353 ii = lambda: int(input()) si = lambda: input() dgl = lambda: list(map(int, input())) f = lambda: map(int, input().split()) il = lambda: list(map(int, input().split())) ls = lambda: list(input()) n, k = f() s = si() k1, k2 = k, k mx = 0 i, j = 0, 0 while j < n: while j < n: if s[j] == "b": if k1 > 0: k1 -= 1 else: break j += 1 mx = max(mx, j - i) while i < j: if s[i] == "b": break i += 1 i += 1 k1 += 1 i, j = 0, 0 while j < n: while j < n: if s[j] == "a": if k2 > 0: k2 -= 1 else: break j += 1 mx = max(mx, j - i) while i < j: if s[i] == "a": break i += 1 i += 1 k2 += 1 print(mx)
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR WHILE VAR VAR IF VAR VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR WHILE VAR VAR IF VAR VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() def solve(x, y): res, j, t = 0, 0, k for i in range(n): if j < i: j = i t = k while j < n and (s[j] == x or s[j] == y and t > 0): t -= int(s[j] == y) j += 1 res = max(res, j - i) t += int(s[i] == y) return res print(max(solve("a", "b"), solve("b", "a")))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING STRING FUNC_CALL VAR STRING STRING
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def answer(n, k, A): if n == 1: return 1 dp = [0] * (n + 1) for i in range(1, n + 1): if A[i - 1] == "a": dp[i] = dp[i - 1] + 1 else: dp[i] = dp[i - 1] l = 0 r = 0 maxi = 0 while r >= l and r < n: x = dp[r + 1] - dp[l] if min(x, r + 1 - l - x) <= k: r += 1 else: maxi = max(maxi, r - l) l += 1 maxi = max(maxi, r - l) return maxi n, k = map(int, input().split()) A = input() print(answer(n, k, A))
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() d = {"a": 0, "b": 0} l = 0 a = 0 for i in s: d[i] += 1 if min(d.values()) > k: d[s[l]] -= 1 l += 1 else: a += 1 print(a)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
from sys import * inp = lambda: stdin.readline() def solve(x, s, n, k): ans, r, bal = 0, 0, 0 for l in range(n): while r < n and (s[r] == x or bal < k): if s[r] != x: bal += 1 r += 1 ans = max(ans, r - l) if s[l] != x: bal -= 1 return ans def main(): n, k = map(int, inp().split()) s = inp() print(max(solve("a", s, n, k), solve("b", s, n, k))) main()
ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING VAR VAR VAR FUNC_CALL VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
from sys import stdin, stdout def fn(a, ch): ans = 0 for i in range(n): l, r = i, n - 1 while l <= r: mid = l + r >> 1 req = a[i] + k - int(s[i] != ch) if a[mid] <= req: l = mid + 1 else: r = mid - 1 ans = max(ans, r - i + 1) return ans for _ in range(1): n, k = list(map(int, stdin.readline().split())) s = input() make_a = [] make_b = [] make_a += [int(s[0] == "a")] make_b += [int(s[0] == "b")] for i in range(1, n): make_a += [make_a[-1] + int(s[i] == "a")] make_b += [make_b[-1] + int(s[i] == "b")] ans = max(fn(make_a, "b"), fn(make_b, "a")) print(ans)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST VAR LIST FUNC_CALL VAR VAR NUMBER STRING VAR LIST FUNC_CALL VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR LIST BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR STRING VAR LIST BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
__author__ = "Utena" n, k = map(int, input().split()) s = ["0"] + list(input()) beauty = 0 i = 0 j = 0 a = 0 b = 0 while i < n: i += 1 if s[i] == "a": a += 1 if s[i] == "b": b += 1 while min(a, b) > k: j += 1 if s[j] == "a": a -= 1 if s[j] == "b": b -= 1 if i - j > beauty: beauty = i - j print(beauty)
ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() res = 1 i = -1 j = 0 cur = 0 while i < j <= n: if j == n and i == n - 1: break while cur <= k and j < n: if cur == k and s[j] == "b": break else: cur += s[j] == "b" j += 1 res = max(res, j - i - 1) if k > 0: if cur < k and i < j - 1: i += 1 cur -= s[i] == "b" while cur == k and i < j - 1: i += 1 cur -= s[i] == "b" else: i = j j = i + 1 res = max(res, j - i - 1) i = -1 j = 0 cur = 0 while i < j <= n: if j == n and i == n - 1: break while cur <= k and j < n: if cur == k and s[j] == "a": break else: cur += s[j] == "a" j += 1 res = max(res, j - i - 1) if k > 0: if cur < k and i < j - 1: i += 1 cur -= s[i] == "a" while cur == k and i < j - 1: i += 1 cur -= s[i] == "a" else: i = j j = i + 1 res = max(res, j - i - 1) print(res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR STRING VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR STRING WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR STRING VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR STRING WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
num = input() n, k = num.split() n = int(n) k = int(k) string = input() count_a = 0 count_b = 0 def check(ch): i = 0 j = 0 count = 0 answer = 0 for i in range(n): if string[i] == ch: count += 1 if count > k: while count > k: if string[j] == ch: count -= 1 j += 1 answer = max(answer, i - j + 1) return answer max_a = check("a") max_b = check("b") print(max(max_a, max_b))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = input().split(" ") n = int(n) k = int(k) s = input() def stack(s, more, less, k): flag = True count = k pos = [] maxsize = -1 decrement = 0 for index, ch in enumerate(s): if ch == less: if count > 0: count -= 1 pos.append(index) flag = True else: pos.append(index) if flag: decrement = 0 flag = False size = index - decrement else: decrement = pos.pop(0) size = index - decrement - 1 if size > maxsize: maxsize = size if index == len(s) - 1 and flag == False: size = index - pos.pop(0) if size > maxsize: maxsize = size elif index == len(s) - 1 and flag == True: maxsize = index + 1 return maxsize ans1 = stack(s, "a", "b", k) ans2 = stack(s, "b", "a", k) if ans1 > ans2: print(ans1) else: print(ans2)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR STRING STRING VAR ASSIGN VAR FUNC_CALL VAR VAR STRING STRING VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def bigsub(s, n, k, x): j = 0 i = 0 tmp = 0 ans = 0 ck = 0 while j < n and i < n: if s[j] != x: tmp += 1 j += 1 if tmp > ans: ans = tmp else: ck += 1 if ck <= k: j += 1 tmp += 1 if tmp > ans: ans = tmp else: while ck > k and i < n: if s[i] == x: ck -= 1 i += 1 tmp -= 1 ck -= 1 return ans n, k = map(int, input().split()) s = input() sol = max(bigsub(s, n, k, "b"), bigsub(s, n, k, "a")) print(sol)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
import sys inf = float("inf") mod = 1000000007 def get_array(): return list(map(int, sys.stdin.readline().split())) def get_ints(): return map(int, sys.stdin.readline().split()) def input(): return sys.stdin.readline() def solve(c, s, k): global ans r = 0 balance = 0 for i in range(len(s)): while r < len(s) and (s[r] == c or balance < k): if s[r] != c: balance += 1 r += 1 ans = max(ans, r - i) if s[i] != c: balance -= 1 return def main(): n, k = get_ints() s = input().strip() solve("a", s, k) solve("b", s, k) print(ans) global ans ans = 0 main()
IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER RETURN FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR STRING VAR VAR EXPR FUNC_CALL VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
import sys __author__ = "goran" n, k = map(int, sys.stdin.readline().split()) s = input() L, R = 0, 0 cnt = [0, 0] best = 1 while R < n: if ( min(cnt[ord(s[R][0]) - ord("a"[0])] + 1, cnt[1 - ord(s[R][0]) + ord("a"[0])]) > k ): cnt[ord(s[L][0]) - ord("a"[0])] -= 1 L += 1 else: cnt[ord(s[R][0]) - ord("a"[0])] += 1 R += 1 best = max(best, R - L) print(best)
IMPORT ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR STRING NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR STRING NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR STRING NUMBER NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR STRING NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def count(a, n, s, k): j = 0 kk = 0 ans = 0 for i in range(n): if a[i] == s: kk += 1 while kk > k: if a[j] == s: kk = kk - 1 j += 1 ans = max(ans, i - j + 1) return ans n, k = [int(i) for i in input().split()] a = list(input()) c = a.count("a") d = a.count("b") if d == 0 or d == k: print(n) elif k == 0: print(max(count(a, n, "a", k), count(a, n, "b", k))) elif d > c: print(count(a, n, "a", k)) else: print(count(a, n, "b", k))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING VAR FUNC_CALL VAR VAR VAR STRING VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) counta, countb = 0, 0 s = input() l, r = 0, 0 maxlength = 0 while r < n: if s[r] == "a": counta += 1 else: countb += 1 if counta <= k or countb <= k: maxlength = max(maxlength, r - l + 1) else: if s[l] == "a": counta -= 1 else: countb -= 1 l += 1 r += 1 print(maxlength)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() left, right = 0, 1 a = [] b = [] t1, t2 = 0, 0 for i in s: if i == "a": t1 += 1 else: t2 += 1 a.append(t1) b.append(t2) temp1 = 0 temp2 = 0 ans = 0 for i in s: if i == "a": temp2 = 0 temp1 += 1 ans = max(ans, temp1) else: temp1 = 0 temp2 += 1 ans = max(ans, temp2) while left < n and right < n: if left == 0: acount = a[right] bcount = b[right] else: acount = a[right] - a[left - 1] bcount = b[right] - b[left - 1] if acount > k and bcount > k: left += 1 else: ans = max(ans, right - left + 1) right += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def solve(i, j): alpha = {"a": 0, "b": 0} alpha[string[i]] += 1 alpha[string[j]] += 1 m = 0 while i < j < len(string): a = alpha["a"] b = alpha["b"] if a <= k or b <= k: m = max(m, j - i + 1) if a > k and b > k: alpha[string[i]] -= 1 i += 1 else: j += 1 if j < len(string): alpha[string[j]] += 1 return i, j, m n, k = map(int, input().split()) string = input() if "a" not in string or "b" not in string: print(n) else: i = 0 j = 1 m = 0 while i < j < len(string): i, j, m2 = solve(i, j) m = max(m, m2) if i == j: j += 1 print(m)
FUNC_DEF ASSIGN VAR DICT STRING STRING NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) a = input() ac = 0 bc = 0 ans = -1 s = 0 e = 0 if k == 0: while e < n: ac = 0 if a[e] == "a": while e < n and a[e] == "a": ac += 1 e += 1 else: while e < n and a[e] == "b": ac += 1 e += 1 ans = max(ans, ac) else: while e < n: if a[e] == "a": ac += 1 else: bc += 1 while min(ac, bc) > k: s += 1 if a[s - 1] == "a": ac -= 1 else: bc -= 1 ans = max(ans, e - s + 1) e += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER IF VAR VAR STRING WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = [*input()] a, b = [0], [0] for i in s: if i == "a": a.append(a[-1] + 1) b.append(b[-1]) else: a.append(a[-1]) b.append(b[-1] + 1) def check(m): for i in range(m, n + 1): if a[i] - a[i - m] <= k: return True if b[i] - b[i - m] <= k: return True return False i = 0 j = n while i <= j: m = (i + j) // 2 if check(m): i = m + 1 else: j = m - 1 print(j)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER LIST NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = list(input()) a, b = [], [] for i in range(n): if s[i] == "a": a.append(i) else: b.append(i) a = [-1] + a + [n] b = [-1] + b + [n] res = 0 if len(a) <= k + 2 or len(b) <= k + 2: print(n) else: for i in range(1, len(a) - k): res = max(res, a[i + k] - 1 - (a[i - 1] + 1) + 1) for i in range(1, len(b) - k): res = max(res, b[i + k] - 1 - (b[i - 1] + 1) + 1) print(res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def get_best(s, n, k, c): l = 0 r = 0 curr_k = k best = 0 while l < n and r < n: if s[r] == c: r += 1 elif curr_k > 0: curr_k -= 1 r += 1 else: if s[l] != c: curr_k += 1 l += 1 best = max(best, r - l + 1) return best - 1 n, k = map(int, input().split()) s = input() best_a = get_best(s, n, k, "a") best_b = get_best(s, n, k, "b") print(max(best_a, best_b))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
a, b = map(int, input().split()) d = input() e = 1 f = a + 1 a1 = [0] a2 = [0] for i in range(a): if d[i] == "a": a1.append(a1[-1] + 1) a2.append(a2[-1]) else: a2.append(a2[-1] + 1) a1.append(a1[-1]) def s1(i, j): return a1[j + 1] - a1[i] def s2(i, j): return a2[j + 1] - a2[i] def q(n): for i in range(0, a - n + 1): j = i + n - 1 x1 = s1(i, j) x2 = s2(i, j) if x1 <= b or x2 <= b: return True return False while e + 1 < f: g = (e + f) // 2 if q(g): e = g else: f = g if e == a - 1: v = d.count("a") if v <= b or a - v <= b: print(a) else: print(e) else: print(e)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def max_substring(s, ch, n, k): i, j = 0, 0 cnt = 0 best = 0 while j < n: if s[j] == ch: cnt += 1 if cnt > k: tmp = j - i if tmp > best: best = tmp while i < j and s[i] != ch: i += 1 i += 1 cnt -= 1 j += 1 tmp = j - i if tmp > best: best = tmp return n if cnt <= k and best == 0 else best n, k = map(int, input().split()) s = input() a = max_substring(s, "a", n, k) b = max_substring(s, "b", n, k) print(a if a > b else b)
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = list(input()) dp = [[(0) for i in range(2)] for i in range(n + 1)] aNum = 0 bNum = 0 a = [] b = [] for i in range(n): if s[i] == "a": aNum += 1 a.append(i) if aNum <= k: dp[i + 1][1] = i + 1 else: dp[i + 1][1] = a[aNum - 1] - a[aNum - 1 - k] if bNum <= k: dp[i + 1][0] = i + 1 else: dp[i + 1][0] = i - b[bNum - 1 - k] else: bNum += 1 b.append(i) if aNum <= k: dp[i + 1][1] = i + 1 else: dp[i + 1][1] = i - a[aNum - 1 - k] if bNum <= k: dp[i + 1][0] = i + 1 else: dp[i + 1][0] = b[bNum - 1] - b[bNum - 1 - k] ans = 0 for i in dp: ans = max(ans, max(i)) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def solve(middle, s, k): aa = 0 bb = 0 f = 0 for i in range(0, middle): if s[i] == "a": aa += 1 else: bb += 1 if min(aa, bb) <= k: f = 1 for i in range(0, len(s) - middle): if s[i] == "a": aa -= 1 else: bb -= 1 if s[i + middle] == "a": aa += 1 else: bb += 1 if min(aa, bb) <= k: f = 1 return f n, k = map(int, input().split()) s = str(input()) left = 1 right = n + 1 while left + 1 != right: middle = (left + right) // 2 if solve(middle, s, k): left = middle else: right = middle print(left)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def solve(n, k, l): ki = i = s = 0 po = 1 for j in range(n): s += l[j] == 0 while s > k: s -= l[i] == 0 i += 1 if j - i > ki - po: po, ki = i, j return ki - po + 1 n, k = map(int, input().split()) s = input() a1, a2 = [], [] for i in range(n): if s[i] == "a": a1.append(1) a2.append(0) else: a1.append(0) a2.append(1) print(max(solve(n, k, a1), solve(n, k, a2)))
FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
l1 = input().split() l2 = list(input()) l1 = [int(i) for i in l1] x = l1[0] y = l1[1] j = 0 c = 0 r = 0 for i in range(x): if l2[i] == "a": c += 1 if c > y: while c > y: if l2[j] == "a": c -= 1 j += 1 r = max(r, i - j + 1) lul = r j = 0 c = 0 r = 0 for i in range(x): if l2[i] == "b": c += 1 if c > y: while c > y: if l2[j] == "b": c -= 1 j += 1 r = max(r, i - j + 1) lul = max(lul, r) print(lul)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split(" ")) s = input() res = 0 i = 0 j = 0 h = 0 for l in s: i += 1 if l != "a": if h < k: h += 1 else: for u in range(j, i): if s[u] == "b": j = u + 1 break else: j = i res = max(res, i - j) i = 0 j = 0 h = 0 for l in s: i += 1 if l != "b": if h < k: h += 1 else: for u in range(j, i): if s[u] == "a": j = u + 1 break else: j = i res = max(res, i - j) print(res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR STRING IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR STRING IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def maxim(s, ch, k): res = 0 maxi = 0 c = 0 start = 0 kc = 0 for i in range(0, len(s)): if s[i] == ch: c += 1 else: kc += 1 c += 1 maxi = max(maxi, i - start) if kc > k else max(maxi, i - start + 1) while kc > k: if s[start] != ch: kc -= 1 c -= 1 start += 1 maxi = max(maxi, i - start) return maxi n, k = map(int, input().split()) s = input() print(max(maxim(s, "a", k), maxim(s, "b", k)))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR VAR STRING VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def count(): global ca, cb if s[r] == "a": ca += 1 else: cb += 1 n, k = map(int, input().split()) s = input() l = 0 r = 0 sm = 0 mx = 0 ca = 0 cb = 0 count() while l < n: while min(ca, cb) <= k: sm += 1 r += 1 if r == n: break count() if sm > mx: mx = sm if r == n: break if s[l] == "a": ca -= 1 else: cb -= 1 sm -= 1 l += 1 print(mx)
FUNC_DEF IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def solve(letter): i = 0 j = 0 k1 = 0 while j < n and k1 <= k: if s[j] != letter: k1 += 1 if k1 <= k: j += 1 best = j - i while i < n and j < n: if s[i] != letter: i += 1 if i < n: j = max(i, j) k1 = k - 1 while j < n and k1 <= k: if s[j] != letter: k1 += 1 if k1 <= k: j += 1 best = max(best, j - i) else: i += 1 return best n, k = list(map(int, input().split())) s = input() if k == 0: last = 0 best = 1 for i in range(1, n): if s[i] != s[i - 1]: best = max(best, i - last) last = i print(max(best, n - last)) else: print(max(solve("a"), solve("b")))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, m = map(int, input().split()) s = input() ans, a, b, c, l = 0, 0, 0, 0, 0 for i in s: if i == "a": a += 1 else: b += 1 if min(a, b) > m: if s[l] == "a": a -= 1 else: b -= 1 l += 1 else: ans += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def executa(n, k, letra, s): r = 0 tk = k p = 0 for i in range(n): while r < n and tk >= 0: if a[r] == letra: if tk == 0: break tk -= 1 r += 1 p += 1 s = max(s, p) p -= 1 if a[i] == letra: tk += 1 if r == n: break return s entrada = input() entrada_str = list(entrada.split(" ")) entrada_int = list(map(int, entrada_str)) n = entrada_int[0] k = entrada_int[1] a = input() soma = executa(n, k, "b", 0) soma = executa(n, k, "a", soma) print(soma)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER IF VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR STRING VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = list(map(int, input().split())) s = input() l = 0 f = 0 g = 0 m = 0 i = 0 while i < n: while min(f, g) <= k and i < n: if s[i] == "a": f += 1 else: g += 1 i += 1 if i == n and min(f, g) <= k: m = max(i - l, m) else: m = max(i - l - 1, m) if s[l] == "a": f -= 1 else: g -= 1 l += 1 print(m)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
s = input() s1 = s.split() K = int(s1[1]) s = input() i = 0 j = 0 k = K maxlen = 0 while j < len(s): if s[j] == "a": j = j + 1 elif k > 0: k = k - 1 j = j + 1 else: maxlen = max(maxlen, j - i) while k == 0: if s[i] == "b": k = k + 1 i = i + 1 maxlen = max(maxlen, len(s) - i) i = 0 j = 0 k = K while j < len(s): if s[j] == "b": j = j + 1 elif k > 0: k = k - 1 j = j + 1 else: maxlen = max(maxlen, j - i) while k == 0: if s[i] == "a": k = k + 1 i = i + 1 maxlen = max(maxlen, len(s) - i) print(maxlen)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() a = 0 b = 0 ff = -1 pp = 0 for i in range(n): if s[i] == "a": a += 1 else: b += 1 if min(a, b) <= k: ff = max(a + b, ff) else: if s[pp] == "a": a -= 1 else: b -= 1 pp += 1 if min(a, b) <= k: ff = max(a + b, ff) print(ff)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().strip().split()) s = input().strip() max_len = 0 def fun(letter): global max_len curr_len = swaps = l = 0 r = -1 while r < n - 1: r += 1 curr_len += 1 c = s[r] if c == letter: swaps += 1 while swaps > k: curr_len -= 1 posito = s[l] if posito == letter: swaps -= 1 l += 1 max_len = max(max_len, curr_len) fun("a") fun("b") print(max_len)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() ca = cb = 0 q = [] ans = 0 l = 0 r = 0 for i in s: if i == "a": ca += 1 else: cb += 1 r += 1 q.append(i) while l <= r and min(ca, cb) > k: if q[l] == "a": ca -= 1 else: cb -= 1 l += 1 ans = max(ans, r - l) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
s = input().split() n, k = int(s[0]), int(s[1]) s = input() ans = 0 k1 = k i1 = -1 i2 = 0 while i1 < n - 1: i1 += 1 if s[i1] == "b": if k1 > 0: k1 -= 1 else: while s[i2] != "b": i2 += 1 i2 += 1 if ans < i1 - i2: ans = i1 - i2 k1 = k i1 = -1 i2 = 0 while i1 < n - 1: i1 += 1 if s[i1] == "a": if k1 > 0: k1 -= 1 else: while s[i2] != "a": i2 += 1 i2 += 1 if ans < i1 - i2: ans = i1 - i2 print(ans + 1)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING IF VAR NUMBER VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING IF VAR NUMBER VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() i = 0 j = 0 a = 0 b = 0 ans = 0 while j < n: if s[j] == "a": a += 1 if s[j] == "b": b += 1 if a <= k or b <= k: ans = max(ans, a + b) else: if s[i] == "a": a -= 1 if s[i] == "b": b -= 1 i += 1 j += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) w = input() ans, i, j = 0, 0, -1 perm = k a, b = 0, 0 if k >= w.count("a") or k >= w.count("b"): ans = n else: while i < n: if i > 0: if w[i - 1] == "a": a -= 1 else: b -= 1 if w[i] == "a" and w[i] != w[i - 1]: perm = k - b elif w[i] == "b" and w[i] != w[i - 1]: perm = k - a while j + 1 < n: if w[j + 1] == w[i] and perm >= 0: if w[j + 1] == "a": a += 1 else: b += 1 j += 1 elif perm > 0: if w[j + 1] == "a": a += 1 else: b += 1 j += 1 perm -= 1 else: break if j - i + 1 > ans and perm >= 0: ans = j - i + 1 i += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING ASSIGN VAR VAR WHILE VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR STRING VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
from sys import stdin def magic(n, k, arr, ch, comp): last = 0 end = -1 temp = k i = 0 count = 0 while i < n: if arr[i] == ch: i += 1 count = max(count, i - last) elif temp > 0: temp -= 1 i += 1 count = max(count, i - last) else: end = end + 1 while arr[end] != comp and end < n: end += 1 last = end + 1 temp += 1 return count def myfunction(n, k, arr): return max(magic(n, k, arr, "a", "b"), magic(n, k, arr, "b", "a")) n, k = list(map(int, stdin.readline().split())) arr = list(stdin.readline()) print(myfunction(n, k, arr))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING STRING FUNC_CALL VAR VAR VAR VAR STRING STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = input().split() n = int(n) k = int(k) s = list(input()) ans1 = 0 ans2 = 0 a = [] b = [] if k != 0: for i in range(n): if s[i] == "a": a.append(i) else: b.append(i) if len(a) <= k: ans1 = n else: i = 0 j = k - 1 while j < len(a): ans = 0 if i == 0: ans += a[i] + 1 else: ans += a[i] - a[i - 1] if j == len(a) - 1: ans += a[j] - a[i] + n - 1 - a[j] else: ans += a[j] - a[i] + a[j + 1] - a[j] - 1 ans1 = max(ans, ans1) i += 1 j += 1 if len(b) <= k: ans2 = n else: i = 0 j = k - 1 while j < len(b): ans = 0 if i == 0: ans += b[i] + 1 else: ans += b[i] - b[i - 1] if j == len(b) - 1: ans += b[j] - b[i] + n - 1 - b[j] else: ans += b[j] - b[i] + b[j + 1] - b[j] - 1 ans2 = max(ans, ans2) i += 1 j += 1 print(max(ans1, ans2)) else: ans = 1 ans1 = 1 for i in range(n - 1): if s[i] == s[i + 1]: ans1 += 1 else: ans = max(ans, ans1) ans1 = 1 ans = max(ans, ans1) print(ans)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() l, r = 0, 0 a, b = 0, 0 def check(l, r, a, b, s): while l <= r: if min(a, b) <= k: return a, b, l, a + b else: if s[l] == "a": a -= 1 else: b -= 1 l += 1 return a, b, l, a + b ans = 0 while r < n: if s[r] == "b": b += 1 r += 1 else: r += 1 a += 1 t = check(l, r, a, b, s) l, a, b = t[2], t[0], t[1] ans = max(ans, t[3]) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF WHILE VAR VAR IF FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = list(map(int, input().split())) s = input() sums = [0] * (n + 1) for i in range(n): if s[i] == "a": sums[i] = sums[i - 1] + 1 else: sums[i] = sums[i - 1] l = 0 r = 0 def check_interval(l, r): length = r - l + 1 a_count = sums[r] - sums[l - 1] return a_count <= k or length - a_count <= k maxl = 1 while l < n: r = l + maxl while r < n and check_interval(l, r): r += 1 maxl += 1 l += 1 print(maxl)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) a = list(input()) ca = k i = 0 j = 0 aa = 0 ab = 0 ma = 0 mb = 0 while j < n: if a[j] == "a": j = j + 1 aa = aa + 1 elif a[j] == "b" and ca > 0: j = j + 1 aa = aa + 1 ca = ca - 1 else: if a[i] == "b": ca = ca + 1 i = i + 1 aa = aa - 1 if ma < aa: ma = aa ca = k i = 0 j = 0 while j < n: if a[j] == "b": j = j + 1 ab = ab + 1 elif a[j] == "a" and ca > 0: j = j + 1 ab = ab + 1 ca = ca - 1 else: if a[i] == "a": ca = ca + 1 i = i + 1 ab = ab - 1 if mb < ab: mb = ab print(max(ma, mb))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() p1 = 0 c = 0 maxi = -1 for p0 in range(n): p1 = max(p1, p0) while p1 < n and (s[p1] == "a" or c < k): if s[p1] == "b": c += 1 p1 += 1 maxi = max(maxi, p1 - p0) if s[p0] == "b": c -= 1 c = max(c, 0) p1 = 0 c = 0 for p0 in range(n): p1 = max(p1, p0) while p1 < n and (s[p1] == "b" or c < k): if s[p1] == "a": c += 1 p1 += 1 maxi = max(maxi, p1 - p0) if s[p0] == "a": c -= 1 c = max(c, 0) print(maxi)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR VAR STRING VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR VAR STRING VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def occurence_list(string): o = [[(0) for i in range(2)] for j in range(len(string))] for i, j in enumerate(string): o[i][ord(j) - ord("a")] += 1 for i in range(1, len(string)): for j in range(0, 2): o[i][j] += o[i - 1][j] return o def freq(o, l, r, target): if l == 0: return o[r][ord(target) - ord("a")] else: return o[r][ord(target) - ord("a")] - o[l - 1][ord(target) - ord("a")] n, k = list(map(int, input().split())) s = input() if n == 1: print(1) else: l = 0 r = 0 o = occurence_list(s) maxm_l = 1 curr_l = 1 while l <= r: if r == n - 1: break if ( min(r + 2 - l - freq(o, l, r + 1, "a"), r + 2 - l - freq(o, l, r + 1, "b")) <= k ): r += 1 curr_l += 1 maxm_l = max(curr_l, maxm_l) else: if l == r: r += 1 l += 1 curr_l = r + 1 - l maxm_l = max(curr_l, maxm_l) print(maxm_l)
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING RETURN BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING BIN_OP BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) text = input() + "0" forward = dump = 0 if len(text) == 1: print(1) quit() def m(a, r): begin = 0 end = 0 maximum = 0 while end != len(text) - 1: if text[end] != a: if r > 0: r -= 1 end += 1 else: while text[begin] == a: begin += 1 begin += 1 r += 1 else: end += 1 if end - begin > maximum: maximum = end - begin return maximum print(max(m("a", k), m("b", k)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) txt = list(input()) l = 0 r = 0 countA = 0 countB = 0 ans = 1 while r <= n - 1: if txt[r] == "a": countA += 1 else: countB += 1 change = min(countA, countB) if change <= k: ans = max(r - l + 1, ans) else: if txt[l] == "a": countA -= 1 else: countB -= 1 l += 1 change = min(countA, countB) if change <= k: ans = max(r - l + 1, ans) r += 1 r -= 1 while l <= n - 1: if txt[l] == "a": countA -= 1 else: countB -= 1 change = min(countA, countB) if change <= k: ans = max(r - l + 1, ans) l += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() l, r = 0, -1 cnt = 0 ans = 0 while l != n: while ( r + 1 != n and min(cnt + int(s[r + 1] == "a"), r - l + 2 - (cnt + int(s[r + 1] == "a"))) <= k ): r += 1 cnt += int(s[r] == "a") ans = max(ans, r - l + 1) cnt -= int(s[l] == "a") l += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() prefix_a = [0] * (n + 1) for i in range(1, n + 1): if s[i - 1] == "b": prefix_a[i] = 1 prefix_a[i] = prefix_a[i] + prefix_a[i - 1] dic = {} ans = -1 dic.update({(0): 0}) for i in range(1, n + 1): if prefix_a[i] <= k: ans = max(ans, i) else: last = dic.get(prefix_a[i] - k, -1) if last != -1: last = dic.get(prefix_a[i] - k) ans = max(i - last, ans) val = dic.get(prefix_a[i], -1) if val == -1: dic[prefix_a[i]] = i prefix_b = [0] * (n + 1) dic = {} dic.update({(0): 0}) for i in range(1, n + 1): if s[i - 1] == "a": prefix_b[i] = 1 prefix_b[i] = prefix_b[i] + prefix_b[i - 1] for i in range(1, n + 1): if prefix_b[i] <= k: ans = max(ans, i) else: last = dic.get(prefix_b[i] - k, -1) if last != -1: last = dic.get(prefix_b[i] - k) ans = max(i - last, ans) val = dic.get(prefix_b[i], -1) if val == -1: dic[prefix_b[i]] = i print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER EXPR FUNC_CALL VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR DICT EXPR FUNC_CALL VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def check(s, x, k): a = s[:x].count("a") b = s[:x].count("b") i = x while i < len(s): if min(a, b) <= k: return True if s[i - x] == "a": a -= 1 else: b -= 1 if s[i] == "a": a += 1 else: b += 1 i += 1 if min(a, b) <= k: return True return False n, k = map(int, input().split()) s = input() left = 1 right = n ans = 1 while left <= right: mid = (left + right) // 2 if check(s, mid, k): ans = mid left = mid + 1 else: right = mid - 1 print(ans)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def longest(s, n, k): d = {"a": 0, "b": 0} i = j = m = l = 0 for i in range(n): d[s[i]] = d.get(s[i], 0) + 1 mm = min(list(d.values())) if mm > k: while j < n and mm > k: d[s[j]] -= 1 j += 1 mm = min(list(d.values())) elif i - j + 1 > m: m = i - j + 1 return m while 1: try: n, k = map(int, input().split()) s = input() print(longest(s, n, k)) except: break
FUNC_DEF ASSIGN VAR DICT STRING STRING NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR WHILE NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() freq = {"a": 0, "b": 0} for i in s: freq[i] = freq[i] + 1 char = "b" if freq["a"] > freq["b"] else "a" if k >= freq[char]: print(n) exit() cnts = [] cnt = 0 for i in s: if i != char: cnt += 1 else: cnts.append(cnt) cnt = 0 if cnt != 0: cnts.append(cnt) cnt_eq = [] cnt = 0 if freq["a"] == freq["b"]: for i in s: if i == char: cnt += 1 else: cnt_eq.append(cnt) cnt = 0 if cnt != 0: cnt_eq.append(cnt) def max_subarr(arr, k): init_sum = 0 max_sum = 0 if k == len(arr): return sum(arr) for i in range(len(arr)): if i < k: init_sum += arr[i] max_sum = init_sum else: init_sum += arr[i] - arr[i - k] max_sum = max(max_sum, init_sum) return max_sum print(max(max_subarr(cnts, k + 1), max_subarr(cnt_eq, k + 1)) + k)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR STRING VAR STRING STRING STRING IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR STRING VAR STRING FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s, ans = input(), 0 for j in ["a", "b"]: b, c, p1, p2 = [], k, 0, 0 for i in range(n): if s[i] == j: b.append(i) if c: c -= 1 else: p1 = b[p2] + 1 p2 += 1 ans = max(ans, i - p1 + 1) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER FOR VAR LIST STRING STRING ASSIGN VAR VAR VAR VAR LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) a, b = 0, 0 ma = 0 i2 = 0 st = input() if st[0] == "a": a += 1 else: b += 1 for i1 in range(n): while min(a, b) <= k and i2 < n - 1: i2 += 1 if st[i2] == "a": a += 1 else: b += 1 if min(a, b) > k: if st[i2] == "a": a -= 1 else: b -= 1 i2 -= 1 ma = max(ma, a + b) if st[i1] == "a": a -= 1 else: b -= 1 print(ma)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def checkmax(s, ch, k): count = 0 ptr1 = 0 maxx_length = 0 temp = 0 for i in range(len(s)): temp += s[i] != ch while temp > k: temp -= s[ptr1] != ch ptr1 += 1 temp_length = i - (ptr1 - 1) maxx_length = max(temp_length, maxx_length) return maxx_length n, k = (int(i) for i in input().split()) s = input() print(max(checkmax(s, "a", k), checkmax(s, "b", k)))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR VAR STRING VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
a = [int(x) for x in input().split()] b = 0 c = 0 asum = 0 bsum = 0 sorozat = input() helyek = [] helyek.append(-1) for x in range(len(sorozat)): if sorozat[x] == "a": asum += 1 helyek.append(x) helyek.append(a[0]) if asum <= a[1]: c = a[0] else: for x in range(len(helyek)): if b + a[1] + 1 < len(helyek) and helyek[b + a[1] + 1] - helyek[b] - 1 > c: c = helyek[b + a[1] + 1] - helyek[b] - 1 b = b + 1 b2 = 0 c2 = 0 helyek2 = [] helyek2.append(-1) for x in range(len(sorozat)): if sorozat[x] == "b": bsum += 1 helyek2.append(x) helyek2.append(a[0]) if bsum <= a[1]: c2 = a[0] else: for x in range(len(helyek2)): if ( b2 + a[1] + 1 < len(helyek2) and helyek2[b2 + a[1] + 1] - helyek2[b2] - 1 > c2 ): c2 = helyek2[b2 + a[1] + 1] - helyek2[b2] - 1 b2 = b2 + 1 if c > c2: c2 = c print(c2)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() res, cnta, cntb, oldi = 0, 0, 0, 0 for i in range(n): if s[i] == "a": cnta += 1 else: cntb += 1 while oldi <= i and k < min(cnta, cntb): if s[oldi] == "a": cnta -= 1 else: cntb -= 1 oldi += 1 res = max(res, i - oldi + 1) print(res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = list(map(int, input().split())) s = input() i = 1 j = 0 ca = 0 cb = 0 ans = 1 if s[0] == "a": ca += 1 else: cb += 1 while i < len(s): if s[i] == "a": ca += 1 else: cb += 1 if ca > k and cb > k: if s[j] == "a": ca -= 1 else: cb -= 1 j += 1 if ca <= k or cb <= k: ans = max(ans, ca + cb) i += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER STRING VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
read = lambda: list(map(int, input().split())) n, k = read() s = input() i = j = 0 cur = k while cur and j < n: if s[j] == "a": cur -= 1 j += 1 while j < n and s[j] == "b": j += 1 ans = j while j < n: while i < n and s[i] == "b": i += 1 i += 1 j += 1 while j < n and s[j] == "b": j += 1 ans = max(ans, j - i) i = j = 0 cur = k while cur and j < n: if s[j] == "b": cur -= 1 j += 1 while j < n and s[j] == "a": j += 1 ans = max(ans, j) while j < n: while i < n and s[i] == "a": i += 1 i += 1 j += 1 while j < n and s[j] == "a": j += 1 ans = max(ans, j - i) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() a = [0] * len(s) b = [0] * len(s) for i in range(len(s)): if s[i] == "a": a[i] += 1 else: b[i] += 1 if i > 0: a[i] += a[i - 1] b[i] += b[i - 1] ans = 0 for i in range(len(s)): lo = 0 hi = len(s) - 1 while lo <= hi: mid = (lo + hi) // 2 count = a[mid] - (a[i - 1] if i > 0 else 0) if count > k: hi = mid - 1 else: lo = mid + 1 ans = max(ans, hi - i + 1) lo = 0 hi = len(s) - 1 while lo <= hi: mid = (lo + hi) // 2 count = b[mid] - (b[i - 1] if i > 0 else 0) if count > k: hi = mid - 1 else: lo = mid + 1 ans = max(ans, hi - i + 1) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def main(): n, k = map(int, input().split()) s, x = input(), 2 if not k < s.count("a") < n - k: print(n) return for a in ("a", "b"): j, cnt = -1, k try: for i, c in enumerate(s): if c != a: if cnt: cnt -= 1 else: if x < i - j: x = i - j j += 1 while s[j] == a: j += 1 except IndexError: pass else: if x < n - j: x = n - j print(x - 1) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER IF VAR FUNC_CALL VAR STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR STRING STRING ASSIGN VAR VAR NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
import sys input = lambda: sys.stdin.readline().strip("\r\n") n, k = map(int, input().split()) s = input() a, b, j = 0, 0, 0 for i in range(n): if s[i] == "a": a += 1 else: b += 1 if min(a, b) > k: if s[j] == "a": a -= 1 else: b -= 1 j += 1 print(n - j)
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = list(map(int, input().split())) s = input() l = 0 r = 0 maxi = {"a": 0, "b": 0} cur = {"a": 0, "b": 0} while r < n: if min(cur.values()) > k: maxi["a"] = max(maxi["a"], cur["a"] + k) maxi["b"] = max(maxi["b"], cur["b"] + k) cur[s[l]] -= 1 l += 1 continue cur[s[r]] += 1 r += 1 maxi["a"] = max(maxi["a"], cur["a"] + k) maxi["b"] = max(maxi["b"], cur["b"] + k) res = max(maxi.values()) res = min(n, res) print(res)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT STRING STRING NUMBER NUMBER ASSIGN VAR DICT STRING STRING NUMBER NUMBER WHILE VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FUNC_CALL VAR VAR STRING BIN_OP VAR STRING VAR ASSIGN VAR STRING FUNC_CALL VAR VAR STRING BIN_OP VAR STRING VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING FUNC_CALL VAR VAR STRING BIN_OP VAR STRING VAR ASSIGN VAR STRING FUNC_CALL VAR VAR STRING BIN_OP VAR STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
l = input().split() n = int(l[0]) k = int(l[1]) s = input() maxa = [] i = 0 j = 0 numofs = 0 while i < n: while j < n and numofs <= k: if s[j] == "a": j += 1 elif numofs < k: numofs += 1 j += 1 else: break maxa.append(j - i + 1) if s[i] == "b": numofs -= 1 i += 1 else: i += 1 i = 0 j = 0 numofs = 0 while i < n: while j < n and numofs <= k: if s[j] == "b": j += 1 elif numofs < k: numofs += 1 j += 1 else: break maxa.append(j - i + 1) if s[i] == "a": numofs -= 1 i += 1 else: i += 1 print(max(maxa) - 1)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
import sys input = sys.stdin.readline n, k = map(int, input().split()) s = [i for i in input() if i != "\n"] def checker(m): l = [0, 0] for i in range(m): l[ord(s[i]) - 97] += 1 if min(l) <= k: return True for i in range(m, len(s)): l[ord(s[i - m]) - 97] -= 1 l[ord(s[i]) - 97] += 1 if min(l) <= k: return True return False beg = 1 last = len(s) while beg < last: mid = beg + (last - beg + 1) // 2 ok = checker(mid) if ok: beg = mid else: last = mid - 1 print(beg)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR STRING FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def f(): n, k = map(int, input().split()) s = input() cnta = [0] cntb = [0] for c in s: cnta.append(cnta[-1] + (c == "a")) cntb.append(cntb[-1] + (c == "b")) l = 1 r = len(s) while l < r: m = (l + r + 1) // 2 flag = False for n in range(len(s) - m + 1): if cntb[n + m] - cntb[n] <= k or cnta[n + m] - cnta[n] <= k: flag = True if flag: l = m else: r = m - 1 print(l) f()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = [int(s) for s in input().split(" ")] str = input() def length_of_longest_substring(str, k): window_start, window_end, maxCharCount, maxLen = 0, 0, 0, 0 char_freq = {} for window_end in range(len(str)): right_char = str[window_end] if right_char not in char_freq: char_freq[right_char] = 0 char_freq[right_char] += 1 maxCharCount = max(maxCharCount, char_freq[right_char]) while window_end - window_start + 1 - maxCharCount > k: left_char = str[window_start] char_freq[left_char] -= 1 window_start += 1 maxLen = max(maxLen, window_end - window_start + 1) print(maxLen) length_of_longest_substring(str, k)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR WHILE BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def check(l, r, k, count): if l != 0: a = count[r][0] - count[l - 1][0] b = count[r][1] - count[l - 1][1] else: a = count[r][0] b = count[r][1] if a > b and b <= k: return a + b elif b >= a and a <= k: return a + b else: return 0 def solve_test(): n, k = map(int, input().split()) string = input() count = [(0, 0) for i in range(n)] if string[0] == "a": count[0] = 1, 0 else: count[0] = 0, 1 for i in range(1, n): if string[i] == "a": count[i] = count[i - 1][0] + 1, count[i - 1][1] else: count[i] = count[i - 1][0], count[i - 1][1] + 1 l = 0 MAXSIZE = 1 for r in range(1, n): c = check(l, r, k, count) while l <= r and c == 0: l += 1 c = check(l, r, k, count) if l > r: l -= 1 if MAXSIZE < c: MAXSIZE = c print(MAXSIZE) def main(): solve_test() main()
FUNC_DEF IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR RETURN BIN_OP VAR VAR IF VAR VAR VAR VAR RETURN BIN_OP VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = list(map(int, input().split(" "))) st = input() a, b = 0, 0 i, j = 0, 0 while i < n: while j < n and b <= k: if st[j] == "b": b += 1 j += 1 if b > k: a = max(a, j - i - 1) else: a = max(a, j - i) if st[i] == "b": b -= 1 i += 1 aa, ba = 0, 0 ia, ja = 0, 0 while ia < n: while ja < n and ba <= k: if st[ja] == "a": ba += 1 ja += 1 if ba > k: aa = max(aa, ja - ia - 1) else: aa = max(aa, ja - ia) if st[ia] == "a": ba -= 1 ia += 1 print(max(a, aa))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, limit = input().split() limit = int(limit) string = input() start = 0 n_a = 0 n_b = 0 for letter in string: if letter == "a": n_a += 1 else: n_b += 1 if n_a > limit and n_b > limit: if string[start] == "a": n_a -= 1 else: n_b -= 1 start += 1 print(n_a + n_b)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def solve(string, k): n = len(string) ans = 0 left = 0 cur = 0 for i in range(n): cur += string[i] == "b" while cur > k: cur -= string[left] == "b" left += 1 ans = max(ans, i - left + 1) return ans n, k = map(int, input().split()) string = list(input()) ans = solve(string, k) for i in range(n): string[i] = "b" if string[i] == "a" else "a" ans = max(ans, solve(string, k)) print(ans)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR STRING WHILE VAR VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def solve(n, k, s): ans = 0 c = {"a": 0, "b": 0} l = 0 cur_len = 0 for r in range(n): cur_len += 1 c[s[r]] += 1 while l <= r and min(c.values()) > k: c[s[l]] -= 1 cur_len -= 1 l += 1 ans = max(ans, cur_len) return ans n, k = map(int, input().split()) s = input() print(solve(n, k, s))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT STRING STRING NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = str(input()) i, j, a, b, m = 0, 0, 0, 0, 0 while i < n: if s[i] == "a": a += 1 else: b += 1 if min(a, b) <= k: m = max(m, a + b) else: e = s[j] if e == "a": a = a - 1 else: b = b - 1 m = max(m, a + b) j = j + 1 i = i + 1 print(m)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = list(map(int, input().split())) s = input() ret = 0 for b in ["a", "b"]: l = 0 r = 0 curr = k while r < n: if s[r] == b: r += 1 elif curr > 0: r += 1 curr -= 1 else: if s[l] != b: curr += 1 l += 1 ret = max(ret, r - l) print(ret)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR LIST STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) a = list(input()) i = 0 j = 0 ans = 1 ca = cb = 0 if a[j] == "a": ca += 1 else: cb += 1 while j < n and i < n: if min(ca, cb) <= k and j < n - 1: j += 1 if a[j] == "a": ca += 1 else: cb += 1 else: if a[i] == "a": ca -= 1 else: cb -= 1 i += 1 if min(ca, cb) <= k: ans = max(ca + cb, ans) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() mx = 0 i, j, cn = 0, 0, 0 while j < n: if s[j] == "b": cn += 1 while cn > k: if s[i] == "b": cn -= 1 i += 1 mx = max(j - i + 1, mx) j += 1 i, j, cn = 0, 0, 0 while j < n: if s[j] == "a": cn += 1 while cn > k: if s[i] == "a": cn -= 1 i += 1 mx = max(j - i + 1, mx) j += 1 print(mx)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
entrada = input().split() n = int(entrada[0]) k = int(entrada[1]) s = input() esquerda = 0 tamanho = 0 ct = [0] * 2 for direita in range(0, n): ct[ord(s[direita]) - ord("a")] += 1 if ct[0] <= k or ct[1] <= k: temp = direita - esquerda + 1 tamanho = tamanho if tamanho > temp else temp else: ct[ord(s[esquerda]) - ord("a")] -= 1 esquerda += 1 print(tamanho)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER IF VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() m = k a = s[:k].count("a") b = k - a l = 0 for r in range(k, len(s)): if s[r] == "a": a += 1 else: b += 1 while min(a, b) > k: if s[l] == "a": a -= 1 else: b -= 1 l += 1 m = max(m, r - l + 1) print(m)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().strip().split()) s = input() maxi = 0 start = 0 last = 0 left = k for i in range(n): if s[i] == "a": last += 1 elif left > 0: left -= 1 last += 1 else: while s[start] != "b": start += 1 last -= 1 start += 1 maxi = max(last, maxi) start = 0 last = 0 left = k for i in range(n): if s[i] == "b": last += 1 elif left > 0: left -= 1 last += 1 else: while s[start] != "a": start += 1 last -= 1 start += 1 maxi = max(last, maxi) print(maxi)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) S = input() l = r = 0 a = b = 0 ans = 0 while r < n: if a <= k or a == 0 or b <= k or b == 0: ans = max(ans, r - l) if S[r] == "a": a += 1 else: b += 1 r += 1 else: if S[l] == "a": a -= 1 else: b -= 1 l += 1 if a <= k or a == 0 or b <= k or b == 0: ans = max(ans, r - l) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def calc(string, k, char): offsets = [i for i, v in enumerate(string) if v != char] if k >= len(offsets): return len(string) left_idx = 0 result = max(offsets[k], len(string) - offsets[len(offsets) - k - 1] - 1) for end_idx in range(k, len(offsets) - 1): right = offsets[end_idx + 1] - 1 left = offsets[left_idx] + 1 result = max(result, right - left + 1) left_idx += 1 return result def main(): n, k = map(int, input().split()) string = input() print(max(calc(string, k, "a"), calc(string, k, "b"))) main()
FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
import sys def solve(ch): l = 0 ans = 0 maxx = 0 for r in range(n): if ch == "a": if s[r] == "b": maxx += 1 elif s[r] == "a": maxx += 1 while maxx > k: if ch == "a": if s[l] == "b": maxx -= 1 elif s[l] == "a": maxx -= 1 l += 1 ans = max(ans, r - l + 1) return ans n, k = map(int, sys.stdin.readline().split()) s = input() a1 = solve("a") a2 = solve("b") print(max(a1, a2))
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER WHILE VAR VAR IF VAR STRING IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
from sys import stdin def scan(K, line, x): start = 0 length = len(line) max_t = 0 cx, cnx = 0, 0 for end in range(length): char = line[end] if char == x: cx += 1 else: cnx += 1 if cnx > K: max_t = max(max_t, cx + cnx - 1) while line[start] == x: start += 1 cx -= 1 start += 1 cnx -= 1 max_t = max(max_t, cx + cnx) return max_t def solve(K, line): result = scan(K, line, "a") result2 = scan(K, line, "b") print(max(result, result2)) def parse(): line = stdin.readline().split() N, K = map(int, line) line = stdin.readline().strip() solve(K, line) parse()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = list(input()) def isPossible(x): count_a = 0 count_b = 0 for i in range(x): if s[i] == "a": count_a += 1 else: count_b += 1 if max(count_a, count_b) + k >= x: return True for i in range(1, n - x + 1): if s[i - 1] == "a": count_a -= 1 else: count_b -= 1 if s[x + i - 1] == "a": count_a += 1 else: count_b += 1 if max(count_a, count_b) + k >= x: return True return False l = 1 r = n ans = 1 while l <= r: mid = (l + r) // 2 if isPossible(mid): l = mid + 1 ans = max(ans, mid) else: r = mid - 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER STRING VAR NUMBER VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() res = 1 p1 = 0 p2 = 0 ck = 0 while p2 < n and p1 < n: if s[p2] == "b" and ck < k or s[p2] == "a": if s[p2] == "b": ck += 1 p2 += 1 l = p2 - p1 if l > res: res = l else: if s[p1] == "b": ck -= 1 p1 += 1 p1 = 0 p2 = 0 ck = 0 while p2 < n: if s[p2] == "a" and ck < k or s[p2] == "b": if s[p2] == "a": ck += 1 p2 += 1 l = p2 - p1 if l > res: res = l else: if s[p1] == "a": ck -= 1 p1 += 1 print(res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR STRING VAR VAR VAR VAR STRING IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR VAR VAR VAR STRING IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def check(m): if min(a[m - 1], b[m - 1]) <= k: return True for i in range(1, n - m + 1): na, nb = a[i + m - 1] - a[i - 1], b[i + m - 1] - b[i - 1] if min(na, nb) <= k: return True else: return False n, k = map(int, input().split()) s = input() a, b = [0] * (n + 1), [0] * (n + 1) for i in range(n): if s[i] == "a": a[i + 1] += a[i] + 1 b[i + 1] = b[i] else: b[i + 1] += b[i] + 1 a[i + 1] = a[i] a.pop(0) b.pop(0) l, r, ans = 1, n, 0 while l <= r: m = (l + r) // 2 if check(m): l = m + 1 ans = m else: r = m - 1 print(ans)
FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() k1 = k k2 = k a = b = ans = 0 for i in range(n): if s[i] == "b": k1 -= 1 else: k2 -= 1 while k1 < 0: if s[a] == "b": k1 += 1 a += 1 while k2 < 0: if s[b] == "a": k2 += 1 b += 1 ans = max(ans, i - a + 1, i - b + 1) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) st = 0 end = 1 s = input() l = [0] * (n + 1) for i in range(len(s)): l[i + 1] = 1 if s[i] == "a" else 0 su = 0 m = 0 while end < n + 1: su += l[end] if su > k and end - st - su > k: st += 1 su -= l[st] m = max(m, st - end) end += 1 m = max(m, end - st - 1) print(m)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR STRING NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
n, k = map(int, input().split()) s = input() l = 0 r = 0 d = {} v = -1 ans = 0 while l < n: while r < n: if v != r: d[s[r]] = d.get(s[r], 0) + 1 if len(d) > 2: d[s[r]] -= 1 if d[s[r]] == 0: d.pop(s[r]) break if d: m = min(d.values()) if m > k and len(d) == 2: break r += 1 ans = max(ans, r - l) v = r d[s[l]] -= 1 if d[s[l]] == 0: d.pop(s[l]) l += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def func(A, n, k, ch): i = 0 j = 0 cnt = 0 maxlen = 1 while i < n: if A[i] != ch: cnt += 1 while cnt > k: if A[j] != ch: cnt -= 1 j += 1 maxlen = max(maxlen, i - j + 1) i = i + 1 return maxlen n, k = map(int, input().split()) A = str(input()) m1 = func(A, n, k, "a") m2 = func(A, n, k, "b") ans = max(m1, m2) print(ans)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def retMaxConsecutive(string, n, k, choice): if string.count(choice) <= k: return n maxi = -1 index = 0 count = 0 for i in range(n): if string[i] != choice: count += 1 while count > k and index < n: if string[index] != choice: count -= 1 index += 1 maxi = max(maxi, i - index + 1) return maxi strLen, maxChange = input().split(" ") string = input() strLen = int(strLen) maxChange = int(maxChange) print( max( retMaxConsecutive(string, strLen, maxChange, "a"), retMaxConsecutive(string, strLen, maxChange, "b"), ) )
FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING FUNC_CALL VAR VAR VAR VAR STRING
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
def stringcheckerb(k, n, string): l = 0 r = 0 bsinstring = 0 best = 0 try: while True: while bsinstring != k + 1: r += 1 if best < r - l + 1: best = r - l + 1 if string[r - 1] == "b": bsinstring += 1 while bsinstring == k + 1: if string[l] == "b": bsinstring -= 1 l += 1 except: return best def stringcheckera(k, n, string): l = 0 r = 0 bsinstring = 0 best = 0 try: while True: while bsinstring != k + 1: r += 1 if best < r - l + 1: best = r - l + 1 if string[r - 1] == "a": bsinstring += 1 while bsinstring == k + 1: if string[l] == "a": bsinstring -= 1 l += 1 except: return best a = input("") b = input("") string = b k = 0 n = 0 for i in range(len(a)): if a[i] == " ": n = int(a[:i]) k = int(a[i + 1 :]) print(max([stringcheckera(k, n, string), stringcheckerb(k, n, string)]) - 2)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
import sys inf = float("inf") abc = "abcdefghijklmnopqrstuvwxyz" abd = { "a": 0, "b": 1, "c": 2, "d": 3, "e": 4, "f": 5, "g": 6, "h": 7, "i": 8, "j": 9, "k": 10, "l": 11, "m": 12, "n": 13, "o": 14, "p": 15, "q": 16, "r": 17, "s": 18, "t": 19, "u": 20, "v": 21, "w": 22, "x": 23, "y": 24, "z": 25, } mod, MOD = 1000000007, 998244353 vow = ["a", "e", "i", "o", "u"] dx, dy = [-1, 1, 0, 0], [0, 0, 1, -1] def solve(char): l, curr, ans = 0, 0, 0 for i in range(n): if string[i] != char: curr += 1 while curr > k: if string[l] != char: curr -= 1 l += 1 ans = max(ans, i - l + 1) return ans def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def get_ints(): return map(int, sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() n, k = get_ints() string = input() ans = max(solve("a"), solve("b")) print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR VAR LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve? -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. -----Output----- Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters. -----Examples----- Input 4 2 abba Output 4 Input 8 1 aabaabaa Output 5 -----Note----- In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
aplha = [chr(i) for i in range(ord("a"), ord("z") + 1)] n, k = map(int, input().split()) s = list(input()) out = 0 for i in aplha: l = 0 r = 0 t = k while l < n and r < n: if s[r] == i: r += 1 elif t > 0: t -= 1 r += 1 elif s[l] == i: l += 1 else: t += 1 l += 1 out = max(out, r - l) print(out)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
There are $n$ points on a plane. The $i$-th point has coordinates $(x_i, y_i)$. You have two horizontal platforms, both of length $k$. Each platform can be placed anywhere on a plane but it should be placed horizontally (on the same $y$-coordinate) and have integer borders. If the left border of the platform is $(x, y)$ then the right border is $(x + k, y)$ and all points between borders (including borders) belong to the platform. Note that platforms can share common points (overlap) and it is not necessary to place both platforms on the same $y$-coordinate. When you place both platforms on a plane, all points start falling down decreasing their $y$-coordinate. If a point collides with some platform at some moment, the point stops and is saved. Points which never collide with any platform are lost. Your task is to find the maximum number of points you can save if you place both platforms optimally. You have to answer $t$ independent test cases. For better understanding, please read the Note section below to see a picture for the first test case. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow. The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$; $1 \le k \le 10^9$) — the number of points and the length of each platform, respectively. The second line of the test case contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le 10^9$), where $x_i$ is $x$-coordinate of the $i$-th point. The third line of the input contains $n$ integers $y_1, y_2, \dots, y_n$ ($1 \le y_i \le 10^9$), where $y_i$ is $y$-coordinate of the $i$-th point. All points are distinct (there is no pair $1 \le i < j \le n$ such that $x_i = x_j$ and $y_i = y_j$). It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$). -----Output----- For each test case, print the answer: the maximum number of points you can save if you place both platforms optimally. -----Example----- Input 4 7 1 1 5 2 3 1 5 4 1 3 6 7 2 5 4 1 1 1000000000 1000000000 5 10 10 7 5 15 8 20 199 192 219 1904 10 10 15 19 8 17 20 10 9 2 10 19 12 13 6 17 1 14 7 9 19 3 Output 6 1 5 10 -----Note----- The picture corresponding to the first test case of the example: [Image] Blue dots represent the points, red segments represent the platforms. One of the possible ways is to place the first platform between points $(1, -1)$ and $(2, -1)$ and the second one between points $(4, 3)$ and $(5, 3)$. Vectors represent how the points will fall down. As you can see, the only point we can't save is the point $(3, 7)$ so it falls down infinitely and will be lost. It can be proven that we can't achieve better answer here. Also note that the point $(5, 3)$ doesn't fall at all because it is already on the platform.
import sys input = sys.stdin.readline t = int(input()) for tests in range(t): n, k = map(int, input().split()) X = list(map(int, input().split())) Y = list(map(int, input().split())) X2 = sorted(X) S = [0] * n LAST = [0] * n end = 0 for start in range(n): v = X2[start] while end < n and X2[end] <= v + k: end += 1 S[start] = end - start LAST[start] = end if max(S) == n: print(n) continue MAXS = [0] * n MAXS[-1] = S[-1] for i in range(n - 2, -1, -1): MAXS[i] = max(S[i], MAXS[i + 1]) ANS = 0 for i in range(n): if LAST[i] == n: break ANS = max(ANS, S[i] + MAXS[LAST[i]]) print(ANS)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR