peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
n, k = map(int,input().split())
h = list(map(int,input().split()))
ans = []

for i in range(n):
    if i == 0:
        ans.append(0)
    
    else:
        x = 10**5
        for j in range(k):
            if i-j-1 < 0:
                break
            y = ans[-j-1] + abs(h[i]-h[i-j-1])
            if y < x:
                x = y
        ans.append(x)

print(ans[-1])
# Judge status: Wrong Answer
from math import *
n=int(input())
l=list(map(int,input().split()))
s=ceil(sum(l)/n)
c=0
for i in range(n):
    c+=(s-l[i])**2
print(c)
# Judge status: Wrong Answer
X = int(input())
i = 1
cnt = 0
n = X
while cnt+i<=X:
    cnt += i
    if X-cnt==0:
        n = i
        break
    if X-cnt>i:
        n = min(n,X-cnt)
    i += 1
print(n)
# Judge status: Accepted
K=int(input())
if(K%2==0):
    num=(K/2)**2
else:
    num=(K-1)/2*(((K-1)/2)+1)
print(int(num))
# Judge status: Accepted
icase=0
if icase==0:
    x=int(input())
    if x==7 or x==5 or x==3:
        print("YES")
    else:
        print("NO")
# Judge status: Accepted
n, *h = map( int, open( 0 ).read().split() )

d = [ 0 ] * n
d[ 1 ] = abs( h[ 1 ] - h[ 0 ] )
for i in range( 2, n ):
  d[ i ] += min( d[ i - 1 ] + abs( h[ i ] - h[ i - 1 ] ), 
                 d[ i - 2 ] + abs( h[ i ] - h[ i - 2 ] ) )
print( d[ n - 1 ] )
# Judge status: Accepted
def dfs(i,Str,res):
    if i==num-1:
        if res==7:
            print(Str+"=7")
            exit()
        return
    dfs(i+1,Str+"+"+S[i+1],res+int(S[i+1]))
    dfs(i+1,Str+"-"+S[i+1],res-int(S[i+1]))    

S=input()
num=len(S)
dfs(0,S[0],int(S[0]))
# Judge status: Wrong Answer
A,B,X=map(int,input().split())
if A<=X and B>=X:
  print("YES")
else:
  print("NO")
# Judge status: Wrong Answer
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
print(l)
ans = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        ans += bisect.bisect_left(l[b+1:], l[b]+l[a]) - bisect.bisect(l[b+1:], l[b]-l[a])
print(ans)
# Judge status: Accepted
import sys
readline = sys.stdin.readline
from fractions import gcd

def main():
    N = int(readline())
    ans = 1
    for _ in range(N):
        t = int(readline())
        ans = (ans * t) // gcd(ans, t)
    
    print(ans)
    
if __name__ == '__main__':
    main()
# Judge status: Accepted
import numpy as np
import itertools

Cmin = 10**10
N, M, X = map(int, input().split())
L = np.array([[int(j) for j in input().split()] for i in range(N)])
for i in range(N):
  for idx in itertools.combinations(list(range(N)), i+1):
    A = np.zeros(M+1, dtype=int)
    for j in idx:
      A = A + L[j]
    if A[0] < Cmin and (A[1:] >= X).all() == True:
      Cmin = A[0]
if Cmin == 10**10:
  print(-1)
  exit()
print(Cmin)
# Judge status: Accepted
#ABC120B
#AもBも割り切る正の整数のうちK番目に大きいものを求める
A,B,K = map(int, input().split())
common_div = []
for i in range(min(A,B)+1,0,-1):
    if A%i==0 and B%i==0:
        common_div.append(i)

#print(common_div)
print(common_div[K-1])
# Judge status: Accepted
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)
for g in G:
    print(len(g))
# Judge status: Accepted
import math

s=int(input())
if s<3:
    print(0)
else:
    k=math.factorial(s-3)
    l=k
    m=1
    num=0
    for i in range(1,s//3+1):
        num+=l//(k*m)
        num%=10**9+7
   
        if i!=s//3:
            l//=(s-2*i-1)*(s-2*i-2)
            k//=(s-3*i)*(s-3*i-1)*(s-3*i-2)
            m*=i
    print(num%(10**9+7))
# Judge status: Accepted
#!/usr/bin/env python3
c = eval(input().replace(" ", "+"))
print(c // 2 * (c % 2 < 1) or "IMPOSSIBLE")
# Judge status: Wrong Answer
n,m =map(int,input().split())
a =list(map(int,input().split()))

if sum(a)>=n:
    print('-1')
else:
    print(n-sum(a))
# Judge status: Accepted
def main():
    N, M = map(int, input().split(" "))
    for i in range(M // N, 0, -1):
        if M % i == 0 and i <= M / N:
            print(i)
            break


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
import collections
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
l=[]
for _ in range(Q):
    l.append(list(map(int,input().split())))
c = collections.Counter(A)
sum=sum(A)
for i in range(Q):
    if c[l[i][0]] == 0:
        print(sum)
        break
    else:
        sum+=c[l[i][0]]*(l[i][1]-l[i][0])
        c[l[i][1]]+=c[l[i][0]]
        del c[l[i][0]]
        print(sum)
# Judge status: Accepted
n,k=list(map(int,input().split()))
S=input()
c,row_count=S[0],1

for s in S:
  if c != s:
    c = s
    row_count += 1

if row_count-k*2 <= 1:
  row_count = 1
else:
  row_count -= k*2
  
print(n-row_count)
# Judge status: Accepted

def solve(A):
    res = 0
    b = 0
    for a in A:
        a += b
        res += a//2
        if a == b:
            b = 0
        else:
            b = a%2
    return res

if __name__ == '__main__':
    N = int(input())
    A = [int(input()) for _ in range(N)]
    print(solve(A))
# Judge status: Accepted
a, b = list(map(int, input().split()))

if (a%3 == 0) or (b%3 == 0) or ((a+b)%3 == 0):
    print("Possible")
else:
    print("Impossible")
# Judge status: Accepted
n=int(input())
upper=list(map(int,input().split()))
lower=list(map(int,input().split()))
m=0
for i in range(n):
  s=sum(upper[:i+1])+sum(lower[i:])
  m=max(s,m)
print(m)
# Judge status: Wrong Answer
def main():
    S,T = input().split()
    a,b = map(int,input().split())
    u = input()
    print(a-1,b if S == u else a,b-1)
    return

if __name__ == "__main__":
    main()
# Judge status: Accepted
A=list(input())
B=list(input())
C=list(input())
t="a"
while True:
  if t=="a":
    if not A:
      print("A")
      break
    else:
      t=A.pop(0)
  elif t=="b":
    if not B:
      print("B")
      break
    else:
      t=B.pop(0)
  else:
    if not C:
      print("C")
      break
    else:
      t=C.pop(0)
# Judge status: Accepted
A = int(input())
B = int(input())
C = int(input())
X = int(input())
i=0
for a in range(0,A+1):
  for b in range(0,B+1):
    for c in range(0,C+1):
      if 500*a + 100*b + 50*c == X:
        i = i+1
print(i)
# Judge status: Accepted
from collections import Counter

n, k, q = map(int, input().split())
A = [int(input()) for _ in range(q)]
C = Counter(A)
for i in range(1, n+1):
    if C[i] + k - q <= 0:
        print('No')
    else:
        print('Yes')
# Judge status: Accepted
n, a, b = map(int, input().split())
s = input()
A = 0
B = 0
for i in range(len(s)):
    if s[i] == "a":
        if A + B < a + b:
            print("Yes")
            A += 1
        else:
            print("No")
    elif s[i] == "b":
        if A + B < a + b and B < b:
            print("Yes")
            B += 1
        else:
            print("No")
    else:
        print("No")
# Judge status: Accepted
from itertools import product
N = int(input())
print("Yes" if N in {a*b for a,b in product(range(1, 10), range(1, 10))} else "No")
# Judge status: Accepted
N = int(input())
S = input()

l = 0
r = 0
for i in range(N):
    if S[i]==")":
        r -= 1
        if r<0:
            l += 1
            r = 0
    else:
        r += 1

ans = "("*l + S + ")"*r

print(ans)
# Judge status: Accepted
x, y = map(int, input().split())

if 0 <= x <= y or x <= y <= 0:
    print(y - x)
elif x <= 0 <= y:
    if x == 0 or y == 0:
        print(abs(x + y))
    else:
        print(abs(y + x) + 1)
elif 0 <= y <= x or y <= x <= 0:
    if x == 0 or y == 0:
        print(abs(x - y) + 1)
    else:
        print(abs(x - y) + 2)
else:
    print(abs(x + y) + 1)
# Judge status: Accepted
n = input('')

if n[0] == '9' or n[1] == '9':
    print('Yes')
else:
    print('No')
# Judge status: Accepted
import math

n, k = map(int, input().split())
a = [int(_) for _ in input().split()]

if n == k:
    print(1)
    exit()

idx = a.index(1)
num_l = idx
num_r = n - idx - 1

print(math.ceil((n-1) / (k-1)))
# Judge status: Accepted
from collections import Counter
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]

ans = sum(a)
a = Counter(a)
for b, c in bc:
    ans = ans + (c - b) * a[b]
    a[c] += a[b]
    a[b] = 0
    print(ans)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
ans = A[0]

counter = 0
idx = 1
for _ in range(N-2):
  ans += A[idx]
  counter += 1
  if counter == 2:
    idx += 1
    counter = 0
print(ans)
# Judge status: Wrong Answer
# A, B, N = map(int, input().split())
A, B, N = 5, 7, 4

A, B, N = map(int, input().split())


def calculate(a, b, n):
    s1 =  a * n // b
    if n == b:
        s1 = a*(n-1) // b
    if N > b:
        if n >= 2 * b:
            x = b + b - 1
        else:
            x = n
        return max(s1,(a * x) // b + a * (x // b))

    return s1


print(calculate(A, B, N))
# Judge status: Wrong Answer
N=int(input())
x0=2
x1=1

x=0

if N==1:
    x=2
elif N==2:
    x=1
else:
    for i in range(N-1):
        x=x1+x0
        x0=x1
        x1=x

print(x)
# Judge status: Accepted
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n, a, b = rli()
    p = n // (a+b)
    ans = p*a+min(n%(a+b), a)
    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Accepted
import sys
import math

A,B=input().split()
X=int(A+B)

print('Yes' if math.sqrt(X).is_integer() else 'No')
# Judge status: Accepted
n = input()
if '7' in n:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
n = int(input())
r = [input().split() for _ in range(n)]
print(*sorted(range(1, n + 1), key=lambda i: (r[i-1][0], -int(r[i-1][1]))), sep='\n')
# Judge status: Wrong Answer
N, M = map(int, input().split())
r = [0]*N
for _ in range(M):
    a, b = map(int, input().split())
    r[a-1]+1
    r[b-1]+1
for rr in r:
    print(rr)
# Judge status: Wrong Answer
import numpy as np

A=list(input().split())

print(A, A[0], int(A[0]))

N=int(A[0])
M=int(A[1])

B=list(input().split())

k=0

for i in range(len(B)):
    k+=int(B[i])

print(N-k if N-k>=0 else -1)
# Judge status: Accepted
from collections import Counter

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

left = [i+A[i] for i in range(n)]
right = [i-A[i] for i in range(n)]

r_counter = Counter(right)

ans = 0

for l in left:
    ans += r_counter[l]

print(ans)
# Judge status: Accepted
A,B,H,M=map(int,input().split())
import math
k=math.cos(math.pi*((H/6)-((11*M)/360)))
L=(A**2+B**2-2*A*B*k)**0.5
print(L)
# Judge status: Accepted
N = int(input())
L = list(map(int,input().split()))
if max(L) * 2 < sum(L):
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
n=int(input())
h=list(map(int,input().split()))
ct=0
ans=0
flag=0
for i in range(n-1):
    ct+=1
    if h[i]<h[i+1]:
        flag+=1
        if ans<ct:
            ans=ct
        ct=0
if ans<ct:
    ans=ct
if flag==(n-1):
    print(0)
else:
    print(ans)
# Judge status: Accepted
print(-~sum(map(int,input().split()))//2)
# Judge status: Wrong Answer
x = input().split()
a = int(x[0])
b = int(x[0])
if a <= 9 and b <= 9:
  print(a * b)
else:
  print('-1')
# Judge status: Accepted
X, A, B = map(int,input().split())
if B <= A:
  print("delicious")
elif B <= X + A:
  print("safe")
else:
  print("dangerous")
# Judge status: Accepted
a=[int(i) for i in input().split()]
a.sort()
print("Yes" if a[2] == a[0]+a[1] else "No")
# Judge status: Accepted
N, M = map(int, input().split())
from math import factorial
mod = 10**9+7

if abs(N-M) > 1:
    print(0)
elif abs(N-M) == 1:
    print(factorial(N)*factorial(M)%mod)
else:
    print(2*factorial(N)*factorial(M)%mod)
# Judge status: Accepted
import math
N, X, T = input().strip().split(' ')
count = math.ceil(int(N)/int(X))
time = int(T) * count
print(time)
# Judge status: Accepted
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
a=sorted(h)
ans=a[k-1]-a[0]
for i in range(1,n-k+1):
    if a[k+i-1]-a[i]<ans:
        ans=a[k+i-1]-a[i]
print(ans)
# Judge status: Accepted
S=list(input())
a,b=len(S),len(set(S))
if a==b:
  print('yes')
else:
  print('no')
# Judge status: Accepted
n = int(input())
if n%2 == 0:
    print(n//2)
else:
    print(n//2+1)
# Judge status: Accepted
a = int(input())
x = a + a**2 + a**3

print(x)
# Judge status: Wrong Answer
X = int(input())
A = -10
B = -10
for A in range(-10, 100):
    for B in range(-10, 100):
        if(A ** 5) - (B ** 5) != X:
            continue
        print(A, B)
        break
# Judge status: Accepted
from collections import Counter
n = int(input())
s = Counter([input() for _ in range(n)])
m = int(input())
t = Counter([input() for _ in range(m)])

ans = 0
for x,y in s.items():
  a = y
  if x in t:
    a -= t[x]
  if ans < a: ans = a
print(ans)
# Judge status: Wrong Answer
import fractions
import numpy as np
MOD = 10**9+7
 
def lcm_n(l):
    rtn = l[0]
    for i in range(1,N):
        rtn = rtn * l[i] // fractions.gcd(rtn,l[i])
    return rtn
  
N = int(input())
A = np.array(list(map(int,input().split())),dtype = np.int64)
lcm = lcm_n(A)
ans = 0
A = (lcm // A) % MOD
 
print(sum(A) % MOD)
# Judge status: Accepted
n, k = map(int, input().split())
print(sum(sorted(map(int, input().split()))[:k]))
# Judge status: Wrong Answer
def main():
    X = input()
    count = 0
    for i in range(450):
        count += X.count("ST")
        X = X.replace("ST","")
    print(len(X))


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
L=[500,100,50,10,5,1]
X=int(input())
happiness_points=0
for i in L:
  if X//i!=0:
    if i==500:
      happiness_points+=1000
    elif i==5:
      happiness_points+=5
    else:
      None
# Judge status: Accepted
N=input()
sum=0
for i in N:
    sum+=int(i)
if sum%9 == 0:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
N, M, *A = map(int, open(0).read().split())
*A, = zip(*[iter(A)]*2)
A.sort()

ans = 0
for a, b in A:
    ans += a*min(b, M)
    M -= min(b, M)

    if M == 0:
        break
print(ans)
# Judge status: Accepted
A,B,C = map(int,input().split())

if A <= C <= B:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
a,b=map(int,input().split())
s=0
for i in range(1,1251):
    if int(i*0.08)==a and int(i*0.1)==b:
        print(str(i))
        s+=1
        break
if s==0:
    print("-1")
# Judge status: Accepted
N = int(input())

lst = list()
for i in range(1, N+1):
    s, p = input().split()
    lst.append({"id":i, "s":s, "p":int(p)})

lst.sort(key=lambda x:x["p"], reverse=True)
lst.sort(key=lambda x:x["s"])

for i in range(0, len(lst)):
    print(lst[i]["id"])
# Judge status: Wrong Answer
import itertools
S = input()

S = S[::-1]
pre = S[0]
cnt = 1
i = 1
while i < len(S):
    if S[i] != pre[-1]:
        cnt += 1
        pre = S[i]
        i += 1
    else:
        j = 2
        while j <= len([pre]):
            if S[i:i+j] == pre[:j]:
                j += 1
        cnt += 1
        pre = S[i:i+j]
        i += j
        
print(cnt)
# Judge status: Accepted
A,B=map(int,input().split())
print((A+B) % 24)
# Judge status: Wrong Answer
s = str(input("Enter a string: "))

if s[2] == s[3] and s[4] == s[5]:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
MOD = 10**9 + 7
def comb(n, k, MOD):
    if n < k or n < 0 or k < 0:
        return 0
    if k == 0:
        return 1
    iinv = [1] * (k + 1)
    ans = n
    for i in range(2, k + 1):
        iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
        ans *= (n + 1 - i) * iinv[i] % MOD
        ans %= MOD
    return ans
n, a, b = map(int, input().split())
ans = pow(2,n,MOD)
print(((ans-comb(n,a,MOD))%MOD-comb(n,b,MOD))%MOD-1)
# Judge status: Wrong Answer
a,b,c = map(int,input().split())
print("YES" if (a + b + c) % 2 == 0 else "No")
# Judge status: Wrong Answer
n = int(input())

list = [1,2,3,4,5,6,7,8,9]

for i in range(n):
  x = list[0]
 # print(i,"番目　",x)
  list.pop(0)
  if x % 10 != 0:
    list.append(10*x + (x%10) -1)
    list.append(10*x + (x%10))
  if x % 10 != 9:
    list.append(10*x + (x%10) + 1)
print(x)
# Judge status: Accepted
a = input()

if a.isupper():
    print('A')
else:
    print('a')
# Judge status: Accepted
ab,bc,ca = map(int,input().split())

print(int(ab*bc/2))
# Judge status: Wrong Answer
x,y = map(int,input().split())

ans = 0

if x <= y:
  ans = y - x
  
else: # x > y
  if abs(x) > abs(y):
    if y <= 0:
      ans = abs(x - y) + 1
    elif y > 0:
      ans = abs(x - y) + 2
      
  elif abs(x) < abs(y):# y ...x or -x ... 0 ... -x or x ... -y
    ans = abs(y - x) + 1
    if x < 0:
      ans += 1
  
  else:#10,-10など
    ans = 1

print(ans)
# Judge status: Accepted
N = int(input())
a = list(map(int, input().split()))
sm = 10000 * N

for y in range(-100, 101):
    s = 0
    for i in range(N):
        s += (a[i] - y) ** 2
    if sm > s:
        sm = s

print(sm)
# Judge status: Accepted
n = int(input())
c = list(input())
R_frag = 0
W_frag = 0
ans = 0
r = n - 1
l = 0
while l < r:
    if c[l] == "R":
        l += 1
    if c[r] == "W":
        r -= 1
    if c[l] == "W" and c[r] == "R":
        c[l] = "R"
        c[r] = "W"
        ans += 1
        l += 1
        r -= 1
print(ans)
# Judge status: Accepted
from sys import stdin

input=stdin.readline

#ユークリッド互除法
def gcd(a, b):
  dekai = max(a, b)
  tiisai = min(a, b)
  
  div = dekai % tiisai
  next_dived=tiisai
  #次割られるのは，さっき割り込んできたやつ
  #次割るのは，さっきの計算で出た余り
  while (div != 0):
    tmp=div
    div = next_dived % div
    next_dived=tmp

  return next_dived

A,B=map(int,input().split())

#print(gcd(A,B))

print (A*B//gcd(A,B))
# Judge status: Wrong Answer
n = int(input())
ans = "No"
for i in range(n // 4):
    if (n - 4 * i) % 7 == 0:
        ans = "Yes"
        break
    else:
        continue
print(ans)
# Judge status: Accepted
# import numpy as np
n = int(input())
a_lst = list(map(int, input().split()))
x = 10 ** 18

# ans = np.prod(a_lst)



ans = 1
if 0 in a_lst:
    # print("a")
    ans = 0
else:
    for i in range(n):
        ans *= a_lst[i]
        if ans > x:
            ans = -1
            break
        # elif ans == 0:
        #     break
    
# if ans > x:
#     print(-1)
# else:
#     print(ans)
print(ans)
# Judge status: Wrong Answer
n = int(input())
t = [int(input()) for _ in range(n)]

import fractions
n = t[0]
for a,b in zip(t, t[1:]):
    g = fractions.gcd(n, b)
    n = a*b//g
print(n)
# Judge status: Wrong Answer
s = input()
for i in range(len(s)):
    if (i+1) % 2 != 0 and s[i] == 'L':
        break
    elif (i+1) % 2 == 0 and s[i] == 'R':
        break
if i == len(s) -1:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
n = int(input())
ans = 0
if n == 2:
    print(0)
    exit()
else:
    for i in range(1, n):
        ans += (n-1)//i
    print(ans)
# Judge status: Accepted
# -*- coding: utf-8 -*-

A,B,M = [int(i) for i in input().rstrip().split()]
a_list = [int(i) for i in input().rstrip().split()]
b_list = [int(i) for i in input().rstrip().split()]
xyc_list = [list(map(int, input().rstrip().split())) for i in range(M)]
#-----

min_price = min(a_list) + min(b_list)

for x,y,c in xyc_list:
    price_discount = a_list[x-1] + b_list[y-1] - c
    min_price = min( min_price, price_discount)

print(min_price)
# Judge status: Accepted
s = input()
ans =0
n = len(s)
for i in range(1 , n):
	f=0
	for j in range(0 , i-1):
		if j+i>=n or s[j]!=s[i+j]:
			f=1
	if f==0:
		if n-2*i!=0:
			ans = max(ans, 2*i)
print(ans)
# Judge status: Accepted
n = int(input())
for i in range(0, n//4 + 1):
  if (n - i*4) % 7 == 0:
    print("Yes")
    exit()
print("No")
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
s=0
for j in range(len(bin(max(a)))-2):
    cnt1=0
    cnt0=0
    for i in range(n):
      if (a[i]>>j)&1:
        cnt1+=1
      else:
        cnt0+=1
    s+=(cnt1*cnt0*2**j)%(10**9+7)
print(s%(10**9+7))
# Judge status: Wrong Answer
# ABC102 C - Linear Approximation
N = int(input())
A = list(map(int, input().split()))

bl = []
for i in range(N):
    bl.append(A[i] - (i+1))
bl.sort()
b = bl[round(N/2)]

ans = 0
for i in range(N):
    ans += abs(A[i] - (b + (i+1)))
print(ans)
# Judge status: Wrong Answer
n = int(input())
all = 10000
 
def sum_digit(num):
    sum = 0
    while(num > 0):
        sum += num % 10
        num = int(num / 10)
    return sum
 
 
for a in range(2,n):
    sum_A =sum_digit(a)
    sum_B =sum_digit(n-a)
    all=min(all,(sum_A + sum_B))

print(all)
# Judge status: Accepted
n, k = map(int, input().split())
a = list(map(int, input().split()))


def ceil(a, b):
    return -(-a // b)


print(ceil(n-1, k-1))
# Judge status: Accepted
w, h, n = map(int, input().split())
area = [0, 0, w, h]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and x > area[0]:
        area[0] = x
    elif a == 2 and x < area[2]:
        area[2] = x
    elif a == 3 and y > area[1]:
        area[1] = y
    elif a == 4 and y < area[3]:
        area[3] = y
print((area[2]-area[0]) * (area[3] - area[1]) if (area[2]-area[0]) > 0 and (area[3] - area[1]) > 0 else 0)
# Judge status: Accepted
x,y=[int(_) for _ in input().split()]

def a():
  if y<x:
    return 10000000000
  return y-x
def ba():
  if -x>y:
    return 10000000000
  return y+x+1

def ab():
  if x>-y:
    return 100000000000
  return -x-y+1
def bab():
  if x<y:
    return 10000000000
  return x-y+2
ans=min(a(),ba(),bab(),ab())
print(ans)
# Judge status: Accepted
#!/usr/bin/env python3
n = int(input())
l = list(map(int,input().split()))
l.sort()
l_max = l[-1]
ans = 1
s = sum(l) - l_max
if s > l_max:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
x=int(input())
for i in range(1,x+1):
  if (360*i)%x==0:
     print((360*i)//x)
     break
# Judge status: Wrong Answer
N, K = [int(x) for x in input().split(" ")]
setlst = {int(x) for x in input().split(" ")}

print(K-len(setlst))
# Judge status: Accepted
S = str(input())
a = b = c = 0
for s in S:
    if s == 'a':
        a += 1
    elif s == 'b':
        b += 1
    elif s == 'c':
        c += 1

if abs(a-b) <= 1 and abs(b-c) <= 1 and abs(c-a) <= 1:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
def main():
    from functools import reduce

    N = int(input())

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

    def lcm(a, b):
        return a // gcd(a, b) * b

    ret = reduce(lcm, (int(input()) for _ in range(N)))
    print(ret)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
a, b, c, x, y =map(int, input().split())
ab = 2*c
i = 1
cost = 0
while True:
    cost = i *ab
    if i <= x  or i <= y:
        break
    i += 1
cost += a *(max(0, (x-i)))
cost += b *(max(0, (y-i)))
print(cost)
# Judge status: Wrong Answer
X = int(input('点数:'))

if 400 <= X <= 599:
    print(8)
if 600 <= X <= 799:
    print(7)
if 800 <= X <= 999:
    print(6)
if 1000 <= X <= 1199:
    print(5)
if 1200 <= X <= 1399:
    print(4)
if 1400 <= X <= 1599:
    print(3)
if 1600 <= X <= 1799:
    print(2)
if 1800 <= X <= 1999:
    print(1)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
c=0
d=sum(A)
for i in range(0,N-1):
    d-=A[i]
    c+=A[i]*d
    if(c>10**9+7):
        c%=(10**9+7)
print(c)
# Judge status: Accepted
K,S=map(int, input().split())
ans = 0
x = S//3+1
for i in range(x):
  y = (S-i)//2+1
  for j in range(i, y):
    k = S - i - j
    if k > K:
      continue
    if i == j == k:
      ans += 1
    elif i == j or j == k:
      ans += 3
    else:
      ans += 6
print(ans)
# Judge status: Wrong Answer
from sys import stdin
n = int(stdin.readline().rstrip())
s = "."+stdin.readline().rstrip()
point = 0
point2 = 0
for i in s:
    if i == ".":
        point += 1
    else:
        break
for j in s[::-1]:
    if j == "#":
        point2 += 1
    else:
        break
s = s[point:len(s)-point2]
S = len(s)
sharp = s.count("#")
flat = S-sharp
print(min(S-sharp,S-flat))
# Judge status: Accepted
import sys
def input(): return sys.stdin.readline().strip()


def main():
    s = input()
    print("2018" + s[4:])


if __name__ == "__main__":
    main()
# Judge status: Accepted
from fractions import gcd    # 最大公約数: gcd(x, y)
from functools import reduce
def gcd_list(numbers):
    return reduce(gcd, numbers)

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

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

    print(gcd_list(num_list))

if __name__ == '__main__':
    main()