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: Wrong Answer

Solution code:
def gcd(x,y):
     if x%y==0:
             return y
     else:
             return gcd(y, x%y)

[n,m]=[int(i) for i in input().split()]
x=[int(i) for i in input().split()]
x.append(m)

li=[]
f=1
if n==1:
    f=0
    print(abs(x[0]-x[1]))

for i in range(len(x)-1):
    li.append(abs(x[i]-x[i+1]))


if f:
    for i in range(len(li)-1):
        a=li[0]
        a=gcd(a, li[i+1])
    print(a)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
 
arr = [int(i) for i in input().split(' ')]
arr.sort()
 
a = arr[-1]
 
 
for i in range(N-1):
    if abs(arr[i+1]-arr[i]) < a:
        a = abs(arr[i+1]-arr[i])
 
for j in range(N):
    if abs(arr[j] - X) < a:
        a = abs(arr[j] - X)
 
print(a)

Submission status: Wrong Answer

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

if N==1:
    print(abs(x[0]-X))
    sys.exit()
    
x.append(X)
x.sort()
x_diff=[]
for j in range (N):
    x_diff.append(x[j+1]-x[j])
ans=min(x_diff)
for i in range (len(x_diff)):
    if x_diff[i]%(ans)!=0:
        print (1)
        sys.exit()
print(ans)

Submission status: Wrong Answer

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

def main():
    n, x = map(int, input().split())
    a = [int(v) for v in input().split(' ')]
    a.append(x)
    a.sort()
    dis = [abs(x2 - x1) for x1, x2 in zip(a, a[1:])]
    max_ = 0
    for i in range(n):
        can = True
        d = sorted(list(set(dis)))
        if len(d) == 1:
            max_ = d[0]
            break
        m = gcd(d[0], d[1])
        for item in d:
            if item % m != 0:
                max_ = 1
                can = False
                break
        if can:
            max_ = m
    print(max_)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
A, B= map(int, input().split())
l = input().split()
l = list(map(int, l))
m = []
for i in l:
    if i<B:
        D = B - i
    else:
        D = i - B
    if D != 0:
        m.append(D)

print(min(m))

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
l = list(map(int,input().split()))
lmin = list()
l.sort()
num = 0

if n == 1:
    print(l[0]-x)
    exit()
else:
    l.append(x)

def calc():
    global l
    global lmin
    global num
    for i in range(n-num):
        lmin.append(l[i+1]-l[i])
    else:
        l = lmin
        num += 1

while(True):
    #print("j")
    for i in range(n-num):
        if l[i] % l[0] != 0:
            calc()
            continue
    else:
        print(l[0])
        break

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
if N == 1:
    x = abs(X - int(input()))
    print(x)
else:
    x = list(map(int, input().split()))
    x = list(map(lambda i: abs(i - X), x))
    xa = list(map(lambda i: i % min(x), x))
    if max(xa) > 0:
        print(1)
    else:
        print(min(x))

Submission status: Wrong Answer

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)]
	MAX=1
	while all([l%(MAX+1)==0 for l in LL]):
		MAX+=1
	print(MAX)

Submission status: Wrong Answer

Solution code:
A,B = list(map(int,input().split()))
l = list(map(int,input().split()))


def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

def gc(n):
    return [gcd(n[0],n[1])]+n[2::]

lgap = [abs(i-B) for i in l]

if len(lgap)==1:
    g = lgap[0]
elif len(lgap)==2:
    g = gcd(lgap[0],lgap[1])
else:
    g = gc(lgap)
    g = gcd(g[0],g[1])

print(g)

Submission status: Wrong Answer

Solution code:
n,x = map(int, input().split())
 
city = list(map(int, input().split()))
 
def check(n):
    return abs(n - x)
 
dist = list(map(check, city))
min_dist = min(dist)
 
if n < 2:
    print(min_dist)
    exit()

city.sort()
prev = 0
for pos in city:
    if not prev == 0:
        if abs(prev - pos) < min_dist:
            print(abs(prev - pos))
            exit()
    prev = pos

print(min_dist)

Submission status: Wrong Answer

Solution code:
num_str=input().split()
num=list(map(int, num_str))
n=num[0]
x=num[1]

num2_str=input().split()
distance=list(map(int, num2_str))

first_distance=list(map(lambda y:abs(y-x),distance))
min_distance=min(first_distance)

flag=True
for i in range(min_distance,-1):
    for j in n:
        if first_distance[j]%i!=0:
            flag=False

    if flag:
        print("i")
        break

Submission status: Wrong Answer

Solution code:
import numpy as np
import functools
import math

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

def gcd_1(l):
    x = max(l)
    y = min(l)
    if x % y == 0:
        return y
    else:
        while x%y!=0:
            z = x%y
            x = y
            y = z
        else:
            return z
        
if N == 1:
    print(x_list[0] - X)
    exit()

values = np.sort(np.array(x_list))[1:] - min(x_list)

if N == 2:
    print(values[0])
    exit()

print(gcd_1(values))

Submission status: Wrong Answer

Solution code:
l = map(int, raw_input().split())
toshisuu= l[0]
starttoshi= l[1]
toshilist = map(int, raw_input().split())
ans=100000000000000000000
for i in toshilist:
    counts=abs(i-starttoshi)
    if ans>counts:
        ans=counts
print ans

Submission status: Wrong Answer

Solution code:
n,w = map(int,input().split())
x = list(map(int,input().split()))
temp = []
for i in range(n):
    temp.append(abs(w-x[i]))
print(min(temp))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split( ))
x_i=[]
x_i+=map(int,input().split( ))
x_i+=[x]
x_i.sort()

c = [y - x for (x, y) in zip(x_i[0:n], x_i[1:n+1])]
min_c=min(c)

def fun(x):
    return x%min_c
  
li=list(map(fun,c))

if max(li)==0:
    print(min(c))
else:
    print(1)

Submission status: Wrong Answer

Solution code:
A, B= map(int, input().split())
l = input().split()
l = list(map(int, l))
m = []
for i in l:
    if i<B:
        D = B - i
    else:
        D = i - B
    m.append(D)

print(min(m))

Submission status: Wrong Answer

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 = fr.gcd(lmin, lmax)

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

Submission status: Wrong Answer

Solution code:
n,x = list(map(int, input().split()))
x_i = list(map(int, input().split()))
x_i.sort()
y = abs(x_i[-1] - x)
z = abs(x_i[0] - x)
ans = 0
for i in range(y,1,-1):
    if y % i == 0 and z % i == 0:
        ans = i
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
d = [1000000000]
e = []
flg = False
for i in range(len(a)-1):
  t = a[1+i] - a[i]
  e.append(t)
  if(t < d[0]):
    d.insert(0,t)
l = len(d)
ans=1000000000
for i in range(l):
  u = list(map(lambda x: x% d[l - 1 - i],e))
  print(u)
  if(u.count(0) == n):
    ans = d[l-1-i]
    break
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

Submission status: Wrong Answer

Solution code:
import functools
import fractions

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

if n == 1:
    ans = cities[0] - x
else:
    cities.append(x)
    dist = []
    for i in range(0,len(cities)-1):
        dist.append(cities[i+1] - cities[i])
    ans = functools.reduce(fractions.gcd, dist)
print(ans)

Submission status: Wrong Answer

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

maxi = 0

for i in range(N):
	if(x[i]!=X):
		sa = abs(x[i]-X)
		
		chk = 0
		for j in range(N):
			if((abs(x[j]-X))%sa!=0):
				break
			else:
				chk += 1
		if(chk==N):
			if(sa>maxi):
				maxi = sa

print(maxi)

Submission status: Wrong Answer

Solution code:
D = 0
N,X = map(int,input().rstrip().split())

#Nマップ、X開始地、x1、x2・・・位置、？D


x = input().rstrip().split()

#print(X,x)

ANS = []
for i in x:
	#print(abs(int(i)-X))
	ANS.append(abs(int(i)-X))

#もし合計値が奇数なら最小値も奇数、偶数なら最小値も偶数、そうでなければ1

mini = sorted(ANS)[0]
if sum(ANS)%mini== 0:
	print(mini)
else:
	print("1")

Submission status: Wrong Answer

Solution code:
import collections
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = []
d = []
for i in range(a[0]):
	b[i] = abs(b[i]-a[1])
b.sort()
c = collections.Counter(b)
c = list(c.keys())
c.sort()
for i in range(len(c)-1):
	d.append(c[i+1]-c[i])
d.sort()
for i in range(len(d)-1):
	if d[i] % d[0] != 0:
		d[0] = 1
		break
if len(c) == 1:
	print(c[0])
else:
	print(d[0])

Submission status: Wrong Answer

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 = fr.gcd(lmin, lmax)
while (d*2)%lmin == 0 and (d*2)%lmax == 0:
    d *= 2

print(d)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
 
arr = [int(i) for i in input().split(' ')]
arr.sort()
 
a = 5000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
 
 
for i in range(N-1):
    if abs(arr[i+1]-arr[i]) < a:
        a = abs(arr[i+1]-arr[i])
 
for j in range(N):
    if abs(arr[j] - X) < a:
        a = abs(arr[j] - X)
 
print(a)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
d = [1000000000]
e = []
flg = False
for i in range(len(a)-1):
  t = a[1+i] - a[i]
  e.append(t)
  if(t < d[0]):
    d.insert(0,t)
l = len(d)
ans = 1
for i in range(l):
  u = list(map(lambda x: x% d[l - 1 - i],e))
  print(u)
  if(u.count(0) == n):
    ans = d[l-1-i]
    break
print(ans)

Submission status: Wrong Answer

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

kakunin=10**10

if N==1:
    if X<S[0]:
        print(10**9-X)
        exit()
    else:
        print(X-S[0])
        exit()

for i in range(N):
    S[i]=S[i]-X
    if abs(S[i])<kakunin:
        kakunin=abs(S[i])
        
ans=1
okflag=True
for i in range(2,kakunin+1):
    okflag=True
    for j in range(N):
        if S[j]%i!=0:
            okflag=False
           
            break
    if okflag==True:
        ans=i
print(ans)

Submission status: Wrong Answer

Solution code:
A, B= map(int, input().split())
l = input().split()
l = list(map(int, l))
m = 10**10
for i in l:
    if i<B:
        D = B - i
    else:
        D = i-B
    m = min(m, D)

print(m)

Submission status: Wrong Answer

Solution code:
import functools
import math
import fractions
n, x = map(int, input().split())
xx = list(map(int, input().split()))  # x1 x2 ... xn
xx.append(x)
xx.sort()
xx = list(set(xx))
diff = []  # 隣接する都市の距離を保存
d = 1
if len(xx) > 2:
    for i in range(1, n):
        diff.append(abs(xx[i - 1] - xx[i]))
    d = functools.reduce(fractions.gcd, diff)
else:
    d = abs(xx[0] - xx[1])
print(d)

Submission status: Wrong Answer

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

def main():
    n, x = map(int, input().split())
    a = [int(v) for v in input().split(' ')]
    a.append(x)
    a.sort()
    dis = [abs(x2 - x1) for x1, x2 in zip(a, a[1:])]
    max_ = 0
    for i in range(n):
        d = sorted(list(set(dis)))
        if len(d) == 1:
            max_ = d[0]
            break
        m = gcd(d[0], d[1])
        for item in d:
            if item % m != 0:
                max_ =1
        max_ = m

    print(max_)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if N==1:
    print(abs(x[0]-X))
    sys.exit()
    
x.append(X)
x.sort()
x_diff=[]
for i in range (N):
    x_diff.append(x[i+1]-x[i])
ans=min(x_diff)
for i in range (len(x_diff)):
    if x_diff[i]%(ans)!=0:
        print (1)
        sys.exit()
print(ans)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
if(a==1):
    print(abs(l[0]-b))
    exit()
else:
    li=[]
    num=abs(b-l[0])
    ans=3534352424235242
    for i in range(1,len(l)):
        li.append(l[i]-l[i-1])
        ans=min(ans,abs(b-l[i]))
    print(min(num,ans))

Submission status: Wrong Answer

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 = fr.gcd(lmin, lmax)
while d%lmin == 0 and d%lmax == 0:
    d *= 2

print(d)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math
n,x=map(int,input().split())
pos=list(map(int,input().split()))

pos2=[abs(p-x) for p in pos]

maxpos= max(pos2)
ans = 1

for i in range(1,int(math.sqrt(maxpos))+2):
    j=int(maxpos/i)
    if all([ x%j==0 for x in pos2 ]):
        ans=j
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
# print(n, x)
citys = list(map(int, input().split()))
# print(citys)

import numpy as np
import sys
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

nearest_city = getNearestValue(citys, x)
# print(nearest_city)

is_passed = True
for xx in reversed(range(2, (abs(nearest_city-x)+1))):
    for city in citys:
        if ((city - x) % xx) != 0:
            is_passed = False
            break
    if is_passed:
        print(xx)
        sys.exit(0)
print(1)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
x = list(map(int, input().split()))
x_max = max(x)
x_min = min(x)
if max(abs(x_max - X), abs(x_min - X)) % min(abs(x_max - X), abs(x_min - X)) == 0:
	print(min(abs(x_max - X), abs(x_min - X)))
else:
	print(1)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a%b)

def gcd_list(l):
    # print(l)
    if len(l) == 1:
        return l[0]
    temp = [gcd(l[0],l[1])]
    n = 0
    while(n<len(l)-2):
        # print(temp)
        temp.append( gcd(temp[n], l[n+2]) )
        n = n+1
    # print(temp)
    return(temp[len(temp)-1])

n, start = map(int, input().split(" "))
li = list(map(int, input().split(" ")))
diff = min(li) - start
if(len(li) == 1):
    print(diff)
else:
    li.append(start)
    diff = min(li) - start
    for i in range(len(li)):
        li[i] = li[i] - start - diff
    # print(li)
    print(gcd_list(li))

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
if(a==1):
    print(abs(l[0]-b))
    exit()
else:
    li=[]
    num=abs(b-l[0])
    ans=3534352424235242
    for i in range(1,len(l)):
        li.append(l[i]-l[i-1])
        ans=min(ans,abs(b-l[i]))
    print(min(num,min(li),ans))

Submission status: Wrong Answer

Solution code:
D = 0
N,X = map(int,input().rstrip().split())

#Nマップ、X開始地、x1、x2・・・位置、？D


x = input().rstrip().split()

#print(X,x)

ANS = []
for i in x:
	#print(abs(int(i)-X))
	ANS.append(abs(int(i)-X))

#もし合計値が奇数なら最小値も奇数、偶数なら最小値も偶数、そうでなければ1


if sum(ANS)%sorted(ANS)[0] == 0:
	print(ANS[0])
else:
	print("1")

Submission status: Wrong Answer

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

xn = [abs(i - x) for i in xn]

if n == 1 :
    print(xn[0])
else:
    for i in range(min(xn), 0, -1):
        if not all([j % i for j in xn]):
            print(i)
            break

Submission status: Wrong Answer

Solution code:
a = input().split()
x = int(a[0])
n = int(a[1])
b = input().split()
l = [int(i) for i in b]

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

def lcm(a, b):
    return a * b // gcd (a, b)

l.append(x)
ld = sorted(l, reverse=True)
tmp = []
for i in range(1, len(ld)):
    tmp.append(abs(ld[i] - ld[i-1]))
print(lcm((min(tmp)), (gcd(abs(max(l)-x), abs(min(l)-x)))))

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
if(a==1):
    print(abs(l[0]-b))
    exit()
else:
    li=[]
    num=b-l[0]
    ans=3534352424235242
    for i in range(1,len(l)):
        ans=min(num,ans,abs(b-l[i]))
    print(ans)

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
L = []
 
if (len(x) == 1):
  print(abs(X-x[0]))
else:
  L.append(abs(X-x[0]))
  for k in range(len(x)):
    p = abs(X-x[k])
    if (p < L[0]):
      if (L[0] % p != 0):
        print('1')
        break
      else:
        if (L[0] != 1):
          del L[0]
          L.append(p)
        print(L[0])

Submission status: Wrong Answer

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

xl.append(x)
xl.sort()

onesam = 0

if len(xl) == 1:
    print(abs(xl[0] - x))
    exit()

for i in range(len(xl)-1):
    one_sa = xl[i+1] - xl[i]
    if onesam == 0:
        onesam = abs(one_sa)
    else:
        short,big = min(onesam,one_sa),max(onesam,one_sa)
        if big % short == 0:
            onesam = short
            continue
        else:
            while big % short != 0:
                for k in range(2,short+1):
                    if short % k == 0:
                        short = short // k
                        break
            onesam = short
            
print(onesam)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
ans=0
gcd=0
amari=0
big=0
small=0
for i in range(N):
	x[i] = abs(x[i]-X)
if N==1:
	print(x[0])
else:
	ans=x[0]
	for j in range(1,N-1,1):
		if x[j]>=ans:
			big=x[j]
			small=ans
		else:
			big=ans
			small=x[j]
		while big%small != 0:
			amari=big%small
			big=small
			small=amari
	print(small)

Submission status: Wrong Answer

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

kakunin=10**10

if N==1:
    if X<=500000000:
        print(10**9-X)
        exit()
    else:
        print(X-1)
        exit()

for i in range(N):
    S[i]=S[i]-X
    if abs(S[i])<kakunin:
        kakunin=abs(S[i])
        
ans=1
okflag=True
for i in range(2,kakunin+1):
    okflag=True
    for j in range(N):
        if S[j]%i!=0:
            okflag=False
           
            break
    if okflag==True:
        ans=i
print(ans)

Submission status: Wrong Answer

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

maxi = 100000000000

for i in range(N):
	sa = abs(x[i]-X)
	
	chk = 0
	for j in range(N):
		if((abs(x[j]-X))%sa!=0):
			break
		else:
			chk += 1
	if(chk==N):
		if(sa<maxi):
			maxi = sa

print(maxi)

Submission status: Wrong Answer

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


def main():
    n, large_x = map(int, input().split())
    x = sorted(list(map(lambda x: int(x) - large_x, input().split())) + [0])
    dx = float('inf')

    for i in range(1, n + 1):
        dx = min(dx, x[i] - x[i - 1])

    for xi in x:
        if xi % dx != 0:
            print(1)
            exit()

    print(dx)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
d = [1000000000000]
e = []
flg = False
for i in range(len(a)-1):
  t = a[1+i] - a[i]
  e.append(t)
  if(t < d[0]):
    d.insert(0,t)
  if(t == 1):
    flg = True
    break
if(flg):
  print(1)
else:
  l = len(d)
  ans = 1
  for i in range(l):
    u = list(map(lambda x: x% d[l - 1 - i],e))
    print(u)
    if(u.count(0) == n):
      ans = d[l-1-i]
      break
  print(ans)

Submission status: Wrong Answer

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

xl.append(x)
xl.sort()

onesam = 0

if len(xl) == 1:
    print(abs(xl[0] - x))
    exit()

for i in range(len(xl)-1):
    one_sa = xl[i+1] - xl[i]
    if onesam == 0:
        onesam = abs(one_sa)
    else:
        short,big = min(onesam,one_sa),max(onesam,one_sa)
        if big % short == 0:
            onesam = short
            continue
        else:
            short,big = min(onesam,one_sa),max(onesam,one_sa)

                
            while big % short != 0:
                for k in range(2,short+1):
                    if short % k == 0:
                        short = short // k
                        break
            onesam = short
            
print(onesam)

Submission status: Wrong Answer

Solution code:
import fractions

N,start = map(int, input().split())

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

a = list(map(int, input().split()))
a = list(map(lambda x: abs(x-start),a))
a.sort()

D = a[0]

for i in range(1,len(a)):
  if i % D == 0:
    continue
  else:
    D = lcm(i, D)

  if D == 1:
    print('1')
    exit()

print(D)

Submission status: Wrong Answer

Solution code:
n,x = list(map(int, input().split()))
x_i = list(map(int, input().split()))
x_i.sort()
y = abs(x_i[-1] - x)
ans = 0
for i in range(y,1,-1):
    if y % i == 0:
        ans = i
        break
print(ans)

Submission status: Wrong Answer

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

c.append(X)
c.sort()

D = float('inf')

for i in range(1,N+1):
    if c[i] - c[i-1] < D:
        D = int(c[i] - c[i-1])

print(int(D))

Submission status: Wrong Answer

Solution code:
import functools
import fractions

n,x = map(int,input().split())
cities = list(map(int,input().split()))
if n == 1:
    ans = cities[0] - x
    print(ans)
else:
    cities.append(x)
    cities.sort()
    dist = []
    for i in range(1,len(cities)):
        dist.append(cities[i] - cities[i-1])
    ans = functools.reduce(fractions.gcd, dist)
    print(ans)

Submission status: Wrong Answer

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

cacheP = Points[0]
interval = Points[1] - cacheP
Points.pop(0)

for p in Points:
    tmpInterval = p - cacheP
    if (tmpInterval < interval):
        interval = tmpInterval
    cacheP = p
print(interval)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
if(a==1):
    print(abs(l[0]-b))
    exit()
else:
    li=[]
    num=b-l[0]
    ans=3534352424235242
    for i in range(1,len(l)):
        li.append(l[i]-l[i-1])
        ans=min(ans,abs(b-l[i]))
    print(min(num,min(li),ans))

Submission status: Wrong Answer

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:
        zz = gcd(x, lis[lmao])
        flag1 = 0
        for i in xrange(n):
            if abs(lis[i]-x) % zz != 0:
                flag1 =1
                break
        if flag1 == 1:
            print 1
        else:
            print zz
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:
        zz = gcd(x, lis[lmao])
        flag1 = 0
        for i in xrange(n):
            if abs(lis[i]-x) % zz != 0:
                flag1 =1
                break
        if flag1 == 1:
            print 1
        else:
            print zz
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:
        zz = gcd(x, lis[lmao])
        flag1 = 0
        for i in xrange(n):
            if abs(lis[i]-x) % zz != 0:
                flag1 =1
                break
        if flag1 == 1:
            print 1
        else:
            print zz


#print bisect.bisect_left(lis, 38)

Submission status: Wrong Answer

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

xl.append(x)
xl.sort()

onesam = 0

if len(xl) == 1:
    print(abs(xl[0] - x))
    exit()

for i in range(len(xl)-1):
    one_sa = xl[i+1] - xl[i]
    if onesam == 0:
        onesam = abs(one_sa)
    else:
        short,big = min(onesam,one_sa),max(onesam,one_sa)
        if big % short == 0:
            onesam = short
            continue
        else:
            short,big = min(onesam,one_sa),max(onesam,one_sa)
            if short == 1:
                onesam = 1
                break
                
            while big % short != 0:
                for k in range(2,short+1):
                    if short % k == 0:
                        short = short // k
                        break
            onesam = short
            
print(onesam)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
if(a==1):
    print(abs(l[0]-b))
    exit()
else:
    li=[]
    num=b-l[0]
    for i in range(1,len(l)):
        li.append(l[i]-l[i-1])
    print(min(num,min(li)))

Submission status: Wrong Answer

Solution code:
headData=[int(n) for n in input().split()]
cityNum=headData[0]
pos_x=headData[1]
cityData=sorted([int(n) for n in input().split()])
min=cityData[0]
max=cityData[len(cityData)-1]

# max_diff計算
min_diff=max
for n in range(len(cityData)-1):
    diff = cityData[n+1]-cityData[n]
    if diff < min_diff:
        min_diff = diff

# 移動しうる位置を解く知恵
answer=min_diff
while True:
    possibleCityList = [pos_x]
    possibleCity = pos_x
    while True:
        possibleCity=possibleCity - answer
        if possibleCity < min :
            break;
        possibleCityList.append(possibleCity)

    possibleCity=pos_x
    while True:
        possibleCity=possibleCity + answer
        if possibleCity > max :
            break;
        possibleCityList.append(possibleCity)

    if(set(cityData).issubset(set(possibleCityList))):
        print(answer)
        break;
    answer=answer-1

Submission status: Wrong Answer

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

if N==1:
    print(abs(x[0]-X))
    sys.exit()
x.append(X)
x.sort()
x_diff=[]
for i in range (N):
    x_diff.append(x[i+1]-x[i])
ans=min(x_diff)
for i in range (len(x_diff)):
    if x_diff[i]%(ans)!=0:
        print (1)
        sys.exit()
print(ans)

Submission status: Wrong Answer

Solution code:
import math as mh
import fractions as fr

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

x_min = min(x)
x_max = max(x)

d = fr.gcd(abs(p-x_min), abs(x_max-p))
while d%abs(p-x_min) == 0 and d%abs(x_max-p) == 0:
    d *= 2

print(d)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, x_start = [int(x) for x in input().split(' ')]
xs = [int(x) for x in input().split(' ')]
xs = np.array(xs)


next_idx = np.argmin(np.abs(xs - x_start))
d = np.abs(x_start - xs[next_idx])
print(d)

Submission status: Wrong Answer

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

maxi = 0

for i in range(N):
	sa = abs(x[i]-X)
	
	chk = 0
	for j in range(N):
		if((abs(x[j]-X))%sa!=0):
			break
		else:
			chk += 1
	if(chk==N):
		if(sa>maxi):
			maxi = sa

print(maxi)

Submission status: Wrong Answer

Solution code:
from sys import stderr
from functools import reduce
from operator import add
from bisect import insort
def f(): return [int(i) for i in input().split()]
def yes(n): print("Yes" if n else "No")
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(str(item))
        stderr.write(sep)
    stderr.write(end)

n, x = f()
X = sorted(f())
insort(X,x)
print(min([X[i+1]-X[i] for i in range(n)]))

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
d = [1000000000]
e = []
flg = False
for i in range(len(a)-1):
  t = a[1+i] - a[i]
  e.append(t)
  if(t < d[0]):
    d.insert(0,t)
  if(t == 1):
    flg = True
    break
if(flg):
  print(1)
else:
  l = len(d)
  ans = 1
  for i in range(l):
    u = list(map(lambda x: x% d[l - 1 - i],e))
    if(u.count(0) == n):
      ans = d[l-1-i]
      break
  print(ans)

Submission status: Wrong Answer

Solution code:
import math as mh
import fractions as fr

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

x_min = min(x)
x_max = max(x)

d = fr.gcd(abs(p-x_min), abs(x_max-p))
while d < abs(p-x_min) and d < abs(x_max-p):
    d *= 2

print(d)