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 math
import sys
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

zahyo = list(map(lambda x : int(x),input().split()))

zahyo.append(x)
zahyo.sort()

min = zahyo[1] - zahyo[0]

is_odd = False
is_even = False


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

    if diff % 2 == 0:
        is_even == True
    else:
        is_odd = True

    if diff < min:
        min = diff


if is_odd == True and is_even == True:
    print(1)
else:
    print(min)

Submission status: Wrong Answer

Solution code:
import numpy as np

def get_nearest_value(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

n,x = list(map(int, input().split()))
x_i = list(map(int, input().split()))
print(abs(get_nearest_value(x_i, x) - 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):
  a.append(x[i+1]-x[i])
  
g = []
h = min(a)
for i in range(1,h+1):
  if h%i == 0:
    g.append(i)
    
gcd = []
for i in g:
  if all(a[j]%i == 0 for j in range(n)):
    gcd.append(g)
    
print(max(gcd))

Submission status: Wrong Answer

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

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

zahyo = list(map(lambda x : int(x),input().split()))

zahyo.append(x)
zahyo.sort()

min = zahyo[1] - zahyo[0]

is_odd = False
is_even = False


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

    if diff % 2 == 0:
        is_even == True
    else:
        is_odd = True

    if diff < min:
        min = diff


if is_odd == True and is_even == True:
    print(1)
else:
    print(min)

Submission status: Wrong Answer

Solution code:
n, x = list(map(int, input().split()))
cities = list(map(int, input().split()))
cities.append(x)
cities.sort()
d = 100000000000
prev = 0
for i in cities:
    if prev != 0:
        dif = abs(prev - i)
        if dif < d:
            d = dif
    prev = i
print(d)

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
for i in range(len(xl)-1):
    one_sa = xl[i+1] - xl[i]
    if onesam == 0:
        onesam = 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 i in range(2,short):
                    if short % i == 0:
                        short = short // i
            if short == 1:
                onesam = 1
                break
            else:
                onesam = short
print(onesam)

Submission status: Wrong Answer

Solution code:
N , X = (int(i) for i in input().split())
x = list(int(i) for i in input().split())
x.sort()
dif = list(0 for i in range(N-1))

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

if N ==1:
    print(x[0]-X)
else:
    for i in range(dif[0]-1):
        possibility = 1
        for j in range(N-1):
            if dif[j]%(dif[0]-i) != 0:
                possibility = 0
                break
        if possibility == 1:
            print((dif[0]-i))
            break

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:
    print(ans2)
else:
    print(ans1)

Submission status: Wrong Answer

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

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

zahyo = list(map(lambda x : int(x),input().split()))

zahyo.append(x)
zahyo.sort()

min = zahyo[1] - zahyo[0]

is_odd = False
is_even = False


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

    if diff % 2 == 0:
        is_even == True
    else:
        is_odd = True

    if diff < min:
        min = diff


# if is_odd == True and is_even == True:
#     print(1)
else:
    print(min)

Submission status: Wrong Answer

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

x.append(X)
x.sort()
result = x[1] - x[0]
print(result)

Submission status: Wrong Answer

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

kouho=[abs(l[i]-x) for i in range(n)]

ans=1
for i in (2,min(kouho)):
  mod = x%i
  signal=1
  for j in range(n):
    if l[j]%i!=mod:
      signal=0
  if signal==1:
    ans=i
print(ans)

Submission status: Wrong Answer

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

start = n-1
for i in range(n):
    if points[i] > x:
        start = i

dxs = set([points[i+1]-points[i] for i in range(n-1)])

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

if start == 0:
    d = points[0]-x
    for i in dxs:
        d = gcd(d, i)
    print(d)

elif start == n-1:
    d = x-points[-1]
    for i in dxs:
        d = gcd(d, i)
    print(d)

else:
    d1 = points[i]-x
    for i in dxs:
        d1 = gcd(d1, i)
    d2 = x-points[i-1]
    for i in dxs:
        d2 = gcd(d2, i)
    print(max(d1,d2))

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):
          print('1')
        else:
          del L[0]
          L.append(p)
          print(L[0])

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if a == 'a':
        return b
    if a%b ==0:
        if b > 0:
            return b
        else:
            return -1 * b
    return gcd(b,a%b) 

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

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

ret = 'a'

for num in x:
    ret = gcd(ret,num - X)

print(ret)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = [int(x) for x in input().split()]
a.append(x)
a.sort()
print(abs(a[a.index(x)] - a[a.index(x)-1]) if a.index(x) > 0 else abs(a[a.index(x)] - a[a.index(x)+1]))

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

def gcds(*numbers):
    return reduce(gcd, numbers)

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

n, x = map(int, input().split())
a_list = list(map(int, input().split()))
minimum = 10000000000
dist_list = []
for i,a in enumerate(a_list):
  minimum = min(abs(a - x), minimum)
  if i == 0:
    continue
  dist_list.append(abs(a_list[i-1] - a))

dist_list.append(minimum)

print(gcd_list(dist_list))

Submission status: Wrong Answer

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

n,x=3,81
pos=[33,105,57]
pos2=[p-x for p in pos]

width= max(pos2)-min(pos2)
ans = 1
for i in range(2,width+1):
    if all([ x%i==0 for x in pos2 ]):ans=i

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
for i in range(len(xl)-1):
    one_sa = xl[i+1] - xl[i]
    if onesam == 0:
        onesam = one_sa
    else:
        if one_sa % onesam == 0:
            onesam = one_sa
            continue
        else:
            short,big = min(onesam,one_sa),max(onesam,one_sa)
            if short == 1:
                onesam =1
                break
                
            while big % short != 0:
                for i in range(2,short):
                    if short % i == 0:
                        short = short // i
            if short == 1:
                onesam = 1
                break
            else:
                onesam = short
print(onesam)

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:
    # for i in range(n):
    #     li[i] = li[i] - start - diff
    # print(gcd_list(li))
    li.append(start)
    minn = min(li)
    for i in range(n+1):
        li[i] = li[i] - minn
    print(gcd_list(li))

Submission status: Wrong Answer

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

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

zahyo = list(map(lambda x : int(x),input().split()))

zahyo.append(x)
zahyo.sort()

min = zahyo[1] - zahyo[0]

is_odd = False
is_even = False


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

    if diff % 2 == 0:
        is_even == True
    else:
        is_odd = True

    if diff < min:
        min = zahyo[i+1] - zahyo[i]


# if is_odd == True and is_even == True:
#     print(1)
else:
    print(min)

Submission status: Wrong Answer

Solution code:
def gcd(dis1,dis2):
    if dis2==0:
        return dis1
    else:
        return gcd(dis2,dis1%dis2)
n,x=map(int,input().split())
a=list(map(int,input().split()))
dis1=x-min(a)
dis2=max(a)-x
print(gcd(dis1,dis2))

Submission status: Wrong Answer

Solution code:
import fractions


def run(n, x, xx):
    xx.append(x)
    xx = sorted(xx)
    d = [xx[i+1]-xx[i] for i in range(n)]
    d = sorted(d)
    min_d = d[0]
    if len(d) == 1:
        return min_d
    for i in range(1, len(d)):
        if d[i] % min_d == 0:
            return min_d
        else:
            min_d = fractions.gcd(min_d, d[i])
            if d[i] % min_d == 0:
                return min_d


def main():
    n, x = map(int, input().split())
    xx = list(map(int, input().split()))
    print(run(n, x, xx))


if __name__ == '__main__':
    main()

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
for i in range(len(xl)-1):
    one_sa = xl[i+1] - xl[i]
    if onesam == 0:
        onesam = one_sa
    else:
        if one_sa % onesam == 0:
            continue
        else:
            short,big = min(onesam,one_sa),max(onesam,one_sa)
            if short == 1:
                onesam =1
                break
                
            while big % short != 0:
                for i in range(2,short):
                    if short % i == 0:
                        short = short // i
            if short == 1:
                onesam = 1
                break
            else:
                onesam = short
print(onesam)

Submission status: Wrong Answer

Solution code:
N, X = map(int,input().split())
x = list(map(int, input().split()))
ans = 10000000000
for i in x:
    tmp = abs(X-i)
    if tmp < ans:
        ans = tmp
print(ans)

Submission status: Wrong Answer

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

n, x0 = map(int, input().split())
x = list(map(int, input().split())) + [x0]

x = list(set(x))
x.sort()
if len(x) >= 3:
    diff_x = [x[i+1] - x[i] for i in range(n-1)]
    ans = diff_x[0]
    for dx in diff_x[1:]:
        ans = int(gcd(ans, dx))
elif len(x) == 2:
    ans = x[1] - x[0]
else:
    ans = 0

print(ans)

Submission status: Wrong Answer

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

    print(temp_sub)
    ans1 = abs(X-x[X_index])
    ans2 = abs(X-x[X_index+1])
    ans3 = min(temp_sub)
    print(min(ans1,ans2,ans3))

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 = c[i] - c[i-1]

print(int(D))

Submission status: Wrong Answer

Solution code:
n,x = map(int, raw_input().split())
lis = sorted(map(int, raw_input().split()))
if n == 1:
    val = abs(lis[0]-x)
    if val == 0:
        print 1
    else:
        print val
    exit()
import bisect
#print lis
idx = bisect.bisect_left(lis, x)
#print idx
if idx == 0:
    val = lis[0] - x
    flag = 0
    for i in range(1, n):
        if (lis[i] - x) % val != 0:
            flag = 1
            break
    if flag == 0:
        print val
    else:
        print 1
elif idx == n:
    val = x - lis[-1]
    flag = 0
    for i in range(n-2, -1, -1):
        if (x - lis[i]) % val != 0:
            flag = 1
            break
    if flag == 0:
        print val
    else:
        print 1
else:
    val = min(lis[idx]-x, x-lis[idx-1])
    flag = 0
    for i in range(idx, n, 1):
        if (lis[i]-x)%val != 0:
            flag= 1
            break
    for i in range(idx-1, -1, -1):
        if (x-lis[i])%val != 0:
            flag = 1
            break
    if flag == 0:
        print val
    else:
        print 1


#print bisect.bisect_left(lis, 38)

Submission status: Wrong Answer

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

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

zahyo = list(map(lambda x : int(x),input().split()))

zahyo.append(x)
zahyo.sort()

min = zahyo[1] - zahyo[0]

is_odd = False
is_even = False

odds = list()

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

    if diff % 2 == 0:
        is_even == True
    else:
        is_odd = True
        odds.append(diff)

    if diff < min:
        min = zahyo[i+1] - zahyo[i]

# print(is_odd)
# print(is_even)
if len(odds) >= 1:
    for i in range(len(odds)):
        for j in range(len(odds)):
            if gcd(odds[i], odds[j]) == 1:
                print(1)
                sys.exit()


if is_odd == True and is_even == True:
    print(1)
else:
    print(min)

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)-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:
    print(ans2)
else:
    print(ans1)

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())))
    dx = abs(x[0])

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

    print(dx)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N , X = (int(i) for i in input().split())
x = list(int(i) for i in input().split())
x.sort()
dif = list(0 for i in range(N-1))

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

X_dif = list(0 for i in range(N))
for i in range(N):
    X_dif[i] = abs(x[i]-X)
X_dif.sort()

if N ==1:
    print(x[0]-X)
else:
    for i in range(1,dif[0]):
        possibility = 1
        for j in range(N-1):
            if dif[j]%(dif[0]-i) != 0 or X_dif[0]%(dif[0]-i) != 0:
                possibility = 0
                break
        if possibility == 1:
            print((dif[0]-i))
            break

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = [int(x) for x in input().split()]
a.append(x)
a.sort()
print(abs(a[a.index(x)] - a[a.index(x)-1]))

Submission status: Wrong Answer

Solution code:
import sys
N,X=map(int,input().split())
x=list(map(int,input().split()))
x.append(X)
x.sort()
x_diff=[]
for i in range (N):
    x_diff.append(x[i+1]-x[i])
for i in range (len(x_diff)):
    if x_diff[i]%(min(x_diff))!=0:
        print (1)
print(min(x_diff))

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    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 = [x2 - x1 for x1, x2 in zip(a, a[1:])]
    max_ = 0
    for i in range(n):
        if len(dis) == 1:
            max_ = dis[0]
            break
        try:
            g = max([gcd(d1, d2) for d1, d2 in zip(dis[i:], dis[i+1:])])
        except ValueError:
            break
        if g > max_:
            max_ = g
    print(max_)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import fractions


def run(n, x, xx):
    xx.append(x)
    xx = sorted(xx)
    d = [xx[i+1]-xx[i] for i in range(n)]
    d = sorted(d)
    min_d = d[0]
    if len(d) == 1:
        return min_d
    for i in range(1, len(d)):
        min_d = fractions.gcd(min_d, d[i])
        if d[i] % min_d == 0:
            return min_d


def main():
    n, x = map(int, input().split())
    xx = list(map(int, input().split()))
    print(run(n, x, xx))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,x = map(int, raw_input().split())
lis = sorted(map(int, raw_input().split()))
if n == 1:
    val = abs(lis[0]-x)
    if val == 0:
        print 1
    else:
        print val
    exit()
import bisect
#print lis
idx = bisect.bisect_left(lis, x)
#print idx
if idx == 0:
    val = lis[0] - x
    flag = 0
    for i in range(1, n):
        if (lis[i] - x) % val != 0:
            flag = 1
            break
    if flag == 0:
        print val
    else:
        print 1
elif idx == n:
    val = x - lis[-1]
    flag = 0
    for i in range(n-2, -1, -1):
        if (x - lis[i]) % val != 0:
            flag = 1
            break
    if flag == 0:
        print val
    else:
        print 1
else:
    val = min(lis[idx]-x, x-lis[idx-1])
    flag = 0
    for i in range(idx, n, 1):
        if (lis[i]-x)%val != 0:
            flag= 1
            break
    for i in range(idx-2, -1, -1):
        if (x-lis[i])%val != 0:
            flag = 1
            break
    if flag == 0:
        print val
    else:
        print 1


#print bisect.bisect_left(lis, 38)

Submission status: Wrong Answer

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

aa = []
for i in range(n):
    a = abs(x[i] - m)
    aa.append(a)

min_a = min(aa)
if all(a % min_a == 0 for a in aa):
    print(min_a)
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()

print(L[0])

Submission status: Wrong Answer

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

firstline=input("")
N,X=firstline.split()
N=int(N)
X=int(X)
secondline=input("")
xi=secondline.split()
dis = list(map(lambda x: int(x)-X, xi))
result = dis[0]
for i in dis[1:]:
    result = gcd(result, i)

print(result)

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 = 10000000000

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

print(D)

Submission status: Wrong Answer

Solution code:
import fractions

N,X=map(int,input().split())
x=map(int,input().split())
x=list(x)
for i in range(N):
    if i==0:
        ans=x[i]-X
    else:
        ans=fractions.gcd(ans,x[i]-X)
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
for i in range(len(a)-1):
  t = a[1+i] - a[i]
  if(t < d):
    d = t
  if(d == 1):
    break
print(d)

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:
    for i in range(n):
        li[i] = li[i] - start - diff
    print(gcd_list(li))

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())))
    dx = abs(x[0])

    for i in range(1, n):
        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())
x = list(map(int, input().split()))
assert len(x) == N

x.sort()

# distance between each two cities
dist = [x[i] - x[i-1] for i in range(1, len(x))]

# distance between the first city and the start point
dist.append(abs(x[0] - X))

def gcd(a, b):
    if a == 1 or b == 1:
        return 1
    while b > 1:
        a, b = b, a % b
    return a

def listgcd(xs):
    g = xs[0]
    for i in range(1, len(xs)):
        g = gcd(g, xs[i])
    return g

print(listgcd(dist))

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
if(n >= 50000):
  print(1)
else:
  a = list(map(int,input().split()))
  a.append(x)
  a.sort()
  d = 1000000000
  for i in range(len(a)-1):
    t = a[1+i] - a[i]
    if(t < d):
      d = t
    if(d == 1):
      break
  print(d)

Submission status: Wrong Answer

Solution code:
def serch_index(X,x):
    for i in range(len(x)):
        if X >=x[i]:
            return i
N,X = map(int,input().split())
x = list(map(int, input().split()))
if N == 1:
    print(abs(x[0]-X))
else:    
    x.sort()
    X_index = serch_index(X, x)
    ans1 = abs(X-x[X_index])
    ans2 = abs(X-x[X_index+1])
    print(min(ans1,ans2))

Submission status: Wrong Answer

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

n, x0 = map(int, input().split())
x = list(map(int, input().split())) + [x0]

x = list(set(x))
x.sort()
if len(x) >= 3:
    diff_x = [x[i+1] - x[i] for i in range(n-1)]
    ans = diff_x[0]
    for dx in diff_x[1:]:
        ans = int(gcd(ans, dx))
elif len(x) == 2:
    ans = x[1] - x[0]
else:
    ans = 0

print(ans)

Submission status: Wrong Answer

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

d = [0 for _ in range(n)]
for i in range(n):
    d[i] = abs(x[i] - X)

d = sorted(list(set(d)))

if n == 1:
    print(d[0])
    exit()

def calc_gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = b % a
    return calc_gcd(b, c)

ans = d[0]
for i in range(1, len(d)):
    ans = calc_gcd(ans, d[i])

print(ans)

Submission status: Wrong Answer

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


n, x = [int(_) for _ in input().split()]
x_list = [int(_) - x for _ in input().split()]

x_sorted = sorted(x_list)

x_gaps = [x_sorted[i+1] - x_sorted[i] for i in range(0, n-1)]

if len(x_gaps) == 0:
    print(x_sorted[0])
elif len(x_gaps) == 1:
    print(gcd(abs(x_list[0]), abs(x_list[1])))
else:
    result = x_sorted[0]
    for i in range(0, n-2):
        if i == 0:
            result = gcd(x_gaps[0], x_gaps[1])
        else:
            result = gcd(result, x_gaps[i+1])
    print(result)

Submission status: Wrong Answer

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

kouho=[abs(l[i]-x) for i in range(n)]

ans=1
for i in kouho:
  mod = x%i
  signal=1
  for j in range(n):
    if l[j]%i!=mod:
      signal=0
  if signal==1:
    ans=i
print(ans)

Submission status: Wrong Answer

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

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

D = abs(P[0]-X)
for i in range(N-1):
    D = gcd(D, abs(P[i]-X))

print(D)

Submission status: Wrong Answer

Solution code:
n,x = map(int, raw_input().split())
lis = sorted(map(int, raw_input().split()))
if n == 1:
    print abs(lis[0]-x)
    exit()
import bisect
#print lis
idx = bisect.bisect_left(lis, x)
if idx == 0:
    val = lis[0] - x
    flag = 0
    for i in range(1, n):
        if (lis[i] - x) % val != 0:
            flag = 1
            break
    if flag == 0:
        print val
    else:
        print 1
elif idx == n:
    val = x - lis[-1]
    flag = 0
    for i in range(n-2, -1, -1):
        if (x - lis[i]) % val != 0:
            flag = 1
            break
    if flag == 0:
        print val
    else:
        print 1
else:
    val = min(lis[idx]-x, x-lis[idx-1])
    flag = 0
    for i in range(idx +1, n, 1):
        if (lis[i]-x)%val != 0:
            flag= 1
            break
    for i in range(idx-2, -1, -1):
        if (x-lis[i])%val != 0:
            flag = 1
            break
    if flag == 0:
        print val
    else:
        print 1


#print bisect.bisect_left(lis, 38)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
L=sorted(x+[X])
if N==1:
	print(abs(X-x[0]))
else:
	LL=[L[i+1]-L[i] for i in range(N-1)]
	M=min(LL)
	while any([l%M!=0 for l in LL]):
		M=M-1
	print(M)

Submission status: Wrong Answer

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


# 最小公倍数
def gcd(a, b):
        while b:
                a, b = b, a % b
        return a

# 最大公約数
def lcm(a, b):
        return a * b // gcd (a, b)


ans = 0
for i, x in enumerate(x_list):

    diff = abs(x - X)

    print(i, x, diff, ans)

    if i == 0:
        ans = diff
    else:
        larger = min(ans, diff)
        smaller = max(ans, diff)

        if smaller % larger == 0:
            ans = larger
        else:
            ans = gcd(ans, diff)

print(ans)

Submission status: Wrong Answer

Solution code:
import math
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
if N > 1:
    mini = min([x[1] - x[0],  abs(X - x[0])])
elif N == 1:
    mini = abs(x[0] - X)
for i in range(1, N):
    if mini > min([x[i] - x[i - 1], abs(X - x[i])]):
        mini = min([x[i] - x[i - 1], abs(X - x[i])])
    if (x[i] - x[i - 1]) % mini != 0:
        break
        mini = math.gcd(mini, x[i] - x[i - 1])
    if abs(X - x[i]) % mini != 0:
        break
        mini = math.gcd(mini, X - x[i])
        

print(mini)

Submission status: Wrong Answer

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

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

m = min(x)
for i in range(N):
    if x[i] % m != 0:
        print(1)
        exit()
print(m)

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=[]
for i in range(len(x)-1):
    li.append(abs(x[i]-x[i+1]))



if len(li)==1:
    print(abs(x[0]-x[1]))
else:
    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 = (int(i) for i in input().split())
x = list(int(i) for i in input().split())
x.sort()
dif = list(0 for i in range(N-1))

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

X_dif = list(0 for i in range(N))
for i in range(N):
    X_dif[i] = abs(x[i]-X)
X_dif.sort()

if N ==1:
    print(x[0]-X)
else:
    for i in range(dif[0]-1):
        possibility = 1
        for j in range(N-1):
            if dif[j]%(dif[0]-i) != 0 or X_dif[0]%(dif[0]-i) != 0:
                possibility = 0
                break
        if possibility == 1:
            print((dif[0]-i))
            break

Submission status: Wrong Answer

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

x.sort()

# distance between each two cities
dist = [x[i] - x[i-1] for i in range(1, len(x))]

# distance between the first city and the start point
dist.append(abs(x[0] - X))

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

def listgcd(xs):
    g = xs[0]
    for i in range(1, len(xs)):
        g = gcd(g, xs[i])
    return g

print(listgcd(dist))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

N, X = map(int, input().split())
xs = list(map(int, input().split()))
xs.append(X)
xs = sorted(xs)
m = 999999999999999999
diffs = []
for idx,e in enumerate(xs):
  if idx==0:
    continue
  diff = abs(e - xs[idx-1])
  diffs.append(diff)
diffs = sorted(diffs)
for idx,dif in enumerate(diffs):
  if idx == 0:
    continue
  if gcd(diffs[idx], diffs[idx-1]) < m:
    m = gcd(diffs[idx], diffs[idx-1])
print(m)

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]) #階差

d.sort()

D = d[0]
for i in range(len(d) - 1):
    if d[i + 1] % D != 0:
        for j in range(int(D ** 0.5), 1, -1):

            if d[i + 1] % D == 0:
                D = d[i + 1]
                continue

    if D == 1:
        break

print(D)

Submission status: Wrong Answer

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

aa = []
for i in range(n):
    a = abs(x[i] - m)
    aa.append(a)

print(min(aa))