Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

black = 0
imos = [[0 for i in range(k)] for j in range(k)]

for i in range(n):
    X, Y, C = input().split()
    x = int(X)
    y = int(Y)
    c = 1 if C == "W" else 0

    x = x % (2*k)
    y = y % (2*k)
    if x > k-1:
        x -= k
        c += 1
    if y > k-1:
        y -= k
        c += 1
    c = 1 if c%2 == 1 else -1
    imos[x][y] += c
    if c == -1:
        black += 1

for i in range(k):
    for j in range(k-1):
        imos[i][j+1] += imos[i][j]

for j in range(k):
    for i in range(k-1):
        imos[i+1][j] += imos[i][j]

ans = 0
for i in range(k):
    for j in range(k):
        m = imos[k-1][k-1] - imos[k-1][j] - imos[i][k-1] + 2 * imos[i][j]
        ans = max(ans, max(n-(black+m), black+m))
print(ans)

Fixed submission:
n, k = map(int, input().split())

black = 0
imos = [[0 for i in range(k)] for j in range(k)]

for i in range(n):
    X, Y, C = input().split()
    x = int(X)
    y = int(Y)
    c = 1 if C == "W" else 0

    x = x % (2*k)
    y = y % (2*k)
    if x > k-1:
        x -= k
        c += 1
    if y > k-1:
        y -= k
        c += 1
    c = 1 if c%2 == 1 else -1
    imos[x][y] += c
    if c == -1:
        black += 1

for i in range(k):
    for j in range(k-1):
        imos[i][j+1] += imos[i][j]

for j in range(k):
    for i in range(k-1):
        imos[i+1][j] += imos[i][j]

ans = 0
for i in range(k):
    for j in range(k):
        m = imos[k-1][k-1] - imos[k-1][j] - imos[i][k-1] + 2 * imos[i][j]
        ans = max(ans, max(n-(black+m), black+m))
print(ans)
Buggy python submission (verdict: Runtime Error):
n, y = list(map(int, input().split()))

a = -1
b = -1
c = -1

for i in range(n+1):
    for j in range(n+1-i):
        if i*1000 + j*5000 + (n-i-j)*10000 == y:
            a, b, c = i, j, n-i-j
            break
print(c, b, a)

Fixed submission:
s = input()

a = s[0:3] + "8" + s[4:]
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
x, y = map(int, input().split())

x_list = []
y_list = []

st = s.split("T")
x -= len(st[0])

for i, ls in enumerate(st[1:]):
    if i % 2:
        x_list.append(len(ls))
    else:
        y_list.append(len(ls))

dpx = [[0 for i in range(16001)] for j in range(len(x_list)+1)]
dpy = [[0 for i in range(16001)] for j in range(len(y_list)+1)]

dpx[0][8000] = 1
dpy[0][8000] = 1

for i in range(len(x_list)):
    for num in range(16001):
        if num + x_list[i] <= 16000 and dpx[i][num] == 1:
            dpx[i+1][num+x_list[i]] = 1
        if num - x_list[i] >= 0 and dpx[i][num] == 1:
            dpx[i+1][num-x_list[i]] = 1

for i in range(len(y_list)):
    for num in range(16001):
        if num + y_list[i] <= 16000 and dpy[i][num] == 1:
            dpy[i+1][num+y_list[i]] = 1
        if num - y_list[i] >= 0 and dpy[i][num] == 1:
            dpy[i+1][num-y_list[i]] = 1

if dpx[len(x_list)][x+8000] == 1 and dpy[len(y_list)][y+8000] == 1:
    print("Yes")
else:
    print("No")

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

x_list = []
y_list = []

st = s.split("T")
x -= len(st[0])

for i, ls in enumerate(st[1:]):
    if i % 2:
        x_list.append(len(ls))
    else:
        y_list.append(len(ls))

def judge(xy, ls):
    dp = set([0])
    for l in ls:
        tmp = []
        for v in dp:
            tmp.append(v+l)
            tmp.append(v-l)
        dp = set(tmp)
    return xy in dp

print("Yes" if judge(x, x_list) and judge(y, y_list) else "No")
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()

ans = "UNRESTORABLE"

memo = -1

for i in range(len(s)):
    for j in range(len(t)):
        count = 0
        if s[i+j] == t[j] or t[j] == "?":
            count += 1
        else:
            count = 0
            break
        if count == len(t):
            ans = s[i:i+len(t)]
            memo = i
            count = 0

if ans == "UNRESTORABLE":
    print(ans)
else:
    ans1 = ""
    for word in t:
        if word == "?":
            ans1 += "a"
        else:
            ans1 += word
    ans1[memo:memo+len(t)] = ans
    print(ans1)
        


Fixed submission:
s = input()
t = input()

ans = "UNRESTORABLE"

memo = -1

for i in range(len(s) - len(t) + 1):
    count = 0
    for j in range(len(t)):
        if s[i+j] == t[j] or s[i+j] == "?":
            count += 1
        else:
            break
        if count == len(t):
            ans = t
            memo = i

if ans == "UNRESTORABLE":
    print(ans)
else:
    ans1 = ""
    for word in s:
        if word == "?":
            ans1 += "a"
        else:
            ans1 += word
    ans2 = ans1[0:memo] + ans + ans1[memo+len(t):]
    print(ans2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
t = list(map(int, input().split()))
v = list(map(int, input().split()))

T = [0 for i in range(n)]
T[0] = t[0]
for i in range(n-1):
    T[i+1] = T[i] + t[i+1]

INF = float('inf')
V = [INF for i in range(2*T[n-1]+1)]

for i in range(2*T[n-1]+1):
    V[i] = min(V[i], 0.5 * i)
    V[i] = min(V[i], T[n-1] - 0.5 * i)

for vi in range(n):
    for ti in range(2*T[n-1]+1):
        if vi == 0:
            if ti <= T[0] * 2:
                V[ti] = min(V[ti], v[0])
            else:
                V[ti] = min(V[ti], v[0] + ti * 0.5 - T[0])
        else:
            if ti <= T[vi-1] * 2:
                V[ti] = min(V[ti], v[vi] + T[vi-1] - ti * 0.5)
            elif (T[vi-1] * 2 <= ti) and (ti <= T[vi] * 2):
                V[ti] = min(V[ti], v[vi])
            else:
                V[ti] = min(V[ti], v[vi] + (ti * 0.5 - T[vi]))

ans = 0
for i in range(2*T[n-1]):
    ans += (V[i] + V[i+1]) * 0.5 * 0.5

print(ans)

Fixed submission:
n = int(input())
t = list(map(int, input().split()))
v = list(map(int, input().split()))

T = [0 for i in range(n)]
T[0] = t[0]
for i in range(n-1):
    T[i+1] = T[i] + t[i+1]

INF = float('inf')
V = [INF for i in range(2*T[n-1]+1)]

for i in range(2*T[n-1]+1):
    V[i] = min(V[i], 0.5 * i)
    V[i] = min(V[i], T[n-1] - 0.5 * i)

for vi in range(n):
    for ti in range(2*T[n-1]+1):
        if vi == 0:
            if ti <= T[0] * 2:
                V[ti] = min(V[ti], v[0])
            else:
                V[ti] = min(V[ti], v[0] + ti * 0.5 - T[0])
        else:
            if ti <= T[vi-1] * 2:
                V[ti] = min(V[ti], v[vi] + T[vi-1] - ti * 0.5)
            elif (T[vi-1] * 2 <= ti) and (ti <= T[vi] * 2):
                V[ti] = min(V[ti], v[vi])
            else:
                V[ti] = min(V[ti], v[vi] + (ti * 0.5 - T[vi]))

ans = 0
for i in range(2*T[n-1]):
    ans += (V[i] + V[i+1]) * 0.5 * 0.5

print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, C, D, E, F = map(int, input().split())

water_set = set()
sugar_set = set()

for ai in range(3000 // (100 * A) + 1):
    for bi in range(3000 // (100 * B) + 1):
        if ai * 100 * A + bi * 100 * B <= 3000:
            water_set.add(ai * 100 * A + bi * 100 * B)

for ci in range(3000 // C + 1):
    for di in range(3000 // D + 1):
        if ci * C + di * D <= 3000:
            sugar_set.add(ci * C + di * D)

water_list = sorted(list(water_set))
sugar_list = sorted(list(sugar_set))

cons = 0
water_ans = 0
sugar_ans = 0
for water in water_list:
    for sugar in sugar_list:
        if water + sugar <= F and sugar <= E * water:
            if 100 * water / (water + sugar) > cons:
                cons = 100 * water / (water + sugar)
                water_ans = water
                sugar_ans = sugar

print(sugar_ans, water_ans)

Fixed submission:
A, B, C, D, E, F = map(int, input().split())

water_set = set()
sugar_set = set()

for a in range(0, F+1, 100*A):
    for b in range(0, F+1, 100*B):
        if a + b <= F:
            water_set.add(a + b)

for c in range(0, F+1, C):
    for d in range(0, F+1, D):
        if c + d <= F//2 + 1:
            sugar_set.add(c + d)

water_set.remove(0)
water_list = list(water_set)
sugar_list = list(sugar_set)

cons = -1
water_ans = 0
sugar_ans = 0
for water in water_list:
    for sugar in sugar_list:
        if water + sugar <= F and sugar * 100 <= E * water:
            if 100 * sugar / (water + sugar) > cons:
                cons = 100 * sugar / (water + sugar)
                water_ans = water
                sugar_ans = sugar

print(water_ans + sugar_ans, sugar_ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations

N, M, R = map(int, input().split())
r = list(map(int, input().split()))

INF = float('inf')
graph = [[INF for i in range(N)] for j in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    graph[A-1][B-1] = C
    graph[B-1][A-1] = C

for i in range(N):
    graph[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
            graph[j][i] = min(graph[j][i], graph[j][k] + graph[k][i])

ans = 10**9
for p in permutations(r, len(r)):
    dist = 0
    flag = 0
    for i in range(len(r) - 1):
        if graph[p[i]-1][p[i+1]-1] == INF:
            flag = 1
            continue
        dist += graph[p[i]-1][p[i+1]-1]
    if flag == 0:
        ans = min(ans, dist)

print(ans)

Fixed submission:
from itertools import permutations

N, M, R = map(int, input().split())
r = list(map(int, input().split()))

INF = float('inf')
graph = [[INF for i in range(N)] for j in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    graph[A-1][B-1] = C
    graph[B-1][A-1] = C

for i in range(N):
    graph[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
            graph[j][i] = min(graph[j][i], graph[j][k] + graph[k][i])

ans = 10**9
for p in permutations(r, len(r)):
    dist = 0
    flag = 0
    for i in range(len(r) - 1):
        if graph[p[i]-1][p[i+1]-1] == INF:
            flag = 1
            continue
        dist += graph[p[i]-1][p[i+1]-1]
    if flag == 0:
        ans = min(ans, dist)

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(n):
    if p[i] == i+1:
        p[i+1] = p[i]
        ans += 1

print(ans)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    if p[i] == i+1:
        p[i+1] = p[i]
        ans += 1

if p[n-1] == n:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s1 = input()
s2 = input()

mod = 10**9 + 7

# dp[i][j] : i番目まで見たときに、i番目の要素が j = 0 だと縦に、
# j = 1 だと横にブロックが並んでいた時の色の塗りかた (mod 10**9+7)
dp = [[0 for j in range(2)] for i in range(n+1)]

if s1[0] == s2[0]:
    dp[1][0] = 3
    i = 1
else:
    dp[2][1] = 3 * 2
    i = 2
while i < n:
    if s1[i] == s2[i]:
        if s1[i+1] == s2[i+1]:
            dp[i+1][0] = dp[i][0] * 2 % mod
            
            i += 1
        else:
            dp[i+2][1] = dp[i][0] * 2 % mod
            i += 2
    else:
        if s1[i+2] == s2[i+2]:
            dp[i+2][0] = dp[i][1] % mod
            i += 2
        else:
            dp[i+3][1] = dp[i][1] * 2 % mod
            i += 3

print((dp[n][0] % mod + dp[n][1] % mod) % mod)

Fixed submission:
n = int(input())
s1 = input()
s2 = input()

mod = 10**9 + 7

# dp[i][j] : i番目まで見たときに、i番目の要素が j = 0 だと縦に、
# j = 1 だと横にブロックが並んでいた時の色の塗りかた (mod 10**9+7)
dp = [[0 for j in range(2)] for i in range(n+1)]

if s1[0] == s2[0]:
    dp[0][0] = 3
    i = 0
else:
    dp[1][1] = 3 * 2
    i = 1
while i < n - 1:
    if s1[i] == s2[i]:
        if s1[i+1] == s2[i+1]:
            dp[i+1][0] = dp[i][0] * 2 % mod
            i += 1
        else:
            dp[i+2][1] = dp[i][0] * 2 % mod
            i += 2
    else:
        if s1[i+1] == s2[i+1]:
            dp[i+1][0] = dp[i][1] % mod
            i += 1
        else:
            dp[i+2][1] = dp[i][1] * 3 % mod
            i += 2

print((dp[n-1][0] % mod + dp[n-1][1] % mod) % mod)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s1 = input()
s2 = input()

mod = 10**9 + 7

# dp[i][j] : i番目まで見たときに、i番目の要素が j = 0 だと縦に、
# j = 1 だと横にブロックが並んでいた時の色の塗りかた (mod 10**9+7)
dp = [[0 for j in range(2)] for i in range(n+1)]

if s1[0] == s2[0]:
    dp[1][0] = 3
    i = 1
else:
    dp[2][1] = 3 * 2
    i = 2
while i < n:
    if s1[i] == s2[i]:
        if s1[i+1] == s2[i+1]:
            dp[i+1][0] = dp[i][0] * 2
            i += 1
        else:
            dp[i+2][1] = dp[i][0] * 2
            i += 2
    else:
        if s1[i+2] == s2[i+2]:
            dp[i+2][0] = dp[i][1]
            i += 2
        else:
            dp[i+3][1] = dp[i][1] * 2
            i += 3

print(dp[n][0] + dp[n][1])

Fixed submission:
n = int(input())
s1 = input()
s2 = input()

mod = 10**9 + 7

# dp[i][j] : i番目まで見たときに、i番目の要素が j = 0 だと縦に、
# j = 1 だと横にブロックが並んでいた時の色の塗りかた (mod 10**9+7)
dp = [[0 for j in range(2)] for i in range(n+1)]

if s1[0] == s2[0]:
    dp[0][0] = 3
    i = 0
else:
    dp[1][1] = 3 * 2
    i = 1
while i < n - 1:
    if s1[i] == s2[i]:
        if s1[i+1] == s2[i+1]:
            dp[i+1][0] = dp[i][0] * 2 % mod
            i += 1
        else:
            dp[i+2][1] = dp[i][0] * 2 % mod
            i += 2
    else:
        if s1[i+1] == s2[i+1]:
            dp[i+1][0] = dp[i][1] % mod
            i += 1
        else:
            dp[i+2][1] = dp[i][1] * 3 % mod
            i += 2

print((dp[n-1][0] % mod + dp[n-1][1] % mod) % mod)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

for k in range(1, n+1):
    s = set([i+1 for i in range(m)])
    while s:
        memo = [0] * (m + 1)
        flag = [0] * (n + 1)
        for j in range(m):
            for i in range(n):
                if flag[i] == 0 and a[i][j] in s:
                    memo[a[i][j]] += 1
                    flag[i] = 1
                    if memo[a[i][j]] > k:
                        s.remove(a[i][j])
                        break
            else:
                continue
            break
        if max(memo) <= k:
            print(k)
            exit()



Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

num = a[0]
for i in range(1, n):
    num = gcd(num, a[i])

if k > max(a):
    print("IMPOSSIBLE")
    exit()

if k % num == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if a == b:
    print(1)
    exit()

# 二進数xの長さを求める時、len(bin(x)) - 2　では、xが0のとき1を返してしまい、バグる原因になる
# よって、二進数の長さを計算する関数を用意しておく
def bitlen(x):
    return 1 + bitlen(x >> 1) if x else 0

t = a ^ b
n = bitlen(t)

T = 1 << (n - 1)

a = a & (T * 2 - 1)
b = b & (T * 2 - 1)

sb = b & (T - 1)
b_max = (2 ** bitlen(sb) - 1) | T

if (T + a) > b_max:
    print((b_max - a + 1) + (2 * T - 1 - (T + a) + 1))
else:
    print(2 * T - 1 - a + 1)


Fixed submission:
n, a, b = map(int, input().split())

if n == 1:
    if a == b:
        print(1)
    else:
        print(0)
else:
    if a < b:
        low = a * (n - 1) + b
        high = a + b * (n - 1)
        print(high - low + 1)
    elif a == b:
        print(1)
    else:
        print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans = -10**15
for i in range(n+1):
    b1 = a[:n+i]
    b2 = a[n+i:]

    b1.sort(reverse=True)
    s1 = sum(b1[:n])
    b2.sort()
    s2 = sum(b2[:n])
    ans = max(ans, s1-s2)

print(ans)

Fixed submission:
import heapq

n = int(input())
a = list(map(int, input().split()))

ans = -10**15
h1 = a[:n]
h2 = [-a[i] for i in range(2*n, 3*n)]
heapq.heapify(h1)
heapq.heapify(h2)

h1sum = sum(a[:n])
h2sum = sum(a[2*n:])

box1 = [h1sum]
box2 = [h2sum]

for i in range(1, n+1):
    heapq.heappush(h1, a[n+i-1])
    h1sum += a[n+i-1] - heapq.heappop(h1)
    box1.append(h1sum)

for i in range(1, n+1):
    heapq.heappush(h2, -a[2*n-i])
    h2sum += a[2*n-i] - (-heapq.heappop(h2))
    box2.append(h2sum)

for i in range(n+1):
    ans = max(ans, box1[i] - box2[n-i])

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from itertools import combinations

n, a, b = map(int, input().split())
v = list(map(int, input().split()))

v.sort(reverse=True)
v_cum = []
num = 0
for i in range(n):
    num += v[i]
    v_cum.append(num)

print(v_cum[a-1]/a)

if a == n:
    print(1)
else:
    if v[a-1] == v[a]:
        num = v[a-1]
        cf = Counter(v[:a])
        cb = Counter(v[a:])
        n_cf = cf[num]
        n_cb = cb[num]
        if cf[num] != a:
            print(combinations(n_cf+n_cb, n_cf))
        else:
            ans = 0
            for k in range(a, a+n_cb+1):
                ans += combinations(a+n_cb, k)
            print(ans)
    else:
        print(1)

Fixed submission:
from collections import Counter
from scipy.misc import comb

n, a, b = map(int, input().split())
v = list(map(int, input().split()))

v.sort(reverse=True)
v_cum = []
num = 0
for i in range(n):
    num += v[i]
    v_cum.append(num)

print(v_cum[a-1]/a)

if a == n:
    print(1)
else:
    if v[a-1] == v[a]:
        num = v[a-1]
        cf = Counter(v[:a])
        cb = Counter(v[a:])
        n_cf = cf[num]
        n_cb = cb[num]
        if n_cf != a:
            print(comb(n_cf+n_cb, n_cf, exact=True))
        else:
            ans = 0
            for k in range(a, min(b+1, a+n_cb+1)):
                ans += comb(a+n_cb, k, exact=True)
            print(ans)
    else:
        print(1)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]


for i in range(n-m+1):
    for j in range(n-m)+1:
        flag = 0
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] != b[k][l]:
                    flag = 1
        if flag == 0:
            print('Yes')
            exit()


print('No')


Fixed submission:
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]


for i in range(n-m+1):
    for j in range(n-m+1):
        flag = 0
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] != b[k][l]:
                    flag = 1
        if flag == 0:
            print('Yes')
            exit()


print('No')
Buggy python submission (verdict: Runtime Error):
s = input()

ans = 0

i = 0
while i < len(s):
    if s[i] == "A":
        num = 1
        while s[i] != "Z" and i < len(s):
            i += 1
            num += 1
        ans = max(ans, num)
    i += 1

print(ans)

Fixed submission:
s = input()

a = 0
for i in range(len(s)):
    if s[i] == "A":
        a = i
        break

b = 0
for i in range(len(s)):
    if s[i] == "Z":
        b = i

print(b-a+1)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)

n = int(input())
rev_g = [[] for _ in range(n+1)]
for i in range(n-1):
    a = int(input())
    rev_g[a].append(i+2)

def f(v):
    m = len(rev_g[v])
    if m == 0:
        return 0
    q = []
    for nv in rev_g[v]:
        q.append(f(nv))
    q.sort()
    dp = [0] * (m+1)
    for i in range(m):
        dp[i+1] = max(q[i]+1, dp[i]+1)
    return dp[m]


print(f(1))


Fixed submission:
n = int(input())
a = []
b  =[]
for i in range(n):
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)

num = 0
for i in reversed(range(n)):
    a[i] += num
    p = a[i] % b[i]
    if p == 0:
        continue
    p = b[i] - p
    num += p

print(num)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())

def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)

num = factorial(n)

ans = 1
for i in range(2, n+1):
    count = 0
    while num % i == 0:
        count += 1
        num = num // i
    ans *= (count + 1)

print(ans % (10 ** 9 + 7))

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
n = int(input())

def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)

num = factorial(n)

ans = 1
for i in range(2, n+1):
    count = 0
    while num % i == 0:
        count += 1
        num = num // i
    ans *= (count + 1)

print(ans % (10 ** 9 + 7))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))

cum = []
abscum = []

cu = 0
acu = 0
for i in range(n):
    cu += a[i]
    acu += abs(a[i])
    cu.append(cum)
    acu.append(abscum)

ans = 0
for i in range(n-k):
    if i == 0:
        ans = max(ans, abscum[n-1] - abscum[i+k-1] + abs(cum[i+k-1]))
    else:
        ans = max(ans, abscum[n - 1] - (abscum[i + k - 1] - abscum[i-1]) + abs(cum[i + k - 1] - cum[i-1]))
        
print(ans)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))

cum = []
abscum = []

cu = 0
acu = 0
for i in range(n):
    cu += a[i]
    acu += max(0, a[i])
    cum.append(cu)
    abscum.append(acu)

ans = 0
for i in range(n-k+1):
    if i == 0:
        ans = max(ans, abscum[n-1] - abscum[i+k-1] + max(0, cum[i+k-1]))
    else:
        ans = max(ans, abscum[n - 1] - (abscum[i + k - 1] - abscum[i-1]) + max(0, cum[i + k - 1] - cum[i-1]))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, x = map(int, input().split())
a = list(map(int, input().split()))

INF = float('inf')
dp = [[INF] * (n+10) for _ in range(n)]

for i in range(n):
    for k in range(n):
        if k == 0:
            dp[i][k] = a[i]
        else:
            dp[i][k] = min(dp[i][k-1], a[(i-k)%n])

ans = INF

for k in range(n):
    tmp = x * k
    for i in range(n):
        tmp += dp[i][k]
    ans = min(ans, tmp)

print(ans)


Fixed submission:
n, x = map(int, input().split())
a = list(map(int, input().split()))

INF = float('inf')
dp = [[INF] * (n+10) for _ in range(n)]

for i in range(n):
    for k in range(n):
        if k == 0:
            dp[i][k] = a[i]
        else:
            dp[i][k] = min(dp[i][k-1], a[(i-k)%n])

ans = INF

for k in range(n):
    tmp = x * k
    for i in range(n):
        tmp += dp[i][k]
    ans = min(ans, tmp)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, a = map(int, input().split())
x = list(map(int, input().split()))

y = []
for i in range(n):
    y.append(x[i] - a)

if n == 1:
    if x[0] == a:
        print(1)
    else:
        print(0)
else:
    g1 = []
    g2 = []

    for i in range(2 ** (n // 2)):
        h = 0
        for j in range(n // 2):
            flag = i >> j & 1
            h += y[j] * flag
        g1.append(h)

    m = n - n // 2
    for i in range(2 ** m):
        h = 0
        for j in range(m):
            flag = i >> j & 1
            h += y[n // 2 + j] * flag
        g2.append(h)

    g2.sort()

    ans = 0
    import bisect

    for i in g1:
        left = bisect.bisect_left(g2, -i)
        right = bisect.bisect(g2, -i)
        ans += right - left

    print(ans-1)


Fixed submission:
n, a = map(int, input().split())
x = list(map(int, input().split()))

y = []
for i in range(n):
    y.append(x[i] - a)

dp = [[0 for i in range(110*n)] for j in range(n+1)]

const = 50*n
dp[0][const] = 1


for i in range(n):
    for j in range(100*n + 1):
        dp[i+1][j] = dp[i][j]
        if j - y[i] >= 0 and j - y[i] <= 100*n:
            dp[i+1][j] += dp[i][j - y[i]]

print(dp[n][const]-1)
Buggy python submission (verdict: Runtime Error):
n, k = [int(x) for x in input().split()]

while n > abs(n-k):
    n = abs(n-k)
    if k == 1:
        n = 0
        break
    elif n%k == 0:
        n = 0
        break


print(n)

Fixed submission:
A, B, C = input().split()

temp = A
A = B
B = temp

temp = A
A = C
C = temp

print(A,B,C)