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:
import math
N, X = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
x.append(X)
x.sort()

xdst = [x[i+1] - x[i] for i in range(N)]
print(xdst)

ans = 10**10
if len(xdst) == 1:
    #print(xdst[0])
    exit()

for i in range(N-1):
    ans = min(math.gcd(xdst[i], xdst[i+1]),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int, input().split())
x_list=[int(i) for i in input().split()]

x_list.append(x)
x_list.sort()
sa=[]
for i in range(n):
    sa.append(x_list[i+1]-x_list[i])
    
print(min(sa))

Submission status: Wrong Answer

Solution code:
from math import gcd
n, x = map(int, input().split())
ls = sorted(list(map(int, input().split())))
if x == 1:
    print(abs(x-ls[0]))
    exit()
distant = []
for i in range(n):
    diff = abs(ls[i]-x)
    distant.append(diff)
distant.sort()
a = distant[0]
for i in distant:
    g = gcd(a, i)
print(g)

Submission status: Wrong Answer

Solution code:
import math
d=10**5+1
n,x=map(int, input().split())
a=[int(x) for x in input().split()]
a.append(x)
a.sort()

for i in range(n-1):
    D=math.gcd(a[i+1]-a[i],a[i+2]-a[i])
    if D<d:
        d=D

if x==1:
    d=abs(a[1]-a[0])
        
print(d)

Submission status: Wrong Answer

Solution code:
from math import gcd

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

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
xlist= list(map(int,input().split()))
if n == 1:
  print(abs(xlist[0]-x))
  exit()
ylist = []
for i in range(n-1):
  ylist.append(abs(xlist[i]-x))
from functools import reduce
from math import gcd
print(reduce(gcd,ylist))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
xlist= list(map(int,input().split()))
if n == 1:
  print(abs(xlist[0]-x))
  exit()
ylist = []
for i in range(n-1):
  ylist.append(xlist[i]-x)
from functools import reduce
from math import gcd
print(reduce(gcd,ylist))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

x.append(X)
num_list = sorted(x)

D = min(map(lambda x: abs(x[0] - x[1]), zip(num_list[:-1],num_list[1:])))
print(D)

Submission status: Wrong Answer

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

diff_list = map(lambda y: abs(y - X), x)
max_num = min(diff_list)

for i in range(max_num , 0, -1):
    if all(map(lambda y: y % i == 0, diff_list)):
        ans = i
        break

print(ans)

Submission status: Wrong Answer

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

print(min(map(lambda y: abs(y - X), x)))

Submission status: Wrong Answer

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

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

ans=0
for x in x_list:
  ans=gcd(ans, x)
print(ans)

Submission status: Wrong Answer

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

    minimum = abs(x_lst[0] - x)
    for i in range(n):
        distance1 = abs(x_lst[i] - x)
        minimum = min(minimum, distance1)

        if i != n - 1:
            distance2 = abs(x_lst[i + 1] - x_lst[i])
            minimum = min(minimum, distance2)

    print(minimum)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    minimum = abs(x_lst[0] - x)
    for i in range(n):
        distance1 = abs(x_lst[i] - x)
        minimum = min(minimum, distance1)

        if i != n - 1:
            distance2 = abs(x_lst[i + 1] - x_lst[i])
            minimum = min(minimum, distance2)

    print(minimum)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    minimum = abs(x_lst[0] - x)
    for i in range(n):
        distance = abs(x_lst[i] - x)
        minimum = min(minimum, distance)

    print(minimum)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def resolve():
    _, X = [int(i) for i in input().split()]
    xx = [int(i) for i in input().split()]
    ans = float("inf")
    for x in xx:
        ans = min(ans, abs(X - x))
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
import math
a=list(map(int,input().split()))
a.append(X)
a.sort()
S=[]
for i in range(N):
    S.append(a[i+1]-a[i])

    
ans=S[0]
for j in range(1,N):
    math.gcd(ans,S[j])
    
print(ans)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
import math
a=list(map(int,input().split()))
a.append(X)
a.sort()
S=[]
for i in range(N):
    S.append(a[i+1]-a[i])
    
ans=S[0]
for j in range(1,N):
    math.gcd(ans,S[j])

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()
d = float("inf")
for i in range(N):
    d = min(d,abs(x[i]-x[i+1]))
print(d)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
x=sorted(list(map(int,input().split())))
ans=min(abs(X-x[0]),abs(X-x[-1]))
print(ans)

Submission status: Wrong Answer

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

x_s.append(x)
x_s.sort()
sub = []
for i in range(n):
    sub.append(x_s[i+1]-x_s[i])

print(min(sub))

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())
x = [int(_)-X for _ in input().split()]
print(gcd_list(x))

Submission status: Wrong Answer

Solution code:
#36 C - Skip
import bisect
import collections
N,X = map(int,input().split())
x = list(map(int,input().split()))
x = sorted(x,reverse = False)

# 間隔の最小の素数 or 1
d_lis = []
for i in range(len(x)):
    d = abs(x[i] - X)
    d_lis.append(d)

d_lis = sorted(d_lis,reverse = False)
cnt = collections.Counter(d_lis)
m = max(d_lis)+1

for j in d_lis:
    for k in range(j*2,m,j):
        del cnt[k]
    if len(cnt) == 1:
        break
if len(cnt) == 1:
    ans = cnt.keys()
    print(*ans)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
#36 C - Skip
import bisect
import collections
N,X = map(int,input().split())
x = list(map(int,input().split()))
x = sorted(x,reverse = False)

bisect.insort_left(x,X)

# 間隔の最小の素数 or 1
d_lis = []
for i in range(len(x)-1):
    d = x[i+1] - x[i]
    d_lis.append(d)

d_lis = sorted(d_lis,reverse = False)
cnt = collections.Counter(d_lis)
m = max(d_lis)+1

for j in d_lis:
    for k in range(j*2,m,j):
        del cnt[k]
    if len(cnt) == 1:
        break
if len(cnt) == 1:
    ans = cnt.keys()
    print(*ans)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
#36 C - Skip
import bisect
N,X = map(int,input().split())
x = list(map(int,input().split()))
x = sorted(x,reverse = False)

bisect.insort_left(x,X)

# 間隔の最小値が最大の D
md = 10**9+1
for i in range(len(x)-1):
    d = x[i+1] - x[i]
    md = min(md,d)
print(md)

Submission status: Wrong Answer

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


n, k = map(int, input().split())
a = list(map(int, input().split()))
a.append(k)
a.sort()
d = [0] * (n)
for i in range(n):
    d[i] = a[i + 1] - a[i]

ans = d[0]
for j in range(1, len(d)):
    ans = gcd(ans, d[i])

print(ans)

Submission status: Wrong Answer

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


n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if n > 1:
    d = [0] * (n - 1)

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

    ans = d[0]
    for j in range(1, len(d)):
        ans = gcd(ans, d[i])

else:
    ans = abs(a[0] - k)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

def gcd(list):
  return reduce(math.gcd, list)

n, x = map(int, input().split())
a = map(lambda b: int(b) - x, input().split())
print(gcd(a))

Submission status: Wrong Answer

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

if len(x)>=3:
    ans = math.gcd(abs(x[0]-X),abs(x[1]-X))

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

Submission status: Wrong Answer

Solution code:
import math
N,X = map(int,input().split())
x = list(map(int,input().split()))
ans = 0
if len(x)>=2:
    ans = math.gcd(abs(x[0]-X),abs(x[1]-X))

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

Submission status: Wrong Answer

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

print(math.gcd(abs(min(x)-X),abs(max(x)-X)))

Submission status: Wrong Answer

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

print(math.gcd(min(x)-X,max(x)-X))

Submission status: Wrong Answer

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

# from fractions import gcd
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

from functools import reduce

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

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

if N != 1:
    ret = []
    x.append(X)
    now = x[0]

    for i in x[1:]:
        ret += [i - now]
        now = i

    ret = sorted(ret)

    print(gcd_list(ret))

else:
    print(x[0] - X)

Submission status: Wrong Answer

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

# from fractions import gcd
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

from functools import reduce

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

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

ret = []
x.append(X)
now = x[0]

for i in x[1:]:
    ret += [i - now]
    now = i

ret = sorted(ret)

print(gcd_list(ret))

Submission status: Wrong Answer

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

# from fractions import gcd
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

from functools import reduce

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

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

if N != 1:
    ret = []
    now = x[0]
    for i in x[1:]:
        ret += [i - now]
        now = i

    ret = sorted(ret)
    print(gcd_list(ret))

else:
    print(x[0] - X)

Submission status: Wrong Answer

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

x.append(X)
from math import gcd
g = x[1] - x[0]
for i in range(N-1):
    g = gcd(g, (x[i+1] - x[i]))

print(abs(g))

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
    
a = [int(s) for s in input().split()]
N = a[0]
st = a[1]
mini = int(-1)
b = [int(s) for s in input().split()]

for i in range(N):
    if abs(b[i] - st) < mini or mini == -1:
        mini = abs(b[i] - st)

yakulist = make_divisors(mini)
gyakulist = sorted(yakulist, reverse=True)
kazu = len(gyakulist)
flag = int(0)

for i in range(kazu):
    for j in range(N):
        if abs(b[j] - st) % gyakulist[i] != 0:
            flag = 1
        else:
            pass
    if flag == 0:
        print(gyakulist[i])
        break

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
    
a = [int(s) for s in input().split()]
N = a[0]
st = a[1]
mini = int(-1)
b = [int(s) for s in input().split()]

for i in range(N):
    if abs(b[i] - st) < mini or mini == -1:
        mini = abs(b[i] - st)

yakulist = make_divisors(mini)
gyakulist = sorted(yakulist, reverse=True)
kazu = len(gyakulist)
print(kazu)
flag = int(0)

for i in range(kazu):
    for j in range(N):
        if abs(b[j] - st) % gyakulist[i] != 0:
            flag = 1
        else:
            pass
    if flag == 0:
        print(gyakulist[i])
        break

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
    
a = [int(s) for s in input().split()]
N = a[0]
st = a[1]
mini = int(100000000000)
b = [int(s) for s in input().split()]

for i in range(N):
    if abs(b[i] - st) < mini:
        mini = abs(b[i] - st)

yakulist = make_divisors(mini)
gyakulist = sorted(yakulist, reverse=True)
kazu = len(gyakulist)
flag = int(0)

for i in range(kazu):
    for j in range(N):
        if abs(b[j] - st) % gyakulist[i] != 0:
            flag = 1
        else:
            pass
    if flag == 0:
        print(gyakulist[i])
        break

Submission status: Wrong Answer

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

x.sort()
idx = 0
if N == 1:
  print(abs(x[0]-X))
else:
  min_diff = x[-1]
  for i in range(N-1):
    min_diff = min(min_diff, x[i+1]-x[i])
  for i in range(0,N-1):
    if x[i] <= X <= x[i+1]:
      idx = i
      break
  if (X - x[idx]) == (x[idx+1] - X):
    print(min(x[idx+1]-X, min_diff))
  else:
    print(min(abs((X - x[idx])-(x[idx+1] - X)), min_diff))

Submission status: Wrong Answer

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

x.sort()
idx = 0
if N == 1:
  print(abs(x[0]-X))
else:
  for i in range(0,N-1):
    if x[i] <= X <= x[i+1]:
      idx = i
      break
  if (X - x[idx]) == (x[idx+1] - X):
    print(x[idx+1]-X)
  else:
    print(abs((X - x[idx])-(x[idx+1] - X)))

Submission status: Wrong Answer

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

x.sort()
min_dist = x[-1]
for i in range(N):
  if min_dist < abs(X-x[i]):
    break
  else:
    min_dist = abs(X-x[i])
if N == 1:
  print(min_dist)
else:
  if min_dist > x[1]-x[0]:
    print(x[1]-x[0])
  else:
    print(min_dist)

Submission status: Wrong Answer

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

x.sort()
min_dist = x[-1]
for i in range(N):
  if min_dist < abs(X-x[i]):
    break
  else:
    min_dist = abs(X-x[i])
print(min_dist)

Submission status: Wrong Answer

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

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

else:
  l=[]
  for i in range(N-1):
    l_=abs(x[i+1]-x[i])
    l.append(l_)
  #print(l)
  ans=l[0]
  for i in range(1,len(l)):
    ans=gcd(ans,l[i])

  print(ans)

Submission status: Wrong Answer

Solution code:
import sys 

def chk(L):
    mi=1001001001
    for i in range(0,len(L)-1):
        mi=min(mi,L[i+1]-L[i])
    for i in range(mi,1,-1):
        flag=True
        for j in range(1, n):
            if (L[j]-L[j-1])%i!=0:
                flag=False
                break;
        if flag: return i
    return 1

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

INF=-10
xidx=INF
m=1
for i in range(0,n):
    if X[i]>x: 
        xidx=i-1
        break
if xidx==-1:
    X.insert(0,x)
    m=max(m,chk(X))
elif xidx==INF:
    X.insert(n,x)
    m=max(m,chk(X))
else:
    for j in range(0,2):
        #go right
        if i==0:
            NX=X
            NX.insert(n,max(X)+x)
            m=max(m,chk(NX))
        #go left
        else:
            X.insert(0,min(X)-abs(min(X)-x))
            m=max(m,chk(X))
print (m)

Submission status: Wrong Answer

Solution code:
import sys 

def chk(L):
    mi=1001001001
    for i in range(0,len(L)-1):
        mi=min(mi,L[i+1]-L[i])
    for i in range(mi,1,-1):
        flag=True
        for j in range(1, n-1):
            if (L[j]-L[j-1])%i!=0:
                flag=False
                break;
        if flag: return i
    return 1

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

INF=-10
xidx=INF
m=1
for i in range(0,n):
    if X[i]>x: 
        xidx=i-1
        break
if xidx==-1:
    X.insert(0,x)
    m=max(m,chk(X))
elif xidx==INF:
    X.insert(n,x)
    m=max(m,chk(X))
else:
    for j in range(0,2):
        #go right
        if i==0:
            NX=X
            NX.insert(n,max(X)+x)
            m=max(m,chk(NX))
        #go left
        else:
            X.insert(0,min(X)-abs(min(X)-x))
            m=max(m,chk(X))
print (m)

Submission status: Wrong Answer

Solution code:
import sys 

def chk(L):
    mi=1001001001
    for i in range(0,len(L)-1):
        mi=min(mi,L[i+1]-L[i])
    for i in range(mi,1,-1):
        flag=True
        for j in range(1, n-1):
            if (L[j]-L[j-1])%i!=0:
                flag=False
                break;
        if flag: return i
    return 0

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

INF=-10
xidx=INF
m=1
for i in range(0,n):
    if X[i]>x: 
        xidx=i-1
        break
if xidx==-1:
    X.insert(0,x)
    m=max(m,chk(X))
elif xidx==INF:
    X.insert(n,x)
    m=max(m,chk(X))
else:
    for j in range(0,2):
        #go right
        if i==0:
            NX=X
            NX.insert(n,max(X)+x)
            m=max(m,chk(NX))
        #go left
        else:
            X.insert(0,min(X)-abs(min(X)-x))
            m=max(m,chk(X))
print (m)

Submission status: Wrong Answer

Solution code:
import sys 

def chk(L):
    mi=1001001001
    for i in range(0,len(L)-1):
        mi=min(mi,L[i+1]-L[i])
    for i in range(mi,1,-1):
        flag=True
        for j in range(1, n-1):
            if (L[j]-L[j-1])%i!=0:
                flag=False
                break;
        if flag: return i
    return 0

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

INF=-10
xidx=INF
m=1
for i in range(0,n):
    if X[i]>x: 
        xidx=i-1
if xidx==-1:
    X.insert(0,x)
    m=max(m,chk(X))
elif xidx==INF:
    X.insert(n,x)
    m=max(m,chk(X))
else:
    for j in range(0,2):
        #go right
        if i==0:
            NX=X
            NX.insert(n,max(X)+x)
            m=max(m,chk(NX))
        #go left
        else:
            X.insert(0,min(X)-abs(min(X)-x))
            m=max(m,chk(X))
print (m)

Submission status: Wrong Answer

Solution code:
#xi-xが全部Dの倍数になればいい
n,x=list(map(int, input().split()))
pos = list(map(int, input().split()))
diff_pos = [abs(s-x) for s in pos]
min_diff = min(diff_pos)
#print(min_diff)
ans = 0
for i in range(1,min_diff+1):
    for n in diff_pos:
        if n % i != 0:
            break
    ans = i
    #print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
n, x = map(int, input().split())
m = [x]+list(map(int, input().split()))


m.sort()

if n==1:
  print(m[1]-x)
else:
  res = gcd(m[1]-m[0], m[2]-m[1])
  for i in range(2, n-1):
    a = m[i+1]-m[i]
    b = m[i+2]-m[i+1]
    if res >= gcd(a,b):
      if res%gcd(a,b)==0:
        res = gcd(a,b)
      else:
        res = gcd(res, gcd(a, b))
    else:
      if gcd(a,b)%res!=0:
        res = gcd(res, gcd(a, b))
  print(res)

Submission status: Wrong Answer

Solution code:
from math import gcd
n, x = map(int, input().split())
m = [x]+list(map(int, input().split()))


m.sort()
res = m[1]-m[0]
if n==1:
  print(m[1]-x)
else:
  for i in range(1, n-1):
    a = m[i+1]-m[i]
    b = m[i+2]-m[i+1]
    if res >= gcd(a,b):
      if res%gcd(a,b)==0:
        res = gcd(a,b)
      else:
        res = gcd(res, gcd(a, b))
    else:
      if gcd(a,b)%res!=0:
        res = gcd(res, gcd(a, b))
  print(res)

Submission status: Wrong Answer

Solution code:
from math import gcd
n, x = map(int, input().split())
m = [x]+list(map(int, input().split()))

res = float('inf')
m.sort()
if n==1:
  print(m[1]-x)
else:
  for i in range(n-1):
    a = m[i+1]-m[i]
    b = m[i+2]-m[i+1]
    res = min(res, gcd(a, b))
  print(res)

Submission status: Wrong Answer

Solution code:
import math

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

absx = [abs(X - xx) for xx in x]
absx.sort()

divx0 = []

for i in range(math.ceil(math.sqrt(absx[0])), 0, -1):
    if absx[0] % i == 0:
        divx0.append(i)

t = []
for x in divx0:
    t.append(x)
    t.append(absx[0] // x)

divx0 = t

for dx0 in divx0:
    isok = True
    for xx in absx:
        if xx % dx0 != 0:
            isok = False
            break

    if isok:
        print(dx0)
        exit()

Submission status: Wrong Answer

Solution code:
import math

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

absx = [abs(X - xx) for xx in x]
absx.sort()

divx0 = [absx[0]]

for i in range(math.ceil(math.sqrt(absx[0])), 0, -1):
    if absx[0] % i == 0:
        divx0.append(i)

for dx0 in divx0:
    isok = True
    for xx in absx:
        if xx % dx0 != 0:
            isok = False
            break

    if isok:
        print(dx0)
        exit()

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = [y - X for y in x]
print(reduce(math.gcd, x))

Submission status: Wrong Answer

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n,s = MI()
x = RI()

l = []
for i in range(n):
    l.append(abs(x[i]-s))
ans = min(l)
print(ans)

Submission status: Wrong Answer

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

t=[c-X for c in C]

import math
from functools import reduce
print(reduce(math.gcd, t))

Submission status: Wrong Answer

Solution code:
f=lambda:[*map(int,input().split())]
n,x=f()
l=f()
d=[l[i+1]-l[i] for i in range(n-1)]
a=x-l[0]
from math import *
for i in d:
  a=gcd(a,i)
print(a)

Submission status: Wrong Answer

Solution code:
import math

n, x = map(int, input().split(" "))
xL = sorted(list(map(int, input().split(" "))) + [x])

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

ans = diff[0]
for d in diff:
    ans = max(math.gcd(diff[0], d), ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import math

n, x = map(int, input().split(" "))
xL = sorted(list(map(int, input().split(" "))) + [x])

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

ans = 0
for d in diff:
    ans = max(math.gcd(diff[0], d), ans)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[]
if n==1 and x==a[0]:
    print(max(x,10**9-x))
    exit()
for i in range(n):
    b.append(abs(a[i]-x))
print(b)
import math
c=0
for i in range(n):
    c=math.gcd(c,b[i])
    if c==1:
        break
print(c)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[]
if n==1 and x==a[0]:
    print(max(x,10**9-x))
    exit()
for i in range(n):
    b.append(abs(a[i]-x))
import math
for i in range(n):
    c=0
    c=math.gcd(c,b[i])
    if c==1:
        break
print(c)

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(abs(a[i]-x))
import math
for i in range(n):
    c=b[0]
    c=math.gcd(c,b[i])
    if c==1:
        break
print(c)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
ans = float("INF")
for ai in a:
    ans = min(ans,abs(ai-x))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, x = inintm()
X = inintl()

if x not in X:
    X.append(x)
    n += 1

X.sort()

ans = 0
prev = X[0]

for i in range(1,n):
    ans = max(math.gcd(ans, X[i]-prev), ans)
    prev = 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()
a=x[1]-x[0]
for i in range(1, n):
  a = math.gcd(a, x[i]-x[i-1])
print(a)

Submission status: Wrong Answer

Solution code:
import sys
from math import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, x, *X = map(int, read().split())

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

x.sort()

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
import math
from functools import reduce


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))

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



def main():
    n, x = nm()
    X = nl()
    X.append(x)
    ans = gcd_list(X)
    print(ans)



if __name__ == '__main__':
    main()