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 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))

L = len(left)
R = len(right)

if L > 1:
    for l in range(L-1):
        distance.append(left[l+1] - left[l])
    distance.append(X - left[-1])
elif L == 1:
    distance.append(X - left[-1])

if R > 1:
    for r in range(R-1):
        distance.append(right[r+1] - right[r])
    distance.append(right[0] - X)
elif R == 1:
    distance.append(right[0] - X)

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

print(gcd)

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)
if N == 1:
    min_diff = x_list[1] - x_list[0]
else:
    x_diffs = [val - x_list[i - 1] for i, val in enumerate(x_list) if i > 0]
    min_diff = min(x_diffs)
D_canditates = [i for i in range(1, min_diff + 1) if min_diff % i == 0]

# Search max D
D_list = []
for D_cand in D_canditates:
    for x_diff in x_diffs:
        if x_diff % D_cand == 0:
            D_list.append(D_cand)
print(min(D_list))

Submission status: Runtime Error

Solution code:
a = input().split()
n = int(a[0])
x = int(a[1])
b = input().split()
l = [int(i) for i in b]

import functools
import math

l.append(x)
ld = sorted(l, reverse=True)
tmp = []
for i in range(1, len(ld)):
    tmp.append(abs(ld[i] - ld[i-1]))
gcd = functools.reduce(math.gcd, tmp)
print(gcd)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

tmp = []

for i in field:
    tmp.append(abs(i-x))


ans = tmp[0]

for i in range(1,n):
    ans = math.gcd(ans,tmp[i])

print(ans)

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())
l=[abs(c-x) for c in list(map(int,input().split()))]
del l[l.index(0)]
print(gcd_list(l) if len(l)>1 else l[0])

Submission status: Runtime Error

Solution code:
N, X = map(int, input().split())
 
arr = [int(_) for _ in input().split(' ')]
arr.sort()
 
a = 1000000000000
 
 
for i in range(N-1):
    if abs(arr[i+1]-arr[i]) < a:
        a = abs(arr[i+1]-arr[i])
 
for j in range(N):
    if abs(arr[j] - X) < a:
        a = abs(arr[j] - X)

if X > arr[N] or X < arr[0]:
    a = 1
 
print(a)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

## 最初に入力回数が与えられて、そのあとデータが入力される。といったパターン
nums = list(map(int, input().split())) # "1 2 3"と入力
N = nums[0]
X = nums[1]

nums = list(map(int, input().split())) # "1 2 3"と入力

a=[]
for item in nums:
	a.append(abs(item - X))


print(gcd (*a))

Submission status: Runtime Error

Solution code:
from math import gcd
tmp = input().split(' ')
N = int(tmp[0])
X = int(tmp[1])
l = list(map(int, input().split()))
l.append(X)
l.sort()
len_l = len(l)
dis_list = []
for i in range(len_l-1):
    dis = l[i+1] - l[i]
    dis_list.append(dis)
len_dis = len(dis_list)
tmp_old = dis_list
if len_dis == 1:
    print(dis_list[0])
else:
    for i in range(len_dis-1):
        tmp_new = []
        len_old_tmp = len(tmp_old)
        for j in range(len_old_tmp-i-1):
            tmp_new.append(gcd(tmp_old[j], tmp_old[j+1]))
    print(tmp_new[0])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
a,b = map(int,input().split())
c = list(map(int,input().split()))
c.append(b)
c.sort()
ans = 0
for i in range(a):
    e = c[i+1]-c[i]
    if i == 0:
        pre = e
        ans = e
    else:
        f = math.gcd(pre,e)
        if f < pre:
            ans = f
print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

field = map(int,input().split())

tmp = []

for i in field:
    tmp.append(abs(i-x))


ans = tmp[0]

for i in range(1,n):
    ans = math.gcd(ans,tmp[i])

print(ans)

Submission status: Runtime Error

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

input = sys.stdin.readline
n, x = map(int, input().split())
a = input().split()
b = list(map(int, a))
b.append(x)
b.sort()
c = []
if len(b) == 2:
    print(b[1] - b[0])
    exit(0)
for i in range(1, n - 1):
    c.append(b[i] - b[i - 1])


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

ans = c[0]
for i in range(len(c)):
    ans = gcd(c[i], ans)
print(ans)

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:
from math import gcd
#from functools import reduce

n, x = map(int, input().split())
xs = map(int, input().split())
xs2 = map(lambda y: abs(y - x), xs)
print(reduce(gcd, xs2))

Submission status: Runtime Error

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

if n == 1:
    print(l[0]-x)
    exit()
else:
    l.append(x)
    l.sort()
    #print(l)

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):
        #print(l)
        if l[i] % l[0] != 0:
            calc()
            break
        else:
            del l[i]
            num += 1
    else:
        print(l[0])
        break

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math
from functools import reduce

N,X=map(int,input().split())
x=list(map(int,input().split()))
x_dif=[]
for i in x:
    x_dif.append(X-i)
print(reduce(math.gcd, x_dif))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import functools
import math

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


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

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

gcd = functools.reduce(math.gcd, to)
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())
l=[abs(c-x) for c in list(map(int,input().split()))]
print(gcd_list(l) if len(l)>1 else l[0])

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

a = [int(i) for i in input().split()]
N = a[0]
X = a[1]
x = [int(i) for i in input().split()]
dis = [i-X for i in x]

print(reduce(math.gcd, dis))

Submission status: Runtime Error

Solution code:
import math
def serch_index(X,x):
    for i in range(len(x)):
        if X >=x[i]:
            return i
# def check_ans(temp_sub,ans):
#     count = 0
#     for i in temp_sub:
#         if i%ans ==0:
#             count += 1
#         else:
#             pass
#     # print(count)
#     if count == len(temp_sub):
#         return False
#     else:
#         return True
def cal_gcd(temp_sub,ans):
    for i in temp_sub:
        temp_ans = math.gcd(i,ans)
        true_ans = min(ans,temp_ans)
    return true_ans

N,X = map(int,input().split())
x = list(map(int, input().split()))
if N == 1:
    print(abs(x[0]-X))
else:    
    X_index = serch_index(X, x)
    if X_index == None:
        x.insert(0,X)
    else:
        x.insert(X_index+1, X)
    x.sort()
    # print(x)
    temp_sub = []
    # print(x)
    for i in range(N):
        temp_sub.append(x[i+1]-x[i])
    # print(temp_sub)
    ans = abs(min(temp_sub))
    true_ans = cal_gcd(temp_sub, ans)
    
    # judge = True
    # while judge:
    #    judge = check_ans(temp_sub, ans)
    #    if judge:
    #         ans -=2
    print(true_ans)

Submission status: Runtime Error

Solution code:
import math as mh
import fractions as fr
from functools import reduce

n, p = (int(_) for _ in input().split())
x = list(int(_) for _ in input().split())
x.append(p)
x.sort()

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

exgcd = reduce(fr.gcd, x)
print(exgcd)

Submission status: Runtime Error

Solution code:
import functools
import math

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


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

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

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

Submission status: Runtime Error

Solution code:
import math
n, x = list(map(int, input().split())) # 整数
array = list(map(int, input().strip().split()))

ans = abs(x-array[0])
for i in range(n-1):
    if math.gcd(ans,abs(array[i]-array[i+1])):
        ans =math.gcd(ans,abs(array[i]-array[i+1]))
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

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

ans = 1000000001
for i in range(n):
    v = abs(x - a[i])

    if v < ans:
        ans = v

    gcd = math.gcd(v, ans)
    if gcd < ans:
        ans = gcd

print(ans)

Submission status: Runtime Error

Solution code:
import math
L = []
N,X = map(int,input().split())
L = list(map(int,input().split()))
L.append(X)
L = sorted(L)
D = []
for i in range(len(L)) :
    d = abs(L[i-1] - L[i])
    if i != 0 :
        D.append(d)

D = sorted(D)
if N != 1 :
    answer = math.gcd(D[0],D[1])
    for j in range(len(D)-1) :
        gcd = math.gcd(D[j],D[j+1])
        if answer > gcd :
            answer = gcd
else :
    answer = D[0]
print(answer)

Submission status: Runtime Error

Solution code:
import functools
import math

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


x = list(map(int,input().rstrip().split()))
x.append(X)
x = sorted(x)
mini = x[1] - x[0]


to = []
for i in range(len(x)-1):
	to.append(x[i+1] - x[i])
	if mini > x[i+1] - x[i]:
		mini =  x[i+1] - x[i]
		

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math
import functools

N,X=map(int,input().split())
x=list(map(int,input().split()))
x_dif=[]
for i in x:
    x_dif.append(X-i)
print(reduce(math.gcd, x_dif))

Submission status: Runtime Error

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

input = sys.stdin.readline
n, x = map(int, input().split())
a = input().split()
b = list(map(int, a))
b.append(x)
b.sort()
c = []
if len(b) == 2:
    print(b[1] - b[0])
    exit(0)
for i in range(1, n - 1):
    c.append(b[i] - b[i - 1])


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

ans = functools.reduce(gcd, c)
print(ans)

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]
    elif len(cities) < 100:
        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)
    else:
        return 100


print(get_res(cities))

Submission status: Runtime Error

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

if len(x) == 1:
    print(abs(x[0]-m))
else:
    set_aa = [a for a in set(aa)]
    print(gcd(*set_aa))

Submission status: Runtime Error

Solution code:
# your code goes here
def gcd(a, b):
	if(a > b):
		a -= b
		return gcd(a, b)
	elif(a < b):
		b -= a
		return gcd(a, b)
	else:
		return int(a)

import numpy as np

n, x = map(int, input().split())
buf = input().split()
xx = np.zeros(n+1)
for i in range(n):
	xx[i] = int(buf[i])
xx[-1] = x
xx.sort()
for i in range(n):
	xx[n-i] -= xx[n-1-i]
	
r = xx[1]
for i in range(n-1):
	if(xx[i+2] % r != 0):
		r = gcd(r, xx[i+2])
print(int(r))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

l = list(map(int, input().split()))
N=l[0]
X=l[1]
x=[0]*N
A=[0]*N
l = list(map(int, input().split()))
for i in range(N):
    x[i] = l[i]
    A[i] = abs(X-x[i])
g=A[0]
for i in range(N):
    g = math.gcd(g, A[i])
print(g)

Submission status: Runtime Error

Solution code:
def g(a,b):x=max([a,b]);y=min([a,b]);return g(y,x%y) if x%y else y
N,X=map(int,input().split());a=[abs(int(i)-X) for i in input().split()];ans=a[0]
for i in range(1,N):ans=g(ans,y[i])
print(ans)

Submission status: Runtime Error

Solution code:

import numpy as np

def main():
    N, X = map(int, input().split())
    x = np.asarray(list(map(int, input().split())))
    x = np.absolute(x - X)
    if N > 1:
        d = []
        for i in range(x.size-2):
            d.append(x[i+1] - x[i])
        d = np.absolute(np.asarray(list(set(d))))
    else:
        d = x
    m = np.min(d)

    for n in range(m, 0, -1):
        if d[d%n != 0].size == 0:
            print(n)
            return 0

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math
from functools import reduce

N,X=map(int,input().split())
x=list(map(int,input().split()))
x_dif=[]
for i in x:
    x_dif.append(X-i)
print(reduce(math.gcd, x_dif))

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

n,x=map(int,input().split())
l=[abs(c-x) for c in list(map(int,input().split()))]
if len(l)<2:
	print(l[0])
else:
	l.append(math.gcd(l[0],l[1]))
	for x in range(n-2):
		l.append(math.gcd(l[-1],l[x+2]))
	print(l[-1])

Submission status: Runtime Error

Solution code:
    NX =  list(map(int, input().split()))
    Points =  list(map(int, input().split()))
    Points.append(NX[1])
     
    min = min(Points)
    max = max(Points)
     
    ran = max - min
    interval = ran
    end = False
    Failed = False
     
    for i in range(interval):
        Failed = False
     
        for p in Points:
            if (p - min) % interval != 0:
                Failed = True
                break
     
        if(not Failed):
            print(interval)
            exit()
        interval -= 1

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

N, X = map(int, input().split())
if N == 1:
    x = abs(X - int(input()))
    print(x)
else:
    x = list(map(int, input().split()))
    x = list(map(lambda i: abs(X - i), x))
    print(reduce(math.gcd, x))

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce

n, x = map(int, input().split())
xs = map(int, input().split())
xs2 = map(lambda y: abs(y - x), xs)
print(reduce(gcd, xs2))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


N, X  = (int(i) for i in input().split())
x = (int(i) for i in input().split())
x = list(x)
x.append(X)
#print(x)
x = sorted(x)

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

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
tmp = input().split(' ')
N = int(tmp[0])
X = int(tmp[1])
l = list(map(int, input().split()))
len_l = len(l)
dis_list = []
for i in range(len_l-1):
    dis = l[i+1] - l[i]
    dis_list.append(dis)
len_dis = len(dis_list)
tmp_old = dis_list
for i in range(len_dis-1):
    tmp_new = []
    len_old_tmp = len(tmp_old)
    for j in range(len_old_tmp-i-1):
        tmp_new.append(gcd(tmp_old[j], tmp_old[j+1]))
print(tmp_new[0])

Submission status: Runtime Error

Solution code:
import math

n,x=map(int,input().split())
z=[]

y=[]
z=list(map(int, input().split()))
z.append(x)
z.sort()

for i in range(n):
  y.append(z[i+1]-z[i])

if n==1:
  print(y[0])
else:
  gcm=math.gcd(y[0],y[1])
  for i in range(2,n):
    gcm=math.gcd(gcm,y[i])
  print(gcm)

Submission status: Runtime Error

Solution code:
import math
def serch_index(X,x):
    for i in range(len(x)):
        if X >=x[i]:
            return i
def check_ans(temp_sub,ans):
    count = 0
    for i in temp_sub:
        if i%ans ==0:
            count += 1
        else:
            pass
    # print(count)
    if count == len(temp_sub):
        return False
    else:
        return True
def cal_gcd(temp_sub,ans):
    for i in temp_sub:
        temp_ans = math.gcd(i,ans)
        ans = min(ans,temp_ans)
    return ans

N,X = map(int,input().split())
x = list(map(int, input().split()))
if N == 1:
    print(abs(x[0]-X))
else:    
    X_index = serch_index(X, x)
    if X_index == None:
        x.insert(0,X)
    else:
        x.insert(X_index+1, X)
    x.sort()
    # print(x)
    temp_sub = []
    # print(x)
    for i in range(N):
        temp_sub.append(x[i+1]-x[i])
    # print(temp_sub)
    ans = abs(min(temp_sub))
    ans = cal_gcd(temp_sub, ans)
    
    # judge = True
    # while judge:
    #    judge = check_ans(temp_sub, ans)
    #    if judge:
    #         ans -=2
    print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import math
ans = 1000000000000000000
n, x = list(map(int, input().split())) # 整数
array = list(map(int, input().strip().split(' ')))

ans = abs(x-array[0])
for i in range(n-1):
    if math.gcd(ans,abs(array[i]-array[i+1])):
        ans =math.gcd(ans,abs(array[i]-array[i+1]))
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
tmp = input().split(' ')
N = int(tmp[0])
X = int(tmp[1])
l = list(map(int, input().split()))
len_l = len(l)
dis_list = []
print(l)
for i in range(len_l-1):
    dis = l[i+1] - l[i]
    dis_list.append(dis)
len_dis = len(dis_list)
tmp_old = dis_list
for i in range(len_dis-1):
    tmp_new = []
    len_old_tmp = len(tmp_old)
    for j in range(len_old_tmp-i-1):
        tmp_new.append(gcd(tmp_old[j], tmp_old[j+1]))
print(tmp_new[0])

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=[]
temp=[]

i=0

def yakusuu(num):
    yakusuu_list=[]
    for i in range(num):
        if num%i==0:
            yakusuu_list.append(i)
    return yakusuu_list


while(True):
    D_list.append(abs(X-int(city[i])))

    if D_list[-1] not in temp:
        temp.append(D_list[-1])
    Flag=True
    #print(D_list)

    for j in range(N):
        #print(D_list)
        if abs(int(city[j])-X) % D_list[-1]!=0:
            D_list.pop()
            break
            #Flag=False
    i+=1
    if i>=N:
        break

if len(D_list)==0:
    for i in range(len(temp)):
        D_test=yakusuu_list(temp[i])

    for k in range(len(D_test)):
        for j in range(N):
            if abs(int(city[j])-X) % D_test[k]==0:
                D_list.append(D_test[k])

print(max(D_list))

Submission status: Runtime Error

Solution code:
import math
import numpy as np
import functools

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

def main():
    diff_a=np.diff(a)
    gcd=functools.reduce(math.gcd,diff_a)
    print(gcd)

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
import math
N, X = map(int, input().split())
xlist =[X]
xlist.extend(list(map(int, input().split())))
dlist =[]
for i in range(N):
    dlist.append(abs(xlist[i+1]-xlist[i]))
g = max(dlist)
for d in dlist:
    g = math.gcd(g, d)
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()))
 
x.append(m)
x.sort() 
 
aa = []
for i in range(len(x)-1):
    a = x[i+1] - x[i]
    aa.append(a)
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)

if len(x) == 1:
    print(abs(x[0]-m))
else:
    print(gcd(*set(aa)))

Submission status: Runtime Error

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)-m for i in input().split()]
x.append(0)

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

for i in range(len(x)-1):
    li.append(abs(x[i]-x[i+1]))
temp=abs(min(x))
li.append(temp)
try:
    x.remove(temp)
except:
    x.remove(-temp)
temp=abs(min(x))
li.append(temp)



if f:
    for i in range(len(li)-1):
        a=li[0]
        a=gcd(a, li[i+1])
    print(a)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import fraction
 
tmp=input()
n = int(tmp.split(" ")[0])
X = int(tmp.split(" ")[1])
tmp=input()
i=int(0)
x=[]
for i in range(n):
    x.append(int(tmp.split(" ")[i]))
x.append(X)
x.sort()
y=[]

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

z=y[0]
i=0
while i < n:
    z=fraction.gcd(z,y[i])
    i+=1

print(z)

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))

L = len(left)
R = len(right)

if L != 0:
    for l in range(L-1):
        distance.append(left[l+1] - left[l])
    distance.append(X - left[-1])

if R != 0:
    distance.append(right[0] - X)
    for r in range(R-1):
        distance.append(right[r+1] - right[r])

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

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 = []
if len(b) == 2:
    print(b[1] - b[0])
    exit(0)
for i in range(1, n - 1):
    c.append(b[i] - b[i - 1])

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

Submission status: Runtime Error

Solution code:
import math as mh
import fractions as fr
from functools import reduce as rd

n, p = (int(_) for _ in input().split())
x = list(int(_) for _ in input().split())

lmin = abs(p - min(x))
lmax = abs(p - max(x))

d = fr.gcd(lmin, lmax)
exgcd = rd.reduce(fr.gcd, [d,lmin,lmax])

print(exgcd)

Submission status: Runtime Error

Solution code:
N,X=map(int,input().split())
inputcities=list(map(int, input().split()))
cities=list(set([abs(inputcities[i]-X) for i in range(N)]))
N=len(cities)
count=0
flag=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
      i=N
    if count==N:
      print(j)
      flag=1
      break
    if i==N:
      for k in range(2,j)
        if j%k==0:
          j=k
          break
  if flag==1:
    break

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:
def factorize(num):
    f_ary=[num]
    for i in range(num-1, 2, -1):
#        print i, "before", f_ary
        div = num / i
        if i * div == num:
#            print f_ary
            if i in f_ary:
                break
            else:
                f_ary.append(i)
            if div in f_ary:
                break
            else:
                f_ary.append(div)
#        print "after", f_ary

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

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

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

#points.sort()
points.reverse()

factors = factorize(points[0])


#print N,X, points, factors

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

print f

Submission status: 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:
n,x = map(int, raw_input().split())
lis = sorted(map(int, raw_input().split()))
def gcd(a, b):
    if a == 0:
        return b
    return gcd(b%a,a)
if n == 1:
    val = abs(lis[0]-x)
    print val
    exit()
import bisect
#print lis
idx = bisect.bisect_left(lis, x)
#print idx
if idx == 0:
    val = lis[0] - x
    flag = 0
    lmao = -1
    for i in range(1, n):
        if (lis[i] - x) % val != 0:
            flag = 1
            lmao = i
            break
    if flag == 0:
        print val
    else:
        factors = []
        flag1 = 0
        for i in range(min(x, lis[lmao]), 0, -1):
            if x % i == 0 and lis[lmao] % i == 0:
                for j in xrange(n):
                    if abs(lis[j]-x) % i != 0:
                        flag1 = 1
                        break
                if flag1==0:
                    print i
                    break
elif idx == n:
    val = x - lis[-1]
    flag = 0
    lmao = -1
    for i in range(n-2, -1, -1):
        if (x - lis[i]) % val != 0:
            lmao = i
            flag = 1
            break
    if flag == 0:
        print val
    else:
        factors = []
        flag1 = 0
        for i in range(min(x, lis[lmao]), 0, -1):
            if x % i == 0 and lis[lmao] % i == 0:
                for j in xrange(n):
                    if abs(lis[j]-x) % i != 0:
                        flag1 = 1
                        break
                if flag1==0:
                    print i
                    break
else:
    val = min(lis[idx]-x, x-lis[idx-1])
    flag = 0
    lmao = -1
    for i in range(idx, n, 1):
        if (lis[i]-x)%val != 0:
            flag= 1
            lmao = i
            break
    for i in range(idx-1, -1, -1):
        if (x-lis[i])%val != 0:
            lmao = i
            flag = 1
            break
    if flag == 0:
        print val
    else:
        factors = []
        flag1 = 0
        for i in range(min(x, lis[lmao]), 0, -1):
            if x % i == 0 and lis[lmao] % i == 0:
                for j in xrange(n):
                    if abs(lis[j]-x) % i != 0:
                        flag1 = 1
                        break
                if flag1==0:
                    print i
                    break


#print bisect.bisect_left(lis, 38)