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

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

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

Xi = list(map(int, input().split()))
Xi.sort()
Di = []
for i in range(N):
    Di.append(abs(X - Xi[i]))
DLen = len(Di)
g = Di[0]
for i in range(1, DLen):
    if Di[i] != 0:
        g = gcd(g, Di[i])
print(g)

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

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    
    
    
    
    
    
    
    
    if y == 0:
        return x
    else:
        return gcd(y, x%y)


x.append(X)
x.sort()





for i in range(N):
    if i == 0:
        c = x[i+1]-x[i]
    else:
        c = gcd(x[i+1]-x[i], c)
print(c)

Solution (Python):
n, x = (int(i) for i in input().split()) 
a = sorted(list(set([int(i) for i in input().split()])))

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

import functools

if len(a) == 1:
    print(abs(a[0] - x))
    exit()

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

list_gcd = functools.reduce(gcd, diff)

import bisect

bi_index = bisect.bisect_left(a, x)
if bi_index == len(a):
    print(gcd(list_gcd, x-a[-1]))
    exit()

if a[bi_index] == x:
    print(list_gcd)
    exit()

if bi_index == 0:
    print(gcd(list_gcd, a[0]-x))
    exit()

print(functools.reduce(gcd, [list_gcd, x-a[bi_index-1], a[bi_index]-x ]))

Solution (Python):
import numpy as np
from functools import reduce
N , X = map(int, input().split())
xn = np.array(list(map(int,input().split() )))

xn = xn - X



def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
print(abs(reduce(gcd, list(xn))))

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

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

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

Solution (Python):
n,x=list(map(int,input().split(" ")))
xi=list(map(int,input().split(" ")))

xi_=list(map(lambda y:abs(y-x),xi))

i=0
while i<=n-2:
    while xi_[i]!=0 and xi_[i+1]!=0:
        (xi_[i],xi_[i+1])=(max(xi_[i],xi_[i+1])%min(xi_[i],xi_[i+1]),min(xi_[i],xi_[i+1]))
    i+=1

print(xi_[n-1])

Solution (Python):

def gcd(n, m):
    
    a = max(n,m)
    b = min(n,m)
    while b:
        a, b = b, a % b
    return a

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

xs.append(X)
xs = sorted(xs)
if len(xs) == 2:
    print(abs(xs[0]-xs[1]))
else:
    diffs = [xs[i]-xs[i-1] for i in range(1,len(xs))] 
    gcd_min = gcd(diffs[0],diffs[1])
    for i in range(2,len(diffs)):
        gcd_min = gcd(gcd_min, diffs[i])

    print(gcd_min)

Solution (Python):
N, X = [int(i) for i in input().split()]
x_ls = [int(i) for i in input().split()]
x_ls = [abs(x - X) for x in x_ls]
while True:
    min_x = min(x_ls)
    x_ls = [x % min_x for x in x_ls]
    if not any(x_ls):
        break
    x_ls = [x for x in x_ls if x != 0]
print(min_x)

Solution (Python):
from sys import stdin
from functools import reduce

import fractions



input = stdin.readline

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

xn = [abs(X - int(i)) for i in input().split()]


def main():
    print(reduce(fractions.gcd, xn))
    return


main()

Solution (Python):
from sys import stdin

input = stdin.readline


def gcd(a, b):
    result = a
    k = 0
    n = b

    while True:
        k = result % n
        result = n
        n = k
        if k == 0:
            break

    return result


def gcd_n(numbers):
    l = numbers[0]

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

    return l


def lcm(a, b):
    g = gcd(a, b)

    return a * (b / g)


def lcm_n(numbers):
    l = numbers[0]

    for i in range(len(numbers)):
        l = lcm(l, numbers[i])

    return l


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

xn = [abs(X - int(i)) for i in input().split()]


def main():
    print(gcd_n(xn))
    return


main()

Solution (Python):
from fractions import*;_,X,*x=map(int,open(0).read().split());s,*x=[abs(X-t)for t in x]
for t in x:s=gcd(s,t)
print(s)

Solution (Python):
from fractions import*;from functools import*;n,x,*a=map(int,open(0).read().split());print(reduce(gcd,[abs(x-i)for i in a]))

Solution (Python):
from fractions import*;from functools import*;n,x,*a=map(int,open(0).read().split());print(reduce(gcd,[abs(x-i)for i in a]))

Solution (Python):
from fractions import*
from functools import*
n,x,*a=map(int,open(0).read().split())
b=[abs(x-i)for i in a]
print(reduce(gcd,b))

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


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

ans = diffs[0]
if N > 1:
    for i in range(1, N):
        ans = gcd(ans, diffs[i])
print(ans)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


N, X = LI()
X_list = LI()
X_list.sort()

bisect.insort_left(X_list, X)

X_diff = [j-i for i, j in zip(X_list[:-1], X_list[1:])]
result = min(X_diff)




for i in range(result+1, 0, -1):
    if all(x % i == 0 for x in X_diff):
        print(i)
        exit()

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


N, X = LI()
X_list = LI()








X_list.sort()

bisect.insort_left(X_list, X)

X_diff = [abs(j-i) for i, j in zip(X_list[:-1], X_list[1:])]
X_diff = list(set(X_diff))





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

for i in range(len(X_diff)):
    
    if i == 0:
        result = X_diff[i]
        continue
    
    result = gcd(X_diff[i], result)






print(result)

Solution (Python):
from functools import reduce
N, X = map(int, input().split())
x = list(map(int, input().split()))

y = [abs(i-X) for i in x]
def gcd(a, b): 
    while b:
        a, b = b, a % b
    return a
print(reduce(gcd,y))

Solution (Python):
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

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

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

import functools
ans = functools.reduce(gcd, x)
print(ans)

Solution (Python):
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x
N,X=map(int,input().split())
l=[int(x) for x in input().split()]
l.append(X)
l.sort()
ans=float("inf")
if N==1:
  ans=l[1]-l[0]
else:
  for i in range(N-1):
    ans=min(ans,gcd(l[i+1]-l[i],l[i+2]-l[i+1]))
print(ans)

Solution (Python):
N, X = map(int, input().split())
x = list(map(int, input().split()))
x_diff = [abs(x[i] - X) for i in range(N)]

def gcd(m, n):
  a = max(m, n)
  b = min(m, n)
  if a % b == 0:
    return b
  else:
    return gcd(b, a % b)

D = x_diff[0]
for i in range(1, N):
  D = gcd(D, x_diff[i])
print(D)

Solution (Python):
def gcd(a: int, b: int)->int:
    if a < b:
        a, b = b, a

    if b == 0:
        return a

    return gcd(b, a % b)


def skip(N: int, X: int, x: list)->int:
    sorted_x = sorted([X] + x)
    dists = [sorted_x[i+1] - sorted_x[i] for i in range(len(x))]
    before = 0
    for d in dists:
        before = gcd(before, d)
    return before


if __name__ == "__main__":
    N, X = map(int, input().split())
    x = [int(s) for s in input().split()]
    ans = skip(N, X, x)
    print(ans)

Solution (Python):
def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

def ans():
  N, X = map(int,input().split())
  x = list(map(int,input().split()))
  xx = [abs(X-n) for n in x]
  res = xx[0]
  for i in range(1,N):
    res = gcd(res, xx[i])
  print(res)
ans()

Solution (Python):
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("GREATER")
    elif (x<y): print("LESS")
    else: print("EQUAL")

def ip():
    return int(input())


def calculate(a):
    s = 0
    for i in range(len(a)):
        for k in range(i+1,len(a)):
            s+=(a[i]*a[k])
    return s


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







s = abs(a[0]-x)
for i in range(1,n):
    s = fractions.gcd(s,abs(a[i]-x))
print(s)

Solution (Python):
import fractions
from functools import reduce

n, X = map(int, input().split())
x = list(map(int, input().split()))
for i in range(len(x)):
    x[i] = abs(x[i] - X)

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

print(gcd_list(x))

Solution (Python):
N, X = map(int, input().split())
x = list(map(int, input().split()))
g = X - max(x)

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
    
for i in range(N):
    if g == 1:
        break
    g = gcd(g, abs(X-x[i]))

print(g)

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

Solution (Python):
from fractions import gcd
from functools import reduce
N,D=map(int,input().split())
X=list(map(int,input().split()))
X=sorted(X+[D])
m=min(X)
s=[X[i]-m for i in range(1,len(X))]
print(reduce(gcd,s))

Solution (Python):
from fractions import gcd 
from functools import reduce 
def gcd1(l):
    return reduce(gcd, l)
n, x=map(int, input().split())
xi=[int(i) for i in input().split()]
d=[abs(xii-x) for xii in xi]
print(gcd1(d))

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

l = list(map(int,input().split()))
dis = []
for i in range(1,len(l)):
    dis.append(abs(l[i]-l[i-1]))

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

res = abs(x-l[0])

for d in dis:
    res = gcd(res,d)
print(res)

Solution (Python):
import numpy as np
from fractions import gcd

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

diff = abs(x-X)
intermediate_gcd = diff[0]

for i in range(len(x)-1):
    intermediate_gcd = gcd(intermediate_gcd, diff[i+1])

print(intermediate_gcd)

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


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

y = list(map(lambda a: abs(a - X), x))
g = y[0]
for yy in y[1:]:
    g = gcd(g, yy)
print(g)

Solution (Python):
N,X=map(int, input().split())
x=list(map(int, input().split()))
 
def gcd(a,b):
    while b:
        a, b = b, a % b
    return a

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

print(ans)

Solution (Python):
n,x = map(int,input().split())
X = list(map(int,input().split()))
sort_X = sorted(X)
temp = sort_X[0]
mini = float("inf")
D = 1
if(n==1):
    print(abs(X[0]-x))
elif(n==2):
    mini = min(X[-1]-x,x-X[0])

    for p in range(1,mini+1):
        point = x%p
        flag = True
        for xx in X:
            if(point != xx%p):
                    flag = False
                    break
        if(flag):
            D = p
    print(D)

else:
    for xx in sort_X[1:]:
        if(mini >= xx-temp):
            mini = xx-temp
        temp = xx
    for p in range(1,mini+1):
        point = x%p
        flag = True
        for xx in X:
            if(point != xx%p):
                    flag = False
                    break
        if(flag):
            D = p

    print(D)

Solution (Python):
import fractions
import functools

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

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

X.append(X0)
X.sort()
between = []
for i in range(N):
    sa = X[i+1] - X[i]
    between.append(sa)
print(gcd_list(between))

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

def gcd_list(a):
    l = len(a)
    if l == 1:
        return a[0]
    ans = gcd(a[0], a[1])
    for i in range(2, l):
        ans = gcd(ans, a[i])
    return ans

N,X=map(int,input().split())
x=list(map(int,input().split()))
x2=[abs(t-X) for t in x]
print(gcd_list(x2))

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


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

if n==1:
    a=int(input())
    print(abs(a-x))
    exit()
else:
    str=input()
    lst=str.split(" ")
    a=int(lst[0])
    b=int(lst[1])
    maxim=gcd(abs(a-x),abs(b-x))
    for i in range(2,n):
        c=int(lst[i])
        maxim=gcd(maxim,abs(c-x))
print(maxim)

Solution (Python):
from functools import reduce

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

n, x = map(int, input().split())
s = list(map(int, input().split()))
s.append(x)
s.sort()
S = []

for i in range(n):
    S.append(abs(s[i]-s[i+1]))

MAX = reduce(gcd, S)

print(MAX)

Solution (Python):
N,K = map(int,input().split())

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

cities.append(K)

cities.sort()

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

dif = []

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

if len(dif) == 1:
	x = dif[0]

else:
    
	x = gcd(dif[0],dif[1])

	for i in range(2,N):
		x = gcd(x,dif[i])

print(x)

Solution (Python):
import collections

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

y = [abs(X-i) for i in x]
y.append(0)
y.sort()
D = min(collections.Counter(list(set([(y[i+1] - y[i]) for i in range(0, N) if (y[i+1] - y[i]) != 0]))).keys())
f = True
for i in range(D, 0, -1):
    f = True
    for j in range(0, N):
        if y[j]%D != 0:
            f = False
            break
    if f:
        break
    D = i
print(D)

Solution (Python):
import collections

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

y = [abs(X-i) for i in x]
y.append(0)
y.sort()
z = [(y[i+1] - y[i]) for i in range(0, N) if (y[i+1] - y[i]) != 0]
z = list(set(z))
a = collections.Counter(z).keys()
D = min(a)
f = True
for i in range(D, 0, -1):
    f = True
    for j in range(0, N):
        if y[j]%D != 0:
            f = False
            break
    if f:
        break
    D = i
print(D)

Solution (Python):
import collections

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

y = [abs(X-i) for i in x]
y.append(0)
y.sort()
z = [(y[i+1] - y[i]) for i in range(0, N)]
zz = []
for i in range(0, N):
    if z[i] != 0 and not(z[i] in zz):
        zz.append(z[i])
a = collections.Counter(zz).keys()
D = min(a)
f = True
for i in range(D, 0, -1):
    f = True
    for j in range(0, N):
        if y[j]%D != 0:
            f = False
            break
    if f:
        break
    D = i
print(D)

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

dx=[abs(X-i) for i in x]
l=len(dx)

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

if l==1:
    k=dx[0]
else:
    for i in range(l-1):
        if i==0:
            k=dx[0]
        k=gcd(k,dx[i+1])

print(k)

Solution (Python):
n,x=map(int,input().split())
xl=list(map(int,input().split()))
for i in range(n):
    xl[i]=abs(xl[i]-x)
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)

while len(xl)>1:
    xl[0]=gcd(xl[0],xl[1])
    del xl[1]
    
print(xl[0])

Solution (Python):
def solve(diff_list):
    max_gcd = diff_list[0]
    for key in range(1, len(diff_list)):
        max_gcd = gcd(max_gcd, diff_list[key])
    return max_gcd

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

def main():
    n, x = map(int, input().split())
    x_list = list(map(int, input().split()))

    diff_list = []
    for i in x_list:
        diff_list.append(abs(i - x))

    ans = solve(diff_list)
    print(ans)

main()

Solution (Python):
n, init = map(int,input().split())
x = list(map(lambda x: abs(int(x)-init), input().split()))
g = x[0]
def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x%y)
for i in range(1,n):
    g = gcd(g,x[i])
print(g)

Solution (Python):
N, X = map(int, input().split())
L = list(map(int, input().split()))
L.append(X)
L.sort()
cand = []
def gcd(x, y):
    while y != 0:
        (x, y) = (y, x % y)
    return x

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

for i, can in enumerate(cand):
    if i == 0:
        tmp = can
        continue
    tmp = gcd(tmp, can)
print(tmp)

Solution (Python):
from functools import reduce

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

xs = list(map(lambda k: abs(k - x), xs))

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

print(reduce(gcd, xs))

Solution (Python):
import fractions
n, x = map(int, input().split())
xi = list(map(int, input().split()))
xi.sort()

L = []
for i in range(n):
    L.append(abs(x - xi[i]))
if 0 in L:
    L.remove(0)

for i in range(len(L) - 1):
    L[i+1] = fractions.gcd(L[i], L[i+1])
print(L[len(L) - 1])

Solution (Python):


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


def main():
    N, X = map(int, input().split())

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

    ans = abs(X - xl[0])
    for i in range(1, len(xl)):
        ans = gcd(max(ans, abs(X - xl[i])), min(ans, abs(X - xl[i])))

    print(ans)


main()

Solution (Python):
n, x = map(int, input().split())
y = [x] + list(map(int, input().split()))
y.sort()

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

for i in range(n):
    y[i] = y[i+1] - y[i]
y.pop()
for i in range(n-1):
    y[i+1] = g(y[i+1], y[i])

print(y[-1])

Solution (Python):
n, x = map(int, input().split())
l = list(map(int, input().split()))

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

    return x

ans = abs(l[0] - x)

for d in l[1:]:
    ans = gcd(ans, abs(d - x))

print(ans)

Solution (Python):
n, x = map(int, input().split())
l = list(map(int, input().split()))

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

    return x

diff = []

for j in l:
    diff.append(abs(j - x))

ans = diff[0]

for d in diff[1:]:
    ans = gcd(ans, d)

print(ans)

Solution (Python):
def gcd(a, b):
    while a:
        a, b = b % a, a
    return b
 
 
def main():
    n, y = map(int, input().split())
    xs = list(map(int, input().split()))
    res = abs(y - xs[0])
    for x in xs[1:]:
        res = gcd(res, abs(y - x))
    print(res)
 
 
if __name__ == '__main__':
    main()

Solution (Python):
import fractions as f

n,x = list(map(int,input().split()))
if n == 1:
    skip = int(input())
    if x == skip:
        print(0)
    else:
        print(abs(x-skip))
else:
    skip = list(map(int,input().split()))
    skip.append(x)
    skip = sorted(skip)
    margin = list()
    for i in range(len(skip)-1):
        margin.append(skip[i+1]-skip[i])
    margin = sorted(margin)
    test = margin[0]
    for i in range(len(margin)):
        test = f.gcd(test,margin[i])
    print(test)

Solution (Python):


import math
import sys
import heapq
from operator import itemgetter
import itertools
input = sys.stdin.readline














def gcd(big, small):
	if big < small:
		tmp = big
		big = small
		small = tmp

	if small == 0:
		return big
	else:
		return gcd(small, big % small)


if __name__ == '__main__':
	N, X = map(int, input().rstrip().split())
	x_s = list(map(int, input().rstrip().split())) + [X]
	x_s = sorted(x_s)

	sec_s = []
	for i in range(1, N+1):
		sec_s.append(x_s[i] - x_s[i-1])
	
	ans = sec_s[0]
	for sec in sec_s[1:]:
		ans = gcd(ans, sec)
	print(ans)

Solution (Python):
n, x = map(int, input().split())
xlist = list(map(int, input().split()))

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

mx = abs(xlist[0] - x)
for _x in xlist[1:]:
  mx = gcd(max(abs(_x-x), mx), min(abs(_x-x), mx))
print(mx)

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

x.sort()

def gcd(x,y):
    X = max(x,y)
    Y = min(x,y)
    if Y == 0:
        return X
    else:
        return gcd(Y,X%Y)

keepgcd = 0
maxgcd = 10**9

if N >= 2:
   for i in range(N-1):
       keepgcd = gcd(abs(X-x[i+1]),abs(X-x[i]))
       if maxgcd > keepgcd:
          maxgcd = keepgcd
   print(maxgcd)
else:
    print(max(x[0],X)-min(x[0],X))

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

Solution (Python):
N,X = map(int,input().split())
L = list(map(int,input().split()))
for i in range(N):
  L[i] = abs(L[i]-X)
L.sort()
L.reverse()
def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd(b,a%b)
def listgcd(L):
  p = L[0]
  for i in range(1,N):
    p = gcd(p,L[i])
  return p
if len(L) >= 2:
  print(listgcd(L))
else:
  print(L[0])

Solution (Python):
import functools
import fractions
N,X = map(int,input().split())
city = [int(c) for c in input().split()]
diff = []
for i in range(N):
    diff.append(city[i]-X)

gcd = functools.reduce(fractions.gcd,diff)
print(abs(gcd))

Solution (Python):
values = raw_input()
n,x = int(values.split(" ")[0]), int(values.split(" ")[1])
cities = raw_input()
cities = [int(i) for i in cities.split(" ")]

cities = sorted(cities)

distances = []
for i in cities:
	distances.append(abs(i-x))
for i in range(1,len(cities)):
	distances.append(abs(cities[i]-cities[i-1]))

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

m = distances[0]
for i in range(1,len(distances)):
	m = hcd(m, distances[i])
print(m)

Solution (Python):
from fractions import gcd
from functools import reduce
N, X = map(int, input().split())
x_list = list(map(int, input().split()))
x_list.append(X)
x_list.sort()
diff_list = [x_list[i + 1] - x_list[i] for i in range(len(x_list) - 1)]
print(reduce(gcd, diff_list))

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

Solution (Python):
n,x = (int(i) for i in input().split())
listx=[int(i) for i in input().split()]

listy=[abs(listx[i]-x) for i in range(n)]
listy.reverse()


def gcd(y, x):
    if x == 0:
        return y
    else:
        return gcd(x, y % x) 
if n==1:
  ans=listy[0]
else:
  if listy[1]==0:
    ans=listy[0]
  else:
    ans=gcd(listy[0],listy[1])
    if n > 2:
      for i in range(0,n-2):
        if listy[i+2]==0:
          ans=ans
        else:
          ans=gcd(ans,listy[i+2])
  
print(ans)

Solution (Python):
N, X = map(int, input().split())
x = [int(i) for i in input().split()]
x.append(X)
x.sort()
dif_x = [x[i + 1] - x[i] for i in range(len(x) - 1)]
n = max(dif_x)  
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(reverse=True)

for i in divisors:
    frag = True
    for j in dif_x:
        if j % i == 0:
            continue
        else:
            frag = False
            break
    if frag:
        print(i)
        break

Solution (Python):
n,o = map(int, input().split())
X = list(map(int, input().split()))
X = [abs(x-o) for x in X]

def euclid(a, b):
    if a>b:
        tmp = a
        a = b
        b = tmp
    while a>0:
        c = b%a
        b = a
        a = c
    return b

def sub_gcd(X):
    Y = []
    P, Q = len(X)//2, len(X)%2
    for p in range(P):
        y = euclid(X[2*p], X[2*p+1])
        Y.append(y)
    if Q!=0:
        Y.append(X[-1])
    return Y

def gcd(X):
    Y = sub_gcd(X)
    while len(Y)>1:
        Y = sub_gcd(Y)
    return Y[0]

print(gcd(X))

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

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

dif=[]
for i in range(n):
    dif.append(abs(X[i]-x))

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

ans=dif[0]
for i in range(1,n):
    ans=gcd(ans,dif[i])

    
    
print(ans)

Solution (Python):
import fractions
from functools import reduce

n, x = [int(x) for x in input().split()]
xlist = [int(x) for x in input().split()]
xlist.append(x)
xlist.sort()
distlist = []
for i in range(len(xlist) - 1):
    distlist.append(xlist[i+1] - xlist[i])

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

print(gcd(distlist))

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

def gcd(m,n):
        while n:
                m,n = n,m%n
        return m

ans=a[0]
for j in a:
        if j%ans != 0:
                ans = gcd(j,ans)
print(ans)

Solution (Python):
import sys

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


def main():
  input = sys.stdin.readline
  N, S = map(int, input().split())
  C = list(map(int, input().split()))
  C = list(set([abs(c - S) for c in C]))
  
  ans = C[0]
  for i in range(1, len(C)):
    ans = gcd(ans, C[i])

  print(ans)


if __name__ == '__main__':
  main()

Solution (Python):
import sys

def main():
  input = sys.stdin.readline
  N, S = map(int, input().split())
  C = list(map(int, input().split()))
  C = list(set([abs(c - S) for c in C]))
  min_C = min(C)
  ans = 1
  for i in range(min_C, 1, -1):
    if min_C % i != 0:
      continue
    
    if all([c % i == 0 for c in C]):
      ans = i
      break
  print(ans)


if __name__ == '__main__':
  main()

Solution (Python):
n=list(map(int,input().split()))
Y=list(map(int,input().split()))
XX=[abs(Y[i]-n[1]) for i in range(n[0])]
X=sorted(XX)
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y) 
ans=X[0]
for i in range(n[0]-1):
    ans=gcd(ans,X[i])
print(ans)

Solution (Python):
import fractions
from functools import reduce

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

n,tmp1 = (int(i) for i in input().split())
x = list(int(i) for i in input().split())
x.append(tmp1)
x.sort()
query = []
for i in range(n):
  query.append(x[i+1]-x[i])
print(gcd_list(query))

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

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m
tmp = [abs(X-xx) for xx in x]
ans = tmp[0]
for i in range(1,N):
  ans = gcd(ans, tmp[i])
print(ans)

Solution (Python):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
N, X = input().split()
xList = [int(x) for x in input().split()]
N = int(N)
X = int(X)
xList.append(X)
xList.sort()
diffList = []
for x, xx in zip(xList, xList[1:]):
    diffList.append(xx - x)
if len(diffList) > 1:
    diffList.sort()
    gcdList = []
    for x in diffList[1:]:
        gcdList.append(gcd(diffList[0], x))
    gcdList.sort()
    print(gcdList[0])
else:
    print(diffList[0])

Solution (Python):
from functools import reduce


class Solver(object):
    def __init__(self):
        self.n, self.x = list(map(int, input().split(" ")))
        self.x_s = list(map(int, input().split(" ")))

    def solve(self):
        self.shifted = [abs(self.x - i) for i in self.x_s]
        print(Solver.gcd(self.shifted))

    @staticmethod
    def gcd(numbers):
        if len(numbers) < 1:
            raise ValueError
        if len(numbers) == 1:
            return numbers[0]
        return reduce(Solver.pair_gcd, numbers)

    @staticmethod
    def pair_gcd(a, b):
        """a = bq + r"""
        a, b = (max(a, b), min(a, b))
        if b == 0:
            return a
        else:
            r = a % b
            return Solver.pair_gcd(b, r)


if __name__ == "__main__":
    s = Solver()
    s.solve()

Solution (Python):
from functools import reduce

n, s = map(int, input().split())
xl = [int(i) - s for i in input().split()]

def gcd_(a, b):
    while b:
        a, b = b, a%b
    return a
def gcd(*numbers):
    return reduce(gcd_, numbers)

print(abs(gcd(*xl)))

Solution (Python):
from functools import reduce

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

def gcd_(a, b):
    while b:
        a, b = b, a%b
    return a
def gcd(*numbers):
    return reduce(gcd_, numbers)

print(gcd(*xl))

Solution (Python):
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    n,x = map(int, input().split())
    xs = list(map(int, input().split()))
    xs.append(x)
    xs.sort(reverse=True)
    dif = [0]*n
    front = xs[0]
    for i,num in enumerate(xs[1:]):
        dif[i] = front - num
        front = num
    min_dif = min(dif)
    div_min = [min_dif]
    for i in range(int(min_dif**0.5),1,-1):
        if min_dif%i == 0:
            div_min.append(i)
            div_min.append(min_dif//i)
    div_min.sort(reverse=True)
    for i in div_min:
        for j in dif[1:]:
            if j % i != 0:
                break
        else:
            print(i)
            exit()
    print(1)

Solution (Python):


from functools import reduce
def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

N,X = map(int, input().split())
A = list(map(int, input().split()))
A = [ abs(a-X) for a in A]

print( reduce(gcd, A) )