Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
import bisect
input = sys.stdin.readline

def main():
    n, q = map(int, input().split())
    a = list(map(int, input().split()))
    
    s = [0]*(n+1)
    odd = [0]*(n+1)
    even = [0]*(n+1)
    for i in range(n):
        s[i+1] += s[i]+a[i]
        odd[i+1] += odd[i]
        even[i+1] += even[i]
        if i%2:
            odd[i+1] += a[i]
        else:
            even[i+1] += a[i]
    
    key = []
    value = dict()
    v = 0
    for i in range(n):
        if i == n-1:
            k = pow(10, 9)
            key.append(k)
            value[k] = v
        k = (a[i+(n-i)//2]+a[i])//2
        v = s[i+(n-i)//2]-s[i]
        if (n-i)%2:
            if i%2:
                v += even[max(0, i)]
            else:
                v += odd[max(0, i)]
        else:
            if i%2:
                v += odd[max(0, i-1)]
            else:
                v += even[max(0, i-1)]
        
        key.append(k)
        value[k] = v
    
    sum_a = s[n]
    
    for i in range(q):
        x = int(input())
        k = key[bisect.bisect_left(key, x)]
        ans = sum_a-value[k]
        print(ans)
    
    
if __name__ == "__main__":
    main()


Fixed submission:
import sys
import bisect
input = sys.stdin.readline

def main():
    n, q = map(int, input().split())
    a = list(map(int, input().split()))
    
    s = [0]*(n+1)
    odd = [0]*(n+1)
    even = [0]*(n+1)
    for i in range(n):
        s[i+1] += s[i]+a[i]
        odd[i+1] += odd[i]
        even[i+1] += even[i]
        if i%2:
            odd[i+1] += a[i]
        else:
            even[i+1] += a[i]
    
    key = []
    value = dict()
    v = 0
    for i in range(n):
        if i == n-1:
            k = pow(10, 9)
            key.append(k)
            value[k] = v
            continue
            
        k = (a[i+(n-i)//2]+a[i])//2
        v = s[i+(n-i)//2]-s[i]
        if (n-i)%2:
            if i%2:
                v += even[max(0, i)]
            else:
                v += odd[max(0, i)]
        else:
            if i%2:
                v += odd[max(0, i-1)]
            else:
                v += even[max(0, i-1)]
        
        key.append(k)
        value[k] = v
    
    sum_a = s[n]
    
    for i in range(q):
        x = int(input())
        k = key[bisect.bisect_left(key, x)]
        ans = sum_a-value[k]
        print(ans)
    
    
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = [int(x) for x in input().split()]

dp_list = [-1]*(n)

def dp(n):
  if dp_list[n] == -1:
    if n == 0:
      dp_list[0] = 0
    elif n == 1:
      dp_list[1] = abs(h[1]-h[0])
    else:
      dp_list[n] = min([dp(n-1)+abs(h[n]-h[n-1]), dp(n-2)+abs(h[n]-h[n-2])])
  return dp_list[n]

ans = dp(n-1)
print(ans)

Fixed submission:
n = int(input())
h = [int(x) for x in input().split()]
inf = 10**9+7

dp_list = [inf]*(n)

for i in range(n):
  if i == 0:
    dp_list[i] = 0
  elif i == 1:
    dp_list[i] = abs(h[1]-h[0])
  else:
    dp_list[i] = min([dp_list[i-1]+abs(h[i]-h[i-1]), dp_list[i-2]+abs(h[i]-h[i-2])])


print(dp_list[n-1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = [int(x) for x in input().split()]

dp_list = [-1]*(n)

def dp(n):
  if n == 0:
    dp_list[0] = 0
    return 0
  if n == 1:
    dp_list[1] = abs(h[1]-h[0])
    return dp_list[1]
  if dp_list[n] == -1:
    dp_list[n] = min([dp(n-1)+abs(h[n]-h[n-1]), dp(n-2)+abs(h[n]-h[n-2])])
  return dp_list[n]

ans = dp(n-1)
print(ans)

Fixed submission:
n = int(input())
h = [int(x) for x in input().split()]
inf = 10**9+7

dp_list = [inf]*(n)

for i in range(n):
  if i == 0:
    dp_list[i] = 0
  elif i == 1:
    dp_list[i] = abs(h[1]-h[0])
  else:
    dp_list[i] = min([dp_list[i-1]+abs(h[i]-h[i-1]), dp_list[i-2]+abs(h[i]-h[i-2])])


print(dp_list[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
dp = [0]*(w+1)

for i in range(n):
  weight, value = map(int, input().split())
  for j in range(w, -1, -1):
    if j == 0 or dp[j] != 0:
      if j+weight <= w:
        dp[j+weight] = max([dp[j+weight], dp[j]+value])

print(max(dp))

Fixed submission:
n, w = map(int, input().split())
dp = [0]*(w+1)

for i in range(n):
  weight, value = map(int, input().split())
  for j in range(w, -1, -1):
    if j == 0 or dp[j] != 0:
      if j+weight <= w:
        dp[j+weight] = max([dp[j+weight], dp[j]+value])

print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def main():
  n, m = map(int, input().split())
  tree_to = [[] for _ in range(n)]
  tree_from = [[] for _ in range(n)]
  for i in range(m):
    x, y = map(int, input().split())
    tree_to[x-1].append(y-1)
    tree_from[y-1].append(x-1)
  
  ans = [0]*n
  already = [False]*n
  for i in range(n):
    if already[i]:
      continue
    already[i] = True
    not_yet = deque(tree_to[i])
    while not_yet:
      key = not_yet.pop()
      if ans[key] or not tree_to[key]:
        already[key] = True
        search = deque(tree_from[key])
        while search:
          already[i]
          sub = search.popleft()
          ans[sub] = 1
          for v in tree_to[sub]:
            if ans[sub] < ans[v]+1:
              ans[sub] = ans[v]+1
          for v in tree_from[sub]:
            search.append(v)
        continue
      for v in tree_to[key]:
        not_yet.append(v)
  print(max(ans))
      

if __name__ == "__main__":
  main()

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100007)

def main():
    n, m = map(int, input().split())
    
    grid = [[] for _ in range(n)]
    
    for _ in range(m):
        x, y = map(int, input().split())
        grid[x-1].append(y-1)
    
    memo = [-1]*n
    
    def dp(n):
        if memo[n] != -1:
            return memo[n]
        res = 0
        for v in grid[n]:
            res = max(res, dp(v)+1)
        memo[n] = res
        return res
    
    ans = 0
    for i in range(n):
        sub = dp(i)
        if ans < sub:
            ans = sub
        
    print(ans)
    
    
    
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(4000)

n = int(input())
p = [float(x) for x in input().split()]

dp_list = [[0]*(n+1) for i in range(n)]

def dp(i, j):
  if dp_list[i][j] == 0:
    if i == 0:
      if j == 0:
        dp_list[i][j] = 1-p[i]
      if j == 1:
        dp_list[i][j] = p[i]
    elif j-i == 1:
      dp_list[i][j] = dp(i-1, j-1)*p[i]
    elif j == 0:
       dp_list[i][j] = dp(i-1, j)*(1-p[i])
    else:
      dp_list[i][j] = dp(i-1, j)*(1-p[i]) + dp(i-1, j-1)*p[i]
  return dp_list[i][j]

ans = 0
for i in range(n//2+1, n+1):
  ans += dp(n-1, i)
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(4000)

n = int(input())
p = [float(x) for x in input().split()]

dp = [[0]*(n+1) for i in range(n)]

dp[0][0] = 1-p[0]
dp[0][1] = p[0]

for i in range(n-1):
  for j in range(i+2):
    dp[i+1][j] += dp[i][j]*(1-p[i+1])
    dp[i+1][j+1] += dp[i][j]*p[i+1]

ans = 0
for i in range(n//2+1, n+1):
  ans += dp[n-1][i]
print(ans)

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

n = int(input())
p = [float(x) for x in input().split()]

dp_list = [[0]*(n+1) for i in range(n)]

def dp(i, j):
  if dp_list[i][j] == 0:
    if i == 0:
      if j == 0:
        dp_list[i][j] = 1-p[i]
      if j == 1:
        dp_list[i][j] = p[i]
    elif j-i == 1:
      dp_list[i][j] = dp(i-1, j-1)*p[i]
    elif j == 0:
       dp_list[i][j] = dp(i-1, j)*(1-p[i])
    else:
      dp_list[i][j] = dp(i-1, j)*(1-p[i]) + dp(i-1, j-1)*p[i]
  return dp_list[i][j]

ans = 0
for i in range(n//2+1, n+1):
  ans += dp(n-1, i)
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(4000)

n = int(input())
p = [float(x) for x in input().split()]

dp = [[0]*(n+1) for i in range(n)]

dp[0][0] = 1-p[0]
dp[0][1] = p[0]

for i in range(n-1):
  for j in range(i+2):
    dp[i+1][j] += dp[i][j]*(1-p[i+1])
    dp[i+1][j+1] += dp[i][j]*p[i+1]

ans = 0
for i in range(n//2+1, n+1):
  ans += dp[n-1][i]
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
p = [float(x) for x in input().split()]

dp_list = [[0]*(n+1) for i in range(n)]

def dp(i, j):
  if dp_list[i][j] == 0:
    if i == 0:
      if j == 0:
        dp_list[i][j] = 1-p[i]
      if j == 1:
        dp_list[i][j] = p[i]
    elif j-i == 1:
      dp_list[i][j] = dp(i-1, j-1)*p[i]
    elif j == 0:
       dp_list[i][j] = dp(i-1, j)*(1-p[i])
    else:
      dp_list[i][j] = dp(i-1, j)*(1-p[i]) + dp(i-1, j-1)*p[i]
  return dp_list[i][j]

ans = 0
for i in range(n//2+1, n+1):
  ans += dp(n-1, i)
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(4000)

n = int(input())
p = [float(x) for x in input().split()]

dp = [[0]*(n+1) for i in range(n)]

dp[0][0] = 1-p[0]
dp[0][1] = p[0]

for i in range(n-1):
  for j in range(i+2):
    dp[i+1][j] += dp[i][j]*(1-p[i+1])
    dp[i+1][j+1] += dp[i][j]*p[i+1]

ans = 0
for i in range(n//2+1, n+1):
  ans += dp[n-1][i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline


def main():
    K = input().replace("\n", "")
    D = int(input())
    
    mod = pow(10, 9)+7
    n = len(K)
    dp = [[0]*D for _ in range(n+1)]
    
    dp[0][0] = 1
    sub = 0
    
    if D == 1:
        ans = 0
        for i in range(n):
            ans = (ans*10+int(K[i]))%mod
        print(ans)
        sys.exit()


    for i in range(n):
        if i != 0:
            for j in range(10):
                for k in range(D):
                    dp[i+1][(k+j)%D] += dp[i][k]
                    dp[i+1][(k+j)%D] %= mod
            for j in range(1, 10):
                dp[i+1][j%D] += 1
                dp[i+1][j%D] %= mod
        
        
        for j in range(int(K[i])):
            if i == 0 and j == 0:
                continue
            dp[i+1][(j+sub)%D] += 1
            dp[i+1][(j+sub)%D] %= mod
        sub = (sub+int(K[i]))%D
    
    sub = 0
    for i in range(n):
        sub = (sub+int(K[i]))%D
    if sub == 0:
        dp[n][0] += 1
        dp[n][0] %= mod
        
    
    print(dp[n][0])
    
    
if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline


def main():
    K = input().replace("\n", "")
    D = int(input())
    
    mod = pow(10, 9)+7
    n = len(K)
    dp = [[0]*D for _ in range(n+1)]
    
    dp[0][0] = 1
    sub = 0
    
    if D == 1:
        ans = 0
        for i in range(n):
            ans = (ans*10+int(K[i]))%mod
        print(ans)
        sys.exit()


    for i in range(n):
        if i != 0:
            for j in range(10):
                for k in range(D):
                    dp[i+1][(k+j)%D] += dp[i][k]
                    dp[i+1][(k+j)%D] %= mod
            for j in range(1, 10):
                dp[i+1][j%D] += 1
                dp[i+1][j%D] %= mod
        
        
        for j in range(int(K[i])):
            if i == 0 and j == 0:
                continue
            dp[i+1][(j+sub)%D] += 1
            dp[i+1][(j+sub)%D] %= mod
        sub = (sub+int(K[i]))%D
    
    sub = 0
    for i in range(n):
        sub = (sub+int(K[i]))%D
    if sub == 0:
        dp[n][0] += 1
        dp[n][0] %= mod
        
    
    print(dp[n][0])
    
    
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [0]*n
for i in range(n):
  a[i] = int(input())

a.sort()

ans = a[-1]-a[0]
for i in range(n-k+1):
  if ans > a[i+k-1]-a[i]:
    ans = a[i+k]-a[i]

print(ans)

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

h.sort()
ans = []
for i in range(n-k+1):
    ans.append(h[i+k-1]-h[i])
print(min(ans))
Buggy python submission (verdict: Runtime Error):
def dp(a, b):
    if a == 1:
        if 1 <= b <= 4:
            return b-1
        else:
            return 3
    elif b == 1:
        return 0
    elif 1 < b < 2**(a+1)-1:
        return dp(a-1, b-1)
    elif b == 2**(a+1)-1:
        return dp(a-1, 2**(a+1)-3) + 1
    elif 2**(a+1)-1 < b < a:
        return dp(a-1, 2**(a+1)-3) + 1 + dp(a-1, b+1-2**(a+1))
    elif b == 2**(a+2)-3:
        return dp(a-1, 2**(a+1)-3) * 2 + 1
    
print(dp(n, x))

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

def dp(a, b):
    if a == 1:
        if 1 <= b <= 4:
            return b-1
        else:
            return 3
    elif b == 1:
        return 0
    elif 1 < b < 2**(a+1)-1:
        return dp(a-1, b-1)
    elif b == 2**(a+1)-1:
        return dp(a-1, 2**(a+1)-3) + 1
    elif 2**(a+1)-1 < b < 2**(a+2)-3:
        return dp(a-1, 2**(a+1)-3) + 1 + dp(a-1, b+1-2**(a+1))
    elif b == 2**(a+2)-3:
        return dp(a-1, 2**(a+1)-3) * 2 + 1
    
print(dp(n, x))

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

def dp(n):
    if n == 0:
        return ["P"]
    k = dp(n-1)
    return ["B"]+k+["P"]+k+["B"]

burger = dp(n)
burger = "".join(burger)
ans = burger[:x].count("P")
print(ans)

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

def dp(a, b):
    if a == 1:
        if 1 <= b <= 4:
            return b-1
        else:
            return 3
    elif b == 1:
        return 0
    elif 1 < b < 2**(a+1)-1:
        return dp(a-1, b-1)
    elif b == 2**(a+1)-1:
        return dp(a-1, 2**(a+1)-3) + 1
    elif 2**(a+1)-1 < b < 2**(a+2)-3:
        return dp(a-1, 2**(a+1)-3) + 1 + dp(a-1, b+1-2**(a+1))
    elif b == 2**(a+2)-3:
        return dp(a-1, 2**(a+1)-3) * 2 + 1
    
print(dp(n, x))
Buggy python submission (verdict: Runtime Error):
n = int(input())
t, a = map(int, input().split())
h = list(abs(t-0.006*int(x)-a), t for x, t in zip(input().split(), range(n)))
k = min(h)
print(k[1])

Fixed submission:
n = int(input())
t, a = map(int, input().split())
h = list((abs(t-0.006*int(x)-a), s) for x, s in zip(input().split(), range(n)))
k = min(h)
print(k[1]+1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = int(input())
b = int(input())
c = a+b
if n == 1:
    print("Hello World")
else:
    print(c)

Fixed submission:
n = int(input())
if n == 1:
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a+b)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = int(input())
b = int(input())
c = a+b
print("Hello World" if n == 1 else c)

Fixed submission:
n = int(input())
if n == 1:
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a+b)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = int(input())
b = int(input())
print("Hello World" if n == 1 else a+b)

Fixed submission:
n = int(input())
if n == 1:
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a+b)
Buggy python submission (verdict: Runtime Error):
import sys

def height(a, b, c, d, e):
    return abs(a-d)+abs(b-e)+c

n = int(input())
hint = []
q = 0
for i in range(n):
    a, b, c = map(int, input().split())
    hint.append(c, a, b)
hint.sort(reverse=True)

for i in range(101):
    for j in range(101):
        frag = True
        H = height(hint[0][1], hint[0][2], hint[0][0] i, j)
        for h in hint[1:]:
            if height(h[1], h[2], h[0], i, j) != H:
                frag = False
                break
        if frag:
            print(i, j, H)
            sys.exit()
        


Fixed submission:
import sys

def height(a, b, c, d, e):
    return abs(a-d)+abs(b-e)+c

n = int(input())
hint = []
q = 0
for i in range(n):
    a, b, c = map(int, input().split())
    hint.append([c, a, b])
hint.sort(reverse=True)

for i in range(101):
    for j in range(101):
        frag = True
        H = height(hint[0][1], hint[0][2], hint[0][0], i, j)
        for h in hint[1:]:
            if h[0] != max(-abs(h[1]-i)-abs(h[2]-j)+H,0):
                frag = False
                break
        if frag:
            print(i, j, H)
            sys.exit()

Buggy python submission (verdict: Runtime Error):
 n = int(input())
hint = []
for i in range(n):
    a, b, c = map(int, input().split())
    hint.append([a, b, c])
frag2 = False
for i in range(101):
    for j in range(101):
        ans_h = -1
        frag = False
        for k in range(n):
            a, b, c = hint[k][0], hint[k][1], hint[k][2]
            if c != 0:
                if ans_h == -1:
                    ans_h = abs(a-i)+abs(b-j)+c
                else:
                    if ans_h != abs(a-i)+abs(b-j)+c:
                        frag = True
                        break
                    else:
                        continue
        if not frag:
            answer = [i, j, ans_h]
            frag2 = True
            break
    if frag2:
        break

for i in range(3):
    print(answer[i], end=" ")

Fixed submission:
import sys

def height(a, b, c, d, e):
    return abs(a-d)+abs(b-e)+c

n = int(input())
hint = []
q = 0
for i in range(n):
    a, b, c = map(int, input().split())
    hint.append([c, a, b])
hint.sort(reverse=True)

for i in range(101):
    for j in range(101):
        frag = True
        H = height(hint[0][1], hint[0][2], hint[0][0], i, j)
        for h in hint[1:]:
            if h[0] != max(-abs(h[1]-i)-abs(h[2]-j)+H,0):
                frag = False
                break
        if frag:
            print(i, j, H)
            sys.exit()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
while True:
    if n%10 == n//10%10 == n // 100:
        print(n)
    else:
        n += 1

Fixed submission:
n = int(input())
while True:
    if n%10 == n//10%10 == n // 100:
        print(n)
        break
    else:
        n += 1
Buggy python submission (verdict: Time Limit Exceeded):
import sys

s = input()
t = input()

def replacement(word, a, b):
    return word.replace(a, "0").replace(b, a).replace("0", b)

yet_list = []
for i in range(len(s)):
    if s[i] != t[i]:
        if s[i] in yet_list:
            print("No")
            sys.exit()
        if not s[i] in yet_list:
            s = replacement(s, s[i], t[i])
            yet_list.append(s[i])
if s == t:
    print("Yes")
else:
    print("No")

Fixed submission:
import sys
s = input()
t = input()
yetlist = {}
yetlist2 = {}
for i in range(len(s)):
    if s[i] in yetlist:
        if t[i] != yetlist[s[i]]:
            print("No")
            sys.exit()
    else:
        yetlist[s[i]] = t[i]
    if t[i] in yetlist2:
        if s[i] != yetlist2[t[i]]:
            print("No")
            sys.exit()
    else:
        yetlist2[t[i]] = s[i]   
            
print("Yes")

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

def replacement(word, a, b):
    return word.replace(a, "0").replace(b, a).replace("0", b)

yet_list = []
for i in range(len(s)):
    if s[i] != t[i]:
        if not s[i] in yet_list:
            s = replacement(s, s[i], t[i])
            yet_list.append(s[i])
            yet_list.append(t[i])
if s == t:
    print("Yes")
else:
    print("No")

Fixed submission:
import sys
s = input()
t = input()
yetlist = {}
yetlist2 = {}
for i in range(len(s)):
    if s[i] in yetlist:
        if t[i] != yetlist[s[i]]:
            print("No")
            sys.exit()
    else:
        yetlist[s[i]] = t[i]
    if t[i] in yetlist2:
        if s[i] != yetlist2[t[i]]:
            print("No")
            sys.exit()
    else:
        yetlist2[t[i]] = s[i]   
            
print("Yes")

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

def replacement(word, a, b):
    return word.replace(a, "0").replace(b, a).replace("0", b)

yet_list = []
for i in range(len(s)):
    if s[i] != t[i]:
        if not s[i] in yet_list:
            s = replacement(s, s[i], t[i])
            yet_list.append(s[i])
if s == t:
    print("Yes")
else:
    print("No")

Fixed submission:
import sys
s = input()
t = input()
yetlist = {}
yetlist2 = {}
for i in range(len(s)):
    if s[i] in yetlist:
        if t[i] != yetlist[s[i]]:
            print("No")
            sys.exit()
    else:
        yetlist[s[i]] = t[i]
    if t[i] in yetlist2:
        if s[i] != yetlist2[t[i]]:
            print("No")
            sys.exit()
    else:
        yetlist2[t[i]] = s[i]   
            
print("Yes")
Buggy python submission (verdict: Runtime Error):
print("Yes" if i%2==1 for i in [map(int, input().split())] else "No")

Fixed submission:
a, b = map(int, input().split())
if a%2==1 and b%2==1:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
yetlist = []
for i in range(n):
    word = input()
    if word in yetlist:
        print("No")
        sys.exit()
    if word[0] != yetlist[-1][-1]:
        print("No")
        sys.exit()
    yetlist.append(word)
print("Yes")

Fixed submission:
import sys
n = int(input())
yetlist = []
for i in range(n):
    word = input()
    if word in yetlist:
        print("No")
        sys.exit()
    if yetlist:
        if word[0] != yetlist[-1][-1]:
            print("No")
            sys.exit()
    yetlist.append(word)
print("Yes")
Buggy python submission (verdict: Runtime Error):
from math import gcd
n, x = map(int, input().split())
x_list = [abs(int(i)-x) for i in input().split()]
a = x_list[0]
for i in range(1, n):
    a = gcd(a, x_list[i])
print(a)

Fixed submission:
def gcd(p, q):
    if p < q:
        p, q = q, p
    while q > 0:
        p, q = q, p%q
    return p
n, x = map(int, input().split())
x_list = [abs(int(i)-x) for i in input().split()]
a = x_list[0]
for i in range(1, n):
    a = gcd(a, x_list[i])
print(a)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
x = list(int(i) for i in input().split())
inf = 10**9
max_x = x[-1]
min_x = x[1]
if min_x >= 0:
    print(x[k-1])
elif max_x <= 0:
    print(x[-k])
else:
    for i in range(n-1):
        if x[i]<0 and x[i+1]>=0:
            key = i+1
            break
    if n-key>=k:
        ans1 = sum(x[key:key+k])
    else:
        ans1 = inf
    if key>=k:
        ans2 = abs(sum(x[key-k:key]))
    else:
        ans2 = inf
    ans3 = inf
    for i in range(max(0, key-k+1), min(n-k, key+k-1)):
        a, b = abs(x[i]), abs(x[i+k-1])
        t = max([a, b])+min([a, b])*2
        if t < ans3:
            ans3 = t
    print(min([ans1, ans2, ans3]))

Fixed submission:
n, k = map(int, input().split())
x = list(int(i) for i in input().split())
inf = 10**9
max_x = x[-1]
min_x = x[0]
if min_x >= 0:
    print(x[k-1])
elif max_x <= 0:
    print(abs(x[-k]))
else:
    for i in range(n-1):
        if x[i]<0 and x[i+1]>=0:
            key = i+1
            break
    if n-key>=k:
        ans1 = sum(x[key:key+k])
    else:
        ans1 = inf
    if key>=k:
        ans2 = abs(sum(x[key-k:key]))
    else:
        ans2 = inf
    ans3 = inf
    for i in range(max(0, key-k+1), min(n-k+1, key+k-1)):
        a, b = abs(x[i]), abs(x[i+k-1])
        t = max([a, b])+min([a, b])*2
        if t < ans3:
            ans3 = t
    print(min([ans1, ans2, ans3]))