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())
x = list(map(int,input().split()))
a=[]
for i in x:
        a.append(abs(i-X))

def gcd(m,n):
        while m%n!=0:
                s = m%n
                m = n
                n = s
        return n

ans=0
for j in range(len(a)):
        if j%min(a) == 0:
                ans = min(a)
        else:
                ans = gcd(j,ans)
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=[]
for i in range(len(x)-1):
        a.append(x[i+1]-x[i])

def gcd(m,n):
        while n!=0:
                s = m%n
                m = n
                n = s
        return n 

for j in range(len(a)):
        if a[j]%min(a) == 0:
                ans = min(a)
        else:
                ans = gcd(j,min(a))
print(ans)

Submission status: Wrong Answer

Solution code:
n=list(map(int,input().split()))
Y=list(map(int,input().split()))
XX=[abs(Y[i]-n[1]) for i in range(n[0])]
X=sorted(XX)
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y) 
ans=X[0]
for i in range(n[0]-1):
    ans=gcd(ans,X[i])
print(max(X))

Submission status: Wrong Answer

Solution code:
n=list(map(int,input().split()))
Y=list(map(int,input().split()))
X=[abs(Y[i]-n[1]) for i in range(n[0])]
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y) 
for i in range(n[0]-1):
    X[0]=gcd(X[0],X[1])
    X=[X[0]]+X[1:]
print(max(X))

Submission status: Wrong Answer

Solution code:
n=list(map(int,input().split()))
Y=list(map(int,input().split()))
X=[abs(Y[i]-n[1]) for i in range(n[0])]
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y) 
for i in range(n[0]-1):
    X[0]=gcd(X[0],X[1])
    X=[X[0]]+X[:1]
print(max(X))

Submission status: Wrong Answer

Solution code:
#-*- coding:utf-8 -*-
"""
数直線上にN個の都市があり、i番目の都市は座標xiにあります。

あなたの目的は、これら全ての都市を1度以上訪れることです。

あなたは、はじめに正整数Dを設定します。

その後、あなたは座標Xから出発し、以下の移動1、移動2を好きなだけ行います。

移動1: 座標yから座標y+Dに移動する
移動2: 座標yから座標y−Dに移動する

全ての都市を1度以上訪れることのできるDの最大値を求めてください。

ここで、都市を訪れるとは、その都市のある座標に移動することです。
"""
import numpy as np


def judge(N, X, pos, max):
    for i in range(0, N):
        if(np.abs(int(pos[i]) - X)%max == 0):
            pass
        else:
            max -= 1
            i = 0

    return max


def max_distance(N, X, pos):
    """
    Dは高々最も近い都市との距離
    """
    min = 1000000000
    for i in range(0, N):
        tmp = np.abs(int(pos[i]) - X)
        if(tmp < min):
            min = tmp

    return min


def main():
    str = input().split()
    CityPos = input().split()  # 各都市の座標
    N = int(str[0])  # 都市の数
    X = int(str[1])  # 初期座標

    max = max_distance(N, X, CityPos)

    D = judge(N, X, CityPos, max)

    print(D)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#-*- coding:utf-8 -*-
"""
数直線上にN個の都市があり、i番目の都市は座標xiにあります。

あなたの目的は、これら全ての都市を1度以上訪れることです。

あなたは、はじめに正整数Dを設定します。

その後、あなたは座標Xから出発し、以下の移動1、移動2を好きなだけ行います。

移動1: 座標yから座標y+Dに移動する
移動2: 座標yから座標y−Dに移動する

全ての都市を1度以上訪れることのできるDの最大値を求めてください。

ここで、都市を訪れるとは、その都市のある座標に移動することです。
"""
import numpy as np


def judge(N, X, pos, max):
    for i in range(0, N):
        if(np.abs(int(pos[i]) - X)%max == 0):
            break
        else:
            max -= 1
            i = 0

    return max


def max_distance(N, X, pos):
    """
    Dは高々最も近い都市との距離
    """
    min = 1000000000
    for i in range(0, N):
        tmp = np.abs(int(pos[i]) - X)
        if(tmp < min):
            min = tmp

    return min


def main():
    str = input().split()
    CityPos = input().split()  # 各都市の座標
    N = int(str[0])  # 都市の数
    X = int(str[1])  # 初期座標

    max = max_distance(N, X, CityPos)

    D = judge(N, X, CityPos, max)

    print(D)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

N, X = input().split()
xList = [int(x) for x in input().split()]
N = int(N)
X = int(X)
xList.append(X)
xList.sort()
diffList = []
for x, xx in zip(xList, xList[1:]):
    diffList.append(xx - x)
if len(diffList) > 1:
    diffList.sort()
    gcdList = []
    for x in diffList[1:]:
        gcdList.append(gcd(diffList[0], x))
    gcdList.sort
    print(gcdList[0])
else:
    print(diffList[0])

Submission status: Wrong Answer

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

N, X = input().split()
xList = [int(x) for x in input().split()]
N = int(N)
X = int(X)
xList.append(X)
xList.sort()
diffList = []
for x, xx in zip(xList, xList[1:]):
    diffList.append(xx - x)

diffList.sort()

print(gcd(diffList[0], diffList[-1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def gcd(m,n):
    while n:
        m,n=n,m%n
    return m

ans=a[0]
for j in range(1,len(a)-1):
    if a[j]%ans != 0:
        ans = gcd(ans,a[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()
a=[]
for i in range(len(x)-1):
    a.append(x[i+1]-x[i])
print(min(a))

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

Submission status: Wrong Answer

Solution code:
n,X=map(int,input().split())
x=list(map(int,input().split()))
x.append(X)
x.sort()
a=[]
for i in range(len(x)-1):
    a.append(x[i+1]-x[i])
a.sort()
for j in range(1,len(a)):
    if a[j]%a[0]!=0:
        print(1)
        exit()
print(a[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    n,x = map(int, input().split())
    xs = list(map(int, input().split()))
    xs.append(x)
    xs.sort(reverse=True)
    dif = [0]*n
    front = xs[0]
    for i,num in enumerate(xs[1:]):
        dif[i] = front - num
        front = num
    min_dif = min(dif)
    div_min = [min_dif]
    for i in range(int(min_dif**0.5),1,-1):
        if min_dif%i == 0:
            div_min.append(i)
    for i in div_min:
        for j in dif[1:]:
            if j % i != 0:
                break
        else:
            print(i)
            exit()
    print(1)

Submission status: Wrong Answer

Solution code:
def func():
    pass


def main():
    n, x = map(int, input().split())
    xl = [int(i) for i in input().split()]
    if x not in xl:
        xl.append(x)
    xl.sort()

    # print(xl)
    min_d = xl[1] - xl[0]
    for i in range(len(xl) - 1):
        d = xl[i + 1] - xl[i]
        min_d = min(min_d, d)

    print(min_d)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def func():
    pass


def main():
    n, x = map(int, input().split())
    xl = [int(i) for i in input().split()]
    xl.append(x)
    xl.sort()

    # print(xl)
    min_d = xl[1] - xl[0]
    for i in range(len(xl) - 1):
        d = xl[i + 1] - xl[i]
        min_d = min(min_d, d)

    print(min_d)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x,y=map(int, input().split())
an = list(map(int,input().split()))

an.append(y)
an.sort()
#print(an)
tm=1
tm2=0
l=len(an)
for i in range(1,l):
    for j in range(int(an[1]),1,-1):
        if (int(an[i])-int(an[i-1]) )% j==0:

            if tm<j:
                tm=j
                if i==1:
                    tm2=tm
if tm2<tm:
    tm=tm2

print(tm)

Submission status: Wrong Answer

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

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

x.reverse()

xmin = x[N-1]

div = []
for i in range(int(xmin/2)+1, 0, -1):
	if xmin % i == 0:
		div.append(i)

for d in div:
	for xi in x:
		if xi % d != 0:
			break
	else:
		D = d
		break

print(D)

Submission status: Wrong Answer

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

from itertools import chain
from functools import reduce
from collections import OrderedDict, Counter, deque
import operator, fractions
from bisect import *

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

def f():
    X.sort()
    L = len(X)
    if L == 1:
        return abs(X[0] - L)
    
    i = bisect_left(X, x)
    
    d = [t - u for t,u in zip(X[1:], X[:-1])]
    s = None
    if i == 0:
        s = set(d)
        s.add(x[0] - x)
    elif i == len(X):
        s = set(d)
        s.add(x - X[-1])
    else:
        s = set(d[:i - 1])
        s.update(d[i+1:])
        s.update({x - X[i-1], X[i] - x})
    return reduce(lambda a,x: fractions.gcd(a, x), s)

print(f())

Submission status: Wrong Answer

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

for i, n in enumerate(xi):
    xi[i] = abs(xi[i]-x)

if len(xi)==1:
    print(xi[0])
    exit()

xi.sort()
for i in range(1, len(xi)):
     ans = gcd(xi[0], xi[i])
print(ans)

Submission status: Wrong Answer

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

for i, n in enumerate(xi):
    xi[i] = abs(xi[i]-x)

if len(xi)==1:
    print(xi[0])
    exit()

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

Submission status: Wrong Answer

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

for i, n in enumerate(xi):
    xi[i] = abs(xi[i]-x)

if len(xi)==1:
    print(xi[0])
    exit()

xi.sort()
print(gcd(xi[0], xi[1]))

Submission status: Wrong Answer

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

for i, n in enumerate(xi):
    xi[i] = abs(xi[i]-x)

while 1:
    out = min(xi)
    for i, n in enumerate(xi):
        if n%out!=0:
            out = out / 2
            continue
    print(out)
    exit()

Submission status: Wrong Answer

Solution code:
def main():
    N, X = map(int, input().split())
    dx = [abs(X - x) for x in map(int, input().split())]
    ans = 10 ** 9 - X
    for i in range(N - 1):
        nm = max(dx[i], dx[i + 1])
        dm = min(dx[i], dx[i + 1])
        while True:
            mod = nm % dm
            if mod == 0:
                break
            nm = dm
            dm = mod
        ans = min(ans, dm)
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
def main():
    N, X = map(int, input().split())
    dx = [abs(X - x) for x in map(int, input().split())]
    nm = max(dx)
    dm = min(dx)
    while True:
        mod = nm % dm
        if mod == 0:
            break
        nm = dm
        dm = mod
    print(dm)


main()

Submission status: Wrong Answer

Solution code:
from functools import reduce
N, X = [int(a) for a in input().strip().split()]
x = [int(a) for a in input().split()]
y = [abs(a - X) for a in x]
y = list(set(y)) 
y.sort()

if N == 1:
    print(y[0])
    exit()

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

ydiff = []
for i in range(0, len(y)-1):
    ydiff.append(y[i+1] - y[i])

if len(ydiff) == 1:
    ydiff.append(ydiff[0])

print(reduce(gcd, ydiff))

Submission status: Wrong Answer

Solution code:
n,d=map(int,input().split())
x=list(map(int,input().split()))
x.append(d)
a=sorted(x)
c=10e9
for i in range(n):
    c=min(c,a[i+1]-a[i])
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
is_prime = [True] * (10**5)
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(2, len(is_prime)):
    if is_prime[i]:
        primes.append(i)
        for j in range(i*2, len(is_prime)):
            is_prime[j] = False

def do_prime_fact(x):
    res = {}
    for prime in primes:
        while x % prime == 0:
            x /= prime
            if not prime in res:
                res[prime] = 0
            res[prime] += 1
    if x > 1: # x is large prime
        res[x] = 1
    return res

def solve(x):
    ys = [do_prime_fact(x[i+1] - x[i]) for i in range(len(x)-1)]
    d = 1
    for k in ys[0].keys():
        ok = True
        while ok:
            for y in ys:
                if (not k in y) or (y[k] == 0):
                    ok = False
                    break
            if ok:
                for i in range(len(ys)):
                    ys[i][k] -= 1
                d *= k
    return d

n, x0 = map(int, raw_input().split())
x = map(int, raw_input().split())
x = list(sorted(set([x0] + x)))
print(solve(x))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    from fractions import gcd

    n, large_x = map(int, input().split())
    x = sorted(list(map(int, input().split())) + [large_x])
    ans = float('inf')

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

    for k in range(n - 2):
        ans = min(ans, gcd(x[k + 2] - x[k + 1], x[k + 1] - x[k]))

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from functools import reduce
N, X = map(int, input().split())
loc = list(map(int, input().split()))

a = min([abs(l-X) for l in loc])
b = reduce(lambda x, y: abs(x-y), sorted(loc)[:2])

if len(loc) > 1:
    if max([a,b]) % min([a,b]):
        print(1)
    else:
        print(min([a,b]))
else:
    print(abs(min(loc)-X))

Submission status: Wrong Answer

Solution code:
from functools import reduce
N, X = map(int, input().split())
loc = list(map(int, input().split()))

a = min([abs(l-X) for l in loc])
b = reduce(lambda x, y: abs(x-y), sorted(loc)[:2])

if max([a,b]) % min([a,b]):
    print(abs(min(loc)-X))
else:
    print(min([a,b]))

Submission status: Wrong Answer

Solution code:
from functools import reduce
N, X = map(int, input().split())
loc = list(map(int, input().split()))

a = min([abs(l-X) for l in loc])
b = reduce(lambda x, y: abs(x-y), sorted(loc)[:2])
print(a,b)
if max([a,b]) % min([a,b]):
    print(abs(min(loc)-X))
else:
    print(min([a,b]))

Submission status: Wrong Answer

Solution code:
from functools import reduce
N, X = map(int, input().split())
loc = list(map(int, input().split()))

a = min([abs(l-X) for l in loc])
b = reduce(lambda x,y: abs(x-y), sorted(loc)[:2])
print(min([a,b]))

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
loc = list(map(int, input().split()))
print(min([abs(l-X) for l in loc] + [abs(loc[i]-loc[j]) for i in range(N) for j in range(N) if i<j]))

Submission status: Wrong Answer

Solution code:
from functools import reduce
from collections import Counter

N, X = map(int, input().split())
loc = list(map(int, input().split()))
mem = {}

def prime_factors(n):
    if mem.get(n) is not None:
        return mem[n]
    else:
        i = 2
        factors = []
        while i*i <= n:
            if n % i == 0:
                factors.append(i)
                n = n // i
            else:
                i += 1
        if n > 1:
            factors.append(n)
        mem[n] = factors
    return factors


def find_shared_factors(factor1, factor2):
    counters = [Counter(factor1), Counter(factor2)]
    if len(factor2) == 0:
        return factor1
    else:
        return list(reduce(lambda x,y: x&y, counters).elements())

factors = []
for l in loc:
    factors = find_shared_factors(prime_factors(abs(l-X)), factors)
for i in range(N):
    for j in range(N):
        if i < j:
            factors = find_shared_factors(prime_factors(abs(loc[i]-loc[j])), factors)

r = reduce(lambda x,y: x*y, factors)

print(r)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from collections import Counter

N, X = map(int, input().split())
loc = list(map(int, input().split()))
mem = {}

def prime_factors(n):
    if mem.get(n) is not None:
        return mem[n]
    else:
        i = 2
        factors = []
        while i*i <= n:
            if n % i == 0:
                factors.append(i)
                n = n // i
            else:
                i += 1
        if n > 1:
            factors.append(n)
        mem[n] = factors
    return factors


def find_shared_factors(factors):
    counters = [Counter(factor) for factor in factors]
    shared = []
    if len(counters) > 1:
        shared = list(reduce(lambda x,y: x&y, counters).elements())
    return shared


d = find_shared_factors([prime_factors(abs(l-X)) for l in loc] + [prime_factors(abs(loc[i] - loc[j])) for i in range(N) for j in range(N) if i < j])
r = reduce(lambda x,y: x*y, d) if len(d) > 0 else max(loc)-X

print(r)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from collections import Counter

N, X = map(int, input().split())
loc = list(map(int, input().split()))
mem = {}

def prime_factors(n):
    if mem.get(n) is not None:
        return mem[n]
    else:
        i = 2
        factors = []
        while i*i <= n:
            if n % i == 0:
                factors.append(i)
                n = n // i
            else:
                i += 1
        if n > 1:
            factors.append(n)
        mem[n] = factors
    return factors


def find_shared_factors(factors):
    counters = [Counter(factor) for factor in factors]
    shared = []
    if len(counters) > 1:
        shared = list(reduce(lambda x,y: x&y, counters).elements())
    return shared

d1 = find_shared_factors([prime_factors(abs(l-X)) for l in loc])
d2 = find_shared_factors([prime_factors(abs(loc[i] - loc[j])) for i in range(N) for j in range(N) if i < j])
d3 = find_shared_factors([d1, d2])
r = reduce(lambda x,y: x*y, d3) if len(d3) > 0 else max(loc)-X

print(r)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from collections import Counter

N, X = map(int, input().split())
loc = list(map(int, input().split()))
mem = {}

def prime_factors(n):
    if mem.get(n) is not None:
        return mem[n]
    else:
        i = 2
        factors = []
        while i*i <= n:
            if n % i == 0:
                factors.append(i)
                n = n // i
            else:
                i += 1
        if n > 1:
            factors.append(n)
        mem[n] = factors
    return factors


def find_shared_factors(factors):
    counters = [Counter(factor) for factor in factors]
    shared = []
    if len(counters) > 1:
        keys = reduce(lambda x,y: x|y, [set(c.keys()) for c in counters])
        for key in keys:
            r = [counter[key] for counter in counters]
            if min(r) > 0:
                for _ in range(min(r)):
                    shared.append(key)
    else:
        shared = []
    return shared


d1 = find_shared_factors([prime_factors(abs(l-X)) for l in loc])
d2 = find_shared_factors([prime_factors(abs(loc[i] - loc[j])) for i in range(N) for j in range(N) if i < j])
d3 = find_shared_factors([d1, d2])
r = reduce(lambda x,y: x*y, d3) if len(d3) > 0 else max(loc)-X
print(r)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from collections import Counter

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

def prime_factors(n):
    i = 2
    factors = []
    while i*i <= n:
        if n % i == 0:
            factors.append(i)
            n = n // i
        else:
            i += 1
    if n > 1:
        factors.append(n)
    return factors

def find_shared_factors(factors):
    counters = [Counter(factor) for factor in factors]
    shared = []
    if len(counters) > 1:
        keys = reduce(lambda x,y: x|y, [set(c.keys()) for c in counters])
        for key in keys:
            r = [counter[key] for counter in counters]
            if min(r) > 0:
                for _ in range(min(r)):
                    shared.append(key)
    else:
        shared = []
    return shared

d1 = find_shared_factors([prime_factors(abs(l-X)) for l in loc])
d2 = find_shared_factors([prime_factors(abs(loc[i] - loc[j])) for i in range(N) for j in range(N) if i < j])
d3 = find_shared_factors([d1, d2])
r = reduce(lambda x,y: x*y, d3) if len(d3) > 0 else max(loc)-X
print(r)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from collections import Counter

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

def prime_factors(n):
    i = 2
    factors = []
    while i*i <= n:
        if n % i == 0:
            factors.append(i)
            n = n // i
        else:
            i += 1
    if n > 1:
        factors.append(n)
    return factors

def find_shared_factors(factors):
    counters = [Counter(factor) for factor in factors]
    shared = []
    if len(counters) > 1:
        keys = reduce(lambda x,y: x|y, [set(c.keys()) for c in counters])
        for key in keys:
            r = [counter[key] for counter in counters]
            if min(r) > 0:
                for _ in range(min(r)):
                    shared.append(key)
    else:
        shared = []
    return shared

d1 = find_shared_factors([prime_factors(abs(l-X)) for l in loc])
d2 = find_shared_factors([prime_factors(abs(loc[i] - loc[j])) for i in range(N) for j in range(N) if i < j])
d3 = find_shared_factors([d1, d2])
r = reduce(lambda x,y: x*y, d3) if len(d3) > 0 else max(loc)-1
print(r)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
Xi=list(map(int,input().split()))
print(1)

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
Xi=list(map(int,input().split()))
a=[]
b=[]
for i in range(N):
    if (Xi[i]-X)>0:
        a.append(Xi[i]-X)
    else:
        b.append(X-Xi[i])
a.sort()
b.sort()
for i in range(len(a)-1):
    a[i]=a[i+1]-a[i]
for i in range(len(b)-1):
    b[i]=b[i+1]-b[i]
a.sort()
b.sort()
x=100000000000
y=100000000000
if len(a)>0:
    x=a[0]
if len(b)>0:
    y=b[0]
z=0
if x!=100000000000 and y!=100000000000:
    if max(x,y)%min(x,y)!=0:
        z=1
    else:
        z=min(x,y)
else:
    z=min(x,y)
print(z)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
Xi=list(map(int,input().split()))
a=[]
b=[]
for i in range(N):
    if (Xi[i]-X)>0:
        a.append(Xi[i]-X)
    else:
        b.append(X-Xi[i])
a.sort()
b.sort()
for i in range(len(a)-1):
    a[i]=a[i+1]-a[i]
for i in range(len(b)-1):
    b[i]=b[i+1]-b[i]
a.sort()
b.sort()
x=100000000000
y=100000000000
if len(a)>0:
    x=a[0]
if len(b)>0:
    y=b[0]
print(min(x,y))

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
Xi=list(map(int,input().split()))
for i in range(N):
    Xi[i]=abs(Xi[i]-X)
Xi.sort()
o=0
e=0
D=0
for i in range(N):
    if Xi[i]%2==0:
        e+=1
    else:
        o+=1
    if o>0 and e>0:
        D=1
        break
if D==0:
    D=Xi[0]
    c=0
    a=0
    while c!=1:
        for i in range(N):
            a=0
            if (Xi[i]%D)!=0:
                a=1
                D-=1
                break
        if a==0:
            c=1
print(D)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
Xi=list(map(int,input().split()))
for i in range(N):
    Xi[i]=abs(Xi[i]-X)
Xi.sort()
D=Xi[0]
c=0
while c!=1:
    for i in range(N):
        if (Xi[i]%D)!=0:
            D-=1
            break
    c=1
print(D)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
Xi=list(map(int,input().split()))
for i in range(N):
    Xi[i]=abs(Xi[i]-X)
Xi.sort()
D=Xi[0]
print(D)

Submission status: Wrong Answer

Solution code:
import fractions as math

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

x_0 = [x_- x_min for x_ in x]

gcd = x_0[0]
for x_0_ in x_0:
    gcd = math.gcd(gcd,x_0_)

ans = gcd

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

print(ans)

Submission status: Wrong Answer

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

r=1
b_list=[]
a=abs(x_list[0]-X)

if(N==1):
    print(a)
else:
    for i in range(N-1):
        x_list[i+1]-=X
        if(x_list[i+1]==0):
            x_list.pop(i+1)
    
    for j in range(len(x_list)-1):    
        b=abs(x_list[j+1])
        a,b=max(a,b),min(a,b)
            
        while(r>0):
            r=a%b
            if(r==0):
                b_list.append(b)
            a=b
            b=r
    print(min(b_list))

Submission status: Wrong Answer

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

r=1
a=abs(x_list[0]-X)

if(N==1):
    print(a)
else:
    for i in range(N-1):
        x_list[i+1]-=X
        b=abs(x_list[i+1])
        a,b=max(a,b),min(a,b)
        
        while(r>0):
            r=a%b
            if(r==0):
                print(b)
            a=b
            b=r

Submission status: Wrong Answer

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

inputs.append(X)
inputs.sort()

print(inputs[1] - inputs[0])

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
x_list=list(map(int,input().split()))
x_sub_list=[]
if(N==1):
    print(abs(x_list[0]-X))
else:
    for i in range(N):
        x_sub_list.append(abs(x_list[i]-X))
        if(x_sub_list[i]==0):
            x_sub_list.pop(i)
            
    
    M=max(x_sub_list)
    m=min(x_sub_list)
        
    r=1
    while(r>0):
        r=M%m
        if(r==0):
            print(m)
        M=m
        m=r

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
x_list=list(map(int,input().split()))
x_sub_list=[]

for i in range(N):
    x_sub_list.append(abs(x_list[i]-X))
    if(x_sub_list[i]==0):
        x_sub_list.pop(i)
        
if(x_sub_list==[]):
    print(0)
else:
    M=max(x_sub_list)
    m=min(x_sub_list)
    
    r=1
    while(r>0):
        r=M%m
        if(r==0):
            print(m)
        M=m
        m=r

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
x_list=list(map(int,input().split()))
x_sub_list=[]

for i in range(N):
    x_sub_list.append(abs(x_list[i]-X))
    if(x_sub_list[i]==0):
        x_sub_list.pop(i)

M=max(x_sub_list)
m=min(x_sub_list)

r=1
while(r>0):
    r=M%m
    if(r==0):
        print(m)
    M=m
    m=r

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
x_list=list(map(int,input().split()))
x_sub_list=[]

for i in range(N):
    x_sub_list.append(abs(x_list[i]-X))

M=max(x_sub_list)
m=min(x_sub_list)

r=1
while(r>0):
    r=M%m
    if(r==0):
        print(m)
    M=m
    m=r

Submission status: Wrong Answer

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

if N == 1:
  	print(x[0]-X)
  	exit()
for i in range(1,max(x)):
    count = 0
    for j in range(N):
        if (max(x[j], X) - min(x[j], X)) % i== 0:
            count += 1
        else:
            break
    if count == N:
        ok_list.append(i)
print(max(ok_list))

Submission status: Wrong Answer

Solution code:
####################
def pri(n):
  i = 2
  X = {}
  while i * i <= n:
    while n % i == 0:
      n /= i
      if i in X:
        X[i] = X[i] + 1
      else:
        X[i] = 1
    i += 1
  if n > 1:
    X[n] = 1
  return X
####################


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

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

x.sort()

d = []
for i in range(N):
  dif = x[i+1] - x[i]
  if dif not in d:
    d.append(dif)

d.sort()

if len(d) == 1:
  print(d[0])
  exit()

m = d[0]
P = pri(d[0])

for i in range(1,len(d)):
  if d[i] % m != 0:
    t = pri(d[i])
    m = 1
    for j in list(P):
      if j in t:
        P[j] = min(P[j], t[j])
        m *= j ** P[j]
      else:
        del P[j]

print(m)

Submission status: Wrong Answer

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

x_abs = []
for i in x_list:
    x_abs.append(abs(X - i))

def gcd(i, j):
    if i % j == 0:
        return j
    else:
        k = i % j
        gcd(j, k)

x_abs.sort(reverse=True)
ans = 0
if len(x_abs) == 1:
    ans = x_abs[0]
else:
    for i in range(N-1):
        ans = gcd(x_abs[i], x_abs[i + 1])
    
print(ans)

Submission status: Wrong Answer

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

x_abs = []
for i in x_list:
    x_abs.append(abs(X - i))

def gcd(i, j):
    if i % j == 0:
        return j
    k = i % j
    gcd(j, k)

x_abs.sort(reverse=True)
ans = 0
if len(x_abs) == 1:
    ans = x_abs[0]
else:
    for i in range(N-1):
        ans = gcd(x_abs[i], x_abs[i + 1])
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

for i in range(len(t)):
    t[i] = abs(t[i]-x)

max = max(t)
min = min(t)

print(gcd(max,min))

Submission status: Wrong Answer

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

min = abs(t[0]-x)
if min == 0:
    min = t[0]

for i in t[1:] :
    s = abs(i-x)
    if s == 0 :
        s = i

    if min > s :
        min = s

print(min)

Submission status: Wrong Answer

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

min = abs(t[0]-x)

for i in t[1:] :
    s = abs(i-x)
    if min > s :
        min = s

print(min)

Submission status: Wrong Answer

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

min = abs(int(t[0])-int(x))

for i in t[1:] :
    s = abs(int(i)-int(x))
    if min > s :
        min = s

print(min)