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: Runtime Error

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


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

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

diff = []
diff.append(X - toshi[0])

for i in range(N-1):
    diff.append(abs(toshi[i+1] - toshi[i]))

print(gcd_list(diff))

Submission status: Runtime Error

Solution code:
N,X = map(int,input().split())
towns = list(map(int,input().split()))
towns.append(X)
towns.sort()
town_diff = [0]*(len(towns)-1)
for i in range(len(towns)-1):
    town_diff[i] = towns[i+1]-towns[i]
town_diff.sort()
status = ''
a = town_diff[0]
b = town_diff[1]
for i in range(len(town_diff)-2):
    while(True):
        t = b%a
        if(t == 0):
            gcd = a
            break
        b = a
        a = t
    a = gcd
    b = town_diff[i+2]
print(gcd)

Submission status: Runtime Error

Solution code:
N,X=map(int,input().split())
inputcities=list(map(int, input().split()))
cities=[abs(inputcities[i]-X) for i in range(N)]
count=0
minimum=min(cities)
for j in range(minimum+1)[::-1]:
  for i in range(N):
    if cities[i]%j==0:
      count+=1
    else:
      count=0
      break
    if count==N:
      print(j)
      flag=1
      break
  if flag==1:
    break

Submission status: Runtime Error

Solution code:
import math
n,x = map(int,input().split())
xlist = list(map(int,input().split()))
ans = 0
for i in range(n):
    ans = math.gcd(xlist[i]-x,ans)
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


def spaceinput():
    return list(map(int,input().split(" ")))


def _gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd(numbers):
    return reduce(math.gcd, numbers)



N,X=spaceinput()

x=spaceinput()

x.append(X)
x=sorted(x)
d=[]
for i,xx in enumerate(x[:-1]):
    d.append(x[i+1]-x[i])

#print(d)

print(gcd(d))

Submission status: Runtime Error

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])
  
h = min(a)
gcd = 1
for i in range(h,0,-1):
  if h%i == 0:
    if all(a[j]%i == 0 for j in range(n)):
      gcd = i
      break
      
print(gcd)
    

    
    
    


    gcd = i
    break
    
    
print(gcd)

Submission status: Runtime Error

Solution code:
import functools
import math

N,X=map(int,input().split())
x_list=list(map(int,input().split()))
x_list.append(X)
x_list.sort()
y_list=[]
for i in range(N):
    y_list.append(x_list[i+1]-x_list[i])
z_list=list(set(y_list))
gcd = functools.reduce(math.gcd, z_list)
print(gcd)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
	if b == 0:
		return 1
	_max = max(a, b)
	_min = min(a, b)
	rest = _max % _min
	if rest == 0:
		return _min
	else:
		return gcd(_min, rest)

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

for i in range(N):
	if X < x[i]:
		x.insert(i, X)
		N += 1
diff = []
for i in range(N - 1):
	d = abs(x[i] - x[i+1])
	diff.append(d)

res = diff[0]
for i in range(N - 2):
	res = gcd(res, diff[i + 1])
print res

Submission status: Runtime Error

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

mindist2 = xs[1] - xs[0]
for i in range(len(xs)-1):
    tmp = xs[i+1] - xs[i]
    if (mindist2 > tmp):
        mindist2 = tmp

for i in range(1, len(xs)):
    if (xs[i] - xs[0]) % mindist != 0:
        if mindist % mindist2 == 0:
            mindist = mindist2
            break
        mindist = 1
        break
if mindist != 1:
    for i in range(1, len(xs)):
        if (xs[i] - xs[0]) % mindist != 0:
            mindist = 1
            break
print(mindist)

Submission status: Runtime Error

Solution code:
import sys
import functools
import math

input = sys.stdin.read().split()

N = int(input[0])
X = int(input[1])
cities = sorted(list(map(int, input[2:])))


# Xより右か左かで分ける
left = []
right = []
distance = []

for city in cities:
    if X > int(city):
        left.append(int(city))
    else:
        right.append(int(city))

for lcity in left:
    distance.append(X - lcity)
for rcity in right:
    distance.append(rcity - X)

# 公約数を求める
gcd = functools.reduce(math.gcd, distance)

print(gcd)

Submission status: Runtime Error

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)
gcd = 1
for i in range(h,0,-1):
  if h%i == 0:
    if all(a[j]%i == 0 for j in range(n)):
      gcd = i
      break
      
print(gcd)
    

    
    
    


    gcd = i
    break
    
    
print(gcd)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
	if(a > b):
		a -= b
		return gcd(a, b)
	elif(a < b):
		b -= a
		return gcd(a, b)
	else:
		return a

import numpy as np
#import math
n, x = map(int, input().split())
buf = input().split()
X = np.abs(np.array([int(buf[i]) for i in range(n)]) - x)
#print(X)
if(X.shape[0] == 1):
	r = X[0]
else:
	r = gcd(X[0], X[1])
	for i in range(n-2):
		r = gcd(r, X[i+2])
print(r)

Submission status: Runtime Error

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


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

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

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

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

print(g)

Submission status: Runtime Error

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

x_list.sort()
import math
if N ==1:
    print(x_list[0]-X)
    exit()

if N==2:
    g1 = abs(X-x_list[0])
    g2 = math.gcd(g1, x_list[1]-x_list[0])
    print(g2)
    exit()

m0 = abs(X - x_list[0])

D = 10**9
for i in range(N-2):
    m1 = abs(x_list[i] - x_list[i+1])
    m2 = abs(x_list[i] - x_list[i+2])
    g = math.gcd(m1, m2)

    if g <= D:
        D = g
print(D)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


def spaceinput():
    return list(map(int,input().split(" ")))


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


N,X=spaceinput()

x=spaceinput()

x.append(X)
x=sorted(x)
d=[]
for i,xx in enumerate(x[:-1]):
    d.append(x[i+1]-x[i])

#print(d)

print(gcd(*d))

Submission status: Runtime Error

Solution code:
import math

n,x = map(int,input().split())
xlist = list(map(int,input().split()))
ans = 0
for i in range(n):
    ans = math.gcd(xlist[i]-x,ans)
print(ans)

Submission status: Runtime Error

Solution code:
N,X=map(int,input().split())
inputcities=list(map(int, input().split()))
cities=[abs(inputcities[i]-X) for i in range(N)]
count=0
minimum=min(cities)
for j in range(minimum+1)[::-1]:
  for i in range(N):
    if cities[i]%j==0:
      count+=1
    else:
      count=0
      break
    if count==N:
      print(j)
      flag=1
      break
  if flag==1:
    break

Submission status: Runtime Error

Solution code:
import functools
import math

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

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

gcd = functools.reduce(math.gcd, city)
print(gcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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


input_list1 = list(map(int, input().split()))
input_list2 = list(map(int, input().split()))
#input_list1 = [3, 81]
#input_list2 = [33, 105, 57]
N = input_list1[0]
X = input_list1[1]

#print('N:', N)
#print('X:', X)

# 都市のリストにXを追加し、小さい順にソートする
input_list2.append(X)
input_list2.sort()
#print(input_list2)

# それぞれの差を取る
ans_list = []
for i, target in enumerate(input_list2):
    if i == N:
        break
    aa = input_list2[i + 1] - input_list2[i]
    #print(input_list2[i + 1], '-' , input_list2[i])
    ans_list.append(aa)

# 重複排除
ans_list = set(ans_list)

# 最大公約数を求める
if len(ans_list) > 1:
    print(gcd_list(ans_list))
else:
    print(min(ans_list))

Submission status: Runtime Error

Solution code:
def gcd(a, b):
	if rest == 0:
		return 1
	_max = max(a, b)
	_min = min(a, b)
	rest = _max % _min
	if rest == 0:
		return _min
	else:
		return gcd(_min, rest)

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

for i in range(N):
	if X < x[i]:
		x.insert(i, X)
		N += 1
diff = []
for i in range(N - 1):
	d = abs(x[i] - x[i+1])
	diff.append(d)

res = diff[0]
for i in range(N - 2):
	res = gcd(res, diff[i + 1])
print res

Submission status: Runtime Error

Solution code:
# coding: utf-8

input_lines=input().split()

N=int(input_lines[0])
X=int(input_lines[1])

city=input().split()

D_list=[]

i=0
while(True):
    D_list.append(abs(X-int(city[i])))
    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
        
#print(D_list)
print(max(D_list))

Submission status: Runtime Error

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

x_list.sort()
if N ==1:
    print(x_list[0]-X)
    exit()

if N==2:
    g1 = abs(X-x_list[0])
    g2 = math.gcd(g1, x_list[1]-x_list[0])
    print(g2)
    exit()

m0 = abs(X - x_list[0])

D = 10**9
for i in range(N-2):
    m1 = abs(x_list[i] - x_list[i+1])
    m2 = abs(x_list[i] - x_list[i+2])
    g = math.gcd(m1, m2)

    if g <= D:
        D = g
print(D)

Submission status: Runtime Error

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


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

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

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

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

print(g)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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)

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

print(gcd(*aa))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import functools
import math

input = sys.stdin.readline
n, x = map(int, input().split())
a = input().split()
b = list(map(int, a))
b.append(x)
b.sort()
c = []
for i in range(1, n):
    c.append(b[i] - b[i - 1])
gcd = functools.reduce(math.gcd, c)
print(gcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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


input_list1 = list(map(int, input().split()))
input_list2 = list(map(int, input().split()))
#input_list1 = [3, 81]
#input_list2 = [33, 105, 57]
N = input_list1[0]
X = input_list1[1]

#print('N:', N)
#print('X:', X)

# 都市のリストにXを追加し、小さい順にソートする
input_list2.append(X)
input_list2.sort()
#print(input_list2)

# それぞれの差を取る
ans_list = []
for i, target in enumerate(input_list2):
    if i == N:
        break
    aa = input_list2[i + 1] - input_list2[i]
    #print(input_list2[i + 1], '-' , input_list2[i])
    ans_list.append(aa)

# 重複排除
ans_list = set(ans_list)

ans_list = [27, 18, 9, 3]

# 最大公約数を求める
if len(ans_list) > 1:
    print(gcd_list(ans_list))
else:
    print(min(ans_list))

Submission status: Runtime Error

Solution code:
import functools
import math

N,X=map(int,input().split())
x_list=list(map(int,input().split()))
x_list.append(X)
x_list.sort()
y_list=[]
for i in range(N):
    y_list.append(x_list[i+1]-x_list[i])


gcd = functools.reduce(math.gcd, y_list)
print(gcd)

Submission status: Runtime Error

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

xlist = map(int, input().split(" "))

x_dst = [xi - x for xi in xlist]

subt = lambda a, b: a-b
dst_list = list(map(subt, x_dst[:-1], x_dst[1:]))

max_temp = abs(dst_list[0])
for d in dst_list:
    max_c = 1
    for i in range(max_temp):
        if abs(d) % (i+1) == 0:
            max_c = i+1
    if max_c < max_temp:
        max_temp = max_c
print(max_temp)

Submission status: Runtime Error

Solution code:
N,X=map(int,input().split())
inputcities=list(map(int, input().split()))
cities=[inputcities[i]-X for i in range(N)]
count=0
minimum=min(cities)
for j in range(minimum+1)[::-1]
  for i in range(N):
    if cities[i]%j==0:
      count+=1
    else:
      count=0
      break
    if count==N:
      print(j)
      flag=1
      break
if flag==1:
  break

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

nk=input().split()
n=int(nk[0])
k=int(nk[1])
l=input().split()
l.sort()
m=(int(l[0])+int(l[-1]))/2
if k<m:
    x=int(l[0])-(k-int(l[0]))
    l.insert(0,x)
else:
    x=int(l[-1])+(int(l[-1])-k)
    l.append(x)
gcd=gcd(int(i) for i in l)
print(gcd)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import functools
import math

input = sys.stdin.readline
n, x = map(int, input().split())
a = input().split()
b = list(map(int, a))
b.append(x)
b.sort()
c = []
for i in range(n):
    if i <= n - 1:
        c.append(b[i + 1] - b[i])
gcd = functools.reduce(math.gcd, c)
print(gcd)

Submission status: Runtime Error

Solution code:
import math
N,X=(int(i) for i in input().split())
x = [int(i) for i in input().split()]
x.append(X)
x.sort()
b=[]
for i in range(N):
    c=x[i+1]-x[i]
    b.append(c)
values = [290021904, 927964716, 826824516, 817140688]
def gcd_all(list):
    return gcd_all([math.gcd(*list[:2])] + list[2:]) if len(list) > 1 else list[0]
gcd = gcd_all(b)
print(gcd)

Submission status: Runtime Error

Solution code:
import math
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)]
	def GCD(LIST):
		if len(LIST)==2:
			return math.gcd(LIST[0],LIST[1])
		else:
			return GCD([math.gcd(LIST[0],LIST[1])]+LIST[2::])
	print(GCD(LL))

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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


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

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

print(gcd_list(city))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def reduce(function, iterable, initializer=None):
    it = iter(iterable)
    if initializer is None:
        value = next(it)
    else:
        value = initializer
    for element in it:
        value = function(value, element)
    return value

def gcd_list(ls):
    return reduce(math.gcd, ls)

N, X = list(map(int, input().split()))
xs = list(map(int, input().split()))
ys = [x - X for x in xs]

print(gcd_list(ys))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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(gcd(*[a for a in aa]))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

if(N == 1):
    print(abs(xs[0]-X))
else:
    xs.sort()
    dist_x = []
    dist_point = []
    
    dist_x.append(abs(xs[0]-X))
    ahead = xs[0]
    
    for i in range(1,len(xs)):
        dist_x.append(abs(xs[i]-X))
        dist_point.append(xs[i]-ahead)
        ahead = xs[i]
    print(math.gcd(gcd_list(dist_point), gcd_list(dist_x)))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import fractions
import sys


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

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 is_odd == True and is_even == True or gcd(*odds) == 1:
    print(1)
    sys.exit()

# print(gcd(*odds))

print(min)

Submission status: Runtime Error

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


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



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

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

Submission status: Runtime Error

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

xlist = map(int, input().split(" "))

x_dst = [xi - x for xi in xlist]

subt = lambda a, b: a-b
dst_list = list(map(subt, x_dst[:-1], x_dst[1:]))

max_temp = abs(dst_list[0])
for d in dst_list:
    max_c = 1
    for i in range(max_temp):
        if max_temp % (i+1) == 0:
            max_c = i+1
    if max_c < max_temp:
        max_temp = max_c
print(max_temp)

Submission status: Runtime Error

Solution code:
import math
import sys
sys.setrecursionlimit(2000000)
n, x = map(int, input().split())
xl = [int(_) for _ in input().split()]
for i in range(n):
    if x > xl[i]:
        xl[i] = x - xl[i]
    else:
        xl[i] = xl[i] - x
x_gcd = xl[0]
if n > 1:
    for i in range(1, n):
        x_gcd = math.gcd(x_gcd, xl[i])
print(x_gcd)

Submission status: Runtime Error

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

x_list.sort()
if N ==1:
    print(x_list[0]-X)
    exit()

m0 = abs(X - x_list[0])

D = 10**9
for i in range(N-1):
    m1 = abs(x_list[i] - x_list[i+1])
    g = math.gcd(m1, m0)

    if D >= g:
        D = g
print(D)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

if N == 1:
    print(abs(x[0] - X))
else:
    x.append(X)
    x.sort()
    print(x)
    x = [n - x[0] for n in x]
    print(x)
    D = reduce(math.gcd, x)
    print(D)

Submission status: Runtime Error

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


def gcdd(a, b):
  while b > 0:
    a, b = b, a%b
  return a
def gc(n):
    return [gcdd(n[0],n[1])]+n[2::]

lgap = [abs(i-B) for i in l]
if len(lgap)==1:
    gcd = lgap[0]
else:
    gcd = gc(lgap)
    gcd = gcdd(gcd[0],gcd[1])

print(gcd)

Submission status: Runtime Error

Solution code:
import math
n, x = map(int, input().split())
cities = list(map(int, input().split()))
cities.append(x)
cities.sort()
 
def get_res(cities):
    if len(cities) == 2:
        return cities[1] - cities[0]
    else:
        gcds = []
        for i in range(len(cities) - 2):
            c1 = cities[i]
            c2 = cities[i + 1]
            c3 = cities[i + 2]
            gcds.append(math.gcd(c2 - c1, c3 - c2))

        return min(gcds)
 
print(get_res(cities))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
from fraction import gcd
import sys


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

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 is_odd == True and is_even == True or gcd(*odds) == 1:
    print(1)
    sys.exit()

# print(gcd(*odds))

print(min)

Submission status: Runtime Error

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


x_now = x_start

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

Submission status: Runtime Error

Solution code:
def sub(a, b):
    if a >= b:
        s = a-b
    else:
        s = b-a
    return s
def gcd(a , b):
    num1 = int(a)
    num2 = int(b)
    i = sub(num1, num2)
    while i > 0:
        num1 = num2
        num2 = i
        i = sub(num1, num2)
    return num2


n_str,x_str = input().split()
n = int(n_str)
x = int(x_str)

point_list = []
point_str_list = input().split()
for i in point_str_list:
    i = int(i)
    point_list.append(i)

point_list.sort()

def_list = []
for i in range(n-1):
    defference = point_list[i+1] - point_list[i]
    def_list.append(defference)

a = def_list[0]
for i in def_list:
    a = gcd(a,i)

print(a)

Submission status: Runtime Error

Solution code:
n,x = map(int,input().split())
x_list = list(map(int,input().split()))
x_list.append(x)
x_list = sorted(x_list)
a = []
for i in range(n):
    b = x_list[i+1]-x_list[i]
    a.append(b)
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans = gcd(*a)
print(int(ans))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce, gcd
import sys


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

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 is_odd == True and is_even == True or gcd(*odds) == 1:
    print(1)
    sys.exit()

# print(gcd(*odds))

print(min)

Submission status: Runtime Error

Solution code:
# coding: utf-8

import functools
import math

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

xs.append(x)
xs.sort()

dxs = list()

for i in range(1, n+1):
    if xs[i-1] != xs[i]:
        dxs.append(xs[i] - xs[i-1])

print(functools.reduce(math.gcd, dxs))

Submission status: Runtime Error

Solution code:
import math

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

for i in range(len(arr)):
    arr[i] -= X
    
df = []
for i in range(1, len(arr)):
    df.append(arr[i] - arr[i-1])

if(N == 1):
    df.append(arr[0])

ans = 0
for num in df:
    ans = math.gcd(ans, num)
    
print(ans)

Submission status: Runtime Error

Solution code:
import math

city_num, start_pos = list(map(int, input().split()))
city_list = list(map(int, input().split()))

# スタート位置を入れて
city_list.append(start_pos)
# 昇順に並び替え
city_list.sort()

# city毎の距離のリストを生成する
distance_list = [city_list[i+1] - city_list[i] for i in range(city_num)]

# 距離が一つならそれを出力
if len(distance_list) == 1:
    print(distance_list[0])
    exit()

# 昇順に並び替え
distance_list.sort()

# 最大公約数を求める
max_gcd = math.gcd(distance_list[0], distance_list[1])
for i in range(2, len(distance_list)):
    max_gcd = math.gcd(max_gcd, distance_list[i])

# 出力
print(max_gcd)

Submission status: Runtime Error

Solution code:
import math
N,X=map(int,input().split())
x=list(map(int,input().split()))
L=sorted(x+[X])
def GCD(LIST):
	if len(LIST)==2:
		return math.gcd(LIST[0],LIST[1])
	else:
		return GCD([math.gcd(LIST[0],LIST[1])]+LIST[2::])
if N==1:
	print(abs(X-x[0]))
else:
	LL=[L[i+1]-L[i] for i in range(N)]
	print(GCD(LL))

Submission status: Runtime Error

Solution code:
def gcd(x,y):
    if x>=y:
        if x%y==0:
            return y
        else:
            return gcd(y,x%y)
    else:
        if y%x==0:
            return x
        else:
            return gcd(x,y%x)
def gcd2(x3):
    if len(x3)>2:
        return gcd2([gcd(x3[0],x3[1]),]+x3[2:])
    elif len(x3) ==2:
        return gcd(x3[0],x3[1])
    else:
        return x3[0]
N, X = map(int,input().split())
x=[int(i) for i in input().split()]
x.append(X)
x2=sorted(x)
x3=[]
for i in range(len(x2)-1):
    x3.append(x2[i+1]-x2[i])
print(gcd2(x3))

Submission status: Runtime Error

Solution code:
import math
n, x = map(int, input().split())
X = list(map(int, input().split()))
Y = X[:]
Y.append(x)
Y.sort()
Z = [Y[i]-Y[i-1] for i in range(1, n+1)]
res = True
gcd = 1
if len(Z) == 1:
    res = False
if res:
    tmp = []
    for i in range(1, len(Z)):
        tmp.append(math.gcd(Z[i],Z[i-1]) )
    gcd = min(tmp) 
else:
    gcd = Z[0]
print(gcd)

Submission status: Runtime Error

Solution code:
import fraction
n, x = map(int, input().split())
xl = [int(_) for _ in input().split()]
for i in range(n):
    if x > xl[i]:
        xl[i] = x - xl[i]
    else:
        xl[i] = xl[i] - x
x_gcd = xl[0]
if n > 1:
    for i in range(1, n):
        x_gcd = fraction.gcd(x_gcd, xl[i])
print(x_gcd)

Submission status: Runtime Error

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

def gcdlist(l):
    if len(l) == 2:
        return gcd(l[0], l[1])
    f = l.pop()
    s = l.pop()
    m = gcd(f, s)
    l.append(m)
    return gcdlist(l)


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
        max_ = gcdlist(dis)
    print(max_)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


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


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

list = [abs(x_list[i] - x) for i in range(n)]

answer = gcd_list(list)
print(answer)

Submission status: Runtime Error

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

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

lgap = [abs(i-B) for i in l]
if len(lgap)==1:
    gcd = lgap[0]
else:
    gcd = gc(lgap)
    gcd = math.gcd(gcd[0],gcd[1])

print(gcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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


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

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

print(gcd_list(city))

Submission status: Runtime Error

Solution code:
import functools
import fractions

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import functools
import math

N,X=map(int,input().split())
x_list=list(map(int,input().split()))
x_list.append(X)
x_list.sort()
y_list=[]
for i in range(N):
    y_list.append(x_list[i+1]-x_list[i])
z_list=list(set(y_list))
if len(z_list)==1:
    print(z_list[0])
else:
    gcd = functools.reduce(math.gcd, z_list)
    print(gcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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


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

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

dis=[abs(X-i) for i in plc]

print(gcd_list(dis))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

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

xs = [int(i) for i in input().split()]
ls = [abs(i-x) for i in xs]


print(gcd_list(ls))

Submission status: Runtime Error

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    print(abs(x-a[0]))
    exit()
a.sort()
else:
    box = [a[i+1]-a[i] for i in range(n-1)]
    b = min(box)
    for i in range(1,b+1):
        for j in range(n-1):
            if box[j]%i:
                break
            if j == n-2:
                ans = i
    d = abs(x-a[0])
    if ans <= d:
        for i in range(1,ans+1):
            if d%i:
                continue
            else:
                temp = i
        print(temp)
    else:
        for i in range(1,d+1):
            if ans%i:
                continue
            else:
                temp = i
        print(temp)