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: Wrong Answer

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

x = sorted(x)
Y = []

for x_ in x:
    Y.append(abs(X-x_))

for i in range(len(x)-1):
    Y.append(x[i+1] - x[i])

D = min(Y)

while True:
    flag = True
    for y in Y:
        if y % D != 0:
            flag = False
            break
    if flag:
        print(D)
        quit()
    D = D // 2

Submission status: Wrong Answer

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

if __name__ == "__main__":
    N, X = list(map(int, input().split()))
    xs = list(map(int, input().split()))

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

    low = 0
    high = 10**9+1
    for x in xs:
        if x < X:
            low = max(x, low)
            continue
        if x > X:
            high = min(x, high)
            continue

    Ds = []
    if low != 0: Ds.append(X - low)
    if high != 10**9+1: Ds.append(high - X)
    for d in Ds:
        failed = False
        for x in xs:
            if abs(X-x)%d == 0:
                continue
            else:
                failed = True
                break
        if failed:
            continue
        else:
            print(d)
            exit()
    print(1)

Submission status: Wrong Answer

Solution code:

import sys


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

yakusuu=[]
for i in range(1,minimum):
    if minimum/i==minimum//i:
        yakusuu.append(i)
        yakusuu.append(minimum//i)
    if minimum/i<i:
        break
yakusuu=sorted(yakusuu)[::-1]
for i in yakusuu:
    flag=True
    for j in x:
        if j%i!=0:
            flag=False
    if flag:
        print(i)
        sys.exit()

Submission status: Wrong Answer

Solution code:
import fractions

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

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

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

distance=[0]*N

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

distance.sort()

D=10*9
for i in range(N-1):
  D=min(D,fractions.gcd(distance[i],distance[i+1]))
print(D)

Submission status: Wrong Answer

Solution code:
import fractions
N,X=map(int,raw_input().split())
A=map(int,raw_input().split())

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

for i,x in enumerate(A):
	t=abs(x-X)
	if i==0:  a=t
	else:
		D=fractions.gcd(a,t)

print D

Submission status: Wrong Answer

Solution code:


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


for i, v in enumerate(town):
    m = abs(v-N)
    if i == 0:
        max_v = m
    if m < max_v:
        max_v = m



while True:
    Flag = True
    for i in range(len(town) - 1):
        if not abs(town[i]-town[i+1]) % max_v == 0:
            Flag = False
            break

    if Flag:
        break
    else:
        max_v -= 1

print(max_v)

Submission status: Wrong Answer

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

N, X = [int(n) for n in input().split()]
xs = [int(n) - X for n in input().split()]

if not all([n == xs[0] for n in xs]):
    m = min(xs)
    xs = [n - m for n in xs]
    g = gcd(max(xs[0], xs[1]), min(xs[0], xs[1]))
    for n in xs[2:]:
        g = gcd(max(g, n), min(g, n))
    print(g)
else:
    print(xs[0])

Submission status: Wrong Answer

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

def main():
    n, x = map(int, input().split())
    x_list = list(map(int, input().split()))
    x_list.append(x)
    x_list.sort()
    diff = []
    for i in range(n):
        diff.append(x_list[i + 1] - x_list[i])
    print(min(diff))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N , X = (int(i) for i in input().split())
x = list(int(i) for i in input().split())
x.sort()
dif = list(0 for i in range(N-1))
for i in range(N-1):
    dif[i] = x[i+1] - x[i]
dif.sort()
if N ==1:
    print(x[0]-X)
else:
    for i in range(dif[0]-1):
        possibility = 1
        for j in range(N-1):
            if dif[j]%(dif[0]-i) != 0:
                possibility = 0
                break
        if possibility == 1:
            print((dif[0]-i))
            break

Submission status: Wrong Answer

Solution code:
import math
import itertools

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

zahyo = list(map(lambda x : int(x),input().split()))

zahyo.append(x)
zahyo.sort()

min = zahyo[1] - zahyo[0]

is_odd = False
is_even = False

for i in range(n):
    diff = zahyo[i+1] - zahyo[i]

    if diff % 2 == 0:
        is_even == True
    else:
        is_odd = True

    if diff < min:
        min = zahyo[i+1] - zahyo[i]

# print(is_odd)
# print(is_even)
if is_odd == True and is_even == True:
    print(1)
else:
    print(min)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,X=map(int,input().split())
x_list=np.array(list(map(int,input().split())))
def find_nearest(array,value):
    idx = (np.abs(array-value)).argmin()
    return array[idx]
print(abs(X-find_nearest(x_list,X)))

Submission status: Wrong Answer

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


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

x_sorted = sorted(x_list)

x_gaps = [x_sorted[i+1] - x_sorted[i] for i in range(0, n-1)]


result = x_sorted[0]
for i in range(0, n-2):
    if i == 0:
        result = gcd(x_gaps[0], x_gaps[1])
    else:
        result = gcd(result, x_gaps[i+1])

print(result)

Submission status: Wrong Answer

Solution code:
import fractions
import functools

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

ans = functools.reduce(fractions.gcd, map(lambda y: abs(y - x), xs))

Submission status: Wrong Answer

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

x.sort()

last = x[0]
max_step = 0
first_step = abs(X - last)
for i in x[1:]:
    first_step = min(first_step, abs(X - i))
    max_step = max(max_step, abs(last - i))
    last = i

print(min(first_step, max_step) if max_step != 0 else first_step)

Submission status: Wrong Answer

Solution code:
def run(n, x, xx):
    xx.append(x)
    xx = sorted(xx)
    d = [xx[i+1]-xx[i] for i in range(n)]
    d = sorted(d)
    min_d = d[0]
    if len(d) == 1:
        return min_d
    for i in range(1, len(d)):
        if d[i] % min_d == 0:
            return min_d


def main():
    n, x = map(int, input().split())
    xx = list(map(int, input().split()))
    print(run(n, x, xx))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x = sorted(x)
Y = []
for i in range(len(x)-1):
    Y.append(x[i+1] - x[i])

D = min(Y)

while True:
    flag = True
    for y in Y:
        if y % D != 0:
            flag = False
            break
    if flag:
        print(D)
        quit()
    D = D // 2

Submission status: Wrong Answer

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

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

D = 1
a = abs(P[0]-X)
for i in range(N-1):
    D = gcd(a, abs(P[i]-X))
    a = D

print(D)

Submission status: Wrong Answer

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

min_res = 1000000000
res = 0
for i in range(N):
    res = abs(X - c[i])
    min_res = min(min_res,res)

print(min_res)

Submission status: Wrong Answer

Solution code:
import math
import itertools

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

zahyo = list(map(lambda x : int(x),input().split()))

zahyo.append(x)
zahyo.sort()

min = zahyo[1] - zahyo[0]

is_odd = False
is_even = False

for i in range(n):
    diff = zahyo[i+1] - zahyo[i]

    if diff % 2 == 0:
        is_even == True
    else:
        is_odd = True

    if diff < min:
        min = zahyo[i+1] - zahyo[i]

# print(is_odd)
# print(is_even)
print(min)

Submission status: Wrong Answer

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

ans = sorted([abs(c - X) for c in cities])[0]
print(ans)

Submission status: Wrong Answer

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

def main():
    n, x = map(int, input().split())
    x_list = list(map(int, input().split()))
    if n == 1:
        print(abs(x_list[0] - x))
        exit()
    x_list.append(x)
    x_list.sort()
    diff = []
    for i in range(1, n):
        diff.append(x_list[i] - x_list[i - 1])
    print(min(diff))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
x = list(map(int,input().split()))
ans = float('inf')
for i in x:
    ans =min(ans,abs(X-i))
print(ans)

Submission status: Wrong Answer

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

mini = pow(10, 9)
for xx in x:
    if abs(X - xx) < mini:
        mini = abs(X - xx)

print(mini)

Submission status: Wrong Answer

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

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


d = x[0]

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

Submission status: Wrong Answer

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

def main():
    n, x = map(int, input().split())
    x_list = list(map(int, input().split()))
    if n == 1:
        print(abs(x_list[0] - x))
        exit()
    x_list.append(x)
    x_list.sort()
    diff = []
    for i in range(1, n):
        print('aaaa')
        diff.append(x_list[i] - x_list[i - 1])
    print(min(diff))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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)

print(min(x))

Submission status: Wrong Answer

Solution code:
n, x = list(map(int, input().split()))
cities = list(map(int, input().split()))
cities.sort()
d = 100000000000
for i in cities:
    dif = abs(i - x)
    if dif < d:
        d = dif
print(d)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
cities = list(map(int, input().split()))
cities.append(x)
cities.sort()
maxVal = 9876543210
for i in range(1,n+1):
    maxVal = min(maxVal, abs(cities[i] - cities[i-1]))
print(maxVal)

Submission status: Wrong Answer

Solution code:
n, x0 = [int(_) for _ in input().split(' ')]
x = [int(_) - x0 for _ in input().split(' ')]

def gcm(p, q):
    if p % q == 0:
        return abs(q)
    else:
        return gcm(q, p % q)

if n == 1:
    print(x[0])
else:
    answer = x[0]
    for i in range(n - 1):
        answer = gcm(answer, x[i + 1])
    print(answer)

Submission status: Wrong Answer

Solution code:
n, x = map(int,input().split())
cities = list(map(int, input().split()))
min = pow(10,9)
for i in range(n):
    if min>abs(cities[i]-x):
        min = abs(cities[i]-x)
print(min)

Submission status: Wrong Answer

Solution code:
import fractions, math
n,x=map(int, input().split())
a=list(map(int, input().split()))
mina=min(a)
a=[i-mina for i in a]+[x-mina]
f=max(a)
for i in a:
    if i!=0:
        f=fractions.gcd(f,i)
print(f)

Submission status: Wrong Answer

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


# 最小公倍数
def gcd(a, b):
        while b:
                a, b = b, a % b
        return a

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


ans = 0
for i, x in enumerate(x_list):

    diff = abs(x - X)

    # print(i, x, diff, ans)

    if i == 0:
        ans = diff
    else:
        min_ = min(ans, diff)
        max_ = max(ans, diff)

        if max_ % min_ == 0:
            ans = min_
        else:
            ans = lcm(ans, diff)

print(ans)

Submission status: Wrong Answer

Solution code:
n,x = map(int, raw_input().split())
lis = sorted(map(int, raw_input().split()))
if n == 1:
    print abs(lis[0]-x)
    exit()
import bisect
#print lis
if x in lis:
    idx = -1
    for i in xrange(n):
        if lis[i] == x:
            idx = i
            break
    if idx == 0:
        print lis[1] - lis[0]
    elif idx == n-1:
        print lis[n-1] - lis[n-2]
    else:
        print min(lis[idx]-lis[idx-1], lis[idx+1]-lis[idx])
else:
    idx = bisect.bisect_left(lis, x)
    if idx == 0:
        print lis[0] - x
    elif idx == n:
        print x - lis[-1]
    else:
        print min(lis[idx]-x, x-lis[idx-1])


#print bisect.bisect_left(lis, 38)

Submission status: Wrong Answer

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

def gcd(x,y):
    if x < y:
        z = x
        x = y
        y = z
    #x>=y
    
    x = abs(x)
    y = abs(y)
    while y!=0:
        q = x%y
        x = y
        y = q
    return(x)
    

xs[0] -= X
g = xs[0]
import math
for i in range(1,N):
    xs[i] -= X
    g = gcd(g,xs[i])
print(g)

Submission status: Wrong Answer

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

x = sorted(x)

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

D = min(Y)

while True:
    flag = True
    for y in Y:
        if y % D != 0:
            flag = False
            break
    if flag:
        print(D)
        quit()
    D = D // 2

Submission status: Wrong Answer

Solution code:
n, x = map(int,input().split())
arr = list(map(int,input().split()))
ans = []
for i in arr:
    ans.append(abs(x - i))
print(min(ans))

Submission status: Wrong Answer

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

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

x.sort()
diff = [abs(X - x[0])]
for i in range(1, N):
    diff.append(abs(x[i] - x[i-1]))
#print(diff)

if len(diff) == 1:
    print(diff[0])
    exit()

ans = 0
for i in range(N-1):
    ans = max(ans, gcd(diff[i], diff[i+1]))

print(ans)

Submission status: Wrong Answer

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

x.sort()

last = x[0]
ans1 = abs(X - last)
ans2 = abs(X - last)
for i in x[1:]:
    ans1 = min(ans1, abs(X - i))
    ans2 = max(ans2, abs(last - i))
    last = i

print(min(ans1, ans2))

Submission status: Wrong Answer

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)

x.sort()
flg = True
for i in range(N):
    for j in range(N):
        if x[j] % x[i] != 0:
            flg = False
    if flg == True:
        print(x[i])

Submission status: Wrong Answer

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

N, X = [int(n) for n in input().split()]
xs = [int(n) - X for n in input().split()]

if len(xs) > 1:
    m = min(xs)
    xs = [n - m for n in xs]
    g = gcd(max(xs[0], xs[1]), min(xs[0], xs[1]))
    for n in xs[2:]:
        g = gcd(max(g, n), min(g, n))
    print(g)
else:
    print(xs[0])

Submission status: Wrong Answer

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

for i in range(a[0]):
	b[i] = abs(b[i]-a[1])
b.sort()
k = b[0]
for i in range(a[0]):
	if b[i] % k != 0:
		k = 1
		break
print(k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

N, X = [int(n) for n in input().split()]
xs = [int(n) - X for n in input().split()]

if len(xs) > 1:
    m = min(xs)
    xs = [n - m for n in xs]
    g = gcd(max(xs[0], xs[1]), max(xs[0], xs[1]))
    for n in xs[2:]:
        g = gcd(max(g, n), min(g, n))
    print(g)
else:
    print(xs[0])

Submission status: Wrong Answer

Solution code:
import numpy as np
N, X = map(int, input().split())
P = [int(_) for _ in input().split()]
Sub = np.zeros((N, ), dtype = int)
Sub += P
Sub -= X
Sub[Sub < 0] *= -1
ans = min(Sub[Sub > 0])
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import itertools

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

zahyo = list(map(lambda x : int(x),input().split()))

zahyo.append(x)
zahyo.sort()

min = zahyo[1] - zahyo[0]

for i in range(n):
    if zahyo[i+1] - zahyo[0] < min:
        min = zahyo[i+1] - zahyo[0]
print(min)

Submission status: Wrong Answer

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

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

x.sort()
diff = [abs(X - x[0])]
for i in range(1, N):
    diff.append(abs(x[i] - x[i-1]))
#print(diff)

if len(diff) == 1:
    print(diff[0])
    exit()

ans = 1
for i in range(N-1):
    ans = max(ans, gcd(diff[i], diff[i+1]))

print(ans)

Submission status: Wrong Answer

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-1):
  s=gcd(b[i+1]-b[i],s)
print(s)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, X = map(int, input().split())
P = [int(_) for _ in input().split()]
Sub = np.zeros((N, ), dtype = int)
Sub += P
Sub -= X
Sub[Sub < 0] *= -1
Sub_sort = np.sort(Sub)
print(Sub_sort[0])

Submission status: Wrong Answer

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

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

diff = [abs(X - x[0])]
for i in range(1, N):
    diff.append(abs(x[i] - x[i-1]))
#print(diff)

if len(diff) == 1:
    print(diff[0])
    exit()

ans = 1
for i in range(N-1):
    ans = max(ans, gcd(diff[i], diff[i+1]))

print(ans)

Submission status: Wrong Answer

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

N, S = map(int,input().split())
x = list(map(int,input().split()))
x.append(S)
x = sorted(x)
t = x[1]-x[0]

for k in range(N-1):
    t = gcd(t,x[k+1]-x[k])

print(t)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
xs = list(map(int, input().split()))
xs.append(X)
xs = sorted(xs)
m = 999999999999999999
for idx,e in enumerate(xs):
  if idx==0:
    continue
  diff = abs(e - xs[idx-1])
  if diff < m:
    m = diff
print(m)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
if N > 1:
    mini = min([x[1] - x[0],  abs(X - x[0])])
elif N == 1:
    mini = abs(x[0] - X)
for i in range(1, N):
    if mini > x[i] - x[i - 1]:
        mini = x[i] - x[i - 1]
    if mini > abs(X - x[i]):
        mini = abs(X - x[i])

print(mini)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
array = [int(x) for x in input().split()]
tmp =float("inf")
for i in array:
    if abs(i-x) < tmp:
        tmp = abs(i-x)

print(tmp)

Submission status: Wrong Answer

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


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


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

    a.append(x)
    a.sort()

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

    print(g)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = [y-x for y in map(int, input().split())]


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

ret = a[0]

for i in range(1, n):
    ret = gcd(ret, a[i])
print(ret)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
from sys import setrecursionlimit
setrecursionlimit(10**6)


def gcds(lst):
    if len(lst) == 2:
        return gcd(*lst)
    return gcd(lst[0], gcds(lst[1:]))

n,x = map(int,input().split())
xl = list(map(int,input().split()))
xl = list(map(lambda y: abs(y-x), xl))

ans = -1
if len(xl) == 1:
    ans = xl[0]
else:
    ans = gcds(xl)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
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: Time Limit Exceeded

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

diff = max(max(xi) - x, x - min(xi))

for d in range(diff, 1, -1):
    xd = x%d
    sol = True

    for xval in xi:
        if ((xval % d) - xd)%d != 0:
            sol = False
            break

    if sol:
        print(d)
        break

Submission status: Time Limit Exceeded

Solution code:
N,start = [int(x) for x in input().split()]
_x = [int(y) for y in input().split()]
x = sorted(_x)
dis = [0 for z in range(N-1)]
z = [0 for z in range(N)]
ans = 1
if N == 1:
    print(abs(x[0]-start))
else:
    for i in range(N-1):
        dis[i] = x[i+1] - x[i]
    for i in range(N):
        z[i] = abs(x[i]-start)
    D = min(dis)
    ans = 1
    for d in reversed(range(2,D+1)):
        count = 0
        for j in range(N):
            if z[j] % d == 0:
                count += 1
            else:
                break
        if count == N:
            ans = d
            break
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,start = [int(x) for x in input().split()]
_x = [int(y) for y in input().split()]
x = sorted(_x)
dis = [0 for z in range(N-1)]
z = [0 for z in range(N)]
ans = 1
if N == 1:
    print(abs(x[0]-start))
else:
    for i in range(N-1):
        dis[i] = x[i+1] - x[i]
    for i in range(N):
        z[i] = abs(x[i]-start)
    D = min(dis)
    ans = 1
    for d in range(2,D+1):
        count = 0
        for j in range(N):
            if z[j] % d == 0:
                count += 1
            else:
                break
        if count == N:
            ans = d
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,start = [int(x) for x in input().split()]
_x = [int(y) for y in input().split()]
x = sorted(_x)
dis = [0 for z in range(N-1)]
count = 0
ans = 1
if N == 1:
    print(abs(x[0]-start))
else:
    for i in range(N-1):
        dis[i] = x[i+1] - x[i]
    D = min(dis)
    ans = 1
    for d in range(2,D+1):
        cite = start
        while True:
            if cite > x[N-1]:
                break
            if cite in x:
                count += 1
            cite += d
        cite = start
        while True:
            if cite < x[0]:
                break
            if cite in x:
                count += 1
            cite -= d
        if count == N:
            ans = d
        count = 0
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,start = [int(x) for x in input().split()]
_x = [int(y) for y in input().split()]
x = sorted(_x)
dis = [0 for z in range(N-1)]
count = 0
if N == 1:
    print(abs(x[0]-start))
else:
    for i in range(N-1):
        dis[i] = x[i+1] - x[i]
    D = min(dis)
    ans = 1
    for d in range(1,D+1):
        cite = start
        while True:
            if cite > x[N-1]:
                break
            if cite in x:
                count += 1
            cite += d
        cite = start
        while True:
            if cite < x[0]:
                break
            if cite in x:
                count += 1
            cite -= d
        if count == N:
            ans = d
        count = 0
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,start = [int(x) for x in input().split()]
_x = [int(y) for y in input().split()]
x = sorted(_x)
dis = [0 for z in range(N-1)]
mark = [False for z in range(N)]
if N == 1:
    print(abs(x[0]-start))
else:
    for i in range(N-1):
        dis[i] = x[i+1] - x[i]
    D = min(dis)
    ans = 1
    for d in range(1,D+1):
        cite = start
        while True:
            if cite > x[N-1]:
                break
            if cite in x:
                mark[x.index(cite)] = True
            cite += d
        cite = start
        while True:
            if cite < x[0]:
                break
            if cite in x:
                mark[x.index(cite)] = True
            cite -= d
        if all(mark):
            ans = d
        mark = [False for z in range(N)]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

# 最大公約数を求める問題
N, X = map(int, input().split())
x = [int(_) for _ in input().split()]
if N == 1:
    print(abs(x[0]-X))
    exit()

x.sort()
# N > 1と仮定
for i in range(N-1):
    if x[i] < X and x[i+1] > X:
        x = x[:i+1] + [X] + x[i+1:]
        break
    elif x[i] >= X:
        x = [X] + x
    elif x[i+1] <= X:
        x = x + [X]

if len(x) >= 3:
    base = math.gcd(x[1]-x[0], x[2]-x[1])
    for i in range(2, N):
        diff = x[i+1] - x[i]
        base = math.gcd(base, diff)
    print(base)
else:
    print(x[1] - x[0])

Submission status: Time Limit Exceeded

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

min_dist = abs(X - min(L))

ans = 1

for d in range(min_dist, 0, -1):
    b = all((x - X) % d == 0 for x in L)
    if b:
        print(d)
        break

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
n, x =map(int,input().split())
s = list(map(int,input().split()))
s.sort()
a, b = x - s[0], s[-1] - x
visit = [0] * n
while sum(visit) != n:
    visit = [0] * n
    y = gcd(a, b)
    i = 0
    while s[0] + y * i <= s[-1] :
        if s[0] + y * i in s:
            visit[s.index(s[0] + y * i)] = 1
        i += 1
    a,b = min(a, b), y
print(y)

Submission status: Time Limit Exceeded

Solution code:
import sys

N, X = map(int, input().split())
x = list(input().split())
city = [int(x[i]) for i in range(N)]
MAX = min([abs(city[i] - X) for i in range(N)])

for j in reversed(range(MAX)):
    tmp = [abs(X - city[i]) % (j+1) for i in range(N)]
    if max(tmp) == 0:
        print(j+1)
        sys.exit()

Submission status: Time Limit Exceeded

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

for i in range(min(x),0,-1):
  flag = 0
  for j in x:
    if j%i != 0:
      flag = 1
      break
  if flag == 0:
    print(i)
    break

Submission status: Time Limit Exceeded

Solution code:
n, s = map(int, input().split())
x = [abs(i-s) for i in map(int, input().split())]
for i in range(min(x), -1, -1):
    if all(j%i==0 for j in x):
        print(i)
        exit()

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b):
  if(b % a == 0):
    return a
  elif(a % b == 0):
    return b
  else:
    ans = 1
    i = 2
    while a!= 1:
      if(a % i == 0):
        while a % i == 0:
          a/= i
        while b % i == 0:
          b/= i
          ans*= i
        i+= 1
    return ans
          

def ggcd(lista):
  if(len(lista) == 1):
    return lista.pop()
  else:
    l = lista.pop()
    for i in range(1, len(lista)):
      l = gcd(l, lista.pop())
    return l

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
d = []
gcds = set()
x.sort()

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

for i in range(N- 1):
  if(d[i+ 1] != d[i]):
    gcds.add(d[i+ 1])

print(ggcd(gcds))

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b):
  if(b % a == 0):
    return a
  else:
    ans = 1
    i = 2
    while a!= 1:
      if(a % i == 0):
        while a % i == 0:
          a/= i
        while b % i == 0:
          b/= i
          ans*= i
        i+= 1
    return ans
          

def ggcd(lista):
  if(len(lista) == 1):
    return lista.pop()
  else:
    l = lista.pop()
    for i in range(1, len(lista)):
      l = gcd(l, lista.pop())
    return l

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
d = []
gcds = set()
x.sort()

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

for i in range(N- 1):
  if(d[i+ 1] != d[i]):
    gcds.add(d[i+ 1])

print(ggcd(gcds))

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b):
  if(b % a == 0):
    return a
  else:
    ans = 1
    i = 2
    while a!= 1:
      if(a % i == 0):
        while a % i == 0:
          a/= i
        while b % i == 0:
          b/= i
          ans*= i
        i+= 1
    return ans
          

def ggcd(lista):
  if(len(lista) == 1):
    return lista.pop()
  else:
    l = lista.pop()
    for i in range(1, len(lista)):
      l = gcd(l, lista.pop())
    return l

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
d = []
gcds = set()
x.sort()

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

for i in range(N- 1):
  if(d[i+ 1] != d[i]):
    gcds.add(gcd(d[i+ 1], d[i]))

print(ggcd(gcds))

Submission status: Time Limit Exceeded

Solution code:
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)
    return divisors

def main():
    N, X = map(int, input().split())
    x = list(map(int, input().split()))
    y = [abs(X-a) for a in x]
    cnt = set(make_divisors(y[0]))
    for d in y:
        cnt.intersection_update(make_divisors(d))
        if len(cnt) == 1:
            print(1)
            return
    ans = max(cnt)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b):
  if(b % a == 0):
    return a
  else:
    ans = 1
    i = 2
    while a!= 1:
      if(a % i == 0):
        while a % i == 0:
          a/= i
        while b % i == 0:
          b/= i
          ans*= i
        i+= 1
    return ans
          

def ggcd(lista):
  if(len(lista) == 1):
    return lista[0]
  else:
    l = lista[0]
    for i in range(1, len(lista)):
      l = gcd(l, lista[i])
    return l

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

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

for i in range(N- 1):
  if(d[i+ 1] != d[i]):
    gcds.append(gcd(d[i+ 1], d[i]))

print(ggcd(gcds))