Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02761 (python)

Fixed submission:
n, m = map(int,input().split())
dic = {}
ans = 0
for _ in range(m):
    s,c = map(int,input().split())
    if s-1 not in dic.keys():
        dic[s-1] = c
    if s-1 in dic.keys() and dic[s-1] !=c:
        ans = -1
        break
    if s == 1 and c == 0 and n!=1:
        ans = -1
        break
if ans == -1:
    print(ans)
    exit()
if 1 not in dic.keys() and n !=1:
    dic[1] = 0
if 2 not in dic.keys() and n ==3:
    dic[2] = 0  
if 0 not in dic.keys() and n!=1:
    dic[0] = 1
if 0 not in dic.keys() and n==1:
    dic[0] = 0
ls = []
for i in range(n):
    ls.append(str(dic[i]))
ans = ''.join(ls)
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
dic = {}
ans = 0
for _ in range(m):
    s,c = map(int,input().split())
    if s not in dic.keys():
        dic[s-1] = c
    elif s in dic.keys() and dic[s-1] !=c:
        ans = -1
        break
if 0 in dic.keys() and dic[0] ==0:
    ans = -1

for i in range(n):
    if i not in dic.keys():
        dic[i] = 0

if ans == -1:
    print('-1')
    exit()
if dic[0] ==0:
    dic[0] = 1
ls = []
for i in range(n):
    ls.append(str(dic[i]))
ans = ''.join(ls)
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
dic = {}
ans = 0
for _ in range(m):
    s,c = map(int,input().split())
    if s not in dic.keys():
        dic[s-1] = c
    elif s in dic.keys() and dic[s-1] !=c:
        ans = -1
        break
for i in range(n):
    if i not in dic.keys():
        dic[i] = 0

if dic[0] ==0:
    ans = -1
if ans == -1:
    print('-1')
    exit()
ls = []
for i in range(n):
    ls.append(str(dic[i]))
ans = ''.join(ls)
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
dic = {}
for _ in range(m):
    s,c = map(int,input().split())
    if s not in dic.keys():
        dic[s-1] = c
    elif s in dic.keys() and dic[s-1] !=c:
        res = -1
        break
for i in range(n):
    if i not in dic.keys():
        dic[i] = 0

if dic[0] ==0:
    res = -1
if res == -1:
    print('-1')
    exit()
ls = []
for i in range(n):
    ls.append(str(dic[i]))
ans = ''.join(ls)
print(ans)
Problem p02845 (python)

Fixed submission:
import sys
n = int(input())
a_ls = list(map(int, input().split()))
hat_nperson = [0,0,1]
ans = 3
mod = 10**9+7

if a_ls[0] != 0 or (n != 1 and a_ls[1] == 2):
    print(0)
    sys.exit()

for i in range(1,n):
    n_same = a_ls[i]
    n_choices = 0
    choice_ind = -1
    for j,person in enumerate(hat_nperson):
        if person == n_same:
            n_choices += 1
            choice_ind = j
    if choice_ind == -1:
        print(0)
        sys.exit()
    hat_nperson[choice_ind] += 1
    ans *= n_choices
    ans %= mod
print(ans%mod)

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
a_ls = list(map(int, input().split()))
hat_nperson = [0,0,1]
ans = 3
mod = 10**9+7
if a_ls[0] != 0 or a_ls[1] == 2:
    print(0)
    sys.exit()
for i in range(1,n):
    n_same = a_ls[i]
    n_choices = 0
    choice_ind = -1
    for j,person in enumerate(hat_nperson):
        if person == n_same:
            n_choices += 1
            choice_ind = j
    if choice_ind == -1:
        print(0)
        sys.exit()
    hat_nperson[choice_ind] += 1
    ans *= n_choices
    ans %= mod
print(ans%mod)

Buggy submission (verdict: Runtime Error):
n = int(input())
a_ls = list(map(int, input().split()))
hats_person = [1,0,0]
ans = 3
mod = 10**9+7
for i in range(1,n):
    same = a_ls[i]
    n_choices = 0
    choice_ind = -1
    for j,person in enumerate(hats_person):
        if person == same:
            n_choices += 1
            choice_ind = j
    if choice_ind == -1:
        print(0)
        sys.exit()
    hats_person[choice_ind] += 1
    ans *= n_choices
    ans %= mod
print(ans%mod)

Buggy submission (verdict: Runtime Error):
n = int(input())
a_ls = list(map(int, input().split()))
hats_person = [1,0,0]
ans = 3
mod = 10**9+7
for i in range(1,n):
    same = a_ls[i]
    n_choices = 0
    #choice_ind = -1
    for j,person in enumerate(hats_person):
        if person == same:
            n_choices += 1
            choice_ind = j
    #if choice_ind == -1:
        #ans = 0
    hats_person[choice_ind] += 1
    ans *= n_choices
    ans %= mod
print(ans)
Problem p02888 (python)

Fixed submission:
n = int(input())
l_ls = list(map(int, input().split()))
l_ls.sort()
stick_count = [0] * (10**3+1)
stick_csum = [0] * (10**3+1)
for i in range(n):
    stick_count[l_ls[i]] += 1
now = 0
for i in range(10**3+1):
    now += stick_count[i]
    stick_csum[i] = now

ans = 0
for first_i in range(n):
    for second_i in range(first_i+1, n):
        #境界は含まない
        greater_than = abs(l_ls[first_i] - l_ls[second_i])
        smaller_than = min(10**3+1,l_ls[first_i] + l_ls[second_i])
        num_canmake = max(0, stick_csum[smaller_than-1] - stick_csum[greater_than])
        if greater_than < l_ls[first_i] < smaller_than:
            num_canmake -= 1
        if greater_than < l_ls[second_i] < smaller_than:
            num_canmake -= 1
        num_canmake = max(0,num_canmake)
        ans += num_canmake
print(ans//3)

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
l_ls = list(map(int, input().split()))
l_ls.sort()
stick_count = [0] * (10**3+1)
for i in range(n):
    stick_count[l_ls[i]] += 1
stick_csum = list(np.cumsum(stick_count))
ans = 0
for first_i in range(n):
    for second_i in range(first_i+1, n):
        #境界は含まない
        greater_than = abs(l_ls[first_i] - l_ls[second_i])
        smaller_than = min(10**3,l_ls[first_i] + l_ls[second_i])
        num_canmake = max(0, stick_csum[smaller_than-1] - stick_csum[greater_than])
        if greater_than < l_ls[first_i] < smaller_than:
            num_canmake -= 1
        if greater_than < l_ls[second_i] < smaller_than:
            num_canmake -= 1
        num_canmake = max(0,num_canmake)
        ans += num_canmake
print(ans//3)
Problem p02923 (python)

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

count = 0
bestcount = count
for i in range(n-1):
    if h_list[i] >= h_list[i+1]:
        count += 1
    else:
        bestcount = max(count,bestcount)
        count= 0
print(max(count,bestcount))

Buggy submission (verdict: Runtime Error):
n = int(input())
h_list = list(map(int,input().split()))
count = {}
for i in range(len(h_list)-1):
    count[i] = 0
    j = i
    while j < n-1:
        if h_list[j] >= h_list[j+1]:
            count[i] += 1
            j += 1

        else:
            break
ls = sorted(count.items(), key=lambda x: x[1])
print(ls[-1][1])
Problem p02924 (python)

Fixed submission:
N = int(input())
print(N*(N-1)//2)

Buggy submission (verdict: Runtime Error):
n = int(input())
print(N*(N-1)//2)
Problem p02937 (python)

Fixed submission:
from collections import defaultdict
import copy
import sys
s = input()
n_s = len(s)
t = input()
n_t = len(t)

chr_firstind = defaultdict(lambda:-1)
chr_nextind = defaultdict(lambda:-1)
i_to_chr_nextind = [0] * n_s
for i in range(n_s-1,-1,-1):
    chr_firstind[s[i]] = i
    i_to_chr_nextind[i] = copy.copy(chr_nextind)
    chr_nextind[s[i]] = i 

first_target = t[0]
previous_ind = chr_firstind[first_target]
if previous_ind == -1:
    print(-1)
    sys.exit()
if n_t == 1:
    print(previous_ind+1)
    sys.exit()
s_used = 0
for i in range(1,n_t):
    # 一つ前のtarget_indを使って、次のtargetのs内でのindexを求める
    d = i_to_chr_nextind[previous_ind]
    next_ind = d[t[i]]
    if next_ind == -1:
        s_used += 1
        next_ind = chr_firstind[t[i]]
        if next_ind == -1:
            print(-1)
            sys.exit()
    previous_ind = next_ind
print(n_s*s_used+previous_ind+1)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import copy
import sys
s = input()
n_s = len(s)
t = input()
n_t = len(t)

chr_firstind = defaultdict(lambda:-1)
chr_nextind = defaultdict(lambda:-1)
i_to_chr_nextind = [0] * n_s
for i in range(n_s-1,-1,-1):
    chr_firstind[s[i]] = i
    i_to_chr_nextind[i] = copy.copy(chr_nextind)
    chr_nextind[s[i]] = i 

first_target = t[0]
previous_ind = chr_firstind[first_target]
if previous_ind == -1:
    print(-1)
    sys.exit()
if n_t == 1:
    print(first_ind+1)
    sys.exit()
s_used = 0
for i in range(1,n_t):
    # 一つ前のtarget_indを使って、次のtargetのs内でのindexを求める
    d = i_to_chr_nextind[previous_ind]
    next_ind = d[t[i]]
    if next_ind == -1:
        s_used += 1
        next_ind = chr_firstind[t[i]]
        if next_ind == -1:
            print(-1)
            sys.exit()
    previous_ind = next_ind
print(n_s*s_used+previous_ind+1)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import copy
s = input()
import sys
n_s = len(s)
t = input()
n_t = len(t)

alphabet = [chr(i) for i in range(97, 97+26)]
al_d = {}
for i in range(26):
    al_d[alphabet[i]] = i

chr_firstind = defaultdict(lambda:-1)
chr_nextind = defaultdict(lambda:-1)
i_to_chr_nextind = [0] * n_s
for i in range(n_s-1,-1,-1):
    chr_firstind[s[i]] = i
    i_to_chr_nextind[i] = copy.copy(chr_nextind)
    chr_nextind[s[i]] = i 

first_target = t[0]
previous_ind = chr_firstind[first_target]
if n_t == 1:
    if previous_ind == -1:
        print(-1)
    else:
        print(first_ind)+1
    sys.exit()
s_used = 0
for i in range(1,n_t):
    # 一つ前のtarget_indを使って、次のtargetのs内でのindexを求める
    d = i_to_chr_nextind[previous_ind]
    next_ind = d[t[i]]
    if next_ind == -1:
        s_used += 1
        next_ind = chr_firstind[t[i]]
        if next_ind == -1:
            print(-1)
            sys.exit()
    previous_ind = next_ind
print(n_s*s_used+previous_ind+1)
Problem p02993 (python)

Fixed submission:
s = input()
list_s = [i for i in s]
for i in range(3):
    if list_s[i] == list_s[i+1]:
        print('Bad')
        exit()
print('Good')

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
from fractions import gcd

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

count_b = b - b//c - b//d + b//lcm(c,d)
count_a = a-1 - (a-1)//c - (a-1)//d + (a-1)//lcm(c,d)
print(count_b-count_a)
Problem p02995 (python)

Fixed submission:
a,b,c,d = map(int,input().split())
from fractions import gcd

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

count_b = b - b//c - b//d + b//lcm(c,d)
count_a = a-1 - (a-1)//c - (a-1)//d + (a-1)//lcm(c,d)
print(count_b-count_a)

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
from fractions import gcd

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

count_b = b - b//c - b//d + b//lcm(c,d)
count_a = a-1 - (a-1)//c - (a-1)//d + (a-1)//lcm(c,d)
print(count_b-count_a)

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
import math

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

count_b = b - b//c - b//d + b//lcm(c,d)
count_a = a-1 - (a-1)//c - (a-1)//d + (a-1)//lcm(c,d)
print(count_b-count_a)
Problem p03043 (python)

Fixed submission:
import math
n, k = map(int,input().split())
ans = 0
for i in range(n):
    if i+1 < k:
        must = math.ceil(math.log2(k/(i+1)))
        ans += (1/n)*((0.5)**must)
    else:
        ans += (1/n)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n, k = map(int,input().split())
ans = 0
for i in range(n):
    if i+1 < k:
        must = math.ceil(math.log2(k/(i+1)))
        ans += (1/n)*((0.5)**must)
    else:
        ans += (1/n)
print(ans)
Problem p03044 (python)

Fixed submission:
from collections import deque
n = int(input())
ad_ls = [[] for _ in range(n)]
for _ in range(n-1):
    a,b,w = map(int,input().split())
    ad_ls[a-1].append([b-1,w])
    ad_ls[b-1].append([a-1,w])

cost_ls = [0] * n
done_ls = [0] * n
done_ls[0] = 1
q = deque()
q.append(0)

while q:
    now = q.pop()
    for new in ad_ls[now]:
        nex,cost = new[0],new[1]
        if not done_ls[nex]:
            cost_ls[nex] = cost + cost_ls[now]
            done_ls[nex] = 1
            q.append(nex)

color_ls = [0] * n
for i in range(n):
    color_ls[i] = cost_ls[i] % 2

for color in color_ls:
    print(color)

Buggy submission (verdict: Runtime Error):
from collections import deque
n = int(input())
ad_ls = [[] for _ in range(n)]
for _ in range(n-1):
    a,b,w = map(int,input().split())
    ad_ls[a-1].append([b-1,w])
    ad_ls[b-1].append([a-1,w])

cost_ls = [0] * n
done_ls = [0] * n
def dfs(v,c):
    for new,cost in ad_ls[v]:
        if not done_ls[new]:
            cost_ls[new] = c+cost
            done_ls[new] = 1
            dfs(new,c+cost)

dfs(0,0)

color_ls = [0] * n
for i in range(n):
    color_ls[i] = cost_ls[i] % 2

for color in color_ls:
    print(color)
Problem p03076 (python)

Fixed submission:
import numpy as np
sho_ls = []
amari_ls = []
a_ls = []
for _ in range(5):
    a = int(input())
    a_ls.append(a)
    sho, amari = divmod(a,10)
    sho_ls.append(sho)
    amari_ls.append(amari)

amari_ls_not0 = []
for i in range(5):
    if amari_ls[i] != 0:
        amari_ls_not0.append(amari_ls[i])

if amari_ls != [0,0,0,0,0]:
    amari_min_not0 = min(amari_ls_not0)
    arg_min = amari_ls.index(amari_min_not0)
else:
    arg_min = 0
ans = 0
for i in range(5):
    if i != arg_min:
        if amari_ls[i] != 0:
            plus = a_ls[i] + 10 - amari_ls[i]
            ans += plus
            
        else:
            plus = a_ls[i]
            ans += plus
plus = a_ls[arg_min]
ans += plus
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
sho_ls = []
amari_ls = []
a_ls = []
for _ in range(5):
    a = int(input())
    a_ls.append(a)
    sho, amari = divmod(a,10)
    sho_ls.append(sho)
    amari_ls.append(amari)

amari_ls_not0 = []
for i in range(5):
    if amari_ls[i] != 0:
        amari_ls_not0.append(amari_ls[i])

amari_min_not0 = min(amari_ls_not0)
arg_min = amari_ls.index(amari_min_not0)
ans = 0
for i in range(5):
    if i != arg_min:
        if amari_ls[i] != 0:
            plus = a_ls[i] + 10 - amari_ls[i]
            ans += plus
            
        else:
            plus = a_ls[i]
            ans += plus
plus = a_ls[arg_min]
ans += plus
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
sho_ls = []
amari_ls = []
a_ls = []
for _ in range(5):
    a = int(input())
    a_ls.append(a)
    sho, amari = divmod(a,10)
    sho_ls.append(sho)
    amari_ls.append(amari)

amari_ls_not0 = []
for i in range(5):
    if amari_ls[i] != 0:
        amari_ls_not0.append(amari_ls[i])

amari_min_not0 = min(amari_ls_not0)
arg_min = amari_ls.index(amari_min_not0)
ans = 0
for i in range(5):
    if i != arg_min:
        if amari_ls[i] != 0:
            plus = a_ls[i] + 10 - amari_ls[i]
            ans += plus
            
        else:
            plus = a_ls[i]
            ans += plus
plus = a_ls[arg_min]
ans += plus
print(ans)
Problem p03164 (python)

Fixed submission:
n,w = map(int,input().split())
w_ls, v_ls = [0] * n, [0] * n
for i in range(n):
    w_ls[i], v_ls[i] = map(int,input().split())
V = sum(v_ls)
dp = [[float("inf")] * (V+1) for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
    for j in range(V+1):
        if j - v_ls[i] >= 0:
            dp[i+1][j] = min(dp[i+1][j], dp[i][j-v_ls[i]] + w_ls[i])
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])

ans = 0
for j in range(V+1):
    if dp[n][j] <= w:
        ans = j

print(ans)

Buggy submission (verdict: Runtime Error):
n,w = map(int,input().split())
w_ls, v_ls = [0] * n, [0] * n
for i in range(n):
    w_ls[i], v_ls[i] = map(int,input().split())
V = sum(v_ls)
dp = [[float("inf")] * (V+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(n):
    for j in range(V+1):
        if j - v[i] >= 0:
            dp[i+1][j] = min(dp[i+1][j], dp[i][j-v[i]] + w[i])
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])

ans = 0
for j in range(V+1):
    if dp[N][j] <= W:
        ans = j

print(ans)
Problem p03223 (python)

Fixed submission:
import sys
n = int(input())
ls = [0] * n
for i in range(n):
    ls[i] = int(input())
ls.sort()
# 長さ2なら例外処理する
if n == 2:
    print(abs(ls[0]-ls[1]))
    sys.exit()
if n % 2 == 1:
    # biggerを2つとる方
    smaller = ls[:n//2+1]
    bigger = ls[n//2+1:]
    diff_1 = 2 * sum(bigger) - 2*sum(smaller) + smaller[-1] + smaller[-2]
    # smallerを2つとる方
    smaller = ls[:n//2]
    bigger = ls[n//2:]
    diff_2 = -2 * sum(smaller) + 2 * sum(bigger) - bigger[0] - bigger[1]
    diff = max(diff_1,diff_2)
else:
    smaller = ls[:n//2]
    bigger = ls[n//2:]
    diff = 2 * sum(bigger) - min(bigger) - 2 * sum(smaller) + max(smaller)

print(diff)

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
ls = [0] * n
for i in range(n):
    ls[i] = int(input())
ls.sort()
# 長さ2なら例外処理する
if n == 2:
    print(abs(ls[0],ls[1]))
    sys.exit()
if n % 2 == 1:
    # biggerを2つとる方
    smaller = ls[:n//2+1]
    bigger = ls[n//2+1:]
    diff_1 = 2 * sum(bigger) - 2*sum(smaller) + smaller[-1] + smaller[-2]
    # smallerを2つとる方
    smaller = ls[:n//2]
    bigger = ls[n//2:]
    diff_2 = -2 * sum(smaller) + 2 * sum(bigger) - bigger[0] - bigger[1]
    diff = max(diff_1,diff_2)
else:
    smaller = ls[:n//2]
    bigger = ls[n//2:]
    diff = 2 * sum(bigger) - min(bigger) - 2 * sum(smaller) + max(smaller)

print(diff)
Problem p03240 (python)

Fixed submission:
import sys
n = int(input())
inf_ls = [[0]*3 for _ in range(n)]
for i in range(n):
    x,y,h = map(int,input().split())
    inf_ls[i] = x,y,h
for Cx in range(101):
    for Cy in range(101):
        this_is_C = True
        H_set = set()
        zero_ls = []
        for i in range(n):
            x,y,h = inf_ls[i]
            if h > 0:
                H = abs(x-Cx) + abs(y-Cy) + h
                H_set.add(H)
            else:
                zero_ls.append([x,y])
        if len(H_set) != 1:
            this_is_C = False
            continue
        H = list(H_set)[0]
        for x,y in zero_ls:
            if H - abs(x-Cx) - abs(y-Cy) > 0:
                this_is_C = False
        if this_is_C:
            print(Cx,Cy,H)
            exit()

Buggy submission (verdict: Runtime Error):
n = int(input())
hint_ls = [0] * n
for i in range(n):
    x,y,h = map(int,input().split())
    hint_ls[i] = [x,y,h]
target_ls = [[i,j] for i in range(101) for j in range(101)]
for x_target, y_target in target_ls:
    res = True
    for i in range(n):
        x_hint, y_hint, h_hint = hint_ls[i]
        if h_hint != 0:
            h_target_new = h_hint + abs(x_hint - x_target) + abs(y_hint - y_target)
            if i>= 1:
                if not h_target_new == h_target_old:
                    res = False
            h_target_old = h_target_new
        else:
            if h_target_old > abs(x_hint - x_target) + abs(y_hint - y_target):
                res = False
    if res:
        x_ans,y_ans,h_ans = x_target, y_target, h_target_new

print(x_ans, y_ans, h_ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
hint_ls = [0] * n
for i in range(n):
    x,y,h = map(int,input().split())
    hint_ls[i] = [x,y,h]
target_ls = [[i,j] for i in range(101) for j in range(101)]
for x_target, y_target in target_ls:
    res = True
    for i in range(n):
        x_hint, y_hint, h_hint = hint_ls[i]
        h_target_new = h_hint + abs(x_hint - x_target) + abs(y_hint - y_target)
        if i>= 1:
            if not h_target_new == h_target_old:
                res = False
        h_target_old = h_target_new
    if res:
        x_ans,y_ans,h_ans = x_target, y_target, h_target_new

print(x_ans, y_ans, h_ans)
Problem p03262 (python)

Fixed submission:
import math
from fractions import gcd
from functools import reduce
n,x = map(int, input().split())
y_ls = list(map(int, input().split()))
y_ls.sort()
d_ls = [0] * (n-1)

if n != 1:
    first_ls = []
    for i in range(n):
        first = abs(x - y_ls[i])
        first_ls.append(first)

    for i in range(n-1):
        distance = y_ls[i+1] - y_ls[i] 
        d_ls.append(distance)

    points_gcd = reduce(gcd, d_ls)
    ans = 0
    for i in range(n):
        D = gcd(points_gcd, first_ls[i])
        if D > ans:
            ans = D

else:
    ans = abs(x - y_ls[0])

print(ans)

Buggy submission (verdict: Runtime Error):
import math
from fractions import gcd
from functools import reduce
n,x = map(int, input().split())
y_ls = list(map(int, input().split()))
y_ls.sort()
d_ls = []

for i in range(n-1):
    distance = y_ls[i+1] - y_ls[i] 
    d_ls.append(distance)

ans = reduce(gcd, d_ls)
print(ans)
Problem p03274 (python)

Fixed submission:
n,k = map(int,input().split())
x_ls = list(map(int, input().split()))
ans = float('inf')
for i in range(n-k+1):
    if x_ls[i+k-1] < 0:
        ans = min(ans, abs(x_ls[i]))
    elif x_ls[i] < 0 and x_ls[i+k-1] >= 0:
        near = min(abs(x_ls[i]),abs(x_ls[i+k-1]))
        far = max(abs(x_ls[i]),abs(x_ls[i+k-1]))
        ans = min(ans, 2 * near + far)
    elif x_ls[i] >= 0:
        ans = min(ans, x_ls[i+k-1])
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
n,k = map(int,input().split())
x_ls = list(map(int, input().split()))
x_ls.sort()
if x_ls[0] >= 0:
    print(x_ls[k-1])
    sys.exit()
elif x_ls[-1] <= 0:
    x_ls.sort(reverse=True)
    print(abs(x_ls[k-1]))
    sys.exit()
l = 0
r = k - 1
while True:
    if x_ls[r+1] > 0:
        break
    l += 1
    r += 1
ans = float('inf')
while r < n:
    cost_1 = 2*abs(x_ls[l]) + abs(x_ls[r])
    cost_2 = abs(x_ls[l]) + 2*abs(x_ls[r])
    cost = min(cost_1,cost_2)
    ans = min(cost, ans)
    r += 1
    l += 1
print(ans)
Problem p03363 (python)

Fixed submission:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
a_ls = list(map(int, input().split()))
a_csum = [0] * n
now = 0
for i in range(n):
    now += a_ls[i]
    a_csum[i] = now
a_csum.append(0)
a_csum.sort()
ans = 0
now = 0
for i in range(n):
    if a_csum[i] == a_csum[i+1]:
        now += 1
    else:
        if now > 0:
            ans += combinations_count(now+1,2)
        now = 0
if now > 0:
    ans += combinations_count(now+1,2)
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a_ls = list(map(int, input().split()))
csum = list(np.cumsum(a_ls))
ans = 0

for start in range(1,n):
    for end in range(start, n):
        if csum[end] - csum[start-1] == 0:
            ans += 1
for i in range(n):
    if csum[i] == 0:
        ans += 1
print(ans)