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

    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())
kotae = list(map(int, input().split()))
kotae.append(x)
kotae = sorted(kotae)
t = kotae[1]-kotae[0]
for i in range(len(kotae)-1):
    t = math.gcd(t, kotae[i + 1] - kotae[i])
print(t)

Submission status: Runtime Error

Solution code:
import math

n,xs=map(int,input().split())

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

a=x[0]
for i in range(n):
    a=math.gcd(a,x[i])

print(a)

Submission status: Runtime Error

Solution code:
import math
import sys

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)

for i in range(len(odds)):
    for j in range(len(odds)):
        if math.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: Runtime Error

Solution code:
import math
from functools import reduce


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


m = min(toshi + [X])
    
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

temp = []
for i in toshi+[X]:
    temp.append(i-m)

print(gcd_list(temp))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
N, X = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(N):
    A[i] = abs(A[i] - X)
print(gcd_list(A))

Submission status: Runtime Error

Solution code:
n, s = map(int, raw_input().split())
xs = [ int(i) for i in raw_input().split()]

diff = [ abs(x-s) for x in xs]

divisors = []
target = min(diff)
while True:
    if target > max(diff):
        break
    if all([d % target == 0  for d in diff]):
        divisors.append(target)
    target += 1

print(max(divisors))

Submission status: Runtime Error

Solution code:
# coding: utf-8

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

ans = dxs[-1]

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

print(ans)

Submission status: Runtime Error

Solution code:
import math
N, X = map(int, input().split())
L = list(map(int, input().split()))
M = [abs(i-X) for i in L if i-X != 0]
n = len(M)
old = M[0]
if n > 1:
    for i in range(n-1):
        new = M[i+1]
        old = math.gcd(old, new)
print(old)

Submission status: Runtime Error

Solution code:
from math import gcd


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

x.append(X)
x.sort()

last = x[0]
ans = abs(x[0] - x[1])
for i in x[1:]:
    ans = gcd(ans, abs(last - i))
    last = i

print(ans)

Submission status: Runtime Error

Solution code:
import functools
import math

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

A=list(map(int,input().split()))
B=[]
for i in range(len(A)):
    B.append(A[i]-X)
#print(B)

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

Submission status: Runtime Error

Solution code:
import math

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

ans = None
for a in A:
    x = abs(a - X)
    if ans is None:
        ans = x
    elif x != 0:
        ans = math.gcd(ans, x)

if ans is not None:
    print(ans)
else:
    print(1)

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3

import math

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

a.sort()

res = 0
for val in a:
    if res == 0:
        res = val
    else:
        res = math.gcd(res, val)
        if res == 1:
            break

print(res)

Submission status: Runtime Error

Solution code:
import math

N, X = map(int, input().split())
koyaku = 0
index = 0
for x in map(int, input().split()):
    if index == 0:
        koyaku = abs(x - X)
        index = 1
    else:
        l = abs(x - X)
        koyaku = math.gcd(koyaku, l)
print(koyaku)

Submission status: Runtime Error

Solution code:
import math

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

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

x.append(X)

x.sort()

xx=[]

for i in range(1,n+1):
    xx.append(x[i]-x[i-1])

xxx = math.gcd(xx[0],xx[1])

if n == 2:
    print(xxx)
    exit()

for i in range(2,n):
    xxx=math.gcd(xxx,xx[i])
print(xxx)

Submission status: Runtime Error

Solution code:
import math
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]
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
from functools import reduce

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

x.append(X)
sx = sorted(x)
dx = [j - i for i, j in zip(sx[:-1], sx[1:])]

mdx = reduce(math.gcd, dx)

print(mdx)

Submission status: Runtime Error

Solution code:
from fraction import gcd

if __name__ == '__main__' :
    N,X = map(int, input().split())
    x = list(map(int, input().split()))

    dist_list = [abs(d-X) for d in x]

    alpha = gcd(dist_list[0],dist_list[1])
    for d in dist_list:
        alpha = gcd(alpha,d)

    print(alpha)

Submission status: Runtime Error

Solution code:
import math


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 = math.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: Runtime Error

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

for i in range(len(xs)):
  xs[i] = abs(xs[i] - X)

isis = False
if N == 1:
  print(xs[0] - X)
  isis = True

max_dis = max(abs(xs[i] - xs[i+1]) for i in range(len(xs) - 1))
min_dis = min(abs(xs[i] - xs[i+1]) for i in range(len(xs) - 1))
a, b = max_dis, min_dis
while isis:
  if b == 0:
    print(a)
    break
  c = a % b
  if c == 0:
    print(b)
    break
  a = b
  b = c

Submission status: Runtime Error

Solution code:
from math 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])
if len(diffs) == 1:
  m = diffs[0]
print(m)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
DATA = input()

N,X = DATA.split()
N = int(N)
X = int(X)

DATA = input()
x = DATA.split()

x[0] = int(x[0])
num = abs(X-x[0])

for lop in range(1,N):
    x[lop] = int(x[lop])
    sa = abs(X-x[lop])
    num = math.gcd(num,sa)
print(num)

Submission status: Runtime Error

Solution code:
N, X = map(int, input().split())
xs = list(map(int, input().split()))
xs.append(X)
xs.sort()
xs = [_ - xs[0] for _ in xs]
diffs = [xs[i]-xs[i-1] for i in range(1, len(xs))]
def gcd(a, b):
    if(a>b): return gcd(b, a)
    if a % b == 0:
      return b
    else:
      r = a % b
      return gcd(b, r)

prev = diffs[0]
for cur in diffs[1:]:
    prev = gcd(prev, cur)
print(prev)

Submission status: Runtime Error

Solution code:
n,x= map(int,input().split())
a = input().rstrip().split() 
b = [0]*n

for i in range(0,n):
    b[i]=abs(int(a[i])-x)
b.sort()#昇順

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

def multi_GCD(le):
    # print(le)
    if len(le)==1:
        return 
    mxle=le[-1]
    del(le[-1])
    le[-1]=GCD(le[-1],mxle)
    multi_GCD(le)

if(len(b)==1):
    print(b[0])
if(len(b)==2):
    print(GCD(b[0],b[1]))
if(len(b)>2):
    multi_GCD(b)
    print(b[0])

Submission status: Runtime Error

Solution code:
import math

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([math.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: Runtime Error

Solution code:
import math


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

y = [abs(xi - X) for xi in x]
r = y[0]

for i in range(N-1):
    if y[i+1] != 0:
        r = math.gcd(r, y[i+1])

print(r)

Submission status: Runtime Error

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

import math
import functools

lgap = [i-B for i in l]
gcd = functools.reduce(math.gcd, lgap)
print(gcd)

Submission status: Runtime Error

Solution code:
import math

N, X = map(int, input().split())
koyaku = 0
for index, x in enumerate(map(int, input().split())):
    if index == 0:
        koyaku = abs(x - X)
    else:
        l = abs(x - X)
        koyaku = math.gcd(koyaku, l)
print(koyaku)

Submission status: Runtime Error

Solution code:
N, X = map(int, input().split())
xs = list(map(int, input().split()))
xs.append(X)
xs.sort()
xs = [_ - xs[0] for _ in xs]
diffs = [xs[i]-xs[i-1] for i in range(1, len(xs))]
def gcd(a, b):
  if(a>b): return gcd(b, a)
  if a % b == 0:
    return b
  else:
    r = a % b
    return gcd(b, r)

prev = diffs[0]
for cur in diffs[1:]:
  prev = gcd(prev, cur)
print(prev)

Submission status: Runtime Error

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:
        mini = math.gcd(mini, x[i] - x[i - 1])
    if abs(X - x[i]) % mini != 0:
        mini = math.gcd(mini, X - x[i])
        

print(mini)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

ans = gcd([abs(c - X) for c in cities])


print(ans)

Submission status: Runtime Error

Solution code:
import math

N, X = map(int, input().split())
xlist = list(map(int, input().split()))
xlist.append(X)
xsorted = sorted(xlist)
xsub = [xsorted[i + 1] - xsorted[i] for i in range(N)]
gcd = xsub[0]
for x in xsub:
    gcd = math.gcd(x, gcd)
print(gcd)

Submission status: Runtime Error

Solution code:
import math

n,xs=map(int,input().split())

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


print(math.gcd(*x))

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):
    a.append(x_list[i+1]-x_list[i])
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
print(gcd_list(a))

Submission status: Runtime Error

Solution code:
from math import gcd

if __name__ == '__main__' :
    N,X = map(int, input().split())
    x = list(map(int, input().split()))

    dist_list = [abs(d-X) for d in x]

    alpha = gcd(dist_list[0],dist_list[1])
    for d in dist_list:
        alpha = gcd(alpha,d)

    print(alpha)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from numpy import gcd

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

Solution code:
import math
a,b = [int(i) for i in input().split(' ')]
xs = [int(i) for i in input().split(' ')]

temp = 0
result = 0
for i, x in enumerate(xs):
    if i == 0:
        result = abs(x - b)
    else:
        result = math.gcd(abs(x - temp), result)
    temp = x
print(result)

Submission status: Runtime Error

Solution code:
from fraction 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: Runtime Error

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

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

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

print(gc(x))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
from functools import reduce

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

N, X = map(int, input().split())
xn = list(map(int, input().split()))
xn2 = []

for xi in xn:
    xn2.append(xi - X)

# print(xn2)
print(gcd_list(xn2))

Submission status: Runtime Error

Solution code:
import math

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

lis = list(map(int,input().split()))
diffs = []
for i in range(n):
    diff = abs(lis[i]-x)
    diffs.append(diff)

if n > 1:
    com = math.gcd(diffs[0],diffs[1])
    for i in range(n-2):
        com = math.gcd(com, diffs[i+2])
else:
    com = diffs[0]

print(com)

Submission status: Runtime Error

Solution code:
from numpy import gcd

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

x.sort()
diff_x = [x[i+1] - x[i] for i in range(n-1)]
ans = 1
for x_i in x:
    ans = int(gcd(ans, x_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 = 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:
from math 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: Runtime Error

Solution code:
import numpy as np
import functools
import math

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

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

values = np.sort(np.array(x_list))[1:] - min(x_list)
gcd = functools.reduce(math.gcd, values)
print(gcd)

Submission status: Runtime Error

Solution code:
import math

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

for i in range(N):
  if town[i] < X:
    town[i] = X - town[i]
  else:
    town[i] = town[i] - X

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

Submission status: Runtime Error

Solution code:
import fraction
from functools import reduce

n,X = map(int,input().split())
x =list(map(int,input().split()))
x.append(X)
x.sort()
a = []*n
for i in range(n):
  a[i] = x[i+1]-x[i]
  
g = gcd(*a)
print(g)

Submission status: Runtime Error

Solution code:
import math

N,X=map(int,input().split(" "))
xl=list(map(int,input().split(" ")))
xl.append(X)
xl=sorted(xl)

xy=[xl[i+1]-xl[i] for i in range(len(xl)-1)]

ans=max(xy)
for i in range(len(xy)):
    ans=math.gcd(ans,xy[i])

print(ans)

Submission status: Runtime Error

Solution code:
N, X = map(int, input().split())
xs = map(int, input().split())
xs.append(X)
xs.sort()
xs = [_ - xs[0] for _ in xs]
diffs = [xs[i]-xs[i-1] for i in range(1, len(xs))]
def gcd(a, b):
  if(a>b): return gcd(b, a)
  if a % b == 0:
    return b
  else:
    r = a % b
    return gcd(b, r)

prev = diffs[0]
for cur in diffs[1:]:
  prev = gcd(prev, cur)
print(prev)

Submission status: Runtime Error

Solution code:
import math
def solve(N, X, cities):
    dists = [abs(city - X) for city in cities]
    min_d = min(dists)
    return max([math.gcd(min_d, d) for d in dists])

if __name__ == "__main__":
    l = input()
    N, X = int(l.split()[0]),int(l.split()[1])
    cities = [int(c) for c in input().split()]
    print(solve(N, X, cities))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import fraction

N,X = map(int,input().split())
x = [int(i) for i in input().split()]
ans = abs(X-x[0])
now = X
for i in x:
    if abs(now - i) % ans:
        ans = fraction.gcd(ans, abs(now-i))
    now = i

print(ans)

Submission status: Runtime Error

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

def minus_x(t):
    return int(t) - x
cities = list(map(minus_x,input().split(" ")))

import math
if n == 1:
    ans = cities[0]
else:
    ans = math.gcd(cities[0],cities[1])
    for i in range(2,n-1):
        ans = math.gcd(cities[i],ans)

print(ans)

Submission status: Runtime Error

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

xl.append(x)
xl.sort()
sa = []
onesam = 2000000000
for i in range(len(xl)-1):
    one_sa = xl[i+1] - xl[i]
    if one_sa % onesam == 0:
        continue
        
    if onesam > one_sa:
        onesam = one_sa
        
    
sa.sort()
samin = min(sa)

flag = 0
while flag == 0:
    amari = 0
    for i in sa:
        amari += i % samin
        if amari != 0:
            break
            
    if amari == 0:
        flag = 1
        break
    else:
        for j in range(1,samin+1):
            if samin % j == 0:
                samin = samin // j
                break
print(samin)

Submission status: Runtime Error

Solution code:
import math

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

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

x.append(X)

x.sort()

xx=[]

for i in range(1,n+1):
    xx.append(x[i]-x[i-1])

xgcd = math.gcd(xx[0],xx[1])

if n == 2:
    print(xgcd)
    exit()

for i in range(2,n):
    xgcd=math.gcd(xgcd,xx[i])
print(xgcd)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a
  
def gcd_list(y):
    if len(y)==1:
        return y[0]
    if len(y)==2:
        return gcd(y[0],y[1])
    else:
        return gcd(y[0],gcd_list(y[1:]))

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

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

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

print gcd_list(x)

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce

N,X = map(int, input().split())
xn = list(map(lambda x: int(x)-X, input().split()))
print(reduce(gcd, xn))

Submission status: Runtime Error

Solution code:
import math

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 = math.gcd(ans, dx)
elif len(x) == 2:
    ans = x[1] - x[0]
else:
    ans = 0

print(ans)

Submission status: Runtime Error

Solution code:
import functools
import math

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

l2 = map(lambda t: t-x, l)

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

Submission status: Runtime Error

Solution code:
import math

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

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

print(ans)

Submission status: Runtime Error

Solution code:
import math
import sys
sys.setrecursionlimit(100000) 
N, X = map(int, input().split())
city = [X] + list(map(int, input().split()))
city_diff = [abs(city[i + 1] - city[i]) for i in range(N)]
ans = city_diff[0]
for i in range(1, N, 1):
    ans = math.gcd(ans, city_diff[i])
print(ans)

Submission status: Runtime Error

Solution code:
import math
n,X=map(int, input().split())
x=list(map(int, input().split()))
ans=abs(x[0]-X)
for xi in x[1:]:
    ans=math.gcd(ans, abs(xi-X))
print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
N, S = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
i = bisect_left(x, S)
if x[i] != S:
    x.insert(i, S)
    N += 1
diff = []
for i in range(N - 1):
    diff.append(x[i + 1] - x[i])

# 最小公倍数を求める
def lcm(a, b):
    while b != 0:
        a, b = b, a % b
    return a
ans = diff[0]
for d in diff[1:]:
    ans = lcm(ans, d)
print(ans)

Submission status: Runtime Error

Solution code:
import math

N, X = list(map(int, input().split(" ")))
town = list(map(int, input().split(" ")))
town.sort()

max_v = math.inf
for v in town:
    m = abs(v-N)
    if m < max_v:
        max_v = m



while True:
    Flag = True
    for i in range(len(town) - 1):
        if not abs(town[i]-town[i+1]) % max_v == 0:
            Flag = False
            break

    if Flag:
        break
    else:
        max_v -= 1

print(max_v)

Submission status: Runtime Error

Solution code:
'''input
3 5
1 2 3
'''
from fractions import gcd
n,x = map(int,raw_input().split())
arr = map(int,raw_input().split())
arr.append(x)
arr.sort()
diff = []
for i in range(1,n):
	diff.append(arr[i]-arr[i-1])
gc = diff[0]
for i in range(1,len(diff)):
	gc = gcd(gc,diff[i])
print gc

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

for i in range(N):
  if town[i] < X:
    town[i] = X - town[i]
  else:
    town[i] = town[i] - X

print(gcd_list(town))

Submission status: Runtime Error

Solution code:
import math

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

koyaku = abs(x[0] - X)
for i in range(1, N):
    l = abs(x[i] - X)
    koyaku = math.gcd(koyaku, l)
print(koyaku)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

ip = input().split()
st = int(ip[1])

li = []

ip2 = input().split()
for i in ip2:
    li.append(abs(int(i) - st))

print(gcd_list(li))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
n,xs=map(int,input().split())

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

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

print(gc(x))

Submission status: Runtime Error

Solution code:
import fraction
from functools import reduce

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

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

print(gcd_list(pos))

Submission status: Runtime Error

Solution code:
# abc109c

import math

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

x.append(X)
x.sort()
diff = [x[1]-x[0]]
for i in range(N):
    diff.append(x[i+1]-x[i])
#print(x)
#print(diff)
D = math.gcd(diff[0],diff[1])
for i in range(2,N+1):
    D = math.gcd(D,diff[i])
    #print(diff[i],D)
print(D)

Submission status: Runtime Error

Solution code:
import fraction

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

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

dist_list = [abs(X - e) for e in x]
ans = dist_list[0]
for e in dist_list:
    ans = fraction.gcd(e, ans)


print(ans)

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

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

a = []

for i in range(n):
    tmp = abs(w[i]-x)
    a.append(tmp)
    
#ans = a[0]
#
#for i in range(1, n):
#    now = a[i]
    
print(gcd_list(a))

Submission status: Runtime Error

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

N, X = [int(n) for n in input().split()]
xs = [int(n) - X for n in input().split()]

if all([n == xs[0] for n in xs]):
    m = min(xs)
    xs = [n - m for n in xs]
    g = gcd(max(xs[0], xs[1]), min(xs[0], xs[1]))
    for n in xs[2:]:
        g = gcd(max(g, n), min(g, n))
    print(g)
else:
    print(xs[0])

Submission status: Runtime Error

Solution code:
import math

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

if N == 1:
    print(abs(xlist[0] - X))

else:
    xsorted = sorted(xlist)
    xsub = [xsorted[i + 1] - xsorted[i] for i in range(N - 1)]
    gcd = xsub[0]
    for x in xsub:
        gcd = math.gcd(x, gcd)
    print(gcd)

Submission status: Runtime Error

Solution code:
# coding=utf-8


def solve_gcd_from_list(number_list):
    if len(number_list) == 2:
        return solve_gcd(number_list[0], number_list[1])
    follow = solve_gcd(number_list[-2], number_list[-1])
    number_list2 = [follow]
    number_list2.extend(number_list[:-2])
    return solve_gcd_from_list(number_list2)


def solve_gcd(number1, number2):
    if number1 == number2:
        return number1

    if number1 < number2:
        number1, number2 = number2, number1

    if number1 % number2 == 0:
        return number2

    return solve_gcd(number2, number1 % number2)


if __name__ == '__main__':
    N, X = map(int, input().split())
    cities = list(map(int, input().split()))

    cities.append(X)
    cities.sort()

    distance_list = []

    for i in range(N):
        distance_list.append(cities[i+1]-cities[i])

    if len(distance_list) == 1:
        D = distance_list[0]
    else:
        D = solve_gcd_from_list(distance_list)
    print(D)

Submission status: Runtime Error

Solution code:
import math

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

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

x.append(X)

x.sort()

xx=[]

for i in range(1,n):
    xx.append(x[i]-x[i-1])

xgcd = math.gcd(xx[0],xx[1])

for i in range(2,n-1):
    xgcd=math.gcd(xgcd,xx[i])
print(xgcd)

Submission status: Runtime Error

Solution code:
import math
import functools

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

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

if len(dif) != 1:
    gcd = functools.reduce(math.gcd, dif)
    print(gcd)
else:
    print(dif[0])

Submission status: Runtime Error

Solution code:
import numpy as np
import math
N,X=map(int,input().split())
x=list(map(int,input().split()))
for i in range(N):
    if i==0:
        ans=x[i]-X
    else:
        ans=math.gcd(ans,x[i]-X)
print(ans)

Submission status: Runtime Error

Solution code:
import math
def solve(N, X, cities):
    dists = [city - X for city in cities]
    gcd = dists[0]
    for d in dists[1:]:
        gcd = math.gcd(gcd, d)
    return gcd

if __name__ == "__main__":
    l = input()
    N, X = int(l.split()[0]),int(l.split()[1])
    cities = [int(c) for c in input().split()]
    print(solve(N, X, cities))

Submission status: Runtime Error

Solution code:
n,x=map(int, input().split())
a=list(map(int, input().split()))
mina=min(a)
a=[i-mina for i in a]+[x-mina]
f=max(a)
for i in a:
    if i!=0:
        f=fractions.gcd(f,i)
print(f)

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
import itertools

if __name__ == "__main__":
    N, X = list(map(int, input().split()))
    xs = list(map(int, input().split()))

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

    xs.sort()
    lowers = list(itertools.takewhile(lambda x: x<=X, xs))
    low = lowers[-1]
    high = xs[len(lowers)]
    Ds = []
    Ds.append(X - low)
    Ds.append(high - X)
    for d in Ds:
        failed = False
        for x in xs:
            if abs(X-x)%d == 0:
                continue
            else:
                failed = True
                break
        if failed:
            continue
        else:
            print(d)
            exit()
    print(1)