Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if S[i] != S[j] and S[j] != S[k] and S[i] != S[k] and j-i != k-j:
                ans += 1
print(ans)


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

U = S.count('R') * S.count('G') * S.count('B')

for i in range(N):
    for j in range(i+1, N):
        k = 2 * j - i
        if k >= N:
            break
        elif S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            U -= 1
print(U)
Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y = map(int, input().split())
ans = []
for i in range(1, N+1):
    for j in range(i+1, N+1):
        # 使わない場合
        a = abs(j - i)
        # 使う場合
        b = abs(i - X) + abs(j - Y) + 1
        ans.append(min(a, b))
for i in range(1, N):
    print(ans.count(i))


Fixed submission:
N, X, Y = map(int, input().split())
ans = [0]*(N-1)
for i in range(1, N+1):
    for j in range(i+1, N+1):
        # 使わない場合
        a = abs(j - i)
        # 使う場合
        b = abs(i - X) + abs(j - Y) + 1
        ans[(min(a, b))-1] += 1
for i in ans:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import collections


def P(n, r):
    return math.factorial(n)//math.factorial(n-r)


def C(n, r):
    if n < 2:
        return 0
    else:
        return P(n, r)//math.factorial(r)


N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
dic = {}
total = 0
for key, value in c.items():
    C_val = C(value, 2)
    dic[key] = C_val
    total += C_val
for i in range(N):
    print(total - dic.get(A[i]) + C(c[A[i]]-1, 2))


Fixed submission:
import math
import collections


def C(n, r):
    if n < 2:
        return 0
    else:
        return n*(n-1)//r


N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
dic = {}
total = 0
for key, value in c.items():
    C_val = C(value, 2)
    dic[key] = C_val
    total += C_val
for i in range(N):
    print(total - dic.get(A[i]) + C(c[A[i]]-1, 2))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))
index = 0
num = 0
ans = 0
for i in range(N-K+1):
    tmp = sum(p[i:i+K])
    if num < tmp:
        index = i
        num = tmp
for i in range(index, index+K):
    ans += 0.5*p[i]*(p[i]+1)/p[i]
print(ans)


Fixed submission:
N, K = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
dp = [0]*N
dp[0] = sum(p[:K])
for i in range(N-K):
    dp[i+1] = dp[i] - p[i] + p[i+K]
index = dp.index(max(dp))
for i in range(index, index+K):
    ans += 0.5*p[i]*(p[i]+1)/p[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))
index = 0
ans = 0
for i in range(N-K+1):
    if sum(p[index:index+K]) < sum(p[i:i+K]):
        index = i
for i in range(index, index+K):
    ans += 0.5*p[i]*(p[i]+1)/p[i]
print(ans)


Fixed submission:
N, K = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
dp = [0]*N
dp[0] = sum(p[:K])
for i in range(N-K):
    dp[i+1] = dp[i] - p[i] + p[i+K]
index = dp.index(max(dp))
for i in range(index, index+K):
    ans += 0.5*p[i]*(p[i]+1)/p[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


N = int(input())
A = list(map(int, input().split()))
l = A[0]
mod = 10**9+7
ans = 0
for i in range(1, N):
    l = lcm(l, A[i])
for i in range(N):
    ans += l // A[i]
print(ans % mod)


Fixed submission:
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


N = int(input())
A = list(map(int, input().split()))
l = A[0]
mod = 10**9+7
ans = 0
for i in range(1, N):
    l = lcm(l, A[i])
for i in range(N):
    ans += l // A[i]
print(ans % mod)
Buggy python submission (verdict: Runtime Error):
N = int(input())
lis = []
for a in range(1,int(N**0.5)):
    b = N // a
    if a * b == N:
       lis.append(a + b - 2)
print(min(lis)) 

Fixed submission:
N = int(input())
lis = []
for a in range(1,int(N**0.5)+1):
    b = N // a
    if a * b == N:
       lis.append(a + b - 2)
print(min(lis))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N = int(input())
l = list(map(int, input().split()))
L = list(itertools.combinations(l,3))
ans = 0
for a, b, c in L:
    if a < b + c and b < c + a and c < a + b:
        ans += 1
print(ans)

Fixed submission:
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += bisect_left(L, L[i]+L[j])-j-1
print(ans)
Buggy python submission (verdict: Runtime Error):
import fractions

def calc_factors(n):
    i = 2
    f = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            f.append(i)
    if n > 1:
        f.append(n)
return f

A, B = map(int, input().split())
print(max(1,len(calc_factors(fractions.gcd(A,B)))))

Fixed submission:
import fractions

def calc_factors(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n /= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n /= f
        else:
            f += 2   
    if n != 1: 
        a.append(n)
    return a

A, B = map(int, input().split())
g = fractions.gcd(A,B)
if g == 1:
    print(1)
else:
    print(len(set(calc_factors(g)))+1)

Buggy python submission (verdict: Runtime Error):
import math

def calc_factors(n):
    i = 2
    f = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            f.append(i)
    if n > 1:
        f.append(n)
    return f

A, B = map(int, input().split())
print(max(1,len(calc_factors(math.gcd(A,B)))))

Fixed submission:
import fractions

def calc_factors(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n /= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n /= f
        else:
            f += 2   
    if n != 1: 
        a.append(n)
    return a

A, B = map(int, input().split())
g = fractions.gcd(A,B)
if g == 1:
    print(1)
else:
    print(len(set(calc_factors(g)))+1)

Buggy python submission (verdict: Runtime Error):
import math
import collections

def calc_factors(n):
    i = 2
    f = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            f.append(i)
    if n > 1:
        f.append(n)
    return f

A, B = map(int, input().split())
print(max(1,len(calc_factors(math.gcd(A,B)))))

Fixed submission:
import fractions

def calc_factors(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n /= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n /= f
        else:
            f += 2   
    if n != 1: 
        a.append(n)
    return a

A, B = map(int, input().split())
g = fractions.gcd(A,B)
if g == 1:
    print(1)
else:
    print(len(set(calc_factors(g)))+1)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
top, bottom = 0, M-1

if len(A) == 1:
    for _ in range(M):
        A[0] //= 2
else:
    for _ in range(M):
        A[top] //= 2
        if A[top] >= A[bottom]:
            if bottom > top >= 0:
                bottom -= 1
            continue
        else:
            top += 1
print(sum(A))

Fixed submission:
import heapq
N, M = map(int, input().split())
heap = [-i for i in list(map(int, input().split()))]
heapq.heapify(heap)
for i in range(M):
    heapq.heappush(heap, -(-heapq.heappop(heap)//2))
print(-sum(heap))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
top, bottom = 0, M-1

if len(A) == 1:
    for _ in range(M):
        A[0] //= 2
else:
    for _ in range(M):
        A[top] //= 2
        if A[top] >= A[bottom]:
            if bottom >= top >= 0:
                bottom -= 1
            continue
        else:
            top += 1
print(sum(A))

Fixed submission:
import heapq
N, M = map(int, input().split())
heap = [-i for i in list(map(int, input().split()))]
heapq.heapify(heap)
for i in range(M):
    heapq.heappush(heap, -(-heapq.heappop(heap)//2))
print(-sum(heap))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
top, bottom = 0, M-1

if len(A) == 1:
    for _ in range(M):
        A[0] //= 2
else:
    for _ in range(M):
        A[top] //= 2
        if A[top] >= A[bottom]:
            bottom -= 1
            continue
        else:
            top += 1
print(sum(A))

Fixed submission:
import heapq
N, M = map(int, input().split())
heap = [-i for i in list(map(int, input().split()))]
heapq.heapify(heap)
for i in range(M):
    heapq.heappush(heap, -(-heapq.heappop(heap)//2))
print(-sum(heap))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
top, bottom = 0, M-1

if len(A) == 1:
    for _ in range(M):
        A[0] //= 2
else:
    for _ in range(M):
        A[top] //= 2
        print(top, bottom)
        if A[top] >= A[bottom]:
            bottom -= 1
            continue
        else:
            top += 1
print(sum(A))

Fixed submission:
import heapq
N, M = map(int, input().split())
heap = [-i for i in list(map(int, input().split()))]
heapq.heapify(heap)
for i in range(M):
    heapq.heappush(heap, -(-heapq.heappop(heap)//2))
print(-sum(heap))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
for i in reversed(range(M)):
    bisect.insort(A, A.pop(-1)//2)
print(sum(A))

Fixed submission:
import heapq
N, M = map(int, input().split())
heap = [-i for i in list(map(int, input().split()))]
heapq.heapify(heap)
for i in range(M):
    heapq.heappush(heap, -(-heapq.heappop(heap)//2))
print(-sum(heap))
Buggy python submission (verdict: Time Limit Exceeded):
import collections
N = int(input())
lis = []
ans = 0

for i in range(N):
    lis.append("".join(sorted(input())))

for i in set(lis): 
    n = lis.count(i) - 1
    ans += int(0.5*n*(n+1))
print(ans)

Fixed submission:
import collections
N = int(input())
l = []
ans = 0

for i in range(N):
    l.append("".join(sorted(input())))

for v in (collections.Counter(l)).values():
    v -= 1
    ans += int(0.5*v*(v+1))

print(ans)
Buggy python submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())
# ansx = min([(W-x)*H,x*H])
# ansy = min([(H-y)*W,y*W])
if W/2 == y or H/2 == x or (W%x ==0 and H%y==0):
    print(W*H//2,1)
else:
    # print(max(ansx,ansy),0)
    print(W*H//2,0)

Fixed submission:
W, H, x, y = map(float, input().split())
if x == W/2 and y == H/2:
    print(W*H/2,1)
else:
    print(W*H/2,0)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
dp = [0]*(N+1)
dp[0] = 1
for i in range(1,N+1):
    if i in A:
        dp[i] = 0
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % (10**9+7)
print(dp[N])

Fixed submission:
N, M = map(int, input().split())
A = set([int(input()) for _ in range(M)])
dp = [0]*(N+1)
dp[0] = 1
for i in range(1,N+1):
    if i in A:
        dp[i] = 0
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % (10**9+7)
print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
dp = [0]*(N+1)
dp[0] = 1
for i in range(1,N+1):
    if i in A:
        dp[i] = 0
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % 1000000007
print(dp[N])

Fixed submission:
N, M = map(int, input().split())
A = set([int(input()) for _ in range(M)])
dp = [0]*(N+1)
dp[0] = 1
for i in range(1,N+1):
    if i in A:
        dp[i] = 0
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % (10**9+7)
print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
dp = [0]*(N+1)
dp[0] = 1
for i in range(1,N+1):
    if i in A:
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]
print(dp[N]%1000000007)

Fixed submission:
N, M = map(int, input().split())
A = set([int(input()) for _ in range(M)])
dp = [0]*(N+1)
dp[0] = 1
for i in range(1,N+1):
    if i in A:
        dp[i] = 0
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % (10**9+7)
print(dp[N])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
L = []
R = []
ans = 0

for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

for i in range(N):
    if max(L) <= i+1 <= min(R):
        ans += 1
print(ans)

Fixed submission:
N, M = map(int, input().split())
L = []
R = []
ans = 0

for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)
L_max = max(L)
L_min = min(R)

for i in range(N):
    if L_max <= i+1 <= L_min:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ans = set(range(1,N+1))
for _ in range(M):
    L, R = map(int, input().split())
    tmp = set(range(L,R+1))
    ans = tmp & ans
print(len(ans))

Fixed submission:
N, M = map(int, input().split())
L = []
R = []
ans = 0

for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)
L_max = max(L)
L_min = min(R)

for i in range(N):
    if L_max <= i+1 <= L_min:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(M)]

ans = 0
t = 0

for i in range(N): 
    t = 1
    for j in range(M):
        if not li[j][0] <= i+1 <= li[j][1]:
            t = 0
            break
    ans += t

print(ans)

Fixed submission:
N, M = map(int, input().split())
L = []
R = []
ans = 0

for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)
L_max = max(L)
L_min = min(R)

for i in range(N):
    if L_max <= i+1 <= L_min:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N ,K = map(int, input().split())

S = str(input())

S = S[:K] + (S[K]).lower() + S[K+1:]

print(S)


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

S = str(input())

S = S[:K-1] + (S[K-1]).lower() + S[K:]

print(S)

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

S = str(input())

S = S[:K-1] + S[K].swapcase() + S[K+1:]

print(S)


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

S = str(input())

S = S[:K-1] + (S[K-1]).lower() + S[K:]

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

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

lis = []
ans = 0

for i in range(N):
	lis = []
	for j in range(N):
		if i != j:
			lis.append(A[j])
	tmp = lis[0]
	for i in range(len(lis)-1):
		tmp = gcd(tmp,lis[i+1])
	ans = max(ans, tmp)
print(ans)

Fixed submission:
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
 
l = [0]*(N+1)
r = [0]*(N+1)

for i in range(N):
	l[i+1] = gcd(l[i], A[i])
for i in reversed(range(N)):	
	r[i] = gcd(r[i+1],A[i])

ans = 0
for i in range(N):
	ans = max(ans, gcd(l[i], r[i+1]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
for i in range(Q):
    print(S[lr[i][0]-1:lr[i][1]].count('AC'))

Fixed submission:
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]

cnt = [0] * (N + 1)
for i in range(N):
    if S[i:i+2] == 'AC':
        cnt[i+1] = cnt[i] + 1 
    else:
        cnt[i+1] = cnt[i]

for i in range(Q):
    print(cnt[lr[i][1]-1]-cnt[lr[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
l = []
r = []
for i in range(Q):
    L, R = map(int, input().split())
    l.append(L-1)
    r.append(R)
for i in range(Q):
    print((S[l[i]:r[i]]).count('AC'))

Fixed submission:
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]

cnt = [0] * (N + 1)
for i in range(N):
    if S[i:i+2] == 'AC':
        cnt[i+1] = cnt[i] + 1 
    else:
        cnt[i+1] = cnt[i]

for i in range(Q):
    print(cnt[lr[i][1]-1]-cnt[lr[i][0]-1])
Buggy python submission (verdict: Time Limit Exceeded):
S = raw_input();

cnt = 0;

while True:
	for i in range(len(S)):
		tmp = S.replace('01', '', 1);
		if S != tmp:
			cnt += 2;
			S = tmp;
			break;

		tmp = S.replace('10', '', 1);
		if S != tmp:
			cnt += 2;
			S = tmp;
			break;

	if len(set(S)) <= 1:
		break;

print(cnt);

Fixed submission:
S = raw_input();

S1 = S.count('1');
S0 = S.count('0');

if S1 > S0:
	print S0 * 2;

else:
	print S1 * 2;
Buggy python submission (verdict: Runtime Error):
K, A, B = map(int, raw_input().split())
bisco = 1
diff = B - A

if not(A+1 < B):
	print(1+K)

else:
	while K >= 1:
		if(bisco >= A and K >= 2):
			bisco += diff
			K -= 2
		else:
			bisco += 1
			K -= 1
	print(bisco)

Fixed submission:
l = map(int, raw_input().split())

if (l[0] >= (2 * l[1]) -1) :
	print("YES")

else :
	print("NO")

Buggy python submission (verdict: Runtime Error):
K, A, B = map(int, raw_input().split())
bisco = 1
diff = B - A

if not(A+1 < B):
	print(1+K)

else:
	while K >= 1:
		if(bisco >= A and K >= 2):
			bisco += diff
			K -= 2
		else:
			bisco += 1
			K -= 1
	print(bisco)

Fixed submission:
l = map(int, raw_input().split())

if (l[0] >= (2 * l[1]) -1) :
	print("YES")

else :
	print("NO")

Buggy python submission (verdict: Runtime Error):
K, A, B = map(int, raw_input().split())
bisco = 1
diff = B - A

if not(A+1 < B):
	print(1+K)

else:
	while K > 1:
		if(bisco >= A and K >= 2):
			bisco += diff
			K -= 2
		else:
			bisco += 1
			K -= 1
	print(bisco+1)

Fixed submission:
l = map(int, raw_input().split())

if (l[0] >= (2 * l[1]) -1) :
	print("YES")

else :
	print("NO")

Buggy python submission (verdict: Runtime Error):
K, A, B = map(int, raw_input().split())
bisco = 1
diff = B - A

if not(A+1 < B):
	print(1+K)

else:
	while K > 1:
		if(bisco >= A and K >= 2):
			bisco += diff
			K -= 2
		else:
			bisco += 1
			K -= 1
	print(bisco)

Fixed submission:
l = map(int, raw_input().split())

if (l[0] >= (2 * l[1]) -1) :
	print("YES")

else :
	print("NO")

Buggy python submission (verdict: Runtime Error):
K, A, B = map(int, raw_input().split())
bisco = 1
diff = B - A

if not(A+1 < B):
	print(1+K)

else:
	while K > 1:
		if(bisco >= A and K >= 2):
			bisco += diff
			K -= 2
		else:
			bisco += 1
			K -= 1
	print(bisco)

Fixed submission:
l = map(int, raw_input().split())

if (l[0] >= (2 * l[1]) -1) :
	print("YES")

else :
	print("NO")
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
X = sorted(list(map(int, input().split())))
if  M <= N:
    print(0)
else:
    L = []
    for i in range(M-1):
        L.append(X[i+1]-X[i])
L = sorted(L)
print(sum(L[:M-N]))

Fixed submission:
N, M = map(int,input().split())
X = sorted(list(map(int, input().split())))
if  M <= N:
    print(0)
else:
    L = []
    for i in range(M-1):
        L.append(X[i+1]-X[i])
    L = sorted(L)
    print(sum(L[:M-N]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys

n = int(input())
v = list(map(str, input().split()))
set_v = list(set(v))

if len(set_v) == 1:
    print(n//2)
    sys.exit()

pattern_v = []
pattern = []

for i in set_v:
    for j in set_v:
        if i != j:
            pattern_v.append([i,j])

for s, e in pattern_v:
    tmp = []
    for k in range(n):
        if k % 2 == 0:
            tmp.append(s)
        else:
            tmp.append(e)
    pattern.append(tmp)

ans = []

for i in range(len(pattern)):
    tmp = 0
    for j in range(n):
        if pattern[i][j] != v[j]:
            tmp += 1
    ans.append(tmp)

print(min(ans))

Fixed submission:
import collections

n = int(input())
v = list(map(str, input().split()))
ans = 0

if len(set(v)) == 1:
    print(n//2)

else:
    v_odd = collections.Counter(v[0::2])
    v_even = collections.Counter(v[1::2])

    v_odd = list(sorted(v_odd.items(), key = lambda x:-x[1]))
    v_even = list(sorted(v_even.items(), key = lambda x:-x[1]))

    if v_odd[0][0] == v_even[0][0]:
        if v_odd[1][1] > v_even[1][1]:
            print(n - v_odd[1][1] - v_even[0][1])
        else:
            print(n - v_odd[0][1] - v_even[1][1])
 
    else:
        print(n - v_odd[0][1] - v_even[0][1])
Buggy python submission (verdict: Runtime Error):
import math

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

if N == 1:
    print(x[0] - X)

else:
    diff = []

    for i in x:
        diff.append(abs(X - i))

    g = math.gcd(diff[0],diff[1])

    for i in range(1,len(diff)):
        g = math.gcd(g,diff[i])

    print(g)

Fixed submission:
import fractions

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

if N == 1:
    print(abs(x[0] - X))

else:
    diff = []

    for i in x:
        diff.append(abs(X - i))

    g = fractions.gcd(diff[0],diff[1])

    for i in range(1,len(diff)):
        g = fractions.gcd(g,diff[i])

    print(g)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

ans = 99999999

for i in range(N):
    cnt_w = 0
    cnt_e = 0
    for j in range(i):
        if S[j] == 'W':
            cnt_w += 1
    for j in range(i,N):
        if S[j] == 'E':
            cnt_e += 1
    ans = min(ans, cnt_w + cnt_e)
print(ans)

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

ans = 99999999

cnt_w = 0
cnt_e = 0
i = 0
for j in range(i):
    if S[j] == 'W':
        cnt_w += 1
for j in range(i,N):
    if S[j] == 'E':
        cnt_e += 1
ans = cnt_w + cnt_e

for i in range(N):
    if S[i] == 'W':
        cnt_w += 1
    else:
        cnt_e -= 1
    ans = min(cnt_w + cnt_e, ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

ans = 99999999

for i in range(N):
    # print(S[:i].count('W'))
    # print(S[i:].count('E'))
    # print("---------")
    ans = min(ans, S[:i].count('W')+S[i:].count('E'))
print(ans)

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

ans = 99999999

cnt_w = 0
cnt_e = 0
i = 0
for j in range(i):
    if S[j] == 'W':
        cnt_w += 1
for j in range(i,N):
    if S[j] == 'E':
        cnt_e += 1
ans = cnt_w + cnt_e

for i in range(N):
    if S[i] == 'W':
        cnt_w += 1
    else:
        cnt_e -= 1
    ans = min(cnt_w + cnt_e, ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import statistics
N = int(input())
X = list(map(int, input().split()))
for i in range(N):
    print(statistics.median(X[0:i]+X[i+1:N]))

Fixed submission:
N = int(input())
X = list(map(int, input().split()))
t = sorted(X)

for i in range(N):
    if X[i] <= t[N // 2 - 1]:
        print(t[N//2])
    else:
        print(t[N//2-1])