description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().split())
a = list(map(int, input().split()))
s = e = ans = c = ans_s = 0
ans_e = -1
while e < n:
if not a[e]:
c += 1
while c > k and e >= s:
if not a[s]:
c -= 1
s += 1
if c <= k and e - s + 1 > ans_e - ans_s + 1:
ans_s = s
... | 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 VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | s = input().split()
n, k = int(s[0]), int(s[1])
s = input().split()
a = []
for x in s:
a.append(int(x))
L, R = [], []
for i in range(n + 2):
L.append(0)
R.append(0)
for i in range(1, n + 1):
if a[i - 1] == 1:
L[i] = L[i - 1] + 1
for i in range(n, 0, -1):
if a[i - 1] == 1:
R[i] = R[i ... | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().split())
a = [int(x) for x in input().split()]
i = 0
j = 0
c = 0
an = 0
p = [0, n - 1]
while j < n and c < k:
if a[j] == 0:
c += 1
j += 1
an = j - i
p = [i, j]
while j < n:
if a[j] == 0:
while a[i] != 0:
i += 1
i += 1
j += 1
if j - i > an:
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 LIST NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIG... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().split())
a = list(map(int, input().split()))
a.append(0)
b = {(-1): 0}
c, l, r, st, ed = 0, 0, 0, 0, 0
for i in range(n + 1):
if a[i] == 0:
c += 1
b[i] = c
while l <= n and r <= n:
k1 = b[r] - b[l - 1]
if k1 <= k:
r += 1
else:
if r - l >= ed - st:
... | 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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VA... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | a, b = map(int, input().split())
z = list(map(int, input().split()))
ans = []
for i in range(len(z)):
if z[i] == 0:
ans.append(i)
freq = []
count = 1
inde = 0
if len(ans) == 0:
print(len(z))
print(*z)
exit()
pair = [[0, 0] for i in range(len(ans))]
if z[0] == 0:
inde = 1
for i in range(1, le... | 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 LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | from sys import stdin, stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int, stdin.readline().split()))
PI = float("inf")
for _ in range(1):
n, k = lst()
ps = [0] * n
a = lst()
for i in range(n):
if a[i] == 0:
ps[i] = ps[max(0, i - 1)] + 1
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
r = -1
ans = 0
ans_po = 0
for l in range(n):
if l > 0:
if a[l - 1] == 0:
m += 1
while r < n - 1 and 1 - a[r + 1] <= m:
r += 1
if a[r] == 0:
m = m - 1
if r - l + 1 > ans:
ans = r... | ASSIGN VAR 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER WHILE VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | def main():
n, k = list(map(int, input().split()))
nums = input().split()
nums.append("0")
n += 1
maxr = maxi = front = rear = 0
while front < n:
for front in range(front, n):
if nums[front] == "0":
if k > 0:
k -= 1
else:
... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | def read_ints():
return [int(x) for x in input().split()]
def main():
n, k = read_ints()
a = read_ints()
lo = 0
hi = 0
count = 0
x = -1
y = -1
while hi < n:
if count < k or a[hi] != 0:
if a[hi] == 0:
count += 1
if hi - lo >= y - x:
... | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR 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 VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASS... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | a, k = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
zeros = 0
left = 0
right = 0
consec = 0
best = 0
switch = []
best_coords = 0, 0
if k == 0:
for i in range(len(arr)):
if arr[i] == 1:
consec += 1
if consec > best:
best = consec
el... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR 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 NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | import sys
input = sys.stdin.readline
def prog():
n, k = map(int, input().split())
a = list(map(int, input().split())) + [0]
count = 0
for i in range(n):
if a[i] == 1:
count += 1
if count + k >= n:
print(n)
print("1 " * n)
elif k == 0:
last = 0
... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP ST... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | from sys import stdin
def main():
n, k = map(int, stdin.readline().split())
ar = list(map(int, stdin.readline().split()))
start = 0
end = -1
zeros = 0
ans = 0
sid = -1
eid = -2
while end < n:
while end < n and zeros <= k:
end += 1
if end < n and ar[e... | FUNC_DEF 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NU... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
if 0 not in a:
print(n)
print(*a)
exit()
if 1 not in a:
print(k)
res = [1] * k + [0] * (n - k)
print(*res)
exit()
zeroes = []
max_ones = 0
ones = 0
for i in range(n):
if a[i] == 0:
zeroes.append(i)
... | ASSIGN VAR 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 IF NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER BIN_OP... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().split())
l = list(map(int, input().split()))
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
print(ki - po + 1)
l[po : ki + 1] = [1] * (ki - po + 1)
print(" ".join(map(str, l))) | 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 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 EXPR FU... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().split())
a = list(map(int, input().split()))
s = []
for i in range(n):
if a[i] == 0:
s.append(i)
z = 0
c = 0
x, w = 0, 0
for i in range(len(s) - k):
y = s[i + k] - z
if c < y:
c = y
x = z
w = s[i + k]
z = s[i] + 1
y = n - z
if c < y:
c = y
... | 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 LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR V... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().split())
a = [int(x) for x in input().split()]
bl, br, bv = -1, -1, 0
l = 0
c = 0
r = 0
while r < n:
if a[r] == 0:
if c < k:
c += 1
else:
if r - l > bv:
bv = r - l
bl = l
br = r
while a[l] == ... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | def main():
n, k = list(map(int, input().split()))
l, x = list(input()[::2]), k + 1
l.append("0")
n += 1
for i, c in enumerate(l):
if c == "0":
x -= 1
if not x:
break
m, j, ji = i, -1, (-1, i)
for i in range(i + 1, n):
if l[i] == "0":
... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER IF VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | import sys
n, k = map(int, sys.stdin.buffer.readline().split())
a = [0] + list(map(int, sys.stdin.buffer.readline().split()))
zero = [0] * (n + 1)
for i in range(1, n + 1):
zero[i] = zero[i - 1] + (1 if a[i] == 0 else 0)
def solve(x):
for i in range(x, n + 1):
if zero[i] - zero[i - x] <= k:
... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER NUMBER FU... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | L = list(map(int, input().split()))
n = L[0]
k = L[1]
a = list(map(int, input().split()))
nbr0 = 0
posi = 0
taillemax = 0
p = 0
for i in range(len(a)):
nbr0 += a[i] == 0
if nbr0 > k:
if i - posi > taillemax:
p = posi
taillemax = i - posi
j = posi
while 1:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR ... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().split())
a = list(map(int, input().split()))
x, y, m, ans = 0, 0, 0, [0, 0]
while x < n:
while y < n and (k > 0 or a[y] == 1):
if a[y] == 0:
k -= 1
y += 1
if y - x > m:
ans = [x, y]
m = y - x
if a[x] == 0:
k += 1
x += 1
a[ans[0]... | 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 VAR VAR VAR NUMBER NUMBER NUMBER LIST NUMBER NUMBER WHILE VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR LIST V... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | mx = 0
def f(need, c, k, n):
for i in range(n):
if i + need - 1 >= n:
break
temp = c[i + need - 1]
if i > 0:
temp -= c[i - 1]
if temp + k >= need:
return True, i
return False, None
def main():
n, k = list(map(int, input().split()))
... | ASSIGN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER VAR RETURN NUMBER NONE FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN V... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
l = 0
ans = 0
resL = -1
resR = -1
cntZero = 0
for r in range(n):
if a[r] == 0:
cntZero += 1
while cntZero > k:
if a[l] == 0:
cntZero -= 1
l += 1
if ans < r - l + 1:
ans = r - l + ... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n = input().split()
k = int(n[-1])
n = int(n[0])
a = [int(x) for x in input().split()]
ii = 0
zero = list()
for x in a:
if not x:
zero.append(ii)
ii += 1
if len(zero) - k <= 0:
print(n)
string = "1"
for x in range(1, n):
string += " 1"
print(string)
elif k == 0:
string = ""
... | 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VA... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
i = 0
j = 0
Ansp = [0, 0]
zcnt = 0
max = 0
while i <= n - 1:
while j < n:
if zcnt >= k and a[j] == 0:
break
j += 1
if not a[j - 1]:
zcnt += 1
if zcnt > k:
j -= 1... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUM... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | ch = input()
ch1 = input()
ch = ch.split(" ")
n = int(ch[0])
k = int(ch[1])
l = ch1.split(" ")
l = [int(i) for i in l]
nb = l.count(0)
if k >= nb:
print(n)
l = ["1"] * n
ch2 = " ".join(l)
print(ch2)
else:
c = 0
t = []
while len(t) < nb:
if l[c] == 0:
t.append(c)
c... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING V... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().split())
b = list(map(int, input().split()))
c = [0]
for j in range(n):
if b[j] == 0:
c.append(j)
j = 0
strt = 0
m = 0
q = 0
s = 0
p = 0
while j < n:
if b[j] == 0:
p += 1
if p > k:
if q != 0:
s += 1
q += 1
s += -... | 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 LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBE... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | class MaxSum(object):
def __init__(self, init_list):
self.l = init_list
self.subl = []
def max_sum(self):
sum = 0
ans = 0
if max(self.l) < 0:
return 0
for x in self.l:
sum += x
ans = sum if sum > ans else ans
if su... | CLASS_DEF VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FOR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CA... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().split(" "))
a = list(map(int, input().split()))
arr = [-1]
for i in range(n):
if a[i] == 0:
arr.append(i)
arr.append(n)
if len(arr) - 2 <= k:
ans = [1] * n
print(n)
print(*ans)
else:
x = len(arr)
ans = 0
start = 0
end = -1
for i in range(k + 1, x):
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXP... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | import sys
n, k = [int(a) for a in input().split()]
As = [int(a) for a in input().split()]
groupstart = [0] * n
for i in range(1, n):
if As[i - 1] == As[i]:
groupstart[i] = groupstart[i - 1]
else:
groupstart[i] = i
groupend = [n] * n
for i in range(n - 2, -1, -1):
if As[i] == As[i + 1]:
... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR ... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
z = 0
zeros = []
for i in range(n):
if arr[i] == 1:
z += 1
else:
zeros.append([i, z])
if len(zeros) > 1:
zeros[-2].append(z)
z = 0
try:
zeros[-1].append(z)
except:
print(n)
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER V... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().split())
s = list(map(int, input().split()))
ans = 0
def get(x):
return 1 - x
l = 0
r = -1
cnt = 0
L = n
R = 0
while l < n:
while r + 1 < n and cnt + get(s[r + 1]) <= k:
cnt += get(s[r + 1])
r += 1
now = r - l + 1
if now > ans:
ans = now
L = l
... | 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 NUMBER FUNC_DEF RETURN BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR WHILE BIN_OP VAR NUMBER VAR BIN_OP VAR FUNC... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = list(map(int, input().split()))
m = list(map(int, input().split()))
ls = [0]
now = 0
for i in range(n):
now += m[i]
ls += [now]
s = 1
bz = 0
locs = [0, 0]
for i in range(1, n + 1):
su = ls[i] - ls[s - 1]
t = i - s + 1
if t - su <= k:
if bz < t:
bz = t
locs = [s... | ASSIGN VAR 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 LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NU... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | import sys
n, k = map(int, input().split())
a = list(map(int, sys.stdin.readline().split()))
l = 0
r = 0
zeroCount = 0
ans = 0
imax = 0
for i in range(n):
if a[i] == 1:
r += 1
elif zeroCount == k:
while a[l] != 0:
l += 1
l += 1
r += 1
else:
zeroCount += 1... | IMPORT 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR WHILE VAR VAR NUMBER VAR NUMBER V... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().split())
l = list(map(int, input().split()))
m = 0
z = 0
p = 0
r = 0
for i in range(n):
if l[i] == 0:
z += 1
if z <= k:
m += 1
r = i
else:
if l[p] == 0:
z -= 1
p += 1
print(m)
l[r - m + 1 : r + 1] = [1] * m
print(*l) | 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().split())
a = list(map(int, input().split()))
i = j = ss = ee = aa = 0
countzero = 0
while i < n:
while countzero <= k and i < n:
if a[i] == 0:
countzero += 1
i += 1
if i - j + 1 > aa and countzero <= k:
ss = i
ee = j
aa ... | 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 VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR ASSIGN VA... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | 3
__metaclass__ = type
__author__ = "xdlove"
n, k = list(map(int, input().split()))
res = [int(x) for x in input().split()]
l, r = -1, -2
L, num_0 = 0, 0
for R in range(n):
if res[R] == 0:
num_0 += 1
while num_0 > k:
if r - l < R - L:
l, r = L, R
if res[L] == 0:
n... | EXPR NUMBER ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR BI... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().split())
a = list(map(int, input().split()))
l = 0
r = 0
ans = 0
ans_pr = [0, 0]
ct = 0
while l < n:
while r < n and (a[r] or ct < k):
ct += not a[r]
r += 1
if r - l > ans:
ans = r - l
ans_pr = [l, r]
ct -= not a[l]
l += 1
print(ans)
print(*(a[: an... | 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIG... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().split())
arr = [int(i) for i in input().split()]
pref = [0]
for i in range(n):
pref.append(pref[-1] + arr[i])
def sat(low, ind):
global k
return pref[ind + 1] - pref[low] >= ind - low + 1 - k
def bs(lo, hi):
ret = -1
low = lo
while lo <= hi:
mid = (lo + hi) //... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().split())
A = [int(x) for x in input().split()]
a, b, c = 0, 0, 0
fa, fl = 0, 0
while b < len(A):
while b < len(A) and c <= k:
if b - a > fl:
fl = b - a
fa = a
if A[b] == 0:
c += 1
b += 1
while c > k and a <= b:
if A[a] =... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | import sys
f = sys.stdin.readline
n, k = map(int, f().strip().split())
arr = [int(v) for v in f().strip().split()]
zr = 0
i = 0
j = 0
ans = -1
ids = [0] * n
while i < n:
while j < n and zr <= k:
if arr[j] == 0:
zr += 1
j += 1
ans = max(ans, j - i - 1) if zr > k else max(ans, j - i)
... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR NUMBER VAR ... |
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n... | n, k = map(int, input().split())
lis = list(map(int, input().split()))
zer = [0] * (n + 1)
for i in range(n):
if lis[i] == 0:
zer[i + 1] = zer[i] + 1
else:
zer[i + 1] = zer[i]
ind = ans = 0
for i in range(n):
l = i + 1
r = n
while l <= r:
mid = l + (r - l) // 2
ze = z... | 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR N... |
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had... | fd = open("input.txt", "r")
fd1 = open("output.txt", "w")
n = int(fd.readline())
arr = list(map(int, fd.readline().split()))
freq = [(0) for i in range(5001)]
for i in range(n):
freq[arr[i]] += 1
presum = [(0) for i in range(5001)]
for i in range(1, 5001):
presum[i] = presum[i - 1] + freq[i]
tot = n
mini = n
fo... | ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR V... |
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had... | import sys
def main():
import sys
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
n, res, j = int(input()), [], 0
cc, f = sorted(map(int, input().split())), res.append
for i, c in enumerate(cc):
while cc[j] * 2 < c:
j += 1
f(i - j)
print... | IMPORT FUNC_DEF IMPORT ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CA... |
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had... | import sys
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
n = int(input())
t = list(map(int, sys.stdin.readline().split()))
p = [0] * 5001
for i in t:
p[i] += 1
q = p[:]
for i in range(1, 5001):
q[i] += q[i - 1]
ans = q[5000] - q[2499]
for i in range(1, 2501):
if p[i]:
s = ... | IMPORT ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BI... |
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had... | with open("input.txt") as f:
n = int(f.readline())
arr = list(map(int, f.readline().split()))
mark = [(0) for _ in range(5001)]
sumMark = [(0) for _ in range(5001)]
total = 0
minA = 1000000
for v in arr:
mark[v] += 1
total += 1
for i in range(1, 5001):
if mark[i] > 0:
sumMark[i] = sumMark[i ... | FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ... |
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had... | import sys
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
n = int(input())
res = [int(t) for t in input().split()]
res.sort()
min_erase = n
i, j = 0, 0
while i != n - 1:
if res[j] <= 2 * res[i]:
ans = True
if n - (j - i + 1) < min_erase:
min_erase = n - (j - i +... | IMPORT ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR NUMB... |
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had... | def solve(seq):
n = len(seq)
cnt = [0] * 5001
for e in seq:
cnt[e] += 1
acc = [0]
for i in range(1, 5001):
acc.append(acc[-1] + cnt[i])
ans = n
for i in range(5001):
if cnt[i] > 0:
n2remove = n - acc[min(2 * i, 5000)] + acc[i - 1]
ans = min(ans... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_O... |
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had... | f = open("input.txt", "r")
n = int(f.readline())
c = sorted(map(int, f.readline().split()))
j, v = 0, n - 1
for i in range(n):
while j < n - 1 and 2 * c[i] >= c[j + 1]:
j += 1
v = min(v, n + i - j - 1)
open("output.txt", "w").write(str(v)) | ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR V... |
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had... | import sys
sys.stdin = open("input.txt")
sys.stdout = open("output.txt", "+w")
n = int(input())
a = [0] + sorted(list(map(int, input().split())))
start = 1
res = 0
for end in range(1, n + 1):
while a[end] > 2 * a[start]:
start += 1
res = max(res, end - start + 1)
print(n - res) | IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP... |
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had... | f = open("input.txt", "r")
f1 = open("output.txt", "w")
def search(mas, val):
p = 0
ost = len(mas) - 1
while p <= ost:
mid = (p + ost) // 2
if mas[mid] > val * 2:
ost = mid - 1
else:
p = mid + 1
return p
n = int(f.readline())
ma = n - 1
l = list(map(in... | ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL... |
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had... | class CodeforcesTask253BSolution:
def __init__(self):
self.result = ""
self.measure_count = 0
self.measurements = []
def read_input(self):
in_ = open("input.txt", "r").read().split("\n")
self.measure_count = int(in_[0])
self.measurements = [int(x) for x in in_[1... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER STRING FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP VA... |
Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) an... | R = lambda: map(int, input().split())
n, m, k = R()
arr = list(R())
arrs = [list() for i in range(m)]
for i, x in enumerate(arr):
arrs[x - 1].append(i)
res = 1
for ar in arrs:
l = -1
for r in range(len(ar)):
while r - l + k < ar[r] - ar[l + 1] + 1:
l += 1
res = max(res, r - l)
pr... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CA... |
Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) an... | n, m, k = map(int, input().split())
a = list(map(int, input().split()))
col = [[] for i in range(m + 1)]
for i in range(n):
col[a[i]] += [i]
pref_c = [([0] * len(col[i])) for i in range(m + 1)]
for i in range(1, m + 1):
for j in range(1, len(col[i])):
pref_c[i][j] = pref_c[i][j - 1] + col[i][j] - col[i]... | ASSIGN VAR 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 LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR LIST VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR V... |
Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) an... | from sys import stdin, stdout
n, q, k = map(int, stdin.readline().split())
colours = list(map(int, stdin.readline().split()))
position = [[] for i in range(q + 1)]
cnt = [[] for i in range(q + 1)]
ans = 0
c, l, r = colours[0], 0, 0
for i in range(1, n):
if colours[i] != c:
position[c].append([l, r])
... | ASSIGN VAR 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 LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMB... |
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. W... | n, k = map(int, input().split())
s = input().rstrip()
if "a" not in s or "b" not in s:
print(n)
exit()
a = [0]
b = [0]
for ch in s:
a.append(a[-1] + (ch == "a"))
b.append(b[-1] + (ch == "b"))
def maxSize(a):
ret = 0
first = [-1] * n
for i, val in enumerate(a):
if first[val] == -1:
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF STRING VAR STRING VAR EXPR FUNC_CALL VAR VAR EXPR 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 FUNC_DE... |
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. W... | def testa_se_da(valor, a, k, a_b):
var = a_b
def consegue(soma):
if soma <= k:
return True
else:
return False
pos_esquerda = 0
n = len(a)
pos_direita = pos_esquerda + valor
soma = 0
for i in range(pos_esquerda, pos_direita):
if a[i] != var:
... | FUNC_DEF ASSIGN VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR RETURN NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR V... |
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. W... | def sol(n, k, a, e):
cnt = 0
l = 0
maxl = 0
for i in range(n):
if a[i] != e:
cnt += 1
while cnt > k:
if a[l] != e:
cnt -= 1
l += 1
maxl = max(maxl, i - l + 1)
return maxl
n, k = map(int, input().split())
s = input()
maxx =... | 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 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 ASS... |
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. W... | n, k = map(int, input().split())
s = input()
e, t = 0, 0
res = 0
for i in range(n):
if s[i] == "b":
t += 1
while t > k and e < i:
if s[e] == "b":
t -= 1
e += 1
res = max(res, i - e + 1)
e, t = 0, 0
for i in range(n):
if s[i] == "a":
t += 1
while t > k and ... | 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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER WHILE VAR VAR 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 N... |
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. W... | n, k = map(int, input().split())
s = list(input())
ans = 0
m = [0, 0]
l = 0
for i in s:
m[ord(i) - 97] += 1
if min(m) > k:
m[ord(s[l]) - 97] -= 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 FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC... |
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. W... | n, k = map(int, input().split())
s = input()
longest = 0
left, right = 0, 0
currb = 1 if s[0] == "b" else 0
while True:
while right < n and currb <= k:
right += 1
if right < n and s[right] == "b":
currb += 1
longest = max(longest, right - left)
if s[left] == "b":
currb -=... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER STRING NUMBER NUMBER WHILE NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF 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. W... | n, k = list(map(int, input().split()))
s = input()
left = 0
changes = 0
record_a = 0
for i in range(len(s)):
if s[i] == "b":
changes += 1
if changes > k:
changes -= 1
while s[left] == "a":
left += 1
left += 1
record_a = max(record_a, i + 1 - le... | 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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP ... |
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. W... | n, k = list(map(int, input().split()))
s = input()
l = 0
r = 0
ans = 0
num = 0
i = 0
while i < n:
r += 1
if s[i] == "b":
num += 1
if num > k:
ans = max(ans, i - l)
while l < n and s[l] != "b":
l += 1
l += 1
num -= 1
i += 1
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 WHILE VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE VAR VAR VAR VAR STR... |
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. W... | n, k = map(int, input().split())
s = input()
count = {"a": s.count("a"), "b": s.count("b")}
r = n
M = 0
l = 0
while l < n:
while count["a"] > k and count["b"] > k:
r -= 1
count[s[r]] -= 1
while r < n and (count["a"] <= k or count["b"] <= k):
count[s[r]] += 1
r += 1
if r - l >... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR STRING VAR VAR STRING VAR VAR NUMBER VAR VAR VAR NUMBER WHILE VAR VAR VAR STRING VAR VAR ST... |
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. W... | n, k = map(int, input().split())
string = input()
count = [0, 0]
j = out = 0
for i in range(n):
count[string[i] == "a"] += 1
if min(count) > k:
count[string[j] == "a"] -= 1
j += 1
else:
out += 1
print(out) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR STRING NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR STRING 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. W... | n, k = map(int, input().split())
s = input()
maxi = res = 0
count = {"a": 0, "b": 0}
for i in range(n):
count[s[i]] += 1
maxi = max(maxi, count[s[i]])
if res - maxi < k:
res += 1
else:
count[s[i - res]] -= 1
print(res) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR DICT STRING STRING NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR 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. W... | n, k = map(int, input().split())
s = input()
l = 0
r = 0
ch = 0
maxa = 0
if k == 0:
maxa = 1
count = 1
for i in range(1, len(s)):
if s[i] == s[i - 1]:
count += 1
else:
maxa = max(maxa, count)
count = 1
maxa = max(maxa, count)
print(maxa)
exit()... | 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 IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR 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. W... | n, k = map(int, input().split())
s = input()
mx = 0
ac = 0
bc = 0
j = 0
for i in range(len(s)):
if s[i] == "a":
ac += 1
elif s[i] == "b":
bc += 1
if ac - k <= 0 or bc - k <= 0:
mx = ac + bc
else:
if s[j] == "a":
ac -= 1
else:
bc -= 1
... | 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 FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP 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. W... | n, t = map(int, input().split())
s = input()
l = 0
k = 0
ma = 0
for r in range(n):
if s[r] == "a":
if r - l + 1 > ma:
ma = r - l + 1
else:
while k >= t:
if s[l] == "b":
k -= 1
l += 1
if r - l + 1 > ma:
ma = r - l + 1
... | 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 IF VAR VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP ... |
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. W... | def solver(myStr, letter):
l, r = 0, 0
curr_k, best = 0, 0
while r < n:
if myStr[r] != letter:
curr_k += 1
if curr_k <= k:
best = max(best, r - l + 1)
else:
while curr_k > k:
if myStr[l] != letter:
curr_k -= 1
... | FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN 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 RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUN... |
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. W... | from itertools import accumulate
n, k = [int(x) for x in input().split()]
A = [(1 if c == "a" else 0) for c in input()]
P = [0] + list(accumulate(A))
x, y = 1, n + 1
z = n // 2
while x != z:
for i in range(n - z + 1):
t = P[i + z] - P[i]
if t >= z - k or t <= k:
x = z
break
... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR STRING NUMBER NUMBER VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VA... |
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. W... | n, k = map(int, input().split())
s = input()
def f(a):
if len(a) <= k:
return n
a = [-1] + a + [n]
return max(a[i] - a[i - k - 1] - 1 for i in range(k + 1, len(a)))
print(
max(
f([i for i, ch in enumerate(s) if ch == "a"]),
f([i for i, ch in enumerate(s) if ch == "b"]),
)... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR F... |
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. W... | n, k = map(int, input().split())
pref = [0]
arr = [(0) for i in range(n)]
s = input()
for i in range(n):
arr[i] = ord(s[i]) - ord("a")
pref.append(pref[-1] + arr[i])
def sat(low, ind):
global k
return (
pref[ind + 1] - pref[low] <= k or pref[ind + 1] - pref[low] >= ind - low + 1 - k
)
de... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR N... |
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. W... | def vasia(n, k, w):
pos = 0
suma = 0
sumb = 0
con = 0
for i in range(n):
if w[i] == "a":
suma = suma + 1
elif w[i] == "b":
sumb = sumb + 1
if min(suma, sumb) <= k:
con = max(con, suma + sumb)
else:
res = w[pos]
... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP 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 BI... |
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. W... | n, k = map(int, input().split())
lis = [[0, 0] for i in range(n + 1)]
s = list(input())
ans = 0
for i in range(1, n + 1):
if s[i - 1] == "a":
lis[i][0] = lis[i - 1][0] + 1
lis[i][1] = lis[i - 1][1]
else:
lis[i][1] = lis[i - 1][1] + 1
lis[i][0] = lis[i - 1][0]
for i in range(1, n ... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUM... |
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. W... | n, k = map(int, input().split())
s = list(input())
aa = [0] * (n + 1)
bb = [0] * (n + 1)
res = 1
a, b = 0, 0
for i in range(1, n + 1):
if s[i - 1] == "a":
a += 1
aa[a] = i
else:
b += 1
bb[b] = i
res = max(res, i - aa[max(a - k, 0)])
res = max(res, i - bb[max(b - k, 0)])
p... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VA... |
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. W... | n, k = map(int, input().split())
a = input()
ka = 0
kb = 0
c = 0
answer = 0
for i in range(n):
if a[i] == "a":
ka += 1
else:
kb += 1
s = min(ka, kb)
if k < s:
if a[c] == "a":
ka -= 1
else:
kb -= 1
c += 1
else:
answer += 1
print(... | 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 ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR N... |
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. W... | n, k = map(int, input().split())
s = list(input())
j = 0
answer = 0
counter = [0, 0]
for i in range(n):
if s[i] == "b":
counter[1] += 1
else:
counter[0] += 1
if min(counter) > k:
if s[j] == "a":
counter[0] -= 1
else:
counter[1] -= 1
j += 1
... | 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 LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER NUMBER VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER NUMBER VAR NUMBER 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. W... | def find(s, n, k, constant):
pref = [0]
for x in s:
if x == constant:
pref.append(pref[-1] + 1)
else:
pref.append(pref[-1])
i, j = 1, 1
ans = 0
while i <= n and j <= n:
nbs = pref[j] - pref[i - 1]
if nbs <= k:
ans = max(ans, j - i +... | FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR N... |
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. W... | from sys import stdin
N, K = map(int, stdin.readline().split())
charArr = list(stdin.readline().strip())
bad = 0
front = 0
front2 = 0
back = len(charArr)
answer = K
while front < back:
if charArr[front] != "a":
bad += 1
if bad > K:
while front2 <= front and charArr[front2] == "a":
f... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER 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. W... | I = lambda: int(input())
IL = lambda: list(map(int, input().split()))
n, k = IL()
s = input()
l1 = list(map(len, s.split("a")))
l2 = list(map(len, s.split("b")))
ms = cs = sum(l1[: k + 1]) + len(l1[: k + 1]) - 1
for i in range(len(l1) - k - 1):
cs += l1[i + k + 1] - l1[i]
ms = max(ms, cs)
cs = sum(l2[: k + 1]) ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP BIN_OP FUN... |
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. W... | def find_max(n, m, t, char="a"):
l = 0
r = 0
count = 0
ans = 0
num = 0
while r < n:
if t[r] == char:
count += 1
r += 1
elif t[r] != char and num < m:
count += 1
r += 1
num += 1
elif t[r] != char and num >= m:
... | FUNC_DEF STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER IF 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. W... | def check(lengths, k, full_count_of_opposite):
maxcount = 0
count = 0
start = 0
cur_k = k
for i, el in enumerate(lengths):
if i % 2 == 0:
count += el
elif cur_k - el >= 0:
cur_k -= el
else:
maxcount = max(count, maxcount)
cur_k ... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR AS... |
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. W... | import sys
input = sys.stdin.readline
def prog():
n, k = map(int, input().split())
string = input().strip()
if k == 0:
print(max(max(map(len, string.split("a"))), max(map(len, string.split("b")))))
else:
ka = k
for i in range(n):
if string[i] == "b":
... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF ... |
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. W... | n, l = input().split()
n = int(n)
l = int(l)
string = input()
a = b = x = j = 0
for i in string:
if i == "a":
a += 1
else:
b += 1
if min(a, b) > l:
if string[j] == "a":
a -= 1
else:
b -= 1
j += 1
else:
x += 1
print(x) | 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 ASSIGN VAR VAR VAR VAR 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. W... | n, k = map(int, input().split())
a = input()
def solve(x, k):
i, j = 0, 0
ans = 0
t = k
while i < n and j < n:
while t >= 0 and j < n:
if a[j] != x and t >= 1:
t -= 1
elif a[j] != x and t == 0:
break
j += 1
ans = max([... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR WHILE VAR NUMBER VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR BIN_OP VAR V... |
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. W... | n, k = map(int, input().split())
s = input()
a = 0
b = 0
left = 0
right = 0
for i in s:
if i == "a":
a = a + 1
else:
b = b + 1
if min(a, b) > k:
if s[left] == "a":
a -= 1
else:
b -= 1
left = left + 1
else:
right += 1
print(right) | 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 VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BI... |
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. W... | n, k = input().split(" ")
n = int(n)
k = int(k)
str = input()
def analyze(str, char):
ans = 0
count_char = 0
i = 0
j = 0
while True:
if count_char <= k:
ans = max(ans, j - i)
if count_char > k:
if str[i] == char:
count_char -= 1
i... | 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR VAR VAR NUMBER VAR N... |
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. W... | def main():
n, k = [int(x) for x in input().split()]
s = input()
a = s[0] == "a" and 1 or 0
b = s[0] == "b" and 1 or 0
i = 0
j = 0
res = 1
while j < n - 1:
aj = 0
bj = 0
if s[j + 1] == "a":
aj += 1
else:
bj += 1
if min(a + a... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER STRING NUMBER NUMBER ASSIGN VAR VAR NUMBER STRING NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUM... |
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. W... | from sys import stdin
input = iter(stdin.readlines()).__next__
n, k = map(int, input().split())
string = input().strip()
p1a, p1b, p2 = 0, 0, 0
max_length = 0
changed_a, changed_b = 0, 0
while p2 < n:
if string[p2] == "b":
changed_a += 1
else:
changed_b += 1
if changed_a > k:
while ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR WHILE NUMBER VAR NUMBER IF VAR BIN_OP... |
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. W... | n, k = map(int, input().split())
s = list(input())
ans = 0
right = 0
cntb = 0
for left in range(n):
while cntb <= k and right < n:
if s[right] == "b":
cntb += 1
if cntb == k + 1:
cntb -= 1
break
right += 1
ans = max(ans, right - left)
if right == l... | 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 FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF... |
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. W... | def solve(k, s, c):
p = [-1, len(s)]
for i in range(len(s)):
if s[i] == c:
p += [i]
p.sort()
n = len(p)
if n - k - 1 <= 0:
return len(s)
m = 0
for i in range(n - k - 1):
m = max(m, p[i + k + 1] - p[i])
return m - 1
n, k = list(map(int, input().split(... | FUNC_DEF ASSIGN VAR LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL ... |
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. W... | N, T = map(int, input().split())
S = input()
a = 0
b = 0
r = 0
l = 0
mx = 0
while r < N:
if S[r] == "a":
mx = max(mx, r - l + 1)
else:
b += 1
if b <= T:
mx = max(mx, r - l + 1)
while b > T:
if S[l] == "b":
b -= 1
l += 1
r += 1
a = 0
b = 0
r = 0
l =... | 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 ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP ... |
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. W... | def getMax(s, i, j, t, k, n):
res = 0
count = 0
while i < n:
while j < n and count < k:
if s[j] != t:
count += 1
j += 1
while j < n and s[j] == t:
j += 1
res = max(res, j - i)
while i < n and s[i] == t:
i += 1
... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUN... |
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. W... | import sys
f = sys.stdin
n, k = map(int, f.readline().strip().split())
s = f.readline()
i = 0
j = 0
curmx = k
a = 0
b = 0
count = [0] * 26
while i < len(s):
while j < len(s) and min(a, b) <= k:
if s[j] == "a":
a += 1
else:
b += 1
j += 1
curmx = max(curmx, a + b -... | IMPORT ASSIGN VAR VAR 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 VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL 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. W... | n, m = input().split(" ")
n, m = int(n), int(m)
ans = 0
s = input()
for i in range(2):
left, used = 0, 0
for right in range(n):
if ord(s[right]) != ord("a") + i:
used += 1
while used > m:
if ord(s[left]) != ord("a") + i:
used -= 1
left += 1
... | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR STRING VAR VAR NUMBER WHILE VAR VAR IF FUNC_CALL V... |
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. W... | def solve(s, k, target):
n = len(s)
acum = [0] * n
first = dict()
for i, v in enumerate(s):
if i > 0:
acum[i] = acum[i - 1]
if v != target:
acum[i] += 1
if acum[i] not in first:
first[acum[i]] = i
best = 0
for i in range(n):
cur... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP V... |
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. W... | n, k = map(int, input().split())
a = input()
r = 0
b = [(ord(x) - ord("a")) for x in a]
s = 0
ans = 0
for i in range(n):
while r < n and (s + b[r] <= k or r + 1 - i - s - b[r] <= k):
s += b[r]
r += 1
ans = max(ans, r - i)
s -= b[i]
if r == n:
break
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR V... |
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. W... | n, k = map(int, input().split())
s = input()
i, j = 0, 0
ans = 0
dp = [0, 0]
while i < n:
dp[ord(s[i]) - ord("a")] += 1
if min(dp[0], dp[1]) > k:
while min(dp[0], dp[1]) > k and j <= i:
dp[ord(s[j]) - ord("a")] -= 1
j += 1
else:
ans = max(ans, dp[0] + dp[1])
i += ... | 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 LIST NUMBER NUMBER WHILE VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER V... |
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. W... | n, k = list(map(int, input().split()))
s = input()
res = 0
count_a = 0
count_b = 0
left = 0
right = 0
while True:
if s[right] == "a":
count_a += 1
else:
count_b += 1
if count_a <= k or count_b <= k:
if right - left + 1 > res:
res = right - left + 1
else:
if s[... | 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 NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP V... |
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. W... | n, k = map(int, input().split())
lst = input()
left = 0
right = 0
def current_length(left, right, changes_left, letter):
best_len = 0
curr_changes = changes_left
while right < n:
if curr_changes == 0 and lst[right] != letter:
if right - left > best_len:
best_len = right... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NU... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.