Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
cell = []
for _ in range(h):
    temp = input()
    cell.append(temp[:-1])

dist = [[float('inf') for _ in range(w)] for _ in range(h)]
dist[0][0] = 0
next_move = [[0, 0]]
x = [1, 0, -1, 0]
y = [0, 1, 0, -1]

while len(next_move):
    if next_move[0] == [h-1, w-1]:
        break
    
    for i in range(4):
        nx = next_move[0][1] + x[i]
        ny = next_move[0][0] + y[i]
        if (nx >= 0 and nx < w and ny >= 0 and ny < h and 
            cell[ny][nx] != '#' and dist[ny][nx] == float('inf')):
            dist[ny][nx] = dist[next_move[0][0]][next_move[0][1]] + 1
            next_move.append([ny, nx])
    next_move.pop(0)

cnt = 0
for i in range(h):
    for t in range(w):
        
        if cell[i][t] == '#':
            cnt += 1
            
if dist[h-1][w-1] == float('inf'):
    print(-1)
else:
    print((h*w) - (dist[h-1][w-1] + 1) - cnt)

Fixed submission:
h, w = map(int, input().split())
cell = []
for _ in range(h):
    cell.append(input())

dist = [[float('inf') for _ in range(w)] for _ in range(h)]
dist[0][0] = 0
next_move = [[0, 0]]
x = [1, 0, -1, 0]
y = [0, 1, 0, -1]

while len(next_move):
    if next_move[0] == [h-1, w-1]:
        break
    
    for i in range(4):
        nx = next_move[0][1] + x[i]
        ny = next_move[0][0] + y[i]
        if (nx >= 0 and nx < w and ny >= 0 and ny < h and 
            cell[ny][nx] != '#' and dist[ny][nx] == float('inf')):
            dist[ny][nx] = dist[next_move[0][0]][next_move[0][1]] + 1
            next_move.append([ny, nx])
    next_move.pop(0)

cnt = 0
for i in range(h):
    for t in range(w):
        
        if cell[i][t] == '#':
            cnt += 1
            
if dist[h-1][w-1] == float('inf'):
    print(-1)
else:
    print((h*w) - (dist[h-1][w-1] + 1) - cnt)
Buggy python submission (verdict: Runtime Error):
from scipy.special import comb
n, a, b = map(int,input().split())
v = list(map(int, input().split()))

v.sort(reverse=True)
max_avg = sum(v[:a]) / a
min_v = min(v[:a])


ans = 0
for i in range(a, b+1):
    if max_avg != sum(v[:i]) / i: break
    cnt1 = v[:i].count(min_v)
    cnt2 = v.count(min_v)
    ans += comb(cnt2, cnt1)

print(max_avg)
print(int(ans))

Fixed submission:
import math
def comb(n, k):
    return math.factorial(n) // (math.factorial(n - k) * math.factorial(k))

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

v.sort(reverse=True)
max_avg = sum(v[:a]) / a
min_v = min(v[:a])

ans = 0
for i in range(a, b+1):
    if max_avg != sum(v[:i]) / i: break
    cnt1 = v[:i].count(min_v)
    cnt2 = v.count(min_v)
    ans += comb(cnt2, cnt1)

print(max_avg)
print(int(ans))
Buggy python submission (verdict: Runtime Error):
n, ma, mb = map(int, input().split())
a, b, c = [0]*n, [0]*n, [0]*n
for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())
   
dp = [[float('inf')] * (sum(a)+1) for _ in range(sum(b)+1)]
dp[0][0] = 0
step = [(0, 0)]

for i in range(n):
    ai, bi = a[i], b[i]

    s = step.copy()
    for si in s:
        if dp[si[0]+ai][si[1]+bi] > dp[si[0]][si[1]] + c[i]:
            dp[si[0]+ai][si[1]+bi] = dp[si[0]][si[1]] + c[i]
            step.append((si[0]+ai, si[1]+bi))
    
ans = float('inf')
for i in range(1, min(sum(a)//ma, sum(b)//mb)+1):
    ans = min(ans, dp[ma*i][mb*i])
    
if ans == float('inf'): print(-1)
else : print(ans)

Fixed submission:
import copy
n, ma, mb = map(int, input().split())
a, b, c = [0]*n, [0]*n, [0]*n
for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())
   
dp = [[float('inf')] * (sum(b)+1) for _ in range(sum(a)+1)]
dp[0][0] = 0
step = set([(0, 0)])

for i in range(n):
    ai, bi = a[i], b[i]

    s = step.copy()
    tempdp = copy.deepcopy(dp)
    for si in s: 
        if dp[si[0]+ai][si[1]+bi] > dp[si[0]][si[1]] + c[i]:
            tempdp[si[0]+ai][si[1]+bi] = dp[si[0]][si[1]] + c[i]
            step.add((si[0]+ai, si[1]+bi))
        
    dp = tempdp[:]
#28 20

ans = float('inf')
for i in range(1, min(sum(a)//ma, sum(b)//mb)+1):
    ans = min(ans, dp[ma*i][mb*i])
    
if ans == float('inf'): print(-1)
else : print(ans)

Buggy python submission (verdict: Runtime Error):
n, ma, mb = map(int, f.readline().split())
a, b, c = [], [], []
for _ in range(n):
    at, bt, ct = map(int, f.readline().split())
    a.append(at)
    b.append(bt)
    c.append(ct)
    
dp = [[float('inf') for _ in range(n*mb + 1)] for _ in range(n*ma + 1)]
dp[0][0] = 0
used = [[0, 0]]

for i in range(n):
    add_used = []
    for at, bt in used:
        if at+a[i] <= n and bt+b[i] <= n:
            if dp[at+a[i]][bt+b[i]] == float('inf'):
                add_used.append([at+a[i], bt+b[i]])
            
            dp[at+a[i]][bt+b[i]] = min(dp[at][bt]+c[i], dp[at+a[i]][bt+b[i]])
        
    used += add_used

if dp[-1][-1] == float('inf'):
    print(-1)
else :
    print(dp[-1][-1])

Fixed submission:
import copy
n, ma, mb = map(int, input().split())
a, b, c = [0]*n, [0]*n, [0]*n
for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())
   
dp = [[float('inf')] * (sum(b)+1) for _ in range(sum(a)+1)]
dp[0][0] = 0
step = set([(0, 0)])

for i in range(n):
    ai, bi = a[i], b[i]

    s = step.copy()
    tempdp = copy.deepcopy(dp)
    for si in s: 
        if dp[si[0]+ai][si[1]+bi] > dp[si[0]][si[1]] + c[i]:
            tempdp[si[0]+ai][si[1]+bi] = dp[si[0]][si[1]] + c[i]
            step.add((si[0]+ai, si[1]+bi))
        
    dp = tempdp[:]
#28 20

ans = float('inf')
for i in range(1, min(sum(a)//ma, sum(b)//mb)+1):
    ans = min(ans, dp[ma*i][mb*i])
    
if ans == float('inf'): print(-1)
else : print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, c = (int(i) for i in input().split())
if a + b >= c:
    print("Yes")
else:
    print("No")5

Fixed submission:
a, b, c = (int(i) for i in input().split())
if a + b >= c:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
for i in range(17):
    a = (N + 1) // (10 ** i)
    if a:
        b = a
    elif a == 0:
        c = (i -1) * 9 + b - 1
        break
print(c)

Fixed submission:
N = int(input())
for i in range(18):
    a = (N + 1) // (10 ** i)
    if a:
        b = a
    elif a == 0:
        c = (i -1) * 9 + b - 1
        break
print(c)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(i) for i in input().split()]
b = [0] * N
for i in range(N):
    b[a[i]] += 1

ans = 0

for i in range(N):
    if b[i] < i:
        ans += b[i]
    else:
        ans+= b[i] - i
print(ans)

Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]
b = [0] * (N + 1)
ans = 0
for i in range(N):
    if a[i] <= N:
        b[a[i]] += 1
    else:
        ans += 1

for i in range(N + 1):
    if b[i] < i:
        ans += b[i]
    else:
        ans+= b[i] - i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]
a.sort()
a_key = list(set(a))
ans = 0
for num in a_key:
    if a.count(num) < num:
        ans += a.count(num)
    else:
        ans += a.count(num) - num
print(ans)

Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]
b = [0] * (N + 1)
ans = 0
for i in range(N):
    if a[i] <= N:
        b[a[i]] += 1
    else:
        ans += 1

for i in range(N + 1):
    if b[i] < i:
        ans += b[i]
    else:
        ans+= b[i] - i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
As = list(map(int, input().split()))
ans = 1
inf = 10 ** 18
for a in As:
    ans *= a

if ans > inf:
    print(-1)
    exit()
print(ans)

Fixed submission:
N = input()
As = list(map(int, input().split()))
for a in As:
    if a == 0:
        print(0)
        exit()
ans = 1
inf = 10 ** 18
for a in As:
    ans *= a
    if ans > inf:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

if N == 1:
    print(0)
    exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

arr = factorization(N)

min_nums = [1]
num_lists = [1]
num_dic = {1: 1}

ans = 0

for Z in arr:
    o = Z[1]
    for i, num in enumerate(num_lists):
        if num > o:
            ans += num_dic[num_lists[i-1]]
            break
    if num <= o:
        o = o - num
        _ans = len(min_nums)
        n = min_nums[-1]+1
        while o >= n:
            o -= n
            min_nums.append(n)
            _ans += 1
            num_lists.append(n+num_lists[-1])
            n += 1
        ans += _ans

print(ans)
        


Fixed submission:
N = int(input())

if N == 1:
    print(0)
    exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

arr = factorization(N)

min_nums = [1]
num_lists = [1]
num_dic = {1: 1}

ans = 0

for Z in arr:
    o = Z[1]
    for i, num in enumerate(num_lists):
        if num > o:
            ans += num_dic[num_lists[i-1]]
            break
    if num <= o:
        o = o - num
        _ans = len(min_nums)
        n = min_nums[-1]+1
        while o >= n:
            o -= n
            min_nums.append(n)
            _ans += 1
            num_lists.append(n+num_lists[-1])
            num_dic[num_lists[-1]] =  _ans
            n += 1
        ans += _ans

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


def main():
    N, M = list(map(int, input().split()))
    graphs = [[] for i in range(N)]
    for i in range(M):
        a, b = list(map(int, input().split()))
        graphs[a-1].append(b-1)
        graphs[b-1].append(a-1)

    INF = 100000000

    distance = [INF for i in range(N)]
    visited = [False] * N
    #    distance = [[None]*field_x_length]*field_y_length
    visited[0] = True
    distance[0] = 0

    def bfs():
        queue = deque([0])
        distance[0] = 0

        while queue:
            x = queue.popleft()
            for y in graphs[x]:
                if visited[y]:
                    continue
                else:
                    distance[y] = x
                    visited[y] = True
                    queue.append(y)
        return distance

    d = bfs()
    for i in range(N):
        if not visited[i]:
            print("No")
            exit()
    print("Yes")
    for i in range(1, N):
        print(d[i]+1)

if __name__ == "__main__":
    main()

Fixed submission:
N = int(input())
import math
sin_dic = {}
mod = 1000000007

zero_num = 0
for i in range(N):
    a, b = list(map(int, input().split()))
    if a == 0 and b == 0:
        zero_num += 1
        continue
    if a == 0:
        b = -1
    elif b == 0:
        a = 1
    else:
        c = math.gcd(a, b)
        a, b = a//c, b//c
        if a < 0 and b < 0:
            a, b = -a, -b
        elif a < 0 and b > 0:
            a, b = -a, -b
    if (a,b) in sin_dic:
        sin_dic[(a, b)].append(i)
    else:
        sin_dic[(a, b)] = [i]

ans = 1
skip_dic = {}
for (key, _key) , values in sin_dic.items():
    if (key, _key) in skip_dic:
        continue
    oth_len = 0
    norm_len = 0
    norm_len += len(values)
    if (-key, -_key) in sin_dic:
        norm_len += len(sin_dic[(-key, -_key)])
    if (_key, -key) in sin_dic:
        oth_len += len(sin_dic[(_key, -key)])
    if (-_key, key) in sin_dic:
        oth_len += len(sin_dic[(-_key, key)])

    p = pow(2, oth_len, mod) - 1 + pow(2, norm_len, mod)
    ans = (ans * p) % mod
    skip_dic[(key, _key)] = True
    skip_dic[(-key, -_key)] = True
    skip_dic[(_key, -key)] = True
    skip_dic[(-_key, key)] = True
print((ans-1 + zero_num) % mod)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import defaultdict

S = input().strip()
l = len(S)
dp = [[0 for _ in range(2019)] for i in range(l)]
for i in range(l):
    s = int(S[i])
    for j in range(2019):
        k = (10 * j + s) % 2019
        dp[i][k] = dp[i-1][j]
    dp[i][s] += 1

ans = 0
for i in range(l):
    ans += dp[i][0]
print(ans)


Fixed submission:
S, W = list(map(int, input().split()))

if W >= S:
    print("unsafe")
else:
    print("safe")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import deque

N = int(input())
#A = list(map(int, input().split()))
A = [(a, i) for i, a in enumerate(map(int, input().split()))]
A = sorted(A, reverse=True)

values = []
num_indcies = {}
for i, a in enumerate(A):
    if not a in num_indcies:
        num_indcies[a] = [i]
        values.append(a)
    else:
        num_indcies[a].append(i)

values = sorted(values, reverse=True)
ans = 0
# indexの配列
dp_indices = []
for v in values:
    dp_indices.extend(num_indcies[v])


dp = [[0] * (N+1) for _ in range(N+1)]
for no, (a, pos) in enumerate(A):
    for i in range(no+1):
        j = no - i
        #k = dp_indices[i+j-2]
        #a = A[k]
        dp[i+1][j] = max(dp[i+1][j], dp[i][j] + a * (pos -i))
        dp[i][j+1] = max(dp[i][j+1], dp[i][j] + a * abs(pos - (N-1-j)))

ans = 0
for i in range(1, N+1):
    ans = max(ans, dp[i][N-i])
print(ans)





Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque

N = int(input())
#A = list(map(int, input().split()))
A = [(a, i) for i, a in enumerate(map(int, input().split()))]
A = sorted(A, reverse=True)

values = []
num_indcies = {}
for i, a in enumerate(A):
    if not a in num_indcies:
        num_indcies[a] = [i]
        values.append(a)
    else:
        num_indcies[a].append(i)

values = sorted(values, reverse=True)
ans = 0
# indexの配列
dp_indices = []
for v in values:
    dp_indices.extend(num_indcies[v])


dp = [[0] * (N+1) for _ in range(N+1)]
for no, (a, pos) in enumerate(A):
    for i in range(no+1):
        j = no - i
        #k = dp_indices[i+j-2]
        #a = A[k]
        dp[i+1][j] = max(dp[i+1][j], dp[i][j] + a * (pos -i))
        dp[i][j+1] = max(dp[i][j+1], dp[i][j] + a * abs(pos - (N-1-j)))

ans = 0
for i in range(1, N+1):
    ans = max(ans, dp[i][N-i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

if  N % 2 == 0:
    M =  N // 2
    even_A = [A[i* 2] for i in range(M)]
    odd_A = [A[i* 2 + 1] for i in range(M)]
    even_sum = []
    _sum = 0
    for a in even_A:
        _sum += a
        even_sum.append(_sum)
    odd_sum = []
    _sum = 0
    for a in odd_A:
        _sum += a
        odd_sum.append(_sum)
    ans = max(odd_sum[-1], even_sum[-1])
    for i in range(M):
            x = even_sum[i] + odd_sum[-1] - odd_sum[i]
            ans = max(ans, x)
    print(ans)
    exit()
M =  N // 2
# evenが元一つ多い
even_A = [A[i* 2] for i in range(M+1)]
odd_A = [A[i* 2 + 1] for i in range(M)]
even_sum = []
_sum = 0
for a in even_A:
    _sum += a
    even_sum.append(_sum)
odd_sum = []
_sum = 0
for a in odd_A:
    _sum += a
    odd_sum.append(_sum)
# 全て奇数
all_even = even_sum[-1] - min(even_A)

ans = all_even
for i in range(M):
        x = even_sum[i] + odd_sum[-1] - odd_sum[i]
        y = odd_sum[i] + even_sum[-1] - even_sum[i+1]
        ans = max(ans, x, y)
        for k in range(i+1, M):
           z = even_sum[i] + odd_sum[k] - odd_sum[i] + even_sum[-1] - even_sum[k+1]
           ans = max(ans, z)

print(ans)



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

if  N % 2 == 0:
    M =  N // 2
    even_A = [A[i* 2] for i in range(M)]
    odd_A = [A[i* 2 + 1] for i in range(M)]
    even_sum = []
    _sum = 0
    for a in even_A:
        _sum += a
        even_sum.append(_sum)
    odd_sum = []
    _sum = 0
    for a in odd_A:
        _sum += a
        odd_sum.append(_sum)
    ans = max(odd_sum[-1], even_sum[-1])
    for i in range(M):
            x = even_sum[i] + odd_sum[-1] - odd_sum[i]
            ans = max(ans, x)
    print(ans)
    exit()
M =  N // 2
# evenが元一つ多い
even_A = [A[i* 2] for i in range(M+1)]
odd_A = [A[i* 2 + 1] for i in range(M)]
even_sum = []
_sum = 0
for a in even_A:
    _sum += a
    even_sum.append(_sum)
odd_sum = []
_sum = 0
for a in odd_A:
    _sum += a
    odd_sum.append(_sum)
# 全て奇数
all_even = even_sum[-1] - min(even_A)
diff_odd_even = [odd_sum[k] - even_sum[k+1] for k in range(M)]
diff_max_odd_even = []
diff_max = diff_odd_even[-1]
for k in range(M):
    diff_max = max(diff_max, diff_odd_even[-k-1])
    diff_max_odd_even.append(diff_max)
diff_max_odd_even.reverse()

ans = all_even
for i in range(M):
        x = even_sum[i] + odd_sum[-1] - odd_sum[i]
        y = odd_sum[i] + even_sum[-1] - even_sum[i+1]
        z = even_sum[i] + - odd_sum[i] + even_sum[-1] + diff_max_odd_even[i]
        ans = max(ans, x, y, z)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

result_dic = {}

for  k in range(1, N-1):
    for i in range(k):
        for j in range(k+1, N):
            result_dic[S[i] + S[k] + S[j]] = 1

print(len(result_dic))

Fixed submission:
N = int(input())
S = input()

result_dic = {}

before_words = {i:0 for i in range(10)}
after_words = {i:0 for i in range(10)}
for s in S:
    after_words[int(s)] += 1

for  i, s in enumerate(S[:-1]):
    if i == 0:
        before_words[int(s)] += 1
        after_words[int(s)] -= 1
        continue
    after_words[int(s)] -= 1

    before =  [x for x, y in before_words.items() if y > 0]
    after =  [x for x, y in after_words.items() if y > 0]
    for b in before:
        for a in after:
            result_dic[str(b) + s + str(a)] = 1

    before_words[int(s)] += 1

print(len(result_dic))
Buggy python submission (verdict: Runtime Error):
 import fractions
A, B = list(map(int, input().split()))

C = fractions.gcd(A, B)


def prime_factorize(n):
    a = {}
    while n % 2 == 0:
        a[2] = True
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] = True
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] = True
    return a

print(len(prime_factorize(C)) + 1)

Fixed submission:
from fractions import gcd
A, B = list(map(int, input().split()))

C = gcd(A, B)


def prime_factorize(n):
    a = {}
    while n % 2 == 0:
        a[2] = True
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] = True
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] = True
    return a

print(len(prime_factorize(C)) + 1)
Buggy python submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))

import numpy as np

arr = np.zeros([N+1,M] ,dtype=int)

for i in range(M):
    x, y, z = list(map(int, input().split()))
    arr[x-1, i] = 1
    arr[y-1, i] = 1
    arr[-1, i ] = z % 2
ml = 0
for j in range(M):
    ml_flag = True
    for i in range(j, N):
        #print(arr[i][j])
        if i == 0 and j == 2:
            import IPython;IPython.embed()
        if arr[i][j] != 0:
            min_i = i
            ml_flag = False
            #print("i,j", i, j, "break")
            break
    if ml_flag:
        ml += 1
    for i in range(min_i+1, N):
        #print("yay")
        #print("arr", arr)
        if arr[i][j] != 0:
            arr[i] = (arr[i] + arr[min_i]) % 2

print(N - M + ml)



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

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]
 
    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
 
    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
 
    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)
 
    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]


uf = UnionFind(N)
for j in range(M):
    x, y, z = list(map(int, input().split()))
    if not uf.is_same(x-1, y-1):
        uf.union(x-1, y-1)

# rootの個数
ans = 0
for i in range(N):
    if i == uf.par[i]:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
 N,K = list(map(int,input().split()))
xs = list(map(int,input().split()))

ans = 10 ** 10
for  i,x  in enumerate(xs):
    if N == 1:
        ans = abs(x)
    if i +  K  > N and i > 0:
        break
    num = abs(xs[ i + K - 1 ] - xs[i]) + abs(xs[i])
    num1 = abs(xs[ i + K - 1 ] - xs[i]) + abs(xs[i + K -1])
    ans = min([num,num1,ans])
print(ans)

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

ans = 10 ** 10
for  i,x  in enumerate(xs):
    if N == 1:
        ans = abs(x)
    if i +  K  > N and i > 0:
        break
    num = abs(xs[ i + K - 1 ] - xs[i]) + abs(xs[i])
    num1 = abs(xs[ i + K - 1 ] - xs[i]) + abs(xs[i + K -1])
    ans = min([num,num1,ans])
print(ans)
Buggy python submission (verdict: Runtime Error):
S = list(input())
K = int(input())

if K == 1 or S[0] == 1:
    print(S[1])
for i,s in enumerate(S):
    if i + 1 == K:
        print(S[i])
        exit()
    if S[i] != 1:
        print(S[i])
        exit()

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

for i,s in enumerate(S):
    if i + 1 == K:
        print(S[i])
        exit()
    if S[i] != "1":
        print(S[i])
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int,input().split()))

lists = []
for i in range(M):
    lists.append(list(map(int,input().split())))
    lists.sort(key=lambda x: x[1])
ans = 0
min_b = 0
for a, b in lists:
    if min_b <= a:
        min_b = b
        ans += 1
print(ans)
    





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

lists = []
for i in range(M):
    lists.append(list(map(int,input().split())))
lists.sort(key=lambda x: x[1])
ans = 0
min_b = 0
for a, b in lists:
    if min_b <= a:
        min_b = b
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
T = int(input())
ABCD = [ list(map(int,input().split())) for _ in range(T)]

def check(a,b,c,d):
    if b > d or a < b:
        print("No")
        return
    elif c >= b:
        print("Yes")
        return
    def_a = a % b
    a = def_a
    while True:
        a = (a + d) % b
        if a > c:
            print("No")
            return
        elif def_a == a:
            print("Yes")
            return

for abcd in ABCD:
    check(abcd[0],abcd[1],abcd[2],abcd[3])


Fixed submission:
T = int(input())
ABCD = [ list(map(int,input().split())) for _ in range(T)]
import fractions

def check(a,b,c,d):
    if b > d or a < b:
        print("No")
        return
    elif c >= b:
        print("Yes")
        return
    def_a = a % b
    a = def_a
    while True:
        a = (a + d) % b
        if a > c:
            print("No")
            return
        g = fractions.gcd(b,d)
        f = (b -a) // g
        if (b - a) % g == 0:
            f -= 1
        if g == 0 or c >= a + f * g:
            print("Yes")
            return
        print("No")
        return

for abcd in ABCD:
    check(abcd[0],abcd[1],abcd[2],abcd[3])