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:
N, X = map(int, input().split())
x = list(map(int, input().split()))
y = [i-X if i-X >= 0 else X-i for i in x]
#print(y)

def gcp(a,b):
    if b == 0:
        return a
    else:
        return gcp(b, a%b)
koyaku = y[0]
for i in range(1, N):
    koyaku = gcp(koyaku,y[i])
print(koyaku)

Submission status: Accepted

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


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


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


print(a)

Submission status: Accepted

Solution code:
from fractions import gcd
n,a=map(int,input().split())
b=list(map(int,input().split())) + [a]
b.sort()
s=b[1]-b[0]
for i in range(n):
  s=gcd(b[i+1]-b[i],s)
print(s)

Submission status: Accepted

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

yli = list(map(lambda a:abs(a-x),xli))

def GCD(a, b):

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

import functools
print(functools.reduce(GCD,yli))

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import fractions

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

if n == 1:
    print(abs(x[0]-start))
    exit()
dist = [0 for i in range(n)]
for i in range(n):
    dist[i] = abs(start-x[i])
max_div = 1000000000
for i in range(1, n):
    max_div = min(max_div, fractions.gcd(dist[i-1], dist[i]))
print(max_div)

Submission status: Accepted

Solution code:
from fractions import gcd

n, s = map(int, raw_input().split())
a = map(int, raw_input().split())

g = 0
for x in a:
	g = gcd(g, abs(s - x))

print g

Submission status: Accepted

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

#input = __import__('sys').stdin.readline
N, X = map(int, input().split())
l = list(map(int, input().split()))
res = -1

for i in range(N):
    d = abs(l[i] - X)
    
    if res == -1:
        res = d
    else:
        res = gcd(res, d)

print(res)

Submission status: Accepted

Solution code:
from functools import reduce
memo = {}
def gcd(a, b):
  x, y = a, b = (a, b) if a >= b else (b, a)
  if (a, b) in memo:
    return memo[(a, b)]
  while b > 0:
    a, b = b, a % b
  memo[(x, y)] = a
  return a

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

xs.append(X)
m = min(xs)
arr = [x - m for x in xs]
print(reduce(gcd, arr))

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
x=sorted(map(lambda x:int(x)-X if int(x)-X>0 else -(int(x)-X),input().split()))
for i in range(x[0]+1)[::-1]:
    if x[0]%i:continue
    if sum(map(lambda x:x%i,x))==0:
        print(i)
        break

Submission status: Accepted

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

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

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

print(abs(ans))

Submission status: Accepted

Solution code:
import fractions
from functools import reduce


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


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


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

x.append(X)
x.sort()

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

print(gcd_list(d))

Submission status: Accepted

Solution code:
import numpy as np
import math
from functools import reduce

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

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

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

d = np.zeros(N, dtype=int)
for n in range(N):
    d[n] = x[n] - X

ret = abs(reduce(gcd, d))

# print(d)
print(ret)

Submission status: Accepted

Solution code:
# coding:utf-8

INF = float('inf')


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


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


N, S = inpl()
X = inpl()
X = [abs(X[i] - S) for i in range(N)]

if len(X) == 1:
    ans = X[0]
else:
    X.sort()
    ans = gcd(X[0], X[1])
    for i in range(2, N):
        ans = gcd(ans, X[i])

print(ans)

Submission status: Accepted

Solution code:
def c_skip(N, X, Pos):
    from fractions import gcd
    diff = [abs(X - x) for x in Pos]
    ans = diff[0]
    for x in diff[1:]:
        ans = gcd(ans, x)
    return ans

N, X = [int(i) for i in input().split()]
Pos = [int(i) for i in input().split()]
print(c_skip(N, X, Pos))

Submission status: Accepted

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

a = list(map(int, input().split()))
a.append(x)
r = 0

def g(k, l):
    if l>k:
        k, l = l, k
    m = k%l
    while m!= 0:
        k = l
        l = m
        m = k%l
    return l
        

for i in range(n):
    b = abs(a[i+1]-a[i])
    if i == 0:
        r = b
    else:
        r = g(r, b)
    
print(r)

Submission status: Accepted

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

n,m=map(int, input().split(" "))

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

arr=[abs(i-m) for i in X]

min=arr[0]
for i in range(len(arr)):
    min=gcd(min,arr[i])

print(min)

Submission status: Accepted

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

n, x = [int(i) for i in input().split()]
xa = [int(i) for i in input().split()]
ans = abs(x - xa[0])

for i in range(n):
    num = abs(x - xa[i])
    ans = gcd(num, ans)
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

N, K = map( int, input().split())
X = list( map( int, input().split()))
now = abs( K - X[0])
for x in X:
    now = gcd(now, abs(x-K))
print(now)

Submission status: Accepted

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

n, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
dx = [abs(x[i]-x[i+1]) for i in range(n)]

for i in range(n):
    if i==0:
        tmp = dx[0]
    else:
        tmp = gcd(tmp, dx[i])
print(tmp)

Submission status: Accepted

Solution code:
from functools import reduce
def gcd(a,b):
  while b>0:
    a,b=b,a%b
  return a

n,x=map(int,input().split())
*l,=map(int,input().split())
*y,=map(lambda a:abs(a-x),l)
print(reduce(gcd,y))

Submission status: Accepted

Solution code:
from functools import reduce

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

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

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

print(gcd_list(x))

Submission status: Accepted

Solution code:
import fractions
n,x = map(int, input().split())
lis = [int(i) for i in input().split()]
lis2 = []
for nums in lis:
  lis2.append(abs(nums-x))
ans = 10000000000000
if n == 1:
  g = lis2[0]
else:
  i = 2
  g = fractions.gcd(lis2[0],lis2[1])
  while i < n:
    g = fractions.gcd(g,lis2[i])
    i += 1
print(g)

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy


from math import *


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

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, X] = [int(input_raw[0]), int(input_raw[1])]
    input_raw = read_func().strip().split()
    x_list = [X]
    for i in range(N):
        x = int(input_raw[i])
        x_list.append(x)
    x_list.sort()
    D = x_list[1] - x_list[0]
    for i in range(1, len(x_list)):
        D = gcd(D, x_list[i] - x_list[i - 1])
    print D

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from fractions import gcd

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

vs = [abs(int(y) - x) for y in input().split()]

g = 0
for v in vs:
  g = gcd(g, v)

print(g)

Submission status: Accepted

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


import fractions
import functools


def gcds(xs):
    return functools.reduce(fractions.gcd, xs)


def max_d(x, ys):
    return abs(gcds(y - x for y in ys))


def main():
    n, x = (int(z) for z in input().split())
    ys = [int(z) for z in input().split()]
    print(max_d(x, ys))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

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

ans = T[0]
for i in range(1,N):
  ans = GCD(ans, T[i])
  
print(ans)

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

Submission status: Accepted

Solution code:
from functools import reduce
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

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

dis = [0]*N
for i in range(N):
    dis[i] = x[i+1] - x[i]

print(gcdlist(dis))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from bisect import bisect_left
from fractions import gcd
def inpl(): return list(map(int, input().split()))

N, S = inpl()

X = [abs(x - S) for x in inpl()]
if N == 1:
    print(X[0])
else:
    ans = gcd(X[0], X[1])
    for x in X[1:]:
        ans = gcd(ans, x)
    print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


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


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

Submission status: Accepted

Solution code:
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)
y=sorted(x)
z=[]
for i in range(N):
    z.append(y[i+1]-y[i])
Min=z[0]
for i in range(N-1):
    if Min>gcd(z[i],z[i+1]):
        Min=gcd(z[i],z[i+1])
print(Min)

Submission status: Accepted

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

import array
from bisect import *
from collections import *
from functools import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

# python3.4では存在しない!!
# from math import gcd

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 = reduce(gcd, diffs)
print(ans)

Submission status: Accepted

Solution code:
def nl(): return list(map(int, input().split()))
def gcd(x, y):
    if x < y:
        # x >= y とする
        x, y = y, x
    while True:
        r = x % y
        if r == 0:
            break
        else:
            x, y = y, r
    return y

N, X = nl()
x = nl()
x2 = list(map(abs, (map(lambda v: v - X, x))))

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

Submission status: Accepted

Solution code:
n,x = (int(i) for i in input().split())
y = [int(i) for i in input().split()]
ans = abs(y[0]-x)
def gcd(a,b):
	if a%b==0: return b
	else: return gcd(b,a%b)
for i in range(1,n): ans = gcd(ans,abs(x-y[i]))
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

N,X = map(int, raw_input().split())
x = map(int, raw_input().split())
ans = abs(x[0]-X)
for t in x:
  ans = gcd(ans, abs(t-X))
print ans

Submission status: Accepted

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,x]=i2()
y=i2()
y.append(x)
y.sort()
def gcd(a,b):
  while b:
    if a<b:
        c=b
        b=a
        a=c
    if b:a%=b
  return a
z=y[1]-y[0]
for i in range(1,n):
 z=gcd(y[i+1]-y[i],z)
print(z)

Submission status: Accepted

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


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


rec = sorted(rec)
gc =  rec[0]
for i in range(1, n):
    gc = gcd(rec[i], gc)

print(gc)

Submission status: Accepted

Solution code:
N,X = map(int,input().split(" "))
x = list(map(int,input().split(" ")))
x = list(map(lambda y: abs(y - X),x))


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

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

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

a = x[0]
for xi in x[1:]:
    a = gcd(a, xi)
print(a)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
N, X = map(int, input().split())
x = [int(xi) for xi in input().split()]
x.append(X)
x = sorted(x)
diffs = [x[i+1] - x[i] for i in range(N)]
if len(diffs) == 1:
    print(diffs[0])
else:
    print(reduce(gcd, diffs))

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

from functools import reduce

# gcdを求める
def findGCD(a:int, b:int) -> int:
    # ユークリッドの互除法
    while 1:
        if a%b == 0:
            return b
        else:
            a = a%b
        
        if b%a == 0:
            return a
        else:
            b = b%a

n,x = li()
a = li()

a_diff = [abs(ai - x) for ai in a]
ans = reduce(findGCD, a_diff)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8


II = lambda: int(input())
MI = lambda: map(int, input().split())


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

def main():
    N, X = MI()
    xs = []
    for x in MI():
        x -= X
        if x != 0:
            xs.append(abs(x))
    a = xs[0]
    for x in xs:
        a = gcd(a, x)
    return a


if __name__ == "__main__":
    print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math
import re

sys.setrecursionlimit(1000000)

def GCD(a, b):
    num1 = max(a, b)
    num2 = min(a, b)
    rem = 1
    while rem > 0:
        rem = num1 % num2
        num1 = num2
        num2 = rem
    return num1

N, X = map(int, raw_input().split())
x_ = map(int, raw_input().split())
x = [abs(num - X) for num in x_]

ans = x[0]
for num in x:
    ans = GCD(ans, num)

print ans

Submission status: Accepted

Solution code:
from functools import reduce

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

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

print(reduce(gcd,d))

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,X = inpl()
xx = inpl()
xx.append(X)
xx.sort()

dists = set()
for i in range(N):
	dists.add(xx[i+1]-xx[i])

dists = list(dists)
dists.sort()

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

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

print(ans)

Submission status: Accepted

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

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

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

result = xs[0]

for x in xs[1:]:
    result = gcd(result, x)

print(result)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from fractions import gcd
n,x = map(int, input().split())
ary = [abs(x-int(i)) for i in input().split()]

d = ary[0]
for i in ary[1:]:
    d = gcd(i,d)

print(d)

Submission status: Accepted

Solution code:
import fractions

N,X = map(int,input().split())
src = list(map(int,input().split()))
ans = abs(X - src[0])
for a,b in zip(src,src[1:]):
    ans = fractions.gcd(ans, abs(b-a))
print(ans)

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect
from fractions import gcd

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N, X = reads()
xs = reads()
ans = abs(reduce(lambda x, y: gcd(x, y), [y-X for y in xs], 0))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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**13
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)


def main():
    n,x = LI()
    a = LI()
    t = [abs(c-x) for c in a if x != c]
    g = min(t)
    for c in t:
        g = fractions.gcd(c,g)

    return g


print(main())

Submission status: Accepted

Solution code:
def  gcd(a,b):
    return a if b==0 else gcd(b,a%b)
n,x = map(int,raw_input().split())
ret = 0
for v in map(int,raw_input().split()):
    ret = gcd(ret, abs(x-v))
print ret

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


# --------------------------------------------

dp = None


def main():
    N, X = li_input()
    C = li_input()
    D = []

    for c in C:
        D.append(abs(X - c))

    print(gcd_list(D))



main()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n,x = na()
a = na()

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

g = 0
for v in a:
    g = gcd(g, abs(v-x))
print(g)

Submission status: Runtime Error

Solution code:
n,x=map(int,input().split())
xlist= list(map(int,input().split()))
xlist.append(x)
xsort = sorted(xlist, reverse=True)
ylist = []
for i in range(n-1):
  ylist.append(xsort[i]-xsort[i+1])
from functools import reduce
from math import gcd
print(reduce(gcd,ylist))

Submission status: Runtime Error

Solution code:
def mapt(fn, *args):
    return list(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))

def main():
    N, X = Input()
    x = Input()

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



main()

Submission status: Runtime Error

Solution code:
def mapt(fn, *args):
    return list(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))

def main():
    N, X = Input()
    x = Input()

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

    x.append(X)
    x.sort()
    data = [abs(x[i] - x[i+1]) for i in range(N)]

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



main()

Submission status: Runtime Error

Solution code:
def mapt(fn, *args):
    return list(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))

def main():
    N, X = Input()
    if N == 1:
        print(abs(N-X))
        exit()
        
    x = Input()
    x.append(X)
    x.sort()
    data = [abs(x[i] - x[i+1]) for i in range(N)]

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



main()

Submission status: Runtime Error

Solution code:
import math


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

    if n == 1:
        minimum = abs(x_lst[0] - x)
    else:
        lst1 = []
        for i in range(n):
            if i != n - 1:
                lst1.append(abs(x_lst[i + 1] - x_lst[i]))

        minimum = math.gcd(lst1[0], lst1[1])
        for i in range(n - 1):
            if i != n - 2:
                minimum = min(minimum, math.gcd(lst1[i], lst1[i + 1]))

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

        lst2.sort()
        lst2.reverse()
        for i in range(n):
            if minimum % lst2[i] == 0:
                minimum = lst2[i]
                break

    print(minimum)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import functools
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)

def gcd(nums):
    return functools.reduce(euclid, nums)



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

a.sort()

sa=[]

for i in range(1,n):
    sa.append(a[i]-a[i-1])



print(gcd(sa))

Submission status: Runtime Error

Solution code:
import fractions
def gcdlist(a):
    ans = a[0]
    for i in range(1, len(a)):
        ans = fractions.gcd(ans, a[i])
    return ans

n,y=map(int,input().split())
x=list(map(int,input().split()))
l=[]
if y==1:
    print(abs(x[0]-1))
    exit()

for i in range(n-1):
    l.append(abs(x[i+1]-x[i]))
print(gcdlist(l))

Submission status: Runtime Error

Solution code:
import numpy as np
import  math
from functools import reduce

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

N,X=map(int,input().split())
x=list(sorted(map(int,input().split())))
diff=np.diff(x)
print(gcd_list(diff))

Submission status: Runtime Error

Solution code:
import math
def ggcd(a):
    if len(a)==0:
        return 0
    i=0
    return math.gcd(a[i],ggcd(a[i+1:]))
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n-1):
    b.append(abs(a[i]-a[i+1]))
c=ggcd(b)
d=abs(x-a[0])
print(math.gcd(c,d))

Submission status: Runtime Error

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

x.sort()

d=[]
for n in range(1,N):
    d.append(x[n]-x[n-1])

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

if len(d)==0:
    print(abs(x[0]-X))
else:
    D=d[0]
    for i in range(1,len(d)):
        D=gcd(D,d[i])
    print(D)

Submission status: Runtime Error

Solution code:
import sys
import math


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

if N == 1:
    print(A[0]-X)
    sys.exit()

A.append(X)
A = sorted(A)

anslis = [0]*N

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

g = anslis.pop(0)
for c in cost_li:
    g = math.gcd(g,c)

print(g)

Submission status: Runtime Error

Solution code:
import sys
import math


N, X = 3,3
A = [1,7,11]

if N == 1:
    print(A[0]-X)
    sys.exit()

A.append(X)
A = sorted(A)

anslis = [0]*N

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

g = anslis.pop(0)
for c in cost_li:
    g = math.gcd(g,c)

print(g)

Submission status: Runtime Error

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
res,ans = [],0
for i in range(n):
	res.append(abs(a[i]-x))
#print(min(res))
res.sort()
bol = False
s = 0
while(bol==False):
	tmp = res[s]
	cnt = 0
	for j in range(n-1):
		if a[j]%tmp == a[j+1]%tmp:
			cnt += 1
	if cnt == n-1:
		bol = True
		ans = tmp
	else:
		s += 1
print(ans)

Submission status: Runtime Error

Solution code:
import math

def agcd(l):
    a=math.gcd(l[0],l[1])
    for i in range(2,len(l)):
        a=math.gcd(a,l[i])
    return a

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

if len(X_lst) == 1:
    print(abs(X_lst[0] - X))
    exit()

u = 0
if X_lst[0] == X:
    u = float('inf')

for i, x in enumerate(X_lst[1:], start=1):
    if x == X:
        u = float('inf')

    if X_lst[i - 1] < X < x:
        u = [X - u, x - X]

    if i == 1:
        g = X_lst[1] - X_lst[0]
    else:
        g = math.gcd(g, x - X_lst[i - 1])


if u == 0:
    u = [X - X_lst[-1]]
elif u != float('inf'):
    g = max(math.gcd(g, u[0]), math.gcd(g, u[1]))

print(g)

Submission status: Runtime Error

Solution code:
import math
n, x = [int(w) for w in input().split()]
la = [int(w)-x for w in input().split()]
la.sort()
if la[0] < 0:
    m = la[0]
    la = [w+m for w in la]

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

g = diff[0]
for i in diff[1:]:
    g = math.gcd(g, i)

print(g)

Submission status: Runtime Error

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