Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import queue

BLACK = '#'
WHITE = '.'
vec_x = [1, 0, -1, 0]
vec_y = [0, 1, 0, -1]
vec_num = len(vec_x)

def solve():
    count = 0
    for i in range(H):
        for j in range(W):
            if used[i][j]:
                continue
            b = 0
            w = 0
            que = queue.Queue()
            used[i][j] = True
            que.put((i, j))

            while not que.empty():
                next_i, next_j = que.get()

                #黒か白かをカウント
                if(S[next_i][next_j] == BLACK):
                    b += 1
                else:
                    w += 1

                #隣接するマスの色が現在のマスと違うならキューに追加
                for d in range(vec_num):
                    d_i = next_i + vec_y[d]
                    d_j = next_j + vec_x[d]
                    if not check(next_i, next_j, d_i, d_j) or used[d_i][d_j]:
                        continue
                    que.put((d_i, d_j))
                    used[d_i][d_j] = True
            count += b * w
    return count

def check(i, j, d_i, d_j):
    if not isIn(d_i, d_j):
        return False
    if S[i][j] == S[d_i][d_j]:
        return False
    return True

def isIn(i, j):
    return 0 <= i < H and 0 <= j < W



if __name__ == "__main__":
    H, W = map(int, input().split())
    S = [[]] * H
    used = [[]] * H
    for h in range(H):
        S[h] = list(input())
        used[h] = [False] * W
    print(solve())


Fixed submission:
from collections import deque

BLACK = '#'
WHITE = '.'
vec_x = [1, 0, -1, 0]
vec_y = [0, 1, 0, -1]
vec_num = len(vec_x)

def solve():
    count = 0
    for i in range(H):
        for j in range(W):
            if used[i][j]:
                continue
            b = 0
            w = 0
            que = deque([(i, j)])
            used[i][j] = True

            while que:
                next_i, next_j = que.popleft()

                #黒か白かをカウント
                if(S[next_i][next_j] == BLACK):
                    b += 1
                else:
                    w += 1

                #隣接するマスの色が現在のマスと違うならキューに追加
                for d in range(vec_num):
                    d_i = next_i + vec_y[d]
                    d_j = next_j + vec_x[d]
                    if not check(next_i, next_j, d_i, d_j) or used[d_i][d_j]:
                        continue
                    que.append((d_i, d_j))
                    used[d_i][d_j] = True
            count += b * w
    return count

def check(i, j, d_i, d_j):
    if not (0 <= d_i < H and 0 <= d_j < W):
        return False
    if S[i][j] == S[d_i][d_j]:
        return False
    return True



if __name__ == "__main__":
    H, W = map(int, input().split())
    S = [[]] * H
    used = [[]] * H
    for h in range(H):
        S[h] = list(input())
        used[h] = [False] * W
    print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = [0] + list(map(int, input().split()))

dp = [-1] * (N + 1)
dp[N] = 0
dp[N - 1] = abs(h[N] - h[N - 1])

for i in reversed(range(1, N - 1)):
    candidates = [10 ** 5] * K
    for k in range(1, K + 1):
        if i + k > N:
            continue
        candidates[k - 1] = dp[i + k] + abs(h[i + k] - h[i])
    dp[i] = min(candidates)
print(dp[1])


Fixed submission:
N, K = map(int, input().split())
h = [0] + list(map(int, input().split()))

dp = [-1] * (N + 1)
dp[N] = 0
dp[N - 1] = abs(h[N] - h[N - 1])

for i in reversed(range(1, N - 1)):
    candidates = [10 ** 5] * K
    for k in range(1, K + 1):
        if i + k > N:
            continue
        candidates[k - 1] = dp[i + k] + abs(h[i + k] - h[i])
    dp[i] = min(candidates)
print(dp[1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
items = [None] * N
for n in range(N):
    w, v = map(int, input().split())
    items[n] = (w, v)
V = 10 ** 6 + 1

dp = [[10 ** 9 + 1] * V for _ in range(N + 1)]
dp[0][0] = 0

for i in range(N):
    for j in range(V):
        w, v = items[i]
        if j >= v:
            dp[i + 1][j] = min(dp[i][j - v] + w, dp[i][j])
        else:
            dp[i + 1][j] = dp[i][j]

ans = 0
for v in range(V):
    if dp[N][v] <= W:
        ans = v
print(ans)


Fixed submission:
N, W = map(int, input().split())
items = [None] * N
for n in range(N):
    w, v = map(int, input().split())
    items[n] = (w, v)
V = 10 ** 5 + 1

dp = [[10 ** 9 + 1] * V for _ in range(N + 1)]
dp[0][0] = 0

for i in range(N):
    for j in range(V):
        w, v = items[i]
        if j >= v:
            dp[i + 1][j] = min(dp[i][j - v] + w, dp[i][j])
        else:
            dp[i + 1][j] = dp[i][j]

ans = 0
for v in range(V):
    if dp[N][v] <= W:
        ans = v
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
input_list = list(map(int,input().split()))
cnt = 0
for i in input_list:
    if i >= K:
        cnt += 1
print(cnt

Fixed submission:
N, K = map(int, input().split())
input_list = list(map(int,input().split()))
cnt = 0
for i in input_list:
    if i >= K:
        cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
power = 1
for i in range(1, N+1):
    power *= i
print(power % (10 ** 9 + 7))


Fixed submission:
N = int(input())
power = 1
div = 10 ** 9 + 7
for i in range(1, N+1):
    power = power * i % div 
print(power)
Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int, input().split())

ans = 0
for x in range(K+1):
    max_y = S - x if S - x < K else K
    for y in range(max_y + 1): 
        max_z = S - x - y if S - x -y < K else K
        for z in range(max_z + 1):
            if (x + y + z) == S:
                ans += 1
print(ans)


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

ans = 0
for x in range(K+1):
    for y in range(K + 1): 
        z = S - x - y 
        if 0 <= z and z <= K:
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = (int(i) for i in input().split())

common_divisor_set = []
result_set = []

GCD = lambda a, b: (GCD(b, a % b) if a % b else b)

for i in range(min(a, b), 0, -1):
    if a%i == 0 and b%i == 0:
        common_divisor_set.insert(0, i)

left = [0 for x in range(n)]
right = [0 for x in range(n)]
ans = -1

n = len(common_divisor_set)
for i in range(n):
    if (i == 0):
        gcd = a[0]
    else:
        gcd = GCD(a[i], left[i - 1])
    left[i] = gcd

for i in range(n-2, -1, -1):   
    if (i == n - 1):
        gcd = a[n - 1]
    else:
        gcd = GCD(a[i], right[i + 1])
    right[i] = gcd

for i in range(n):
    if (i == 0):
        gcd = right[1]
    elif (i == n - 1):
        gcd = left[n - 2]
    else:
        gcd = GCD(left[i - 1], right[i + 1])
    if (gcd>ans):
        ans = gcd

print(ans)


Fixed submission:
from math import sqrt
a, b = (int(i) for i in input().split())

GCD = lambda x, y: (GCD(y, x % y) if x % y else y)
ab_gcd = GCD(a, b)

def factoring(gcb,n=2):
    for i in range(n,int(gcb**0.5)+1):
        if gcb%i==0:
            ret = factoring(gcb//i,i)
            ret[i] = ret.get(i,0)+1
            return ret
    return {gcb:1}

result = set(factoring(ab_gcd).keys())
result.add(1)
print(len(result))
Buggy python submission (verdict: Runtime Error):
n = map(int, input())

print((n // 2 + n % 2) / n)
  

Fixed submission:
n = int(input())

print((n // 2 + n % 2) / n)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = map(int, input().split())
tmp = 3 ** N
g = len([c for c in a if a % 2 == 0])
print(tmp - (2 ** g))

Fixed submission:
N = int(input())
a = map(int, input().split())
tmp = 3 ** N
g = len([c for c in a if c % 2 == 0])
print(tmp - (2 ** g))
Buggy python submission (verdict: Runtime Error):
S = input()
st = 0
la = len(S) - 1
result = 0

while(st > la):
  if S[st]== 'x' and S[la]== 'x':
    st += 1
    la += 1
    continue
  if S[st] != 'x' and S[la]== 'x':
    result += 1
    la += 1
  elif S[st] == 'x' and S[la] != 'x':
    result += 1
    st += 1
  else
    result = -1
    break

 print(result)
  

Fixed submission:
S = input()
N = len(S)
st = 0
la = N - 1
result = 0

while(st < la):
  if S[st] == 'x' and S[la] == 'x':
    st += 1
    la -= 1
    continue
  if S[st] != 'x' and S[la] == 'x':
    la -= 1
    result += 1
  elif S[st] == 'x' and S[la] != 'x':
    st += 1
    result += 1
  elif S[st] == S[la]:
    st += 1
    la -= 1
  else:
    result = -1
    break

print(result)
Buggy python submission (verdict: Runtime Error):
print(input().conut('1'))

Fixed submission:
print(input().count('1'))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import itertools
import fractions
import re
import math

from collections import Counter
 
def va(first_word, second_word):
    def get_counter(s):
        return Counter(s.upper().replace(' ', ''))
    return get_counter(first_word) == get_counter(second_word)
def resolve():
    N = int(input())
    S = list(input() for _ in range(N))
    count = 0
    for C in itertools.combinations(range(N),2):
        if va(S[C[0]],S[C[1]]) == True:
            count += 1
    print(count)

    
resolve()

Fixed submission:
def resolve():
    N = int(input())
    S = sorted(list(sorted(input()) for _ in range(N)))
    count = 0
    S_dict = {}
    for i in range(N):
        s = str(S[i])
        if s in S_dict:
            tmp =  S_dict[s]
            S_dict[s] = tmp + 1
            count = count + tmp
        else:
            S_dict.setdefault(s,1)
    print(count)

    
resolve()
Buggy python submission (verdict: Runtime Error):

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
x = min(A[0],B[0])
ans += x
for j in range(N-1):
    i = j+1
    x = min(A[i],B[i-1]-x)
    ans += x
    x = min(A[i]-x,B[i])
    ans += x
i = i+1
x = min(A[i],B[i-1]-x)
ans += x
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans, x = 0, 0
ans += x
for i in range(N):
    x = min(A[i]-x,B[i])
    ans += x
    x = min(A[i+1],B[i]-x)
    ans += x
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
x = min(A[0],B[0])
ans += x
for j in range(N-1):
    i = j+1
    x = min(A[i],B[i-1]-x)
    ans += x
    x = min(A[i]-x,B[i])
    ans += x
i = i+1
x = min(A[i],B[i-1]-x)
ans += x

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans, x = 0, 0
ans += x
for i in range(N):
    x = min(A[i]-x,B[i])
    ans += x
    x = min(A[i+1],B[i]-x)
    ans += x
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
x = 0
ans += min(A[0],B[0])

for j in range(N-1):
    i = j+1
    x = min(A[i],B[i-1]-x)
    ans += x
    x = min(A[i]-x,B[i])
    ans += x
i = i+1
x = min(A[i],B[i-1]-x)
ans += x
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans, x = 0, 0
ans += x
for i in range(N):
    x = min(A[i]-x,B[i])
    ans += x
    x = min(A[i+1],B[i]-x)
    ans += x
print(ans)
Buggy python submission (verdict: Runtime Error):
n,d = map(int, input().split())
print int((n+(d*2+1)-1)/(d*2+1))

Fixed submission:
n,d = map(int, input().split())
print(int((n+(d*2+1)-1)/(d*2+1)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)

for i in range(N):
    if i == A.index(max(A)):
        print(B[-2])
    else:
        print(B[-1])

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)
c = A.index(max(A))
for i in range(N):
    if i == c:
        print(B[-2])
    else:
        print(B[-1])
Buggy python submission (verdict: Runtime Error):
L, R = map(int,input().split())
a = 10**10
for i in range(L,min(R,L+2019):
    for j in range(i+1,min(R,L+2019)+1):
        a = min(a,(i*j)%2019)
        if a == 1:
            print("1")
            exit()
print(a)

Fixed submission:
L, R = map(int,input().split())
a = 10**10
for i in range(L,min(R,L+2019)+1):
    for j in range(i+1,min(R,L+2019)+1):
        a = min(a,(i*j)%2019)
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int,input().split())
a = 100000000000
for i in range(L,R+1):
    for j in range(i+1,R+1):
        a = min(a,(i*j)%2019)
print(a)

Fixed submission:
L, R = map(int,input().split())
a = 10**10
for i in range(L,min(R,L+2019)+1):
    for j in range(i+1,min(R,L+2019)+1):
        a = min(a,(i*j)%2019)
print(a)
Buggy python submission (verdict: Runtime Error):
    N = int(input())
    d = list(map(int,input().split()))

    d.sort()
    i = len(d)//2
    print(d[i]-d[i-1])

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

d.sort()
i = len(d)//2
print(d[i]-d[i-1])
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
e = (c * d) // math.gcd(c, d)
x = b//c - (a-1)//c
y = b//d - (a-1)//d
z = b//e- (a-1)//e
print(b-a+1-(x+y-z))


Fixed submission:
from fractions import gcd
a,b,c,d = map(int,input().split())
e = (c * d) // gcd(c, d)
x = b//c - (a-1)//c
y = b//d - (a-1)//d
z = b//e- (a-1)//e
print(b-a+1-(x+y-z))
Buggy python submission (verdict: Runtime Error):
n,x = map(int,input().split())
l = list(map(int,input().split()))
L=0
for i in range(n):
    L += l[i]
    if L > x:
        print(i+1)
        return()

Fixed submission:
n,x = map(int,input().split())
l = list(map(int,input().split()))
ans = 1
L=0
for i in range(n):
    L += l[i]
    if L <= x:
        ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
    w,h,x,y = map(float, input().split())
    if (abs(w//2-x)>abs(h//2-y)):
        print("{:.6f} {}".format(min(y*w,(h-y)*w),0))
    elif (abs(w//2-x)<abs(h//2-y)):
        print("{:.6f} {}".format(min(x*h,(w-x)*h),0))
    else:
        print("{:.6f} {}".format(min(x*h,(w-x)*h),1))

Fixed submission:
w,h,x,y = map(float, input().split())
print('{:.6f} {}'.format(float(w)*float(h)/2, int(x+x==w and y+y==h)))
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
if a>13:
  print(b)
  elif a>6:
    print(b//2)
    else:
      print(0)

Fixed submission:
a,b = map(int,input().split())
if a>=13:
    print(b)
elif a>=6:
    print(b//2)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N,M = map(int,input().split())
#    LL,RR = [],[]
#    for i in range(M):
#        L,R = map(int,input().split())
#        LL.append(L)
#        RR.append(R)

    ans = 0
#    print()
#    print(N,M)
#    print(LL,RR)
    bool_id = [1]*N
#    print(bool_id)
    for i in range(M): #Gate num
#        print(LL[i],RR[i])
#        l,r = LL[i]-1,RR[i]
        l,r = map(int,input().split())
        #bool_id[l:r] = [True]*(r-l)
        bool_id[:l-1] = [0]*(l-1)
        bool_id[r:] = [0]*(N-r)
#        print(bool_id)
    print(sum(bool_id))

resolve()

Fixed submission:
def resolve():
    N,M = map(int,input().split())
    LL,RR = [],[]
    for i in range(M):
        L,R = map(int,input().split())
        LL.append(L)
        RR.append(R)

    bool_id = [1]*N
    lmin = -1
    rmax = 10**10
    for i in range(M):
        lmin = max(lmin,LL[i])
        rmax = min(rmax,RR[i])
    print(max(rmax-lmin+1,0))

resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N,M = map(int,input().split())
    LL,RR = [],[]
    for i in range(M):
        L,R = map(int,input().split())
        LL.append(L)
        RR.append(R)

    ans = 0
#    print()
#    print(N,M)
#    print(LL,RR)
    bool_id = [1]*N
#    print(bool_id)
    for i in range(M): #Gate num
#        print(LL[i],RR[i])
        l,r = LL[i]-1,RR[i]
        #bool_id[l:r] = [True]*(r-l)
        bool_id[:l] = [0]*(l)
        bool_id[r:] = [0]*(N-r)
#        print(bool_id)
    print(sum(bool_id))

resolve()


Fixed submission:
def resolve():
    N,M = map(int,input().split())
    LL,RR = [],[]
    for i in range(M):
        L,R = map(int,input().split())
        LL.append(L)
        RR.append(R)

    bool_id = [1]*N
    lmin = -1
    rmax = 10**10
    for i in range(M):
        lmin = max(lmin,LL[i])
        rmax = min(rmax,RR[i])
    print(max(rmax-lmin+1,0))

resolve()
Buggy python submission (verdict: Runtime Error):
s = list(input())
a = int(s[0]+s[1])
b = int(s[2]+s[3])
if 0<a<13 and 0<b<13:
    print('AMBIGUOUS')
elif 0<a<13:
    print('MMYY')
elif 0<b<13:
    print('YYMM')
else:
    print('NA')


Fixed submission:
n,k = map(int,input().split())
s = list(input())
s[k-1] = s[k-1].lower()
print("".join(s))
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
print((max(a,b)+max(max(a,b)-1,min(a,b)))

Fixed submission:
a,b = map(int,input().split())
print((max(a,b)+max(max(a,b)-1,min(a,b))))
Buggy python submission (verdict: Runtime Error):
def resolve():
    a = list(int(input()) for _ in range(5))
    mint = 1000
    ans = 0
    for i in range(5):
        ans += math.ceil(a[i]/10)*10
        if a[i]%10 == 0: continue
        mint = min(mint,a[i]%10)
    print(ans+mint-10)

resolve()

Fixed submission:
import math
def resolve():
    a = list(int(input()) for _ in range(5))
    mint = 1000
    ans = 0
    for i in range(5):
        ans += math.ceil(a[i]/10)*10
        if a[i]%10 == 0: continue
        mint = min(mint,a[i]%10)
    if mint == 1000:
        print(ans)
    else:
        print(ans+mint-10)
resolve()
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
print(math.ceil(N/min(A,B,C,D,E))+4)

Fixed submission:
import math
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
print(math.ceil(N/min(A,B,C,D,E))+4)

Buggy python submission (verdict: Time Limit Exceeded):

def resolve():
    N = int(input())
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    E = int(input())
#    print()
#    print(N,A,B,C,D,E)
    n,a,b,c,d,e,t = N,0,0,0,0,0,0
#    print(n,a,b,c,d,e,t)
    while (e != N):
        tmp = min(d,E)
        d -= tmp
        e += tmp
        tmp = min(c,D)
        c -= tmp
        d += tmp
        tmp = min(b,C)
        b -= tmp
        c += tmp
        tmp = min(a,B)
        a -= tmp
        b += tmp
        tmp = min(n,A)
        n -= tmp
        a += tmp
        t += 1
#        print(n,a,b,c,d,e,t)
    print(t)
resolve()


Fixed submission:
import math
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
print(math.ceil(N/min(A,B,C,D,E))+4)
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    n,k= map(int,input().split())
    h = list(map(int,input().split()))
    d = [float("inf")]*(n)
    d[0] = 0
    for i in range(n):
        for j in range(1,min(i,k)+1):
            d[i] = min(d[i-j]+abs(h[i]-h[i-j]),d[i])
#            print(i,j)
#        print(d[i])
    print(d[-1])

resolve()


Fixed submission:
import numpy as np
def resolve():
    n,k= map(int,input().split())
    h = np.array(list(map(int,input().split())))
    d = np.array([0]*n)
    d[0] = 0
    for i in range(1,n):
        j=max(0,i-k)
        d[i] = (d[j:i]+np.abs(h[i]-h[j:i])).min()
    print(d[-1])

resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    n,k= map(int,input().split())
    h = list(map(int,input().split()))
    d = [float("inf")]*(n)
    d[0] = 0
    for i in range(n):
        for j in range(min(i,k)+1):
            d[i] = min(d[i-j]+abs(h[i]-h[i-j]),d[i])
    print(d[-1])

resolve()


Fixed submission:
import numpy as np
def resolve():
    n,k= map(int,input().split())
    h = np.array(list(map(int,input().split())))
    d = np.array([0]*n)
    d[0] = 0
    for i in range(1,n):
        j=max(0,i-k)
        d[i] = (d[j:i]+np.abs(h[i]-h[j:i])).min()
    print(d[-1])

resolve()
Buggy python submission (verdict: Runtime Error):
print(input().replace(1,0).replace(9,1).replace(0,9))

Fixed submission:
print(str(input()).replace('1','0').replace('9','1').replace('0','9'))
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    S=input()
    T=input()
    for i in range(len(S)):
        s=S[i]
        S=S.replace(s,'A')
        S=S.replace(T[i],s)
        S=S.replace('A',T[i])
    if S==T:
        print('Yes')
    else:
        print('No')
resolve()

Fixed submission:
def resolve():
    S=input()
    T=input()
    a,b={},{}
    for s,t in zip(S,T):
        if a.setdefault(s,t)!=t :
            print('No')
            return()
        if b.setdefault(t,s)!=s :
            print('No')
            return()
    print('Yes')
resolve()
Buggy python submission (verdict: Runtime Error):
import math
import functools
def resolve():
    N,x=map(int,input().split())
    X=list(map(int,input().split()))
    X.append(x)
    X=list(set(X))
    X.sort()
    D=[]
    for i in range(len(X)-1):
        D.append(X[i+1]-X[i])
    gcd = functools.reduce(math.gcd, D)
    print(gcd)
resolve()


Fixed submission:
def gcd(a, b):
    while a > 0:
        if a < b:
            a, b = b, a
        a = a % b
    return b
def resolve():
    N,x=map(int,input().split())
    X=list(map(int,input().split()))
    X.append(x)
    X=list(set(X))
    X.sort()
    D=[]
    for i in range(len(X)-1):
        D.append(X[i+1]-X[i])
    ans=D[0]
    for d in D:
        if d%ans!=0:
            ans=gcd(ans,d)
    print(ans)
resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
    N,x=map(int,input().split())
    X=list(map(int,input().split()))
    X.append(x)
    X=list(set(X))
    X.sort()
    D=[]
    for i in range(len(X)-1):
        D.append(X[i+1]-X[i])
    import math
    import functools
    gcd = functools.reduce(math.gcd, D)
    print(gcd)
resolve()


Fixed submission:
def gcd(a, b):
    while a > 0:
        if a < b:
            a, b = b, a
        a = a % b
    return b
def resolve():
    N,x=map(int,input().split())
    X=list(map(int,input().split()))
    X.append(x)
    X=list(set(X))
    X.sort()
    D=[]
    for i in range(len(X)-1):
        D.append(X[i+1]-X[i])
    ans=D[0]
    for d in D:
        if d%ans!=0:
            ans=gcd(ans,d)
    print(ans)
resolve()
Buggy python submission (verdict: Runtime Error):
a,b=map(int,iput().split())
print((a-1)*(b-1))

Fixed submission:
a,b=map(int,input().split())
print((a-1)*(b-1))
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input())
print(0 if a%b==0 else 1)

Fixed submission:
a,b=map(int,input().split())
print(0 if a%b==0 else 1)
Buggy python submission (verdict: Runtime Error):
def resolve():
    N=int(input())
    print(f(N))

memo = [-1]*110000

def f(n):
    if n==0: return 0
    
    global memo
    if memo[n]!=-1:
        return memo[n]
    
    minc=n
    minc=min(minc,f(n-1)+1)
    i=1
    while 6**i<=n:
        j=6**i
        minc=min(minc,f(n-j)+1)
        i+=1
    
    i=1
    while 9**i<=n:
        j=9**i
        minc=min(minc,f(n-j)+1)
        i+=1

    memo[n]=minc
    return minc

resolve()

Fixed submission:
def resolve():
    N=int(input())
    mini=10**10
    for i in range(N+1):
        j=N-i
        mini=min(mini,f(i,6)+f(j,9))
    print(mini)


def f(n,m):#nをm進数にしたときの桁和
    i=0
    while n>0:
        i=i+n%m
        n=n//m
    return(i)
resolve()
Buggy python submission (verdict: Runtime Error):
    s = list(input() for _ in range(int(input())))
    t = list(input() for _ in range(int(input())))
    print(max(0,max(s.count(S)-t.count(S) for S in set(s))))

Fixed submission:
s = list(input() for _ in range(int(input())))
t = list(input() for _ in range(int(input())))
print(max(0,max(s.count(S)-t.count(S) for S in set(s))))
Buggy python submission (verdict: Runtime Error):
print('Yes') if int(input())//500 <= int(input()) else: print('No')

Fixed submission:
print('Yes') if int(input())%500 <= int(input()) else print('No')
Buggy python submission (verdict: Runtime Error):
a,b,c,x = map(int,[input() for _ in range(4)])
ans=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if (500*i + 100*j + 50*k == x):
                ans += 1
print(ans)

Fixed submission:
x = int(input())
a = int(input())
b = int(input())

x -= a
while x >= b:
    x -= b
print(x)