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:
from fractions import gcd
n,x=map(int,input().split())
X=list(map(int,input().split()))

X.sort()
for i in range(n):
  if X[i]>=x:
    break
mae=X[:i]+[x]
ato=[x]+X[i:]
maesa=[0]*(len(mae)-1)
for i in range(1,len(mae)):
  maesa[i-1]=mae[i]-mae[i-1]
atosa=[0]*(len(ato)-1)
for i in range(1,len(ato)):
  atosa[i-1]=ato[i]-ato[i-1]

maeans = maesa[0] if len(maesa)>=1 else 0
atoans = atosa[0] if len(atosa)>=1 else 0
if len(maesa)>=2:
  for i in range(1,len(maesa)):
    maeans=gcd(maeans,maesa[i])
if len(atosa)>=2:
  for i in range(1,len(atosa)):
    atoans=gcd(atoans,atosa[i])
if len(maesa)==0 or len(atosa)==0:
  print(max(maeans,atoans))
else:
  print(gcd(maeans,atoans))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n,x=map(int,input().split())
X=list(map(int,input().split()))

X.sort()
for i in range(n):
  if X[i]>=x:
    break
mae=X[:i]+[x]
ato=[x]+X[i:]
maesa=x
for i in range(1,len(mae)):
  maesa=min(maesa,mae[i]-mae[i-1])
atosa=ato[-1]
for i in range(1,len(ato)):
  atosa=min(atosa,ato[i]-ato[i-1])
if len(mae)==1 or len(ato)==1:
  print(max(maesa,atosa))
else:
  print(gcd(maesa,atosa))

Submission status: Wrong Answer

Solution code:
n,*x=map(int,open(0).read().split())
x.sort()
a=[i-j for i,j in zip(x[1:],x[:-1])]
set(a)
a.sort()
b=[i for i in a if i%a[0]]
b.append(a[0])
if len(b)==1:
    print(*b)
else:
    print(2)

Submission status: Wrong Answer

Solution code:
n,*x=map(int,open(0).read().split())
x.sort()
a=[i-j for i,j in zip(x[1:],x[:-1])]
set(a)
a.sort()
b=[i for i in a if i%a[0]]
b.append(a[0])
if len(b)==1:
    print(*b)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
n,*x=map(int,open(0).read().split())
x.sort()
a=[i-j for i,j in zip(x[1:],x[:-1])]
set(a)
print(min(a))

Submission status: Wrong Answer

Solution code:
import math
import fractions
n,x = map(int,input().split())
x  =[int(i) for i in input().split()]
dec = []
for i in range(1,n):
    j = abs(x[i-1]-x[i])
    dec.append(j)
if len(dec) >0:
    ans = dec[0]
else:
    pass
for i in range(1,n-1):
    ans = fractions.gcd(ans,dec[i])
if len(dec)>1:
    print(ans)
else:
    print(x[0]-1)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
d = 10 ** 9
for i in range(N):
    d = min(d, x[i+1] - x[i])

print(d)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
dx = list(map(lambda x: x-X, x))
d_min = min(list(map(lambda x: abs(x), dx)))
d = d_min
for i in range(N-1):
    d = min(d, dx[i+1] - dx[i])

print(d)

Submission status: Wrong Answer

Solution code:
n, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
minX = 10**9

for _x in x:
        if abs(_x - X) != 0:
                minX = min(minX, abs(_x - X))
print(minX)

Submission status: Wrong Answer

Solution code:
n, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
minX = 10**9

for _x in x:
        minX = min(minX, abs(_x - X))
print(minX)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
x1=list(map(int,input().split()))+[X]
x2=list(set(x1))
x=sorted(x2)
N=len(x)
min=1e+15
for i in range(N-1):
  dif=x[i+1]-x[i]
  if min>dif:min=dif
print(min)

Submission status: Wrong Answer

Solution code:
line = raw_input()
N, X = [int(s) for s in line.split(' ')]
line = raw_input()
xs = [int(s) for s in line.split(' ')]
xs.append(X)
xs = [x - X for x in xs]
xs.sort()
X = 0
if len(xs) == 1:
    print abs(xs[0])
else:
    sub = [a - b for a, b in zip(xs[1:], xs)]
    abs_sub = [abs(s) for s in sub]
    max_s = max(abs_sub)
    min_s = min(abs_sub)
    mod = 1
    while mod > 0:
        mod = max_s % min_s
        max_s = min_s
        min_s = mod
    print max_s

Submission status: Wrong Answer

Solution code:
line = raw_input()
N, X = [int(s) for s in line.split(' ')]
line = raw_input()
xs = [int(s) for s in line.split(' ')]

xs = [x - X for x in xs]
X = 0
if len(xs) == 1:
    print abs(xs[0])
else:
    sub = [a - b for a, b in zip(xs[1:], xs)]
    abs_sub = [abs(s) for s in sub]
    max_s = max(abs_sub)
    min_s = min(abs_sub)
    mod = 1
    while mod > 0:
        mod = max_s % min_s
        max_s = min_s
        min_s = mod
    print max_s

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(n):
    d.append(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 = sorted(x)

min_v = 10 ** 10
for i in range(N):
    min_v = min(min_v, abs(x[i] - x[i+1]))

print(min_v)

Submission status: Wrong Answer

Solution code:
import sys
N, X = map(int, input().split())
x = sorted(list(map(lambda x:int(x) - X, input().split())))
y = []

if N == 1:
  print (abs(x[0]))
  sys.exit()
for i in range(N-1):
  y.append(x[i+1]-x[i])

def gcd(a, b):
  if a < b:
    a, b = b, a
  a, b = b, a % b
  if b == 0:
    return a
  else:
    return gcd(a, b)
ans = y.pop()
while y:
  ans = gcd(ans, y.pop())
print (ans)

Submission status: Wrong Answer

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

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

    else:
        return gcd(b, a % b)

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

else:
    output = gcd(abs(x - X[0]), abs(X[0] - X[1]))

for i in range(1, n - 1):
    tmp = abs(X[i] - X[i + 1])
    output = gcd(output, tmp)

print(output)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
lst = list(map(int, input().split()))
ans = []
for i in lst:
    ans.append(abs(i-X))
small = min(ans)
for i in ans:
    if i%small == 0:
        continue
    else:
        print(1)
        exit()
print(small)

Submission status: Wrong Answer

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

cityList = [abs(X-int(i)) for i in input().split()]

max_D = min(cityList)

while max_D > 1:
    for city in cityList:
        if city % max_D != 0:
            max_D -= 1
            break
    break
print(max_D)

Submission status: Wrong Answer

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

cityList = [abs(X-int(i)) for i in input().split()]
flag = False

max_D = min(cityList)

while max_D > 1:
    for city in cityList:
        if city % max_D != 0:
            max_D -= 1
            break
        flag = True
    if flag == True:
        break
print(max_D)

Submission status: Wrong Answer

Solution code:
import numpy as np

def q74(N, X, x):
    y = np.array(x)
    return min(abs(y - X))


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


print(q74(N, X, x))

Submission status: Wrong Answer

Solution code:
import fractions

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

xXMin = abs(X - x[n-1])
xxMin = 10**10

if n != 1:
    for i in range(n-1):
        if xXMin > abs(X-x[i]):
            xXMin = abs(X-x[i])
        if xxMin > abs(x[i+1]-x[i]):
            xxMin = abs(x[i+1]-x[i])
    print(fractions.gcd(xXMin, xxMin))
else:
    print(abs(X - x[n-1]))

Submission status: Wrong Answer

Solution code:
import math

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

xXMin = abs(X - x[n-1])
xxMin = 10**10

if n != 1:
    for i in range(n-1):
        if xXMin > abs(X-x[i]):
            xXMin = abs(X-x[i])
        if xxMin > abs(x[i+1]-x[i]):
            xxMin = abs(x[i+1]-x[i])
print(min(xXMin, xxMin))

Submission status: Wrong Answer

Solution code:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

from fractions import gcd

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

X.append(M)
X.sort()

diff = []
for i in range(1, N+1):
    diff.append(X[i] - X[i-1])

#print(diff)

gc = diff[0]
for i in range(len(diff)-1):
    gc = (gcd(gc, diff[i]))

print(gc)

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

X.append(M)
X.sort()

diff = []
for i in range(1, N+1):
    diff.append(X[i] - X[i-1])

print(min(diff))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    n,x=map(int,input().split())
    A=list(map(lambda y:int(y)-x,input().split()))
    if n==1:
        print(A[0])
        return
    from fractions import gcd
    from functools import reduce
    print(abs(reduce(gcd,A)))
resolve()

Submission status: Wrong Answer

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

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

#x_list.append(X)
x_list_new=sorted(x_list)
x_list_new_dif=[abs(x_list_new[i]-X) for i in range(len(x_list_new))]

skip=x_list_new_dif[0]
for i in range(1,len(x_list_new_dif)-1):
    skip=gcd(skip,x_list_new_dif[i])
print(skip)

Submission status: Wrong Answer

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

x_list.append(X)
x_list_new=sorted(x_list)
x_list_new_dif=[x_list_new[i+1]-x_list_new[i] for i in range(len(x_list_new)-1) if x_list_new[i+1]-x_list_new[i]!=0]

print(min(x_list_new_dif))

Submission status: Wrong Answer

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

x_list.append(X)
x_list_new=sorted(x_list)
x_list_new_dif=[x_list_new[i+1]-x_list_new[i] for i in range(len(x_list_new)-1)]

print(min(x_list_new_dif))

Submission status: Wrong Answer

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

x_list.append(X)
x_list_new=sorted(x_list)
x_list_new_dif=[x_list_new[i+1]-x_list_new[i] for i in range(len(x_list_new)-1)]

min(x_list_new_dif)

Submission status: Wrong Answer

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

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

if n==1:
  print(abs(x[0]-s))
else:
  x = sorted(x)
  next_dist = [x[i+1]-x[i] for i in range(n-1)]
  near_start = min([abs(s-x[i]) for i in range(n)])

  print(gcd(near_start, min(next_dist)))

Submission status: Wrong Answer

Solution code:
import fractions

N,X=map(int,input().split())
x=list(map(int,input().split()))+[X]
x.sort()
#print(x)

y=[]
for i in range(N):
  y.append(x[i+1]-x[i])
#print(y)

max_gcd=y[0]
for i in range(N-1):
  max_gcd=fractions.gcd(max_gcd,y[i])
print(max_gcd)

Submission status: Wrong Answer

Solution code:
import fractions

N,X=map(int,input().split())
x=list(map(int,input().split()))+[X]
x.sort()
#print(x)

y=[]
for i in range(N):
  y.append(x[i+1]-x[i])
#print(y)

max_gcd=0
for i in range(N-1):
  max_gcd=max(max_gcd,fractions.gcd(max_gcd,y[i]))
print(max_gcd if N!=1 else y[0])

Submission status: Wrong Answer

Solution code:
import fractions

N,X=map(int,input().split())
x=list(map(int,input().split()))+[X]
x.sort()
print(x)

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

max_gcd=0
for i in range(N-1):
  max_gcd=max(max_gcd,fractions.gcd(max_gcd,y[i]))
print(max_gcd if N!=1 else y[0])

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
  if y == 0:
    return x
  else:
    return gcd(y,x%y)
n,x = map(int,input().split())
X = list(map(int,input().split())) + [x]
X.sort()
Dif_X = []
for i in range(n):
    Dif_X += [X[i+1]-X[i]]
gcd_Dif_X = Dif_X[0]
for i in range(n-1):
    gcd_Dif_X = gcd(gcd_Dif_X,Dif_X[i])
print(gcd_Dif_X)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
x = list(map(int, input().split()))
ans = []
for i in range(0, N):
    ans.append(abs(x[i]-X))
print(min(ans))

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
x = list(map(int, input().split()))
ans = 1000000000
for i in x:
    ans = min(ans, abs(i-X))
print(ans)

Submission status: Wrong Answer

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

from fractions import gcd

ans = X[0]-x
for i in range(n):
  ans = gcd(ans,X[i]-x)
  
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC109 C - Skip
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 10**11
t = 0
for i in range(n):
    t = abs(x[i]-k)
    if t==0:
        continue
    ans = min(ans,t)
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC109 C - Skip
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 10**11
for i in range(n):
    ans = min(ans,abs(x[i]-k))
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC109 C - Skip
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 10**10
for i in range(n):
    ans = min(ans,abs(x[i]-k))
print(ans)

Submission status: Wrong Answer

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

'''考え方
都市の位置をソートする
距離を全て計算
距離の最大公約数を計算
'''
  
list_x.sort()
list_dist = []

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

for i,city in enumerate(list_x):
  if (i == len(list_x) - 1):
    continue
  
  list_dist.append(list_x[i+1] - list_x[i])
  

## 上記で求めたリストから最大公約数を求める
import fractions
ans = list_dist[0]
for i in range(1, N-1):
    ans = fractions.gcd(ans, list_dist[i])

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N,X = map(int,input().split())
x = sorted(list(map(int,input().split())))
if x[0]>X:print(x[-1]-X)
elif x[-1]<X:print(X-x[0])
else:print(gcd(abs(x[-1]-X),abs(x[0]-X)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N,X = map(int,input().split())
x = sorted(list(map(int,input().split())))
print(gcd(abs(x[-1]-X),abs(x[0]-X)))

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd

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

print(x,reduce(gcd,x))

Submission status: Wrong Answer

Solution code:
def gcd(a, b):#a,bは０以上の整数
  if a < b:
    a, b = b, a
  if b == 0:
    return a
  while(True):
    a, b = b, a%b
    if b == 0:
      break
  return a
    


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

x = [(x[i] - X) for i in range(N)]
x = sorted(x)
m = x[0]
x = [(x[i] - x[0]) for i in range(N)]
g = 0
if N == 1:
  print(m)
else:
  g = gcd(x[0], x[1])
  for i in range(2, N):
    g = gcd(g, x[i])
  print(g)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):#a,bは０以上の整数
  if a < b:
    a, b = b, a
  if b == 0:
    return a
  while(True):
    a, b = b, a%b
    if b == 0:
      break
  return a
    


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

x = [(x[i] - X) for i in range(N)]
x = sorted(x)
x = [(x[i] - x[0]) for i in range(N)]
g = 0
if N == 1:
  print(x[0])
else:
  g = gcd(x[0], x[1])
  for i in range(2, N):
    g = gcd(g, x[i])
  print(g)