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:
# 最大公約数(mathは3.5以降) 
import math
from functools import reduce

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

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

# 初期入力
import sys
#input = sys.stdin.readline  #文字列では使わない
N,X = map(int, input().split())
x = list(map(int, input().split()))

# ｘの隣同士の距離リスト
x_div =[abs(X-x[0])] #初項
for i in range(N):
    x_div.append(abs(x[i] -x[i+1]))

#x_divの最大公約数
if N ==1:
    ans =abs(x[0] -X)
else:
    ans =gcd_list(x_div)
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

x.append(X)
x.sort()

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

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

x.append(X)
x.sort()

if N==1:
    ans = abs(x[1]-x[0])


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

print(ans)

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:
    print(math.gcd(x[1]-x[0],x[2]-x[1]))
else:
    print(abs(x[0]-X))

Submission status: Runtime Error

Solution code:
import math

# 最大公約数を求める問題
N, X = map(int, input().split())
x = [int(_) for _ in input().split()]
if N == 1:
    print(abs(x[0]-X))
    exit()

x.sort()
# N > 1と仮定
for i in range(N-1):
    if x[i] < X and x[i+1] > X:
        x = x[:i+1] + [X] + x[i+1:]
        break

if len(x) >= 3:
    base = math.gcd(x[1]-x[0], x[2]-x[1])
    for i in range(2, N):
        diff = x[i+1] - x[i]
        base = math.gcd(base, diff)
    print(base)
else:
    print(x[1] - x[0])

Submission status: Runtime Error

Solution code:
import math

# 最大公約数を求める問題
N, X = map(int, input().split())
x = [int(_) for _ in input().split()]
if N == 1:
    print(abs(x[0]-X))
    exit()

x.sort()
# N >= 1と仮定
for i in range(N-1):
    if x[i] <= X and x[i+1] > X:
        x = x[:i+1] + [X] + x[i+1:]
        break

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

Submission status: Runtime Error

Solution code:
import math

# 最大公約数を求める問題
N, X = map(int, input().split())
x = [int(_) for _ in input().split()]
if N == 1:
    print(abs(x[0]-X))
    exit()

x.sort()
# N >= 1と仮定
for i in range(N-1):
    if x[i] <= X and x[i+1] > X:
        x = x[:i-2] + [X] + x[i+1:]
        break

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

Submission status: Runtime Error

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

min_dist = abs(X - min(L))

ans = 1

for d in range(min_dist, 0, -1):
    b = all((x - X) % d == 0 for x in L)
    if b:
        print(d)
        break

Submission status: Runtime Error

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

min_dist = abs(X - min(L))

ans = 1

for d in range(min_dist, 0, -1):
    b = all((x - X) % d == 0 for x in L)
    if b:
        print(d)
        break

Submission status: Runtime Error

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

li = []
x.sort()
for i in range(N):
  li.append(x[i+1]-x[i])
  
li.sort()
while len(li) > 1:
  l = []
  div = li[0]
  for n in li:
    mod = n % div
    if mod != 0:
      mod.append(l)
  l.append(div)
  l.sort()
  li = l
print(*li)

Submission status: Runtime Error

Solution code:
import math
def main():
    N,X=map(int,input().split())
    x=[a-X for a in sorted(map(int,input().split()), reverse=True)]
    if N == 1:
        print(x[0])
        return
    d=[]
    for i in range(N-1):
        d.append(x[i]-x[i+1])
    ans=math.gcd(d[0], d[1])
    for a in d[1:]:
        ans = math.gcd(ans, a)
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math
def main():
    n,x=map(int,input().split())
    x=sorted(map(int,input().split()), reverse=True)
    d=[]
    for i in range(n-1):
        d.append(x[i]-x[i+1])
    if len(d) < 1:
        print(x[0]-1)
        return
    ans=math.gcd(d[0], d[1])
    for a in d[1:]:
        ans = math.gcd(ans, a)
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

x = list(map(int,input().split()))
lst = [0]*N
for i in range(len(x)):
    lst[i] = abs(x[i] - X)
    
def find_gcd(x, y): 
    while(y): 
        x, y = y, x % y 
  
    return x 

num1=lst[0] 
num2=lst[1] 
gcd=find_gcd(num1,num2) 
  
for i in range(2,len(lst)): 
    gcd=find_gcd(gcd,lst[i]) 
    
print(gcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

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

res = [abs(x[i+1]-x[i]) for i in range(len(x))]
print(gcd(*res))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

res = [x[i+1]-x[i] for i in range(len(x)-1)]

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

print(gcd(*res))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
N, X = map(int, input().slpit())
x = list(map(int,input().split()))
 
for i in range(N):
    x[i] = abs(x[i]-X)
 
x = sorted(x)[::-1]
cnt = 0
 
for i in range(N):
    cnt = math.gcd(cnt, x[i])
 
print(cnt)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
N, X = map(int, input().slpit())
x = [int(input()) for i in range(N)]

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

x = sorted(x)[::-1]
cnt = 0

for i in range(N):
    cnt = math.gcd(cnt, x[i])

print(cnt)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
N, X = map(int, input().split())
x = [int(input()) for i in range(N)]
 
 
x.insert(0,X)
x = sorted(x)
 
y = [0]*N
 
for i in range(N):
    y[i] = x[i+1]-x[i]
 
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
 
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
 
print(gcd(*y))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
N, X = map(int, input().split())
x = [int(input()) for i in range(N)]


x.insert(0,X)
x = sorted(x)

y = [0 for i in range(N)]

for i in range(N):
    y[i] = x[i+1]-x[i]

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

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

print(gcd(*y))

Submission status: Runtime Error

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

x = list(map(int,input().split()))
st = []
x.append(X)

x.sort()

gcd = x[0]

for i in range(N):
    gcd = math.gcd(gcd,x[i+1]-x[i])
    st.append(x[i+1]-x[i])
st.sort()
for v in st:
    if not v % gcd:
        print(v)
        break

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
n,s=map(int,input().split())
x=list(map(int,input().split()))
#print(x)

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

gcd=reduce(math.gcd,x)

print(gcd)

Submission status: Runtime Error

Solution code:
import math

n,s=map(int,input().split())
x=list(map(int,input().split()))
ans=0
#print(x)

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

print(ans)

Submission status: Runtime Error

Solution code:
import functools
from math import gcd
n,x =map(int,input().split())
lis = list(map(int,input().split()))
for i in range(n):
lis[i] = abs(lis[i]-x)
print(functools.reduce(gcd,lis))

Submission status: Runtime Error

Solution code:
from functools import reduce
from math import gcd
n,x =map(int,input().split())
if n==1:
    c = abs(int(input())-x)
    print(c)
else:
    lis = list(map(int,input().split()))
    for i in range(n):
        lis[i] = abs(lis[i]-x)
    print(reduce(gcd,lis))

Submission status: Runtime Error

Solution code:
import functools
from math import gcd
n,x =map(int,input().split())
if n==1:
    print(abs(int(input())-x))
else:
    lis = list(map(int,input().split()))
    for i in range(n):
        lis[i] = abs(lis[i]-x)
    print(functools.reduce(gcd,lis))

Submission status: Runtime Error

Solution code:
import math,functools

n,x =map(int,input().split())
if n==1:
    print(abs(int(input())-x))
else:
    lis = list(map(int,input().split()))
    for i in range(n):
        lis[i] = abs(lis[i]-x)
    print(functools.reduce(math.gcd,lis))

Submission status: Runtime Error

Solution code:
from math import gcd
n, x =map(int,input().split())
s = list(map(int,input().split()))
y = abs(s[0] - x)
for i in range(1,n-1):
    y = gcd(y, abs(s[i] - x))
print(y)

Submission status: Runtime Error

Solution code:
from fraction import gcd
n, x =map(int,input().split())
s = list(map(int,input().split()))
s.sort()
a, b = x - s[0], s[-1] - x
visit = [0] * n
while sum(visit) != n:
    visit = [0] * n
    y = gcd(a, b)
    i = 0
    while s[0] + y * i <= s[-1] :
        if s[0] + y * i in s:
            visit[s.index(s[0] + y * i)] = 1
        i += 1
    a,b = min(a, b), y
print(y)

Submission status: Runtime Error

Solution code:
n, x =map(int,input().split())
s = list(map(int,input().split()))
s.sort()
a, b = x - s[0], s[-1] - x
visit = [0] * n
while sum(visit) != n:
    visit = [0] * n
    y = gcd(a, b)
    i = 0
    while s[0] + y * i <= s[-1] :
        if s[0] + y * i in s:
            visit[s.index(s[0] + y * i)] = 1
        i += 1
    a,b = min(a, b), y
print(y)

Submission status: Runtime Error

Solution code:
def gcd(x, y):
    while (y):
        x, y = y, x % y
    return x

n,x=map(int,input().split())
a=list(map(int,input().split()))
if n==1:
    print(abs(a[0]-x))
else:
    a.append(x)
    a.sort()
    s = set()
    for i in range(1, n):
        s.add(a[i] - a[i - 1])
    s = list(s)
    hcf = s[0]
    for i in s:
        if i!=0:
            hcf = gcd(gcd, i)
    print(gcd)

Submission status: Runtime Error

Solution code:
def gcd(x, y):
    while (y):
        x, y = y, x % y
    return x

n,x=map(int,input().split())
a=list(map(int,input().split()))
if n==1:
    print(abs(a[0]-x))
else:
    a.append(x)
    a.sort()
    s = set()
    for i in range(1, n):
        s.add(a[i] - a[i - 1])
    s = list(s)
    gcd = s[0]
    for i in s:
        if i!=0:
            gcd = gcd(gcd, i)
    print(gcd)

Submission status: Runtime Error

Solution code:
import math
n,x=map(int,input().split())
a=list(map(int,input().split()))
if n==1:
    print(abs(a[0]-x))
else:
    a.append(x)
    a.sort()
    s = set()
    for i in range(1, n):
        s.add(a[i] - a[i - 1])
    s = list(s)
    gcd = s[0]
    for i in s:
        if i!=0:
            gcd = math.gcd(gcd, i)
    print(gcd)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, s, *x = map(int, read().split())
x.append(s)
x.sort()
k = x.index(s)
r = min(abs(x[k + 1] - s), abs(x[k - 1] - s))
for i in reversed(range(r + 1)):
    div = s % i
    bl = True
    for a in x:
        if a % i != div:
            bl = False
            break
    if bl == True:
        print(i)
        exit()

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

# move1 = D
# move2 = -D


# D = 1のときは必ずゴールできる
ans = []
# 初期のXとそれ以外の街の差をDで割ったあまりが全て0なら訪れることができる
# つまりそれぞれの街の差を保存し、その最大公約数がDとなる
for i in range(N):
    dfe = abs(L[i] - X)
    ans.append(dfe)

ans = list(set(ans))

# reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]
# functoolsのreduceはある関数があり、それを前の計算結果と重なりを考慮しながら
# 関数に当てはめる、というアクションを繰り返す


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


# print(ans)
# print(reduce(lambda x, y: x + y, ans))
print(gcd_list(ans))

Submission status: Runtime Error

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

is_ok = True
# x[i] - X たちの最大公約数

from math import gcd
if N == 1:
    print(abs(x[0]-X))
elif N == 2:
    GCD = gcd(abs(x[0]-X), abs(x[1]-X))
    print(GCD)
else:
    GCD = gcd(abs(x[0]-X), abs(x[1]-X))
    for i in range(2, N):
        a = abs(x[i] - X)
        GCD = gcd(GCD, a)

    print(GCD)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

n, x = map(int, input().split())
xl = list(map(int, input().split()))
l = []

for i in xl:
    l.append(abs(i - x))

ans = l[0]

for i in l:
    ans = math.gcd(ans, i)

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from math import gcd

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

res = abs(X - x[0])
for v in x[1:]:
    res = gcd(res, abs(X - v))

print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

x_min=min(x)
a=[x_min]*N
g=np.gcd(a,x)
print(min(g))

Submission status: Runtime Error

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

if __name__ == "__main__":
    n,x = map(int,input().split())
    X = list(map(int,input().split()))
    X.sort()
    a = bisect.bisect_left(X,x)
    X.insert(a,x)
    ans = []
    for i in range(1,len(X)):
        diff = X[i] - X[i-1]
        ans.append(diff)
    d = ans[0]
    for i in range(1,len(ans)):
        d = math.gcd(d,ans[i])
    print(d)

Submission status: Runtime Error

Solution code:
from math import gcd
n,x=map(int, input().split())
town=list(map(int, input().split()))+[x]
town.sort()
if n == 1:
    town.remove(x)
    print(abs(town[0]-x))
    exit()

d1 = abs(town[0]-town[1])
d2 = abs(town[1]-town[2])
ans = gcd(d1,d2)

for i in range(2,n):
    d = abs(town[i]-town[i+1])
    ans = gcd(d,ans)
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

d = x[0]
for xi in x[1:]:
    d = math.gcd(d, xi)
print(d)

Submission status: Runtime Error

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

Submission status: Runtime Error

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


ok = [1]
if m == 1:
    print(z[0]-n)
    exit()

for i in range(1,z[1]-z[0]):
    ans = True
    for j in range(len(z)-1):
        if abs(z[j]-m)%i != 0:
            ans = False
            break
    if ans :
        ok.append(i)
print(ok[-1])

Submission status: Runtime Error

Solution code:
import math
n, x, *a = list(map(int, open(0).read().split()))
ans = abs(a[0] - x)
for i in range(1, n):
    ans = math.gcd(ans, abs(x - a[i]))
print(ans)

Submission status: Runtime Error

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


ok = [1]
if m == 1:
    print(z[0]-n)
    exit()

for i in range(1,z[1]-z[0]):
    ans = True
    for j in range(len(z)):
        if abs(z[j]-m)%i != 0:
            ans = False
    if ans :
        ok.append(i)
print(ok[-1])

Submission status: Runtime Error

Solution code:
import math
n, x, *a = list(map(int, open(0).read().split()))
a.append(x)
a = sorted(a)
ans = a[1] - a[0]
for i in range(1, n - 1):
    ans = math.gcd(ans, abs(a[i + 1] - a[i]))
print(ans)

Submission status: Runtime Error

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

xl.append(x)

arr=np.array(xl)

p=min(arr)
arrr=arr-p
print(np.gcd.reduce(arrr))

Submission status: Runtime Error

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

lis = []
for x in Xs:
    lis.append(abs(x-X))

G = 0
for l in lis:
    G = gcd(l, G)
print(G)

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,x=map(int, input().split())
    l=list(map(int,input().split()))
    if n==1:
        print(l[0]-x)
    else:
        l.append(x)
        l.sort()
        S=[]
        for i in range(n):
            S.append(l[i+1]-l[i])
        from functools import reduce
        from math import gcd
        print(reduce(gcd,S))
resolve()

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,x=map(int, input().split())
    l=list(map(int,input().split()))
    if n==1:
        print(l[0]-x)
    else:
        l.append(x)
        l.sort()
        S=[]
        for i in range(n-1):
            S.append(l[i+1]-l[i])
        from functools import reduce
        from math import gcd
        print(reduce(gcd,S))
resolve()

Submission status: Runtime Error

Solution code:
n,x = map(int,input().split())
li = list(map(int,input().split()))
lin = [abs(i-x) for i in li]
print(lin)
import fractions#python3.4ではmathではなくこちらのライブラリを用いる
def gcd_all(list):
    return gcd_all([fractions.gcd(*list[:2])] + list[2:]) if len(list) > 1 else list[0]
gcd = gcd_all(lin)

print(gcd)

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce


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


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

x_arr = [0] * n

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

for i in range(len(x_arr)):
    x_arr[i] = abs(x_arr[i] - x)
print(gcd_list(x_arr))

Submission status: Runtime Error

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

def ggcd(lista):
  if(len(lista) == 1):
    return lista.pop()
  else:
    l = lista.pop()
    for i in range(1, len(lista)):
      l = gcd(l, lista.pop())
    return l

N, X = map(int, input().split())
x = list(map(int, input().split()))
m = min(x)
d = []
gcds = set()
if(X < m):
  d.append(m- X)
else:
  if(N > 1):
    x.sort()
    if(x[1] > X):
      d.append(X- m)
      del x[0]
      x.insert(0, X)
    else:
      d.append(x[1]- x[0])
      del x[0]
      x.insert(0, X)
  else:
    d.append(abs(x[0]- X))
  
x.sort()
  
for i in range(N- 1):
  d.append(x[i+ 1]- x[i])
  
gcds.add(d[0])

for i in range(N- 1):
  if(d[i+ 1] != d[i]):
    gcds.add(d[i+ 1])

print(ggcd(gcds))

Submission status: Runtime Error

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

def ggcd(lista):
  if(len(lista) == 1):
    return lista.pop()
  else:
    l = lista.pop()
    for i in range(1, len(lista)):
      l = gcd(l, lista.pop())
    return l

N, X = map(int, input().split())
x = list(map(int, input().split()))
m = min(x)
d = []
gcds = set()
if(X < m):
  d.append(m- X)
else:
  if(N > 1):
    x.sort()
    if(x[1] > X):
      d.append(X- m)
      del x[0]
      x.insert(0, X)
    else:
      d.append(x[1]- x[0])
      del x[0]
      x.insert(0, X)
  
x.sort()
  
for i in range(N- 1):
  d.append(x[i+ 1]- x[i])
  
gcds.add(d[0])

for i in range(N- 1):
  if(d[i+ 1] != d[i]):
    gcds.add(d[i+ 1])

print(ggcd(gcds))

Submission status: Runtime Error

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

def ggcd(lista):
  if(len(lista) == 1):
    return lista.pop()
  else:
    l = lista.pop()
    for i in range(1, len(lista)):
      l = gcd(l, lista.pop())
    return l

N, X = map(int, input().split())
x = list(map(int, input().split()))
d = []
gcds = set({abs(X- x[0])})
x.sort()

for i in range(N- 1):
  d.append(x[i+ 1]- x[i])
  
d.append(abs(X- x[0]))

for i in range(N- 1):
  if(d[i+ 1] != d[i]):
    gcds.add(d[i+ 1])

print(ggcd(gcds))

Submission status: Runtime Error

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

def ggcd(lista):
  if(len(lista) == 1):
    return lista.pop()
  else:
    l = lista.pop()
    for i in range(1, len(lista)):
      l = gcd(l, lista.pop())
    return l

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
d = []
gcds = set()
x.sort()

for i in range(N):
  d.append(x[i+ 1]- x[i])
  
gcds.add(d[0])

for i in range(N- 1):
  if(d[i+ 1] != d[i]):
    gcds.add(d[i+ 1])

print(ggcd(gcds))

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce

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

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

for i in x:
    y.append(abs(X-i))

#print(y)
print(gcd_list(y))

Submission status: Runtime Error

Solution code:
# C - Skip

import numpy as np
import math

N, X = map(int, input().split())
x = list(int(x) for x in input().split())
x.append(X)
x.sort()
x = np.array(x)
x = x - x[0]

ans = 10**18
if N == 1:
    print(x[1] - x[0])
else:
    for i in range(N-1):
        ans = min(ans, math.gcd(x[i], x[i+1]))
    print(ans)

Submission status: Runtime Error

Solution code:
import fractions from gcd
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
m = x[1]-x[0]

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

print(m)

Submission status: Runtime Error

Solution code:
import fractions import gcd
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
m = x[1]-x[0]

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

print(m)

Submission status: Runtime Error

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

def make_codivisors(n):
    divisors = []
    n0divisors = make_divisors(n[0])
    n0len = len(n0divisors)
    for i in n0divisors:
        for j in range(1, len(n)):
            if n[j] % i != 0:
                break
            if j == len(n)-1:
                divisors.append(i)
            
    # divisors.sort()
    return max(divisors)


n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(x)
a.sort()
b = [a[i]-a[i-1] for i in range(1, n+1)]

#print(b)
#print(a)

print(make_codivisors(b))

Submission status: Runtime Error

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

def make_codivisors(n):
    divisors = []
    n0divisors = make_divisors(n[0])
    n0len = len(n0divisors)
    for i in n0divisors:
        for j in range(1, len(n)):
            if n[j] % i != 0:
                break
            if j == len(n)-1:
                divisors.append(i)
            
    # divisors.sort()
    return max(divisors)


n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(x)
a.sort()
b = [a[i]-a[i-1] for i in range(1, n+1)]

print(b)
print(a)

print(make_codivisors(b))

Submission status: Runtime Error

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
# from math import *
import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)

# def seive():
#     prime=[1 for i in range(10**6+1)]
#     prime[0]=0
#     prime[1]=0
#     for i in range(10**6+1):
#         if(prime[i]):
#             for j in range(2*i,10**6+1,i):
#                 prime[j]=0


def gcd(x,y):
    if(x<y):
        x,y=y,x
    if(y==0):
        return x
    return gcd(y,x%y)
n,x=l()
X=l()
X.append(x)
X.sort()
A=[X[i]-X[i-1] for i in range(1,n+1)]
A=list(set(A))
A.sort()
x=A[0]
for i in range(1,len(A)):
    x=gcd(x,A[i])
print(x)

Submission status: Runtime Error

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
# from math import *
import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)

# def seive():
#     prime=[1 for i in range(10**6+1)]
#     prime[0]=0
#     prime[1]=0
#     for i in range(10**6+1):
#         if(prime[i]):
#             for j in range(2*i,10**6+1,i):
#                 prime[j]=0



n,x=l()
X=l()
X.append(x)
X.sort()
A=[X[i]-X[i-1] for i in range(1,n+1)]
A=list(set(A))
A.sort()
x=A[0]
for i in range(1,len(A)):
    x=math.gcd(x,A[i])
print(x)

Submission status: Runtime Error

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
# from math import *
import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)

def seive():
    prime=[1 for i in range(10**6+1)]
    prime[0]=0
    prime[1]=0
    for i in range(10**6+1):
        if(prime[i]):
            for j in range(2*i,10**6+1,i):
                prime[j]=0



n,x=l()
X=l()
X.append(x)
X.sort()
A=[X[i]-X[i-1] for i in range(1,n+1)]
A=list(set(A))
A.sort()
x=A[0]
for i in range(1,len(A)):
    x=math.gcd(x,A[i])
print(x)

Submission status: Runtime Error

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)

def seive():
    prime=[1 for i in range(10**6+1)]
    prime[0]=0
    prime[1]=0
    for i in range(10**6+1):
        if(prime[i]):
            for j in range(2*i,10**6+1,i):
                prime[j]=0



n,x=l()
X=l()
X.append(x)
X.sort()
A=[X[i]-X[i-1] for i in range(1,n+1)]
A=list(set(A))
A.sort()
x=A[0]
for i in range(1,len(A)):
    x=gcd(x,A[i])
print(x)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
d = np.diff(a)
if n>1:
    gcd = math.gcd(d[0],d[1])
    if n>3:
        for i in range(2,n-1):
            gcd = math.gcd(gcd,d[i])
    print(gcd)
else:
    print(d[0])

Submission status: Runtime Error

Solution code:
from functions import gcd
n,x = map(int,input().split())
ls = list(map(int,input().split()))
new = [0]*n
for i in range(n):
    new[i] = abs(ls[i]-x)
ans = new[0]
for j in range(1,n):
    ans = functions.gcd(ans,new[j])
print(ans)