Problem:


Score : 300 points

Problem Statement

There are N cities on a number line. The i-th city is located at coordinate x_i.

Your objective is to visit all these cities at least once.

In order to do so, you will first set a positive integer D.

Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like:

Move 1: travel from coordinate y to coordinate y + D.

Move 2: travel from coordinate y to coordinate y - D.

Find the maximum value of D that enables you to visit all the cities.

Here, to visit a city is to travel to the coordinate where that city is located.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq X \leq 10^9

1 \leq x_i \leq 10^9

x_i are all different.

x_1, x_2, ..., x_N \neq X

Input

Input is given from Standard Input in the following format:

N X
x_1 x_2 ... x_N

Output

Print the maximum value of D that enables you to visit all the cities.

Sample Input 1

3 3
1 7 11

Sample Output 1

2

Setting D = 2 enables you to visit all the cities as follows, and this is the maximum value of such D.

Perform Move 2 to travel to coordinate 1.

Perform Move 1 to travel to coordinate 3.

Perform Move 1 to travel to coordinate 5.

Perform Move 1 to travel to coordinate 7.

Perform Move 1 to travel to coordinate 9.

Perform Move 1 to travel to coordinate 11.

Sample Input 2

3 81
33 105 57

Sample Output 2

24

Sample Input 3

1 1
1000000000

Sample Output 3

999999999



Sample input:
3 3
1 7 11


Sample output:
2

Submission status: Runtime Error

Solution code:
import math
def serch_index(X,x):
    for i in range(len(x)):
        if X >=x[i]:
            return i
def check_ans(temp_sub,ans):
    count = 0
    for i in temp_sub:
        if i%ans ==0:
            count += 1
        else:
            pass
    # print(count)
    if count == len(temp_sub):
        return False
    else:
        return True
def cal_gcd(temp_sub,ans):
    for i in temp_sub:
        temp_ans = math.gcd(i,ans)
        ans = min(ans,temp_ans)
    return ans

N,X = map(int,input().split())
x = list(map(int, input().split()))
if N == 1:
    print(abs(x[0]-X))
else:    
    X_index = serch_index(X, x)
    x.insert(X_index+1, X)
    x.sort()
    # print(x)
    temp_sub = []
    # print(x)
    for i in range(N):
        temp_sub.append(x[i+1]-x[i])
    # print(temp_sub)
    ans = abs(min(temp_sub))
    ans = cal_gcd(temp_sub, ans)
    
    # judge = True
    # while judge:
    #    judge = check_ans(temp_sub, ans)
    #    if judge:
    #         ans -=2
    print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

#Xとの差の最大公約数を求めればOK

#都市数と初期値を取得する
N,X=map(int,input().split())

#print(N)
#print(X)

#都市の位置を配列に格納する
lst1 = map(int,input().split())

# Xとの差の絶対値をとる関数
def calc1(n):
    return abs(n - X)
 
# map関数を使用
lst2 = map(calc1, lst1)

# 最大公約数を求める式
def gcd_list(numbers):
    return reduce(math.gcd, numbers)


print(gcd_list(lst2))

Submission status: Runtime Error

Solution code:
from math import gcd
N , X = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [abs(x[i]-X) for i in range(N)]
res = y[0]
for i in range(1,N):
    res = gcd(res,y[i])
print(res)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcd_ori(*num):
	return reduce(math.gcd, num)

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

Y = []
for i in x:
	Y.append(abs(X-i))

print(gcd_ori(*Y))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
 
n,m = map(int,input().split())
x = list(map(int,input().split()))
 
aa = []
for i in range(len(x)-1):
    a = x[i+1] - x[i]
    aa.append(a)
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)

if len(x) == 1:
    print(abs(x[0]-m))
else:
    print(gcd(*aa))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# Skip
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

i = input().split(' ')
N = int(i[0])
X = int(i[1])
xs = list(map(lambda x: int(x), input().split(' ')))
ds = list(map(lambda x: abs(X-x), xs))
#print(xs)
#print(ds)
l = gcd_list(ds)
print(l)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

D=[]

for i in range(N):
    D.append(abs(X-x[i]))
    
def gcd(D):
    return reduce(math.gcd, D)
    
def gcd_list(numbers):
    return reduce(math.gcd, D)

print(gcd(D))

Submission status: Runtime Error

Solution code:
N, X = map(int, input().split())
x_list = list(map(int, input().split()))
x_list.append(X)

x_list = sorted(x_list)
if N == 1:
	min_diff = x_list[1] - x_list[0]
else:
	x_diffs = [val - x_list[i - 1] for i, val in enumerate(x_list) if i > 0]
	min_diff = min(x_diffs)
D_canditates = [i for i in range(1, min_diff + 1)]

# Search max D
D_list = []
for D_cand in D_canditates:
    for x_diff in x_diffs:
        if x_diff % D_cand == 0:
            D_list.append(D_cand)
print(min(D_list))

Submission status: Runtime Error

Solution code:
import math
def GCD(LIST):
	if len(LIST)==2:
		return math.gcd(LIST[0],LIST[1])
	else:
		return GCD([math.gcd(LIST[0],LIST[1])]+LIST[2::])

N,X=map(int,input().split())
x=list(map(int,input().split()))
L=sorted(x+[X])
if N==1:
	print(abs(X-x[0]))
else:
	LL=[L[i+1]-L[i] for i in range(N)]
	print(GCD(LL))

Submission status: Runtime Error

Solution code:
# coding: utf-8

input_lines=input().split()

N=int(input_lines[0])
X=int(input_lines[1])

city=input().split()

D_list=[]
temp=[]

i=0

def yakusuu(num):
    yakusuu_list=[]
    for i in range(num):
        if num%i==0:
            yakusuu_list.append(i)
    return yakusuu_list


while(True):
    D_list.append(abs(X-int(city[i])))
    
    if D_list[-1] not in temp:
        temp.append(D_list[-1])
    Flag=True
    #print(D_list)

    for j in range(N):
        #print(D_list)
        if abs(int(city[j])-X) % D_list[-1]!=0:
            D_list.pop()
            break
            #Flag=False
    i+=1
    if i>=N:
        break

if len(D_list)==0:
    for i in range(len(D_list)):
        D_test=yakusuu_list(temp[i])

    for k in range(len(D_test)):
        for j in range(N):
            if abs(int(city[j])-X) % D_test[k]==0:
                D_list.append(D_test[k])

print(max(D_list))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

N, X  = (int(i) for i in input().split())
x = (int(i) for i in input().split())
x = list(x)
x.append(X)
#print(x)
x = sorted(x)
dif = []
for i in range(1, N):
    dif.append(x[i]-x[i-1])

if N == 1:
    print(abs(x[0]-x[1]))
else:
    print(gcd(dif)[0])

Submission status: Runtime Error

Solution code:
N, X = map(int, input().split())
L = list(map(int, input().split()))
for i in range(N):
    L[i] = abs(L[i] - X)

L.sort()

for i in range(1, L[0] + 1):
    if (L[0]%i == 0) and (L[1]%i == 0):
        res = i

print(res)

Submission status: Runtime Error

Solution code:
import math
L = []
N,X = map(int,input().split())
L = list(map(int,input().split()))
L.append(X)
L = sorted(L)
D = []
for i in range(len(L)) :
    d = abs(L[i-1] - L[i])
    D.append(d)

D = sorted(D)
if N != 1 :
    answer = math.gcd(D[0],D[1])
    for j in range(len(D)-1) :
        gcd = math.gcd(D[j],D[j+1])
        if answer > gcd :
            answer = gcd
else :
    answer = D[0]
print(answer)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


N, X = map(int, input().split())
toshi = list(map(int, input().split()))
toshi.sort()
if N == 1:
    print(toshi[0] - X)
    exit()

diff = [abs(X - toshi[0])]

for i in range(N - 1):
    diff.append(abs(toshi[i+1] - toshi[i]))

print(gcd_list(diff))

Submission status: Runtime Error

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

x.append(X)
x.sort()
D = []
for i in range(len(x)):
    if X == x[i]:
        D.append(abs(X - x[i-1]))
        D.append(abs(X + x[i+1]))
print(min(D))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
N,X=map(int,input().split())
x=list(map(int,input().split()))
x_dif=[]
for i in x:
    x_dif.append(X-i)
print(gcd_list(x_dif))

Submission status: Runtime Error

Solution code:
import math

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

xx = []

for i in range(n):
    xx.append(abs(x[i]-X))

if n == 1:
    print(xx[0])
else:
    xg = xx[0]
    for i in range(1,n):
        xg = math.gcd(xg,xx[i])
    print(xg)

Submission status: Runtime Error

Solution code:
import math
def GCD(LIST):
	if len(LIST)==2:
		return math.gcd(LIST[0],LIST[1])
	else:
		return GCD([math.gcd(LIST[0],LIST[1])]+LIST[2::])

N,X=map(int,input().split())
x=list(map(int,input().split()))
L=x+[X]
if N==1:
	print(abs(X-x[0]))
else:
	LL=[abs(L[i+1]-L[i]) for i in range(N)]
	print(GCD(LL))

Submission status: Runtime Error

Solution code:
import functools
import math
a,b = map(int,input().split())
c = list(map(int,input().split()))
c.append(b)
c.sort()
d = []
for i in range(a):
    e = c[i+1]-c[i]
    if e not in d:
        d.append(e)
gcd = functools.reduce(math.gcd, d)
print(gcd)

Submission status: Runtime Error

Solution code:
n,x = map(int, raw_input().split())
lis = sorted(map(int, raw_input().split()))
def gcd(a, b):
    if a == 0:
        return b
    return gcd(b%a,a)
if n == 1:
    val = abs(lis[0]-x)
    print val
    exit()
import bisect
#print lis
idx = bisect.bisect_left(lis, x)
#print idx
if idx == 0:
    val = lis[0] - x
    flag = 0
    lmao = -1
    for i in range(1, n):
        if (lis[i] - x) % val != 0:
            flag = 1
            lmao = i
            break
    if flag == 0:
        print val
    else:
        factors = [] 
        for i in range(min(x, lis[lmao]), 0, -1):
            if x % i == 0 and lis[lmao] % i == 0:
                factors.append(i)
        for i in xrange(len(factors)):
            flag1 = 0
            for j in xrange(n):
                if abs(lis[j]-x) % factors[i] != 0:
                    flag1 = 1
                    break
            if flag1 == 0:
                print factors[i]
                break
elif idx == n:
    val = x - lis[-1]
    flag = 0
    lmao = -1
    for i in range(n-2, -1, -1):
        if (x - lis[i]) % val != 0:
            lmao = i
            flag = 1
            break
    if flag == 0:
        print val
    else:
        factors = [] 
        for i in range(min(x, lis[lmao]), 0, -1):
            if x % i == 0 and lis[lmao] % i == 0:
                factors.append(i)
        for i in xrange(len(factors)):
            flag1 = 0
            for j in xrange(n):
                if abs(lis[j]-x) % factors[i] != 0:
                    flag1 = 1
                    break
            if flag1 == 0:
                print factors[i]
                break
else:
    val = min(lis[idx]-x, x-lis[idx-1])
    flag = 0
    lmao = -1
    for i in range(idx, n, 1):
        if (lis[i]-x)%val != 0:
            flag= 1
            lmao = i
            break
    for i in range(idx-1, -1, -1):
        if (x-lis[i])%val != 0:
            lmao = i
            flag = 1
            break
    if flag == 0:
        print val
    else:
        factors = [] 
        for i in range(min(x, lis[lmao]), 0, -1):
            if x % i == 0 and lis[lmao] % i == 0:
                factors.append(i)
        for i in xrange(len(factors)):
            flag1 = 0
            for j in xrange(n):
                if abs(lis[j]-x) % factors[i] != 0:
                    flag1 = 1
                    break
            if flag1 == 0:
                print factors[i]
                break


#print bisect.bisect_left(lis, 38)

Submission status: Runtime Error

Solution code:
(n, x) = list(map(int, input().split()))
x_list = list(map(int, input().split()))

x_list.append(x)
x_list.sort()

min_diff = 999_999_999_999
for i in range(len(x_list) - 1):
    diff = x_list[i + 1] - x_list[i]
    if min_diff > diff:
        min_diff = diff

# 差分の最小を約分していく
x_diff = [xx - x_list[0] for xx in x_list]

for i in range(1, min_diff):
    if min_diff % i != 0:  # 約分できない場合は次の数に進む
        continue
    xx = min_diff // i
    is_divided = [j for j in x_diff if j % xx != 0]
    if len(is_divided) == 0:
        print(xx)
        exit()

Submission status: Runtime Error

Solution code:
import math
n, x = map(int, input().split())
g = map(int, input().split())
result = abs(g[0]-x)
for i in range(1, n):
	result = math.gcd(result, abs(int(abs(g[i]-x))))
print(result)

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
import itertools

def main():
    N, X = list(map(int, input().split()))
    xs = list(map(int, input().split()))

    if len(xs) == 1:
        print(abs(xs[0] - X))
        exit()

    low = 0
    high = 10**9+1
    for x in xs:
        if x < X:
            low = max(x, low)
            continue
        if x > X:
            high = min(x, high)
            continue

    Ds = []
    if low != 0: Ds.append(X - low)
    if high != 10**9+1: Ds.append(high - X)
    for d in Ds:
        failed = False
        for x in xs:
            if abs(X-x)%d == 0:
                continue
            else:
                failed = True
                break
        if failed:
            continue
        else:
            print(d)
            exit()
    print(1)


def main2():
    def gcd(*numbers):
        return reduce(math.gcd, numbers)

    import math
    from functools import reduce
    N, X = list(map(int, input().split()))
    xs = list(map(int, input().split()))

    if len(xs) == 1:
        print(abs(xs[0] - X))
        exit()

    diffs = []
    for x in xs:
        diffs.append(abs(x-X))
    print(gcd(*diffs))

def main3():
    def gcd(*numbers):
        return reduce(math.gcd, numbers)

    import math
    from functools import reduce
    N, X = list(map(int, input().split()))
    xs = list(map(int, input().split()))

    if len(xs) == 1:
        print(abs(xs[0] - X))
        exit()

    xs.append(X)
    xs.sort()
    diffs = []
    for i in range(len(xs)-1):
        diffs.append(xs[i+1] - xs[i])
    print(gcd(*diffs))


if __name__ == "__main__":
    main3()

Submission status: Runtime Error

Solution code:
# coding: utf-8

input_lines=input().split()

N=int(input_lines[0])
X=int(input_lines[1])

city=input().split()

D_list=[]
temp=[]

i=0

def yakusuu(num):
    yakusuu_list=[]
    for i in range(num):
        if num%i==0:
            yakusuu_list.append(i)
    return yakusuu_list


while(True):
    D_list.append(abs(X-int(city[i])))
    if D_list[i] not in temp:
        temp.append(D_list[i])
    Flag=True
    #print(D_list)

    for j in range(N):
        #print(D_list)
        if abs(int(city[j])-X) % D_list[-1]!=0:
            D_list.pop()
            break
            #Flag=False
    i+=1
    if i>=N:
        break

if len(D_list)==0:
    for i in range(len(D_list)):
        D_test=yakusuu_list(temp[i])

    for k in range(len(D_test)):
        for j in range(N):
            if abs(int(city[j])-X) % D_test[k]=0:
                D_list.append(D_test[k])

print(max(D_list))

Submission status: Runtime Error

Solution code:
from math import gcd
n, x = map(int, input().split())
a = sorted([int(x) for x in input().split()] + [x])
a = [abs(y-x) for x, y in zip(a, a[1:])]
ans = a[0]
if len(a) > 1:
    ans = gcd(a[0], a[1])
    for i in range(2, len(a)): 
        ans = gcd(ans, a[i]) 
print(ans)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
	if b == 0:
		return 1
	_max = max(a, b)
	_min = min(a, b)
	rest = _max % _min
	if rest == 0:
		return _min
	else:
		return gcd(_min, rest)

N, X = map(int, raw_input().split())
x = map(int, raw_input().split())
x.sort()
	
for i in range(N):
	if X < x[i]:
		x.insert(i, X)
		break
diff = []
for i in range(N):
	d = abs(x[i] - x[i+1])
	diff.append(d)

res = diff[0]
for i in range(N - 1):
	res = gcd(res, diff[i + 1])
print res

Submission status: Runtime Error

Solution code:
# your code goes here
def gcd(a, b):
	if(a > b):
		a -= b
		return gcd(a, b)
	elif(a < b):
		b -= a
		return gcd(a, b)
	else:
		return int(a)

import numpy as np

n, x = map(int, input().split())
buf = input().split()
xx = np.zeros(n+1)
for i in range(n):
	xx[i] = int(buf[i])
xx[-1] = x
xx.sort()
for i in range(n):
	xx[n-i] -= xx[n-1-i]
	
if(xx.shape[0] == 2):
	r = xx[1]
else:
	r = gcd(xx[1], xx[2])
	for i in range(n-2):
		r = gcd(r, xx[i+3])
print(int(r))
	
#print(xx)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
N,X=map(int,input().split())
x=list(map(int,input().split()))
x_dif=[]
for i in x:
    x_dif.append(X-i)
print(gcd_list(x_dif))

Submission status: Runtime Error

Solution code:
N,X = map(int,input().split())
towns = list(map(int,input().split()))
towns.append(X)
towns.sort()
town_diff = [0]*(len(towns)-1)
for i in range(len(towns)-1):
    town_diff[i] = towns[i+1]-towns[i]
town_diff.sort()
if(len(town_diff) == 1):
    gcd = town_diff[0]
else:
    a = town_diff[0]
    b = town_diff[1]
    for i in range(len(town_diff)-2):
        while(True):
            t = b%a
            if(t == 0):
                gcd = a
                break
            b = a
            a = t
        a = gcd
        b = town_diff[i+2]
print(gcd)

Submission status: Runtime Error

Solution code:
from math import gcd
n, x = map(int, input().split())
a = sorted([int(x) for x in input().split()] + [x])
a = [abs(y-x) for x, y in zip(a, a[1:])]
ans = gcd(a[0], a[1]) if len(a) > 1 else a[0]
for i in range(2, len(a)): 
    ans = gcd(ans, a[i]) 
print(ans)

Submission status: Runtime Error

Solution code:
N,X=map(int,input().split())
inputcities=list(map(int, input().split()))
cities=set([abs(inputcities[i]-X) for i in range(N)])
N=len(cities)
count=0
flag=0
minimum=min(cities)
for j in range(minimum+1)[::-1]:
  for i in range(N):
    if cities[i]%j==0:
      count+=1
    else:
      count=0
      break
    if count==N:
      print(j)
      flag=1
      break
  if flag==1:
    break

Submission status: Runtime Error

Solution code:
import math
def serch_index(X,x):
    for i in range(len(x)):
        if X >=x[i]:
            return i
def check_ans(temp_sub,ans):
    count = 0
    for i in temp_sub:
        if i%ans ==0:
            count += 1
        else:
            pass
    # print(count)
    if count == len(temp_sub):
        return False
    else:
        return True
def cal_gcd(temp_sub,ans):
    for i in temp_sub:
        temp_ans = math.gcd(i,ans)
        ans = min(ans,temp_ans)
    return ans

N,X = map(int,input().split())
x = list(map(int, input().split()))
if N == 1:
    print(abs(x[0]-X))
else:    
    x.sort()
    X_index = serch_index(X, x)
    x.insert(X_index+1, X)
    # print(x)
    temp_sub = []
    for i in range(N):
        temp_sub.append(x[i+1]-x[i])

    ans = abs(min(temp_sub))
    ans = cal_gcd(temp_sub, ans)
    
    # judge = True
    # while judge:
    #    judge = check_ans(temp_sub, ans)
    #    if judge:
    #         ans -=2
    print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
N, X = [int(x) for x in stdin.readline().rstrip().split()]
xs = [int(x) for x in stdin.readline().rstrip().split()]
xs.sort()

mindist = abs(X - xs[0])
for i in range(1, len(xs)):
    dist = abs(X - xs[i])
    if mindist > dist:
        mindist = dist

mindist2 = xs[1] - xs[0]
for i in range(len(xs)-1):
    tmp = xs[i+1] - xs[i]
    if (mindist2 > tmp):
        mindist2 = tmp
if mindist == 0:
    mindist = mindist2

for i in range(1, len(xs)):
    if (abs(xs[i]-X)) % mindist != 0:
        if mindist % mindist2 == 0:
            mindist = mindist2
            break
        mindist = 1
        break

if mindist != 1:
    for i in range(1, len(xs)):
        if (abs(xs[i]-X)) % mindist != 0:
            mindist = 1
            break

print(mindist)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
 
tmp=input()
n = int(tmp.split(" ")[0])
X = int(tmp.split(" ")[1])
tmp=input()
i=int(0)
x=[]
for i in range(n):
    x.append(int(tmp.split(" ")[i]))
x.append(X)
x.sort()
y=[]

i=0
while i < n:
    y.append(x[i+1]-x[i])
    i +=1
y.sort()

z=y[0]
i=0
while i < n:
    z=math.gcd(z,y[i])
    i+=1

print(z)

Submission status: Runtime Error

Solution code:
# your code goes here
def gcd(a, b):
	if(a > b):
		a -= b
		return gcd(a, b)
	elif(a < b):
		b -= a
		return gcd(a, b)
	else:
		return int(a)

import numpy as np

n, x = map(int, input().split())
buf = input().split()
xx = np.zeros(n+1)
for i in range(n):
	xx[i] = int(buf[i])
xx[-1] = x
xx.sort()
for i in range(n):
	xx[n-i] -= xx[n-1-i]
	
if(xx.shape[0] == 2):
	r = xx[1]
else:
	r = gcd(xx[1], xx[2])
	for i in range(n-2):
		r = gcd(r, xx[i+3])
print(r)
	
#print(xx)

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
for i in range(N):
   A.append(input())
S = 0
for i in range(N-1):
    if A[i][-1] == A[i+1][0]:
        S += 1
B = 0
for i in range(N):
    for j in range(N):
        if A[i] == A[j]:
            B += 1
            else:
                B += 0

if S == N-1 and B == N:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import math

NX =  list(map(int, input().split()))
Points =  list(map(int, input().split()))
Points.append(NX[1])
Points.sort()

for i in range(len(Points)):
    Points[i] -= Points[0]

print(math.gcd(Points))

Submission status: Runtime Error

Solution code:
import math

n,x=map(int,input().split())
l=[abs(c-x) for c in list(map(int,input().split()))]
l.append(math.gcd(l[0],l[1]))
for x in range(n-2):
	l.append(math.gcd(l[-1],l[x+2]))
print(l[-1])

Submission status: Runtime Error

Solution code:
import math

N, X = map(int, input().split())
L = list(map(int, input().split()))
for i in range(N):
    L[i] = abs(L[i] - X)

L.sort()

print(math.gcd(L[0], L[1]))

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
for i in range(N):
   A.append(input())
S = 0
for i in range(N-1):
    if A[i][-1] == A[i+1][0]:
        S += 1
B = 0
for i in range(N):
    for j in range(N):
      if A[i] == A[j]:
        B += 1
      else:
        B += 0

if S == N-1 and B == N:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
N,X = map(int,input().split())
u = list(map(int,input().split()))
def gcd_list(numbers):
    gct = numbers[0]
    for i in range(len(numbers)-1):
        r = numbers[i+1] % gct
        while r != 0:
            ka = r
            r = gct
            gct = ka
            r = r % gct
    return gct
u.append(X)
u.sort()
sa = []
for i in range(len(u)-2):
    sa.append(u[i+1]-u[i])
print(gcd_list(sa))

Submission status: Runtime Error

Solution code:
from math import gcd
N, X = map(int, input().split())
kotae = list(map(int, input().split()))
kotae.append(X)
kotae.sort()
t = kotae[1]-kotae[0]
for i in range(len(kotae)-1):
    t = gcd(t, abs(kotae[i + 1] - kotae[i]))
print(t)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
	if b == 0:
		return 1
	_max = max(a, b)
	_min = min(a, b)
	rest = _max % _min
	if rest == 0:
		return _min
	else:
		return gcd(_min, rest)

N, X = map(int, raw_input().split())
x = map(int, raw_input().split())

for i in range(N):
	if X < x[i]:
		x.insert(i, X)
		break
diff = []
for i in range(N):
	d = abs(x[i] - x[i+1])
	diff.append(d)

res = diff[0]
for i in range(N - 1):
	res = gcd(res, diff[i + 1])
print res

Submission status: Runtime Error

Solution code:
def gcd(a, b):
	if b == 0:
		return -1
	_max = max(a, b)
	_min = min(a, b)
	rest = _max % _min
	if rest == 0:
		return _min
	else:
		return gcd(_min, rest)

N, X = map(int, raw_input().split())
x = map(int, raw_input().split())

for i in range(N):
	if X < x[i]:
		x.insert(i, X)
		break
diff = []
for i in range(N):
	d = abs(x[i] - x[i+1])
	diff.append(d)

res = diff[0]
for i in range(N - 1):
	res = gcd(res, diff[i + 1])
print res

Submission status: Runtime Error

Solution code:
from sys import stdin
N, X = [int(x) for x in stdin.readline().rstrip().split()]
xs = [int(x) for x in stdin.readline().rstrip().split()]
xs.sort()

mindist = abs(X - xs[0])
for i in range(1, len(xs)):
    dist = abs(X - xs[i])
    if mindist > dist:
        mindist = dist

mindist2 = xs[1] - xs[0]
for i in range(len(xs)-1):
    tmp = xs[i+1] - xs[i]
    if (mindist2 > tmp):
        mindist2 = tmp

for i in range(1, len(xs)):
    if (abs(xs[i]-X)) % mindist != 0:
        if mindist % mindist2 == 0:
            mindist = mindist2
            break
        mindist = 1
        break

if mindist != 1:
    for i in range(1, len(xs)):
        if (abs(xs[i]-X)) % mindist != 0:
            mindist = 1
            break

print(mindist)

Submission status: Runtime Error

Solution code:
N,X =[int(i) for i in input().split()]
c = [int(i) for i in input().split()]

c.append(X)
c.sort()

index_x = c.index(X)

if len(c) == 2:
    print(abs(c[index_x] - c[index_x - 1]))
else:
    print(min(c[index_x] - c[index_x - 1],c[index_x + 1] - c[index_x]))

Submission status: Runtime Error

Solution code:
n,x = map(int,input().split())
x_list = list(map(int,input().split()))
x_list.append(x)
x_list = sorted(x_list)
a = []
for i in range(n):
    b = x_list[i+1]-x_list[i]
    a.append(b)
import math
from functools import reduce
ans = reduce(math.gcd, a)
print(int(ans))

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
  
n,x = map(int,input().split())
xlist = list(map(int,input().split()))
ans = 0
for i in range(n):
    ans = gcd(int(xlist[i]-x),ans)
print(ans)

Submission status: Runtime Error

Solution code:
import math
n, X = map(int, input().split())

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

x.append(X)

sorted_x = sorted(x)
sorted_aaa = []

aaa = []

for (i, item) in enumerate(sorted_x):
    if i == 0:
        continue
    aaa.append(int(sorted_x[i] - sorted_x[i - 1]))

sorted_aaa = sorted(aaa)
res = 1 << 99

for (k, elm) in enumerate(sorted_aaa):
    # if elm % sorted_aaa[0] != 0:
    #     res = 1
    if len(sorted_aaa) == 1:
        res = sorted_aaa[k]
        break
    if k == 0:
        continue
    g = math.gcd(sorted_aaa[k - 1], sorted_aaa[k])
    if g < res:
        res = g

print(res)

Submission status: Runtime Error

Solution code:
import math
import numpy as np
from functools import reduce


def spaceinput():
    return list(map(int,input().split(" ")))


def _gcd(*numbers):
    return reduce(math.gcd, numbers)

#def gcd(numbers):
#    return reduce(np.gcd, numbers)



N,X=spaceinput()

x=spaceinput()

x.append(X)
x=sorted(x)
d=[]
for i,xx in enumerate(x[:-1]):
    d.append(x[i+1]-x[i])

#print(d)

#print( np.gcd(12, 20))
print(np.gcd.reduce(d))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
a,b = map(int,input().split())
c = list(map(int,input().split()))
c.append(b)
c.sort()
d = []
for i in range(a):
    e = c[i+1]-c[i]
    if e not in d:
        d.append(e)
print(gcd_list(d))

Submission status: Runtime Error

Solution code:
import functools
import math

n,x=map(int,input().split())
z=[]

y=[]
z=list(map(int, input().split()))
z.append(x)

z.sort()
for i in range(n):
  y.append(z[i+1]-z[i])
  
gcd = functools.reduce(math.gcd, y)
print(gcd)

Submission status: Runtime Error

Solution code:
import sys
import functools
import math

input = sys.stdin.read().split()

N = int(input[0])
X = int(input[1])
cities = sorted(list(map(int, input[2:])))


left = []
right = []
distance = []

for city in cities:
    if X > int(city):
        left.append(int(city))
    else:
        right.append(int(city))

for lcity in left:
    distance.append(X - lcity)
for rcity in right:
    distance.append(rcity - X)

gcd = functools.reduce(math.gcd, distance)

print(gcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
N, X = map(int, input().split())
L = list(map(int, input().split()))
for i in range(N):
    L[i] = abs(L[i] - X)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
print(gcd_list(L))

Submission status: Runtime Error

Solution code:

#coding: utf-8
import numpy as np
import math
from functools import reduce

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

y = np.asarray(list(map(int,input().split())))
y -= x

print(reduce(math.gcd, y))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import functools
import math

input = sys.stdin.readline
n, x = map(int, input().split())
a = input().split()
b = list(map(int, a))
b.append(x)
b.sort()
c = []
for i in range(n):
    if i <= n - 1:
        c.append(b[i + 1] - b[i])
gcd = functools.reduce(math.gcd, c)

print(gcd)

Submission status: Runtime Error

Solution code:
import math

N,X = map(int,input().split())
L = list(map(int,input().split()))
L.append(X)
L = sorted(L)
D = []
for i in range(len(L)) :
    d = abs(L[i+1] - L[i])
    D.append(d)

D = sorted(D)
if N != 1 :
    answer = math.gcd(D[0],D[1])
    for j in range(len(D)) :
        gcd = math.gcd(D[i-1],D[i])
        if answer > gcd :
            answer = gcd
else :
    answer = D[0]
print(answer)

Submission status: Runtime Error

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
L=x+[X]
if N==1:
	print(abs(X-x[0]))
else:
	LL=[abs(L[i+1]-L[i]) for i in range(N)]
	import math
	from functools import reduce
	def gcd(*numbers):
		return reduce(math.gcd, numbers)
	print(gcd(*LL))

Submission status: Runtime Error

Solution code:
import math as mh
import fractions as fr

n, p = (int(_) for _ in input().split())
x = list(int(_) for _ in input().split())

if p < min(x):
    lmin = abs(p + min(x))
    lmax = abs(p - max(x))
elif p > max(x):
    lmin = abs(p - min(x))
    lmax = abs(p + max(x))
else:
    lmin = abs(p - min(x))
    lmax = abs(p - max(x))

d = mh.gcd(lmin, lmax)

#while (d*2)%lmin == 0 and (d*2)%lmax == 0:
#    d *= 2
print(d)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
a,b = map(int,input().split())
c = list(map(int,input().split()))
c.append(b)
c.sort()
d = []
for i in range(a):
    d.append(c[i+1]-c[i])
print(gcd_list(d))

Submission status: Runtime Error

Solution code:
#coding: utf-8
import numpy as np
import fraction
from functools import reduce

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

y = np.asarray(list(map(int,input().split())))
y -= x

print(reduce(fraction.gcd, y))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import copy
N,X=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
limit=max(abs(x[0]-X),abs(x[len(x)-1]-X))
x_ans1=[]
x_ans2=[]
x_ansnum=[]
for i in range(1,limit+1):
    for j in range(1,limit+1):
        x_ans2.append(X+i*j)
        x_ans2.append(X-i*j)
    x_ans1.append(copy.copy(x_ans2))
    x_ans2.clear()
for k in range(limit):
    if len(set(x)&set(x_ans1[k]))==len(x):
        x_ansnum.append(k)
print(max(x_ansnum)+1)