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:
import functools
import fractions

N, X = map(int, input().split())
x = [int(i) for i in input().split()]

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

x.append(X)
x.sort()
print(x)

dist = []
for i in range(N-1):
    dist.append(abs(x[i] - x[i+1]))

gcd = functools.reduce(fractions.gcd, dist)
print(gcd)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

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

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


for i in range(N):
	x[i] = x[i]-X

print(gcd_list(x))

Submission status: Wrong Answer

Solution code:
x=int(input().split()[1])
c=list(map(int,input().split()))+[x]
s=set()

def gcd(a, b=0):
  if b==0: return a
  return gcd(b, a%b)
def ngcd(s):
  m=0
  for i in s: m=gcd(m,i)
  return m

for i in range(len(c)-1): s.add(c[i+1]-c[i])
print(ngcd(sorted(list(s))))

Submission status: Wrong Answer

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

def check(n):
    return abs(n - x)

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

dist = list(map(check, city))
min_dist = min(dist)

if n < 2:
    print(min_dist)
    exit()

dists = []
prev = 0

city.sort()
for pos in city:
    if not prev == 0:
        dists.append(abs(prev - pos))
    prev = pos

new_min = min(dists)

if min_dist % new_min == 0:
    print(new_min)
elif new_min % min_dist == 0:
    print(min_dist)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,X = list(map(int, input().split()))
x = list(map(int, input().split()))
x = np.array(x)
x = x - X

def gcd(a,b):
    while b:
        a, b = b, a%b
    return a
if len(x) > 1:
    a = gcd(x[0],x[1])
    for k in range(1,len(x)):
        a = gcd(a,x[k])
    print(abs(a))
else:
    print(x[0])

Submission status: Wrong Answer

Solution code:
import numpy as np
N,X = list(map(int, input().split()))
x = list(map(int, input().split()))
x = np.array(x)
x = x - X

def gcd(a,b):
    while b:
        a, b = b, a%b
    return a
if len(x) > 1:
    a = gcd(x[0],x[1])
    for k in range(1,len(x)):
        a = gcd(a,x[k])
    print(a)
else:
    print(x[0])

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n,x = list(map(int, input().split()))
x_i = list(map(int, input().split()))
d = x_i[0]
for i in range(n):
    d = gcd(d,x_i[i])
print(d)

Submission status: Wrong Answer

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

def check(n):
    return abs(n - x)

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

dist = list(map(check, city))
min_dist = min(dist)

if n < 2:
    print(min_dist)
    exit()

dists = []
prev = 0

city.sort()
for pos in city:
    if not prev == 0:
        dists.append(abs(prev - pos))
    prev = pos

for l in dists:
    if l > min_dist:
        if l % min_dist != 0:
            print(1)
            exit()
    if l < min_dist:
        if min_dist % l != 0:
            print(1)
            exit()

new_min = min(dists)

if min_dist > new_min:
    print(new_min)
elif new_min >= min_dist:
    print(min_dist)
else:
    print(1)

Submission status: Wrong Answer

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

def check(n):
    return abs(n - x)

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

dist = list(map(check, city))
min_dist = min(dist)

if n < 2:
    print(min_dist)
    exit()

dists = []
prev = 0

city.sort()
for pos in city:
    if not prev == 0:
        dists.append(abs(prev - pos))
    prev = pos

for l in dists:
    if l > min_dist:
        if l % min_dist != 0:
            print(1)
            exit()
    if l < min_dist:
        if min_dist % l != 0:
            print(1)
            exit()

new_min = min(dists)

if min_dist > new_min and min_dist % new_min == 0:
    print(tmp)
elif new_min > min_dist and new_min % min_dist == 0:
    print(min_dist)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
import numpy as np

N,X = map(int,input().split())
town_list = np.array(list(map(int,input().split())))
print(min(abs(town_list - X)))

Submission status: Wrong Answer

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

def check(n):
    return abs(n - x)

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

dist = list(map(check, city))
min_dist = min(dist)

if n < 2:
    print(min_dist)
    exit()

dists = []
prev = 0

city.sort()
for pos in city:
    if not prev == 0:
        dists.append(abs(prev - pos))
    prev = pos

for l in dists:
    if l > min_dist:
        if l % min_dist == 0:
            print(1)
            exit()
    if l < min_dist:
        if min_dist % l == 0:
            print(1)
            exit()

new_min = min(dists)

if min_dist > new_min and min_dist % new_min == 0:
    print(tmp)
elif new_min > min_dist and new_min % min_dist == 0:
    print(min_dist)
else:
    print(1)

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()
val = 0
#print lis
for i in range(1, n):
    val = gcd(val, lis[i]-lis[i-1])
print val

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().rstrip().split())
x = []
x = list(map(int,input().rstrip().split()))
x.append(X)
x = sorted(x)
if N==1:
	print(abs(X-x[0]))
	exit()
mini = x[1] - x[0]
for i in range(len(x)-1):
	if mini > x[i+1] - x[i]:
		mini =  x[i+1] - x[i]
print(mini)

Submission status: Wrong Answer

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

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()
xa=list(set(x))
y=[]

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

ya=list(set(y))
m=len(ya)
z=ya[0]
i=0
while i < m:
    z=fractions.gcd(z,ya[i])
    i+=1

print(z)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
arr = list(map(int, input().split()))
arr_sort = sorted(arr)

ans = -1
previous = -1

for ele in arr_sort:
    if previous < 0:
        previous = ele
    else:
        elediff = abs(ele - previous)
        if ans < 0 or elediff < ans:
            ans = elediff
        previous = ele

    xdiff = abs(X - ele)
    if ans < 0 or xdiff < ans:
        ans = xdiff


print(ans)

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
L = list(map(int,input().split()))
counter = 0
L.append(X)
L = sorted(L)
D = []
for i in range(len(L)) :
    d = L[i]-L[i-1]
    if i != 0 :
        D.append(d)
#print(D)
D = sorted(D)
qq = min(D)
for j in range(len(D)-1) :
    if D[j+1] % qq == 0 :
        counter += 1

if counter == (len(D)-1) :
    print(qq)
else :
    print(1)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
 
arr = [int(_) for _ in input().split(' ')]
arr.sort()
 
a = 1000000000000
 
 
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)

for k in range(N):
    if abs(arr[k]-X) % a != 0:
        a = 1
 
print(a)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import sys
N, X = map(int, input().split())
lis_map = list(map(int, input().split()))

lis_ans=[]
for m in lis_map:
    tmp = abs(X - m)
    lis_ans.append(tmp)

print(min(lis_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(1,N):
	p_sa = x[i]-x[i-1]

	chk2 = 0
	for m in range(N):
		if((x[m]-X)%p_sa!=0):
			break
		else:
			chk2 += 1
	if(chk2==N):
		if(p_sa>maxi):
			maxi = p_sa

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

sa = abs(x[N-1]-X)
chk = 0
for j in range(N):
	if((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:
n,x = map(int, input().split())

def check(n):
    return abs(n - x)

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

dist = list(map(check, city))
min_dist = min(dist)

if n < 2:
    print(min_dist)
    exit()

dists = []
prev = 0

city.sort()
for pos in city:
    if not prev == 0:
        dists.append(abs(prev - pos))
        if abs(prev - pos) > min_dist:
            if abs(prev -pos) % min_dist != 0:
                print(1)
                exit()
    prev = pos

tmp = min(dists)

if min_dist > tmp and min_dist % tmp == 0:
    print(tmp)
elif tmp % min_dist == 0:
    print(min_dist)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
x = list(map(int,input().split()))
 
x.append(m)
x.sort()
 
if len(x) == 1:
    print(abs(x[0]-m))
else:
    aa = []
    for i in range(len(x) - 1):
        a = x[i+1] - x[i]
        aa.append(a)
    print(min(aa))

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
  if y==0:
    return x
  return gcd(y,x%y)
n,x=map(int,input().split())
cities=list(map(int,input().split()))
if len(cities)==1:
  print(abs(cities[0])-x)
else:
  res=abs(cities[0]-x)
  for city in cities[1:]:
    res=gcd(res,abs(city-x))
  print(res)

Submission status: Wrong Answer

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

for i in range(N):
    L[i] = L[i] - X
L.insert(0,0)
L.sort()

res = 40000000000
for i in range(N):
    if (abs(L[i + 1] - L[i]) < res) and (L[i + 1] - L[i]!= 0):
        res = abs(L[i + 1] - L[i])

print(res)

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().rstrip().split())
x = []
x = list(map(int,input().rstrip().split()))
x.append(X)
x = sorted(x)
mini = x[1] - x[0]
for i in range(len(x)-1):
	if mini >= x[i+1] - x[i]:
		mini =  x[i+1] - x[i]
print(mini)

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()))
x_list.append(X)
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:
N, X = map(int, input().split())
L = list(map(int, input().split()))

for i in range(N):
    L[i] = L[i] - X
L.insert(0,0)
L.sort()

res = 2000000000
for i in range(N):
    if (abs(L[i + 1] - L[i]) < res) and (L[i + 1] - L[i]!= 0):
        res = abs(L[i + 1] - L[i])

print(res)

Submission status: Wrong Answer

Solution code:
def factorize(num):
    f_ary=[num]
    for i in xrange(num-1, 2, -1):
#        print i, "before", f_ary
        div = num / i
        if i * div == num:
#            print f_ary
            if i in f_ary:
                break
            else:
                f_ary.append(i)
            if div in f_ary:
                break
            else:
                f_ary.append(div)
#        print "after", f_ary

    f_ary.append(1)
#    print "last", f_ary
    return f_ary

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

points=map(int,raw_input().split())
#for i in range(len(points)):
#    dist.append(abs(points[i] -X))
for i in range(len(points)):
    points[i] = abs(points[i] -X)

#points.sort()
points.reverse()

factors = factorize(points[0])


#print N,X, points, factors

for f in factors:
#    print f
    judge = 'Yes'
    for p in points:
        if p % f != 0:
#            print "NG:", p, f
            judge = 'No'
            break
    if judge == 'Yes':
        break

print f

Submission status: Wrong Answer

Solution code:
def f(x,y):
    if y>x:
        t=x
        x=y
        y=t
    while y!=0 and x!=y:
        t=y
        y=x%y
        x=t
    return x
    
n,x=[int(s)for s in input().split(" ")]
co=[int(s)for s in input().split(" ")]
co=sorted(co)
mi=1145141919810 if n!=1 else co[0]-x 
for i in range(n-1):
    if mi==1:break
    for j in range(i+1,n-i):
        mi=min(f(abs(co[i]-x),abs(co[j]-x)),mi)
print(mi)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
def fun():
    nx = input()
    N, X = nx.split(' ')
    N = int(N)
    X = int(X)
    cities = [int(c) for c in input().split(' ')]
    cities.append(X)
    x = sorted(cities)
    nx = x[1:]
    dist = [nn - x[i] for i, nn in enumerate(nx)]
    min_gcd = 10000000000
    for i, d in enumerate(dist[:-1]):
        dp = dist[i+1]
        gc = gcd(d, dp)
        if gc < min_gcd:
            min_gcd = gc
    print(min_gcd)

fun()

Submission status: Wrong Answer

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

for i in range(N):
    L[i] = L[i] - X
L.insert(0,0)
L.sort()

res = 2000000000
for i in range(N):
    if (L[i + 1] - L[i] < res) and (L[i + 1] - L[i]!= 0):
        res = abs(L[i + 1] - L[i])

print(res)

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 (max(L[0],p) % min(L[0],p) != 0):
      print('1')
    else:
      if (L[0] >= p):
        del L[0]
        L.append(p)
        print(L[0])

Submission status: Wrong Answer

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(1,num):
        if num%i==0:
            yakusuu_list.append(i)
    return yakusuu_list


for i in range(N):
    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

if len(D_list)==0:
    for i in range(len(temp)):
        D_test=yakusuu(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: Wrong Answer

Solution code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = []
d = []
co = 0
for i in range(a[0]):
	c.append(b[i]-a[1])
	if b[i]-a[1] > 0 and co == 0:
		c.insert(i,0)
		co += 1
if co == 0:
	c.append(0)

for i in range(len(c)-1):
	d.append(abs(c[i+1]-c[i]))
k = min(d)
for i in range(len(d)):
	if d[i] % k != 0:
		d[0] = 1
		break
print(d[0])

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
arr = list(map(int, input().split()))
arr_sort = sorted(arr)

ans = -1
previous = -1

for ele in arr_sort:
    if previous < 0:
        previous = ele
    else:
        elediff = ele - previous
        if ans < 0 or elediff < ans:
            ans = elediff
        previous = ele

    xdiff = abs(X - ele)
    if ans < 0 or xdiff < ans:
        ans = xdiff

print(ans)

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)


for i in range(min_distance,0,-1):
    Can_go_list=list(map(lambda z: 1 if z % i == 0 else 0,first_distance))

    if 1 not in Can_go_list:
        ans = i
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
n,x = map(int, input().split() )
y = list(map(int,input().split()))
z = [0]*n

for i in range(n) :
   y[i] = abs(y[i]-x)

y.sort()

for i in range(n-1) :
   y[i] = y[i+1]-y[i]

for j in range(min(y),0,-1) :
   for i in range(n) :
      z[i] = y[i]%j

   if z == [0]*n :
      print(j)
      break

Submission status: Wrong Answer

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

for i in range(N):
    
    if x[i] < X:
        x[i]=X-x[i]
    else :
        x[i]=x[i]-X

x=set(x)
x=list(x)
x.sort()

for i in range (len(x)):
    if i==0:
        yakusu=x[i]
    else :
        if x[i]%yakusu!=0:
            n=2
            while True:
                if yakusu%n==0:
                    yakusu=yakusu/n
                    if x[i]%yakusu==0:
                        break
                else :
                    n=n+1
                    
yakusu=int(yakusu)                    
print(yakusu)

Submission status: Wrong Answer

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

xi=[int(i) for i in input().split()]

ans1=1000000000
ans2=1000000000


L=[]
L2=[]
if N>1:
    for i in range(0,len(xi)):
        if i<len(xi)-1:
            L.append(abs(xi[i]-xi[i+1]))
        
        L2.append(abs(xi[i]-X))
    
    ans1=min(L)
    ans2=min(L2)

else:
    ans1=abs(xi[0]-X)


if ans1>ans2:
    ans=ans2
else:
    ans=ans1

for i in L:
    if i%ans!=0:
        ans=1
for i in L2:
    if i%ans!=0:
        ans=1

print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    L[i] = L[i] - X

L.sort()
L.insert(0,0)
res = 2000000000
for i in range(N):
    if (L[i + 1] - L[i] < res) and (L[i + 1] - L[i]!= 0):
        res = abs(L[i + 1] - L[i])

print(res)

Submission status: Wrong Answer

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)):
    D.append(abs(x[i-1] - x[i-2]))
    D.append(abs(x[i-1] + x[i]))
print(min(D))

Submission status: Wrong Answer

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

x.append(X)
x.sort()
m = 10000000000
for i in range(N):
    t = abs(x[i+1] - x[i])
    if t < m :
        m = t
for i in range(N):
    if x[i] % m != 0 and x[i] != X:
        print(1)
        exit()
print(m)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
def fun():
    nx = input()
    N, X = nx.split(' ')
    N = int(N)
    X = int(X)
    cities = [int(c) for c in input().split(' ')]
    cities.append(X)
    x = sorted(cities)
    nx = x[1:]
    dist = [nn - x[i] for i, nn in enumerate(nx)]
    min_gcd = 1000000000
    for i, d in enumerate(dist[:-1]):
        dp = dist[i+1]
        gc = gcd(d, dp)
        if gc < min_gcd:
            min_gcd = gc
    print(min_gcd)

fun()

Submission status: Wrong Answer

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

maxi = 0

sa_list = []

for i in range(1,N):
	p_sa = x[i]-x[i-1]
	sa_list.append(p_sa)

	chk2 = 0
	for m in range(N):
		if((x[m]-X)%p_sa!=0):
			break
		else:
			chk2 += 1
	if(chk2==N):
		if(p_sa>maxi):
			maxi = p_sa

for i in range(N):
	sa = abs(x[i]-X)
	
	chk = 0
	for j in range(N):
		if((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:
def f(x,y):
    if y>x:
        t=x
        x=y
        y=t
    while y!=0 and x!=y:
        t=y
        y=x%y
        x=t
    return x
    
n,x=[int(s)for s in input().split(" ")]
co=[int(s)for s in input().split(" ")]
co=sorted(co)
mi=1145141919810
for i in range(n-1):
    for j in range(i+1,n-i):
        mi=min(f(abs(co[i]-x),abs(co[j]-x)),mi)
print(mi)

Submission status: Wrong Answer

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(1,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(temp)):
        D_test=yakusuu(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: Wrong Answer

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

def check(n):
    return abs(n - x)

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

dist = list(map(check, city))
min_dist = min(dist)

if n < 2:
    print(min_dist)
    exit()

dists = []
prev = ''

city.sort()
for pos in city:
    if not prev == '':
        dists.append(abs(prev - pos))
    prev = pos

tmp = min(dists)

if min_dist > tmp and min_dist % tmp == 0:
    print(tmp)
elif tmp % min_dist == 0:
    print(min_dist)
else:
    print(1)

Submission status: Wrong Answer

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()
L.insert(0,0)
res = 2000000000
for i in range(N):
    if (L[i + 1] - L[i] < res) and (L[i + 1] - L[i]!= 0):
        res = L[i + 1] - L[i]

print(res)

Submission status: Wrong Answer

Solution code:
list1 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
list2 = list(map(int, input().split()))
list2.append(x)
list2.sort()

list3 = []
list4 = []
length = len(list2)
index =1
while index < length:
    if list2[index] ==x or list2[index-1]==x:
        list4.append(list2[index]-list2[index-1])
    else:
        list3.append(list2[index]-list2[index-1])
    index+=1
list3.append(min(list4))
list3.append(min(list4)+max(list4))

list3.sort()
mimN = list3[0]
ans =0
index2 =mimN
if len(list3) ==1:
    print(mimN)
else:
    flag2 =0
    for number in list3:
       if number%mimN !=0:
           flag2 =1
    if flag2 ==0:
        print(mimN)
    else:
        while index2>=1:
            flag=0
            for number in list3:
                if number%index2 ==0:
                    flag =1
                else:
                    flag =0
            if flag ==1:
                ans = index2
                break
            else:
                index2-=1

Submission status: Wrong Answer

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

x.append(X)
x.sort()
m = 10000000000
for i in range(N):
    t = abs(x[i+1] - x[i])
    if t < m :
        m = t
for i in range(N+1):
    if x[i] % m != 0:
        print(1)
        exit()
print(m)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
arr = list(map(int, input().split()))
arr_sort = sorted(arr)

ans = -1
previous = -1

for ele in arr_sort:
    if previous < 0:
        previous = ele

    elediff = ele - previous
    if ans < 0 or elediff < ans:
        ans = elediff

    xdiff = abs(X - ele)
    if ans < 0 or xdiff < ans:
        ans = xdiff

    previous = ele

print(ans)

Submission status: Wrong Answer

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
if len(xs) > 1:
    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(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(len(xs)):
            if (abs(xs[i]-X)) % mindist != 0:
                mindist = 1
                break

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

print(mindist)

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)]
	def gcd(a,b):
		while b>0:
			a,b=b,a%b
		return a
	def GCD(LIST):
		if len(LIST)==2:
			return gcd(LIST[0],LIST[1])
		else:
			return([gcd(LIST[0],LIST[1])]+LIST[2::])
	print(GCD(LL))

Submission status: Wrong Answer

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

maxi = 0

sa_list = []

for i in range(1,N):
	p_sa = x[i]-x[i-1]
	sa_list.append(p_sa)
sa_list.sort()
sa_list.reverse()


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

for n in range(len(sa_list)):
	chk2 = 0
	for m in range(N):
		if((x[m]-X)%sa_list[n]!=0):
			break
		else:
			chk2 += 1
	if(chk2==N):
		if(sa_list[n]>maxi):
			maxi = sa_list[n]

print(maxi)

Submission status: Wrong Answer

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)):
    D.append(abs(x[i-1]-x[i]))
print(min(D))

Submission status: Wrong Answer

Solution code:
a = input().split()
n = int(a[0])
x = 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(min(tmp))

Submission status: Wrong Answer

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

x.append(X)
x.sort()
m = 10000000000
for i in range(N):
    t = abs(x[i+1] - x[i])
    if t < m :
        m = t
print(m)

Submission status: Wrong Answer

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

def check(n):
    return abs(n - x)

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

dist = list(map(check, city))
min_dist = min(dist)

if n < 2:
    print(min_dist)
    exit()

dists = []
prev = ''

for pos in city:
    if not prev == '':
        dists.append(abs(prev - pos))
    prev = pos

tmp = min(dists)

if min_dist > tmp and min_dist % tmp == 0:
    print(tmp)
elif tmp % min_dist == 0:
    print(min_dist)
else:
    print(1)

Submission status: Wrong Answer

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(1,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

for i in range(len(temp)):
    D_test=yakusuu(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: Wrong Answer

Solution code:
def euclid(a, b):
    if a < b:
        a, b = (b, a)

    while True:
        r = a % b
        if r == 0:
            break
        a, b = (b, r)

    return b


if __name__ == '__main__':
    n, x = tuple(map(int, input().split()))
    points = [int(x) for x in input().split()]
    if not x in points:
        points.append(x)

    buf = [abs(points[i + 1] - points[i]) for i in range(len(points) - 1)]
    while len(buf) > 1:
        print(buf)
        buf = [euclid(buf[i + 1], buf[i]) for i in range(len(buf) - 1)]

    print(buf[0])

Submission status: Wrong Answer

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
if len(xs) > 1:
    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

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

print(mindist)

Submission status: Wrong Answer

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()
L.insert(0,0)
res = 2000000000
for i in range(N):
    if (L[i + 1] - L[i] < res):
        res = L[i + 1] - L[i]

print(res)

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
L = list(map(int,input().split()))
counter = 0
L.append(X)
L = sorted(L)
D = []
for i in range(len(L)) :
    d = L[i]-L[i-1]
    if i != 0 :
        D.append(d)
#print(D)
D = sorted(D)
qq = min(D)
for j in range(len(D)-1) :
    if D[j+1] % qq == 0 :
        counter += 1
if counter == len(D)-1 :
    print(qq)
else :
    print(1)

Submission status: Wrong Answer

Solution code:
n,x = list(map(int, input().split()))
x_i = list(map(int, input().split()))
a = []
ans = 0
for i in x_i:
    a.append(abs(i - x))
b = max(a)
x_i.sort()
c = abs(x_i[0] - x_i[-1])
print(abs(b - c))