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:
N, X = map(int, input().split())
x = list(map(int, input().split()))
x_gcd = []
for i in range(N):
    x_gcd.append(X-x[i])


def gcd(a, b):
    while b != 0:
        a, b = b, a%b
    return a
ans = [0]*(N-1)

for i in range(N-1):
    ans[i] = gcd(x_gcd[i], x_gcd[i+1])
if ans:
    print(abs(max(ans)))
else:
    print(x[0] - X)

Submission status: Wrong Answer

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


def gcd(a, b):
    while b != 0:
        a, b = b, a%b
    return a
ans = [0]*(N-1)

for i in range(N-1):
    ans[i] = gcd(x_gcd[i], x_gcd[i+1])
if ans:
    print(max(ans))
else:
    print(x[0] - X)

Submission status: Wrong Answer

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

dir_list = []
for i in x:
    dir_list.append(abs(i - X))
m = 0
for i in range(2,min(dir_list) + 1):
    flag = True
    for j in dir_list:
        if j % i != 0:
            flag = False
            break
    if flag:
        m = i
print(m)

Submission status: Wrong Answer

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

dir_list = []
for i in x:
    dir_list.append(abs(i - X))
m = 0
for i in range(2,min(dir_list) + 1):
    flag = True
    for j in dir_list:
        if j % i != 0:
            flag = False
            break
    if flag:
        m = i
print(m)
print(dir_list)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.append(x)
a = np.array(list(set(a)))
a.sort()
diff = a[1:] - a[:-1]

# print(a - x)
# print(diff)
print(diff.min())

Submission status: Wrong Answer

Solution code:
n,X = map(int,input().split())
x = list(map(int,input().split()))
a = []
for i in range(n):
    a.append(abs(X-x[i]))
    a = sorted(a)
if 0 in a:
    print(a[1])
else:
    print(a[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def f(m,n):
  if min(m,n)<0:
    return f(abs(m),abs(n))
  elif m<n:
    return f(n,m)
  elif m%n==0:
    return n
  else:
    return f(n,m%n)
ans=X[0]-x
for i in range(1,n):
  ans=f(ans,X[i]-x)
print(ans)

Submission status: Wrong Answer

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

x.append(a)
x.sort()

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

"""import fraction
from functools import reduce

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

print(gcd_list(diff_all))
"""

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def gcd(a, b):
	if a > b:
		a, b = b, a
		
	while a > 0:
		a, b = b % a, a
	return b
	
def main():
	N, X = map(int, input().split(" "))
	L = input().split(" ")
	L = [int(s) for s in L]
	
	if N == 1:
		print(abs(L[0]-X))
		sys.exit()
	
	L.sort()
	tmp = bisect_left(L, X)
	
	max1 = 2000000001
	if tmp < len(L):
		max1 = L[tmp]
	
	min1 = 2000000001
	if tmp != 0:
		min1 = L[tmp-1]
	
	seed = 0
	mark = -1
	if abs(max1-X) < abs(X-min1):
		seed = abs(max1-X)
		mark = tmp
	else:
		seed = abs(X-min1)
		mark = tmp-1
	
	ans = 0
	for i, val in enumerate(L):
		if i == mark:
			continue
		tmp = abs(L[i] - L[mark])
		ans = gcd(tmp, seed)
	
	print(ans)
		
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def main():
	N, X = map(int, input().split(" "))
	L = input().split(" ")
	L = [int(s) for s in L]
	
	if N == 1:
		print(abs(L[0]-X))
		sys.exit()
	
	L.sort()
	tmp = bisect_left(L, X)
	
	max1 = 2000000001
	if tmp < len(L):
		max1 = L[tmp]
	
	min1 = 2000000001
	if tmp != 0:
		min1 = L[tmp-1]
	
	ans = min(abs(max1-X), abs(X-min1))
	
	print(ans)
		
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
        
if len(x) < 2:
    print(x[0])
else:
    D = gcd(x[0], x[1])
    for i in range(2, N):
        D = gcd(D, x[2])

    print(D)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
from sys import stdin
N, X = [int(_) for _ in stdin.readline().rstrip().split()]
xs = [int(_) for _ in stdin.readline().rstrip().split()]
xs.sort()
diff = [xs[i] - xs[i-1] if i > 0 else xs[i]-X for i in range(N)]
gcd = reduce(fractions.gcd, diff)
print(gcd)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

inpl = lambda: list(map(int,input().split()))
N, X = inpl()
x = inpl()
y = [ p - X for p in x ]
print(gcd_list(y))

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
x = input().split()
xls = []

for n in range(0,N):
    xls.append(int(x[n]))

xls.append(X)
xls.sort(reverse = True)

tousa = []

for n in range(0,N):
    tousa.append(xls[n]-xls[n+1])

print(min(tousa))

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
x = input().split()
xls = []

for n in range(0,N):
    xls.append(int(x[n]))

roop = min(abs(X-xls[0]),abs(X-xls[N-1]))

print(roop)

Submission status: Wrong Answer

Solution code:
n, x = map(int,input().split())
lx = list(map(int,input().split()))
lx.sort()
ls = [abs(lx[i]-x) for i in range(n)]

print(min(ls))

Submission status: Wrong Answer

Solution code:
import math
def determine_D(x,X):
    min = float('inf')
    cand = []
    for i in range(len(x)):
        cand.append(abs(x[i] - X))
    cand.sort()
    while True:
        for i in cand:
            if i % cand[0] == 0:
                return cand[0]
            else:
                cand[0] = math.gcd(cand[0], i)



def main():
    i = 1
    N, X = map(int, input().split())
    *x, = map(int, input().split())
    print(determine_D(x,X))
main()

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()
def gcd(x,y):
  while y != 0:
    x = y
    y = x%y
  return x
cur = L[0]
for i in range(1,N):
  cur = gcd(L[i],cur)
print(cur)

Submission status: Wrong Answer

Solution code:
def determine_D(x,X):
    min = float('inf')
    for i in range(len(x)):
        if abs(x[i] - X) < min:
            min = abs(x[i] - X)
    return min


def main():
    i = 1
    N, X = map(int, input().split())
    *x, = map(int, input().split())
    print(determine_D(x,X))
main()

Submission status: Wrong Answer

Solution code:
#values
INF = 10**9

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

x_list.append(X)
x_list.sort()
min_d = INF
for i in range(N):
    d = x_list[i+1] - x_list[i]
    min_d = min(min_d,d)
print(min_d)

Submission status: Wrong Answer

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

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

if len(list) >= 3:
    #リストの差を取得
    diff = [b - a for a, b in zip(list, list[1::])]
    diff.sort()
    #差の最大公約数を取得
    gcd_val = diff[0]
    for i in diff[1::]:
        gcd_val = gcd(i,gcd_val)
    print(gcd_val)
elif len(list) == 2:
    print(list[1]-list[0])
#もしリストが1つの場合はそのまま表示
else:
    print(list[0])

Submission status: Wrong Answer

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

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

if len(list) >= 2:
    list.sort()
    #リストの差を取得
    diff = [b - a for a, b in zip(list, list[1::])]
    diff.sort()
    #差の最大公約数を取得
    gcd_val = diff[0]
    for i in diff[1::]:
        gcd_val = gcd(i,gcd_val)
    print(gcd_val)
#もしリストが1つの場合はそのまま表示
else:
    print(list[0])

Submission status: Wrong Answer

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

import sys
input = sys.stdin.readline
N, S = map(int, input().split())
X = list(map(int, input().split()))
if N > 1:
    D = gcd(X[0] - S, X[1] - S)
    for x in X[2:]:
        D = gcd(S - x, D)
    print(D)
else:
    print(abs(S - X[0]))

Submission status: Wrong Answer

Solution code:
import fractions
def gcd(a,b):
    c=fractions.gcd(a,b)
    return c
    
n,x0=map(int,input().split())
x=list(map(int,input().split()))
x.append(x0)
x.sort()
w=[]
for i in range(n):
    w.append(x[i+1]-x[i])
k=w[0]
for i in w:
    ans=gcd(k,i)
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
import fractions

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

xn.sort()
print(xn)
distance = [xn[i]-xn[i-1] for i in range(1,N+1)]
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
print(gcd_list(distance))

Submission status: Wrong Answer

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

min_d = float('inf')
for i in X_list:
    min_d = min(min_d, abs(X - i))

print(min_d)

Submission status: Wrong Answer

Solution code:
import fractions

N,X = (int(x) for x in input().split())
x = [int(p) for p in input().split()]
x.append(X)
x.sort()
D = x[1] - x[0]

for i in range(1,N-1):
    D = fractions.gcd(D,x[i+1]-x[i])

print(D)

Submission status: Wrong Answer

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())
x = list(map(int,input().split()))

x.append(X)
x.sort()
ans = x[1]-x[0]
for i in range(1,N-1):
    ans = gcd(ans,x[i+1]-x[i])
print(ans)

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
xdif = [x[i+1] - x[i] for i in range(N)]
minxdif = min(xdif)
divisor = []
i = 1
for i in range(1,int(minxdif**0.5) + 1):
    if minxdif % i == 0:
        divisor.append(i)
        if i != minxdif//i:
            divisor.append(minxdif//i)
divisor = sorted(divisor)[::-1]
flag = 0
for div in divisor:
    for dif in xdif:
        if dif % div != 0:
            flag = 1
    if flag == 0:
        print(div)
        break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

    x_n = sorted(x_n)
    if len(x_n) == 1:
        print(abs(X-x_n[0]))
        return

    # print(N,X)
    # print(x_n)
    x_0 = x_n[0]
    x_n = [n - x_0 for n in x_n]
    
    D = 0
    
    
    for i in range(len(x_n) - 1):
        a = x_n[i]
        b = x_n[i+1]
        # print(a, b)
        max_kouyaku = gcd(a, b)
        if max_kouyaku >= D:
            D = max_kouyaku

    print(D)
    return





main()

Submission status: Wrong Answer

Solution code:
n,X=[int(i) for i in input().split()]
x=sorted([int(i) for i in input().split()])
ans=min([abs(X-x[i]) for i in range(n)])
for i in range(n):
    if abs(x[i]-X)%ans==1:
        print(1)
        break
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n,X=[int(i) for i in input().split()]
x=sorted([int(i) for i in input().split()])
x.append(X)
x.sort()
ans=10**9
for i in range(n):
    diff=abs(x[i]-x[i+1])
    if ans>diff:
        ans=diff
print(ans)

Submission status: Wrong Answer

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

def main():
    ds = list(map(lambda n: abs(X - n), P))
    d = min(ds)
    while d > 0:
        if all(filter(lambda distance: distance % d == 0, ds)):
            break
        d = d - 1
    print(d)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def main():
    ds = list(map(lambda n: abs(X - n), P))
    d = min(ds)
    for n in range(d, 0, -1):
        d = n
        if all(filter(lambda distance: distance % d == 0, ds)):
            break
    print(d)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,x = map(int, input().split())
X = [int(x) for x in input().split()]
X = [abs(i-x) for i in X]
print(min(X))

Submission status: Wrong Answer

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

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

elif sum(X)%2 != o:
    print(1)

else:
    X.append(x)
    X.sort()
    ans = []
    for i in range(n-1):
        ans.append(X[i+1]-X[i])
    print(min(ans))

Submission status: Wrong Answer

Solution code:
n,cx=map(int,input().split())#city_num,default_location
x=list(map(int,input().split()))
x.sort()
"""
#1
#if cx<=x[0] or cx>=x[-1]:
a=abs(cx-x[0])
b=abs(cx-x[-1])

c=abs(x[0]-x[-1])
d=(min(a,b)+c)
print(d)
#elif x[0]<cx and cx<x[-1]:
"""
m_l=[]
for l in x:
    m_l.append(abs(l-cx))

print(min(m_l))

Submission status: Wrong Answer

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

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

Xi = list(map(int, input().split()))
Xi.sort()
Di = []
found = False
for i in range(N - 1):
    if Xi[i] < X and Xi[i + 1] >= X:
        Di.append(X - Xi[i])
        Di.append(Xi[i  + 1] - X)
        found = True
    else:
        Di.append(Xi[i + 1] - Xi[i])
if not found:
    Di.append(X - Xi[-1])
Dl = len(Di)
if Dl == 0:
    print(abs(X - Xi[0]))
else:
    g = Di[0]
    for i in range(1, Dl):
        g = gcd(g, Di[i])
    print(g)

Submission status: Wrong Answer

Solution code:
_,X,*x=map(int,open(0).read().split());s,*x=sorted(abs(X-t)for t in x)
for t in x:
 while s:t,s=s,s%t
 s=t
print(s)

Submission status: Wrong Answer

Solution code:
from fractions import*
from functools import*
n,x,*a=map(int,open(0).read().split())
b=[abs(a[i+1]-a[i]) for i in range(n-1)]
if b==[]:
    print(a[0]-x)
else:    
    print(reduce(gcd,b))

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


N, X = LI()
X_list = LI()

#  N = 10**5
#  X = 10**9
#  X_list = [i for i in range(1, 10**5, 5)]
if N == 1:
    print(abs(X_list[0] - 1))
    exit()
X_list.sort()

bisect.insort_left(X_list, X)
#  print(X_list)
X_diff = [abs(j-i) for i, j in zip(X_list[:-1], X_list[1:])]
X_diff = list(set(X_diff))
#  result = min(X_diff)
# 全部行けない場合がある
# 1 4 9 など
# すべてステップ幅-1で割り切れなければ不可

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

for i in range(len(X_diff)):
    #  print(i)
    if i == 0:
        result = X_diff[i]
        continue
    
    result = gcd(X_diff[i], result)
#  while True:
#      if all(x % result == 0 for x in X_diff):
#          result = i
#      else:
#          result = [i for i in range(result, 0, -1) if ]

print(result)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


N, X = LI()
X_list = LI()

#  N = 10**5
#  X = 10**9
#  X_list = [i for i in range(1, 10**5, 5)]
if N == 1:
    print(abs(X_list[0] - 1))
    exit()
X_list.sort()

bisect.insort_left(X_list, X)
#  print(X_list)
X_diff = [j-i for i, j in zip(X_list[:-1], X_list[1:])]
X_diff = list(set(X_diff))
#  result = min(X_diff)
# 全部行けない場合がある
# 1 4 9 など
# すべてステップ幅-1で割り切れなければ不可

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

for i in range(len(X_diff)):
    #  print(i)
    if i == 0:
        result = X_diff[i]
        continue
    
    result = gcd(X_diff[i], result)
#  while True:
#      if all(x % result == 0 for x in X_diff):
#          result = i
#      else:
#          result = [i for i in range(result, 0, -1) if ]

print(result)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


N, X = LI()
X_list = LI()
if N == 1:
    print(abs(X_list[0] - 1))
    exit()
X_list.sort()

bisect.insort_left(X_list, X)
#  print(X_list)
X_diff = [j-i for i, j in zip(X_list[:-1], X_list[1:])]
result = min(X_diff)
# 全部行けない場合がある
# 1 4 9 など
# すべてステップ幅-1で割り切れなければ不可

for i in range(1, result+1):
    if all(x % i == 0 for x in X_diff):
        result = i

print(result)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


N, X = LI()
X_list = LI()
if N == 1:
    print(abs(X_list[0] - 1))
    exit()
X_list.sort()

bisect.insort_left(X_list, X)
#  print(X_list)
X_diff = [j-i for i, j in zip(X_list[:-1], X_list[1:])]
result = min(X_diff)
# 全部行けない場合がある
# 1 4 9 など
# すべてステップ幅-1で割り切れなければ不可

results = []
for i in range(1, result+1):
    if all(x % i == 0 for x in X_diff):
        results.append(i)

print(results[-1])

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


N, X = LI()
X_list = LI()
X_list.sort()

bisect.insort_left(X_list, X)
#  print(X_list)
X_diff = [j-i for i, j in zip(X_list[:-1], X_list[1:])]
print(min(X_diff))

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
X = list(map(int,input().split()))
sort_X = sorted(X)
temp = sort_X[0]
mini = float("inf")
D = 1
if(n==1):
    print(999999999-abs(X[0]-x))
elif(n==2):
    mini = min(X[-1]-x,x-X[0])

    for p in range(1,mini+1):
        point = x%p
        flag = True
        for xx in X:
            if(point != xx%p):
                    flag = False
                    break
        if(flag):
            D = p
    print(D)

else:
    for xx in sort_X[1:]:
        if(mini >= xx-temp):
            mini = xx-temp
        temp = xx
    for p in range(1,mini+1):
        point = x%p
        flag = True
        for xx in X:
            if(point != xx%p):
                    flag = False
                    break
        if(flag):
            D = p

    print(D)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
X = list(map(int,input().split()))
sort_X = sorted(X)
temp = sort_X[0]
mini = float("inf")
D = 1
if(n==1):
    print(999999999)
elif(n==2):
    mini = min(X[-1]-x,x-X[0])

    for p in range(1,mini+1):
        point = x%p
        flag = True
        for xx in X:
            if(point != xx%p):
                    flag = False
                    break
        if(flag):
            D = p
    print(D)

else:
    for xx in sort_X[1:]:
        if(mini >= xx-temp):
            mini = xx-temp
        temp = xx
    for p in range(1,mini+1):
        point = x%p
        flag = True
        for xx in X:
            if(point != xx%p):
                    flag = False
                    break
        if(flag):
            D = p

    print(D)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
X = list(map(int,input().split()))
sort_X = sorted(X)
temp = sort_X[0]
mini = max(X[-1]-x,x-X[0])
D = 1
if(n==1):
    print(999999999)
else:
    for xx in sort_X[1:]:
        if(mini >= xx-temp):
            mini = xx-temp
        temp = xx
    for p in range(1,mini+1):
        point = x%p
        flag = True
        for xx in X:
            if(point != xx%p):
                    flag = False
                    break
        if(flag):
            D = p

    print(D)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
X = list(map(int,input().split()))
sort_X = sorted(X)
temp = sort_X[0]
mini = min(X[-1]-x,x-X[0])
D = 1
if(n==1):
    print(999999999)
else:
    for xx in sort_X[1:]:
        if(mini >= xx-temp):
            mini = xx-temp
        temp = xx
    for p in range(1,mini+1):
        point = x%p
        flag = True
        for xx in X:
            if(point != xx%p):
                    flag = False
                    break
        if(flag):
            D = p

    print(D)

Submission status: Wrong Answer

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

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

x.append(X)
x.sort()

ans=x[1]-x[0]

for i in range(N-1):
    ans=gcd(ans,x[i+1]-x[i])

print(ans)

Submission status: Wrong Answer

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

d = []
for i in range(n):
  pre = xf if i == 0 else x[i-1]
  d.append(x[i] - pre)

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

ans = 0
for di in d:
  ans = gcd(ans, di)
print(ans)

Submission status: Wrong Answer

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

def gcd(x, y):
    while (y != 0):
        x, y = y, x%y

    return x

diff = []

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

for j in l:
    diff.append(abs(j - x))

ans = gcd(diff[0], diff[1])

for i in range(2, len(diff)):
    ans = gcd(ans, diff[i])

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions as f

n,x = list(map(int,input().split()))
if n == 1:
    skip = int(input())
    if x == skip:
        print(0)
    else:
        print(abs(x-skip))
else:
    skip = list(map(int,input().split()))
    skip.append(n)
    skip = sorted(skip)
    margin = list()
    for i in range(len(skip)-1):
        margin.append(skip[i+1]-skip[i])
    test = margin[0]
    for i in range(len(margin)):
        test = f.gcd(test,margin[i])
    print(test)

Submission status: Wrong Answer

Solution code:
import fractions as f

n,x = list(map(int,input().split()))
if n == 1:
    skip = int(input())
    if x == skip:
        print(0)
    else:
        print(abs(x-skip))
else:
    skip = list(map(int,input().split()))
    skip.append(n)
    skip = sorted(skip)
    margin = list()
    for i in range(len(skip)-1):
        margin.append(skip[i+1]-skip[i])
    for i in range(len(margin)-1):
        test = f.gcd(margin[i],margin[i+1])
    print(test)

Submission status: Wrong Answer

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

x.append(X)
x.sort()
A = []

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

def gcd(x,y):
    X = max(x,y)
    Y = min(x,y)
    if Y == 0:
        return X
    else:
        return gcd(Y,X%Y)

keepgcd = 0
maxgcd = 10**5
B = []

if N >= 2:
   for i in range(N-2):
       B.append(gcd(A[i+1],A[i]))
       print(min(B))
else:
    print(max(x)-min(x))

Submission status: Wrong Answer

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

x.append(X)
x.sort()
A = []

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

def gcd(x,y):
    X = max(x,y)
    Y = min(x,y)
    if Y == 0:
        return X
    else:
        return gcd(Y,X%Y)

keepgcd = 0
maxgcd = 10**5

if N >= 2:
   for i in range(N-2):
       keepgcd = gcd(A[i+1],A[i])
       if maxgcd >= keepgcd:
          maxgcd = keepgcd
   print(maxgcd)

else:
    print(max(x)-min(x))

Submission status: Wrong Answer

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

x.append(X)
x.sort()
A = []

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

def gcd(x,y):
    X = max(x,y)
    Y = min(x,y)
    if Y == 0:
        return X
    else:
        return gcd(Y,X%Y)

keepgcd = 0
maxgcd = 0

if N >= 2:
   for i in range(N-2):
       keepgcd = gcd(A[i+1],A[i])
       if maxgcd <= keepgcd:
          maxgcd = keepgcd
   print(maxgcd)

else:
    print(max(x)-min(x))

Submission status: Wrong Answer

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

x.append(X)
x.sort()
A = []
for i in range(N-1):
    A.append(x[i+1]-x[i])
A.sort()

ans = 10**5
if N >= 2:
    for i in range(N-2):
        if A[i+1] % A[i] == 0:
           if A[i] <= ans:
              ans = A[i]
    print(ans)
else:
    print(abs(x[-1]-X))

Submission status: Wrong Answer

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

x.append(X)
x.sort()
A = []
for i in range(N-1):
    A.append(x[i+1]-x[i])

ans = 10**5
if N >= 2:
    for i in range(N-2):
        if A[i+1] % A[i] == 0:
           if A[i] <= ans:
              ans = A[i]
    print(ans)
else:
    print(abs(x[-1]-X))

Submission status: Wrong Answer

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

x.append(X)
x.sort()

if N >= 2:
   A = []
   for i in range(N-1):
       A.append(x[i+1]-x[i])

   ans = A[0]
   for i in range(N-2):
       if A[i+1] % A[i] == 0:
          ans = A[i]
       else:
          ans = 1

   print(ans)
else:
    print((max(x)-min(x)))

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
L = []
for i in range(N):
    L.append(abs(X - A[i]))
for i in range(N-1):
    L.append(A[i+1] - A[i])
print(min(L))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import functools
import fractions
N,X = map(int,input().split())
city = [int(c) for c in input().split()]
diff = []
for i in range(N):
    diff.append(city[i]-X)

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

Submission status: Wrong Answer

Solution code:
values = raw_input()
n,x = int(values.split(" ")[0]), int(values.split(" ")[1])
cities = raw_input()
cities = [int(i) for i in cities.split(" ")]

distances = []
for i in cities:
	distances.append(abs(i-x))
print(min(distances))

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
x = list(map(int,input().split()))
x = sorted(x)
dis = float('inf')
for x_ in x:
    dis = min(dis,abs(X-x_))
print(dis)

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
x = list(map(int,input().split()))
x = sorted(x)
dis = 1000000
for x_ in x:
    dis = min(dis,abs(X-x_))
print(dis)

Submission status: Wrong Answer

Solution code:
# C
N, X = map(int, input().split())
x = list(map(int, input().split()))
new_list = list(map(lambda l: abs(l - X), x))
new_list.sort()

min_val = new_list[0]
if all((l % min_val == 0 for l in new_list)):
    print(min_val)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
# C
N, X = map(int, input().split())
x = list(map(int, input().split()))
new_list = list(map(lambda l: abs(l - X), x))
new_list.sort()

min_val = new_list[0]
if all((x % min_val == 0 for x in new_list)):
    print(min_val)
else:
    print(1)