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: Accepted

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

Submission status: Accepted

Solution code:
import sys, fractions
input = sys.stdin.readline

N, A = map(int, input().split())
X = [int(i) for i in input().split()]
X.append(A)
X.sort()

dX = [0]*(N)

for i in range(N):
  dX[i] = X[i+1] - X[i]
Xgcd = [0]*(N)
Xgcd[0] = dX[0]
  
for i in range(N-1):
  Xgcd[i+1] = fractions.gcd(Xgcd[i], dX[i+1])
print(Xgcd[-1])

Submission status: Accepted

Solution code:
def gcd(a, b):
  if a < b:
    a, b = b, a
  if b == 0:
    return a
  c = a % b
  return gcd(b, c)
n, x = [int(i) for i in input().split()]
point = list(map(int, input().split()))
dif = []

if(len(point) == 1):
  ans = abs(point[0] - x)
else:
  gcd_now = abs(point[0] - x)
  for i in range(len(point) - 1):
    dif.append(abs(point[i+1] - point[i]))
    gcd_now = gcd(gcd_now, dif[i])
  ans = gcd_now
print(ans)

Submission status: Accepted

Solution code:
n, X = list(map(int, input().split()))
x = list(map(int, input().split()))
x.append(X)
x.sort()
s = [0 for i in range(n)]
for i in range(n):
  s[i] = x[i+1]-x[i]

def gcd(a, b):
  return gcd(b, a%b) if b else a

ans = s[0]
for i in range(n):
  ans = gcd(ans, s[i])
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
N,X=map(int,input().split())
L=list(map(int,input().split()))
L.append(X)
L.sort()
ans=0
for i in range(N):
  ans=gcd(ans,L[i+1]-L[0])
print(ans)

Submission status: Accepted

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()))
k = []
for i in range(len(a)):
    k.append(abs(a[i]-x))
g = 0
for i in range(len(k)):
    g = gcd(g,k[i])
print(g)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

x_lis = list(map(int, input().split())) + [X]

x_lis = sorted(x_lis)

x_diff = [0] * (N)

for i in range(N):
    x_diff[i] = x_lis[i + 1] - x_lis[i]

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

print(gcd_list(x_diff))

Submission status: Accepted

Solution code:
# Setup
import sys
sys.setrecursionlimit(4100000)

a, b = [int(i) for i in input().split()]
c = [b-int(i) for i in input().split()]
import fractions
if a >= 2:
  temp = fractions.gcd(c[1],c[0])
  for i in range(2,a):
      temp = fractions.gcd(temp,c[i])
  print(abs(temp))
else:
  print(abs(c[0]))

Submission status: Accepted

Solution code:
from fractions import gcd
N, X = map(int, input().split())
x = list(map(int, input().split()))
ans = 0
for i in range(N):
  ans = gcd(ans, abs(x[i]-X))
print(ans)

Submission status: Accepted

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

N,X =  map(int,input().split())
para = [i for i in map(int,input().split())] + [X]
para.sort(reverse=True)
dif = []
for i in range(N):
    dif.append(para[i] - para[i+1])
dif.sort()
for i in range(N):
    if i == 0 :
        val = dif[i]
        continue
    val = gcd(max(dif[i],val),min(dif[i],val))

print(val)

Submission status: Accepted

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

n,x = map(int,input().split())
x_list = list(map(int,input().split()))
x_new = [abs(i-x) for i in x_list]
if n == 1:
    print(x_new[0])
    exit()
ans = x_new[0]
for i in range(n-1):
    ans = gcd(ans,x_new[i+1])
print(ans)

Submission status: Accepted

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

N, X = map(int, input().split())
result = 0
for x in map(int, input().split()):
    result = gcd(result, abs(x - X))
print(result)

Submission status: Accepted

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

N, X = map(int, input().split())
x = list(map(int, input().split())) + [X]
D = [0] * N

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

if N == 1:
    print(D[0])
    exit()

ans = gcd(D[0], D[1])
for j in range(2, N):
    ans = gcd(ans, D[j])

print(ans)

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
x.append(X) #len(x)=N+1
x.sort()

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

init=x[0]
x=[i-init for i in x]
d=x[1]
for i in range(N-1):   # 0 2 4 6 10 14   N=5
    if d==0:
        d=x[i+2]
    else:
        d=gcd(d,x[i+2])
print(d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import*
from fractions import*
N,X=map(int, input().split())
print(reduce(gcd, [abs(x-X) for x in map(int,input().split())]))

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
N, X = map(int, input().split())
print(reduce(gcd, list(map(lambda x: abs(int(x)-X), input().split()))))

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

B = [abs(x - X) for x in A]
# print(B)
d = reduce(gcd, B)
print(d)

Submission status: Accepted

Solution code:
N,X = map(int,input().split())
A = [int(x) - X for x in input().split()]

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

answer = 0
for x in A:
  answer = gcd(answer, x)
print(answer)

Submission status: Accepted

Solution code:
def gcd(m, n):
    if m < n:
        return gcd(n, m)
    elif n == 0:
        return m
    return gcd(n, m % n)

def gcd_list(lst):
    if len(lst) <= 1:
        return lst[0]
    ans = gcd(lst[0], lst[1])
    for e in lst:
        ans = gcd(ans, e)
    return ans

N, X = map(int, input().split())
x = list(map(int, input().split()))
x_adjusted = list(map(lambda x : abs(x - X), x))
print(gcd_list(x_adjusted))

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
X_list = list(map(int, input().split()))
X_list.append(X)
X_list.sort()
kyori_list = []
for i, x in enumerate(X_list):
    if i == len(X_list) - 1:
        break
    kyori_list.append(X_list[i + 1] - x)

import fractions
from functools import reduce


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


print(gcd_list(*kyori_list))

Submission status: Accepted

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

from fractions import gcd

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

ans=0
for i in range(N):
    ans=gcd(ans,x[i])
print(abs(ans))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

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

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

# PROCESS
distance_cap = list(map(lambda c: abs(x-c), capitals))
answer = gcd_list(distance_cap)

# OUTPUT
print(answer)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
def gcds(*numbers):
    return reduce(gcd, numbers)

def resolve():
    (N, X) = list(map(int, input().split(" ")))
    Xs = list(map(int, input().split(" ")))
    Xs.append(X)
    Xs.sort()
    diffs = [Xs[i+1]-Xs[i] for i in range(len(Xs)-1)]
    print(gcds(*diffs))


if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

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

x.append(X)
x.sort()

D = []
for n in range(N):
    D.append(x[n+1]-x[n])
    
ans = 0
for d in D:
    ans = gcd(ans,d)
        
print(ans)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
ls = [abs(int(i)-x) for i in input().split()]

from fractions import gcd
from functools import reduce

def gdc_list(lis):
    return reduce(gcd,lis)

print(gdc_list(ls))

Submission status: Accepted

Solution code:
import math
import fractions


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

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

x_mi = []
x_pl = []

for i in x:

    if i-X < 0:
        x_mi.append(X - i)

    else:
        x_pl.append(i - X)

now_gcd = -1

for i in range(len(x_mi)):

    if now_gcd < 0:
        now_gcd = x_mi[i]

    else:
        now_gcd = fractions.gcd(now_gcd , x_mi[i])

for i in range(len(x_pl)):

    if now_gcd < 0:
        now_gcd = x_pl[i]

    else:
        now_gcd = fractions.gcd(now_gcd , x_pl[i])

print (now_gcd)

Submission status: Accepted

Solution code:
# coding: utf-8
import time
import re
import math

def main():
    n,start=map(int,input().split())
    X=list(map(int,input().split()))
    now=abs(X[0]-start)
    for xi in range(1,n):
        now=GCD(now,abs(X[xi]-start))
    print(now)
def GCD(a,b):
    if a%b==0:
        return b
    else:
        return GCD(b,a%b)
main()

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

N, X = map(int, input().split())
xs = list(map(int, input().split()))
a = [X - x if X >= x else x - X for x in xs]

print(reduce(gcd, a))

Submission status: Accepted

Solution code:
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
n,x = list(map(int,input().split()))
data = [int(s) for s in input().split()]
dis = [None] * (n-1)
#distanceの生成
for i in range(n-1):
    dis[i] = abs(data[i+1] - data[i])
if n == 1:
    print(abs(x-data[0]))
    exit()

dis.sort()
if n == 2:
    temp = min(abs(x-data[0]),abs(x-data[1]))
    print(gcd(temp,dis[0]))
    exit()
#distanceのGCD



for i in range(n-2):#n-2→n == 2 の時を考慮
    dis[i+1] = gcd(dis[i+1],dis[i])
    
print(dis[i+1])

Submission status: Accepted

Solution code:
import math
from functools import reduce
import fractions

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

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

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

print(gcd_list(x))

Submission status: Accepted

Solution code:
import fractions as fra
n,x=list(map(int,input().split()))
location=list(map(int,input().split()))
diff=[]
for i in location:
    diff.append(abs(x-i))
if len(diff)==1:
    print(diff[0])
else:
    ans=fra.gcd(diff[0],diff[1])
    for i in diff:
        ans=fra.gcd(ans,i)
    print(ans)

Submission status: Accepted

Solution code:
n, o = map(int, input().split())
x = sorted(list(map(int, input().split())) + [o])
difs = [x[i+1]-x[i] for i in range(n)]

ans = difs[0]
for i in range(n-1):
    a, b = difs[i+1], ans
    while a%b:
        a, b = b, a%b
    ans = b
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
n, a = map(int, input().split())
s = [int(i) for i in input().split()]
for i in range(n):
    s[i] = abs(a-s[i])
    
def saidaikouyakusuu(x, y):
    while x%y != 0:
        x, y = y, x%y
    return (y)

print(reduce(saidaikouyakusuu, s))

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

print(reduce(gcd, diff))

Submission status: Accepted

Solution code:
from fractions import gcd
N,X = map(int,input().split())
A = list(map(int,input().split()))+[X]
A.sort()
diff = []
for i in range(1,N+1):
    diff.append(A[i]-A[i-1])
res = diff[0]
for d in diff:
    res = gcd(res,d)
print(res)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

def gcds(nums):
  return reduce(gcd,nums)

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

dif = list(set([abs(X-i) for i in x]))

print(gcds(dif))

Submission status: Accepted

Solution code:
from fractions import gcd

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

ans = abs(x[0]-X)

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

print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
N,X=map(int,input().split())
Lx=list(map(int,input().split()))
Lxabs=[]
for i in Lx:Lxabs.append(abs(i-X))

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

def multigcd(List):
    return reduce(gcd,List)
        
print (multigcd(Lxabs))

Submission status: Accepted

Solution code:
def GCD(a,b):
  if a == 0 or b == 0: return max(a,b)
  else:
    gcd = 1
    while 1:
      if a%b == 0:
        gcd = b
        break
      else:
        r = a%b
        a = b
        b = r
    return gcd

def main():
  n,x = map(int,input().split())
  pos = list(map(int,input().split()))
  res = 1
  if n == 1:
    res = abs(pos[0] - x)
  else:
    gcd = GCD(abs(pos[0] - x), abs(pos[1] - x))
    for i in range(2,n): gcd = GCD(gcd, abs(pos[i] - x))
    res = gcd
  
  print(res)

if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

n, x0 = map(int, input().split())
x = list(map(int,input().split()))
x.append(x0)
x.sort()
xdiff = []
tmp = x[0]
for xs in x:
    if xs - tmp == 0: continue
    xdiff.append(xs-tmp)
print(gcd_list(xdiff))

Submission status: Accepted

Solution code:
from fractions import gcd
n,x=map(int,input().split())

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

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

print(ans)

Submission status: Accepted

Solution code:
import fractions

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

def dist(n):
    return abs(int(n)-x)

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

ans = a[n-1]

for i in range(n):
    ans = fractions.gcd(ans,a[i])

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
N, X = map(int, input().split())
x = list(map(int, input().split()))
l = []
for xx in x:
    l.append(abs(xx - X))
 
g = l[0]
 
for i in range(1, len(l)):
    g = gcd(g, l[i])
 
print(g)

Submission status: Accepted

Solution code:
from fractions import gcd
n,x=map(int,input().split())
lst=list(map(int,input().split()))
gaps=[]
ans=1
if x in lst:
    pass
else:
    lst.append(x)
    lst=sorted(lst)
for i in range(1,len(lst)):
    gaps.append(lst[i]-lst[i-1])
#print(gaps,lst)
tmp=gaps[0]
for i in range(1,len(gaps)):
    ans=gcd(tmp,gaps[i]) ; tmp=ans
if len(lst)==2:
    print(lst[1]-lst[0])
else:
    print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

# GCD
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x

def main():
  n,x=LI()
  l=LI()

  b=abs(l[0]-x)
  for a in l[1:]:
    b=gcd(b,abs(a-x))

  return b

print(main())

Submission status: Accepted

Solution code:
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,x=map(int,input().split())
a=[abs(i-x)for i in list(map(int,input().split()))]
x=a[-1]
for i in a[:-1]:x=gcd(x,i)
print(x)

Submission status: Accepted

Solution code:
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,x=map(int,input().split())
a=[abs(i-x)for i in list(map(int,input().split()))]
x=a[0]
for i in a[1:]:x=gcd(x,i)
print(x)

Submission status: Accepted

Solution code:
from fractions import gcd
N, X = map(int, input().split())
x = list(map(int, input().split()))
l = []
for xx in x:
    l.append(abs(xx - X))

g = l[0]

for i in range(1, len(l)):
    g = gcd(g, l[i])

print(g)

Submission status: Accepted

Solution code:
import fractions

N,X=map(int,input().split())
L=list(map(int,input().split()))
ans = abs(L[0] - X)
for i in range(N-1):
  z = abs(L[i+1] - X)
  if ans > z:
    if ans % z != 0:
      ans = fractions.gcd(ans, ans % z)
    else:
      ans = z
  else:
    if z % ans != 0:
      ans = fractions.gcd(z, z % ans)

print(ans)

Submission status: Accepted

Solution code:
#ユークリッド互除法
def gcd(a,b):
  if(a<b):
    a,b=b,a
  if(b==0):
    return a
  c= a%b
  return gcd(b,c)

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

Submission status: Accepted

Solution code:
N,X = [int(i) for i in input().split()]
L = [int(i) for i in input().split()]

if N == 1:
    print(abs(L[0]-X))
else:
    P = [0]*N
    P[0] = abs(min(L) - X)
    for i in range(1,N):
        P[i] = abs(L[i]-L[i-1])

    def gcd( x, y ):
        while y != 0:
            x, y = y, x%y
        return x

    ans = gcd(P[0],P[1])

    for i in range(2,N):
        ans = gcd(ans,P[i])

    print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

print(reduce(gcd,x))

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

print(abs(reduce(fractions.gcd, cities)))

Submission status: Accepted

Solution code:
# PROXY

import functools
import fractions
N, X = [int(i) for i in input().split()]
X_N = [int(i) for i in input().split()]
list = []
for e in X_N:
    list.append(abs(e - X))
gcd = functools.reduce(fractions.gcd, list)
print(gcd)

Submission status: Accepted

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

N, X = map(int, input().split())
if N == 1:
    x =int(input())
    print(abs(x - X))
else:
    x =list(map(int, input().split()))
    ans = gcd(abs(x[0] - X), abs(x[1] - X))
    if N == 2:
        print(ans)
    else:
        for i in range(2, N):
            ans = gcd(ans, abs(x[i] - X))
        print(ans)

Submission status: Accepted

Solution code:
import fractions

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

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

else:
    diff = []

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

    g = fractions.gcd(diff[0],diff[1])

    for i in range(1,len(diff)):
        g = fractions.gcd(g,diff[i])

    print(g)

Submission status: Accepted

Solution code:
N, X = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
x.append(X)
D = abs(X-x[0])
x.sort()


def GCD(x, y):
    a = max(x, y)
    b = min(x, y)
    r = a % b

    if r == 0:
        return b
    else:
        return GCD(b, r)

for ni in range(N):
    dif = x[ni+1] - x[ni]
    D = GCD(dif, D)

print(D)

Submission status: Accepted

Solution code:
N, X = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
x.append(X)
D = abs(X-x[0])
x.sort()


def GCD(x, y):
    a = max(x, y)
    b = min(x, y)
    r = 1
    while r != 0:
        r = a % b
        a = b
        b = r
    return a


for ni in range(N):
    dif = x[ni+1] - x[ni]
    D = GCD(dif, D)

print(D)

Submission status: Accepted

Solution code:
N, X = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
x.append(X)
D = abs(X-x[0])
x.sort()
for ni in range(N):
    dif = x[ni+1] - x[ni]
    if dif >= D:
        a = dif
        b = D
        r = 1
        while r != 0:
            r = a % b
            a = b
            b = r
        D = a
    else:
        a = D
        b = dif
        r = 1
        while r != 0:
            r = a % b
            a = b
            b = r
        D = a
print(D)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions

N,X = map(int,input().split())
x = [int(i) for i in input().split()]
x.append(X)
x.sort()
y = [0]*N
for i in range(N):
    y[i] = x[i+1]-x[i]

if len(y) == 1:
    print(y[0])
else:
    answer = fractions.gcd(y[0],y[1])
    for i in range(2,N):
        answer = fractions.gcd(answer,y[i])
    print(answer)

Submission status: Accepted

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

def gcd(x,y):
    if x > y:
        x, y = y, x
    d = 0
    while(True):
        if y % x == 0:
            return x
        else:
            d = x
            x = y % x
            y = d

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

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

n, x = map(int, input().split())
diff_arr = [abs(x-int(i)) for i in input().split()]
print(reduce(gcd, diff_arr))

Submission status: Accepted

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


n, entry = map(int, input().split())
X = list(map(int, input().split()))
X.append(entry)
X.sort()
for i in range(n, 0, -1):
    X[i] -= X[i - 1]
del X[0]
ans = X.pop()
for x in X:
    ans = gcd(ans, x)
print(ans)

Submission status: Accepted

Solution code:
import functools
import fractions

n,x = map(int, input().split())
X = list(map(lambda i:abs(int(i)-x), input().split()))
gcd = functools.reduce(fractions.gcd, X)
print(gcd)

Submission status: Accepted

Solution code:
import fractions
import itertools
n,x=map(int,input().split())
X=[int(i) for i in input().split()]
gcd_=[]
for i in X:
    gcd_.append(abs(i-x))
gcd_=list(itertools.accumulate(gcd_,fractions.gcd))

print(gcd_[-1])

Submission status: Accepted

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

def euclid(x,y):
    if x > y:
        x,y = y,x
    d = 0
    while(True):
        if y%x == 0:
            return x
        else:
            d= x
            x = y%x
            y= d

ans = abs(x[0]-X)
for i in range(1,N):
    ans = euclid(ans,abs(x[i]-X))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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


n, x = [ int(v) for v in input().split() ]
city_list = [ int(v) for v in input().split() ] + [x]
city_list.sort()

ans = 0

def_list = [ city_list[i+1] - city_list[i] for i in range(n)]


if n == 1:
	ans = def_list[0]
else:
	gcd_list = [ 0 for i in range(n-1)]
	gcd_list[0] = gcd(def_list[0],def_list[1])
	for i in range(1,n-1):
		gcd_list[i] = gcd(gcd_list[i-1], def_list[i+1])

	ans = gcd_list[-1]
print(ans)

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
l = list(map(int, input().split()))
g = X - l[0]
from fractions import gcd
for i in l[1:N]:
	if i == X: continue
	g = gcd(g, abs(X-i))

print(abs(g))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

if s[0] != 0:
    t = s[0]
    for i in range(n-1):
        if s[i+1] == 0:
            continue
        else:
            t = gcd(t,s[i+1])
else:
    t = s[-1]
    for i in range(n-1):
        if s[-i-2] == 0:
            continue
        else:
            t = gcd(t,s[-i-1])

print(t)

Submission status: Accepted

Solution code:
N, start = [int(x) for x in input().split()]
# N < 10 ** 5
# start < 10 ** 9
# x < 10 ** 9
xs = [int(x) for x in input().split()]
xs.append(start)
xs.sort()
ds = sorted(list({(x1 - x0) for x0, x1 in zip(xs, xs[1:])}), reverse=True)

def gcd(a, b):
    while True:
        r = a % b
        if r == 0:
            return b
        a, b = b, r
        
a = ds[0]
for b in ds[1:]:
    a = gcd(a, b)
print(a)

Submission status: Accepted

Solution code:
N, X = map(int,input().split())
x = list(map(int,input().split())) + [X]
ans = abs(X-x[0])

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

for i in range(N):
    ans = gcd(ans,abs(x[i]-X))
print(ans)

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

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

def solve():
    n,start =f()
    x = f()
    x.append(start)

    x = sorted(x)

    g = 0
    for i in range(1,n+1):
        g = gcd(g, x[i] - x[i-1])

    print(g)





solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
N, *X = map(int, open(0).read().split())
X.sort()
y = [X[i + 1] - X[i] for i in range(N)]

ans = y[0]
for v in y[1:]:
  ans = gcd(ans, v)
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce

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

if X not in x_list:
    x_list.append(X)
    x_list.sort()
    N += 1    

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

if N >= 3:
    space = [abs(x_list[i + 1] - x_list[i]) for i in range(N - 1)]
    print(reduce(gcd, space))
elif N == 2:
    space = x_list[1] - x_list[0]
    print(space)
elif N == 1:
    space = x_list[0]
    print(space)

Submission status: Accepted

Solution code:
import fractions

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

if N != 1:
    A = [0]*N
    for i in range(N):
        A[i] = x[i+1]-x[i]
    a = A[0]
    for j in range(N):
        a = fractions.gcd(a,A[j])
    print(a)
else:
    print(x[1]-x[0])

Submission status: Accepted

Solution code:
import sys 
import fractions
input = sys.stdin.readline

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

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

ans = xX[0]

for i in range(N):
  ans = fractions.gcd(xX[i],ans)

print(ans)

Submission status: Accepted

Solution code:
import fractions
n,x=map(int,input().split())
t=list(map(int,input().split()))
d=set()
for t_ in t:
    d.add(abs(t_-x))
if len(d)==1:
    print(d.pop())
else:
    g=fractions.gcd(d.pop(),d.pop())
    while(d):
        g=fractions.gcd(g,d.pop())
    print(g)

Submission status: Accepted

Solution code:
def euc(x, y):
	if y == 0: return x
	return euc(y, x%y)
def gcdall(lst):
	if lst == []: return 0
	v = lst[0]
	for i in range(1, len(lst)):
		v = euc(v, lst[i])
	return v

N, X = map(int, raw_input().split())
x = map(lambda val: int(val)-X, raw_input().split())
left = []
right = []
for i in range(0, len(x)):
	if x[i] < 0: left.append(-x[i])
	elif x[i] > 0: right.append(x[i])
print euc(gcdall(left), gcdall(right))

Submission status: Accepted

Solution code:
import sys
from functools import reduce 
n, m = map(int, sys.stdin.readline().split())
a  = list(map(int, sys.stdin.readline().split()))
b = [abs(i-m) for i in a]

def gcd(x,y):
    while y > 0:
        x, y = y ,x % y
    return x
  
print(reduce(gcd, b))

Submission status: Accepted

Solution code:
from sys import stdin
import fractions
from functools import reduce
A,B=[int(x) for x in stdin.readline().rstrip().split()]
data=[int(x) for x in stdin.readline().rstrip().split()]
data=[abs(i-B) for i in data]

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

print(gcd_list(data))

Submission status: Accepted

Solution code:
from sys import stdin
import fractions

N, X = [int(k) for k in stdin.readline().rstrip().split()]
x = [int(k) for k in stdin.readline().rstrip().split()]
y = [abs(k - X) for k in x]
C = y[0]
for l in range(N):
    C = fractions.gcd(C, y[l])
print(C)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import functools

def gcd(x,y):
    if y == 0:
        return x
    return gcd(y,x%y)

def solve(N: int, X: int, x: "List[int]"):
    x2 = list(map(lambda x: abs(x-X),x))
    print(functools.reduce(gcd,x2))

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    x = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, X, x)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from functools import reduce

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        a, b = b, a % b
    return a

def gcd_from_list(vals):
    return reduce(gcd, vals)

n, x = map(int, input().split())
c = [abs(x - xn) for xn in map(int, input().split())]
print(gcd_from_list(c))

Submission status: Accepted

Solution code:
# ABC109C - Skip
def gcd(a, b):
    while a:
        a, b = b % a, a
    return b
        

n, x = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
d = abs(x - lst[0])
for i in range(n):
    dif = abs(x - lst[i])
    if dif % d == 0:
        continue
    d = gcd(d, dif)
print(d)

Submission status: Accepted

Solution code:
#import math
import fractions as math

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