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:
# coding: utf-8

input_lines=input().split()

N=int(input_lines[0])
X=int(input_lines[1])

city=input().split()

D_list=[]
temp=[]

i=0

def yakusuu(num):
    yakusuu_list=[]
    for i in range(1,num):
        if num%i==0:
            yakusuu_list.append(i)
    return yakusuu_list


while(True):
    D_list.append(abs(X-int(city[i])))

    if D_list[-1] not in temp:
        temp.append(D_list[-1])
    Flag=True
    #print(D_list)

    for j in range(N):
        #print(D_list)
        if abs(int(city[j])-X) % D_list[-1]!=0:
            D_list.pop()
            break
            #Flag=False
    i+=1
    if i>=N:
        break

for i in range(len(temp)):
    D_test=yakusuu(temp[i])

for k in range(len(D_test)):
    for j in range(N):
        if abs(int(city[j])-X) % D_test[k]==0:
            D_list.append(D_test[k])

print(max(D_list))

Submission status: Wrong Answer

Solution code:
import math

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

L.sort()
L.insert(0,0)
res = 2000000000
for i in range(N-1):
    if (L[i + 1] - L[i] < res):
        res = abs(L[i + 1] - L[i])

print(res)

Submission status: Wrong Answer

Solution code:
import math as mh
import fractions as fr
from functools import reduce

n, p = (int(_) for _ in input().split())
x = list(int(_) for _ in input().split())
x.append(p)

exgcd = reduce(fr.gcd, x)
print(exgcd)

Submission status: Wrong Answer

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


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

c.append(X)
c.sort()

D = float('inf')

for i in range(1,N+1):
    if c[i] - c[i-1] < D:
        D = c[i] - c[i-1]

print(int(D))

Submission status: Wrong Answer

Solution code:
NX =  list(map(int, input().split()))
Points =  list(map(int, input().split()))
Points.append(NX[1])
 
min = min(Points)
max = max(Points)
 
ran = max - min
interval = ran
end = False
Failed = False
 
for i in range(interval):
    Failed = False

Submission status: Wrong Answer

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

[n,m]=[int(i) for i in input().split()]
x=[int(i)-m for i in input().split()]
x.append(0)

li=[]
f=1
if n==1:
    f=0
    print(abs(x[0]-x[1]))

for i in range(len(x)-1):
    li.append(max(abs(x[i]-x[i+1]), (abs(x[i+1]-x[i]))))
temp=abs(min(x))
li.append(temp)


if f:
    for i in range(len(li)-1):
        a=li[0]
        a=gcd(a, li[i+1])
    print(a)

Submission status: Wrong Answer

Solution code:
NX =  list(map(int, input().split()))
Points =  list(map(int, input().split()))
Points.append(NX[1])
Points.sort()
min = Points[0]
for i in range(len(Points)):
    Points[i] -= min

cacheP = Points[0]
interval = Points[1] - cacheP
Points.pop(0)

for p in Points:
    tmpInterval = p - cacheP
    if (tmpInterval < interval):
        interval = tmpInterval
    cacheP = p
print(interval)

Submission status: Wrong Answer

Solution code:
import math

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

L.sort()
res = 2000000000
for i in range(N-1):
    if (L[i + 1] - L[i] < res):
        res = L[i + 1] - L[i]

print(res)

Submission status: Wrong Answer

Solution code:
num_str=input().split()
num=list(map(int, num_str))
n=num[0]
x=num[1]
num2_str=input().split()
distance=list(map(int, num2_str))

first_distance=list(map(lambda y:abs(y-x),distance))
min_distance=min(first_distance)


for i in range(min_distance,0,-1):
    Can_go_list=list(map(lambda z:z%i,first_distance))

    if 0 not in Can_go_list:
        ans = i
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
L=x+[X]
if N==1:
	print(abs(X-x[0]))
else:
	LL=[L[i+1]-L[i] for i in range(N)]
	M=min(LL)
	while any([l%M!=0 for l in LL]):
		M=M-1
	print(M)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
arr = list(map(int, input().split()))
arrsort = sorted(arr)

ans = -1
previous = -1
for ele in arrsort:
    if previous < 0:
        previous = ele
    else:
        elediff = ele - previous
        if ans < 0 or elediff < ans:
            ans = elediff

    xdiff = abs(X - ele)
    if ans < 0 or xdiff < ans:
        ans = xdiff

    previous = ele

print(ans)

Submission status: Wrong Answer

Solution code:
list1 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
list2 = list(map(int, input().split()))
list2.append(x)
list2.sort()

list3 = []
list4 = []
length = len(list2)
index =1
while index < length:
    if list2[index] ==x or list2[index-1]==x:
        list4.append(list2[index]-list2[index-1])
    else:
        list3.append(list2[index]-list2[index-1])
    index+=1
list3.append(max(list4))
list3.append(min(list4)+max(list4))

list3.sort()
mimN = list3[0]
ans =0
index2 =mimN
if len(list3) ==1:
    print(mimN)
else:
    flag2 =0
    for number in list3:
       if number%mimN !=0:
           flag2 =1
    if flag2 ==0:
        print(mimN)
    else:
        while index2>=1:
            flag=0
            for number in list3:
                if number%index2 ==0:
                    flag =1
                else:
                    flag =0
            if flag ==1:
                ans = index2
                break
            else:
                index2-=1
            
        print(ans)

Submission status: Wrong Answer

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

x.sort()

for i in range(N):
    
    if x[i] < X:
        x[i]=X-x[i]
    else :
        x[i]=x[i]-X

    if i==0:
        yakusu=x[i]
    else :
        if x[i]%yakusu!=0:
            n=2
            while True:
                if yakusu%n==0:
                    yakusu=yakusu/n
                    if x[i]%yakusu==0:
                        break
                else :
                    n=n+1
                    
yakusu=int(yakusu)                    
print(yakusu)

Submission status: Wrong Answer

Solution code:
a = input().split()
n = int(a[0])
x = int(a[1])
b = input().split()
l = [int(i) for i in b]

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

def lcm(a, b):
    return a * b // gcd (a, b)

l.append(x)
l = list(set(l))
ld = sorted(l, reverse=True)
tmp = []
for i in range(1, len(ld)):
    tmp.append(abs(ld[i] - ld[i-1]))
print(lcm((min(tmp)), (gcd(abs(max(l)-x), abs(min(l)-x)))))

Submission status: Wrong Answer

Solution code:
from sys import stdin
N, X = [int(x) for x in stdin.readline().rstrip().split()]
xs = [int(x) for x in stdin.readline().rstrip().split()]
xs.sort()

mindist = abs(X - xs[0])
for i in range(1, len(xs)):
    dist = abs(X - xs[i])
    if mindist > dist:
        mindist = dist
if len(xs) > 1:
    mindist2 = xs[1] - xs[0]
    for i in range(len(xs)-1):
        tmp = xs[i+1] - xs[i]
        if (mindist2 > tmp):
            mindist2 = tmp

    if mindist == 0:
        mindist = mindist2

    for i in range(1, len(xs)):
        if (abs(xs[i]-X)) % mindist != 0:
            if mindist % mindist2 == 0:
                mindist = mindist2
                break
            mindist = 1
            break

    if mindist != 1:
        for i in range(1, len(xs)):
            if (abs(xs[i]-X)) % mindist != 0:
                mindist = 1
                break

if len(xs) == 1 and X == xs[0]:
    mindist = 0

print(mindist)

Submission status: Wrong Answer

Solution code:
list1 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
list2 = list(map(int, input().split()))
list2.append(x)
list2.sort()

list3 = []
list4 = []
length = len(list2)
index =1
while index < length:
    if list2[index] ==x or list2[index-1]==x:
        list4.append(list2[index]-list2[index-1])
    else:
        list3.append(list2[index]-list2[index-1])
    index+=1
list3.append(min(list4))
list3.append(min(list4)+max(list4))

list3.sort()
mimN = list3[0]
ans =0
index2 =mimN
if len(list3) ==1:
    print(mimN)
else:
    flag2 =0
    for number in list3:
       if number%mimN !=0:
           flag2 =1
    if flag2 ==0:
        print(mimN)
    else:
        while index2>=1:
            flag=0
            for number in list3:
                if number%index2 ==0:
                    flag =1
                else:
                    flag =0
            if flag ==1:
                ans = index2
                break
            else:
                index2-=1
            
        print(ans)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
 
arr = [int(_) for _ in input().split(' ')]
arr.sort()
 
a = arr[-1]**5
 
 
for i in range(N-1):
    if abs(arr[i+1]-arr[i]) < a:
        a = abs(arr[i+1]-arr[i])
 
for j in range(N):
    if abs(arr[j] - X) < a:
        a = abs(arr[j] - X)
 
print(a)

Submission status: Wrong Answer

Solution code:
a = input().split()
n = int(a[0])
x = int(a[1])
b = input().split()
l = [int(i) for i in b]

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

def lcm(a, b):
    return a * b // gcd (a, b)

l.append(x)
ld = sorted(l, reverse=True)
tmp = []
for i in range(1, len(ld)):
    tmp.append(abs(ld[i] - ld[i-1]))
print(lcm((min(tmp)), (gcd(abs(max(l)-x), abs(min(l)-x)))))

Submission status: Wrong Answer

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

[n,m]=[int(i) for i in input().split()]
x=[int(i)-m for i in input().split()]
x.append(0)

li=[]
f=1
if n==1:
    f=0
    print(abs(x[0]-x[1]))

for i in range(len(x)-1):
    li.append(abs(x[i]-x[i+1]))
temp=abs(min(x))
li.append(temp)


if f:
    for i in range(len(li)-1):
        a=li[0]
        a=gcd(a, li[i+1])
    print(a)

Submission status: Wrong Answer

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


x = list(map(int,input().rstrip().split()))
x.append(X)
x = sorted(x)
mini = x[1] - x[0]



for i in range(len(x)-1):
	if mini > x[i+1] - x[i]:
		mini =  x[i+1] - x[i]


if sum(x) % mini == 0:
	print(mini)
else:
	print("1")

Submission status: Wrong Answer

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

x_list.append(x)
x_list.sort()
x_list = list(set(x_list))

min_diff = 99999999999
for i in range(len(x_list) - 1):
    diff = x_list[i + 1] - x_list[i]
    if min_diff > diff:
        min_diff = diff

# 差分の最小を約分していく
x_diff = [xx - x_list[0] for xx in x_list]

for i in range(1, min_diff):
    if min_diff % i != 0:  # 約分できない場合は次の数に進む
        continue
    xx = min_diff // i
    is_divided = [j for j in x_diff if j % xx != 0]
    if len(is_divided) == 0:
        print(xx)
        exit()

Submission status: Wrong Answer

Solution code:
import math as mh
import fractions as fr
from functools import reduce

n, p = (int(_) for _ in input().split())
x = list(int(_) for _ in input().split())

lmin = abs(p - min(x))
lmax = abs(p - max(x))

d = fr.gcd(lmin, lmax)
exgcd = reduce(fr.gcd, [d,lmin,lmax])

print(exgcd)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
 
arr = [int(_) for _ in input().split(' ')]
arr.sort()
 
a = arr[-1]**2
 
 
for i in range(N-1):
    if abs(arr[i+1]-arr[i]) < a:
        a = abs(arr[i+1]-arr[i])
 
for j in range(N):
    if abs(arr[j] - X) < a:
        a = abs(arr[j] - X)
 
print(a)

Submission status: Wrong Answer

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

D = []
for i in range(len(x)):
    D.append(abs(X - x[i-1]))
print(min(D))

Submission status: Wrong Answer

Solution code:
n,x = map(int, input().split() )
y = list(map(int,input().split()))
z = [0]*n

for i in range(n) :
   y[i] = abs(y[i]-x)

for j in range(min(y),1,-1) :
   for i in range(n) :
      z[i] = y[i]%j

   if z == [0]*n :
      print(j)
      break

Submission status: Wrong Answer

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

c.append(X)
c.sort()

D = float('inf')

for i in range(1,N+1):
    if c[i] - c[i-1] < D:
        D = abs(c[i] - c[i-1])

print(int(D))

Submission status: Wrong Answer

Solution code:
num_str=input().split()
num=list(map(int, num_str))
n=num[0]
x=num[1]
num2_str=input().split()
distance=list(map(int, num2_str))

first_distance=list(map(lambda y:abs(y-x),distance))
min_distance=min(first_distance)

flag=True

for i in range(min_distance,0,-1):
    for j in range(n):
        if first_distance[j]%i != 0:
            flag = False
            break

    if flag:
        ans = i
        print(ans)
        break

Submission status: Wrong Answer

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

x_list.append(x)
x_list.sort()

min_diff = 99999999999
for i in range(len(x_list) - 1):
    diff = x_list[i + 1] - x_list[i]
    if min_diff > diff:
        min_diff = diff

# 差分の最小を約分していく
x_diff = [xx - x_list[0] for xx in x_list]

for i in range(1, min_diff):
    if min_diff % i != 0:  # 約分できない場合は次の数に進む
        continue
    xx = min_diff // i
    is_divided = [j for j in x_diff if j % xx != 0]
    if len(is_divided) == 0:
        print(xx)
        exit()

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
diffs = []
for i in range(1,n+1):
    maxVal = min(maxVal, cities[i] - cities[i-1])
    diffs.append(cities[i] - cities[i-1])
for d in diffs:
    if d%maxVal != 0:
        print(1)
        break
else:
    print(maxVal)

Submission status: Wrong Answer

Solution code:
# import math
import fractions as math
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
diff = [x[i-1] - x[i] for i in range(1,len(x))]
gcf = diff[0]
for d in diff:
    gcf = math.gcd(gcf, d)
print(gcf)

Submission status: Wrong Answer

Solution code:
headData=[int(n) for n in input().split()]
cityNum=headData[0]
pos_x=int(headData[1])
cityList=[int(n) for n in input().split()]
allList=[]
allList.append(pos_x)
for n in cityList:
    allList.append(n)

allList=sorted(allList)
print(allList)

diffList=[]

for n in range(len(allList)-1):
    diffList.append(allList[n+1]-allList[n])

answer = min(diffList)

while True:
    isAnswer = True
    for n in diffList:
        if n % answer != 0:
            isAnswer = False
            break
    if isAnswer:
        print(answer)
        break
    else:
        answer = answer-1

Submission status: Wrong Answer

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


def main():
    from fractions import gcd
    from functools import reduce

    n, large_x = map(int, input().split())
    x = sorted(list(map(lambda x: int(x) - large_x, input().split())) + [0])
    print(reduce(gcd, x))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a = input().split()
n = int(a[0])
x = int(a[1])
b = input().split()
l = [int(i) for i in b]

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

def lcm(c, d):
    return c * d // gcd (c, d)

l.append(x)
l = list(set(l))
ld = sorted(l, reverse=True)
#print(ld)
tmp = []
for i in range(1, len(ld)):
    tmp.append(abs(ld[i] - ld[i-1]))
#print(tmp)
#print(gcd(abs(max(l)-x), abs(min(l)-x)))
print(lcm(min(tmp), gcd(abs(max(l)-x), abs(min(l)-x))))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

n, X = map(int, input().split())
if n==1:
    x = int(input())
    print(abs(x-X))
    quit()    
else:
    x = list(map(int, input().split()))

    a = np.abs(np.ones(n)*X)
    b = x - a
    c = b[1]
    for i in range(n-1):
        c = gcd(c, b[i])
    print(int(c))

Submission status: Wrong Answer

Solution code:

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

x = []
x = list(map(int,input().rstrip().split()))
x.append(X)
x = sorted(x)
mini = x[1] - x[0]


if len(x)-1 > 10:
	k = 10
else:
	k = len(x)-1
for i in range(k):
	if mini > x[i+1] - x[i]:
		mini =  x[i+1] - x[i]
print(mini)

Submission status: Wrong Answer

Solution code:
import math

def count_factor(factor, factors):
    count = 0
#    print("factor: " + str(factor))
#    print(factors)
    
 #   print(factor)
 #   print(factors[1:])
    for facts in factors[1:]:
        for f in sorted(facts):
            if f > factor:
                return False
            if f == factor:
                break
    return True

def divide_to_prime_factors(num):
    factor = 1
    factors = []

    while factor <= math.sqrt(num):
        if num % factor == 0:
            factors.append(factor)
            if factor * factor != num:
                factors.append(int(num / factor))

        factor += 1

    return factors

n_and_x = input().split(" ")
city_num = int(n_and_x[0])
start = int(n_and_x[1])

city_places = [int(n) for n in input().split(" ")]

city_distances = []
for place in city_places:
    city_distances.append(abs(place - start))

dist_factors = []
for dist in city_distances:
    dist_factors.append(divide_to_prime_factors(dist))
#print(dist_factors)

step = 1
for factor in dist_factors[0]:
    if factor > step:
        if count_factor(factor, dist_factors):
            step = factor
#        print(fact_count)
#step = int(max(city_distances) / 2)

#can_travel = False
#while can_travel == False:
#    can_travel = True
#    for city in city_places:
#        if abs(city - start) % step != 0:
#           can_travel = False
#    if can_travel == False:
#        step -= 1

print(step)

Submission status: Wrong Answer

Solution code:
import functools
import fractions

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

if n == 1:
    ans = abs(cities[0] - x)
else:
    cities.append(x)
    cities.sort()
    cities = list(set(cities))
    dist = []
    for i in range(1,len(cities)):
        dist.append(cities[i] - cities[i-1])
    ans = functools.reduce(fractions.gcd, dist)
print(ans)

Submission status: Wrong Answer

Solution code:
n,w = map(int,input().split())
x = list(map(int,input().split()))
temp,r= [],""
for i in range(n):
    temp.append(abs(w-x[i]))
while r == "AC":
    for i in range(n):
        if min(temp) % temp[i] == 1:
            temp.pop(i)
            r = "WA"
            break
        else:
            r = "AC"
print(min(temp))

Submission status: Wrong Answer

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

[n,m]=[int(i) for i in input().split()]
x=[int(i)-m for i in input().split()]
x.append(0)

li=[]
f=1
if n==1:
    f=0
    print(abs(x[0]-x[1]))

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


if f:
    for i in range(len(li)-1):
        a=li[0]
        a=gcd(a, li[i+1])
    print(a)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
A=list(map(int,input().split()))
B=[]
for i in range(N):
    B.append(A[i]-X)

a=B[0]

for j in range(1,N):
    b=B[j]
    if b<a:
        a,b=b,a
    while b!=0:
        a,b=b,a%b
print(a)

Submission status: Wrong Answer

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

m1,m2 = 10000000000,10000000000
for i in range(N):
    x[i] = abs(x[i] - X)
    if x[i] < m1:
        m2 = m1
        m1 = x[i]
print(m2-m1)

Submission status: Wrong Answer

Solution code:
import fractions
n,m=map(int,input().split())
tosi = list(map(int,input().split()))
for i in range(n):
    tosi[i]=abs(m-tosi[i])
answer=min(tosi)
print(tosi)
while max(tosi)!=0:
    for i in range(n):
        if tosi[i]%answer==0:
            tosi[i]=0
        else:
            answer=fractions.gcd(answer,tosi[i])
print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A, B= map(int, input().split())
l = input().split()
l = list(map(int, l))
m = []
for i in l:
    if i<B:
        D = B - i
    else:
        D = i - B
    if i==B and len(m) == 1:
        m.append(i)
        break
    if D != 0:
        m.append(D)

print(min(m))

Submission status: Wrong Answer

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

x_list = sorted(x_list)
x_diffs = [val - x_list[i - 1] for i, val in enumerate(x_list) if i > 0]
min_diff = min(x_diffs)
D_canditates = [i for i in range(1, min_diff + 1)]

# Search max D
D_list = []
for D_cand in D_canditates:
    for x_diff in x_diffs:
        if x_diff % D_cand == 0:
            D_list.append(D_cand)
print(min(D_list))

Submission status: Wrong Answer

Solution code:
n,x=[int(s)for s in input().split(" ")]
co=[int(s)for s in input().split(" ")]
co.append(x)
co=sorted(co)
mi=1145141919810
for i in range(n):
  mi=min((co[i+1]-co[i],mi))
print(mi)

Submission status: Wrong Answer

Solution code:
list1 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
list2 = list(map(int, input().split()))
list2.append(x)
list2.sort()

list3 = []
length = len(list2)
index =1
while index < length:
    list3.append(list2[index]-list2[index-1])
    index+=1

list3.sort()
mimN = list3[0]
ans =0
index2 =mimN
if len(list3) ==1:
    print(mimN)
else:
    flag2 =0
    for number in list3:
       if number%mimN !=0:
           flag2 =1
    if flag2 ==0:
        print(mimN)
    else:
        while index2>=1:
            flag=0
            for number in list3:
                if number%index2 ==0:
                    flag =1
                else:
                    flag =0
            if flag ==1:
                ans = index2
                break
            index2-=1
            
        print(ans)

Submission status: Wrong Answer

Solution code:
a = input().split()
n = int(a[0])
x = int(a[1])
b = input().split()
l = [int(i) for i in b]

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

def lcm(c, d):
    return c * d // gcd (c, d)

l.append(x)
ld = sorted(l, reverse=True)
#print(ld)
tmp = []
for i in range(1, len(ld)):
    tmp.append(abs(ld[i] - ld[i-1]))
#print(tmp)
#print(gcd(abs(max(l)-x), abs(min(l)-x)))
print(lcm(min(tmp), gcd(abs(max(l)-x), abs(min(l)-x))))

Submission status: Wrong Answer

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

Y = []
for i in x:
	Y.append(abs(X-i))
print(min(Y))

Submission status: Wrong Answer

Solution code:
import math as mh
import fractions as fr

n, p = (int(_) for _ in input().split())
x = list(int(_) for _ in input().split())

lmin = abs(p - min(x))
lmax = abs(p - max(x))

d = fr.gcd(lmin, lmax)

if d > lmin:
    d = fr.gcd(d, lmin)
elif d > lmax:
    d = fr.gcd(d, lmax)

print(d)

Submission status: Wrong Answer

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

maxi = 0

for i in range(N):
	sa = abs(x[i]-X)
	
	chk = 0
	for j in range(N):
		if((x[j]-X)%sa!=0):
			break
		else:
			chk += 1
	if(chk==N):
		if(sa>maxi):
			maxi = sa

print(maxi)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
l = list(map(int,input().split()))
lmin = list()
l.sort()
num = 0

if n == 1:
    print(l[0]-x)
    exit()
else:
    l.append(x)
    l.sort()

def calc():
    global l
    global lmin
    global num
    for i in range(n-num):
        lmin.append(l[i+1]-l[i])
    else:
        l = lmin
        num += 1

while(True):
    #print("j")
    for i in range(n-num):
        if l[i] % l[0] != 0:
            calc()
            continue
    else:
        print(l[0])
        break

Submission status: Wrong Answer

Solution code:
num_str=input().split()
num=list(map(int, num_str))
n=num[0]
x=num[1]

num2_str=input().split()
distance=list(map(int, num2_str))

first_distance=list(map(lambda y:abs(y-x),distance))
min_distance=min(first_distance)

flag=True
for i in range(min_distance,-1):
    for j in range(n):
        if first_distance[j]%i!=0:
            flag=False
            break

    if flag:
        ans=i
        print(ans)
        break

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

X_dif = list(0 for i in range(N))
for i in range(N):
    X_dif[i] = abs(x[i]-X)
X_dif.sort()

if N ==1:
    print(x[0]-X)
else:
    for i in range(dif[0]):
        possibility = 1
        for j in range(N-1):
            if dif[j]%(dif[0]-i) != 0 or X_dif[0]%(dif[0]-i) != 0:
                possibility = 0
                break
        if possibility == 1:
            print((dif[0]-i))
            break

Submission status: Wrong Answer

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

[n,m]=[int(i) for i in input().split()]
x1=[int(i) for i in input().split()]
x1.append(m)

x=[]
for i in range(len(x1)):
    temp=min(x1)
    x.append(temp)
    x1.remove(temp)

li=[]
f=1
if n==1:
    f=0
    print(abs(x[0]-x[1]))

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


if f:
    for i in range(len(li)-1):
        a=li[0]
        a=gcd(a, li[i+1])
    print(a)

Submission status: Wrong Answer

Solution code:
import math
l = map(int, raw_input().split())
toshisuu= l[0]
starttoshi= l[1]
toshilist = map(int, raw_input().split())
ans=100000000000000000000
for i in toshilist:
    counts=abs(i-starttoshi)
    if ans>counts:
        ans=counts
    
print ans

Submission status: Wrong Answer

Solution code:
import sys
from functools import reduce

import numpy


def main():
    lines = [list(map(int, x.strip().split())) for x in sys.stdin.readlines()]
    N, X = lines[0]
    location = sorted(lines[1])
    if len(location) == 1:
        print(location[0] - X)
    else:
        location = numpy.array(location)
        sub = location[1:] - location[:-1]
        result = reduce(gcd, sub)
        print(result)


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





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = []
d = []
for i in range(a[0]):
	b[i] = abs(b[i]-a[1])
l = min(b)
for i in range(len(b)-1):
	d.append(abs(b[i+1]-b[i]))
	if d[-1] == 0:
		d.pop()
d.sort()
for i in range(len(d)-1):
	if d[i] % d[0] != 0:
		d[0] = 1
		break
if len(d) == 0:
	print(l)
else:
	print(d[0])

Submission status: Wrong Answer

Solution code:
listA=list(map(int,input().split()))
N=listA[0]
X=listA[1]
listx=list(map(int,input().split()))
listx.append(X)
sortx=sorted(listx)
listdiff=[]
for i in range(N):
    listdiff.append(sortx[i+1]-sortx[i])
listdiff=list(set(listdiff))
ma=1
for i in range(len(listdiff)):
    c=listdiff[i]
    for j in range(len(listdiff)):
        if(listdiff[j]%c!=0):
            break;
        if(j==len(listdiff)-1):
            ma=c
    if(j!=len(listdiff)-1):
        break;
print(ma)

Submission status: Wrong Answer

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


def main():
    n, large_x = map(int, input().split())
    x = sorted(list(map(lambda x: int(x) - large_x, input().split())) + [0])
    dx = float('inf')

    for i in range(1, n + 1):
        dx = min(dx, x[i] - x[i - 1])

    candidates = sorted([dx, 2, 1], reverse=True)
    ans = 0
    count = 0

    for candidate in candidates:
        for xi in x:
            if xi % candidate == 0:
                count += 1

        if count == n + 1:
            ans = candidate

    print(ans)

Submission status: Wrong Answer

Solution code:
A,B = list(map(int,input().split()))
l = list(map(int,input().split()))


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

def gc(n):
    return [gcd(n[0],n[1])]+n[2::]

lgap = [abs(i-B) for i in l]
if 0 in lgap:
    lgap.remove(0)
if len(lgap)==1:
    g = lgap[0]
elif len(lgap)==2:
    g = gcd(lgap[0],lgap[1])
else:
    g = gc(lgap)
    g = gcd(g[0],g[1])

print(g)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
x=list(map(int,input().split()))
ans=0
amari=0
big=0
small=0
for i in range(N):
	x[i] = abs(x[i]-X)
if N==1:
	print(x[0])
else:
	ans=x[0]
	for j in range(1,N-1,1):
		if x[j]>=ans:
			big=x[j]
			small=ans
		else:
			big=ans
			small=x[j]
		while big%small != 0:
			amari=big%small
			big=small
			small=amari
		ans=small
	print(ans)

Submission status: Wrong Answer

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

x.append(X)
x.sort()
temp = []
for i in range(len(x)):
    if X <= x[i]:
        temp.append(abs(x[i] - x[i-1]))
print(min(temp))

Submission status: Wrong Answer

Solution code:
list1 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
list2 = list(map(int, input().split()))
list2.append(x)
list2.sort()

list3 = []
length = len(list2)
index =1
while index < length:
    list3.append(list2[index]-list2[index-1])
    index+=1

list3.sort()
mimN = list3[0]
ans =0
index2 =mimN
if len(list3) ==1:
    print(mimN)
else:
    flag2 =0
    for number in list3:
       if number%mimN !=0:
           flag2 =1
    if flag2 ==0:
        print(mimN)
    else:
        while index2>=1:
            flag=1
            for number in list3:
                if number%index2 ==0:
                    flag =1
            if flag ==1:
                ans = index2
                break
            index2-=1
            
        print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split( ))
x_i=[]
x_i+=map(int,input().split( ))
x_i+=[x]

x_c=list(set(x_i))
x_c.sort()

c = [y - x for (x, y) in zip(x_c[0:n], x_c[1:n+1])]
min_c=min(c)

def fun(x):
    return x%min_c
  
li=list(map(fun,c))

if max(li)==0:
    print(min(c))
else:
    print(1)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = sorted([int(x) for x in input().split()] + [x])
print(min([abs(y-x) for x, y in zip(a, a[1:])]))

Submission status: Wrong Answer

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

x.append(m)
x.sort()

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

print(min(aa))