Problem:


Score : 300 points

Problem Statement

There are N cities on a number line. The i-th city is located at coordinate x_i.

Your objective is to visit all these cities at least once.

In order to do so, you will first set a positive integer D.

Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like:

Move 1: travel from coordinate y to coordinate y + D.

Move 2: travel from coordinate y to coordinate y - D.

Find the maximum value of D that enables you to visit all the cities.

Here, to visit a city is to travel to the coordinate where that city is located.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq X \leq 10^9

1 \leq x_i \leq 10^9

x_i are all different.

x_1, x_2, ..., x_N \neq X

Input

Input is given from Standard Input in the following format:

N X
x_1 x_2 ... x_N

Output

Print the maximum value of D that enables you to visit all the cities.

Sample Input 1

3 3
1 7 11

Sample Output 1

2

Setting D = 2 enables you to visit all the cities as follows, and this is the maximum value of such D.

Perform Move 2 to travel to coordinate 1.

Perform Move 1 to travel to coordinate 3.

Perform Move 1 to travel to coordinate 5.

Perform Move 1 to travel to coordinate 7.

Perform Move 1 to travel to coordinate 9.

Perform Move 1 to travel to coordinate 11.

Sample Input 2

3 81
33 105 57

Sample Output 2

24

Sample Input 3

1 1
1000000000

Sample Output 3

999999999



Sample input:
3 3
1 7 11


Sample output:
2

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def main():
	N, X = map(int, input().split(" "))
	L = input().split(" ")
	L = [int(s) for s in L]
	
	if N == 1:
		print(abs(L[0]-X))
		sys.exit()
	
	L.sort()
	tmp = bisect_left(L, X)
	
	max = 2000000001
	if tmp < len(L)
		max1 = L[tmp]
	
	min1 = 2000000001
	if tmp != 0:
		min1 = L[tmp-1]
	
	ans = min(abs(max1-X), abs(X-min1))
	
	print(ans)
		
	
if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def main():
	N, X = map(int, input().split(" "))
	L = input().split(" ")
	L = [int(s) for s in L]
	
	if N == 1:
		print(abs(L[0]-X))
		sys.exit()
	
	L.sort()
	tmp = bisect_left(L, X)
	max1 = L[tmp]
	min1 = 2000000001
	if tmp != 0:
		min1 = L[tmp-1]
	
	ans = min(abs(max1-X), abs(X-min1))
	
	print(ans)
		
	
if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def main():
	N, X = map(int, input().split(" "))
	L = input().split(" ")
	L = [int(s) for s in L]
	
	if N == 1:
		print(abs(L[0]-X))
		sys.exit()
	
	L.sort()
	tmp = bisect_left(L, X)
	max1 = L[tmp]
	min = 2000000001
	if tmp != 0:
		min1 = L[tmp-1]
	
	ans = min(abs(max1-X), abs(X-min1))
	
	print(ans)
		
	
if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def main():
	N, X = map(int, input().split(" "))
	L = input().split(" ")
	L = [int(s) for s in L]
	
	if N == 1:
		print(abs(L[0]-X))
		sys.exit()
	
	L.sort()
	tmp = bisect_left(L, X)
	max1 = L[tmp]
	min1 = L[tmp-1]
	
	ans = min(abs(max1-X), abs(X-min1))
	
	print(ans)
		
	
if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def main():
	N, X = map(int, input().split(" "))
	L = input().split(" ")
	L = [int(s) for s in L]
		
	L.sort()
	tmp = bisect_left(L, X)
	max1 = L[tmp]
	min1 = L[tmp-1]
	
	ans = min(abs(max1-X), abs(X-min1))
	
	print(ans)
		
	
if __name__ == "__main__":
	main()

Submission status: Runtime Error

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

xdef = [abs(x[i]-X) for i in range(N)]
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

if N == 1:
  print(xdef[0])
else:
  tmp = gcd(xdef[0], xdef[1])
  for i in range(1,N):
    gcd = gcd(tmp,xdef[i])
  print(gcd)

Submission status: Runtime Error

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

xdef = [abs(x[i]-X) for i in range(N)]
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z
    
tmp = gcd(xdef[0], xdef[1])
for i in range(2,N):
  gcd = gcd(tmp,xdef[i])
print(gcd)

Submission status: Runtime Error

Solution code:
# def makelist(n, m):
#     return [[0 for i in range(m)] for j in range(n)]

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

# ユークリッドの互除法
def gcd(a, b):  # a >= b
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

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

print(sa[-1])

Submission status: Runtime Error

Solution code:
import math
N, X = map(int, input().split())
xs = list(map(int, input().split()))
xs.append(X)
xs.sort()
dif = []
for i in range(N):
    dif.append(xs[i+1] -xs[i])
if len(dif) > 1:
    ans = math.gcd(dif[0], dif[1])
    for i in range(N):
        ans = math.gcd(ans, dif[i])
    print(ans)
else:
    print(dif[0])

Submission status: Runtime Error

Solution code:
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = list(map(lambda x: abs(X - int(x)), x))
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

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

print(D)

Submission status: Runtime Error

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


def solve(N: int, X: int, x: "List[int]"):
    x.sort()
    gMax = None
    last = None
    begin = 0
    if abs(X - x[0]) > 0:
        last = abs(X-x[0])
        gMax = last
    else:
        begin = 1
        last = x[1]-x[0]
        gMax = last
    for i in range(begin, N-1):
        next = x[i+1] - x[i]
        gMax = math.gcd(gMax, next)
    print(gMax)
    return


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

Solution code:
N,A = map(int,input().split())
X = sorted(map(int,input().split()))
Y = []
for x in X:
    Y.append(abs(A-x))
ans = Y[0]%Y[1]
for y in Y:
    for i in range(y-1,0,-1):
        if y%i == 0:
            ans = max(ans,i)
            break
print(ans)

Submission status: Runtime Error

Solution code:
N,A = map(int,input().split())
X = sorted(map(int,input().split()))
Y = []
for x in X:
    Y.append(abs(A-x))
import math
minY = min(Y)
ans = 0
for i in range(len(Y)):
    ans = max(ans,math.gcd(minY,Y[i]))
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
x=[abs(X-c) for c in x]
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
D=gcd(*x)
print(D)

Submission status: Runtime Error

Solution code:
import math

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

for n in range(0,N):
    xls.append(int(x[n]))

xls.append(X)
xls.sort(reverse = True)

tousa = []

for n in range(0,N):
    tousa.append(xls[n]-xls[n+1])

if len(tousa) == 1:
    print(tousa[0])
    exit()
gcd = math.gcd(tousa[0],tousa[1])

for n in range(0,N):
    gcd = math.gcd(gcd,tousa[n])
    
print(gcd)

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce


def _gcd(*n):
    return reduce(gcd, n)


N, X = map(int, input().split())
x = list(map(int, input().split()))
x = sorted(x + [X])
diff = [x[i+1] - x[i] for i in range(N)]
print(_gcd(*diff))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

#values
INF = 10**9

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

d_list = [abs(X-i) for i in x_list]
print(gcd(*d_list))

Submission status: Runtime Error

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

import math
from functools import reduce

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

print(gcd_list(d))

Submission status: Runtime Error

Solution code:
#coding: utf-8
from math import gcd
from functools import reduce
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = [abs(X - x[i]) for i in range(N)]
l = reduce(gcd, x)
print(l)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    if a<b:
        temp = a
        a = b
        b = temp

    r = a%b
    
    while r>0:
        r = a%b
        a = b
        b = r
    
    return b

        

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

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

D = x2[0]
for i in range(N-1):
    D = gcd(D, x2[i+1])

print(D)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator

from fraction import gcd


inf = float('inf')


# globals
N, X = 0, 0
C = []


def set_inputs():
    global N, X, C
    N, X = get_li()
    C = get_li()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    ans = reduce(gcd, filter(lambda x: x != 0, map(lambda x: abs(x-X), C)))
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import fraction
def gcd(a,b):
    c=fraction.gcd(a,b)
    return c
    
n,x0=map(int,input().split())
x=list(map(int,input().split()))
x.append(x0)
x.sort()
w=[]
for i in range(n):
    w.append(x[i+1]-x[i])
k=w[0]
for i in w:
    ans=gcd(k,i)
print(ans)

Submission status: Runtime Error

Solution code:
import math
def gcd(a,b):
    c=math.gcd(a,b)
    return c
    
n,x0=map(int,input().split())
x=list(map(int,input().split()))
x.append(x0)
x.sort()
w=[]
for i in range(n):
    w.append(x[i+1]-x[i])
k=w[0]
for i in w:
    ans=gcd(k,i)
print(ans)

Submission status: Runtime Error

Solution code:
import math
def gcd(a,b):
    c=math.gcd(a,b)
    return c
    
n,x0=map(int,input().split())
x=list(map(int,input().split()))
x.append(x0)
x.sort()
w=[]
for i in range(n):
    w.append(x[i+1]-x[i])
k=w[0]
for i in w:
    ans=gcd(k,i)
print(gcd(k,i))

Submission status: Runtime Error

Solution code:
import math
def gcd(a,b):
    c=math.gcd(a,b)
    return c
    
n,x0=map(int,input().split())
x=list(map(int,input().split()))
x.append(x0)
x.sort()
w=[]
for i in range(n):
    w.append(x[i+1]-x[i])
k=w[0]
for i in w:
    ans=gcd(k,i)
print(gcd(k,i))
x,w

Submission status: Runtime Error

Solution code:
from functools import reduce
import fractions

N,X = map(int,input().split())
xn = list(map(int,input().split()))
xn.append(X)
xn.sort()
distance = [xn[i]-xn[i-1] for i in range(1,N)]
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
print(gcd_list(distance))

Submission status: Runtime Error

Solution code:
from functools import reduce
import fractions

N,X = map(int,input().split())
xn = list(map(int,input().split()))
xn.sort()
distance = [xn[i]-xn[i-1] for i in range(1,N)]
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
print(gcd_list(distance))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

N,X = (int(x) for x in input().split())
x = [int(p) for p in input().split()]
x.append(X)
x.sort()
D = x[1] - x[0]

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

print(D)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import functools
import math

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

diffs = [abs(X - x) for x in xs]

print(functools.reduce(math.gcd,diffs))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import functools
import math

def gcd(values):
    x=functools.reduce(math.gcd, values)
    return x

N,X=map(int,input().split())
li=list(map(int,input().split()))
if X not in li:
    li.append(X)
li=sorted(li)
distance=[]

for i in range(len(li)-1):
    distance.append(li[i+1]-li[i])
answer=gcd(distance)
print(answer)

Submission status: Runtime Error

Solution code:
from functools import reduce
from math import gcd

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

def main():
    ds = list(map(lambda n: abs(X - n), P))
    # ans = reduce(lambda a, b: gcd(a, b), ds)
    d = min(ds)
    while d > 0:
        if all(map(lambda distance: distance % d == 0, ds)) == True:
            break
        d = d - 1
    ans = d
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

n,x=map(int,input().split())
x_lst=list(map(int,input().split()))
x_lst=list(map(lambda a:abs(a-x),x_lst))
print(gcd_list(x_lst))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
N, o = list(map(int, input().split()))
X = list(map(int, input().split()))
X = sorted(X)
X = [abs(x-o) for x in X]
# 最大公約数が答え
print(reduce(math.gcd, X))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

Submission status: Runtime Error

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

Xi = list(map(int, input().split()))
Xi.sort()
Di = []
found = False
for i in range(N - 1):
    if not found and Xi[i] < X and Xi[i + 1] >= X:
        Di.append(X - Xi[i])
        Di.append(Xi[i  + 1] - X)
        found = True
    elif Xi[i] != Xi[i + 1]:
        Di.append(Xi[i + 1] - Xi[i])
if not found:
    Di.append(X - Xi[-1])
Dl = len(Di)
if Dl == 0:
    print(abs(X - Xi[0]))
else:
    gcd = Di[0]
    for i in range(1, Dl):
        gcd = math.gcd(gcd, Di[i])
    print(gcd)

Submission status: Runtime Error

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

Xi = list(map(int, input().split()))
Xi.sort()
Di = []
found = False
for i in range(N - 1):
    if not found and Xi[i] >= X and Xi[i + 1] < X:
        Di.append(X - Xi[i])
        Di.append(Xi[i  + 1] - X)
        found = True
    else:
        Di.append(Xi[i + 1] - Xi[i])

if len(Di) == 0:
    print(abs(X - Xi[0]))
else:
    gcd = Di[0]
    for i in range(1, N - 1):
        gcd = math.gcd(gcd, Di[i])
    print(gcd)

Submission status: Runtime Error

Solution code:
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 a[bi_index] == x:
    print(list_gcd)
    exit()

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

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

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

Submission status: Runtime Error

Solution code:
n, x = (int(i) for i in input().split()) 
a = sorted([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 a[bi_index] == x:
    print(list_gcd)
    exit()

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

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

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

Submission status: Runtime Error

Solution code:
n, x = (int(i) for i in input().split()) 
a = sorted([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(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 a[bi_index] == x:
    print(list_gcd)
    exit()

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

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

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

Submission status: Runtime Error

Solution code:
n, x = (int(i) for i in input().split()) 
a = sorted([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(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 a[bi_index] == x:
    print(list_gcd)
    exit()

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

if bi_index == len(a):
    print(gcd)
    exit()

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

Submission status: Runtime Error

Solution code:
# 最大公約数なきがするけど。
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)
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)

Submission status: Runtime Error

Solution code:
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:
    if all([x % min(x_ls) == 0 for x in x_ls]):
        break
    else:
        x_ls = [x % min(x_ls) for x in x_ls]
print(min(x_ls))

Submission status: Runtime Error

Solution code:
from sys import stdin
from functools import reduce
import math

input = stdin.readline

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

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


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


main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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)
#  print(X_list)
X_diff = [j-i for i, j in zip(X_list[:-1], X_list[1:])]
print(min(X_diff)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

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 = math.gcd(intermediate_gcd, diff[i+1])

print(intermediate_gcd)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;

int main(){
  ll N,start;
  cin >> N >> start;
  ll x[N];
  vector<ll> sub;
  rep(i,N) cin >> x[i];
  
  rep(i,N){
    ll temp = abs(start-x[i]);
    sub.push_back(temp);
  }
  
  ll current_gcd = sub[0];
  for(int i=1;i<N;i++){
    current_gcd = __gcd(current_gcd, sub[i]);
  }
  
  cout << current_gcd << endl;



  return 0;
}

Submission status: Runtime Error

Solution code:
n,x = map(int,input().split())
X = list(map(int,input().split()))
sort_X = sorted(X)
temp = sort_X[0]
mini = X[-1]-X[0]
D = 1
if(n==1):
    print(999999999)
elif(n==2):
    print(mini)
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)

Submission status: Runtime Error

Solution code:
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
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
if(n==1):
    print(999999999)
else:
    print(D)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if b==0:
        return a
    else:
        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)

Submission status: Runtime Error

Solution code:
import sympy

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

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

cities.append(K)

cities.sort()

dif = []

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

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

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

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

print(x)

Submission status: Runtime Error

Solution code:
import sympy

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

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

cities.append(K)

cities.sort()

dif = []

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

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

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

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

print(x)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
n,x=map(int,input().split())
if n==1:
  print(abs(x-int(input())))
  exit()
l=list(map(int,input().split()))
l.append(x)
l.sort()
l2=[]
for i in range(1,n+1):
  l2.append(l[i]-l[i-1])
a=10000000000
for i in range(len(l2)-1):
  b=math.gcd(l2[i],l2[i+1])
  if b<a:
    a=b
print(a)

Submission status: Runtime Error

Solution code:
# https://atcoder.jp/contests/abc109/tasks/abc109_c

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()
# https://atcoder.jp/contests/abc109/tasks/abc109_c

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

Submission status: Runtime Error

Solution code:
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 range(d[1:]):
    ans = gcd(ans, d)

print(ans)

Submission status: Runtime Error

Solution code:
from math 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)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
L = []
for i in range(N):
    L.append(abs(X - A[i]))
for i in range(N-1)
    L.append(A[i+1] - A[i])
print(min(L))

Submission status: Runtime Error

Solution code:
import math

int_n, int_x = map(int, input().split())
li_pos = list(map(int, input().split()))

li_pos.sort()
if len(li_pos) == 1:
    print(abs(li_pos[0] - int_x))
else:
    print(math.gcd(*[abs(li_pos[i] - li_pos[i + 1]) for i in range(len(li_pos) - 1)]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import functools
import math
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(math.gcd,diff)
print(gcd)

Submission status: Runtime Error

Solution code:
# C
from functools import reduce
from fractions import gcd
from functools import lru_cache

@lru_cache(None)
def lcm(a, b):
    return int(a*b/gcd(a, b))

n = int(input()) 
a = list(map(int, input().split()))

result = 0
mod = reduce(lcm, a)-1

for i in range(len(a)):
    result += mod % a[i] 

print(int(result))

Submission status: Runtime Error

Solution code:
import math

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

x.append(X)

xsub = []

if N >= 2:
    for i in range(N-1):
         xsub.append(x[i+1]-x[i])

    A = []

    for i in range(N-2):
         A.append(math.gcd(xsub[i+1],xsub[i]))

    print(min(A))

else:
    print(abs(x[0]-X))

Submission status: Runtime Error

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

x.append(X)

xsub = []

if N >= 2:
    for i in range(N-1):
         xsub.append(x[i+1]-x[i])

else:
    print(abs(x[0]-X))

import math

A = []

for i in range(N-2):
    A.append(math.gcd(xsub[i+1],xsub[i]))

print(min(A))

Submission status: Runtime Error

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

x.append(X)

xsub = []

if N >= 2:
    for i in range(N-1):
         xsub.append(x[i+1]-x[i])

else:
    print(abs(x[0]-X))

import sympy

A = []

for i in range(N-2):
    A.append(sympy.gcd(xsub[i+1],xsub[i]))

print(min(A))

Submission status: Runtime Error

Solution code:
from functools import reduce
import math
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(math.gcd, new_list)
print(gcd)

Submission status: Runtime Error

Solution code:
import functools
import math
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 = functools.reduce(math.gcd, new_list)
print(gcd)

Submission status: Runtime Error

Solution code:
# C
import functools
import math

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 = functools.reduce(math.gcd, new_list)
print(gcd)