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: Accepted

Solution code:
from functools import reduce
import math
def main():
    n, s = map(int, input().split())
    X = list(map(lambda x:abs(int(x) - s), input().split()))
    ans = reduce(lambda x, y :math.gcd(x, y), X, X[0])
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

nlis = []

for i in range(n):
    nlis.append(abs(lis[i]- x))

ans = nlis[0]

for j in range(1, n):
    ans = math.gcd(ans, nlis[j])

print(ans)

Submission status: Accepted

Solution code:
import math

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

if len(X_lst) == 1:
    print(abs(X_lst[0] - X))
    exit()

u = 0
if X_lst[0] == X:
    u = float('inf')

for i, x in enumerate(X_lst[1:], start=1):
    if x == X:
        u = float('inf')

    if X_lst[i - 1] < X < x:
        u = [X - X_lst[-1], x - X]

    if i == 1:
        g = X_lst[1] - X_lst[0]
    else:
        g = math.gcd(g, x - X_lst[i - 1])


if u == 0:
    u = [X - X_lst[-1]]
elif u != float('inf'):
    g = max(math.gcd(g, u[0]), math.gcd(g, u[1]))

print(g)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

def gcd(a,b):
    return math.gcd(a,b)

if __name__ == "__main__":
    n,x = I2()
    a = Intl()
    ans = abs(a[0]-x)
    for i in range(1,n):
        ans = gcd(ans,abs(a[i]-x))
    print(ans)

Submission status: Accepted

Solution code:
import math
n, x = [int(w) for w in input().split()]
la = [int(w) for w in input().split()]+[x]
la.sort()
if la[0] < 0:
    m = la[0]
    la = [w+m for w in la]

diff = [0]*n
for i in range(n):
    diff[i] = la[i+1]-la[i]
g = diff[0]
for i in diff[1:]:
    g = math.gcd(g, i)

print(g)

Submission status: Accepted

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

import math
from functools import reduce

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

A=[]
for num in x:
    A.append(abs(num-X))

print(gcd_list(A))

Submission status: Accepted

Solution code:
# abc109_c.py
# https://atcoder.jp/contests/abc109/tasks/abc109_c

# C - Skip /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 数直線上に N個の都市があり、i 番目の都市は座標 xiにあります。
# あなたの目的は、これら全ての都市を 1度以上訪れることです。
# あなたは、はじめに正整数 Dを設定します。
# その後、あなたは座標 Xから出発し、以下の移動 1、移動 2を好きなだけ行います。
#     移動 1: 座標 y から座標 y+Dに移動する
#     移動 2: 座標 y から座標 y−Dに移動する
# 全ての都市を 1度以上訪れることのできる Dの最大値を求めてください。
# ここで、都市を訪れるとは、その都市のある座標に移動することです。

# 制約
#     入力はすべて整数である
#     1≤N≤10^5
#     1≤X≤10^9
#     1≤xi≤10^9
#     xiはすべて異なる
#     x1,x2,...,xN≠X

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N X
# x1 x2 ... xN

# 出力
# 全ての都市を 1度以上訪れることのできる Dの最大値を出力せよ。

# 入力例 1
# 3 3
# 1 7 11

# 出力例 1
# 2

# D=2と設定すれば次のように移動を行うことですべての都市を訪れることができ、これが最大です。

#     移動 2を行い、座標 1に移動する
#     移動 1を行い、座標 3に移動する
#     移動 1を行い、座標 5に移動する
#     移動 1を行い、座標 7に移動する
#     移動 1を行い、座標 9に移動する
#     移動 1を行い、座標 11に移動する

# 入力例 2
# 3 81
# 33 105 57

# 出力例 2
# 24

# 入力例 3
# 1 1
# 1000000000

# 出力例 3
# 999999999


def calculation(lines):
    # N = int(lines[0])
    N, X = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    values.append(X)
    mi = min(values)
    # 最小値を起点とする
    values = [value - mi for value in values]

    for _ in range(10):
        # 解の候補として最小値を取得する
        values = [value for value in values if value > 0]
        mi = min(values)
        # 最小値単位のあまりを取得する
        values = list(set([value % mi for value in values]))
        if values == [0]:
            return [mi]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3 3', '1 7 11']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['3 81', '33 105 57']
        lines_export = [24]
    if pattern == 3:
        lines_input = ['1 1', '1000000000']
        lines_export = [999999999]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
N,X = map(int,input().split())
Y = list(map(int,input().split()))
Z = [abs(y-X) for y in Y]
print(np.gcd.reduce(Z))

Submission status: Accepted

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 = [abs(c - x) for c in city]

print(gcd(*distance))

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

print(gcd(xn))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from functools import reduce
from math import gcd

n, X, *x = map(int, open(0).read().split())
x = [abs(i - X) for i in x]
print(reduce(gcd, x))

Submission status: Accepted

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

Submission status: Accepted

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 =abs(x[0] -X)
else:
    ans =gcd_list(x_div)
print(ans)

Submission status: Accepted

Solution code:
from math import gcd
N, X = map(int, input().split())
L = list(map(lambda x: abs(int(x) - X), input().split()))
L.sort()
if N == 1:
  print(L[0])
elif N == 2:
  print(gcd(L[0], L[1]))
else:
  ans = gcd(L[0], L[1])
  for l in L[2:]:
    ans = gcd(ans, l)
  print(ans)

Submission status: Accepted

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

d=reduce(gcd,a)
print(d)

Submission status: Accepted

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

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

x_list.sort()

x_diff = [x_list[i+1]-x_list[i] for i in range(len(x_list)-1)]

# print(x_diff)
A = x_diff

value = A[0]
for i in range(1, len(A)):
    value = math.gcd(value, A[i])
print(value)

Submission status: Accepted

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):
    Mindif = math.gcd(Mindif,x[i+1]-x[i])
print(Mindif)

Submission status: Accepted

Solution code:
import math

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

D = abs(l[0]-X)

for i in range(N):
    D = math.gcd(D,abs(l[i]-X))

print(D)

Submission status: Accepted

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):
    ans = math.gcd(ans, abs(x[i]))
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))
 
N,X=map(int, input().split())
A = list(map(int, input().split()))

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

print(ans)

Submission status: Accepted

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

g=0

for y in a:
  g=math.gcd(g,abs(y-x))
  
print(g)

Submission status: Accepted

Solution code:
import bisect
import math
from functools import reduce

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

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

Submission status: Accepted

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


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


res = abs(X - Y[0])
for i in range(N - 1):
    res = gcd(res, Y[i + 1] - Y[i])
print(res)

Submission status: Accepted

Solution code:
from math import gcd

N,X=map(int,input().split())
L=list(map(lambda x:int(x)-X,input().split()))

a=L[0]
for b in L:
    a=gcd(a,b)
print(a)

Submission status: Accepted

Solution code:
from math import gcd
n,x=map(int,input().split())
c=list(map(int,input().split()))
o=[]
if len(c)==1:
  print(abs(c[0]-x))
else:
  for i in c:
    o.append(abs(i-x))
  ans=gcd(o[1],o[0])
  for j in range(n-2):
      ans=gcd(ans,o[j+2])
  print(ans)

Submission status: Accepted

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

y = sorted(x+[X])
d_y = [y[i]-y[i-1] for i in range(1,N+1)]
import math
from functools import reduce
print( reduce(math.gcd,d_y) )

Submission status: Accepted

Solution code:
import numpy as np
import math

N,X=map(int,input().split())
L=np.array(list(map(int,input().split())))
L=abs(L-X)
ans=L[0]

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
 
def gcd(ns):
    return reduce(math.gcd, ns)
 
N, X = map(int, input().split())
L = list(map(int, input().split()))
 
diff = [abs(x - X) for x in L]
 
if len(diff) == 1:
    print(diff[0])
else:
    print(gcd(diff))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
N, A = map(int, input().split())
X = list(map(int, input().split()))
L = ([abs(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: Accepted

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()))
l.append(x)
l.sort()
l2 = diff(l)
print(multiGCD(l2))

Submission status: Accepted

Solution code:
import math
[n,x] = [int(i) for i in input().split()]
xs = [int(i) for i in input().split()]
if n != 1:
    xs.append(x)
    xs.sort()
    diff = []
    for i in range(1,n+1):
        diff.append(xs[i] - xs[i-1])
    ans = 0
    for i in range(1,len(diff)):
        if i == 1:
            ans = math.gcd(diff[i-1],diff[i])
        else:
            ans = math.gcd(ans,diff[i])
    print(ans)
else:
    print(abs(x - xs[0]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def gcd(l):
    ans = l[0]
    for i in l:  ans = gcd_(ans, i)
    return ans

N, X = list(map(int,input().split()))
a = list(map(int,input().split()))
p = [abs(X - a[i]) for i in range(N)]
ans = gcd(p)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import bisect
import math
from functools import reduce

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

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

index = bisect.bisect_left(a, x)
a.insert(index, x)
d = [0]*(n)
for i in range(n):
    d[i] = a[i+1] - a[i]
ans = gcd(*d)
print(ans)

Submission status: Accepted

Solution code:
n, X = map(int, input().split())
x = list(map(abs, [i-X for i in list(map(int, input().split()))]))
x.sort()
if x[0] == 0:
    del x[0]
    n -= 1
def gcd(a, b):
    while True:
        c = a%b
        if c == 0:
            break
        a = b
        b = c
    return b

if n == 1:
    ans = x[0]
else:
    for i in range(1, n):
        x[i] = gcd(x[i], x[i - 1])
    ans = x[-1]
print(ans)

Submission status: Accepted

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

kyori = []

for i in arr:
    kyori.append(abs(X-i))

c =math.gcd(kyori[0],kyori[0])
for i in kyori:
    c =math.gcd(c,i)

print(c)

Submission status: Accepted

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+1):
        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: Accepted

Solution code:
import math
N,start = [int(x) for x in input().split()]
_x = [int(y) for y in input().split()]
x = [0 for y in range(N)]
for i in range(N):
    x[i] = abs(_x[i] - start)
g = x[0]
for i in range(N):
    g = math.gcd(g,x[i])
print(g)
ans = 1

Submission status: Accepted

Solution code:
import math
n, x = map(int,input().split())
p = list(map(int,input().split()))
if n == 1:
    print(abs(p[0]-x))
else:
    g = math.gcd(p[0]-x,p[1]-x)
    for i in range(2,n):
        g = math.gcd(g,p[i]-x)
    print(g)

Submission status: Accepted

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])
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: Accepted

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

Submission status: Accepted

Solution code:
import math
N,X  = (int(T) for T in input().split())
Cor  = sorted([abs(int(T)-X) for T in input().split()])
GCDC = Cor[0]
for T in range(1,N):
    GCDC = math.gcd(GCDC,Cor[T])
    if GCDC==1: break
print(GCDC)

Submission status: Accepted

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

x.append(m)
x = sorted(x)
l = [0]*n
for i in range(n): l[i] = x[i+1] - x[i]

ans = l[0]
for i in range(1,n): ans = gcd(ans,l[i])
print(ans)

Submission status: Accepted

Solution code:
import functools
import math

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

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

ans = functools.reduce(math.gcd, dist_next)
print(ans)

Submission status: Accepted

Solution code:
import math

# 最大公約数を求める問題
N, X = map(int, input().split())
x = [int(_) for _ in input().split()]
if N == 1:
    print(abs(x[0]-X))
    exit()

x.sort()
# N > 1と仮定
for i in range(N-1):
    if x[i] < X and x[i+1] > X:
        x = x[:i+1] + [X] + x[i+1:]
        break
    elif x[i] >= X:
        x = [X] + x
        break
    elif x[i+1] <= X:
        x = x + [X]
        break

if len(x) >= 3:
    base = math.gcd(x[1]-x[0], x[2]-x[1])
    for i in range(2, N):
        diff = x[i+1] - x[i]
        base = math.gcd(base, diff)
    print(base)
else:
    print(x[1] - x[0])

Submission status: Accepted

Solution code:
import numpy as np

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

x.append(X)
x.sort()

y = []

for i in range(N):
  y.append(x[i + 1] - x[i])
  
ans = y[0]

#print(x)
#print(y)
  
for i in range(N - 1):
  #print(ans, y[i+1])
  g = np.gcd.reduce([ans, y[i + 1]])
  #print(g)
  if g == 1:
    print(1)
    break
  else:
    ans = g
else:
  print(ans)

Submission status: Accepted

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

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

diff = []

for i in x:
    diff.append(abs(i-s))

ans = diff[0]
for i in diff:
    ans = (gcd(ans, i))

print(ans)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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


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

X.append(Y)
X2 =sorted(X)
X3 = []

for i in range(1, len(X)):
    X3.append(X2[i] - X2[i-1])

print(gcd_list(X3))

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")

N, X = map(int, input().split())
A = list(map(lambda x: abs(int(x) - X), input().split()))
g = A[0]
for i in range(1, N):
  g = math.gcd(g, A[i])
print(g)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n, x=  map(int, raw_input().split(' '))
def gcd(a,b): return a if b == 0 else gcd(b, a % b)
print reduce(gcd,map(lambda c: abs(c - x), map(int, raw_input().split(' '))))

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
X = tuple(map(lambda k:abs(int(k)-x), input().split()))
from math import gcd
from functools import reduce
ans = reduce(gcd, X)
print(ans)

Submission status: Accepted

Solution code:
import math
from functools import reduce

def my_gcd(*N):
    return reduce(math.gcd, N)

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

if X not in C:
	C.append(X)
C.sort()

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

print(my_gcd(*D))

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

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

if len(diff) == 1:
    print(diff[0])
else:
    print(gcd(diff))

Submission status: Accepted

Solution code:
import math  

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]

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

Submission status: Accepted

Solution code:
from math import gcd

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

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
A = list(map(lambda a: abs(int(a) - X), input().split()))
def gcd(a, b):
    while b != 0:
        r = a % b
        a = b
        b = r
    return a
g = A[0]
for a in A[1:]:
    g = gcd(g, a)
print(g)

Submission status: Accepted

Solution code:
import math

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

#x = sorted(x, reverse=True)

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

print(out)

Submission status: Accepted

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

# In[5]:


import math
from functools import reduce


# In[15]:


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


# In[16]:


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


# In[17]:


def myfunc(x,X):
    mylist = [abs(i-X) for i in x]
    print(gcd_list(list(set(mylist))))


# In[18]:


myfunc(x,X)


# In[ ]:

Submission status: Accepted

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

Submission status: Accepted

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):
  ans = math.gcd(ans,xs[i+1]-xs[i])

print(ans)

Submission status: Accepted

Solution code:
import math
n, x = map(int, input().split())
xx = sorted(list(map(int, input().split())) + [x])
y = xx[0]
for i in range(n + 1):
    xx[i] -= y
y = xx[1]
for i in range(2, n + 1):
    y = math.gcd(y, xx[i])
print(y)

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    import math
    N, X = [int(item) for item in input().split()]
    xs = [int(item) for item in input().split()] + [X]
    xs.sort()

    if N > 2:
        res = math.gcd(xs[1] - xs[0], xs[2] - xs[0])

        for item in xs[3:]:
            res = math.gcd(res, item - xs[0])
    elif N == 2:
        res = math.gcd(xs[1] - xs[0], xs[2] - xs[0])
    else:
        res = xs[1] - xs[0]
    
    print(res)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

li = []
x.sort()
for i in range(N):
  li.append(x[i+1]-x[i])
  
li.sort()
while len(li) > 1:
  l = []
  div = li[0]
  for n in li:
    mod = n % div
    if mod != 0:
      l.append(mod)
  l.append(div)
  l.sort()
  li = l
print(*li)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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 = abs(X - k)
    y.append(val)

print(reduce(math.gcd, y))

Submission status: Accepted

Solution code:
import math
from functools import reduce

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
x = list(map(lambda n: n - x[0], x))
print(reduce(math.gcd, x[1:]))

Submission status: Accepted

Solution code:
import numpy as np
import bisect
def main():
    n,X = map(int,input().split())
    x = [int(i) for i in input().split()]
    index = bisect.bisect_left(x,X)
    x.insert(index,X)
    diff = []
    for i in range(1,n+1):
        diff.append(x[i]-x[i-1])
    diff = np.array(diff)
    ans = np.gcd.reduce(diff)
    print(ans)
main()

Submission status: Accepted

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

X_.append(X)
X_.sort()

X_diff=[]
for x_idx in range(1,len(X_)):
    x =X_[x_idx-1]
    x_=X_[x_idx]
    X_diff.append(x_-x)
    
import math
gcd_=X_diff[0]

for x_diff in  X_diff[1:]:
    gcd_=math.gcd(gcd_,x_diff)
    
print(gcd_)

Submission status: Accepted

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

x.append(m)
x = sorted(x)

dis = [0]*n
for i in range(n): dis[i] = x[i+1] - x[i]

ans = dis[0]
for i in range(1,n): ans = gcd(ans,dis[i])
print(ans)

Submission status: Accepted

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

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

a=lst[0]
for i in range(1,n):
    a=gcd(a,lst[i])

print(a)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, x = map(int, input().split())
point = list(map(int, input().split()))
diff = [0] * n
for i in range(n):
    diff[i] = abs(point[i] - x)

def gcd(big, small):
    if small == 0:
        return big
    else:
        return gcd(small, big % small)

import functools

print(functools.reduce(gcd, diff))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)
def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]

#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
N,X = zz()
x = zz()

distance = [0]*N
for i in range(N):
    distance[i] = abs(x[i] - X)
# print(distance)
ans = distance[0]
for d in distance:
    ans = gcd(ans, d)
    # print(ans)
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
from math import gcd
from bisect import bisect
def main():
    n, x, *a = map(int, read().split())
    if n == 1:
        print(abs(a[0] - x))
        sys.exit()
    a.sort()
    a2 = [x - y for x, y in zip(a[1:], a)]
    xpos = bisect(a, x)
    if xpos == 0:
        xd = a[0] - x
        a2.append(xd)
        a2.append(xd)
    elif xpos == n:
        xd = x - a[-1]
        a2.append(xd)
        a2.append(xd)
    else:
        xd1 = x - a[xpos - 1]
        xd2 = a[xpos] - x
        a2.append(xd1)
        a2.append(xd2)
    if len(a2) == 2:
        r = gcd(a[0], a[1])
        print(r)
        sys.exit()

    r = gcd(a2[0], a2[1])
    for i1 in range(2, n + 1):
        r = gcd(r, a2[i1])
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

s = 0

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

for i in A:
  s = gcd(abs(X-i), s)
  
print(s)

Submission status: Accepted

Solution code:
import math

def solve():
    arr = [0]*N
    ans = abs(start-x[0])
    for i in range(1,N):
        arr[i] = (abs(start-x[i]))
        ans = math.gcd(arr[i], ans)
    print(ans)
        
if __name__=="__main__":
    N,start = list(map(int, input().split()))
    x = list(map(int, input().split()))
    solve()