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

kakunin=10**10

if N==1:
    print(abs(10**9-X))
    exit()

for i in range(N):
    S[i]=S[i]-X
    if abs(S[i])<kakunin:
        kakunin=abs(S[i])
        
ans=1
okflag=True
for i in range(2,kakunin+1):
    okflag=True
    for j in range(N):
        if S[j]%i!=0:
            okflag=False
           
            break
    if okflag==True:
        ans=i
print(ans)

Submission status: Wrong Answer

Solution code:
a = input().split()
x = int(a[0])
n = 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(n)
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:
import functools
import fractions

n,x = map(int,input().split())
cities = list(map(int,input().split()))
cities.append(x)
if n == x:
    ans = cities[0] - x
    print(ans)
else:
    cities.sort()
    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, x = map(int,input().split())
xl = list(map(int,input().split()))

xl.append(x)
xl.sort()

onesam = 0

if len(xl) == 1:
    print(abs(xl[0] - x))
    exit()

for i in range(len(xl)-1):
    one_sa = xl[i+1] - xl[i]
    if onesam == 0:
        onesam = one_sa
    else:
        short,big = min(onesam,one_sa),max(onesam,one_sa)
        if big % short == 0:
            onesam = short
            continue
        else:
            short,big = min(onesam,one_sa),max(onesam,one_sa)
            if short == 1:
                onesam = 1
                break
                
            while big % short != 0:
                for k in range(2,short+1):
                    if short % k == 0:
                        short = short // k
                        break
            onesam = short
            
print(onesam)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
x = sorted(map(int, input().split()))
if abs(X-x[0]) < abs(X-x[-1]):
    x = x.copy()[::-1]
flag = False
for xi in x:
    D = abs(xi-X)
    if N == 1:
        print(abs(X-x[0]))
        break
    for i in range(N-1):
        if abs(x[i]-x[i+1]) % D:
            flag = False
            break
        flag = True
    if flag:
        print(D)
        break

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)
a = []
for i in range(n):
    b = x_list[i+1]-x_list[i]
    a.append(b)
import math
from functools import reduce
print(a)

Submission status: Wrong Answer

Solution code:

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

#Nマップ、X開始地、x1、x2・・・位置、？D


x = input().rstrip().split()

#print(X,x)

ANS = []
for i in x:
	#print(abs(int(i)-X))
	ANS.append(abs(int(i)-X))

print(sorted(ANS)[0])

Submission status: Wrong Answer

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

input = sys.stdin.readline
n, x = map(int, input().split())
a = input().split()

b = list(map(int, a))
b.append(x)
b.sort()
minimum = b[1] - b[0]
for i in range(n):
    if i <= n - 1:
        if minimum > b[i + 1] - b[i]:
            minimum = b[i + 1] - b[i]

print(minimum)

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

length = len(list2)
index =1
while index < length:
    if index ==1:
        minL = list2[index]- list2[index-1]
    else:
        if minL>list2[index]-list2[index-1]:
            minL = list2[index]- list2[index-1]
    index+=1
print(minL)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split( ))
x_i=[]
x_i+=map(int,input().split( ))
x_i+=[x]
x_i.sort()
x_c=[]
for i in range(len(x_i)-1):
    x_c+=[x_i[i+1]-x_i[i]]

def fun(x):
    return x%min(x_c)
  
li=list(map(fun,x_c))

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

Submission status: Wrong Answer

Solution code:
import sys
N,X=map(int,input().split())
x=list(map(int,input().split()))
x.append(X)
x.sort()
x_diff=[]
for i in range (N):
    x_diff.append(x[i+1]-x[i])
ans=min(x_diff)
for i in range (len(x_diff)):
    if x_diff[i]%(ans)!=0:
        print (1)
        sys.exit()
print(ans)

Submission status: Wrong Answer

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

input = sys.stdin.readline
n, x = map(int, input().split())
a = input().split()

b = list(map(int, a))
b.append(x)
b.sort()
print(b)
minimum = b[1] - b[0]
for i in range(n):
    if i <= n - 1:
        if minimum > b[i + 1] - b[i]:
            minimum = b[i + 1] - b[i]

print(minimum)

Submission status: Wrong Answer

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

arr = [int(i) for i in input().split(' ')]

a = 5000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000


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

xl.append(x)
xl.sort()

onesam = 0
for i in range(len(xl)-1):
    one_sa = xl[i+1] - xl[i]
    if onesam == 0:
        onesam = one_sa
    else:
        short,big = min(onesam,one_sa),max(onesam,one_sa)
        if big % short == 0:
            onesam = short
            continue
        else:
            short,big = min(onesam,one_sa),max(onesam,one_sa)
            if short == 1:
                onesam = 1
                break
                
            while big % short != 0:
                for k in range(2,short+1):
                    if short % k == 0:
                        short = short // k
                        break
            onesam = short
            
print(onesam)

Submission status: Wrong Answer

Solution code:
import fractions
data=map(int,raw_input().split())
x=map(int,raw_input().split())

x.append(data[1])
x.sort()

print x
d=[]
for i in range(data[0]):
  d.append(x[i+1]-x[i])
print d
print reduce(fractions.gcd,d)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
if(a==1):
    print(abs(l[0]-b))
    exit()
else:
    num=abs(l[-1]-l[-2])
    num2=abs(l[0]-b)
    ans=563634235364353
    for i in range(1,len(l)):
        ans=min(abs(l[i]-l[i-1]),ans)
    print(min(ans,num2,num))

Submission status: Wrong Answer

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

def gcd_list(l):
    # print(l)
    if len(l) == 1:
        return l[0]
    temp = [gcd(l[0],l[1])]
    n = 0
    while(n<len(l)-2):
        # print(temp)
        temp.append( gcd(temp[n], l[n+2]) )
        n = n+1
    # print(temp)
    return(temp[len(temp)-1])

n, start = map(int, input().split(" "))
li = list(map(int, input().split(" ")))
diff = min(li) - start
if(len(li) == 1):
    print(diff)
else:
    # for i in range(n):
    #     li[i] = li[i] - start - diff
    # print(gcd_list(li))
    li.append(start)
    minn = min(li)
    for i in range(len(li)):
        li[i] = li[i] - minn
    print(gcd_list(li))

Submission status: Wrong Answer

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

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 i != 0:
        temp.append(x[i] - x[i-1])
print(min(temp))

Submission status: Wrong Answer

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

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

odds = list()

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

    if diff % 2 == 0:
        is_even == True
    else:
        is_odd = True
        odds.append(diff)

    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)
    sys.exit()
    
if len(odds) >= 1:
    for i in range(len(odds)):
        for j in range(len(odds)):
            if gcd(odds[i], odds[j]) == 1:
                print(1)
                sys.exit()




print(min)

Submission status: Wrong Answer

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

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

x.append(X)

sorted_x = sorted(x)
sorted_aaa = []

aaa = []

for (i, item) in enumerate(sorted_x):
    if i == 0:
        continue
    aaa.append(int(sorted_x[i] - sorted_x[i - 1]))

sorted_aaa = sorted(aaa)

res = sorted_aaa[0]


for (k, elm) in enumerate(sorted_aaa):
    if elm % sorted_aaa[0] != 0:
        res = 1

print(res)

Submission status: Wrong Answer

Solution code:
# AtCoder Beginner Contest 109 20180908
# Question:C 全ての都市間の最大公約数を求める

#二つの数の最大公約数
def gcd(a, b):
	if b == 0: return a
	return gcd(b, a % b)
 

init = input().split(" ")
init = [int(c) for c in init]

nums = input().split(" ")
nums = [int(c) for c in nums]

if not init[1] in nums:
	nums.append(init[1])
nums.sort()

d = max(nums) - min(nums)

for j in range(init[0]-2):
	d1 = nums[j+1] - nums[j]
	d2 = nums[j+2] - nums[j+1]
	
	d = min(gcd(d1,d2), d)
	if d == 1:
		break
print(d)

Submission status: Wrong Answer

Solution code:
NX =  list(map(int, input().split()))
Points =  list(map(int, input().split()))
Points.append(NX[1])
Points.sort()

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

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

Submission status: Wrong Answer

Solution code:
import math
n,x=map(int,input().split())
pos=list(map(int,input().split()))
pos2=[abs(p-x) for p in pos]
width= max(pos)
ans = 1
for i in range(2,width+1):
    if all([ x%i==0 for x in pos2 ]):ans=i

print(ans)

Submission status: Wrong Answer

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

xl.append(x)
xl.sort()

onesam = 0
for i in range(len(xl)-1):
    one_sa = xl[i+1] - xl[i]
    if onesam == 0:
        onesam = one_sa
    else:
        short,big = min(onesam,one_sa),max(onesam,one_sa)
        if big % short == 0:
            onesam = short
            continue
        else:
            short,big = min(onesam,one_sa),max(onesam,one_sa)
            if short == 1:
                onesam = 1
                break
                
            while big % short != 0:
                for k in range(2,short+1):
                    if short % k == 0:
                        short = short // k
                        break
            if short == 1:
                onesam = 1
                break
            else:
                onesam = short
print(onesam)

Submission status: Wrong Answer

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

arr = [int(i) for i in input().split(' ')]

a = 500000000000000000000000000000000000000000000000000000000000

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

xx = [abs(xxx - X) for xxx in x]

l = xx[0]
#if len(xx) > 1:
#    for i in xx[1:]:
#        l = math.gcd(l, i)


print(l)

Submission status: Wrong Answer

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

def check(n):
    return abs(n - x)

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

dist = list(map(check, city))
min_dist = min(dist)

if n < 2:
    print(min_dist)
    exit()

dists = []
prev = ''

for pos in city:
    if not prev == '':
        dists.append(abs(prev - pos))
    prev = pos

tmp = min(dists)

if(min_dist > tmp):
    print(tmp)
else:
    print(min_dist)

Submission status: Wrong Answer

Solution code:
import numpy as np
import functools
import math

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

def gcd_1(l):
    x = max(l)
    y = min(l)
    if x % y == 0:
        return y
    else:
        while x%y!=0:
            z = x%y
            x = y
            y = z
        else:
            return z
        
if N == 1:
    print(x_list[0] - X)
    exit()

values = np.sort(np.array(x_list))[1:] - min(x_list)
print(gcd_1(values))

Submission status: Wrong Answer

Solution code:
# encoding: utf-8
import math

N, X = map(int, input().split())
dx = sorted(map(lambda x: x - X, map(int, input().split())))

ddx_min = 10 ** 9
dx_tmp = dx[0]
for i, dxi in enumerate(dx):
    if i == 0: continue
    # minimum distance
    if dxi - dx_tmp < ddx_min: ddx_min = dxi - dx_tmp
    dx_tmp = dxi
if N == 1: ddx_min = dx[0]
    
for D in range(ddx_min + 1)[::-1]:
    for dxi in dx:
        # print(D, dxi)
        if dxi % D > 0: break
        else: continue
    else:
        print(D)
        break
else: print("oops")

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
if(a==1):
    print(l[0]-b)
    exit()
else:
    num=abs(l[-1]-l[-2])
    num2=abs(l[0]-b)
    ans=563634235364353
    for i in range(1,len(l)):
        ans=min(abs(l[i]-l[i-1]),ans)
    print(min(ans,num2,num))

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

x_min = min(x)
x_max = max(x)

d = fr.gcd(abs(p-x_min), abs(x_max-p))
print(d)

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

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

Submission status: Wrong Answer

Solution code:
n,x = map(int, raw_input().split())
lis = sorted(map(int, raw_input().split()))
def gcd(a, b):
    if a == 0:
        return b
    return gcd(b%a,a)
if n == 1:
    val = abs(lis[0]-x)
    if val == 0:
        print 1
    else:
        print val
    exit()
import bisect
#print lis
idx = bisect.bisect_left(lis, x)
#print idx
if idx == 0:
    val = lis[0] - x
    flag = 0
    for i in range(1, n):
        if (lis[i] - x) % val != 0:
            flag = 1
            break
    if flag == 0:
        print val
    else:
        zz = gcd(x, min(lis))
        flag1 = 0
        for i in xrange(n):
            if abs(lis[i]-x) % zz != 0:
                flag1 =1
                break
        if flag1 == 1:
            print 1
        else:
            print zz
elif idx == n:
    val = x - lis[-1]
    flag = 0
    for i in range(n-2, -1, -1):
        if (x - lis[i]) % val != 0:
            flag = 1
            break
    if flag == 0:
        print val
    else:
        zz = gcd(x, min(lis))
        flag1 = 0
        for i in xrange(n):
            if abs(lis[i]-x) % zz != 0:
                flag1 =1
                break
        if flag1 == 1:
            print 1
        else:
            print zz
else:
    val = min(lis[idx]-x, x-lis[idx-1])
    flag = 0
    for i in range(idx, n, 1):
        if (lis[i]-x)%val != 0:
            flag= 1
            break
    for i in range(idx-1, -1, -1):
        if (x-lis[i])%val != 0:
            flag = 1
            break
    if flag == 0:
        print val
    else:
        zz = gcd(x, min(lis))
        flag1 = 0
        for i in xrange(n):
            if abs(lis[i]-x) % zz != 0:
                flag1 =1
                break
        if flag1 == 1:
            print 1
        else:
            print zz


#print bisect.bisect_left(lis, 38)

Submission status: Wrong Answer

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

D=[]

for i in range(N):
    D.append(abs(X-x[i]))

print(min(D))

Submission status: Wrong Answer

Solution code:
import functools
import math
import fractions
n, x = map(int, input().split())
xx = list(map(int, input().split()))  # x1 x2 ... xn
xx.append(x)
xx.sort()
diff = []  # 隣接する都市の距離を保存
d = 0
if len(xx) > 2:
    for i in range(1, n):
        diff.append(abs(xx[i - 1] - xx[i]))
    d = functools.reduce(fractions.gcd, diff)
else:
    d = abs(xx[0] - xx[1])
print(d)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
# print(n, x)
citys = list(map(int, input().split()))
# print(citys)

import numpy as np

def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

nearest_city = getNearestValue(citys, x)
# print(nearest_city)

for xx in reversed(range(1, (abs(nearest_city-x)+1))):
    for city in citys:
        if ((city - x) % xx) != 0:
            break
    break
print(xx)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
if(a==1):
    print(l[0]-b)
    exit()
else:
    num=l[-1]-l[-2]
    num2=abs(l[0]-b)
    ans=563634235364353
    for i in range(1,len(l)):
        ans=min(abs(l[i]-l[i-1]),ans)
    print(min(ans,num2,num))

Submission status: Wrong Answer

Solution code:
from functools import reduce
import sys
n=list(map(int,input().split()))
a=list(map(int,input().split()))

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

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

for i in range(n[0]):
  a[i] -= n[1]

print(gcd_list(a))

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
c = list(map(int,input().split()))
c.append(b)
c.sort()
d = 1000000000
for i in range(a):
    e = c[i+1]-c[i]
    if e < d:
        d = e
print(d)

Submission status: Wrong Answer

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

kakunin=10**10

if N==1:
    print(10**9-X)
    exit()

for i in range(N):
    S[i]=S[i]-X
    if abs(S[i])<kakunin:
        kakunin=abs(S[i])
        
ans=1
okflag=True
for i in range(2,kakunin+1):
    okflag=True
    for j in range(N):
        if S[j]%i!=0:
            okflag=False
           
            break
    if okflag==True:
        ans=i
print(ans)

Submission status: Wrong Answer

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

start = n-1
for i in range(n):
    if points[i] > x:
        start = i

dxs = set([points[i+1]-points[i] for i in range(n-1)])

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

if start == 0:
    d = points[0]-x
    for i in dxs:
        d = gcd(d, i)
    print(d)

elif start == n-1:
    d = x-points[-1]
    for i in dxs:
        d = gcd(d, i)
    print(d)

else:
    d1 = points[start]-x
    for i in dxs:
        d1 = gcd(d1, i)
    d2 = x-points[start-1]
    for i in dxs:
        d2 = gcd(d2, i)
    print(max(d1,d2))

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)
a = []
for i in range(n):
    b = x_list[i+1]-x_list[i]
    a.append(b)
print(a)

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

x_min = min(x)
x_max = max(x)

d = fr.gcd(p-x_min, x_max-p)
print(d)

Submission status: Wrong Answer

Solution code:
NX =  list(map(int, input().split()))
Points =  list(map(int, input().split()))
Points.append(NX[1])
Points.sort()

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

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

Submission status: Wrong Answer

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

xl.append(x)
xl.sort()

onesam = 0
for i in range(len(xl)-1):
    one_sa = xl[i+1] - xl[i]
    if onesam == 0:
        onesam = one_sa
    else:
        short,big = min(onesam,one_sa),max(onesam,one_sa)
        if big % short == 0:
            onesam = short
            continue
        else:
            short,big = min(onesam,one_sa),max(onesam,one_sa)
            if short == 1:
                onesam = 1
                break
                
            while big % short != 0:
                for k in range(2,short+1):
                    if short % k == 0:
                        short = short // k
            if short == 1:
                onesam = 1
                break
            else:
                onesam = short
print(onesam)

Submission status: Wrong Answer

Solution code:
import sys
N, X = [int(c) for c in raw_input().split()]
xs = [int(c) for c in raw_input().split()]

if len(xs) == 1:
    print abs(xs[0]-X)
else:
    xs.sort()
    d_min = sys.maxint

    if X < xs[0]:
        d_min = min(d_min, xs[0]-X)
    elif X > xs[-1]:
        d_min = min(d_min, X-xs[-1])

    for i in range(len(xs)-1):
        d_min = min(d_min, xs[i+1] - xs[i])

        if xs[i] < X < xs[i+1]:
            d_min = min(d_min, X-xs[i], xs[i+1]-X)
    print d_min

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)):
    temp.append(abs(x[i] - x[i-1]))
print(min(temp))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
tosi = list(map(int,input().split()))
for i in range(n):
    tosi[i]=abs(m-tosi[i])
print(min(tosi))

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-X)
    if i == 0:
        max_v = m
    if m < max_v:
        max_v = m

if max_v == 1:
    print(max_v)
else:
    wented = [max_v, 1]
    minimam = 1
    maximam = max_v+1
    ran = round(max_v / 2)
    while True:
        # print(max_v)
        Flag = True
        for i in range(len(town) - 1):
            if not abs(town[i]-town[i+1]) % max_v == 0:
                Flag = False
                break

        if not Flag:
            if max_v - 1 == minimam:
                break
            else:
                maximum = max_v
                max_v = max_v - ran
                ran = round(ran / 2)

        else:
            if max_v + 1 == maximam:
                break
            else:
                minimam = max_v
                max_v = max_v + ran
                ran = round(ran / 2)


    if not Flag:
        print(max_v - 1)
    else:
        print(max_v)

Submission status: Wrong Answer

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

kouho=[abs(l[i]-x) for i in range(n)]

ans=1
for i in (2,min(kouho)):
  mod = (x-i)%i
  signal=1
  for j in range(n):
    if l[j]%i!=mod:
      signal=0
  if signal==1:
    ans=i
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

N, X = map(int, input().split())
xn = list(map(int, input().split()))
xn2 = []

for xi in xn:
    xn2.append(xi - X)

xn2.sort()

gcd_num = max(xn2)
for xi2 in xn2:
    tmp = gcd(xi2,gcd_num)
    if tmp < gcd_num:
        gcd_num = tmp

print(gcd_num)

Submission status: Wrong Answer

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

xl.append(x)
xl.sort()

onesam = 0
for i in range(len(xl)-1):
    one_sa = xl[i+1] - xl[i]
    if onesam == 0:
        onesam = one_sa
    else:
        short,big = min(onesam,one_sa),max(onesam,one_sa)
        if big % short == 0:
            onesam = short
            continue
        else:
            short,big = min(onesam,one_sa),max(onesam,one_sa)
            if short == 1:
                onesam = 1
                break
                
            while big % short != 0:
                for i in range(2,short+1):
                    if short % i == 0:
                        short = short // i
            if short == 1:
                onesam = 1
                break
            else:
                onesam = short
print(onesam)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,X = list(map(int, input().split()))
x = list(map(int, input().split()))
x = np.array(x)

x = x - X

# n = 10000
# x = np.arange(n)[np.random.binomial(1, 0.5, n) == 1] * 2
# x = np.append(x,333333)

def check(x):
    for k in range(len(x)):
        for i in range(k+1,len(x)):
            a = x[k]
            b = x[i]
            y = gcd(a,b)
#             print(a,b)

            temp = x%y
            if np.sum(temp)==0:
                return [y]
            else:
                xs = []
                xs.append(x[temp == 0][0:1])
                xs.append(x[temp == 1])
                x = np.hstack(xs)
            return x
def gcd(a,b):
    while b:
        a, b = b, a%b
    return a

while len(x)>1:
    x = check(x)
print(x[0])

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
if(a==1):
    print(l[0]-b)
    exit()
else:
    num=l[-1]-l[-2]
    num2=abs(l[0]-b)
    if(num==num2 or (num%num2)==0 or (num2%num)==0):
        print(min(num,num2))

Submission status: Wrong Answer

Solution code:
# AtCoder Beginner Contest 109 20180908
# Question:C 全ての都市間の最大公約数を求める

#二つの数の最大公約数
def gcd(a, b):
	if b == 0: return a
	return gcd(b, a % b)
 

init = input().split(" ")
init = [int(c) for c in init]

nums = input().split(" ")
nums = [int(c) for c in nums]

nums.append(init[1])
nums.sort()

d = max(nums) - min(nums)

for j in range(init[0]-2):
	d1 = nums[j+1] - nums[j]
	d2 = nums[j+2] - nums[j+1]
	
	d = min(gcd(d1,d2), d)
	if d == 1:
		break
print(d)

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
x = list(map(int,input().split()))
ans = []
for i in x:
    ans.append(abs(X-i))
ansmin = min(ans)
if ansmin %2==0:
    for i in ans:
        if i %2 !=0:
            print(1)
            exit()
    print(ansmin)
else:
    for i in ans:
        if i %2 ==0:
            print(1)
            exit()
    print(ansmin)

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)
    if x[i] == 0:
        x[i] = 10000000000
m = min(x)

for i in range(N):
    if x[i] % m != 0 and x[i] != 10000000000:
        print(1)
        exit()
print(m)

Submission status: Wrong Answer

Solution code:
n,x = map(int, raw_input().split())
lis = sorted(map(int, raw_input().split()))
def gcd(a, b):
    if a == 0:
        return b
    return gcd(b%a,a)
if n == 1:
    val = abs(lis[0]-x)
    if val == 0:
        print 1
    else:
        print val
    exit()
import bisect
#print lis
idx = bisect.bisect_left(lis, x)
#print idx
if idx == 0:
    val = lis[0] - x
    flag = 0
    for i in range(1, n):
        if (lis[i] - x) % val != 0:
            flag = 1
            break
    if flag == 0:
        print val
    else:
        zz = gcd(x, min(lis))
        print zz
elif idx == n:
    val = x - lis[-1]
    flag = 0
    for i in range(n-2, -1, -1):
        if (x - lis[i]) % val != 0:
            flag = 1
            break
    if flag == 0:
        print val
    else:
        zz = gcd(x, min(lis))
        print zz
else:
    val = min(lis[idx]-x, x-lis[idx-1])
    flag = 0
    for i in range(idx, n, 1):
        if (lis[i]-x)%val != 0:
            flag= 1
            break
    for i in range(idx-1, -1, -1):
        if (x-lis[i])%val != 0:
            flag = 1
            break
    if flag == 0:
        print val
    else:
        zz = gcd(x, min(lis))
        print zz


#print bisect.bisect_left(lis, 38)

Submission status: Wrong Answer

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

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

x.append(X)

sorted_x = sorted(x)
sorted_aaa = []

aaa = []

for (i, item) in enumerate(sorted_x):
    if i == 0:
        continue
    aaa.append(int(sorted_x[i] - sorted_x[i - 1]))

for j in aaa:
    sorted_aaa = sorted(aaa)

res = sorted_aaa[0]


for (k, elm) in enumerate(sorted_aaa):
    if elm % sorted_aaa[0] != 0:
        res = 1

print(res)

Submission status: Wrong Answer

Solution code:
input_list1 = list(map(int, input().split()))
input_list2 = list(map(int, input().split()))
#input_list1 = [3, 81]
#input_list2 = [33, 105, 57]
N = input_list1[0]
X = input_list1[1]

#print('N:', N)
#print('X:', X)

# 都市のリストにXを追加し、小さい順にソートする
input_list2.append(X)
input_list2.sort()
#print(input_list2)

# それぞれの差を取る
ans_list = []
for i, target in enumerate(input_list2):
    if i == N:
        break
    aa = input_list2[i + 1] - input_list2[i]
    #print(input_list2[i + 1], '-' , input_list2[i])
    ans_list.append(aa)

# 最小値が答え
print(min(ans_list))

Submission status: Wrong Answer

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

x.append(X)
x.sort()

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

d.sort()

D = d[0]

for i in range(len(d) - 1):
    if d[i + 1] % D != 0:

        for j in range(int(D ** 0.5) + 1, 1, -1):

            if d[i + 1] % j == 0 and D % j == 0:
                D = j
                continue

    if D == 1:
        break

print(D)