Harryxun/stf_run huggingface dataset:
#AGC033-A-Darker and Darker
from collections import deque

h,w = map(int,input().split())
grid = [input() for i in range(h)]

#初期の黒('#')の位置からの距離
dist = [[-1]*w for _ in range(h)]

p = deque()
p.append((0,0))
d = 0
for i in range(h):
    for j in range(w):
        if grid[i][j] == '#':
            p.append((i,j))
            dist[i][j] = 0

while p:
    x,y = p.pop()
    d = dist[x][y]
    for dx,dy in (1,0),(0,1),(-1,0),(0,-1):
        if 0<= x+dx < w and 0<= y+dy < h and dist[y+dy][x+dx] == -1:
            dist[y+dy][x+dx] = d+1
            p.appendleft((x+dx,y+dy))

#distの最大値を出力
m = []
for i in range(h):
    m.append(max(dist[i]))
    
print(max(m))

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
grid = [input() for i in range(H)]

# 初期の黒('#')の位置からの距離
dist = [[-1]*W for _ in range(H)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append((h, w))
            dist[h][w] = 0

def bfs(black_cells, dist):
    """
    BFSを用いて、全マス目を黒くする回数を求める

    Args:
        black_cells: 「開始時の黒マス」の座標が入ったキュー（複数座標あり）
        dist: 「開始時の黒マス」からの距離の入ったリスト  [[-1, -1, 0], ...]
        　　　（白マスの初期値は0）

    Returns:
        g: 操作を繰り返した数
    """
    d = 0
    while black_cells:
        # キューとして使うのでpop()ではなくpopleft()
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:  # セルが白('.')であるのと同義
                dist[new_h][new_w] = d+1
                black_cells.append((new_h, new_w))
    return d

d = bfs(black_cells, dist)
print(d)
an = int(input())

numbers = [an]
while True:
	if an%2 == 1:
		an = 3*an+1
	else:
		an = an//2
	if an in numbers:
		print(len(numbers)+1)
        break
    else:
		numbers.append(an)

### FIXED CODE ###

an = int(input())

numbers = [an]
while True:
  if an%2 == 1:
    an = 3*an+1
  else:
    an = an//2
  if an in numbers:
    print(len(numbers)+1)
    break
  else:
    numbers.append(an)
from collections import defaultdict
MAX_N = 10 ** 3 + 10
MAX_M = 2 * (10 ** 3) + 1
INF = -(10 ** 100)

def bfs(graph, N, M):
    que = []
    que.append([0, 0])
    visited = defaultdict(list)
    result = INF
    while (len(que) > 0):
        now = que[0]
        que.pop(0)

        pos = now[0]
        cost = now[1]

        if (pos in visited):
            visited_cost = visited[pos][0]
            visited_cnt = visited[pos][1]
            if (visited_cost >= cost):
                continue
            if (visited_cnt >= 5 * MAX_N):
                return (0, False)
            visited[pos] = [cost, visited_cnt + 1]
        else:
            visited[pos] = [cost, 1]

        if (pos == N - 1):
            result = max(result, cost)

        for val in graph[pos]:
            nxt = val[0]
            nxt_cost = val[1]
            if (nxt not in visited):
                que.append([nxt, nxt_cost + cost])
            elif(nxt_cost + cost > visited[pos][0]):
                que.append([nxt, nxt_cost + cost])
    return (result, True)


if __name__ == "__main__":
    N, M = map(int, input().split())
    graph = defaultdict(list)
    for x in range(M):
        a,b,c = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append([b, c])
    res,ok = bfs(graph, N, M)
    if (not ok):
        assert(False)
    else:
        print (res)


### FIXED CODE ###


MAX_N = 10 ** 3 + 10
MAX_M = 2 * (10 ** 3) + 1
INF = 10 ** 13

def bfs(graph, N, M):
    que = []
    que.append([0, 0])
    visited = [-INF for x in range(MAX_N)]
    update_cnt = [0 for x in range(MAX_N)]
    result = -INF
    while (len(que) > 0):
        now = que[0]
        que.pop(0)

        pos = now[0]
        cost = now[1]
        if (visited[pos] > cost):
            continue
        for val in graph[pos]:
            nxt = val[0]
            nxt_cost = val[1]

            if (cost + nxt_cost > visited[nxt] and update_cnt[nxt] < MAX_M):
                visited[nxt] = cost + nxt_cost
                update_cnt[nxt] += 1
                que.append([nxt, nxt_cost + cost])

    if (update_cnt[N - 1] >= MAX_N):
        return (0, False)
    return (visited[N - 1], True)


if __name__ == "__main__":
    N, M = map(int, input().split())
    graph = [[] for x in range(MAX_N)]
    for x in range(M):
        a,b,c = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append([b, c])
    res,ok = bfs(graph, N, M)
    if (not ok):
        print ('inf')
    else:
        print (res)
A,B = =map(int,input().split())
x = A+B
y = A-B
z = A*B
print( max(x,y,z) )


### FIXED CODE ###

A,B = map(int,input().split())
x = A+B
y = A-B
z = A*B
print( max(x,y,z) )
import bisect
A, B, Q = list(map(int, input().split()))
S, T, X = [-INF], [-INF], []
for _ in range(A):
    S.append(int(input()))
for _ in range(B):
    T.append(int(input()))
for _ in range(Q):
    X.append(int(input()))
INF = 10 ** 12
S.append(INF)
T.append(INF)

for x in X:
    ans = INF
    sr = bisect.bisect_right(S, x)
    tr = bisect.bisect_right(T, x)
    for s in S[sr-1: sr+1]:
        for t in T[tr-1: tr+1]:
            ans = min(ans, abs(s-x) + abs(s-t), abs(t-x) + abs(s-t))
    print(ans)


### FIXED CODE ###

import bisect
A, B, Q = list(map(int, input().split()))
S, T, X = [], [], []
for _ in range(A):
    S.append(int(input()))
for _ in range(B):
    T.append(int(input()))
for _ in range(Q):
    X.append(int(input()))
INF = 10 ** 12
S = [-INF] + S + [INF]
T = [-INF] + T + [INF]

for x in X:
    ans = INF
    sr = bisect.bisect_right(S, x)
    tr = bisect.bisect_right(T, x)
    for s in S[sr-1: sr+1]:
        for t in T[tr-1: tr+1]:
            ans = min(ans, abs(s-x) + abs(s-t), abs(t-x) + abs(s-t))
    print(ans)
#66 A - Two Abbreviations
import math
N,M = map(int,input().split())
S = input()
T = input()

L = N*M//math.gcd(N,M)

dist_N = L//N
dist_M = L//M
lis = [0]*L

i = 0
for n in range(0,L,dist_N):
    lis[n] = S[i]
    i += 1
    print(lis)
    
j = 0
for m in range(0,L,dist_M):
    if lis[m] == 0:
        j += 1
    else:
        if lis[m] == T[j]:
            j += 1
        else:
            ans = -1
            break
    print(lis)
else:
    ans = L
print(ans)

### FIXED CODE ###

#66 A - Two Abbreviations
import math
N,M = map(int,input().split())
S = input()
T = input()

GCD = math.gcd(N,M)
L = N*M//GCD

dist_N = L//N
dist_M = L//M

# 同じ位置に書く文字は最大公約数 + 1 だけ存在する
for i in range(GCD):
    # S の s 文字目と T の t 文字目が同じ位置に来る
    s = dist_M * i
    t = dist_N * i
    if S[s] != T[t]:
        ans = -1
        break
else:
    ans = L
print(ans)
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * (n)
    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):

        x = self.find(x)
        y = self.find(y)

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x

            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same_check(self, x, y):

        return self.find(x) == self.find(y)


N, M = map(int, input().split())
*p, = map(int, input().split())
xy = [(*map(int,input().split()),) for _ in range(M)]
result = 0

union = UnionFind(N)
for x,y in xy:
    union.union(x-1,y-1)

for i in p:
    if union.same_check(p[i-1]-1,i-1):
        result += 1

print(result)

### FIXED CODE ###

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * (n)
    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):

        x = self.find(x)
        y = self.find(y)

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x

            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same_check(self, x, y):

        return self.find(x) == self.find(y)


N, M = map(int, input().split())
*p, = map(int, input().split())
xy = [map(int,input().split()) for _ in range(M)]
result = 0

union = UnionFind(N)
for x,y in xy:
    union.union(x-1,y-1)

for i in p:
    if union.same_check(p[i-1]-1,i-1):
        result += 1

print(result)
a = []
for i in range(5):
    a.append(i)
W = int(a[0])
H = int(a[1])
x = int(a[2])
y = int([3])
r = int(a[4])

if x>=r and W-x>=r and y>=r and H-y>=r:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

W,H,x,y,r = [int(i) for i in input().split(" ")]

print("No" if x < r or y < r or x + r > W or y + r > H else "Yes" )
n = int(input())
 
nodes = []
nodes_append = nodes.append
components = 0
for i in range(n - 1):
  edge = tuple(map(int, input().split()))
  node_max = max(edge)
  node_min = min(edge)
  if node_min not in nodes:
      nodes_append(node_min)
      components += node_min * (n - node_min + 1)
  if node_max not in nodes:
      nodes_append(node_max)
      components += node_max * (n - node_max + 1)
  num_edge = node_min * (n - node_max + 1)
  components -= num_edge
  
print(components)

### FIXED CODE ###

a = int(input())

if a % 1000 == 0:
  out = 0
else:
  out = 1000 - a % 1000

print(out)
import sys
import random
import bisect
from collections import deque

x = input().split()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n, m, time = int(x[0]), int(x[1]), int(x[2])

#n, m = 100000, 100000
#time = 100000000
#a = list(random.choices(range(10000), k=n))
#b = list(random.choices(range(10000), k=m))

a_sum, b_sum = cumsum(a), cumsum(b)

a_pos = bisect.bisect_left(a_sum, time)
b_pos = bisect.bisect_left(b_sum, time)
read = 0
for i in range(a_pos):
    bpos = bisect.bisect_left(b_sum, time-a_sum[i]+.1)
    read = max(read, i+bpos+1)

print (read)

def cumsum(a):
    tmp = 0
    ret = []
    for i in range(len(a)):
        tmp += a[i]
        ret.append(tmp)
    return ret


### FIXED CODE ###

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

a, b = [0], [0]
for i in range(N): a.append(a[i] + A[i])
for i in range(M): b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
n,m=map(int,input().split())
x=[]
y=[]
for i in range(m):
    a,b=map(int,input().split())
    x.append([a,b,i])
x.sort()
s=1
for i in range(m):
    c=x[i][0]
    if len(str(x[i][0]))<6:
        a=6-len(str(x[i][0]))
        b=["0"]*a
        for j in range(len(str(x[i][0]))):
            b.append(str(x[i][0])[j])
        x[i][0]="".join(b)
    if len(str(s))<6:
        a=6-len(str(s))
        b=["0"]*a
        for j in range(len(str(s))):
            b.append(str(s)[j])
        x[i].append("".join(b))
    if i<m-1:
        if c==x[i+1][0]:
            s+=1
        else:
            s=1
for i in range(m):
    y.append([x[i][2],x[i][0],x[i][3]])
y.sort()
for i in range(m):
    print(y[i][1]+y[i][2])

### FIXED CODE ###

n,m=map(int,input().split())
x=[]
y=[]
for i in range(m):
    a,b=map(int,input().split())
    x.append([a,b,i])
x.sort()
s=1
for i in range(m):
    c=x[i][0]
    a=6-len(str(x[i][0]))
    b=["0"]*a
    for j in range(len(str(x[i][0]))):
        b.append(str(x[i][0])[j])
    x[i][0]="".join(b)
    a=6-len(str(s))
    b=["0"]*a
    for j in range(len(str(s))):
        b.append(str(s)[j])
    x[i].append("".join(b))
    if i<m-1:
        if c==x[i+1][0]:
            s+=1
        else:
            s=1
for i in range(m):
    y.append([x[i][2],x[i][0],x[i][3]])
y.sort()
for i in range(m):
    print(y[i][1]+y[i][2])
l,r=map(int,input().split())
i=0
s=[]
if (r-l)>2019:
    print(0)
else:
    while i!=(r-l)+1:
        s.append(((l+i)%2019))
        i+=1
    s.sort()
print(s[0]*s[1])

### FIXED CODE ###

l,r=map(int,input().split())
s=[]
i=0
j=0
if (r-l)>4038:
    while i!=(r-l)+1 and i!=2019:
        while j!=(r-l)+1 and j!=2019:
            s.append(((l+i)*(l+j))%2019)
            j+=1
        j=0
        i+=1
    print(min(s))
else:
    while i!=(r-l)+1:
        while j!=(r-l)+1:
            if i!=j:
                s.append(((l+i)*(l+j))%2019)
            j+=1
        j=0
        i+=1
    #print(s)
    print(min(s))
a=input().split()
b=int(a[0])
data = [input() for i in range(+1)]
sort(data)

for j in data:
    c=c+j
    
print(c)



### FIXED CODE ###

a=input().split()
b=int(a[0])
data = [input() for i in range(b)]
data.sort()
#print(data)

k=""
for i in data:
    k=k+i
print(k)
#!/usr/bin/env python3
import sys
import math

MOD = 1000000007  # type: int
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def solve(N: int, K: int):
    re = N-K

    for i in range(1,K+1):
        split_pattern = combinations_count(K-1,i-1)
        print(split_pattern*combinations_count(re+1,i)%MOD)
        
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import math

MOD = 1000000007  # type: int
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def solve(N: int, K: int):
    for i in range(1,K+1):
        split_pattern = combinations_count(K-1,i-1)
        if N-K >= i-1:
            print((split_pattern*combinations_count(N-K+1,i))%MOD)
        else:
            print(0)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()
import pandas as pd

N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

t = [abs(A - (T - i*0.006)) for i in H]
print(pd.Series(t).idxmin()+1)

### FIXED CODE ###

N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

t = [abs(A - (T - i*0.006)) for i in H]
print(t.index(min(t))+1)
import itertools,math,numpy as np
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
xy = np.array([LI() for _ in range(N)])
sum_norm = 0
dict_norm = {}
for a in itertools.permutations(range(N)):
    for i in range(len(a)-1):
        vector = tuple(xy[a[i+1]]-xy[a[i]])
        if not vector in dict_norm:
            dict_norm[vector] = np.linalg.norm(vector)
            vector_inverse = tuple(vector[0]*-1,vector[1]*-1)
            dict_norm[vector_inverse] = dict_norm[vector]
        sum_norm += dict_norm[vector]
print(sum_norm/math.factorial(N))


### FIXED CODE ###

import itertools,math,numpy as np
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
xy = np.array([LI() for _ in range(N)])
sum_norm = 0
dict_norm = {}
for a in itertools.permutations(range(N)):
    for i in range(len(a)-1):
        vector = xy[a[i+1]]-xy[a[i]]
        if not tuple(vector) in dict_norm:
            dict_norm[tuple(vector)] = np.linalg.norm(vector)
        sum_norm += dict_norm[tuple(vector)]
print(sum_norm/math.factorial(N))
A=input()
cnt=0
if A[0]=='1':
    cnt++
if A[1]=='1':
    cnt++
if A[2]=='1':
    cnt++
print(cnt)

### FIXED CODE ###

A=input()
cnt=0
if A[0]=='1':
    cnt+=1
if A[1]=='1':
    cnt+=1
if A[2]=='1':
    cnt+=1
print(cnt)
A = int(input())
B = int(input())

if A <= 9 and B <= 9:
    print(A*B)
else:
    print("-1")


### FIXED CODE ###

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

if  data[0]<= 9 and data[1] <= 9:
    print(data[0]*data[1])
else:
    print("-1")
x, n = map(int, input().split(" "))
p = list(map(int, input().split(" ")))

p_under = list(filter(lambda v: v<x, p))
p_upper = list(filter(lambda v: v>x, p))
p_under.sort(reverse=True)
p_upper.sort()

cnt = 0
while(True):
    if x - cnt not in p_under:
        print(x - cnt)
        break
    if x + cnt not in p_upper:
        print(x + cnt)
        break
    cnt += 1


### FIXED CODE ###

x, n = map(int, input().split(" "))

if n == 0:
    print(x)
else:
    p = list(map(int, input().split(" ")))

    p_under = list(filter(lambda v: v<=x, p))
    p_upper = list(filter(lambda v: v>=x, p))
    p_under.sort(reverse=True)
    p_upper.sort()

    cnt = 0
    while(True):
        if x - cnt not in p_under:
            print(x - cnt)
            break
        if x + cnt not in p_upper:
            print(x + cnt)
            break
        cnt += 1
S=input()
if S==ABC
    print("ARC")
else:
    print("ABC")

### FIXED CODE ###

S=input()
if S=="ABC":
    print("ARC")
else:
    print("ABC")
from fractions import gcd

lcm = lambda x, y: x*y//gcd(x, y)

n, m = map(int, input().split())
s = input()
t = input()

L = lcm(n, m)
ans = ["0"]*L

for i in range(n):
    p = i*L//n
    ans[p] = s[i]

for j in range(m):
    q = j*L//m
    if ans[q] != "0" and ans[q] != t[j]:
        print(-1)
        exit()

print(L)

### FIXED CODE ###

from fractions import gcd

N, M = map(int, input().split())
s = input()
t = input()
g = gcd(N, M)
n, m = N//g, M//g

for i in range(g):
    if s[n*i] != t[m*i]:
        print(-1)
        exit()
print(N*M//g)
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
ans = A[0]

if N%2 == 0:
  for i in range(1,N/2):
    ans = ans + A[i]*2
if N%2 == 1:
  for i in range(1,(N-1)/2)
    ans = ans + A[i]*2
  ans += A[(N+1)/2]
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
ans = A[0]

if N%2 == 0:
  for i in range(1,int(N/2)):
    ans = ans + A[i]*2
if N%2 == 1:
  for i in range(1,int((N-1)/2)):
    ans = ans + A[i]*2
  ans += A[int((N-1)/2)]
print(ans)
X Y = map(int, raw_input().split())

print(X + Y//2)


### FIXED CODE ###

x, y = map(int, input().split())
print(x + y//2)
s=list(map(int,input().split())
s.sort()
print(max(10*s[0]+s[1]+s[2],s[0]+s[1]*10+s[2],s[0]+s[1]+s[2]*10))

### FIXED CODE ###

A,B,C=sorted(map(int,input().split()))
print(A+B+C*10)
import numpy as np
N, M, K = map(int, input().split())

A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

cum_A = np.cumsum(A)
cum_B = np.cumsum(B)

a = 0
b = 0

flg = False

if cum_A[N] + cum_B[M] <= K:
    ans = N + M
elif cum_A[N - 1] + cum_B[M] <= K:
    ans = N + M - 1
elif cum_A[N] + cum_B[M - 1] <= K:
    ans = N + M - 1
else:
    while True:
        if cum_A[a] <= cum_B[b]:
            if cum_A[a + 1] + cum_B[b] <= K:
                a += 1
            else:
                flg = True
        elif cum_A[a] > cum_B[b]:
            if cum_A[a] + cum_B[b + 1] <= K:
                b += 1
            else:
                flg = True
        
        if flg:
            ans = a + b
            break

print(ans)


### FIXED CODE ###

# author:  Taichicchi
# created: 15.09.2020 21:14:18

import sys

N, M, K = map(int, input().split())

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

a = [0]
b = [0]

for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans = 0
j = M

for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
a=int(input())
b=a[-1]
if b==3:
  print('bon')
elif b==2 or b==4 or b==5 or b==7 or b==9:
  print('hon')
else:
  print('pon')

### FIXED CODE ###

a=int(input())
b = a % 10
if b==3:
  print("bon")
elif b==2 or b==4 or b==5 or b==7 or b==9:
  print("hon")
else:
  print("pon")
A, B = int(input()) for i in range(2)
print("GREATER" if A>B else "EQOUL" if A=B else "LESS")

### FIXED CODE ###

A = int(input())
B = int(input())
print("GREATER" if A>B else "EQUAL" if A==B else "LESS")
from itertools import *

def merge(x,y):
  while 1:
    if x and y and x[0] >= y[0] or (not (x and y)) and x:
      yield x.pop(0)
    else y:
      yield y.pop(0)
    else:
      return

X, Y, A, B, C = map(int, input().split())
P = sorted(map(int, input().split()), reverse=True)
Q = sorted(map(int, input().split()), reverse=True)
R = sorted(map(int, input().split()), reverse=True)

S = sum(islice(merge(P,R), X))
S += sum(islice(merge(Q,R), Y))
print(S)

### FIXED CODE ###

from itertools import *
from heapq import *

X, Y, A, B, C = map(int, input().split())
P = sorted(map(lambda x:-int(x), input().split()))
Q = sorted(map(lambda x:-int(x), input().split()))
R = sorted(map(lambda x:-int(x), input().split()))

S = sum(islice(merge(islice(P, X),islice(Q, Y),R), X+Y))

print(-S)
N = int(input())
L = list(map(int,inptu().split()))
ave = sum(L) / len(L)
if ave * 10 % 10 >= 5:
  ave = int(ave) + 1
else:
  ave = int(ave)
ans = 0
for x in L:
  ans += (x - ave) **2
print(ans)

### FIXED CODE ###

N = int(input())
ans = 10**10
L = list(map(int,input().split()))
for i in range(-101,101): 
  tmp = 0
  for x in L:
    tmp += (i - x) ** 2
  ans = min(ans,tmp)
print(ans)
N = str(input())

for n in N:
    n = str(eval(10 - n))
    
print(int(n))

### FIXED CODE ###

N = str(input())

ans = ""
for n in N:
    formura = "10-{}".format(n)
    ans += str(eval(formura))

print(int(ans))
N,M = map(int,inpu().split())

def solve(N,M):
  # 今あるもの
  if M < N * 2:
    return N
  
  M -= N * 2
  
  ans = N + M // 3
  return ans

print(solve(N,M))


### FIXED CODE ###

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

def solve(N,M):
  # 今あるもの
  if M < N * 2:
    return M // 2
  
  M -= N * 2
  
  ans = N + (M // 4)
  return ans

print(solve(N,M))
(r, c) = [int(i) for i in input().split()]
src = []
for _ in range(r):
    row = ([int(i) for i in input().split()])
    row.append(sum(row))
    src.append(row)

last_row = [0 for _ in range(c+1)]
for rc in range(r):
    for cc in range(c):
        last_row += src[rc][cc]
src.append(last_row)

for rc in range(r+1):

### FIXED CODE ###

(r, c) = [int(i) for i in input().split()]
src = []
for _ in range(r):
    row = [int(i) for i in input().split()]
    row.append(sum(row))
    src.append(row)
last_row = [0 for _ in range(c + 1)]
for rc in range(r):
    for cc in range(c+1):
        last_row[cc] += src[rc][cc]
src.append(last_row)
 
for rc in range(r+1):
    print(' '.join([str(a) for a in src[rc]]))
import numpy as np

L, R = map(int, input().split())
range_L_R = np.array(list(range(L, R+1)))
range_L_R = range_L_R % 2019


if ((R>=673) and (L<=672)) or ((R>=675) and (L<=673)) or 0 in range_L_R:
    print(0)
else:
    print(L*(L+1) % 2019) 

### FIXED CODE ###

L, R = map(int, input().split())

ans = 2018

if R-L>=2019:
    print(0)
else:
    for i in list(range(L, R)):
        for j in list(range(i+1, R+1)):
            ans = min(ans, i*j % 2019)
    print(ans)
import math
from functools import reduce

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

if n == 1:
    ans = xx[0] - x
else:
    dist = [xx[i + 1] - xx[i] for i in range(n - 1)]
    ans = reduce(math.gcd, dist)

print(ans)


### FIXED CODE ###

import fractions
from functools import reduce

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

if n == 1:
    ans = xx[0]
else:
    ans = reduce(fractions.gcd, xx)

print(ans)