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: Runtime Error

Solution code:
import math
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.append(x)
a.sort()
t = 0
for i in range(n):
    if i == 0:
        t = a[1] - a[0]
    else:
        t = math.gcd(t, a[i + 1] - a[i])
print(t)

Submission status: Runtime Error

Solution code:
import functools
import math
N,X=map(int,input().split())
x=list(map(int,input().split()))
def minus(n):
  return n-X
x=list(map(minus, x)) 
gcd = functools.reduce(math.gcd, x)
print(gcd)

Submission status: Runtime Error

Solution code:
import math
import functools
n,x=map(int,input().split())
xl=list(map(int,input().split()))
a=[]
for i in range(n):
    a.append(abs(xl[i]-x))
ans=functools.reduce(math.gcd,a)
print(ans)

Submission status: Runtime Error

Solution code:
import math

n, x0 = map(int, input().split())
x = list(map(int, input().split())) + [x0]

x = list(set(x))
x.sort()
if len(x) >= 3:
    diff_x = [x[i+1] - x[i] for i in range(n-1)]
    ans = diff_x[0]
    for dx in diff_x[1:]:
        ans = math.gcd(ans, dx)
else:
    ans = x[1] - x[0]

print(ans)

Submission status: Runtime Error

Solution code:
import math


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

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

dist_list = [abs(X - e) for e in x]
ans = dist_list[0]
for e in dist_list:
    ans = math.gcd(e, ans)


print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
    
x.append(X)
x.sort()
y=[]

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

Submission status: Runtime Error

Solution code:
import math

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

ans = None
for a in A:
    x = abs(a - X)
    if ans is None:
        ans = x
    else:
        ans = math.gcd(ans, x)

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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

A = sorted(list(map(int,input().split()))+[X])

B = []
for i in range(len(A)-1):
    B.append(A[i+1]-A[i])

G = B[0]
if G>1:
    for b in B[1:]:
        G = gcd(G,b)
        if G==1:break
            
print(G)

Submission status: Runtime Error

Solution code:
import fraction

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

x_sorted = sorted(x_list)

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

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

print(result)

Submission status: Runtime Error

Solution code:
import math
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.append(x)
a.sort()
for i in range(n):
    if i == 0:
        t = a[1] - a[0]
    else:
        t = math.gcd(t, a[i + 1] - a[i])
print(t)

Submission status: Runtime Error

Solution code:
import math


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

y = [abs(xi - X) for xi in x]
r = y[0]

for i in range(N-1):
    r = math.gcd(r, y[i+1])

print(r)

Submission status: Runtime Error

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

#input = __import__('sys').stdin.readline
N, X = map(int, input().split())
l = [*map(int, input().split())]
res = -1

for i in range(N):
    d = abs(l[i] - X)
    
    if res == -1:
        res = d
    else:
        res = gcd(res, d)

print(res)

Submission status: Runtime Error

Solution code:
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
L = []
if (len(x) == 1):
  print(abs(X-x[0]))
else:
  for k in range(len(x)):
    L.append(abs(X-x[k]))
    L.sort()
print(L[0])

Submission status: Runtime Error

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

input = __import__('sys').stdin.readline
N, X = map(int, input().split())
l = [*map(int, input().split())]
res = -1

for i in range(N):
    d = abs(l[i] - X)
    
    if res == -1:
        res = d
    else:
        res = gcd(res, d)

print(res)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


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


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

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

dist_list = [abs(X - e) for e in x]

print(gcd_list(dist_list))

Submission status: Runtime Error

Solution code:
import math

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

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import fractions

n,x= list(map(int,input().split()))	
a= [int(i)-x for i in input().split()]

ans=a[1]
for i in range(n):
    ans = fractions.gcd(ans,a[i])

print(abs(ans))

Submission status: Runtime Error

Solution code:
from math import gcd

input = __import__('sys').stdin.readline
N, X = map(int, input().split())
l = [*map(int, input().split())]
res = -1

for i in range(N):
    d = abs(l[i] - X)
    
    if res == -1:
        res = d
    else:
        res = gcd(res, d)

print(res)

Submission status: Runtime Error

Solution code:
import fractions
n,x = map(int, input().split())
lis = [int(i) for i in input().split()]
lis2 = []
for nums in lis:
  lis2.append(abs(nums-x))
ans = 10000000000000
if n == 1:
  ans = lis2[0]
else:
  i = 2
  g = fractions.gcd(lis2[0],lis2[1])
  while i < n:
    g = fractions.gcd(g,lis2[i])
    i += 1
print(g)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

Submission status: Runtime Error

Solution code:
import math

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

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

print(t)

Submission status: Runtime Error

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

x = sorted(x+[X])
# print(x)
x_diff = [x[i+1]-x[i] for i in range(n)]
ans = x_diff[0]
for i in range(1, len(x_diff)):
    ans = math.gcd(ans, x_diff[i])
print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

d = np.zeros(N, dtype=int)
for n in range(N):
    d[n] = x[n] - X

gcd = reduce(math.gcd, d)

# print(d)
print(gcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

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

if len(dif) != 1:
    print(gcd_list(dif))
else:
    print(dif[0])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

if len(xs) > 1:
    m = min(xs)
    xs = [n - m for n in xs]

print(reduce(math.gcd, xs))

Submission status: Runtime Error

Solution code:
'''input
3 81
33 105 57
'''
from fractions import gcd
n,x = map(int,raw_input().split())
arr = map(int,raw_input().split())
arr.append(x)
arr.sort()
diff = []
for i in range(1,n):
	diff.append(arr[i]-arr[i-1])
gc = diff[0]
for i in range(1,len(diff)):
	gc = gcd(gc,diff[i])
print gc

Submission status: Runtime Error

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


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

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

print(ans)

Submission status: Runtime Error

Solution code:
import functools
import math
import fraction
n,x = map(int,input().split())
values = list(map(int,input().split()))
for i in range(n):
    values[i] = abs(values[i]-x)
gcd = functools.reduce(fraction.gcd, values)
print(gcd)

Submission status: Runtime Error

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

import array
from bisect import *
from collections import *
from functools import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys
from math import gcd

N, X = map(int, input().split())
Xs = map(int, input().split())
diffs = [abs(X - x) for x in Xs]
ans = reduce(gcd, diffs)
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from math import gcd
n,x = map(int, input().split())
ary = [abs(x-int(i)) for i in input().split()]

d = ary[0]
for i in ary[1:]:
    d = gcd(i,d)

print(d)

Submission status: Runtime Error

Solution code:
import functools
import math
n,x = map(int,input().split())
values = list(map(int,input().split()))
for i in range(n):
    values[i] = abs(values[i]-x)
gcd = functools.reduce(math.gcd, values)
print(gcd)