Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, K, L = map(int, input().split())

class UnionFind():
  def __init__(self):
    self.par = [i for i in range(N)]

  def root(self, x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] = self.root(self.par[x])
      return self.par[x]
  
  def unite(self, x, y):
    x = self.root(x)
    y = self.root(y)
    self.par[y] = x

ufRoad = UnionFind()

for i in range(K):
  p, q = map(int, input().split())
  ufRoad.unite(p-1, q-1)

ufRail = UnionFind()

for i in range(L):
  r, s = map(int, input().split())
  ufRail.unite(r-1, s-1)

SRoad = [set() for i in range(N)]
SRail = [set() for i in range(N)]

for i in range(N):
  ufRoad.root(i)
  ufRail.root(i)

for i in range(N):
  SRoad[ufRoad.par[i]].add(i)
  SRail[ufRail.par[i]].add(i)

r = [0] * N
for i in range(N):
  r[i] = len(SRoad[ufRoad.par[i]] & SRail[ufRail.par[i]])

print(*r)

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

class UnionFind():
  def __init__(self):
    self.par = [i for i in range(N)]

  def root(self, x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] = self.root(self.par[x])
      return self.par[x]
  
  def unite(self, x, y):
    self.par[self.root(y)] = self.root(x)

ufRoad = UnionFind()

for i in range(K):
  p, q = map(int, input().split())
  ufRoad.unite(p-1, q-1)

ufRail = UnionFind()

for i in range(L):
  r, s = map(int, input().split())
  ufRail.unite(r-1, s-1)

d = {}

for i in range(N):
  d[(ufRoad.root(i), ufRail.root(i))] = d.get((ufRoad.root(i), ufRail.root(i)), 0) + 1

r = [0] * N

for i in range(N):
  r[i] = d.get((ufRoad.root(i), ufRail.root(i)))

print(*r)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
T, A = 1, 1
for i in range(N):
  t, a = map(int, input().split())
  i = 1
  while t * i < T or a * i < A:
    i += 1
  T = t * i
  A = a * i
print(T + A)

Fixed submission:
def ceil(a, b):
  return a // b + (a % b > 0)

N = int(input())
T = A = 1
for i in range(N):
  t, a = map(int, input().split())
  m = max(ceil(T, t), ceil(A, a))
  T = t * m
  A = a * m
print(T + A)
Buggy python submission (verdict: Runtime Error):
a,b = input().split()
a = int(a)
c = []

c = input().split()

for i in range(int(b)):
	a-=int(c[i])

if(a>=0):
		print (a)
else:
	print("-1")


Fixed submission:
r = int(input())

print(r*2*3.141592)
Buggy python submission (verdict: Runtime Error):
s = input()
a = s[len(s)-1]

if a == "2" or a == "4" or a == "5" or a == "7" or a == "9":
    print("hon)
elif a == "0" or a == "1" or a == "6" or a == "8":
    print("pon")
else:
    print("bon")

Fixed submission:
s = input()
a = s[len(s)-1]

if a == "2" or a == "4" or a == "5" or a == "7" or a == "9":
    print("hon")
elif a == "0" or a == "1" or a == "6" or a == "8":
    print("pon")
else:
    print("bon")

Buggy python submission (verdict: Runtime Error):
import math
# 時針の速度
# 360度/720分 = 1/2度/m
# 分針の速度
# 360度/60分 = 6度/m
# 時針と分針の度数は両者を減算したものの絶対値
# 使用するのは余弦定理

# def str_to_int(str_num):
#     int_num = int(str_num)
#     return int_num


line = input().split(' ')
# int_line = list(map(lambda str_num: int(str_num), line))
int_line = [int(str_num) for str_num in line]
# print(int_line)

# 時針の進行角度
# radian_h =　(H * 60 + M) * 0.5
# radian_m = M * 6

# 時針と分針の角度
degree = abs((int_line[2] * 60 + int_line[3]) * 0.5 - int_line[3] * 6)

# 分針と時針の末端同士の距離
distance_squared = int_line[0] ** 2 + int_line[1] ** 2 - 2 * \
    int_line[0] * int_line[1] * math.cos(math.radians(degree))

distance = math.sqrt(distance_squared)

print(distance)


Fixed submission:
num = input()
if num.isdecimal():
    if int(num) <= 999:
        first_class_num = int(num[-1])
        if first_class_num in {2, 4, 5, 7, 9}:
            print("hon")
        elif first_class_num in {0, 1, 6, 8}:
            print("pon")
        elif first_class_num is 3:
            print("bon")

Buggy python submission (verdict: Runtime Error):
import math
# 時針の速度
# 360度/720分 = 1/2度/m
# 分針の速度
# 360度/60分 = 6度/m
# 時針と分針の度数は両者を減算したものの絶対値
# 使用するのは余弦定理

# def str_to_int(str_num):
#     int_num = int(str_num)
#     return int_num


line = input().split(' ')
# int_line = list(map(lambda str_num: int(str_num), line))
int_line = [int(str_num) for str_num in line]
print(int_line)

# 時針の進行角度
# radian_h =　(H * 60 + M) * 0.5
# radian_m = M * 6

# 時針と分針の角度
degree = abs((int_line[2] * 60 + int_line[3]) * 0.5 - int_line[3] * 6)

# 分針と時針の末端同士の距離
distance_squared = int_line[0] ** 2 + int_line[1] ** 2 - 2 * \
    int_line[0] * int_line[1] * math.cos(math.radians(degree))

distance = math.sqrt(distance_squared)

# print(distance)


Fixed submission:
num = input()
if num.isdecimal():
    if int(num) <= 999:
        first_class_num = int(num[-1])
        if first_class_num in {2, 4, 5, 7, 9}:
            print("hon")
        elif first_class_num in {0, 1, 6, 8}:
            print("pon")
        elif first_class_num is 3:
            print("bon")
Buggy python submission (verdict: Runtime Error):
k = input()
s = input()

if s > len(str(k)):
  print(s)
else:
  print(s[k:] + '...')

Fixed submission:
k = int(input())
s = input()
 
if len(str(s)) <= k:
  print(s)
else:
  print(s[:k] + '...')
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
u = t.rstip(t[len(t) - 1])
out = ('No', 'Yes')[s == u]
print(out)

Fixed submission:
s = input()
t = input()
u = t[:-1]
out = ('No', 'Yes')[s == u]
print(out)
Buggy python submission (verdict: Runtime Error):
a, b, c, k = map(int, input().split())
if k < a:
  out = k
elif k > a:
  out = a
if k > (a + b):
  out += (k - a - b) * (-1)
print(out)

Fixed submission:
a, b, c, k = map(int, input().split())
out = 0
if k < a:
  out = k
elif k >= a:
  out = a
if k > (a + b):
  out += (k - a - b) * (-1)
print(out)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(range(N))
for i in range(N):
    a[i] = int(input())
a = a.sort()
p = 1
for i in range(N - 1):
    if a[i + 1] - a[i] != 0:
        p += 1
print(p)

Fixed submission:
N = int(input())
a = list(range(N))
for i in range(N):
    a[i] = int(input())
a.sort()
p = 1
for i in range(N - 1):
    if a[i + 1] - a[i] != 0:
        p += 1
print(p)
Buggy python submission (verdict: Runtime Error):
 = map(int, input().split())
for i in range(n + 1):
  for ii in range(n - i + 1):
    if 10000 * i + 5000 * ii + 1000 * (n - i - ii) == y:
      print('{} {} {}'.format(i, ii, n - i - ii))
      exit()
print('-1 -1 -1')

Fixed submission:
n, y = map(int, input().split())
for i in range(n + 1):
  for ii in range(n - i + 1):
    if 10000 * i + 5000 * ii + 1000 * (n - i - ii) == y:
      print('{} {} {}'.format(i, ii, n - i - ii))
      exit()
print('-1 -1 -1')
Buggy python submission (verdict: Runtime Error):
# 数値の入力
a, b, c = map(int, input().split())
if a < 0 or b < 0 or c < 0:
    print("false")
if a > 1 or b > 1 or c > 1:
    print("false")
else:
    print("{}".format(a+b+c))


Fixed submission:
s = input()
print(int(s[0]) + int(s[1]) + int(s[2]))
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())

if h == 1 or w == 1:
    print(1)
    exit()

if h * w % 2 == 0:
    print(h * w // 2)
else:
    print((h * w)//2 + 1)


Fixed submission:
k = int(input()) - 1
li = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(li[k])
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
 
now = 1
ans = 0
match = 0
chuumoku = 0
for i in range(n):
    if a[chuumoku] != now:
        ans += 1
        a.pop(chuumoku)
    else:
        match += 1
        chuumoku += 1
        now += 1
 
    if chuumoku == len(a) and match == 0:
        print(-1)
        exit(0)
 
print(ans)

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

ans = [1, 2, 3]

ans.remove(a)
ans.remove(b)

print(ans[0])
Buggy python submission (verdict: Runtime Error):
A = list(map(int, input().split()))
    a1, a2, a3 = A
    if a1 + a2 + a3 >= 22:
        print('bust')
    else:
        print('win')

Fixed submission:
A = list(map(int, input().split()))
a1, a2, a3 = A
if a1 + a2 + a3 >= 22:
  print('bust')
else:
  print('win')
Buggy python submission (verdict: Runtime Error):
s = input()

if s == 'SUN':
  return 7
elif s == 'MON':
  return 6
elif s == 'TUE':
  return 5
elif s == 'WED':
  return 4
elif s == 'THU':
  return 3
elif s == 'FRI':
  return 2
else s == 'SAT':
  return 1

Fixed submission:
s = input()
if s == 'SUN':
  print(7)
elif s == 'MON':
  print(6)
elif s == 'TUE':
  print(5)
elif s == 'WED':
  print(4)
elif s == 'THU':
 print(3)
elif s == 'FRI':
  print(2)
else:
  print(1)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))

INF = 10**12
dp = [INF] * n
dp[0] = 0

for i in range(n):
    if i == 1:
        dp[1] = abs(h[1] - h[0])
        continue

    for j in range(1, k + 1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print(dp[-1])


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

INF = 10**12
dp = [INF] * n
dp[0] = 0

for i in range(n):
    if i == 1:
        dp[1] = abs(h[1] - h[0])
        continue

    for j in range(1, k + 1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, sum_w = map(int, input().split())
weight = []
value = []
for i in range(n):
    w, v = map(int, input().split())
    weight.append(w)
    value.append(v)

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

for i in range(n):
    for j in range(sum_w + 1):
        if j < weight[i]:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - weight[i]] + value[i])

print(dp[-1][-1])


Fixed submission:
n, sum_w = map(int, input().split())
weight = []
value = []
for i in range(n):
    w, v = map(int, input().split())
    weight.append(w)
    value.append(v)

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

for i in range(n):
    for j in range(sum_w + 1):
        if j < weight[i]:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - weight[i]] + value[i])

print(dp[-1][-1])
Buggy python submission (verdict: Runtime Error):
a_card = list(input())
b_card = list(input())
c_card = list(input())

turn = 'a'
while True:
    if turn == 'a':
        turn = a_card.pop(0)
        print(a_card, b_card, c_card)
        if len(a_card) == 0:
            print('A')
            exit()
    elif turn == 'b':
        turn = b_card.pop(0)
        print(a_card, b_card, c_card)
        if len(a_card) == 0:
            print('B')
            exit()
    else:
        turn = c_card.pop(0)
        print(a_card, b_card, c_card)
        if len(a_card) == 0:
            print('C')
            exit()


Fixed submission:
a_card = list(input())
b_card = list(input())
c_card = list(input())

turn = 'a'
while True:
    if turn == 'a':
        if len(a_card) == 0:
            print('A')
            exit()
        turn = a_card.pop(0)

    elif turn == 'b':
        if len(b_card) == 0:
            print('B')
            exit()
        turn = b_card.pop(0)

    else:
        if len(c_card) == 0:
            print('C')
            exit()
        turn = c_card.pop(0)
Buggy python submission (verdict: Runtime Error):
nm = list(map(int,input().split()))
n = nm[0]
m = nm[1]
a = []
b = []
for i in range(0, m):
    ab = list(map(int,input().split()))
    a.append(ab[0])
    b.append(ab[1])
signs = [0]*(n+1)
signs[1]=-1
now = [1]
nexx = []
while True:
    for i in now:
        for j in range(0,m):
            if a[j] == i:
                if signs[b[j]] == 0:
                    signs[b[j]] = i
                    nexx.append(b[j])
            elif b[j] == i:
                if signs[a[j]] == 0:
                    signs[a[j]] = i
                    nexx.append(a[j])
    now=nexx.copy()
    if len(nexx)==0:
        break
    nexx = []
flag = 0
for i in range(2, n+1):
    if signs[i]==0:
        print("No")
        flag = 1
        break
if flag == 0:
    print("Yes")
    for k in range(2,n+1):
        print(signs[k])



Fixed submission:
n = int(input())
rem = n%10
if rem == 3:
  print("bon")
elif rem == 0 or rem == 1 or rem == 6 or rem == 8:
  print("pon")
else:
  print("hon")

Buggy python submission (verdict: Runtime Error):
nm = list(map(int,input().split()))
n = nm[0]
m = nm[1]
a = []
b = []
for i in range(0, m):
    ab = list(map(int,input().split()))
    a.append(ab[0])
    b.append(ab[1])
signs = [0]*(n+1)
signs[1]=-1
now = [1]
nexx = []
while True:
    for i in now:
        for j in range(0,m):
            if a[j] == i:
                if signs[b[j]] == 0:
                    signs[b[j]] = i
                    nexx.append(b[j])
            elif b[j] == i:
                if signs[a[j]] == 0:
                    signs[a[j]] = i
                    print("signs=",signs)
                    nexx.append(a[j])
    now=nexx.copy()
    if len(nexx)==0:
        break
    nexx = []
flag = 0
for i in range(2, n+1):
    if signs[i]==0:
        print("No")
        flag = 1
        break
if flag == 0:
    print("Yes")
    for k in range(2,n+1):
        print(signs[k])



Fixed submission:
n = int(input())
rem = n%10
if rem == 3:
  print("bon")
elif rem == 0 or rem == 1 or rem == 6 or rem == 8:
  print("pon")
else:
  print("hon")
Buggy python submission (verdict: Time Limit Exceeded):
nm = list(map(int,input().split()))
n = nm[0]
m = nm[1]
a = []
b = []
for i in range(0, m):
    ab = list(map(int,input().split()))
    a.append(ab[0])
    b.append(ab[1])
signs = [0]*(n+1)
signs[1]=-1
now = [1]
nexx = []
while True:
    for i in now:
        for j in range(0,m):
            if a[j] == i:
                if signs[b[j]] == 0:
                    signs[b[j]] = i
                    nexx.append(b[j])
            elif b[j] == i:
                if signs[a[j]] == 0:
                    signs[a[j]] = i
                    nexx.append(a[j])
    now=nexx.copy()
    if len(nexx)==0:
        break
    nexx = []
flag = 0
for i in range(2, n+1):
    if signs[i]==0:
        print("No")
        flag = 1
        break
if flag == 0:
    print("Yes")
    for k in range(2,n+1):
        print(signs[k])



Fixed submission:
n, m = map(int,input().split())
graph = {}
for i in range(0, m):
    am, bm = map(int, input().split())
    if am not in graph:
        graph[am] = [bm]
    else:
        graph[am].append(bm)
    if bm not in graph:
        graph[bm] = [am]
    else:
        graph[bm].append(am)
signs = {1:0}
current = [1]
i = 0
while True:
    flag = 0
    for j in graph[current[i]]:
        if j not in signs:
            signs[j] = current[i]
            current.append(j)
            flag = 1
    i+=1
    if flag == 0 and i == len(current):
        break
    
if i == n:
    print("Yes")
    for x in range(2, n+1):
        print(signs[x])
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


def list_gcd(a):
    a_gcd = a[0]
    for i in range(n-1):
        a_gcd = gcd(a_gcd, a[i+1])
    return a_gcd


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0

for i in range((n+1)//2):
    b = a[:]
    b[i] = b[i-1]
    ans = max(ans, list_gcd(b))

print(ans)

Fixed submission:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


n = int(input())
a = list(map(int, input().split()))
a = [0]+a[:]+[0]

l = [0]*len(a)
r = [0]*len(a)

for i in range(len(a)-1):
    m = len(a)-1
    l[i+1] = gcd(l[i], a[i+1])
    r[m-i-1] = gcd(r[m-i], a[m-i-1])

ans = [0]*n

for i in range(n):
    ans[i] = gcd(l[i], r[i+2])

print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


def list_gcd(a):
    a_gcd = a[0]
    for i in range(n-1):
        a_gcd = gcd(a_gcd, a[i+1])
    return a_gcd


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

ans = 0

for i in range(n):
    b = a[:]
    b[i] = b[i-1]
    ans = max(ans, list_gcd(b))

print(ans)

Fixed submission:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


n = int(input())
a = list(map(int, input().split()))
a = [0]+a[:]+[0]

l = [0]*len(a)
r = [0]*len(a)

for i in range(len(a)-1):
    m = len(a)-1
    l[i+1] = gcd(l[i], a[i+1])
    r[m-i-1] = gcd(r[m-i], a[m-i-1])

ans = [0]*n

for i in range(n):
    ans[i] = gcd(l[i], r[i+2])

print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
b = [[]*2 for _ in range(q)]
for i in range(q):
    b[i] = list(map(int, input().split()))

for i in range(q):
    count = 0
    start = b[i][0]-1
    end = b[i][1]-1
    for j in range(start, end):
        if s[j:j+2] == "AC":
            count += 1
    print(count)

Fixed submission:
n, q = map(int, input().split())
s = list(input())
b = [[]*2 for _ in range(q)]
for i in range(q):
    b[i] = list(map(int, input().split()))

c = [0 for _ in range(len(s))]
count = 0

for i in range(len(s)):
    if s[i:i+2] == ["A", "C"]:
        count += 1
        c[i:i+2] = [count-1, count]
    else:
        c[i:i+2] = [count, count]

for i in range(q):
    start = b[i][0]-1
    end = b[i][1]-1
    ans = c[end] - c[start]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())

ans = A

for i in range(A+1, B+1):

    ans = ans ^ i

print(ans)

Fixed submission:
def f(n):
    x = n // 2

    if n % 2 == 0:
        if x % 2 == 0:
            return 0 ^ n
        else:
            return 1 ^ n

    else:
        x += 1
        if x % 2 == 0:
            return 0
        else:
            return 1


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

print(f(A-1) ^ f(B))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

if len(set(a)) == 1:
    print(a[0])
else:
    a.sort()
    for i in range(1, 10 ^ 9+1):
        count = i
        for i in range(1, len(a)):
            x = a[i] + count
            for j in range(i):
                x = x % a[i-1-j]
        if x == 0:
            break

    print(count)


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


def gcd(a, b):
    if a <= b:
        if b % a == 0:
            return a
        else:
            return(gcd(b % a, a))
    else:
        if a % b == 0:
            return b
        else:
            return(gcd(a % b, b))


ans = gcd(a[0], a[1])

for i in range(2, len(a)):
    ans = gcd(ans, a[i])

print(ans)

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

if len(set(a)) == 1:
    print(a[0])
else:
    a.sort()
    count = 0
    while(1):
        count = count + 1
        for i in range(1, len(a)):
            x = a[i] + count
            for j in range(i):
                x = x % a[i-1-j]
        if x == 0:
            break

    print(count)


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


def gcd(a, b):
    if a <= b:
        if b % a == 0:
            return a
        else:
            return(gcd(b % a, a))
    else:
        if a % b == 0:
            return b
        else:
            return(gcd(a % b, b))


ans = gcd(a[0], a[1])

for i in range(2, len(a)):
    ans = gcd(ans, a[i])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import functools
import numpy as np

n, X = map(int, input().split())
x = list(map(int, input().split()))

x.append(X)
x = np.array(x)
min_x = np.array([min(x) for _ in range(n+1)])
x = (sorted(x) - min_x)[1:]


def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a % b)


if n > 1:
    ans = euclid(x[0], x[1])


    for xi in x[2:]:
        ans = euclid(ans, xi)
        if ans == 1:
            break

else:
    ans = x[0]

print(ans)


Fixed submission:
import functools
import numpy as np

n, X = map(int, input().split())
x = list(map(int, input().split()))


def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a % b)


if n > 1:
    if abs(x[0]-X) == 0:
        ans = euclid(abs(x[1]-X), abs(x[2]-X))
    elif abs(x[1]-X) == 0:
        ans = euclid(abs(x[0]-X), abs(x[2]-X))
    else:
        ans = euclid(abs(x[0]-X), abs(x[1]-X))

    for xi in x[2:]:
        ans = euclid(ans, abs(xi-X))
        if ans == 1:
            break

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import functools
import numpy as np

n, X = map(int, input().split())
x = list(map(int, input().split()))

x.append(X)
x = np.array(x)
min_x = np.array([min(x) for _ in range(n+1)])
x = (sorted(x) - min_x)[1:]


def gcd(nums):
    return functools.reduce(euclid, nums)


def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a % b)


print(gcd(x))


Fixed submission:
import functools
import numpy as np

n, X = map(int, input().split())
x = list(map(int, input().split()))


def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a % b)


if n > 1:
    if abs(x[0]-X) == 0:
        ans = euclid(abs(x[1]-X), abs(x[2]-X))
    elif abs(x[1]-X) == 0:
        ans = euclid(abs(x[0]-X), abs(x[2]-X))
    else:
        ans = euclid(abs(x[0]-X), abs(x[1]-X))

    for xi in x[2:]:
        ans = euclid(ans, abs(xi-X))
        if ans == 1:
            break

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import functools
import numpy as np

n, X = map(int, input().split())
x = list(map(int, input().split()))

x.append(X)
x = np.array(x)
min_x = np.array([min(x) for _ in range(n+1)])
x = (sorted(x) - min_x)[1:]


def gcd(nums):
    return functools.reduce(euclid, nums)


def euclid(a, b):
    while b:
        a, b = b, a % b
    return a


print(gcd(x))


Fixed submission:
import functools
import numpy as np

n, X = map(int, input().split())
x = list(map(int, input().split()))


def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a % b)


if n > 1:
    if abs(x[0]-X) == 0:
        ans = euclid(abs(x[1]-X), abs(x[2]-X))
    elif abs(x[1]-X) == 0:
        ans = euclid(abs(x[0]-X), abs(x[2]-X))
    else:
        ans = euclid(abs(x[0]-X), abs(x[1]-X))

    for xi in x[2:]:
        ans = euclid(ans, abs(xi-X))
        if ans == 1:
            break

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

print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = map(int(input()))

if abs(a-b) < 2:
    print("Yay!")
else:
    printa, b = map(int, input().split())

if abs(a-b) < 2:
    print("Yay!")
else:
    print(":(")

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

if abs(a-b) < 2:
    print("Yay!")
else:
    print(":(")

Buggy python submission (verdict: Runtime Error):
a, b = map(int(input()))

if abs(a-b) < 2:
    print("Yay!")
else:
    print(":(")

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

if abs(a-b) < 2:
    print("Yay!")
else:
    print(":(")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
ans = n
for i in range(n):
    if i == 0:
        ans = min(ans, s[1:].count("E"))
    elif i == n-1:
        ans = min(ans, s[:n-2].count("W"))
    else:
        ans = min(ans, s[:i-1].count("W")+s[i+1:].count("E"))
print(ans)


Fixed submission:
n = int(input())
s = list(input())
w = [0] * (n+1)
e = [0] * (n+1)
ans = n
for i in range(n):
    if s[i] == "W":
        w[i+1] = w[i] + 1
    else:
        w[i+1] = w[i]

for i in range(n-1, -1, -1):
    if s[i] == "E":
        e[i] = e[i+1] + 1
    else:
        e[i] = e[i+1]

for i in range(1, n+1):
    ans = min(ans, w[i-1]+e[i])
print(ans)