Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(4100000)

n = int(input())
a = list(map(int, input().split()))
ans = []
for i in a:
    ans.append(i)
    ans.reverse()
ans = [str(i) for i in ans]
output = " ".join(ans)
print(output)


### FIXED CODE ###

import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(4100000)

n = int(input())
a = list(map(int, input().split()))
ans = [-1] * (2 *10 ** 5 + 1)
left = False
right = False
if n % 2 == 0:
    left = True
else:
    right = True
start = n // 2
ans[start] = a[0]
for i in range(1, n):
    if left:
        ans[start - i] = a[i]
        start -= i
        left = False
        right = True
    else:
        ans[start + i] = a[i]
        start += i
        left = True
        right = False
for i in range(n):
    print(ans[i], " ", sep="", end="")
### BUGGY CODE ###

from sys import stdin
from itertools import combinations

n = int(stdin.readline().rstrip())
li = [stdin.readline().rstrip() for _ in range(n)]

lin = []

for i in range(n):
    if li[i][0] in "MARCH":
        lin.append(li[i][0])

liv = list(combinations(lin, 3))
point = 0
for i in liv:
    if i[0] != i[1] and i[0] != i[2] and i[2] != i[1]:
        point += 1
print(point)

### FIXED CODE ###

from sys import stdin
from itertools import combinations
from math import factorial

n = int(stdin.readline().rstrip())
li = [stdin.readline().rstrip() for _ in range(n)]

lin = [0]*5

for i in range(len(li)):
    if li[i][0] == "M":
        lin[0] += 1
    elif li[i][0] == "A":
        lin[1] += 1
    elif li[i][0] == "R":
        lin[2] += 1
    elif li[i][0] == "C":
        lin[3] += 1
    elif li[i][0] == "H":
        lin[4] += 1
        
lis = list(combinations(lin, 3))

point = 0
for i in lis:
    point += i[0]*i[1]*i[2]

print(point)
### BUGGY CODE ###

H,W=map(int,input().split())
g=[[True for j in range(W)] for i in range(H)] # 障害物がなければTrue
for i in range(H):
    S=input()
    for j in range(W):
        if S[j]=='#':
            g[i][j]=False
D=[[0 for j in range(W)] for i in range(H)]
U=[[0 for j in range(W)] for i in range(H)]
R=[[0 for j in range(W)] for i in range(H)]
L=[[0 for j in range(W)] for i in range(H)]

for i in range(H):
    for j in range(W):
        if g[i][j]:
            if j==0:
                L[i][j]=1
            else:
                L[i][j]=L[i][j-1]+1
    for j in reversed(range(W)):
        if g[i][j]:
            if j==W-1:
                R[i][j]=1
            else:
                R[i][j]=R[i][j+1]+1

for j in range(W):
    for i in range(H):
        if g[i][j]:
            if i==0:
                U[i][j]=1
            else:
                U[i][j]=U[i-1][j]+1
    for i in reversed(range(H)):
        if g[i][j]:
            if i==H-1:
                D[i][j]=1
            else:
                D[i][j]=D[i+1][j]+1

ans=0

for i in range(H):
    for j in range(W):
        if g[i][j]:
            ans=max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
            
print(ans)

### FIXED CODE ###

H,W=map(int,input().split())
s=[]
for i in range(H):
    si=[]
    Si=input()
    for j in range(W):
        si.append(Si[j]=='.')
    s.append(si)

# 左に照らした場合 行ごとに見てゆく
L=[[0 for j in range(W)] for i in range(H)]
for i in range(H):
    for j in range(W):
        if j==0 and s[i][j]:
            L[i][j]=1
        elif s[i][j]:
            L[i][j]=L[i][j-1]+1

# 右に照らした場合 行ごとに見てゆく
R=[[0 for j in range(W)] for i in range(H)]
for i in range(H):
    for j in reversed(range(W)):
        if j==W-1 and s[i][j]:
            R[i][j]=1
        elif s[i][j]:
            R[i][j]=R[i][j+1]+1

# 上に照らした場合 列ごとに見てゆく
U=[[0 for j in range(W)] for i in range(H)]
for j in range(W):
    for i in range(H):
        if i==0 and s[i][j]:
            U[i][j]=1
        elif s[i][j]:
            U[i][j]=U[i-1][j]+1

# 下に照らした場合 列ごとに見てゆく
D=[[0 for j in range(W)] for i in range(H)]
for j in range(W):
    for i in reversed(range(H)):
        if i==H-1 and s[i][j]:
            D[i][j]=1
        elif s[i][j]:
            D[i][j]=D[i+1][j]+1

ans=0
for i in range(H):
    for j in range(W):
        ans=max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)
### BUGGY CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]

for b,c in BC:
  for _ in range(b):
    A.append(c)
A = sorted(A,reverse = True)

print(sum(A[:N]))

### FIXED CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [(A[i], 1) for i in range(N)]
for _ in range(M):
    B, C = map(int, input().split())
    BC.append((C,B))
BC = sorted(BC,reverse = True)
ans = 0
a = 0
count = N
for c,b in BC:
  lamb = min(count,b)
  ans += c * lamb
  count -= lamb

print(ans)
### BUGGY CODE ###

import itertools
import math
from functools import reduce

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

k = int(input())

a = [i for i in range(1, k+1)]
b = [i for i in range(1, k+1)]
c = [i for i in range(1, k+1)]

product = list(itertools.product(a, b, c))

output = 0
for p in product:
    output += gcd_list(p)
    
print(output)


### FIXED CODE ###

import math
output = 0
K = int(input())
for i in range(1, K+1):
    for j in range(1, K+1):
        r = math.gcd(i, j)
        for k in range(1, K+1):
            output += math.gcd(r,k)
            
print(output)
### BUGGY CODE ###

n=int(input())
s=sorted([''.join(sorted(input())) for _ in range(n)])
ans=0
for x in set(s):
  cnt=s.count(x)
  ans+=cnt*(cnt-1)//2
print(ans)


### FIXED CODE ###

n=int(input())
s=[''.join(sorted(input())) for _ in range(n)]
ans=0
cnt={}
for i in range(n):
  if s[i] in cnt:
    cnt[s[i]]+=1
  else:
    cnt[s[i]]=1
print(sum(cnt[key]*(cnt[key]-1)//2 for key in cnt))
### BUGGY CODE ###

def gcd(x,y):
  n,m = min(x,y), max(x,y)
  while n!=0:
    n, m = m%n, n
  
  return m

def prime(N):
  p = [i+1 for i in range(N)]
  for i in range(2,N+1):
    p = [i_p for i_p in p if i_p%i!=0 or i_p/i==1]

  return p
def prime_factorization(N):
  n = N
  P = prime(int(N**0.5))
  p_f = [1]
  while n != 1:
    for p in P[1:]:
      if n%p == 0:
        p_f.append(p)
        n = n / p
        break
  return p_f

A, B = list(map(int, input().split(" ")))
print(len(set(prime_factorization(gcd(A, B)))))

### FIXED CODE ###

def gcd(x,y):
  n,m = min(x,y), max(x,y)
  while n!=0:
    n, m = m%n, n
  
  return m

def prime_factorization(N):
  f = 2
  p_f = []
  while N%f==0:
    p_f.append(f)
    N //= f
  f = 3
  while f**2 <= N:
    if N%f==0:
      p_f.append(f)
      N //= f
    else: f+=2
  if N!=1: p_f.append(N)
  return p_f

A, B = list(map(int, input().split(" ")))
print(1+len(set(prime_factorization(gcd(A, B)))))
### BUGGY CODE ###

input()
get_data = input().split(' ')  # String
default = 1
dup_list = list()
for v in get_data:
  if int(v) == default:
    dup_list.append(int(v))
  default += 1
 
del_count = 0
next_skip = False
for v in dup_list:
  if next_skip:
    next_skip = False
    continue
  if v+1 in dup_list:
    next_skip = True
  del_count += 1
  
print(del_count)

### FIXED CODE ###

input()
get_data = input().split(' ')  # String
default = 1
dup_list = list()
for v in get_data:
  if int(v) == default:
    dup_list.append(int(v))
  default += 1
 
del_count = 0
next_skip = False
for v in dup_list:
  if next_skip:
    next_skip = False
    continue
  if v+1 in dup_list:
    next_skip = True
  del_count += 1
  
print(del_count)
### BUGGY CODE ###

n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

for i in range(m):
    b, c = [int(i) for i in input().split()]
    a.extend([c]*b)

a.sort(reverse=True)

print(sum(a[:n]))



### FIXED CODE ###

import bisect
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
d = []
cnt = 1
for i in range(n-1):
    if a[i+1] == a[i]:
        cnt += 1
    else:
        d.append([a[i], cnt])
        cnt = 1
d.append([a[n-1], cnt])


for i in range(m):
    b, c = [int(i) for i in input().split()]
    d.append([c, b])
d.sort(reverse=True)
ans = 0
j = 0
for i in range(n):
    if d[j][1] > 0:
        ans += d[j][0]
        d[j][1] -= 1
    if d[j][1] == 0:
        j += 1
print(ans)
### BUGGY CODE ###

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

m = M//N

for x in range(m, 0, -1):
  if M % x == 0:
    print(x)
    break



### FIXED CODE ###

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

m = M//N

# def prime_factors(n):
#     i = 2
#     factors = OrderedDict()
#     while i * i <= n:
#         if n % i:
#             i += 1
#         else:
#             n //= i
#             if i in factors:
#               factors[i] += 1
#             else:
#               factors[i] = 1
#     if n > 1:
#       if n in factors:
#         factors[n] += 1
#       else:
#         factors[n] = 1
#     return factors

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

if M == 1:
  print(1)
  exit()

fct = factorize(M)
current_n = 1

for div in divisorize(fct):
    n = num(div)
    if n <= m and current_n < n:
      current_n = n

print(current_n)

# for x in range(m, 0, -1):
#   if M % x == 0:
#     print(x)
#     break
### BUGGY CODE ###

h,n=[int(j) for j in input().split()]
ab=[[int(j) for j in input().split()] for i in range(n)]
dp=[10**18]*(h+1)
dp[0]=0
ans=10**18
for a,b in ab:
    for i in range(h+1):
        if dp[i]!=10**18:
            if i+a<h:
                if dp[i]+b<dp[i+a]:
                    dp[i+a]=dp[i]+b
            else:
                if dp[i]+b<ans:
                    ans=dp[i]+b

print(ans)







### FIXED CODE ###

h,n=[int(j) for j in input().split()]
ab=[[int(j) for j in input().split()] for i in range(n)]
dp=[10**18]*(h+1)
dp[0]=0
ans=10**18
for a,b in ab:
    for i in range(h+1):
        if dp[i]!=10**18:
            if i+a<h:
                if dp[i]+b<dp[i+a]:
                    dp[i+a]=dp[i]+b
            else:
                if dp[i]+b<ans:
                    ans=dp[i]+b

print(ans)
### BUGGY CODE ###

s = input()

for _ in range(100000):
    s = s.replace('ST', '')
print(len(s))



### FIXED CODE ###

s = list(input())
l = []
for i in range(len(s)):
    if s[i] == 'S':
        l.append('S')
    elif not l:
        l.append('T')
    elif l[-1] == 'T':
        l.append('T')
    else:
        l.pop()
print(len(l))
### BUGGY CODE ###

n = int(input())
s = input()
del_n = n - 3
ch_n = len(s) - del_n
import itertools
lis = []
for i in itertools.combinations(s, ch_n):
    tmp_ch = ''.join(i)
    if tmp_ch not in lis:
        lis.append(tmp_ch)
print(len(lis))

### FIXED CODE ###

from string import digits

n = int(input())
s = input()

cnt = 0
for i in digits:
    x = s.find(i)
    if x == -1:
        continue
    for j in digits:
        y = s.find(j, x + 1)
        if y == -1:
            continue
        for k in digits:
            z = s.find(k, y + 1)
            if z == -1:
                continue
            cnt += 1

print(cnt)
### BUGGY CODE ###

import numpy as np
#import math
N, K = map(int, input().split())
A = np.array(sorted(list(map(int, input().split()))))
F = np.array(sorted(list(map(int, input().split())), reverse=True))

C = A*F

left = - 1
right = max(C)

def f(x):
    cnt = 0
    for i in range(N):
        if C[i] > x:
            #cnt += math.ceil((C[i] - x)/F[i])
            cnt += (C[i] - x + F[i] - 1)//F[i]
            if cnt > K:
                return False
    return True

while right - left > 1:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid
    
print(right)

### FIXED CODE ###

import numpy as np
N, K = map(int, input().split())
A = np.array(sorted(list(map(int, input().split()))))
F = np.array(sorted(list(map(int, input().split())), reverse=True))

left = - 1
right = 10**12

def f(x):
    return np.maximum(0, A - x//F) .sum()<= K

while right - left > 1:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid
    
print(right)
### BUGGY CODE ###

import math
import fractions

#最小公倍数
def union_lcm(lists):
    if len(lists)==1:
        return lists[0]
    elif len(lists)>1:
        num=lists[0]
        for i in range(1,len(lists)):
            num=num*lists[i]//fractions.gcd(num,lists[i])
        return num


#最大公約数
def union_gcd(lists):
    if len(lists)==1:
        return lists[0]
    elif len(lists)>1:
        num=lists[0]
        for i in range(1,len(lists)):
            num=fractions.gcd(num,lists[i])
        return num
mod=10**9+7   
n=int(input())
lists=list(map(int,input().split()))
a=union_lcm(lists)

c=0
for i in range(n):
    c+=a//lists[i]
    c=c%mod
print(c)

### FIXED CODE ###

import math
import fractions
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

#最小公倍数
def union_lcm(lists):
    if len(lists)==1:
        return lists[0]
    elif len(lists)>1:
        num=lists[0]
        for i in range(1,len(lists)):
            num=num*lists[i]//fractions.gcd(num,lists[i])
        return num


#最大公約数
def union_gcd(lists):
    if len(lists)==1:
        return lists[0]
    elif len(lists)>1:
        num=lists[0]
        for i in range(1,len(lists)):
            num=fractions.gcd(num,lists[i])
        return num
mod=10**9+7   
n=int(input())
lists=list(map(int,input().split()))
a=union_lcm(lists)
c=0
a=a%mod

for i in range(n):
    c+=a*modinv(lists[i],mod)
    c=c%mod
print(c)
### BUGGY CODE ###

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

K = min(K, 100)
for _ in range(K):
    B = [0 for _ in range(N)]
    for i in range(N):
        l = max(0, i - A[i])
        r = min(N - 1, i + A[i])
        B[l] += 1
        if r+1 < N:
            B[r+1] -= 1
    
    for i in range(1, N):
        B[i] += B[i-1]
    
    A = B.copy()

print(" ".join(map(str, A)))

### FIXED CODE ###

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

for _ in range(K):
    B = [0] * N
    for i, d in enumerate(A):
        l = max(0, i-d)
        r = min(N-1, i+d)
        B[l] += 1
        if r+1 < N:
            B[r+1] -= 1
    
    for i in range(1, N):
        B[i] += B[i-1]
    
    A = B.copy()
    if min(A) == N:
        break

print(" ".join(map(str, A)))
### BUGGY CODE ###

from collections import deque

N=int(input())
tree=[[] for _ in range(N)]
for _ in range(N-1):
  u,v,w=map(int,input().split())
  tree[u-1].append((v-1,w))
  tree[v-1].append((u-1,w))
ans=[-1]*N
ans[0]=0
d=deque([0])
done=[0]
while d:
  p=deque.popleft(d)
  color=ans[p]
  for v,w in tree[p]:
    if not v in done:
      deque.append(d,v)
      done.append(v)
      ans[v]=color^(w%2)
print(*ans,sep='\n')

### FIXED CODE ###

import sys
from collections import deque
input=sys.stdin.readline
N=int(input())
tree=[[] for _ in range(N)]
for _ in range(N-1):
  u,v,w=map(int,input().split())
  tree[u-1].append((v-1,w))
  tree[v-1].append((u-1,w))
ans=[-1]*N
ans[0]=0
d=deque([0])
while d:
  p=deque.popleft(d)
  color=ans[p]
  for v,w in tree[p]:
    if ans[v]==-1:
      deque.append(d,v)
      ans[v]=color^(w%2)
print(*ans,sep='\n')
### BUGGY CODE ###

import sys
inputs = sys.stdin.readline
N, Q= map(int,inputs().split())
V = [list(map(int,inputs().split())) for p in [0]*N]

for q in [0]*Q:
	ans = sys.maxsize
	m = int(inputs())
	for n in range(N):
		if V[n][0] - V[n][2] <=m and m <= V[n][1] - V[n][2] -1:
			ans = min(V[n][2],ans)
	if ans < sys.maxsize:
		print(ans)
	else:
		print(-1)

### FIXED CODE ###

import sys
from operator import itemgetter
def main():
	inputs = sys.stdin.readline
	N, Q= map(int,inputs().split())
	E = [None]*2*N
	for n in range(N):
		a,b,c = map(int,inputs().split())
		E[2*n] = (a - c, 1, c)
		E[2*n + 1] = (b - c, -1, c)
	E.sort(key=itemgetter(0))
	tuple(tuple(E))
	mini = 1000000001
	kouho = {1000000001}
	my_add = kouho.add
	my_discard = kouho.discard
	q = 0
	d = int(inputs())
	flag = False
	cont = False
	for e in E:
		while e[0] > d:
			if cont == True:
				print(mini-(mini//1000000001)*1000000002)
			else:
				mini = min(kouho)
				print(mini-(mini//1000000001)*1000000002)
			cont = True
			q = q + 1
			if q > Q-1:
				flag = True
				break
			d = int(inputs())
		if flag == True:
			break
		if e[1] == 1:
			my_add(e[2])
			if mini > e[2]:
				mini = e[2]
		elif e[1] == -1:
			my_discard(e[2])
			if mini == e[2]:
				cont = False
	for t in [None]*(Q-q):
		print(-1)
main()
### BUGGY CODE ###

List = list(map(int, input().split()))
x = List[0]
y = abs(x-List[1])

while x >= y:
    z = abs(x-List[1])
    x = y
    y = z

print(x)

### FIXED CODE ###

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

if List[0]%List[1] >= abs(List[0]%List[1] - List[1]):
    print(abs(List[0]%List[1] - List[1]))
else:
    print(abs(List[0]%List[1]))
### BUGGY CODE ###

import queue
def dist(s, t, g):
    q = queue.Queue()
    dists = [-1]*len(g)
    dists[s] = 0
    q.put(s)
    while not q.empty():
        target = q.get()
        for v in g[target]:
            if dists[v] == -1:
                dists[v] = dists[target] + 1
                q.put(v)
    return dists[t]

def main():
    n, m = map(int, input().split())
    g = [[] for _ in range(n*3)]
    for _ in range(m):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        g[u].append(v+n)
        g[u+n].append(v+2*n)
        g[u+2*n].append(v)
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    print(dist(s, t, g)//3)

if __name__ == "__main__":
    main()

### FIXED CODE ###

def dist(s, t, g):
    q = [s]
    dists = [-1]*len(g)
    dists[s] = 0
    while len(q) != 0:
        p = []
        for u in q:
            for v in g[u]:
                if dists[v] != -1:
                    continue
                p.append(v)
                dists[v] = dists[u] + 1
        q = p
    return dists[t]

def main():
    n, m = map(int, input().split())
    g = [[] for _ in range(n*3)]
    for _ in range(m):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        g[u].append(v+n)
        g[u+n].append(v+2*n)
        g[u+2*n].append(v)
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    print(dist(s, t, g)//3)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

import collections

n = int(input())
ls = []
for i in range(n):
    s = input()
    ls.append(s)
c = collections.Counter(ls)
ls2 = [i for i in c if c[i] == max(c.values())]
for l in sorted(ls2):
    print(l)

### FIXED CODE ###

n = int(input())
dic = {}
for i in range(n):
    s = input()
    if not s in dic.keys():
        dic[s]=1
    else:
        dic[s]+=1
maxv = max(dic.values())
ls = [i for i in dic if dic[i] == maxv]
for key in sorted(ls):
    print(key)
### BUGGY CODE ###

import collections

N = int(input())
S = list(input() for i in range(N))

c = collections.Counter(S)

max_k_list = [kv[0] for kv in c.items() if kv[1] == max(c.values())]

max_k_list.sort()

for i in max_k_list:
    print(i)


### FIXED CODE ###

import collections

N = int(input())
S = list(input() for i in range(N))
dict = {}

for l in S:
        if l in dict:
            dict[l] += 1;
        else:
            dict[l] = 1;
            
max = max(dict.values())

max_k_list = [kv[0] for kv in dict.items() if kv[1] == max]

max_k_list.sort()

for i in max_k_list:
    print(i)
### BUGGY CODE ###

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

def pc(x):
    return format(x, 'b').count('1')

N = int(input())
X = input()
Xn = int(X,2)
p = pc(Xn)
X = list(X)

Xp = Xn%(p+1)
if p==1:
    Xm = 0
else:
    Xm = Xn%(p-1)

def f(i):
    if p==1 and X[i]=='1':
        #Xi == 0 > POPcount ==0
        return 0
    else:
        if X[i]=='1':
            # p->p-1
            pn = p-1
            ret = Xm - pow(2, N-1-i)%pn
        else:
            # p->p+1
            pn = p+1
            ret = Xp + pow(2, N-1-i)%pn
        ret %= pn
        cnt = 1
        while ret > 0:
            ret %= pc(ret)
            cnt += 1
        return cnt

def main():
    for i in range(N):
        ret = f(i)
        print(ret)

if __name__ == '__main__':
    main()


### FIXED CODE ###

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

def pc(x):
    return format(x, 'b').count('1')

N = int(input())
X = input()
Xn = int(X,2)
p = pc(Xn)
X = list(X)

Xp = Xn%(p+1)
if p==1:
    Xm = 0
else:
    Xm = Xn%(p-1)

def f(i):
    if p==1 and X[i]=='1':
        #Xi == 0 > POPcount ==0
        return 0
    else:
        if X[i]=='1':
            # p->p-1
            ret = Xm - pow(2, N-1-i, p-1)
            ret %= p-1
        else:
            # p->p+1
            ret = Xp + pow(2, N-1-i, p+1)
            ret %= p+1
        cnt = 1
        while ret > 0:
            ret %= pc(ret)
            cnt += 1
        return cnt

def main():
    for i in range(N):
        ret = f(i)
        print(ret)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import deque

H, W = map(int, input().split())

INF = 10**9
n_i = [-1, 0, 1, 0]
n_j = [0, -1, 0, 1]
a = [input() for i in range(H)]

dist_map = [[INF]*W for _ in range(H)]

# 黒マスの位置を記録
q = deque([])
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            q.append([i, j, 0])

max_dist = 0
def update(c_h, c_w, d_map, dist, q):
    global max_dist
    if d_map[c_h][c_w] != INF:
        return
    if max_dist < dist:
        max_dist = dist
    d_map[c_h][c_w] = dist
    for dir in range(4):
        if c_h+n_i[dir] < 0 or H <= c_h+n_i[dir] or c_w+n_j[dir] < 0 or W <= c_w+n_j[dir]:
            continue
        if a[c_h+n_i[dir]][c_w+n_j[dir]] == "#":
            continue
        q.append((c_h+n_i[dir], c_w+n_j[dir], dist+1))

while len(q) > 0:
    current = q.popleft()
    current_h = current[0]
    current_w = current[1]
    dist = current[2]
    update(current_h, current_w, dist_map, dist, q)


print(max_dist)


### FIXED CODE ###

from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)
### BUGGY CODE ###

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

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

if M > N:
    
    for i in range(N-1):
        difX.pop(difX.index(max(difX)))

    total = 0
    for x in difX:
        total+= x

    print(total)
else:
    print(0)

### FIXED CODE ###

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

difX = []
for i in range(len(X)-1):
    difX.append(X[i+1]-X[i])
difX.sort(reverse=True)

if M > N:

    difX = difX[N-1:]

    total = 0
    for x in difX:
        total+= x

    print(total)
else:
    print(0)