Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
S = input()
n = len(S)
if n == 1:
    print(1)
else:
    prev = None
    cand = []
    for i in range(n):
        if i != 0:
            if S[i] != prev:
                cand.append(max(i, n-i))
        prev = S[i]    

    print(min(cand))

Fixed submission:
S = input()
n = len(S)

prev = None
cand = []
for i in range(n):
    if i != 0:
        if S[i] != prev:
            cand.append(max(i, n-i))
    prev = S[i]    
if cand:
    print(min(cand))
else:
    print(n)

Buggy python submission (verdict: Runtime Error):
S = input()
n = len(S)
prev = None
cand = []
for i in range(n):
    if i != 0:
        if S[i] != prev:
            cand.append(max(i, n-i))
    prev = S[i]    

print(min(cand))

Fixed submission:
S = input()
n = len(S)

prev = None
cand = []
for i in range(n):
    if i != 0:
        if S[i] != prev:
            cand.append(max(i, n-i))
    prev = S[i]    
if cand:
    print(min(cand))
else:
    print(n)

Buggy python submission (verdict: Runtime Error):
# スペース区切りの整数の入力
bit = map(str, input().split())
length = len(bit)

num0 = 0
num1 = 0

for i in range(length):
    if bit[i] == '0':
        num0 += 1
    else:
        num1 += 1

K = max(num0, num1)
        
print(K)

Fixed submission:
S = input()
n = len(S)

prev = None
cand = []
for i in range(n):
    if i != 0:
        if S[i] != prev:
            cand.append(max(i, n-i))
    prev = S[i]    
if cand:
    print(min(cand))
else:
    print(n)
Buggy python submission (verdict: Runtime Error):
from collections import  defaultdict

s = input()
x, y = map(int, input().split())
N = len(s)

# 0: x-direction, 1: y-direction
dist = {0: [], 1: []}
current = 0
temp = 0
for move in s:
    if move == 'F':
        temp += 1
    else:
        dist[current].append(temp)
        temp = 0
        current ^= 1
if temp > 0:
    dist[current].append(temp)

xdp = {i: defaultdict(bool) for i in range(len(dist[0]))}
ydp = {i: defaultdict(bool) for i in range(len(dist[1]))}

xdp[0][dist[0][0]] = True
for i in range(1, len(dist[0])):
    d = dist[0][i]
    for j in range(-N, N+1):
        xdp[i][j] = xdp[i-1][j-d] | xdp[i-1][j+d] 

ydp[0][dist[1][0]] = True
ydp[0][-dist[1][0]] = True
for i in range(1, len(dist[1])):
    d = dist[1][i]
    for j in range(-N, N+1):
        ydp[i][j] = ydp[i-1][j-d] | ydp[i-1][j+d] 

if xdp[len(dist[0])-1][x] & ydp[len(dist[1])-1][y]:
    print('Yes')
else:
    print('No')

Fixed submission:
from collections import  defaultdict

s = input()
x, y = map(int, input().split())

s_splitted = s.split('T')
x -= len(s_splitted[0])

dist = {0: [], 1: []} # 0: x-direction, 1: y-direction
for i, Fs in enumerate(s_splitted[1:]):
    dist[(i+1) % 2].append(len(Fs))

reachable = {0: set([0]), 1: set([0])}

for i in range(2):
    for d in dist[i]:
        temp = []
        for r in reachable[i]:
            temp.append(r+d)
            temp.append(r-d)
        reachable[i] = set(temp)

if x in reachable[0] and y in reachable[1]:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
from collections import  defaultdict

s = input()
x, y = map(int, input().split())
N = len(s)

# 0: x-direction, 1: y-direction
dist = {0: [], 1: []}
current = 0
temp = 0
for move in s:
    if move == 'F':
        temp += 1
    else:
        dist[current].append(temp)
        n_move[current] += 1
        temp = 0
        current ^= 1
if temp > 0:
    dist[current].append(temp)
    n_move[current] += 1
        
xdp = {i: defaultdict(bool) for i in range(len(dist[0]))}
ydp = {i: defaultdict(bool) for i in range(len(dist[1]))}

xdp[0][dist[0][0]] = True
for i in range(1, len(dist[0])):
    d = dist[0][i]
    for j in range(-N, N+1):
        xdp[i][j] = xdp[i-1][j-d] | xdp[i-1][j+d] 

ydp[0][dist[1][0]] = True
ydp[0][-dist[1][0]] = True
for i in range(1, len(dist[1])):
    d = dist[1][i]
    for j in range(-N, N+1):
        ydp[i][j] = ydp[i-1][j-d] | ydp[i-1][j+d] 

if xdp[len(dist[0])-1][x] & ydp[len(dist[1])-1][y]:
    print('Yes')
else:
    print('No')

Fixed submission:
from collections import  defaultdict

s = input()
x, y = map(int, input().split())

s_splitted = s.split('T')
x -= len(s_splitted[0])

dist = {0: [], 1: []} # 0: x-direction, 1: y-direction
for i, Fs in enumerate(s_splitted[1:]):
    dist[(i+1) % 2].append(len(Fs))

reachable = {0: set([0]), 1: set([0])}

for i in range(2):
    for d in dist[i]:
        temp = []
        for r in reachable[i]:
            temp.append(r+d)
            temp.append(r-d)
        reachable[i] = set(temp)

if x in reachable[0] and y in reachable[1]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
X = input()
print('Yes' if X % sum(map(int, X)) == 0 else 'No')

Fixed submission:
X = input()
print('Yes' if int(X) % sum(map(int, X)) == 0 else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
A = sorted(A)
B = sorted(B)
C = sorted(C)

ans = 0
for c in C:
    b_cands = bisect_left(B, c)
    for i in range(b_cands):
        a_cands = bisect_left(A, B[i])
        ans += a_cands
print(ans)

Fixed submission:
from bisect import bisect_left, bisect_right

N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
A = sorted(A)
C = sorted(C)

ans = 0
for b in B:
    ans += bisect_left(A, b) * (N-bisect_right(C, b))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

N, K = map(int, input().split())
coord = [tuple(map(int, input().split())) for _ in range(N)]
ans = float('inf')
for points in combinations(coord, K):
    x_coords, y_coords = [x for x, _ in points], [y for _, y in points]
    x_min, x_max, y_min, y_max = min(x_coords), max(x_coords), min(y_coords), max(y_coords)
    cand = (x_max - x_min)*(y_max - y_min)
    inside = 0
    for p in coord:
        inside += 1 if p[0] in range(x_min, x_max+1) and p[1] in range(y_min, y_max+1) else 0
        if inside == K:
            break
    else:
        continue
    ans = min(ans, cand)
print(ans)

Fixed submission:
from itertools import combinations

N, K = map(int, input().split())
coord = sorted([tuple(map(int, input().split())) for _ in range(N)])
ans = float('inf')
for left, right in combinations(range(N), 2):
    n_points = right - left + 1
    if n_points < K: continue
    width = coord[right][0] - coord[left][0]
    y_coords = sorted([y for _, y in coord[left: right+1]])
    for i in range(n_points - K + 1):
        height = y_coords[i+K-1] - y_coords[i]
        ans = min(ans, width*height)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

N, K = map(int, input().split())
coord = [tuple(map(int, input().split())) for _ in range(N)]
ans = float('inf')
for points in combinations(coord, K):
    x_coords, y_coords = [x for x, _ in points], [y for _, y in points]
    x_min, x_max, y_min, y_max = min(x_coords), max(x_coords), min(y_coords), max(y_coords)
    cand = (x_max - x_min)*(y_max - y_min)
    inside = 0
    for p in coord:
        inside += 1 if p[0] in range(x_min, x_max+1) and p[1] in range(y_min, y_max+1) else 0
        if inside == K:
            break
    else:
        continue
    ans = min(ans, cand)
print(ans)

Fixed submission:
from itertools import combinations

N, K = map(int, input().split())
coord = sorted([tuple(map(int, input().split())) for _ in range(N)])
ans = float('inf')
for left, right in combinations(range(N), 2):
    n_points = right - left + 1
    if n_points < K: continue
    width = coord[right][0] - coord[left][0]
    y_coords = sorted([y for _, y in coord[left: right+1]])
    for i in range(n_points - K + 1):
        height = y_coords[i+K-1] - y_coords[i]
        ans = min(ans, width*height)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product

N = int(input())
for h, n in product(range(1, 3501), repeat=2):
    numer = N * h * n
    denom = 4 * h* n - N * n - N * h
    if denom == 0:
        continue
    w, r = divmod(numer, denom)
    if r == 0 and w > 0:
        print(h, n, w)
        break

Fixed submission:
from itertools import product

N = int(input())
for h, n in product(range(1, 3501), repeat=2):
    if 4 / N > 1 / h + 1 / n:
        numer = N * h * n
        denom = 4 * h* n - N * (n + h)
        if denom <= 0:
            continue
        w, r = divmod(numer, denom)
        if r == 0:
            print(h, n, w)
            break
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]

num_count = [A.count(i) % 2 for i in set(A)]
        
print(sum(num_count))

Fixed submission:
from collections import defaultdict

N = int(input())
A = defaultdict(int)

for _ in range(N):
    a = int(input())
    if A[a] == 1:
        A[a] = 0
    else:
        A[a] = 1
        
print(sum(A.values()))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]

num_count = {i: A.count(i) for i in set(A)}
ans = 0

for i in num_count.values():
    if i % 2 == 1:
        ans += 1
        
print(ans)

Fixed submission:
from collections import defaultdict

N = int(input())
A = defaultdict(int)

for _ in range(N):
    a = int(input())
    if A[a] == 1:
        A[a] = 0
    else:
        A[a] = 1
        
print(sum(A.values()))
Buggy python submission (verdict: Runtime Error):
X, t = map(int, input(),split())
print(max(X - t, 0))

Fixed submission:
X, t = map(int, input().split())
print(max(X - t, 0))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

maximum = max(A)
count = [0]*(maximum + 1)

for i in range(N):
    if A[i] == 0:
        count[0] += 1
        count[1] += 1
        
    elif A[i] == maximum:
        count[A[i]] += 1
        count[A[i] - 1] += 1
    
    else:
        count[A[i] + 1] += 1
        count[A[i]] += 1
        count[A[i] - 1] += 1

print(max(count))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

maximum = max(A)
count = [0]*(maximum + 2)

for i in range(N):
    if A[i] == 0:
        count[0] += 1
        count[1] += 1
        
    elif A[i] == maximum:
        count[A[i]] += 1
        count[A[i] - 1] += 1
    
    else:
        count[A[i] + 1] += 1
        count[A[i]] += 1
        count[A[i] - 1] += 1

print(max(count))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

count = [0]*(max(A) + 1)

for i in range(N):
    if A[i] == 0:
        count[0] += 1
        count[1] += 1
        
    elif A[i] == max(A):
        count[A[i]] += 1
        count[A[i] - 1] += 1
    
    else:
        count[A[i] + 1] += 1
        count[A[i]] += 1
        count[A[i] - 1] += 1

print(max(count))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

maximum = max(A)
count = [0]*(maximum + 2)

for i in range(N):
    if A[i] == 0:
        count[0] += 1
        count[1] += 1
        
    elif A[i] == maximum:
        count[A[i]] += 1
        count[A[i] - 1] += 1
    
    else:
        count[A[i] + 1] += 1
        count[A[i]] += 1
        count[A[i] - 1] += 1

print(max(count))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

count = [0 for i in range(max(A) + 1)]
for i in range(N):
    if A[i] == 0:
        count[A[i]] += 1
        count[A[i] + 1] += 1
    elif A[i] == max(A):
        count[A[i]] += 1
        count[A[i] - 1] += 1
    else:
        count[A[i] + 1] += 1
        count[A[i]] += 1
        count[A[i] - 1] += 1
print(max(count))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

maximum = max(A)
count = [0]*(maximum + 2)

for i in range(N):
    if A[i] == 0:
        count[0] += 1
        count[1] += 1
        
    elif A[i] == maximum:
        count[A[i]] += 1
        count[A[i] - 1] += 1
    
    else:
        count[A[i] + 1] += 1
        count[A[i]] += 1
        count[A[i] - 1] += 1

print(max(count))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

num = [A.count(A[i]) + A.count(A[i]-1) + A.count(A[i]+1) for i in range(N)]
print(max(num))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

maximum = max(A)
count = [0]*(maximum + 2)

for i in range(N):
    if A[i] == 0:
        count[0] += 1
        count[1] += 1
        
    elif A[i] == maximum:
        count[A[i]] += 1
        count[A[i] - 1] += 1
    
    else:
        count[A[i] + 1] += 1
        count[A[i]] += 1
        count[A[i] - 1] += 1

print(max(count))
Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(int, input().split()))

dist = [P[i-1] - i for i in range(1, N+1)]

count = 0

for i in range(N):
    if dist[i] == 0:
        count += 1
        dist[i] -= 1
        dist[i+1] += 1
    elif i == N-1 and dist[i] == 0:
        count += 1
        dist[i] += 1
        dist[i-1] -= 1
        
print(count)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))

dist = [P[i-1] - i for i in range(1, N+1)]

count = 0

for i in range(N):
    if dist[i] == 0:
        count += 1
        if i < N-1:
            dist[i] -= 1
            dist[i+1] += 1
        else: # i == N-1
            dist[i] += 1
            dist[i-1] -= 1
    
print(count)

Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(int, input().split()))

dist = [P[i-1] - i for i in range(1, N+1)]

count = 0

for i in range(N):
    if dist[i] == 0:
        count += 1
        dist[i] -= 1
        dist[i+1] += 1
    elif i == N-1 and dist[i+1] == 0:
        count += 1
        dist[i] -= 1
        dist[i+1] += 1
        
print(count)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))

dist = [P[i-1] - i for i in range(1, N+1)]

count = 0

for i in range(N):
    if dist[i] == 0:
        count += 1
        if i < N-1:
            dist[i] -= 1
            dist[i+1] += 1
        else: # i == N-1
            dist[i] += 1
            dist[i-1] -= 1
    
print(count)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
*A, = map(int, input().split())
A = sorted(A)
diff = min([A[i+1] - A[i] for i in range(N-1) if A[i+1] - A[i] > 0])
for a in [a for a in A if a >= K]:
    if (a - K) % diff == 0:
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')

Fixed submission:
N, K = map(int, input().split())
*A, = map(int, input().split())
A = sorted(A)
if K in A:
    print('POSSIBLE')
else:
    temp = [A[i+1] - A[i] for i in range(N-1) if A[i+1] - A[i] > 0]
    diff = min(temp) if temp else -1
    if diff == -1:
        print('IMPOSSIBLE')
    else:
        for a in [a for a in A if a >= K]:
            if (a - K) % diff == 0:
                print('POSSIBLE')
                break
        else:
            print('IMPOSSIBLE')

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
*A, = map(int, input().split())
A = sorted(A)
diff = min([A[i+1] - A[i] for i in range(N-1)])
for a in [a for a in A if a >= K]:
    if (a - K) % diff == 0:
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')

Fixed submission:
N, K = map(int, input().split())
*A, = map(int, input().split())
A = sorted(A)
if K in A:
    print('POSSIBLE')
else:
    temp = [A[i+1] - A[i] for i in range(N-1) if A[i+1] - A[i] > 0]
    diff = min(temp) if temp else -1
    if diff == -1:
        print('IMPOSSIBLE')
    else:
        for a in [a for a in A if a >= K]:
            if (a - K) % diff == 0:
                print('POSSIBLE')
                break
        else:
            print('IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
s = input().split()
print('YES' if str(''.join(s))%4 == 0 else 'NO')

Fixed submission:
s = input().split()
print('YES' if int(''.join(s))%4 == 0 else 'NO')
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify, heappop, heappush, heappushpop

N = int(input())
*A, = map(int, input().split())
INF = 10**16
first = A[:N]
heapify(first)
second = [-a for a in A[2*N:]]
heapify(second)
f = [0]*(N+1)
s = [0]*(N+1)
f[0] = sum(first)
s[N] = - sum(second)
for k in range(1, N+1):
    heappushpop(first, A[N-1+k])
    f[k] = sum(first)
for k in range(N-1, -1, -1):
    heappushpop(second, -A[N+k])
    s[k] = - sum(second)
ans = -INF
for k in range(N+1):
    ans = max(ans, f[k] - s[k])
print(ans)

Fixed submission:
from heapq import heapify, heappushpop

N = int(input())
*A, = map(int, input().split())
INF = 10**16
first = A[:N]
heapify(first)
second = [-a for a in A[2*N:]]
heapify(second)
f = [0]*(N+1)
s = [0]*(N+1)
f[0] = sum(first)
s[N] = - sum(second)
for k in range(1, N+1):
    a = heappushpop(first, A[N-1+k])
    f[k] = f[k-1] + A[N-1+k] - a
for k in range(N-1, -1, -1):
    a = heappushpop(second, -A[N+k])
    s[k] = s[k+1] + A[N+k] + a
ans = -INF
for k in range(N+1):
    ans = max(ans, f[k] - s[k])
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

def bellman_ford(V, E, s):
    '''
    Input:
        V = list(range(N))
        E = {i: defaultdict(int) for i in range(N)}
        s (in V) : start vertex
    Output:
        dist: the list of the minimum cost from s to arbitrary vertex v in the given graph
    '''
    INF = float('inf')
    N = len(V)
    dist = [INF]*N
    dist[s] = 0
    for n_iterations in range(N):
        updated = [False]*N
        for v in V:
            d = dist[v]
            if d != INF:
                for u, c in E[v].items():
                    temp = d + c
                    if dist[u] > temp:
                        updated[u] = True
                        dist[u] = temp
                        prev[u] = v
        if sum(updated) == 0: # the minimum costs are already stored in dist
            break
    else: # the above loop is not broken if and only if there exists a negative cycle
        if updated[N-1]: return None
        else: return dist
    return dist

N, M = map(int, input().split())
E = {i: defaultdict(int) for i in range(N)}
for _ in range(M):
    a, b, c = map(int, input().split())
    E[a-1][b-1] = -c
V = list(range(N))
dist = bellman_ford(V, E, 0)
if dist is None:
    print('inf')
else:
    print(-dist[N-1])

Fixed submission:
from collections import defaultdict

def bellman_ford(V, E, s):
    '''
    Input:
        V = list(range(N))
        E = {i: defaultdict(int) for i in range(N)}
        s (in V) : start vertex
    Output:
        dist: the list of the minimum cost from s to arbitrary vertex v in the given graph
    '''
    INF = float('inf')
    N = len(V)
    dist = [INF]*N
    dist[s] = 0
    for n_iterations in range(N):
        updated = [False]*N
        for v in V:
            d = dist[v]
            if d != INF:
                for u, c in E[v].items():
                    temp = d + c
                    if dist[u] > temp:
                        updated[u] = True
                        dist[u] = temp
        if sum(updated) == 0: # the minimum costs are already stored in dist
            break
    else: # the above loop is not broken if and only if there exists a negative cycle
        if updated[N-1]: return None
        else: return dist
    return dist

N, M = map(int, input().split())
E = {i: defaultdict(int) for i in range(N)}
for _ in range(M):
    a, b, c = map(int, input().split())
    E[a-1][b-1] = -c
V = list(range(N))
dist = bellman_ford(V, E, 0)
if dist is None:
    print('inf')
else:
    print(-dist[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, W = map(int, input().split())
items = []
for _ in range(N):
    items.append(tuple(map(int, input().split())))
v_max = sum([i[1] for i in items])
INF = 10**12
dp = np.array([[INF for j in range(v_max+1)] for _ in range(N+1)])
dp[0, 0] = 0
for i in range(1, N+1):
    w, v = items[i-1]
    dp[i, :v] = dp[i-1, :v]
    dp[i, v:] = np.minimum(dp[i-1, :-v] + w, dp[i-1, v:])
ans = 0
for v in range(v_max, -1, -1):
    if dp[N][v] <= W:
        ans = v
        break
print(ans)

Fixed submission:
from collections import defaultdict
from itertools import product, accumulate

N, W = map(int, input().split())
items = defaultdict(list)
for _ in range(N):
    w, v = map(int, input().split())
    items[w].append(v)
weights = list(items.keys())
nums = {w: len(items[w]) for w in weights}
cumsum = {w: None for w in weights}
for i, w in enumerate(weights):
    items[w].sort(reverse=True)
    cumsum[w] = [0] + list(accumulate(items[w]))
ans = 0
for tup in product(*[range(nums[w] + 1) for w in weights]):
    temp_weight = sum(w * t for w, t in zip(weights, tup))
    if temp_weight > W: continue
    temp_value = sum(cumsum[w][t] for w, t in zip(weights, tup))
    ans = max(temp_value, ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, W = map(int, input().split())
items = []
for _ in range(N):
    items.append(tuple(map(int, input().split())))
dp = np.array([[0 for j in range(W+1)] for _ in range(N+1)])
for i in range(1, N+1):
    w, v = items[i-1]
    dp[i, :w] = dp[i-1, :w]
    dp[i, w:] = np.maximum(dp[i-1, :-w] + v, dp[i-1, w:])
print(dp[N, W])

Fixed submission:
from collections import defaultdict
from itertools import product, accumulate

N, W = map(int, input().split())
items = defaultdict(list)
for _ in range(N):
    w, v = map(int, input().split())
    items[w].append(v)
weights = list(items.keys())
nums = {w: len(items[w]) for w in weights}
cumsum = {w: None for w in weights}
for i, w in enumerate(weights):
    items[w].sort(reverse=True)
    cumsum[w] = [0] + list(accumulate(items[w]))
ans = 0
for tup in product(*[range(nums[w] + 1) for w in weights]):
    temp_weight = sum(w * t for w, t in zip(weights, tup))
    if temp_weight > W: continue
    temp_value = sum(cumsum[w][t] for w, t in zip(weights, tup))
    ans = max(temp_value, ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
*A, = map(int, input().split())
ans = -float('inf')
for i in range(N - K + 1):
    ans = max(ans, max(sum(A[i: i+K]), 0) + sum([a for a in A[:i] + A[i+K:] if a > 0]))
print(ans)

Fixed submission:
from itertools import accumulate

N, K = map(int, input().split())
*A, = map(int, input().split())
A_pos = list(map(lambda x: max(x, 0), A))
A_pos_cumsum = [0] + list(accumulate(A_pos))
ans = -float('inf')
S = sum(A[0: K])
for i in range(N - K + 1):
    ans = max(ans, max(S, 0) + A_pos_cumsum[i] + (A_pos_cumsum[-1] - A_pos_cumsum[i+K]))
    S = S - A[i] + A[i+K] if i < N - K else 0
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import product

H, W = map(int, input().split())
table = [input().split() for _ in range(H)]
for i, j in product(range(H), range(W)):
    if table[i][j] == 'snuke': print('ABCDEFGHIJ'[j] + str(i+1)); break

Fixed submission:
from itertools import product

H, W = map(int, input().split())
table = [input().split() for _ in range(H)]
for i, j in product(range(H), range(W)):
    if table[i][j] == 'snuke': print('ABCDEFGHIJKLMNOPQRSTUVWXYZ'[j] + str(i+1)); break
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ratio = []
for _ in range(N):
    ratio.append(tuple(map(int, input().split())))
ans = 0; total_t = 0; total_a = 0;
for t, a in ratio:
    i = 1
    while total_t > t*i or total_a > a*i:
        i += 1
    total_t = t*i
    total_a = a*i
    ans = total_t + total_a
print(ans)

Fixed submission:
N = int(input())
ratio = []
for _ in range(N):
    ratio.append(tuple(map(int, input().split())))
total_t = 1; total_a = 1;
for t, a in ratio:
    q = max((total_t + t - 1) // t, (total_a + a - 1) // a)
    total_t = t*q
    total_a = a*q
ans = total_t + total_a
print(ans)