Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())  # 1 <= N <= 4000
S = input()  # [RGB]{N}
L = {
    'R': tuple(i for i, v in enumerate(S) if v == 'R'),
    'G': tuple(i for i, v in enumerate(S) if v == 'G'),
    'B': tuple(i for i, v in enumerate(S) if v == 'B')
}

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] != S[j]:
            other = list({'R', 'G', 'B'} - {S[i], S[j]})[0]
            tmp = j + j - i

            ans += len([k for k in L[other] if (k > j) and (tmp != k)])
print(ans)





Fixed submission:
N = int(input())  # 1 <= N <= 4000
S = input()  # [RGB]{N}
L = {
    'R': tuple(i for i, v in enumerate(S) if v == 'R'),
    'G': tuple(i for i, v in enumerate(S) if v == 'G'),
    'B': tuple(i for i, v in enumerate(S) if v == 'B')
}
R_length = len(L['R'])
G_length = len(L['G'])
B_length = len(L['B'])

ans = R_length * G_length * B_length
for i in range(N):
    for j in range(i+1, N):
        k = j + j - i
        if k >= N:
            break
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())  # 1 <= N <= 4000
S = input()  # [RGB]{N}

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] != S[j]:
            other = list({'R', 'G', 'B'} - {S[i], S[j]})[0]
            tmp = j + j - i
            for k in range(j+1, N):
                if (S[k] == other) and (tmp != k):
                    ans += 1
print(ans)





Fixed submission:
N = int(input())  # 1 <= N <= 4000
S = input()  # [RGB]{N}
L = {
    'R': tuple(i for i, v in enumerate(S) if v == 'R'),
    'G': tuple(i for i, v in enumerate(S) if v == 'G'),
    'B': tuple(i for i, v in enumerate(S) if v == 'B')
}
R_length = len(L['R'])
G_length = len(L['G'])
B_length = len(L['B'])

ans = R_length * G_length * B_length
for i in range(N):
    for j in range(i+1, N):
        k = j + j - i
        if k >= N:
            break
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())  # 1 <= N <= 4000
S = input()  # [RGB]{N}
L = {
    'R': [i for i, v in enumerate(S) if v == 'R'],
    'G': [i for i, v in enumerate(S) if v == 'G'],
    'B': [i for i, v in enumerate(S) if v == 'B']
}

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] != S[j]:
            other = list({'R', 'G', 'B'} - {S[i], S[j]})[0]
            ans += len([k for k in L[other] if (k > j) and (j - i != k - j)])
print(ans)

Fixed submission:
N = int(input())  # 1 <= N <= 4000
S = input()  # [RGB]{N}
L = {
    'R': tuple(i for i, v in enumerate(S) if v == 'R'),
    'G': tuple(i for i, v in enumerate(S) if v == 'G'),
    'B': tuple(i for i, v in enumerate(S) if v == 'B')
}
R_length = len(L['R'])
G_length = len(L['G'])
B_length = len(L['B'])

ans = R_length * G_length * B_length
for i in range(N):
    for j in range(i+1, N):
        k = j + j - i
        if k >= N:
            break
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Query = [input().split() for _ in range(Q)]

muki = 1
for i in Query:
    if i[0] == '1':
        muki *= -1
    else:
        if i[1] == '1':
            if muki == 1:
                S = i[2] + S
            else:
                S = S + i[2]
        else:
            if muki == -1:
                S = i[2] + S
            else:
                S = S + i[2]
if muki == -1:
    S = S[::-1]
print(S)
    



Fixed submission:
S = input()
Q = int(input())
Query = [input().split() for _ in range(Q)]

muki = 1
a = ''
b = ''
for i in Query:
    if i[0] == '1':
        muki *= -1
    else:
        if i[1] == '1':
            if muki == 1:
                a += i[2]
                # S = i[2] + S
            else:
                # S = S + i[2]
                b += i[2]
        else:
            if muki == -1:
                # S = i[2] + S
                a += i[2]
            else:
                # S = S + i[2]
                b += i[2]
S = a[::-1] + S + b
if muki == -1:
    print(S[::-1])
else:
    print(S)
Buggy python submission (verdict: Runtime Error):
N, a, b = map(int, input().split())
M = 1000000007

m = N//2 + 1
fact_list = [1] * (N+1)
fact_inv = [1] * (N+1)

for i in range(1, N+1):
    fact_list[i] = fact_list[i-1] * i % M

for i in range(1, N+1):
    fact_inv[i] = pow(int(fact_list[i]), M-2, M)

def mod_comb_k(n,k,M):
    return int(fact_list[n]) * int(fact_inv[k]) % M * int(fact_inv[n-k]) % M

ans = 0
for i in range(1, N+1):
    if i == a or i == b:
        continue
    ans += mod_comb_k(N, i, M) % M
    # print(ans)
print(ans)








Fixed submission:
N, a, b = map(int, input().split())
M = 1000000007


def mod_comb_k(n, k):
    n_P_n_k = 1
    fact_k = 1
    for i in range(k):
        n_P_n_k = n_P_n_k * (n - i) % M
        fact_k = fact_k * (i + 1) % M
    return n_P_n_k * pow(fact_k, M-2, M)

ans = (pow(2, N, M) - 1 - mod_comb_k(N, a) - mod_comb_k(N, b)) % M
print(ans)

Buggy python submission (verdict: Runtime Error):
N, a, b = map(int, input().split())
M = 1000000007

m = N//2 + 1
fact_list = [1] * (N+1)
fact_inv = [1] * (N+1)

for i in range(1, N+1):
    fact_list[i] = fact_list[i-1] * i % M

for i in range(1, N+1):
    fact_inv[i] = pow(int(fact_list[i]), M-2, M)

def mod_comb_k(n,k,M):
    return int(fact_list[n]) * int(fact_inv[k]) % M * int(fact_inv[n-k]) % M

ans = 0
for i in range(1, N+1):
    if i == a or i == b:
        continue
    ans += mod_comb_k(N, i, M) % M
    # print(ans)
print(ans)








Fixed submission:
N, a, b = map(int, input().split())
M = 1000000007


def mod_comb_k(n, k):
    n_P_n_k = 1
    fact_k = 1
    for i in range(k):
        n_P_n_k = n_P_n_k * (n - i) % M
        fact_k = fact_k * (i + 1) % M
    return n_P_n_k * pow(fact_k, M-2, M)

ans = (pow(2, N, M) - 1 - mod_comb_k(N, a) - mod_comb_k(N, b)) % M
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N, a, b = map(int, input().split())
M = 1000000007

m = N//2 + 1
fact_list = np.ones(N+1, dtype='int32')
fact_inv = np.ones(N+1, dtype='int32')

for i in range(1, N+1):
    fact_list[i] = fact_list[i-1] * i % M

for i in range(1, N+1):
    fact_inv[i] = pow(int(fact_list[i]), M-2, M)

def mod_comb_k(n,k,M):
    return int(fact_list[n]) * int(fact_inv[k]) % M * int(fact_inv[n-k]) % M

ans = 0
for i in range(1, N+1):
    if i == a or i == b:
        continue
    ans += mod_comb_k(N, i, M) % M
    # print(ans)
print(ans)








Fixed submission:
N, a, b = map(int, input().split())
M = 1000000007


def mod_comb_k(n, k):
    n_P_n_k = 1
    fact_k = 1
    for i in range(k):
        n_P_n_k = n_P_n_k * (n - i) % M
        fact_k = fact_k * (i + 1) % M
    return n_P_n_k * pow(fact_k, M-2, M)

ans = (pow(2, N, M) - 1 - mod_comb_k(N, a) - mod_comb_k(N, b)) % M
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))

E = [(i + 1)/2 for i in p]
ans = 0
for i in range(N - K + 1):
    s = sum(E[i:i+K])
    if ans < s:
        ans = s
print(ans)

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

E = [(i + 1)/2 for i in p]
S = sum(E[0:K])
ans = S
for i in range(1, N - K + 1):
    S += E[i+K-1] - E[i-1]
    if ans < S:
        ans = S
print(ans)

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

E = [(i + 1)/2 for i in p]
ans = 0
for i in range(N - K + 1):
    s = sum(E[i:i+K])
    ans = max([ans, s])
print(ans)

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

E = [(i + 1)/2 for i in p]
S = sum(E[0:K])
ans = S
for i in range(1, N - K + 1):
    S += E[i+K-1] - E[i-1]
    if ans < S:
        ans = S
print(ans)

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

E = [sum(range(1, i+1)) / i for i in p]
ans = 0
for i in range(N - K + 1):
    s = sum(E[i:i+K])
    ans = max([ans, s])
print(ans)

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

E = [(i + 1)/2 for i in p]
S = sum(E[0:K])
ans = S
for i in range(1, N - K + 1):
    S += E[i+K-1] - E[i-1]
    if ans < S:
        ans = S
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
print(sum(list(range(n))))

Fixed submission:
n = int(input())
print((n-1 + 1) * (n-1) // 2)
Buggy python submission (verdict: Runtime Error):
n,a,b = map(int,input.split())

print(min(a,b),max(a+b-n,0))

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

print(min(a,b),max(a+b-n,0))
Buggy python submission (verdict: Runtime Error):
a =int(input()) 
b= int(input())
if a <= 8 and b <= 8:
    print('Yay!')
else:
    print(':(')

Fixed submission:
a,b = map(int,input().split())
if a <= 8 and b <= 8:
    print('Yay!')
else:
    print(':(')
Buggy python submission (verdict: Runtime Error):
N = int(input())
LR = [tuple(map(int,input().split()))for i in [None] * N]
Lmin = sorted(LR,key=lambda x:x[0])
Rmax = sorted(LR,key=lambda x:x[1],reverse=True)

T = 0
def t_len(lr):
    a = lr[1] - T
    b = T - lr[0]
    return  a if a > b else b

def select(l):
    return sorted(l,key=t_len,reverse=True)[0]

def select2(l):
    a = abs(Lmin[0][0] - T)
    b = abs(Rmax[0][1] - T)
    return Lmin[0] if a > b else Rmax[0]

def selectT(lr):
    if lr[0] <= T <= lr[1]:
        return T
    a = lr[1] - T
    b = T - lr[0]
    return  lr[0] if a > b else lr[1]
K = 0
for i in [None]*N:
    s = select2(LR)
    nextT = selectT(s)
    K += abs(nextT-T)
    T = nextT
    LR.remove(s)
    Lmin.remove(s)
    Rmax.remove(s)
K += abs(T)
print(K)

Fixed submission:
N = sum([int(i) for i in input()])
print('10' if N == 1 else N)
Buggy python submission (verdict: Runtime Error):
s = input()
print(sorted(set([s[i:j+1] for i in range(len(s)) for j in range(i,len(s))]))[int(input())-1])

Fixed submission:
s = input()
K = int(input()) # 1 <= K <= 5

alpha = "abcdefghijklmnopqrstuvwxyz"
substring = ''
L = []
for i in alpha:
    indeces = [key for key, x in enumerate(s) if x == i]
    for j in indeces:
        for k in range(j,j+K):
            substring += s[j:k+1] + ','
    L += substring.split(',')[:-1] 
    if len(set(L)) >= K:
        break
    substring = ""
print(sorted(set(L))[K-1])

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

substring = ''
for i in range(len(s)):
    for j in range(i,len(s)):
        substring += s[i:j+1] + ','
L = sorted(set(substring.split(',')[:-1]))
print(L[K-1])

Fixed submission:
s = input()
K = int(input()) # 1 <= K <= 5

alpha = "abcdefghijklmnopqrstuvwxyz"
substring = ''
L = []
for i in alpha:
    indeces = [key for key, x in enumerate(s) if x == i]
    for j in indeces:
        for k in range(j,j+K):
            substring += s[j:k+1] + ','
    L += substring.split(',')[:-1] 
    if len(set(L)) >= K:
        break
    substring = ""
print(sorted(set(L))[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
def get_prime_list(n):
    L = list(range(2,n+1))
    for i in range(2,int((n+1)**0.5)):
        if i not in L:
            continue
        L = [j for j in L if j <= i] + [j for j in L if j > i and j % i != 0]
    return L

Q = int(input())
lr = [list(map(int,input().split())) for _ in range(Q)]
prime_list = get_prime_list(100000)
like_num = [i for i in prime_list if (i+1)//2 in prime_list]
for l,r in lr:
    print(len([i for i in like_num if l<=i<=r]))

Fixed submission:
def get_prime_list(n):
    L = tuple(range(2,n+1))
    for i in range(2,int((n+1)**0.5)):
        if i not in L:
            continue
        L = tuple(j for j in L if j <= i) + tuple(j for j in L if j > i and j % i != 0)
    return L

Q = int(input())
lr = [tuple(map(int,input().split())) for _ in range(Q)]
prime_list = get_prime_list(100000)
like_num = tuple(i for i in prime_list if (i+1)//2 in prime_list)
L = [0] * 100002
for i in range(3,100001,2):
    if i in like_num:
        L[i] = L[i-2]+1
    else:
        L[i] = L[i-2]
for l,r in lr:
    print(L[r]-L[l-2])
Buggy python submission (verdict: Runtime Error):
N,Z,W = map(int,input().split())
a = list(map(int,input().split()))
amax = max(*a,Z,W)
amin = min(*a,Z,W)
alast = a[N-1]
if N == 1:
    print(abs(W-a[0]))
    exit()
print(max(amax-alast,amin-alast))

Fixed submission:
N,Z,W = map(int,input().split())
a = list(map(int,input().split())) 
alast = a[N-1]
if N == 1:
    print(abs(W-alast))
    exit()
print(max(abs(W-alast),abs(a[N-2]-alast)))
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
if K == 0:
    print(2)
    print(1,1)
    exit()
N = 50
L = list(range(N))
for i in range(K):
    L[i%N] += N + 1
    L = list(map(lambda x:x-1,L))
print(N)
print(*L)

Fixed submission:
K = int(input())
N = 50
L = list(range(N))
q,r = divmod(K,N)
for i in range(N):
    L[i] += N * q + (N if r > i else 0)
    L[i] -= (N-1) * q + (r-1 if r > i else r)
print(N)
print(*L)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int,input().split()))
if N == 2:
    print(abs(a[1]-a[0]))
    exit()
S = sum(a)
m = float('inf')
for i in range(N-2):
    m = min(abs(S - sum(a[:i+1])*2),m)
    if m == 0:
        break
print(m)

Fixed submission:
N = int(input())
a = list(map(int,input().split()))
if N == 2:
    print(abs(a[1]-a[0]))
    exit()
S = sum(a)
m = float('inf')
memo = [0]*(N-1)
memo[0] = a[0]
for i in range(1,N-1):
    memo[i] = memo[i-1] + a[i]
for i in range(N-1):
    m = min(abs(S-memo[i]*2),m)

print(m)
Buggy python submission (verdict: Time Limit Exceeded):
N,M =map(int,input().split())
abc = [list(map(int,input().split())) for _ in range(M)]
abc = [(a-1,b-1,-c) for a,b,c in abc]
dist = [float('inf')] * N
dist[0] = 0

for _ in range(N-1):
    for a,b,c in abc:
        if dist[a] == float('inf'):
            continue
        if dist[b] > dist[a] + c:
            dist[b] = dist[a] + c

ans = dist[N-1]
negative = [False]*N

for _ in range(N):
    for a,b,c in abc:
        if dist[a] == float('inf'):
            continue
        if dist[b] > dist[a] + c:
            dist[b] = dist[a] + c
            negative[b] = True
        if negative[a]:
            negative[b] = True

if negative[N-1]:
    print('inf')
else:
    print(-ans)


Fixed submission:
N,M =map(int,input().split())
abc = [list(map(int,input().split())) for _ in range(M)]
abc = [(a-1,b-1,-c) for a,b,c in abc]

dist = [float('inf')] * N
dist[0] = 0

for _ in range(N-1):
    for a,b,c in abc:
        if dist[a] == float('inf'):
            continue
        if dist[b] > dist[a] + c:
            dist[b] = dist[a] + c

ans = dist[N-1]
negative = [False]*N

for _ in range(N):
    for a,b,c in abc:
        if dist[a] == float('inf'):
            continue
        if dist[b] > dist[a] + c:
            dist[b] = dist[a] + c
            negative[b] = True
        if negative[a]:
            negative[b] = True

if negative[N-1]:
    print('inf')
else:
    print(-ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

S = S.replace("dream",'/*/').replace('erase','/+/')
S = S.split('/')
while '' in S:
    S.remove('')
for i in range(len(S)):
    if S[i] == '*' or S[i] == '+':
        continue
    if S[i] == 'r':
        if i != 0 and S[i-1] == '+':
            continue
    elif S[i] == 'er':
        if i != 0 and S[i-1] == '*':
            continue
    print('NO')
    exit()
print('YES')
            

Fixed submission:
S = input()

S = S.replace("dream",'/*/').replace('erase','/+/')
S = [i for i in S.split('/') if i != '']
for i in range(len(S)):
    if S[i] == '*' or S[i] == '+':
        continue
    if S[i] == 'r':
        if i != 0 and S[i-1] == '+':
            continue
    elif S[i] == 'er':
        if i != 0 and S[i-1] == '*':
            continue
    print('NO')
    exit()
print('YES')
Buggy python submission (verdict: Runtime Error):

in_d = input()
n = int(in_d)

a = [int(i) for i in input().split()]

result = 0
if 0 in a:
    print(0)
else:
    result = 1
    limit = 10 ** 18
    over = 0
    a.sort()
    for v in a:
        result *= v
        if result > limit:
            over = 1
            break
    if over == 1:
        print(-1)
    else:
        print(result)

Fixed submission:
in_d = input()

a, b = in_d.split()
a = int(a)
b = int(b)

c = a * b
print(c)
Buggy python submission (verdict: Runtime Error):
import sys

args = sys.argv

a = "abcdefghijklmnopqrstuvwxyz"

c = args[1]
idx = a.index(c)
print(a[idx + 1])


Fixed submission:
import sys

args = sys.argv

a = "abcdefghijklmnopqrstuvwxyz"

c = input()
idx = a.index(c)
print(a[idx + 1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys

n, m = input().split()
i = [input() for i in range(int(m))]

n_l = [0] * int(n)
w_l = [0] * int(n)
p_l = []

a = 0
w = 0
for i_s in i:
    p, c = i_s.split()
    p = int(p) - 1
    if n_l[p] == 1:
        continue

    if p not in p_l:
        p_l.append(p)

    if c == "AC":
        n_l[p] = 1
    else:
        w_l[p] += 1

for p in p_l:
    if n_l[p] == 1:
        a += 1
        w += w_l[p]

print("{} {}".format(a, w))


Fixed submission:
import sys
import numpy as np

n, m = input().split()
i = [input() for i in range(int(m))]

n_l = [False] * int(n)
w_l = [0] * int(n)

for i_s in i:
    p, c = i_s.split()
    p = int(p) - 1
    if n_l[p] == 1:
        continue

    if c == "AC":
        n_l[p] = True
    else:
        w_l[p] += 1

n_l = np.array(n_l)
w_l = np.array(w_l)
w_l = w_l[n_l]

print("{} {}".format(n_l.sum(), w_l.sum()))

Buggy python submission (verdict: Time Limit Exceeded):
import sys

n, m = input().split()
i = [input() for i in range(int(m))]

n_l = [0] * int(n)
w_l = [0] * int(n)
p_l = []

a = 0
w = 0
for i_s in i:
    p, c = i_s.split()
    p = int(p) - 1
    if p not in p_l:
        p_l.append(p)

    if n_l[p] == 1:
        continue

    if c == "AC":
        n_l[p] = 1
    else:
        w_l[p] += 1

for p in p_l:
    if n_l[p] == 1:
        a += 1
        w += w_l[p]

print("{} {}".format(a, w))


Fixed submission:
import sys
import numpy as np

n, m = input().split()
i = [input() for i in range(int(m))]

n_l = [False] * int(n)
w_l = [0] * int(n)

for i_s in i:
    p, c = i_s.split()
    p = int(p) - 1
    if n_l[p] == 1:
        continue

    if c == "AC":
        n_l[p] = True
    else:
        w_l[p] += 1

n_l = np.array(n_l)
w_l = np.array(w_l)
w_l = w_l[n_l]

print("{} {}".format(n_l.sum(), w_l.sum()))
Buggy python submission (verdict: Runtime Error):
n = int(input())
if (n % 2 == 0):
  print("%.10f" % (1/2))
else:
  print("%.10f" % ((n//2)+1)/n)

Fixed submission:
n = int(input())
if (n%2 == 0):
    print("%.10f" % (1/2))
else:
    ans = ((n//2) + 1) / n
    print("%.10f" % ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
order = list(map(int, input().split()))
for i in range(1, len(order)+1):
  id = order.index(i)
  print(id+1, end = ' ')

Fixed submission:
n = int(input())
order = list(map(int, input().split()))
correctOrder = [0 for x in range(n)]
for i in range(n):
    correctOrder[order[i]-1] = str(i+1)
toStr = ' '.join(correctOrder)
print(toStr)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
order = list(map(int, input().split()))
while (min(order) != 999999):
  minVal = min(order)
  minIndex = order.index(minVal)
  print(minIndex+1, end = ' ')
  order[minIndex] = 999999

Fixed submission:
n = int(input())
order = list(map(int, input().split()))
correctOrder = [0 for x in range(n)]
for i in range(n):
    correctOrder[order[i]-1] = str(i+1)
toStr = ' '.join(correctOrder)
print(toStr)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = list(map(int,input().split()))
tot_votes = sum(A)
count = 0
for a in A:
    if(a>=tot_votes/(4*M)):
        count+=1
if(count>=M):
    print("Yes")
else:
    print("No")

Fixed submission:
x,y,z = input().split()
x,y = int(y),int(x)
x,z = int(z),int(x)
print(x,y,z)
Buggy python submission (verdict: Runtime Error):
N,M = input().split()
A = list(map(int,input().split()))
tv = sum(A)
i,count=0,0
while(i<N and count!=M):
  if(A[i]>int(tv/4*int(M))):
    count+=1
if(count==M):
  print("YES")
else:
  print("NO")

Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
tot_votes = sum(A)
count = 0
for a in A:
    if(a>=tot_votes/(4*M)):
        count+=1
if(count>=M):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
if(K==1 and N>1):
    print(int(0))
elif(N==0 and K>=1):
    print(int(0))
else:
    i = 0
    l = 100000000000000000
    r = []
    while(i==0):
        r.append(N)
        s = abs(N-K)
        if(l>s):
            l = s
        N = s
        if(N in r):
            i+=1
    print(l)

Fixed submission:
N,K = map(int,input().split())
if(N==0):
    print(int(0))
else:
    r = N%K
    print(min(r,K-r))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
a = list(map(int, input().split()))
total = 1
if 0 in a:
    total = 0
else:
    for num in a:
        total *= num
    if total > 10**18:
        total = -1

print(total)

Fixed submission:
n = int(input())
a = []
a = list(map(int, input().split()))
total = 1
if 0 in a:
    total = 0
else:
    for num in a:
        total *= num
        if total > 10**18:
            total = -1
            break

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
a = list(map(int, input().split()))
total = 1
if 0 in a:
    total = 0
else:
    for num in a:
        total *= num
if total > 10**18:
    total = -1

print(total)

Fixed submission:
n = int(input())
a = []
a = list(map(int, input().split()))
total = 1
if 0 in a:
    total = 0
else:
    for num in a:
        total *= num
        if total > 10**18:
            total = -1
            break

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
a = list(map(int, input().split()))
total = 1
for num in a:
    total *= num
if total > 10**18:
    total = -1

print(total)

Fixed submission:
n = int(input())
a = []
a = list(map(int, input().split()))
total = 1
if 0 in a:
    total = 0
else:
    for num in a:
        total *= num
        if total > 10**18:
            total = -1
            break

print(total)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
a, b, c, k = map(int, input().split())
max = 0
if a < k:
    for i in range(a, -1, -1):
        for j in range(b, -1, -1):
            for l in range(c+1):
                if i+j+l == k:
                    print(i-l)
                    sys.exit()
else:
    for i in range(k, -1, -1):
        for j in range(b, -1, -1):
            for l in range(c+1):
                if i+j+l == k:
                    print(i-l)
                    sys.exit()

Fixed submission:
import sys
a, b, c, k = map(int, input().split())
if a >= k:
    print(k)
    sys.exit()
else:
    if b >= k-a:
        print(a)
        sys.exit()
    else:
        print(a-(k-a-b))
        sys.exit()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
a, b, c, k = map(int, input().split())
max = 0
for i in range(a, -1, -1):
    for j in range(b, -1, -1):
        for l in range(c+1):
            if i+j+l == k:
                print(i-l)
                sys.exit()

Fixed submission:
import sys
a, b, c, k = map(int, input().split())
if a >= k:
    print(k)
    sys.exit()
else:
    if b >= k-a:
        print(a)
        sys.exit()
    else:
        print(a-(k-a-b))
        sys.exit()