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());print(sorted([abs(x-i) for i in list(map(int,input().split()))])[0])

Submission status: Wrong Answer

Solution code:
import sys

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

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

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

anslis = [0]*N

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

EvenorOdd = anslis[0] % 2
for j in range(1,len(anslis)):
    
    if EvenorOdd == anslis[j] % 2:
        EvenorOdd = anslis[j] % 2
        pass
    else:
        print(1)
        sys.exit()

print(min(anslis))

Submission status: Wrong Answer

Solution code:
import sys

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

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



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




flag = 0
ans = 10**10
for i in range(N-2):
    EvenorOdd1 = (A[i+1] - A[i]) % 2
    EvenorOdd2 = (A[i+2]-A[i+1]) % 2
    
    minimun1 =  (A[i+1] - A[i])
    minimun2 =  (A[i+2]-A[i+1])

    if EvenorOdd1 == EvenorOdd2:
        pass
    else:
        flag = 1

    ans = min(ans,minimun1,minimun2)
    
if flag == 0:
    print(ans)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
import bisect as bs

if __name__ == '__main__':

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

	ind = bs.bisect_left(A,x)

	ans = 0
	if ind == 0:#最内
		ans = abs(A[ind] - x)
	elif ind == n:#大外
		ans = abs(A[ind-1] - x)
	else:
		ans = min(abs(A[ind-1] - x),abs(A[ind] - x))
	print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
res,ans = [],0
for i in range(n):
	res.append(abs(a[i]-x))
#print(min(res))
res.sort()
ans = res[0]
cnt = 0
if n > 1:
	num = min((n-1),11)
	for j in range(2,num):
		cmp = a[0]%res[0]*j
		for s in range(n):
			if a[s]%res[0]*j != cmp:
				break
			else:
				cnt += 1
		if cnt == n:
			ans = res[0]*j
print(ans)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
res,ans = [],0
for i in range(n):
	res.append(abs(a[i]-x))
#print(min(res))
res.sort()
ans = res[0]
if n > 1:
	num = min((n-1),11)
	for j in range(1,num):
		cmp = a[0]%res[j]
		for s in range(j+1,n):
			if a[s]%res[j] != cmp:
				continue
			ans = res[j]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def bin_search(m,B):

	left = 0
	right = len(B) - 1
	
	while left <= right:
		middle = (left + right) // 2
		if m == B[middle]:
			return 0
		elif m > B[middle]:
			left = middle + 1
		else:
			right = middle - 1

	return abs(m - B[middle])


if __name__ == '__main__':

	n,x = map(int,input().split())
	A = list(map(int,input().split()))
	B = sorted(A)

	print(bin_search(x,B))

Submission status: Wrong Answer

Solution code:
import math

n, x = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(n):
  b.append(abs(x-a[i]))
ans = b[0]
for j in range(1, n):
  ans = math.gcd(ans, b[i])
print(ans)

Submission status: Wrong Answer

Solution code:
import math

n, x = map(int, input().split())
a = [x] + list(map(int, input().split()))
a.sort(reverse=True)
b = []
for i in range(n):
  b.append(a[i]-a[i+1])
ans = b[0]
for j in range(1, n):
  ans = math.gcd(ans, b[i])
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from math import gcd
# from numba import njit
from functools import reduce
# from collections import Counter
# from itertools import accumulate
# import numpy as np
# from heapq import heappop,heappush
# from bisect import bisect_left

# @njit
def solve(n,x,a):
    delta_a = [a[i] - x for i in range(n)]
    return reduce(gcd,delta_a)



def main():
    # N = int(input())
    N,X = map(int,input().split())
    a = list(map(int,input().split()))
    print(solve(N,X,a))
    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

# from numba import njit

# from collections import Counter
# from itertools import accumulate
# import numpy as np
# from heapq import heappop,heappush
# from bisect import bisect_left

# @njit
def solve(n,x,a):
    delta_a = [a[i] - x for i in range(n)]
    d = max(delta_a)
    while d > 0:
        if all(k % d == 0 for k in delta_a):
            return d
        else:
            d -= 1
    return -1



def main():
    # N = int(input())
    N,X = map(int,input().split())
    a = list(map(int,input().split()))
    print(solve(N,X,a))
    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if n == 1:
    print(abs(lis[0] - x))
    exit()

lis.append(x)
lis = sorted(lis)

ans = 10**9 + 7

for i in range(n-1):
    ans = min(ans, abs(lis[i+1] - lis[i]))

print(ans)

Submission status: Wrong Answer

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

ans = 10**9 + 7
ans2 = 0

for i in range(n):
    ans = min(ans, abs(x-lis[i]))
    ans2 = max(ans2, abs(x-lis[i]))

print(min(ans, ans2))

Submission status: Wrong Answer

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

ans = 10**9 + 7

for i in range(n):
    ans = min(ans, abs(x-lis[i]))

print(ans)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

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

distance = []
for c in city:
    distance.append(c- x)

print(gcd(*distance))

Submission status: Wrong Answer

Solution code:
# 最大公約数(mathは3.5以降) 
import math
from functools import reduce

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

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

# 初期入力
import sys
#input = sys.stdin.readline  #文字列では使わない
N,X = map(int, input().split())
x = list(map(int, input().split()))

# ｘの隣同士の距離リスト
x_div =[abs(X-x[0])]
for i in range(N-1):
    x_div.append(abs(x[i] -x[i+1]))

#x_divの最大公約数
if N ==1:
    ans =x[0] -X
else:
    ans =gcd_list(x_div)
print(ans)

Submission status: Wrong Answer

Solution code:
# 最大公約数(mathは3.5以降) 
import math
from functools import reduce

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

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

# 初期入力
import sys
#input = sys.stdin.readline  #文字列では使わない
N,X = map(int, input().split())
x = list(map(int, input().split()))

# ｘの隣同士の距離リスト
x_div =[]
for i in range(N-1):
    x_div.append(abs(x[i] -x[i+1]))

#x_divの最大公約数
if N ==1:
    ans =x[0] -X
else:
    ans =gcd_list(x_div)
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()
Mindif = x[1]-x[0]
import math
for i in range(1,N-1):
    Mindif = math.gcd(Mindif,x[i+1]-x[i])
print(Mindif)

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
x = list(map(int,input().split()))
if N == 1:
    print(abs(x[0]-X))
    exit()
x.sort()
Mindif = x[1]-x[0]
import math
for i in range(1,N-1):
    Mindif = math.gcd(Mindif,x[i+1]-x[i])
print(Mindif)

Submission status: Wrong Answer

Solution code:
import math

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

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

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

Submission status: Wrong Answer

Solution code:
import math

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

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

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

Submission status: Wrong Answer

Solution code:
import math

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

x.append(X)
x.sort()

ans = x[1]-x[0]
for i in range(1,N-1):
    if N == 1:
        break
    ans = math.gcd(ans, x[i+1]-x[i])


print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

x.append(X)
x.sort()

if N==1:
    ans = x[1]-x[0]
else:
    for i in range(N-1):
        ans = math.gcd(x[i+1]-x[i], x[i+2]-x[i+1])

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N,X = map(int, input().split())
x = sorted(map(int, input().split()))
bisect.insort(x,X)
ans = [x[i+1]-x[i] for i in range(N)] 
if N ==1:
    print(x[1]-x[0])
else:
    print(min(ans))

Submission status: Wrong Answer

Solution code:
import bisect
N,X = map(int, input().split())
x = sorted(map(int, input().split()))
bisect.insort(x,X)
ans = [x[i+1]-x[i] for i in range(N-1)] 
if N ==1:
    print(x[1]-x[0])
else:
    print(min(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
from bisect import bisect
def diff(l):
    c = 0
    ans = []
    for i in l:
        try:
            ans.append(abs(i-l[c+1]))
            c+=1
        except:
            continue
    return ans
def multiGCD(l):
    ans = 0
    for i in l:
        ans = math.gcd(ans, i)
    return ans
n, x = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
l2 = diff(l)
if len(l2)==0:
    print(l[0]-x)
else:
    print(multiGCD(l2))

Submission status: Wrong Answer

Solution code:
import math
def diff(l):
    c = 0
    ans = []
    for i in l:
        try:
            ans.append(abs(i-l[c+1]))
            c+=1
        except:
            continue
    return ans
def multiGCD(l):
    ans = 0
    for i in l:
        ans = math.gcd(ans, i)
    return ans
n, x = map(int, input().split())
l = list(map(int, input().split()))
l2 = diff(l)
if len(l2)==0:
    print(l[0]-x)
else:
    print(multiGCD(l2))

Submission status: Wrong Answer

Solution code:
from math import gcd
N,X = map(int, input().split())
L = list(map(int, input().split()))
k = 0
for i in L:
  if k == 0:
    k = i - X
  else:
    k = gcd(k, i-X)
print(k)

Submission status: Wrong Answer

Solution code:
n, X = map(int, input().split())
x = list(map(abs, [i-X for i in list(map(int, input().split()))]))
x.sort()
ans = 1
if x[0] == 0:
    del x[0]
    n -= 1
if n == 1:
    ans = x[0]
elif min(x) != 1:
    fi = x[1] - x[0]
    if 1 < fi <= x[0]:
        st = fi
    else:
        st = 2
    for i in range(st, min(x) + 1):
        go = True
        while go:
            go = False
            cnt = 0
            for j in x:
                if j%i == 0:
                    cnt += 1
            if cnt == n:
                ans *= i
                go = True
                for j in range(n):
                    x[j] //= i
            else:
                break
print(ans)

Submission status: Wrong Answer

Solution code:
n, X = map(int, input().split())
x = list(map(abs, [i-X for i in list(map(int, input().split()))]))
x.sort()
ans = 1
if x[0] == 0:
    del x[0]
    n -= 1
if n == 1:
    ans = x[0]
elif min(x) != 1:
    for i in range(2, min(x)):
        go = True
        while go:
            go = False
            cnt = 0
            for j in x:
                if j%i == 0:
                    cnt += 1
            if cnt == n:
                ans *= i
                go = True
                for j in range(n):
                    x[j] //= i
            else:
                break
print(ans)

Submission status: Wrong Answer

Solution code:
n, X = map(int, input().split())
x = list(map(abs, [i-X for i in list(map(int, input().split()))]))
x.sort()
ans = 1
if x[0] == 0:
    del x[0]
    n -= 1
if n == 1:
    ans = x[0]
elif min(x) != 1:
    for i in range(2, int(min(x)**0.5) + 2):
        go = True
        while go:
            go = False
            cnt = 0
            for j in x:
                if j%i == 0:
                    cnt += 1
            if cnt == n:
                ans *= i
                go = True
                for j in range(n):
                    x[j] //= i
            else:
                break
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, g = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    if n == 1:
        print(abs(a[0]-g))
        return
    a.append(g)
    a.sort()
    b = []
    for i in range(1, n):
        b.append(a[i]-a[i-1])
    g = b[-1]
    for e in b:
        g = gcd(e, g)
    print(g)
    




        

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""

Submission status: Wrong Answer

Solution code:
def A(a,b):
    if a<b:
        tmp = a
        a = b
        b = tmp
    r = a % b
    while r!=0:
      a = b
      b = r
      r = a % b
    return b
n,X=map(int,input().split())
x=list(map(int,input().split()))
x.append(X)
x.sort()
x2=[]
for i in range(1,n+1):
    x2.append(x[i]-x[i-1])
print(x2)
if len(x2)==1:
    p=x2[0]
else:
    for i in range(n):
        if i==0:
            p=A(x2[i-1],x2[i])
        elif i!=1:
            p=A(p,x2[i])
print(p)

Submission status: Wrong Answer

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

ans = 10**9
X2 = sorted(X)

for i in range(1, len(X)):
    ans = min(ans, abs(X2[i]-X2[i-1]))
    if (X2[i]%2 + X[i]%2)%2 == 1:
        print(1)
        exit()
for x in X:
    ans = min(ans, abs(Y-x))

print(ans)

Submission status: Wrong Answer

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

ans = 10**9
X2 = sorted(X)

for i in range(1, len(X)):
    ans = min(ans, abs(X2[i]-X2[i-1]))
for x in X:
    ans = min(ans, abs(Y-x))

print(ans)

Submission status: Wrong Answer

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

ans = 10**9
for x in X:
    ans = min(ans, abs(Y-x))

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

a = [x[i] - x[i-1] for i in range(1, N+1)]
mn = min(a)

print(mn if len([m for m in a if m % mn == 0]) == len(a) else 1)

Submission status: Wrong Answer

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

a = [None] * N
for i in range(1, N+1):
    a[i-1] = x[i] - x[i-1]

mn = min(a)

for m in a:
    if m % mn != 0:
        print(1)
        break
else:
    print(mn)

Submission status: Wrong Answer

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

diff = [abs(x - X) for x in Coordinates]

print(min(diff))

Submission status: Wrong Answer

Solution code:
from math import gcd

N, X = map(int, input().split())
xs = sorted(map(int, input().split()))
xs = [x - X for x in xs]
ds = []
for i in range(1, N):
    ds.append(xs[i] - xs[i - 1])
if ds:
    ans = abs(ds[0])
    for d in ds:
        ans = gcd(abs(d), ans)
else:
    ans = abs(xs[0])
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd

N, X = map(int, input().split())
xs = sorted(map(int, input().split()))
xs = [x - X for x in xs]
ds = []
for i in range(1, N):
    ds.append(xs[i] - xs[i - 1])
if ds:
    ans = ds[0]
    for d in ds:
        ans = gcd(d, ans)
else:
    ans = xs[0]
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

x = sorted(x, reverse=True)

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

elif N==2:
    print(math.gcd(abs(x[0]-X), abs(x[1]-X)))

else:
    #Xとの距離の最小公倍数
    f = math.gcd(abs(x[0]-X), abs(x[1]-X))
    for i in range(2,N):
        dammy1 = f
        dammy2 = abs(x[i]-X)
        f = math.gcd(dammy1,dammy2)

    print(f)

Submission status: Wrong Answer

Solution code:
import math

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

x = sorted(x, reverse=True)

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

else:
    #Xとの距離の最小公倍数
    f = math.gcd(abs(x[0]-X), abs(x[1]-X))
    for i in range(2,N):
        dammy1 = f
        dammy2 = abs(x[i]-X)
        f = math.gcd(dammy1,dammy2)

    print(f)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n,x = readInts()
xs = readInts()
xs.append(x)
xs.sort()

ans = xs[1]-xs[0]
for i in range(n-1):
  ans = math.gcd(ans,xs[i+1]-xs[i])

print(ans)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

n, k = map(int, input().split())
x = list(map(int, input().split()))
y = []

for i,X in enumerate(x):
    val = X - k
    y.append(val)

print(reduce(math.gcd, y))

Submission status: Wrong Answer

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

x = list(map(int,input().split()))
lst = [0]*N
for i in range(len(x)):
    lst[i] = abs(x[i] - X)
   
def find_gcd(x, y): 
    while(y): 
        x, y = y, x % y 
  
    return x 
if len(lst) > 1:
    num1=lst[0] 
    num2=lst[1] 
    gcd=find_gcd(num1,num2) 
  
    for i in range(2,len(lst)): 
        gcd=find_gcd(gcd,lst[i]) 
    print(gcd)
else:
    min(lst)

Submission status: Wrong Answer

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

x = list(map(int,input().split()))
lst = [0]*N
for i in range(len(x)):
    lst[i] = abs(x[i] - X)
    
print(min(lst))

Submission status: Wrong Answer

Solution code:
import math

def solve():
    arr = []
    for i in range(N):
        arr.append(abs(start-x[i]))
    a = min(arr)
    b = max(arr)
    print(math.gcd(a,b))
        
if __name__=="__main__":
    N,start = list(map(int, input().split()))
    x = list(map(int, input().split()))
    solve()

Submission status: Wrong Answer

Solution code:
n, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
def euclid(a,b):
    if a % b == 0:
        return b
    else:
        return euclid(b, a%b)

now = abs(x[0] -x[1])
for i in range(1, len(x)-2):
    r = euclid(now, abs(x[i] - x[i+1]))
    if r < now:
        now = r
print(now)

Submission status: Wrong Answer

Solution code:
def gcd(p,q):
    if p%q==0: return q
    else: return gcd(q,p%q)
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
ans = a[1]-a[0]
for i in range(2,n+1):
    tmp = a[i]-a[i-1]
    ans = max(ans,gcd(ans,tmp))
print(ans)

Submission status: Wrong Answer

Solution code:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

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

    min_num = 10**9
    for i in range(n):
        if abs(x_list[i]-x) <= min_num:
            min_num = abs(x_list[i]-x)

    print(min_num)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc109/tasks/abc109_c
# Xを中心にしたときの最大公約数かな
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


from functools import reduce
from math import gcd

N, zero = ints()
X = [x - zero for x in ints()]
print(reduce(gcd, X))

Submission status: Wrong Answer

Solution code:
from math import gcd
N,X = map(int,input().split())
g = None
for x in map(int,input().split()):
    if g == None:
        g = x-X
    else:
        g = gcd(g,x-X)
print(g)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

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

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

if len(x) == 1:
    print(int(*x)-X)
else:
    res = [abs(x[i+1]-x[i]) for i in range(len(x)-1)]
    print(gcd(*res))

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

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

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

if len(x) == 1:
    print(int(*x)-X)
else:
    res = [x[i+1]-x[i] for i in range(len(x)-1)]
    print(gcd(*res))

Submission status: Wrong Answer

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


if __name__ == '__main__':
    n, x = map(int, input().split())
    X = list(map(int, input().split()))

    X = sorted(X)

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

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

    ans = 0
    if (len(diff) == 1):
        print(diff[0])
        exit()
    else:
        ans = gcd(diff[0], diff[1])
        for i in range(2, len(diff)):
            ans = gcd(ans, diff[i])

        print(ans)

Submission status: Wrong Answer

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


if __name__ == '__main__':
    n, x = map(int, input().split())
    X = list(map(int, input().split()))

    X = sorted(X)

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

    diff = []
    for i in range(n-1):
        diff.append(X[i+1]-X[i])

    ans = 0
    if (len(diff) == 1):
        print(diff[0])
        exit()
    else:
        ans = gcd(diff[0], diff[1])
        for i in range(2, len(diff)):
            ans = gcd(ans, diff[i])

        print(ans)

Submission status: Wrong Answer

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


def main():
    n, s = map(int, input().split())
    xs = sorted(list(map(int, input().split())))

    for i, x in enumerate(xs):
        if i == 0:
            ans = x-s
        else:
            ans = gcd(ans, x-s)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

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

N,X=map(int,input().split())
A=list(map(int,input().split()))
A.append(X)
A=sorted(A)
if N==1:
  print(A[1]-A[0])
else:
  B=[A[i]-A[i-1] for i in range(1,N)]
  print(gcd(*B))

Submission status: Wrong Answer

Solution code:
import math

n, x = map(int, input().split())
X = sorted(list(map(int, input().split())))
dis = [0] * (n-1)

xdis = 0
for i in range(n-1):
    dis[i] = X[i+1] - X[i]
    if X[i] <= x <= X[i+1]:
        xdis = min(abs(x-X[i]), abs(X[i+1]-x))

if n == 1:
    print(X[0]-x)
    exit()
        
reg = xdis

for i in range(n-1):
    reg = math.gcd(reg, dis[i])

print(reg)

Submission status: Wrong Answer

Solution code:
import math

n, x = map(int, input().split())
X = sorted(list(map(int, input().split())))
dis = [0] * (n-1)

xdis = 0
for i in range(n-1):
    dis[i] = X[i+1] - X[i]
    if X[i] <= x <= X[i+1]:
        xdis = min(abs(x-X[i]), abs(X[i+1]-x))

if n == 1:
    print(X[0]-x)
        
reg = xdis

for i in range(n-1):
    reg = math.gcd(reg, dis[i])

print(reg)

Submission status: Wrong Answer

Solution code:
import math

n, x = map(int, input().split())
X = sorted(list(map(int, input().split())))
dis = [0] * (n-1)

xdis = 0
for i in range(n-1):
    dis[i] = X[i+1] - X[i]
    if X[i] <= x <= X[i+1]:
        xdis = min(abs(x-X[i]), abs(X[i+1]-x))

if n == 1:
    print(X[0]-x)
    exit()        
if xdis == 0:
    reg = dis[0]
else:
    reg = xdis

for i in range(n-1):
    reg = math.gcd(reg, dis[0])

print(reg)

Submission status: Wrong Answer

Solution code:
from fractions import gcd


def main():
    n, s = map(int, input().split())
    xs = sorted(list(map(int, input().split())))

    for i, x in enumerate(xs):
        if i == 0:
            ans = x-s
        else:
            ans = gcd(ans, x-s)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, s = map(int, input().split())
    xs = sorted(list(map(int, input().split())))

    ans = float("inf")
    for x in xs:
        if x - s > 0:
            ans = min(ans, x-s)
        if s - x > 0:
            ans = min(ans, s-x)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import math
from functools import reduce


def read():
    N, X = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    return N, X, A


def solve(N, X, A):
    A = [a-X for a in A]
    ans = reduce(math.gcd, A)
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
c=list(map(int,input().split()))
d=[]
for i in c:
    d.append(abs(b-i))
print(min(d))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
m = 10**9
for i in range(N):
    m = min(m, x[i+1]-x[i])
print(m)

Submission status: Wrong Answer

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

def gcd(*nums):
    return reduce(math.gcd,nums)
n,x = [int(i) for i in input().split()]
X =  np.array([int(i) for i in input().split()])

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

ans = int(gcd(*X))
print(ans)

Submission status: Wrong Answer

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

x = list(map(int,input().split()))
st = []
x.append(X)

x.sort()

gcd = x[0]

for i in range(N):
    gcd = fractions.gcd(gcd,x[i+1]-x[i])
    st.append(x[i+1]-x[i])
st.sort()
for v in st:
    if not v % gcd:
        print(v)
        break

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
l=list(map(int,input().split()))
minl=[]
for i in range(1,n):
    if x>l[i-1] and x<l[i]:
        minl.append(min(abs(x-l[i-1]),abs(l[i]-x)))
    else:
        minl.append(abs(l[i]-l[i-1]))
if n==1:
    print(l[0]-x)
else:
    print(min(minl))

Submission status: Wrong Answer

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

n, x = map(int,input().split())
arr = list(map(int,input().split()))
diff = []
arr.sort()
g = 0
for i in range(n-1):
    diff.append(abs(arr[i]-arr[i+1]))
for item in diff:
    g = gcd(g,item)
print(g)

Submission status: Wrong Answer

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

n, x = map(int,input().split())
arr = list(map(int,input().split()))
diff = []
g = 0
for i in range(n-1):
    diff.append(abs(arr[i]-arr[i+1]))
for item in diff:
    g = gcd(g,item)
print(g)

Submission status: Wrong Answer

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

n, x = map(int,input().split())
arr = list(map(int,input().split()))
diff = []
if n==1:
    print(arr[0]-x)
elif n==2:
    print(abs(arr[1]-arr[0]))
else:
    for i in range(n-1):
        diff.append(abs(arr[i]-arr[i+1]))
    for i in range(n-2):
        g = gcd(diff[i],diff[i+1])
    print(g)

Submission status: Wrong Answer

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

n, x = map(int,input().split())
arr = list(map(int,input().split()))
diff = []
if n==1:
    print(arr[0]-x)
elif n==2:
    first = abs(x-arr[0])
    second = abs(arr[1]-x)
    print(gcd(first,second))
else:
    for i in range(n-1):
        diff.append(abs(arr[i]-arr[i+1]))
    for i in range(n-2):
        g = gcd(diff[i],diff[i+1])
    print(g)

Submission status: Wrong Answer

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

n, x = map(int,input().split())
arr = list(map(int,input().split()))
diff = []
if n==1:
    print(arr[0])
elif n==2:
    first = abs(x-arr[0])
    second = abs(arr[1]-x)
    print(gcd(first,second))
else:
    for i in range(n-1):
        diff.append(abs(arr[i]-arr[i+1]))
    for i in range(n-2):
        g = gcd(diff[i],diff[i+1])
    print(g)

Submission status: Wrong Answer

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