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:

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

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

n,x=getints()
xs=getints()

res = abs(x-xs[0])

for i in range(n):
    d = abs(x - xs[i])
    res = gcd(res, d)

print(res)

Submission status: Accepted

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def _euclid(x, y):
    if x > y:
        large = x
        small = y
    else:
        large = y
        small = x

    if small == 0:
        return large

    return _euclid(small, large % small)


def euclid_multi(nums):
    if len(nums) == 1:
        return nums[0]

    e = -1
    for i in range(1, len(nums)):
        if e == -1:
            e = _euclid(nums[0], nums[1])
        else:
            e = _euclid(e, nums[i])
    return e


def solve(inputs):
    [N, X] = string_to_int(inputs[0])
    x = string_to_int(inputs[1])
    x.append(X)
    x.sort()
    diffs = []
    for i in range(len(x)-1):
        diffs.append(x[i+1] - x[i])

    e = euclid_multi(diffs)
    return e


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Submission status: Accepted

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

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


x.sort()


#最大公約数
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

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


print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

def main():

    N,X= map(int,input().split())
    targetList = list(map(int,input().split()))
    targetList.append(X)
    targetList.sort()
    diffList = []

    if N > 2:
        for i in range(N-1):
            diffList.append(targetList[i+1] - targetList[i])

    elif N==2:
        for i in targetList:
            diffList.append(i)
    else:
        print(abs(targetList[0]-targetList[1]))
        exit()

    print(reduce(fractions.gcd,diffList))

        
    
if __name__== "__main__":
    main()

Submission status: Accepted

Solution code:

import fractions
n,x = map(int,input().split())
lst = [int(i) for i in input().split()]
distance = [x-lst[0]]
for i in range(1,n):
    distance.append(lst[i]-lst[i-1])
d = distance[0]
for i in range(n):
    d = fractions.gcd(d,distance[i])
print(abs(d))

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
lst = list(map(int, input().split()))
x = [abs(X - i) for i in lst]
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)


if N==1:
    print(x[0])
else:
    element = gcd(x[0], x[1])
    if N==2:print(element)
    else:
        for i in range(2,N):
            element=gcd(element,x[i])
        print(element)

Submission status: Accepted

Solution code:
import sys, fractions
input = sys.stdin.readline
n,x = map(int,input().split())
a = tuple(map(int,input().split()))
b = [0] * n
c = abs(a[0] - x)
for i in range(1,n):
  c = fractions.gcd(c,abs(a[i]-x))
print(c)

Submission status: Accepted

Solution code:
from fractions import*
n,x,*l=map(int,open(0).read().split())
g=abs(l[0]-x)
for a,b in zip([x]+l,l):
	g=gcd(g,abs(b-a))
print(g)

Submission status: Accepted

Solution code:
import fractions

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

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

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

ans = fractions.gcd(x[0],x[1])

if N == 2:
    print(ans)
    exit()
    
for i in range(N-2):
    ans = fractions.gcd(ans,x[i+2])
    
print(ans)

Submission status: Accepted

Solution code:
words = lambda t : list(map(t, input().split()))
n,x = words(int)
xs = words(int)

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

ys = list(map(lambda y: abs(y-x), xs))
g = ys[0]
for y in ys:
    g = gcd(g,y)

print(g)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
N,X=map(int,input().split())
li=list(map(int,input().split()))
li2=[X]*N
a=[abs(x-y) for x,y in zip(li2,li)]
def gcd(*n):
    return reduce(fractions.gcd, n)
print(gcd(*a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

N, X = map(int, input().split())
x = list(map(int, input().split()))
X_x = [0] * N
for i in range(N):
    X_x[i] = max(X-x[i], x[i]-X)
 
ans = gcd(*X_x)
print(ans)

Submission status: Accepted

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

n = [abs(x-i) for i in a]

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

ans = n[0]
for c in n[1:]:
  ans = gcd(ans, c)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

l = abs(X - L[0])
L.sort()
if N > 1:
    D = [L[i] - L[i-1] for i in range(1, N)]
    for i in range(N-1):
        l = gcd(l, D[i])

print(l)

Submission status: Accepted

Solution code:
# -*- coding: UTF-8 -*-
# ABC109_C


def LCM(num1, num2):
    m = max(num1, num2)
    n = min(num1, num2)
    r = m % n
    while(r != 0):
        m = n
        n = r
        r = m % n
    return n


N, x = map(int, input().split())
D = 1

if (N == 1):
    tmp = int(input())
    print(abs(x - tmp))
else:
    tmp = input()
    list = []
    list = tmp.split()
    for i in range(N):
        list[i] = abs(x - int(list[i]))
    D = list[0]
    for i in range(N):
        D = LCM(D, list[i])
    print(D)

Submission status: Accepted

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

Submission status: Accepted

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

def gcd2(array):
    t = array[0]
    for i in array:
        t = gcd(t,i)
    return t

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

dif=[abs(a-b)  for a,b in zip([X]+x,x)]
print(gcd2(dif))

Submission status: Accepted

Solution code:
N,X = map(int,input().split())
x = list(map(int,input().split()))
def GCD(x,y):
    while y!=0:
        x,y = y,x%y
    return x
ans = 0
for i in range(N):
    ans = GCD(ans,abs(x[i]-X))
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    if (a * b) % 2:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    w = SR(n)
    d = []
    for i in w:
        d.append("".join(i))
    if len(set(d)) != n:
        print("No")
        return
    for i in range(n - 1):
        if w[i][-1] != w[i + 1][0]:
            print("No")
            return
    print("Yes")
    return

#C
def C():
    def gcd(a, b):
        a, b = max(a, b), min(a, b)
        while b:
            a, b = b, a % b
        return a
    n, x = LI()
    xn = LI()+[x]
    xn.sort()
    ans = xn[1] - xn[0]
    for i in range(1, n):
        ans = gcd(ans, xn[i + 1] - xn[i])
    print(ans)
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

Solution code:
def g_c_d(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return g_c_d(y, x % y)


a, b = map(int, input().split())
c = list(map(int, input().split()))
c.append(b)
d = 0
for i in range(len(c)):
    d = g_c_d(d, abs((c[i] - c[i-1])))
print(d)

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

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

x.insert(0,X)
diff = []
for i in range(len(x)-1):
	diff.append(abs(x[i+1]-x[i]))

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce


def main():
    _, y = map(int, input().split())
    x = map(int, input().split())
    x = [xx - y for xx in x]
    ans = reduce(lambda x, y: gcd(x, abs(y)), x, 0)
    print(ans)


main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ABC109C
import sys

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

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
x=hoge[1]

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

res = abs(x-hoge[0])
for i in range(1,n):
	res=gcd(res, abs(hoge[i]-hoge[i-1]))
print(res)

Submission status: Accepted

Solution code:
import sys
import fractions

sys.setrecursionlimit(10**9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return [int(x) for x in input().split()]
MOD = 10**9 + 7

N, X = LIST()

x = LIST()

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import fractions

sys.setrecursionlimit(10**9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return [int(x) for x in input().split()]
MOD = 10**9 + 7

N, X = LIST()

x = LIST()

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

def gcd_all(n):
    if len(n) == 1:
        return n[0]

    tail = n.pop(-1)
    return fractions.gcd(tail, gcd_all(n))

print(gcd_all(dx))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit((2**31)-1)
from fractions import gcd
from collections import deque
n,X = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
x.append(X)
x = sorted(x)
k = x[0]
x = deque([i-k for i in x])
x.popleft()

def gcdn():
    if len(x)==1:
        return
    p=x.pop()
    q=x.pop()
    x.append(gcd(p,q))
    gcdn()

gcdn()
print(x[0])

Submission status: Accepted

Solution code:
import fractions

def main29():
    data = input().split()
    nx = []
    for i in range(2):
        nx.append(int(data[i]))
    data2 = input().split()
    zahyo = []
    for i in range(nx[0]):
        kari = int(data2[i])
        kari = int(abs(nx[1]-kari))
        zahyo.append(kari)
    result = zahyo[0]
    if nx[0] == 1:
        print(zahyo[0])
        return
    for i in range(1,nx[0],1):
        result = fractions.gcd(result,zahyo[i])
    print(result)

if __name__ == "__main__":
    main29()

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

x = map(lambda x_i: abs(X - x_i), x)
ans = reduce(gcd, x)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n, x = map(int, input().split())
ans = 1
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 check(n, li):
    for i in li:
        if i != 0:
            if abs(i) % n != 0:
                return False
    return True
li = list(map(int, input().split()))
li.append(x)
li = list(set(li))
li.sort()
start_index = li.index(x)
li = np.array(li)
if start_index == len(li)-1:
    n = li[start_index] - li[start_index - 1]
    n_div = make_divisors(n)
    for i in n_div[::-1]:
        if check(i, li-x) and i > ans:
            ans = i
            break
        
elif start_index == 0:
    n = li[start_index+1] - li[start_index]
    n_div = make_divisors(n)
    for i in n_div[::-1]:
        if check(i, li-x) and i > ans:
            ans = i
            break
else:
    n = li[start_index] - li[start_index - 1]
    n_div = make_divisors(n)
    for i in n_div[::-1]:
        if check(i, li-x) and i > ans:
            ans = i
            break
    n = li[start_index+1] - li[start_index]
    n_div = make_divisors(n)
    
    for i in n_div[::-1]:
        if check(i, li-x) and i > ans:
            ans = i
        if ans > i:
            break

print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

n, x0 = map(int,input().split())
xn = list(map(int,input().split()))
xn = [abs(x - x0) for x in xn]
d = reduce(fractions.gcd, xn)
print(d)

Submission status: Accepted

Solution code:
def g_c_d(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return g_c_d(y, x%y)


a, b = map(int, input().split())
c = list(map(int, input().split()))
c.append(b)
c.sort()
d = 0
for i in range(1, a + 1):
    d = g_c_d(c[i] - c[i-1], d)
print(d)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

print(reduce(fractions.gcd, xldiv))

Submission status: Accepted

Solution code:
import fractions
n,x=map(int, input().split())
c=list(map(int, input().split()))
c.append(x)
c.sort()
v=[]
r=[0]
for i in range(n):
    v.append(c[i+1]-c[i])
for i in range(n):
    z=fractions.gcd(r[-1],v[i])
    r.append(z)
print(r[-1])

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

a = []
for i in b:
    if i != x:
        a.append(abs(i-x))
print(gcd(a))

Submission status: Accepted

Solution code:
#最大公約数
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

#最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)

#最大公約数（複数）
def gcds(l):
    if len(l) == 1:
        return l[0]
    elif len(l) == 2:
        return gcd(l[0], l[1])
    else:
        n = len(l) // 2
        L = l[:n]
        R = l[n:]
        return gcd(gcds(L), gcds(R))

#最小公倍数(複数)
def lcms(l):
	if len(l) == 1:
		return l[0]
	elif len(l) == 2:
		return lcm(l[0], l[1])
	else:
		n = len(l) // 2
		L = l[:n]
		R = l[n:]
		return lcm(lcms(L), lcms(R))
      
n, X = (int(i) for i in input().split())  
x = [int(i) for i in input().split()] 
x.append(X)
mm = min(x)
x.remove(mm)
#print(x)
for i in range(n):
  x[i] -= mm
#print(x)
print(gcds(x))

Submission status: Accepted

Solution code:
import fractions
N,X=map(int,input().split())
listX=list(map(int,input().split()))
listX+=[X]
listX.sort()
MIN=10**9
gcd=listX[1]-listX[0]
for i in range(N):
  a=listX[i+1]-listX[i]
  gcd=fractions.gcd(a,gcd)
print(gcd)

Submission status: Accepted

Solution code:
N,X = map(int, input().split())
List = [int(x) for x in input().split()]
 
import math
List.append(X)
List.sort()
 
distance = []
for i in range(N):
    distance.append(List[i+1]-List[i])
 
d_min = min(distance)
 
num_list = []
 
c = 1
while c <= math.sqrt(d_min):
    if d_min%c == 0:
        num_list.append(c)
    c += 1
 
num_list2 = [0]*len(num_list)
for i in range(len(num_list)):
    num_list2[len(num_list)-i-1] = int(d_min/num_list[i])
 
num_list = num_list + num_list2

num_list.append(d_min)

j = len(num_list)-1

while j >= 0:
    c2 = 0
    for k in range(len(distance)):
        if distance[k]%num_list[j] == 0:
            c2 += 1
    if c2 == len(distance):
        ans = num_list[j]
        j = 0
    j -= 1
 
print(ans)

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(map(int, input().split()))
x = [abs(X - e) for e in x]

res = x[0]
for e in x[1:]:
    res = gcd(res, e)
print(res)

Submission status: Accepted

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

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

ans = abs(A[0]-X)
for a in A:
    ans = gcd(ans, abs(a-X))


print(ans)

Submission status: Accepted

Solution code:
import fractions
N,X = map(int,input().split())
x = list(map(int,input().split()))
ag = 0
for c in x:
    if ag==0:ag=abs(c-X)
    else:ag=fractions.gcd(ag,abs(c-X))
print(ag)

Submission status: Accepted

Solution code:
import fractions

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

for i in range(n):
    l[i] -= x
    l[i] = abs(l[i])
#print(n,x,l)

if n == 1:
    res = l[0]
else:
    res = fractions.gcd(l[0],l[1])
    for i in range(2,n):
        res = fractions.gcd(res,l[i])
print(res)

Submission status: Accepted

Solution code:
import fractions

N, X = map(int, input().split())
cities = list(map(int, input().split()))
gcds = abs(cities[0]-X)
for city in cities[1:]:
  gcds = fractions.gcd(gcds, abs(city-X))
print(gcds)

Submission status: Accepted

Solution code:
from fractions import gcd

N, X = map(int, input().split()) # 横に2個
A = list(map(int, input().split()))
A.append(X)

A.sort()

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

ans = D[0]
for d in D:
    ans = gcd(ans, d)

print(ans)

Submission status: Accepted

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

N, X = map(int, input().split())
x = list(map(int, input().split()))
dist = list(map(lambda v: abs(v-X), x))
ans = dist[0]
for i in range(1, N):
	ans = euc(ans, dist[i])
print(ans)

Submission status: Accepted

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

import fractions as frc

x.append(s)
al=sorted(x)

ds=[0]*n
for i in range(n):
	ds[i]=al[i+1]-al[i]

if n>1:
	gc=[0]*(n-1)
	for i in range(n-1):
		gc[i]=frc.gcd(ds[i],ds[i+1]) 
    
if n==1:
	res=ds[0]
else:
	res=min(gc)

print(res)

Submission status: Accepted

Solution code:
import fractions
N, X = [int(x) for x in input().split()]
x_list = [abs(int(x)-X) for x in input().split()]
tmp = x_list[0]
for x in x_list[1:]:
    tmp = fractions.gcd(tmp, x)
print(tmp)

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
    if f:
        print('Yes')
    else:
        print('No')
def Y(f):
    if f:
        print('YES')
    else:
        print('NO')

n,x = map(int,input().split())
a = list(map(int,input().split()))
p = []
for i in a:
    p.append(abs(i - x))
g = p[0]
for i in p:
    g = gcd(i, g)
print(g)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N, X = list(map(int, input().split()))
P = [abs(int(c)-X) for c in input().split() if int(c)-X !=0 ]

for i in range(len(P)-1):
    a, b = P[i], P[i+1]
    if a>b: a,b = b,a
    while a>0:
        a, b = b%a, a
    P[i+1]=b

print(P[-1])

Submission status: Accepted

Solution code:
n, x =  map(int, input().split())
dat = list(map(int, input().split()))
dat.append(x)
dat.sort()
dist = []
cur = dat[0]
for i in range(1, len( dat)):
    dist.append(dat[i] - cur)
    cur = dat[i]
#print(dist)

res = 0
import fractions
for i in range(len(dist)):
    res = fractions.gcd(res, dist[i])

print(res)

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, S = list(map(int, sys.stdin.readline().split()))
X = list(map(int, sys.stdin.readline().split()))

X = np.array(X + [S])
X -= X.min()

print(reduce(gcd, 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=list(map(int,input().split()))
B=[]

if N==1:
    print(abs(A[0]-X))
    exit(0)
for i in range(N):
    B.append(abs(X-A[i]))

a=gcd(B[0],B[1])
for i in range(2,N):
    a=gcd(a,B[i])
print(a)

Submission status: Accepted

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

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

answer = numbers[0]
for i in numbers:
  answer = gcd(answer, i)
print(answer)

Submission status: Accepted

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

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

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

print(abs(gcd_list(x)))

Submission status: Accepted

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

import sys
sys.setrecursionlimit(100000000)

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

s = list(map(lambda x:abs(x-X),x))
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y,x % y)

if n > 1:
    ans = gcd(s[0],s[1])
    for i in range(2,n):
        ans = gcd(ans,s[i])
    print(ans)
else:
    print(s[0])

Submission status: Accepted

Solution code:
from functools import reduce
N, X = map(int, raw_input().split())
cities = map(int, raw_input().split())
absolutes = [abs(X-c) for c in cities]

def gcd(a, b):
    if b > a:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a%b)
print reduce(gcd, absolutes)

Submission status: Accepted

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

import sys
from fractions import gcd

input = sys.stdin.readline

def main():
    N, X = map(int, input().split())
    x = [int(e) for e in input().split()]
    x.sort()

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

    m = []
    for i in range(N-1):
        if x[i] < X and X < x[i+1]:
            m.append(x[i+1] - X)
            m.append(X - x[i])
        else:
            m.append(x[i+1]-x[i])
    
    n = m[0]
    for i in m:
        n = gcd(n, i)
    print(n)

main()

Submission status: Accepted

Solution code:
import functools, fractions
n,x=map(int, input().split())
X=list(map(int, input().split()))
X.append(x)
X=sorted(X)
XX=[X[i+1]-X[i] for i in range(n)]
print(functools.reduce(fractions.gcd, XX))

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

x = tuple(map(lambda a: a - X, x))

xl = map(lambda b: -b, filter(lambda a: a < 0, x))
xr = filter(lambda a: a >= 0, x)

g = 0
for xx in xl:
    g = gcd(g, xx)
for xx in xr:
    g = gcd(g, xx)
print(g)

Submission status: Accepted

Solution code:
def c_gcd(x, y):
    if y == 0:
        return x
    else:
        return c_gcd(y, x % y)


a, b = map(int, input().split())
c = list(map(int, input().split()))
c.append(b)
c.sort()
d = -1
for i in range(1, len(c)):
    if i == 1:
        d = c[i] - c[i-1]
    else:
        d = c_gcd(c[i] - c[i-1], d)
print(d)

Submission status: Accepted

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

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

ans = x[0] - X

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

print(abs(ans))

Submission status: Accepted

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

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

print(gcd)

Submission status: Accepted

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

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

y = lst[0]
for x in lst[1:]:
    y = gcd(max(x, y), min(x, y))
print(y)

Submission status: Accepted

Solution code:
import functools
import fractions

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

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

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
b=[a[i+1]-a[i]for i in range(n-1)]
b.insert(0,abs(a[0]-x))

def search_common_divisor(x,y):
    if x<y:
        x,y=y,x
    while y!=0:
        x,y=y,x%y
    return x

def search_list_common_divisor(*numbers):
    b=[search_common_divisor(numbers[0],numbers[1])]
    for i in numbers:
        b.append(search_common_divisor(b[-1],i))
    return b[-1]


if n!=1:
    print(search_list_common_divisor(*b))
else:
    print(b[0])

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
lx=sorted(list(map(lambda y:abs(y-x),list(map(int,input().split())))),reverse=True)

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

a=lx[0]
for i in range(1,n):
	a=gcd(a,lx[i])

print(a)

Submission status: Accepted

Solution code:
import fractions

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

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

g = dist[0]

for i in range(N-1):
    g = fractions.gcd(g, dist[i+1])

print(g)

Submission status: Accepted

Solution code:
import functools
import fractions

def resolve():
	n,x=map(int,input().split())
	x_list=list(map(int,input().split()))
	x_list.append(x)
	x_list.sort()
	a=[abs(x_list[i]-x_list[i+1]) for i in range(n)]
	print(functools.reduce(fractions.gcd,a))
resolve()

Submission status: Accepted

Solution code:
from fractions import gcd


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


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

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd


def gcd_arg(lst):
    return reduce(gcd, lst)


N, X = map(int, input().split())
lst_x = list(map(int, input().split())) + [X]
lst_x.sort()
lst_diff = [lst_x[i] - lst_x[i-1] for i in range(1, N+1)]
ans = gcd_arg(lst_diff)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

n,x = map(int,input().split())
xa = list(map(int,input().split()))
diff=[]
for i in range(n):
    diff.append(abs(xa[i]-x))
y=diff[0]    
for i in range(1,n):
    y=gcd(y,diff[i])
print(y)

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())
li = list(map(int,input().split()))
m = 0
for i in range(n):
  m = gcd(li[i]-x,m)
print(abs(m))

Submission status: Accepted

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

from functools import reduce

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

List.append(X)
List = sorted(List)

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

ans = reduce(gcd, diff)
print(ans)

Submission status: Accepted

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