Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
S=input()
S=list(S)

count=0
for i in range(len(S)//2):
  if S[i]!=S[-(i+1)]:
    count = cunt+1

print(count)


Fixed submission:
S=input()
S=list(S)

count=0
for i in range(len(S)//2):
  if S[i]!=S[-(i+1)]:
    count+=1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split(" "))
a = [k for _ in range(n)]
for i in range(q):
    winIndex = int(input()) - 1
    for j in range(n):
        if j != winIndex:
            a[j]-= 1

for i in range(n):
    print("Yes" if a[i] > 0 else "No")

Fixed submission:
n, k, q = map(int, input().split(" "))
a = [0 for _ in range(n)]
for i in range(q):
    winIndex = int(input()) - 1
    a[winIndex] += 1  

for i in range(n):
    print("Yes" if k > q - a[i] else "No")
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split(" "))
a = list(map(int,input().split(" ")))

for i in range(m):
    maxIndex = 0
    for j in range(n):
        if a[maxIndex] < a[j]:
            maxIndex = j
    a[maxIndex] = a[maxIndex] >> 1
print(sum(a))

Fixed submission:
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] *= -1
heapq.heapify(a)
for _ in range(m):
    x = heapq.heappop(a)
    heapq.heappush(a, (-x//2)*(-1))    
 
print(-sum(a))

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

for i in range(m):
    maxIndex = 0
    for j in range(n):
        if a[maxIndex] < a[j]:
            maxIndex = j
    a[maxIndex] //= 2
print(sum(a))

Fixed submission:
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] *= -1
heapq.heapify(a)
for _ in range(m):
    x = heapq.heappop(a)
    heapq.heappush(a, (-x//2)*(-1))    
 
print(-sum(a))
Buggy python submission (verdict: Runtime Error):
n = int(input())
print(int((n-1)*n/2))

Fixed submission:
in1 = input()
in2 = input()
c = 0
if in1[0] == in2[0]: c +=1
if in1[1] == in2[1]: c +=1
if in1[2] == in2[2]: c +=1
print(c)
Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())

import numpy as np
 
dp = np.zeros(W + 1, dtype = int)

for i in range(N):
    w, v = map(int, input().split())
    np.maximum(dp[:-w] + v, dp[w:], out = dp[w:])

print(dp.max())

Fixed submission:
N,W = map(int,input().split())
 
import numpy as np
dp = np.full(10 ** 5 + 1, W + 1, dtype = int)
dp[0] = 0

for i in range(N):
  w, v = map(int, input().split())
  np.minimum(dp[:-v] + w, dp[v:], out = dp[v:])

for i in range(len(dp) - 1, -1, -1):
    if dp[i] <= W:
        print(i)
        break
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split(" "))
s = []
for i in range(h):
    s.append(str(input()))
d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
ss = ["" for i in range(h)]
for i in range(h):
    for j in range(w):
        f = False
        if s[j][i] == ".":
            f = True
            continue
        for dx, dy in d:
            if 0 <= i + dx < w and 0 <= j + dy < h:
                if s[j + dy][i + dx] == "#":
                    f = True
                    break
        if not f:
            break
    if not f:
        break

if f:
    print("Yes")
else:
    print("No")


Fixed submission:
h, w = map(int, input().split(" "))
s = []
for i in range(h):
    s.append(str(input()))
d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
ss = ["" for i in range(h)]
for i in range(h):
    for j in range(w):
        f = False
        if s[i][j] == ".":
            f = True
            continue
        for dy, dx in d:
            if 0 <= i + dy < h and 0 <= j + dx < w:
                if s[i + dy][j + dx] == "#":
                    f = True
                    break
        if not f:
            break
    if not f:
        break

if f:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = [0] * 100
for i in range(0, n):
    inp = int(input())
    d[inp] += 1

count = 0
for i in d:
    if i > 0:
        count += 1
print(count)

Fixed submission:
n = int(input())
d = [0] * 101
for i in range(0, n):
    inp = int(input())
    d[inp] += 1

count = 0
for i in d:
    if i > 0:
        count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split(" ")))

mmax = max(a)
mmin = min(a)
mcount = 0
for i in range(mmin, mmax + 1):
    count = 0
    count += a.count(i)
    count += a.count(i + 1)
    count += a.count(i - 1)
    if mcount < count:
        mcount = count

print(mcount)


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

c_dic = {}
for i in a:
    if i not in c_dic:
        c_dic[i] = 1
    else:
        c_dic[i] += 1
    
    if i + 1 not in c_dic:
        c_dic[i + 1] = 1
    else:
        c_dic[i + 1] += 1

    if i - 1 not in c_dic:
        c_dic[i - 1] = 1
    else:
        c_dic[i - 1] += 1

print(max(c_dic.values()))

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

mmax = max(a)
mmin = min(a)
mcount = 0
for i in range(mmin, mmax + 1):
    count = 0
    count += a.count(i)
    count += a.count(i + 1)
    count += a.count(i - 1)
    if mcount < count:
        mcount = count

print(mcount)


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

c_dic = {}
for i in a:
    if i not in c_dic:
        c_dic[i] = 1
    else:
        c_dic[i] += 1
    
    if i + 1 not in c_dic:
        c_dic[i + 1] = 1
    else:
        c_dic[i + 1] += 1

    if i - 1 not in c_dic:
        c_dic[i - 1] = 1
    else:
        c_dic[i - 1] += 1

print(max(c_dic.values()))
Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
l = []
for i in range(1, int(math.sqrt(n))):
    if n % i == 0:
        a = len(str(int(n / i)))
        b = len(str(int(i)))
        l.append(max(a, b))

print(min(l))

Fixed submission:
import math

n = int(input())
l = []
for i in range(1, int(math.sqrt(n)) + 1):
    if n % i == 0:
        a = len(str(int(n / i)))
        b = len(str(int(i)))
        l.append(max(a, b))

print(min(l))
Buggy python submission (verdict: Time Limit Exceeded):
kk, s = map(int, input().split(" "))
count = 0
for i in range(0, kk + 1):
    for j in range(0, kk + 1):
        for k in range(0, kk + 1):
            if i + j + k == s:
                count += 1

print(count)


Fixed submission:
k, s = map(int, input().split(" "))
count = 0
for i in range(0, k + 1):
    for j in range(0, k + 1):
            if 0 <= s - i - j <=k:
                count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
s = input()
n = len(s)
cost = 0
for i in range(n // 2):
    cost += (s[i] != s[n - i])
print(cost)

Fixed submission:
s = input()
n = len(s)
cost = 0
for i in range(n // 2):
    cost += (s[i] != s[n - i - 1])
print(cost)
Buggy python submission (verdict: Runtime Error):
def all_you_can_eat(n, t, a, b):
    dp = [[0 for _ in range(2)] for _ in range(t)]
    for x in range(n):
        for i in reversed(range(t)):
            if i + a[x] < t:
                dp[i + a[x]][0] = max(dp[i + a[x]][0], dp[i][0] + b[x])
                dp[i + a[x]][1] = max(dp[i + a[x]][1], dp[i][1] + b[x])
            dp[i][1] = max(dp[i][1], dp[i][0] + b[x])
    return dp[t-1][1]


def solve():
    n, t = map(int, input().split())
    a = [0 for _ in range(n)]
    b = [0 for _ in range(n)]
    for i in range(n):
        a[i], b[i] = map(int, input().split())

    print(all_you_can_eat(n, t, a, b))


if __name__ == "__main__":
    solve()


Fixed submission:
print(int(input()) ** 2)
Buggy python submission (verdict: Time Limit Exceeded):
def all_you_can_eat(n, t, a, b):
    dp = [[0 for _ in range(2)] for _ in range(t)]
    for x in range(n):
        for i in reversed(range(t)):
            if i + a[x] < t:
                dp[i + a[x]][0] = max(dp[i + a[x]][0], dp[i][0] + b[x])
                dp[i + a[x]][1] = max(dp[i + a[x]][1], dp[i][1] + b[x])
            dp[i][1] = max(dp[i][1], dp[i][0] + b[x])
    return dp[t-1][1]


def solve():
    n, t = map(int, input().split())
    a = [0 for _ in range(n)]
    b = [0 for _ in range(n)]
    for i in range(n):
        a[i], b[i] = map(int, input().split())

    print(all_you_can_eat(n, t, a, b))


if __name__ == "__main__":
    solve()


Fixed submission:
import numpy as np


def solve():


    N, T = map(int, input().split())

    A = []
    B = []

    for _ in range(N):
        A_temp, B_temp = map(int, input().split())
        A.append(A_temp)
        B.append(B_temp)

    A = np.array(A, np.int)
    B = np.array(B, np.int)

    idx = np.argsort(A)
    A = A[idx]
    B = B[idx]

    dp = np.zeros((N, T), np.int)

    for i in range(N - 1):
        dp[i + 1, :A[i]] = dp[i, :A[i]]
        dp[i + 1, A[i]:] = np.maximum(dp[i, A[i]:], dp[i, :-A[i]] + B[i])

    print(np.max(dp[:, -1] + B))


if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Runtime Error):
def all_you_can_eat(n, t, a, b):
    dp = [[0 for _ in range(2)] for _ in range(t)]
    for x in range(n):
        for i in reversed(range(t)):
            if i + a[x] < t:
                dp[i + a[x]][0] = max(dp[i + a[x]][0], dp[i][0] + b[x])
                dp[i + a[x]][1] = max(dp[i + a[x]][1], dp[i][1] + b[x])
            dp[i][1] = max(dp[i][1], dp[i][0] + b[x])
    return dp[t-1][1]


def solve():
    n, t = map(int, input().split())
    a = []
    b = []
    for i in range(n):
        a[i], b[i] = map(int, input().split())

    print(all_you_can_eat(n, t, a, b))


if __name__ == "__main__":
    solve()


Fixed submission:
import numpy as np


def solve():


    N, T = map(int, input().split())

    A = []
    B = []

    for _ in range(N):
        A_temp, B_temp = map(int, input().split())
        A.append(A_temp)
        B.append(B_temp)

    A = np.array(A, np.int)
    B = np.array(B, np.int)

    idx = np.argsort(A)
    A = A[idx]
    B = B[idx]

    dp = np.zeros((N, T), np.int)

    for i in range(N - 1):
        dp[i + 1, :A[i]] = dp[i, :A[i]]
        dp[i + 1, A[i]:] = np.maximum(dp[i, A[i]:], dp[i, :-A[i]] + B[i])

    print(np.max(dp[:, -1] + B))


if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Runtime Error):
def solve():
    n = int(input())
    d = list(map(int, input().split()))

    print(calc(d, n))


def calc(d, n):
    if d[0] != 0:
        return 0
    else:
        k = max(d)
        a = [0] * (k + 1)
        for i in range(1, n):
            a[d[i]] += 1
        if a[0] > 0:
            return 0
        else:
            r = 1
            for i in range(2, k + 1):
                r *= a[i - 1] ** a[i]
            return r % 998244353


if __name__ == "__main__":
    solve()


Fixed submission:
def solve():
    i = int(input())
    print(i // 2 -1 if i % 2 == 0 else i // 2)


if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = list(map(lambda x: int(x), input().split()))

res = 0


def is_triangle(i, j, k):
    return 1 if i < j + k and j < i + k and k < i + j else 0


i = 0
j = 1
k = 2

while i < n:
    while j < n:
        while k < n:
            res += is_triangle(d[i],d[j],d[k])
            k += 1
        j += 1
        k = j + 1
    i += 1
    j = i + 1
    k = j + 1


print(res)

Fixed submission:
n = int(input())
d = list(map(lambda x: int(x), input().split()))
d.sort()

res = 0

for i in range(n-2):
    k = i + 2
    for j in range(i+1, n-1):
        while k < n and d[i] + d[j] > d[k]:
            k += 1
        if k > j:
            res += k - j - 1

print(res)

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

res = 0


def is_triangle(i, j, k):
    return i < j + k and j < i + k and k < i + j


for i in range(n):
    for j in range(n):
        for k in range(n):
            if i != j and j != k and i != k and is_triangle(d[i],d[j],d[k]):
                res += 1

print(res // 6)

Fixed submission:
n = int(input())
d = list(map(lambda x: int(x), input().split()))
d.sort()

res = 0

for i in range(n-2):
    k = i + 2
    for j in range(i+1, n-1):
        while k < n and d[i] + d[j] > d[k]:
            k += 1
        if k > j:
            res += k - j - 1

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

max_len = 0

for i in range(n-2):
    j = i
    cur_len = 0
    while True:
        if j == n-1:
            break
        cur = h[j]
        next = h[j + 1]
        j += 1
        if cur >= next:
            cur_len += 1
        else:
            break

    max_len = max(max_len, cur_len)

print(max_len)


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

d = []

for i in range(1, n):
    if h[i-1] >= h[i]:
        d.append(1)
    else:
        d.append(0)

max_len = 0
cur_len = 0

for i in range(len(d)):
    if d[i] == 0:
        cur_len = 0
    else:
        cur_len += 1
    max_len = max(max_len, cur_len)

print(max_len)
Buggy python submission (verdict: Runtime Error):
return int(input())**2

Fixed submission:
print(int(input())**2)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, input().sprit())
ans = c-(a-b)

if ans < 0:
  print(0)
else:
  print(ans)

Fixed submission:
a,b,c = map(int, input().split())
ans = c-(a-b)

if ans < 0:
  print(0)
else:
  print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
li = list(int(input()) for i in range(n))

for i in range(n):
  li_copy = li.copy()
  del li_copy[i]
  print(max(li_copy))

Fixed submission:
n = int(input())
li = list(int(input()) for i in range(n))

sorted_li = sorted(li)
a, b = sorted_li[-1], sorted_li[-2]

for i in li:
  if i == a:
    print(b)
  else:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = list(int(input()) for i in range(n))

for i in range(n):
  li_copy = li.copy()
  del li_copy[i]
  print(max(li_copy))

Fixed submission:
n = int(input())
li = list(int(input()) for i in range(n))

sorted_li = sorted(li)
a, b = sorted_li[-1], sorted_li[-2]

for i in li:
  if i == a:
    print(b)
  else:
    print(a)
Buggy python submission (verdict: Runtime Error):
w,h,x,y = map(int, input().split())

c_x = w/2
c_y = h/2

if x = c_x and y = c_y:
  print(w*h/2, 1)
else:
  print(w*h/2, 0)


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

c_x = w/2
c_y = h/2

if x == c_x and y == c_y:
  print(w*h/2, 1)
else:
  print(w*h/2, 0)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
li = [list(map(int, input().split())) for i in range(m)]

left = 0
right = n

for i in li):
  left = max(i[0], left)
  right = min(i[1], right)
  
print(right - left + 1)

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

left = 0
right = n

for i in li:
  left = max(i[0], left)
  right = min(i[1], right)
  
if right < left:
  print(0)
else:
  print(right - left + 1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = [int(input()) for _ in range(n)]

idx_li = []

count = 1
bu = li[0]
idx_li.append(bu)
if bu == 2:
  print(count)
  exit()
  
while True:
  bu = li[bu - 1]
  count += 1
  
  if bu == 2:
    print(count)
    exit()
  
  if bu in idx_li:
    print(-1)
    exit()
  else:
    idx_li.append(bu)
    
  

Fixed submission:
n = int(input())
li = [int(input()) for _ in range(n)]

light = 1
count = 0

for i in range(n):
  light = li[light - 1]
  count+=1
  if light == 2:
    print(count)
    exit()
print(-1)

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

idx_li = []

count = 1
bu = li[0]
idx_li.append(bu)
if bu == 2:
  print(count)
  exit()
  
while True:
  bu = li[bu - 1]
  count += 1
  
  if bu == 2:
    print(count)
    exit()
  
  if bu in idx_li:
    print(-1)
    exit()
  else:
    idx_li.append(bu)
    
  

Fixed submission:
n = int(input())
li = [int(input()) for _ in range(n)]

light = 1
count = 0

for i in range(n):
  light = li[light - 1]
  count+=1
  if light == 2:
    print(count)
    exit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

p = 1

li = [i for i in range(1, n+1)]

for i in li:
  if p > (10**9+7):
    p -= (10**9+7)
  p *= i
  
print(p % (10**9+7))

Fixed submission:
n = int(input())

p = 1

li = [i for i in range(1, n+1)]

for i in li:
  p = p*i % (10**9+7)
  
print(p)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

p = 1

li = [i for i in range(1, n+1)]

for i in li:
  p *= i
  
print(p % (10**9+7))

Fixed submission:
n = int(input())

p = 1

li = [i for i in range(1, n+1)]

for i in li:
  p = p*i % (10**9+7)
  
print(p)
Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q = [ int(n) for n in input().split() ]
A = []
for _ in range(Q):
    A.append(int(input())-1)

Points = [ K for _ in range(N) ]
for a in A:
    for i in range(0,a):
        Points[i] -= 1
    for i in range(a+1,N):
        Points[i] -= 1
        
for i in range(N):
    if Points[i] > 0:
        print("Yes")
    else:
        print("No")

Fixed submission:
N, K, Q = [ int(n) for n in input().split() ]
A = []
for _ in range(Q):
    A.append( int(input())-1 )

Points = [ K-Q for _ in range(N) ]
for a in A:
    Points[a] += 1
        
for i in range(N):
    if Points[i] > 0:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def create_graph(N, a, b):
    g = {}
    for i in range(N-1):
        if a[i] in g:
            g[a[i]][b[i]] = 0
        else:
            g[a[i]] = {b[i]: 0}
        if b[i] in g:
            g[b[i]][a[i]] = 0
        else:
            g[b[i]] = {a[i]: 0}
    return g


def find_color(used, m):
    for i in range(1, m+1):
        if i not in used:
            return i
    return m+1


def dfs(g, p):
    for q in g[p].keys():
        # print(f"p:{p} q:{q} g:{g[p][q]}")
        if not g[p][q]:
            c = find_color(set([v for k, v in g[p].items() if v > 0]), len(g[p]))
            g[p][q] = c
            g[q][p] = c
            dfs(g, q)


def solve(N: int, a, b):
    g = create_graph(N, a, b)
    dfs(g, a[0])
    # print(g)
    m = 1
    for i in range(N-1):
        m = max(m, g[a[i]][b[i]])
    print(m)
    for i in range(N-1):
        print(g[a[i]][b[i]])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, a, b)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
import queue

def create_graph(N, a, b):
    g = {}
    for i in range(N-1):
        if a[i] in g:
            g[a[i]][b[i]] = 0
        else:
            g[a[i]] = {b[i]: 0}
        if b[i] in g:
            g[b[i]][a[i]] = 0
        else:
            g[b[i]] = {a[i]: 0}
    return g


def bfs(g, s):
    Q = queue.Queue()
    Q.put(s)
    while not Q.empty():
        p = Q.get()
        cs = set(range(len(g[p])+2)) - set([v for k, v in g[p].items()])
        for q in g[p].keys():
            # print(f"p:{p} q:{q} g:{g[p][q]}")
            if not g[p][q]:
                c = cs.pop()
                g[p][q] = c
                g[q][p] = c
                Q.put(q)


def solve(N: int, a, b):
    g = create_graph(N, a, b)
    bfs(g, a[0])
    # print(g)
    m = 1
    for i in range(N-1):
        m = max(m, g[a[i]][b[i]])
    print(m)
    for i in range(N-1):
        print(g[a[i]][b[i]])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, a, b)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys

def append_zero(x):
    if 0 in x:
        return
    if x[0] > 0:
        x.insert(0, 0)
        return
    if x[len(x)-1] < 0:
        x.appnd(0)
        return
    for i in range(1, len(x)):
        if x[i-1] < 0 and x[i] > 0:
            x.insert(i, 0)
            return

def solve(N, K, x):
    y = [0]
    append_zero(x)
    n = len(x)
    z = 0
    for i in range(1, n):
        y.append(y[i-1] + x[i] - x[i-1])
        if x[i] == 0:
            z = i
    # print(x)
    # print(y)
    if n == K:
        if n-1 == z or z == 0:
            return y[n-1]
        else:
            l = y[z] + y[n-1]
            r = y[n-1] - y[z] + y[n-1]
            return min(l, r)
    ans = 10e20
    for i in range(n - K):
        k = i + K
        if k <= z:
            ans = min(ans, y[z] - y[i])
        if z <= i:
            ans = min(ans, y[k] - y[z])
        if i <= z and z < k:
           l = y[z] - y[i] + y[k] - y[i]
           r = y[k] - y[z] + y[k] - y[i]
           ans = min(ans, l, r)
    return ans


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, K, x))

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def append_zero(x):
    if 0 in x:
        return
    if x[0] > 0:
        x.insert(0, 0)
        return
    if x[len(x)-1] < 0:
        x.append(0)
        return
    for i in range(1, len(x)):
        if x[i-1] < 0 and x[i] > 0:
            x.insert(i, 0)
            return


def solve(N, K, x):
    y = [0]
    append_zero(x)
    n = len(x)
    z = 0
    for i in range(1, n):
        y.append(y[i-1] + x[i] - x[i-1])
        if x[i] == 0:
            z = i
    # print(x)
    # print(y)
    if n == K:
        if n-1 == z or z == 0:
            return y[n-1]
        else:
            l = y[z] + y[n-1]
            r = y[n-1] - y[z] + y[n-1]
            return min(l, r)
    ans = 10e20
    for i in range(n - K):
        k = i + K
        if k <= z:
            ans = min(ans, y[z] - y[i])
        if z <= i:
            ans = min(ans, y[k] - y[z])
        if i <= z and z < k:
            l = y[z] - y[i] + y[k] - y[i]
            r = y[k] - y[z] + y[k] - y[i]
            ans = min(ans, l, r)
    return ans


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, K, x))


if __name__ == '__main__':
    main()