Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(sys.stdin.readline().strip())

# 1を約数に持つ
divisers = [1 for _ in range(N+1)]
divisers[0] = 0
# divisers[1] = 1

exists = set()
for i in range(2, N+1):
    if i in exists:
        continue
    j = 1
    while i * j <= N:
        tmp = i*j
        exists.add(tmp)
        c = 0
        tmp2 = tmp
        while tmp2 % i == 0:
            tmp2 //= i
            c += 1
        # print(tmp, i, c)
        divisers[tmp] *= c + 1
        j += 1
# print(divisers)

ans = 0
for i in range(1, N+1):
    ans += i * divisers[i]

print(ans)

Fixed submission:
import sys

N = int(sys.stdin.readline().strip())

ans = 0
for i in range(1, N+1):
    j = N // i
    ans += j * (j+1) * i // 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys 
import math

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().split()))
A.sort()
# print(A)

ans = 0 
invalid = set()
for i in range(N):
    if A[i] in invalid:
        continue

    flag = True
    for j in range(i+1, N):
        if A[j] in invalid:
            continue
        
        # print(A[i], A[j])
        if A[j] % A[i] == 0:
            invalid.add(A[j])
        if A[i] == A[j]:
            # print("break")
            #break
            flag = False
    else:
        if flag:
            ans += 1

print(ans)

Fixed submission:
import sys 

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().split()))
A.sort()

max_a = max(A)
counts = [0 for _ in range(max_a + 1)]
ans = 0

for a in A:
    counts[a] += 1

for a in A:
    if counts[a] == 1:
        ans += 1
    n = 1
    while n * a <= max_a:
        counts[n * a] += 2
        n += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys 

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().split()))
A.sort()
# print(A)

ans = 0 
exists = set()
for i in range(N):
    for e in exists:
        if A[i] % e == 0:
            break
    else:
        if i + 1 == N or A[i] != A[i+1]:
            ans += 1
    exists.add(A[i])

print(ans)

Fixed submission:
import sys 

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().split()))
A.sort()

max_a = max(A)
counts = [0 for _ in range(max_a + 1)]
ans = 0

for a in A:
    counts[a] += 1

for a in A:
    if counts[a] == 1:
        ans += 1
    n = 1
    while n * a <= max_a:
        counts[n * a] += 2
        n += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque

N, K = map(int, sys.stdin.readline().strip().split())
tmp = list(map(int, sys.stdin.readline().strip().split()))

A = [a-1 for a in tmp]

visited = set()
loop = []

q = deque()
q.append(0)
start = float("inf")
end = float("inf")

count = 0
while q and count < K:
    s_town = q.popleft()
    # ループを確認
    if s_town in visited:
        start = loop.index(s_town)
        end = len(loop)
        break
    visited.add(s_town)
    loop.append(s_town)
    n_town = A[s_town]
    q.append(n_town)
    count += 1

# print(start, end)
if start >= K:
    print(loop[K]+1)
else:
    res = K - start
    res %= (end - start)
    # print("res", res)
    print(loop[start + res]+1)

Fixed submission:
import sys
from collections import deque

N, K = map(int, sys.stdin.readline().strip().split())
tmp = list(map(int, sys.stdin.readline().strip().split()))

A = [a-1 for a in tmp]

visited = set()
loop = []

q = deque()
q.append(0)
start = float("inf")
end = float("inf")

count = 0
while q and count <= N:
    s_town = q.popleft()
    # ループを確認
    if s_town in visited:
        start = loop.index(s_town)
        end = len(loop)
        break
    visited.add(s_town)
    loop.append(s_town)
    n_town = A[s_town]
    q.append(n_town)
    count += 1

# print(start, end)
if start >= K:
    print(loop[K]+1)
else:
    res = K - start
    res %= (end - start)
    # print("res", res)
    print(loop[start + res]+1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from pprint import pprint

S = sys.stdin.readline().strip()
S = S[::-1]

n = len(S)
r = [0] * 2019
acum = [0] * (len(S)+1)
r[0] += 1
for i, s_i in enumerate(S):
    acum[i+1] = int(s_i) * 10 ** (i) + acum[i]
    acum[i+1] %= 2019
    r[acum[i+1]] += 1
# print(acum)

ans = 0
for r_i in r:
    ans += r_i * (r_i - 1) // 2
print(ans)

Fixed submission:
import sys
from pprint import pprint

S = sys.stdin.readline().strip()
S = S[::-1]

n = len(S)
r = [0] * 2019
acum = [0] * (len(S)+1)
r[0] += 1
for i, s_i in enumerate(S):
    acum[i+1] = int(s_i) * pow(10, i, 2019) + acum[i]
    acum[i+1] %= 2019
    r[acum[i+1]] += 1
# print(acum)

ans = 0
for r_i in r:
    ans += r_i * (r_i - 1) // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter

input = sys.stdin.readline
N = int(input())
S = input().strip()

counter = Counter(S)
if len(counter) < 3:
    print(0)
    sys.exit()

exclude = 0
max_w = N // 2
for w in range(1, max_w+1):
    for i in range(N):
        if N <= i + 2*w:
            continue
        if S[i] != S[i+w] and S[i] != S[i+2*w] and S[i+w] != S[i+2*w]:
            exclude += 1
# print(exclude)

print(counter["R"] * counter["G"] * counter["B"] - exclude)

Fixed submission:
import sys
from pprint import pprint

from collections import Counter
from math import factorial

def nCr(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)

N = int(sys.stdin.readline())
S = sys.stdin.readline().strip()
# print(len(S))

counter = Counter(S)
if len(counter) != 3:
    print("0")
    sys.exit()
rgb_count = 0

max_width = len(S) // 2
for width in range(1, max_width+1):
    max_left = len(S) - 2 * width
    # print(width, max_left)
    for i in range(max_left):
        if len(set([S[i], S[i+width], S[i+2*width]])) == 3:
            rgb_count += 1


all_count = nCr(counter["R"], 1) * nCr(counter["G"], 1) * nCr(counter["B"], 1) 
# print(all_count, rgb_count)
print(all_count - rgb_count)

Buggy python submission (verdict: Runtime Error):
import sys
from pprint import pprint

from collections import Counter
from math import factorial

def nCr(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)

N = int(sys.stdin.readline())
S = sys.stdin.readline().strip()
# print(len(S))

counter = Counter(S)
rgb_count = 0

max_width = len(S) // 2
for width in range(1, max_width+1):
    max_left = len(S) - 2 * width
    # print(width, max_left)
    for i in range(max_left):
        if len(set([S[i], S[i+width], S[i+2*width]])) == 3:
            rgb_count += 1


all_count = nCr(counter["R"], 1) * nCr(counter["G"], 1) * nCr(counter["B"], 1) 
# print(all_count, rgb_count)
print(all_count - rgb_count)

Fixed submission:
import sys
from pprint import pprint

from collections import Counter
from math import factorial

def nCr(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)

N = int(sys.stdin.readline())
S = sys.stdin.readline().strip()
# print(len(S))

counter = Counter(S)
if len(counter) != 3:
    print("0")
    sys.exit()
rgb_count = 0

max_width = len(S) // 2
for width in range(1, max_width+1):
    max_left = len(S) - 2 * width
    # print(width, max_left)
    for i in range(max_left):
        if len(set([S[i], S[i+width], S[i+2*width]])) == 3:
            rgb_count += 1


all_count = nCr(counter["R"], 1) * nCr(counter["G"], 1) * nCr(counter["B"], 1) 
# print(all_count, rgb_count)
print(all_count - rgb_count)
Buggy python submission (verdict: Runtime Error):
import sys
from pprint import pprint

H, W = map(int, sys.stdin.readline().strip().split())

if H % 2 == 0 or W % 2 == 0:
    print(H * W // 2)
else:
    print((H * W // 2 + 1)

Fixed submission:
import sys

H, W = map(int, sys.stdin.readline().strip().split())

if H == 1 or W == 1:
    print(1)
elif H % 2 == 0 or W % 2 == 0:
    print(H * W // 2)
else:
    print(H * W // 2 + 1)
Buggy python submission (verdict: Runtime Error):
import sys
from pprint import pprint

S = sys.stdin.readline().strip()
Q = int(sys.stdin.readline().strip())

n_rev = 0
for _ in range(Q):
    tmp = sys.stdin.readline().strip().split()
    if tmp[0] == "1":
        n_rev += 1
    else:
        f, c = tmp[1], tmp[2]
        if f == "1":
            if n_rev % 2 == 0:
                S = c + S
            else:
                S = S + s
        else:
            if n_rev % 2 == 0:
                S = S + c
            else:
                S = c + S

if n_rev % 2 == 0:
    print(S)
else:
    print(S[::-1])

Fixed submission:
import sys
from pprint import pprint
from collections import deque

S = list(sys.stdin.readline().strip())
Q = int(sys.stdin.readline().strip())

q = deque(S)

n_rev = 0
for _ in range(Q):
    tmp = sys.stdin.readline().strip().split()
    if tmp[0] == "1":
        n_rev += 1
    else:
        f, c = tmp[1], tmp[2]
        if f == "1":
            if n_rev % 2 == 0:
                #S = c + S
                q.appendleft(c)
            else:
                #S = S + c
                q.append(c)
        else:
            if n_rev % 2 == 0:
                #S = S + c
                q.append(c)
            else:
                #S = c + S
                q.appendleft(c)

S = "".join(list(q))
if n_rev % 2 == 0:
    print(S)
else:
    print(S[::-1])

Buggy python submission (verdict: Runtime Error):
import sys
from pprint import pprint

S = sys.stdin.readline().strip()
Q = int(sys.stdin.readline().strip())

n_rev = 0
for _ in range(Q):
    tmp = sys.stdin.readline().strip().split()
    if tmp[0] == "1":
        n_rev += 1
    else:
        f, c = tmp[1], tmp[2]
        if f == "1":
            if n_rev % 2 == 0:
                S = c + S
            else:
                S = S + s
        else:
            if n_rev % 2 == 0:
                S = S + c
            else:
                S = c + S

if n_rev % 2 == 0:
    print(S)
else:
    print(S[::-1])

Fixed submission:
import sys
from pprint import pprint
from collections import deque

S = list(sys.stdin.readline().strip())
Q = int(sys.stdin.readline().strip())

q = deque(S)

n_rev = 0
for _ in range(Q):
    tmp = sys.stdin.readline().strip().split()
    if tmp[0] == "1":
        n_rev += 1
    else:
        f, c = tmp[1], tmp[2]
        if f == "1":
            if n_rev % 2 == 0:
                #S = c + S
                q.appendleft(c)
            else:
                #S = S + c
                q.append(c)
        else:
            if n_rev % 2 == 0:
                #S = S + c
                q.append(c)
            else:
                #S = c + S
                q.appendleft(c)

S = "".join(list(q))
if n_rev % 2 == 0:
    print(S)
else:
    print(S[::-1])
Buggy python submission (verdict: Runtime Error):
import sys
from pprint import pprint

def solve(n, k, p):
    E = [(1.0 + p_i)/2 for p_i in p]
    # pprint(E)
    
    ans = 0
    for i in range(n - k + 1):
        # print(i+3)
        ans = max(ans, sum([E[i+j] for j in range(k)]))
        # print(i, sum([E[i+j] for j in range(k)]))
    print(ans)

if __name__ == '__main__':
    n, k = map(int, sys.stdin.readline().strip().split(" "))
    p = list(map(int, sys.stdin.readline().strip().split(" ")))
    solve(n, k, p)

Fixed submission:
import sys
from pprint import pprint

def solve(n, a):
    exists = set()
    for a_i in a:
        if a_i in exists:
            return "NO"
        exists.add(a_i)
    return "YES"

if __name__ == '__main__':
    n = sys.stdin.readline().strip()
    a = list(map(int,sys.stdin.readline().strip().split(" ")))
    
    print(solve(n, a))
Buggy python submission (verdict: Runtime Error):
import sys
import math

def solve(a, b):
    print(math.gcd(a, b))

if __name__ == '__main__':
    a, b = map(int, sys.stdin.readline().strip().split(" "))
    solve(a, b)

Fixed submission:
import sys
from pprint import pprint
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def solve(a, b):
    print(lcm(a, b))

if __name__ == '__main__':
    a, b = map(int, sys.stdin.readline().strip().split(" "))
    solve(a, b)
Buggy python submission (verdict: Runtime Error):
import sys

H, W, A, B = map(int, sys.stdin.readline().split())

if B == 0:
    if W // 2 == A:
        for j in range(W):
            if i < A:
                print(1, end="")
            else:
                print(0, end="")
        print("")
    else:
        print("No")
elif H % B or W % A:
    print("No")
else:
    for i in range(H):
        for j in range(W):
            if (i // B) * A <= j < (i // B + 1)  * A:
                print(1, end="")
            else:
                print(0, end="")
        print("")

Fixed submission:
import sys

H, W, A, B = map(int, sys.stdin.readline().split())

for i in range(H):
    for j in range(W):
        if i < B:
            if j < A:
                print(0, end="")
            else:
                print(1, end="")
        else:
            if j < A:
                print(1, end="")
            else:
                print(0, end="")
    print("")
Buggy python submission (verdict: Runtime Error):
import sys

N = int(sys.stdin.readline())
D = list(map(int, sys.stdin.readline().split()))

times = [0] * 24
for d in D:
    times[d] += 1

if max(times) > 2 or times[0] == 2 or times[12] == 2:
    print(0)
else:
    ans = 0
    # 1 - 11時間の時差の場合、Diと24 - Diの両方を試す
    for i in range(2**11):
        positions = []
        if times[0] == 1:
            positions.append(0)
        for j in range(11):
            if times[j+1] == 2:
                positions.append(j+1)
                positions.append(24 - j-1)
            elif times[j+1] == 1:
                if (i >> j) & 1:
                    positions.append(24 - j-1)
                else:
                    positions.append(j+1)
        if times[12] == 1:
            positions.append(12)
        positions.sort()
        # print(positions)
        lp = len(positions)
        d = float("inf")
        for p in range(lp):
            # 0をまたぐ場合がある
            if p == lp -1:
                diff = 24 - positions[p] + positions[0]
            else:
                diff = positions[p+1] - positions[p]
            d = min(d, diff if diff != 24 else 0)
        ans = max(ans, d)

print(ans)

Fixed submission:
import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

B = [-1 for _ in range(N)]
ans = []

for i in range(N, 0, -1):
    tmp_sum = 0
    tmp_i = 2 * i
    while N >= tmp_i :
        tmp_sum += B[tmp_i - 1]
        tmp_i += i

    # print(i, tmp_sum)
    if A[i-1] == tmp_sum % 2:
        B[i-1] = 0
    else:
        ans.append(i)
        B[i-1] = 1

print(len(ans))
if len(ans):
    print(" ".join(map(str, ans[::-1])))

Buggy python submission (verdict: Runtime Error):

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

ans = [-1 for _ in range(N)]

count = 0
for i in range(N, 0, -1):
    tmp_sum = 0
    if N % i == 0 and N // i > 1:
        multi_max = N // i
        c = 1
        while multi_max > c:
            c += 1
            tmp_sum += ans[c * i - 1]

    # print(i, tmp_sum)
    if A[i-1] == 1:
        if tmp_sum % 2 == 0:
            count += 1
            ans[i-1] = 1
        else:
            ans[i-1] = 0
    else:
        if tmp_sum % 2 == 0:
            ans[i-1] = 0
        else:
            count += 1
            ans[i-1] = 1

print(count)
if count:
    print(" ".join(["1"] * count))

Fixed submission:
import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

B = [-1 for _ in range(N)]
ans = []

for i in range(N, 0, -1):
    tmp_sum = 0
    tmp_i = 2 * i
    while N >= tmp_i :
        tmp_sum += B[tmp_i - 1]
        tmp_i += i

    # print(i, tmp_sum)
    if A[i-1] == tmp_sum % 2:
        B[i-1] = 0
    else:
        ans.append(i)
        B[i-1] = 1

print(len(ans))
if len(ans):
    print(" ".join(map(str, ans[::-1])))
Buggy python submission (verdict: Time Limit Exceeded):
import sys

nCr_memo = {}

def solve(n, k):
    for i in range(k):
        i += 1
        ans = nCr(n - k + 1, i) * nCr(k - 1, i - 1)
        print  ans % (10**9 + 7)


def nCr(n, r):
    key = str(n) + '_' + str(r)
    if key in nCr_memo:
        return nCr_memo[key]

    a = 1
    b = 1
    for i in range(r):
        a *= (n - i)
        b *= (i + 1)

    nCr_memo[key] = a / b
    return nCr_memo[key]


if __name__ == '__main__':

    n, k = map(int, sys.stdin.readline().strip().split(" "))
    solve(n, k)

Fixed submission:
import sys
 
nCr_memo = {}
 
def solve(n, k):
    for i in range(k):
        i += 1
        ans = nCr(n - k + 1, i) * nCr(k - 1, i - 1)
        print  ans % (10**9 + 7)
 
 
def nCr(n, r):
    key = str(n) + '_' + str(r)
    if key in nCr_memo:
        return nCr_memo[key]
 
    a = 1
    b = 1
    for i in range(r):
        a *= (n - i)
        b *= (i + 1)
 
    nCr_memo[key] = a / b
    return nCr_memo[key]
 
 
if __name__ == '__main__':
 
    n, k = map(int, sys.stdin.readline().strip().split(" "))
    solve(n, k)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

N, M = map(int, sys.stdin.readline().split())

edges = [[] for _ in range(N)]
for _ in range(M):
    u, v = map(int, sys.stdin.readline().split())
    edges[u-1].append(v-1)

S, T = map(int, sys.stdin.readline().split())
S -= 1
T -= 1

visited = {}
q = deque()
q.append((S, 0))
d = -1
while q:
    s, c = q.popleft()
    if s in visited and visited[s] % 3 == c % 3:
        continue
    visited[s] = c
    for n in edges[s]:
        if n == T and c % 3 == 2:
            d = c + 1
            break
        q.append((n, c+1))

    if d % 3 == 0:
        break

if d == -1:
    print(-1)
else:
    print(d // 3)

Fixed submission:
import sys
from collections import deque

N, M = map(int, sys.stdin.readline().split())

edges = [[] for _ in range(N)]
for _ in range(M):
    u, v = map(int, sys.stdin.readline().split())
    edges[u-1].append(v-1)

S, T = map(int, sys.stdin.readline().split())
S -= 1
T -= 1

visited = {}
q = deque()
q.append((S, 0))
d = -1
while q:
    s, c = q.popleft()
    if s in visited and (c % 3) in visited[s]:
        continue
    if s not in visited:
        visited[s] = set()
    visited[s].add(c % 3)
    for n in edges[s]:
        if n == T and c % 3 == 2:
            d = c + 1
            break
        q.append((n, c+1))

    if d % 3 == 0:
        break

if d == -1:
    print(-1)
else:
    print(d // 3)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

N, M = map(int, sys.stdin.readline().split())

edges = [[] for _ in range(N)]
for _ in range(M):
    u, v = map(int, sys.stdin.readline().split())
    edges[u-1].append(v-1)

S, T = map(int, sys.stdin.readline().split())
S -= 1
T -= 1

visited = {}
q = deque()
q.append((S, 0))
d = -1
while q:
    s, c = q.popleft()
    if s in visited and visited[s] % 3 == c % 3:
        continue
    visited[s] = c
    for n in edges[s]:
        if n == T and c % 3 == 2:
            d = c + 1
            break
        q.append((n, c+1))

    if d % 3 == 0:
        break

if d == -1:
    print(-1)
else:
    print(d // 3)

Fixed submission:
import sys
from collections import deque

N, M = map(int, sys.stdin.readline().split())

edges = [[] for _ in range(N)]
for _ in range(M):
    u, v = map(int, sys.stdin.readline().split())
    edges[u-1].append(v-1)

S, T = map(int, sys.stdin.readline().split())
S -= 1
T -= 1

visited = {}
q = deque()
q.append((S, 0))
d = -1
while q:
    s, c = q.popleft()
    if s in visited and (c % 3) in visited[s]:
        continue
    if s not in visited:
        visited[s] = set()
    visited[s].add(c % 3)
    for n in edges[s]:
        if n == T and c % 3 == 2:
            d = c + 1
            break
        q.append((n, c+1))

    if d % 3 == 0:
        break

if d == -1:
    print(-1)
else:
    print(d // 3)
Buggy python submission (verdict: Runtime Error):
import sys
from pprint import pprint

def solve(n, m, a):
    sum = 1
    a_pre = 0
    for a_i in a:
        if a_pre != 0 and a_pre == a_i:
            return 0
        if a_i == 1:
            a_pre = a_i + 1
            continue
        pattern = (a_i - 1 - a_pre - 1)
        #print pattern
        sum *= 2**pattern
        a_pre = a_i + 1
    pattern = (n - a_pre - 1)
    #print pattern
    sum *= 2**pattern

    return sum % 1000000007


if __name__ == '__main__':

    n, m = map(int, sys.stdin.readline().strip().split(" "))
    a = []
    for i in range(m):
        a.append(int(sys.stdin.readline().strip()))
    print solve(n, m, a)

Fixed submission:
import sys

N, M = map(int, sys.stdin.readline().strip().split())
A = set()
for _ in range(M):
    A.add(int(sys.stdin.readline()))

# i段目の階段への到達方法の数
dp = [0 for _ in range(N+1)]
dp[0] = 1
dp[1] = 0 if 1 in A else 1

for i in range(2, N+1):
    if i in A:
        continue
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] %= 1000000007

print(dp[N])
Buggy python submission (verdict: Time Limit Exceeded):
import sys

R, G, B, N = map(int, sys.stdin.readline().split())

r_max = N // R
g_max = N // G

ans = 0
for r in range(r_max+1):
    for g in range(g_max+1):
        res = N - r * R - g * G
        if 0 <= res and res % B == 0:
            # print(r, g, res // B)
            ans += 1

print(ans)

Fixed submission:
import sys

R, G, B, N = map(int, sys.stdin.readline().split())

r_max = N // R
g_max = N // G

ans = 0
for r in range(r_max+1):
    for g in range(g_max+1):
        res = N - r * R - g * G
        if 0 <= res and res % B == 0:
            # print(r, g, res // B)
            ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

def solve(N, S, K):
    char = S[K]

    ans = ''
    for i in xrange(len(S)):
        ans += S[i] if S[i] == char else '*'
    return ans

if __name__ == '__main__':

    N = sys.stdin.readline().strip()
    S = sys.stdin.readline().strip()
    K = sys.stdin.readline().strip()
    ans = solve(int(N), S, int(K))
    print ans

Fixed submission:
import sys

def solve(a, b, c):
    if a > c > b or a < c < b:
        return 'Yes'
    return 'No'

if __name__ == '__main__':

    a, b, c = map(int, sys.stdin.readline().strip().split(" "))
    ans = solve(a, b, c)
    print ans
Buggy python submission (verdict: Runtime Error):
import sys

def solve(N, S, K):
    char = S[K]

    ans = ''
    for i in xrange(len(S)):
        ans += S[i] if S[i] == char else '*'
    return ans

if __name__ == '__main__':

    N = sys.stdin.readline().strip()
    S = sys.stdin.readline().strip()
    K = sys.stdin.readline().strip()
    ans = solve(int(N), S, int(K))
    print ans

Fixed submission:
import sys

def solve(N, S, K):
    char = S[K-1]

    ans = ''
    for i in xrange(len(S)):
        ans += S[i] if S[i] == char else '*'
    return ans

if __name__ == '__main__':

    N = sys.stdin.readline().strip()
    S = sys.stdin.readline().strip()
    K = sys.stdin.readline().strip()
    ans = solve(int(N), S, int(K))
    print ans
Buggy python submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline
N, K = map(int, input().split())
S = list(input().strip())

comp = [0]
pre = S[0]
tmp = 0
for s_i in S:
    if s_i != pre:
        comp.append(tmp)
        tmp = 1
    else:
        tmp += 1
    
    pre = s_i
comp.append(tmp)
for i in range(len(comp)-1):
    comp[i+1] += comp[i]

ans = 1
if K == 1:
    w = 2
else:
    w = 2*K + 1
ans = 1
tmp = 0
c = 0
if K == 1:
    for i in range(2, len(comp)):
        tmp = comp[i] - comp[i-2]
        ans = max(ans, tmp)
else:
    start = 0 if S[0] == "1" else 1
    for i in range(start, len(comp), 2):
        tmp = comp[i] - comp[i-w-1]
        ans = max(ans, tmp)
print(ans)

Fixed submission:
import sys

N, K = map(int, sys.stdin.readline().strip().split())
S = sys.stdin.readline().strip()

l = x = ans = 0
for r in range(N):
    if S[r] == '0' :
        if r == 0 or S[r-1] == '1':
            x += 1
    if x > K:
        while S[l] == '1':
            l += 1
        while S[l] == '0':
            l += 1
        x -= 1
    ans = max(ans, r-l+1)
print(ans)