Harryxun/stf_run huggingface dataset:
K, N = list(map(int, input().split()))
an = list(map(int,input().split()))

min_list = []
for i in range(N):
    if i == 0:
        left = an[i] + K - an[-1]
        right = an[i+1] - an[i]
    elif i == N-1:
        left = an[i] - an[i-1]
        right = an[0] + K - an[N-1]
    else:
        left = an[i] - an[i-1]
        right = an[i+1] - an[i]
    min_list.append(min(K-left, K-right))
print(min(n_list))

### FIXED CODE ###

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

min_list = []
for i in range(N):
    if i == 0:
        left = an[i] + K - an[-1]
        right = an[i+1] - an[i]
    elif i == N-1:
        left = an[i] - an[i-1]
        right = an[0] + K - an[N-1]
    else:
        left = an[i] - an[i-1]
        right = an[i+1] - an[i]
    min_list.append(min(K-left, K-right))
print(min(min_list))
# -*- coding: utf-8 -*-
n = int(input())
s = str(input())
s = s.replace(".", "0").replace('#', "1")
b = s.find("1")
a = 0
for i in range(b, n):
    a+=int(s[i])
s = [int(n) for n in s]
sums = sum(list(s))
print(min(sums, n-sums, n-b-a))

### FIXED CODE ###

# -*- coding: utf-8 -*-
 
# スペース区切りの整数の入力
a, b, c = map(int, input().split())
if a < c and c < b:
    print("Yes")
elif b < c and c < a:
    print("Yes")
else:
    print("No")
N, u, v = map(int, input().split())
u -= 1
v -= 1

e_list = [[] for _ in range(N)]

for _ in range(N - 1):
	a, b = map(int, input().split())
	a -= 1
	b -= 1
	e_list[a].append(b)
	e_list[b].append(a)

def calc_depth_table(v):
	queue = [[v, None, 0]]
	depth_table = [0] * N
	depth_table[v] = 0
	
	while queue:
		cur, pre, depth = queue.pop()
		depth += 1
		for n in e_list[cur]:
			if n != pre:
				queue.append([n, cur, depth])
				depth_table[n] = depth
	return depth_table

def calc_depth_table2(depth_from_v, u):
	queue = [[u, None, 0, depth_from_v[u], u]]
	depth_table = [0] * N
	depth_table[u] = (0, depth_from_v[u], u)
	
	while queue:
		cur, pre, depth, min_depth_from_v, min_depth_point = queue.pop()
		depth += 1
		for n in e_list[cur]:
			if n != pre:
				depth2 = depth_from_v[n]
				if min_depth_from_v > depth2:
					new_min_depth = depth2
					new_min_depth_point = n
				else:
					new_min_depth = min_depth_from_v
					new_min_depth_point = min_depth_point
				queue.append([n, cur, depth, new_min_depth, new_min_depth_point])
				depth_table[n] = (depth, new_min_depth, new_min_depth_point)
	return depth_table

depth_from_v = calc_depth_table(v)
depth_from_u = calc_depth_table2(depth_from_v, u)

#print(depth_from_v)
#print(depth_from_u)

max_count = 0
for i in range(N):
	a_dist = depth_from_v[i]
	t_dist, a_hit_dist, hit_pos = depth_from_u[i]
	t_hit_dist = depth_from_u[hit_pos][0]
	
#	print(t_hit_dist, a_hit_dist)
	if t_hit_dist < a_hit_dist:
#		print(t_hit_dist, a_hit_dist)
#		if (a_hit_dist - t_hit_dist) % 2 == 1:
		if max_count < a_dist - 1:
			max_count = a_dist - 1
#			else:
#				

print(max_count)


### FIXED CODE ###

answers = ["1", "2", "3"]
answers.remove(input().strip())
answers.remove(input().strip())
print(answers[0])
def insertionSort(A,n,g):
    for i in range(g,n,1):
        v = int(A[i])
        j = i - g
        while j >= 0 and int(A[j]) > v:
            global cnt
            A[j + g] = A[j]
            j = j - g
            cnt = cnt + 1
        A[j+g] = str(v)
            
def shellSort(A,n):
    global cnt
    global G
    G = []
    cnt = 0
    h = 1
    while h <= n:
        G.append(h)
        h = 3*h + 1
        
    m = len(G)
    print(m)
    G.reverse()
    print(' '.join(map(str, G)))
    for i in range(0,m,1):
        insertionSort(A,n,G[i])
    print(cnt)
        

n = int(input())
#改行で標準入力を受け付ける場合
A = [0] * n
for i in range(n):
    A[i] = input()
shellSort(A,n)
print('\n'.join(A))


### FIXED CODE ###

import sys


def print_A(A):
    for i in range(len(A)):
        sys.stdout.write(str(A[i]))
        if i!= len(A) -1:
            sys.stdout.write(' ')
    print()


def insertionSort(A,n,g):
    cnt = 0
    for i in range(g,n):
        v = A[i]
        j = i - g
        while (j>=0) and (A[j] > v):
            A[j + g] = A[j]
            j -= g
            cnt +=1
        A[j + g] = v
    return cnt

def shellSort(A,n,G):
    cnt = 0
    for i in range(len(G)):
        cnt += insertionSort(A,n,G[i])
    return cnt
        

def get_gap(n):
    G = []
    h = 1
    cnt = 1
    while h <= n:
        G.append(h)
        h = 3*h + 1
        cnt +=1
    if len(G) == 0: G.append(1)
    return list(reversed(G))


n = int(input())
A = [0] * n
for i in range(n):
    A[i] = int(input())
    
G = get_gap(n)
m = len(G)
cnt = shellSort(A,n,G)

print(m)
print_A(G)
print(cnt)
for i in range(n):
    print(A[i])
n = int(input())
x = list(map(int, input().split()))
import math
a = 0
b = 1
for i in range(n):
  a += math.log(x[i], 10)
if a > 18:
  print('-1')
else:
  for i in range(n):
    b *= x[i]
  print(b)

### FIXED CODE ###

n = int(input())
x = list(map(int, input().split()))
a = 1
flag = True
for i in range(n):
  a *= x[i]
  if a > 10**18:
    if 0 in x:
      print(0)
    else:
      print('-1')
    flag = False
    break
if flag:
  print(a)
s,k=map(int,input().split())
print(len([z for x in range(0,k+1) for y in range(0,k+1) if 0<=s-x-y<=k]))

### FIXED CODE ###

k,s=map(int,input().split())
print(len([1 for z in range(k+1) for y in range(k+1) if 0<=s-y-z<=k]))
N = int(input())
Y = int(input())

ans = [-1,-1,-1]
for x in range(N):
    for y in range(N):
        for z in range(N):
            if x+y+z==N and 10000*x+5000*y+1000*z==Y:
                ans[0] = x
                ans[1] = y
                ans[2] = z

print("{0} {1} {2}".format(ans[0],ans[1],ans[2]))

### FIXED CODE ###

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

ans = [-1,-1,-1]
for x in range(N+1):
    for y in range(N+1):
        k = N-x-y
        if k>=0 and 10000*x+5000*y+1000*k==Y:
                ans[0] = x
                ans[1] = y
                ans[2] = k

print(ans[0],ans[1],ans[2])
s = int(input())

if s == 2:
  print(4)
elif s == 4:
  print(4)
elif s == 1:
  print(4)
else:
  count = 2
  while s > 1:
  	count+=1
  	if s % 2 == 0:
    	s = s//2
  	else:
    	s = 3*s+1
  print(count)

### FIXED CODE ###

s = int(input())
l=[]
count = 1

while s not in l:
  l.append(s)
  count+=1
  if s % 2 == 0:
    s = s//2
  else:
    s = 3*s+1

print(count)
s = list(map(str, input()))
display = []
for action in s:
    if action == '0':
        display.append('0')
    elif action == '1':
        display.append('1')
    elif action == 'B':
        display.pop()
print(''.join(display))

### FIXED CODE ###

s = list(map(str, input()))
display = []
for action in s:
    if action == '0':
        display.append('0')
    elif action == '1':
        display.append('1')
    elif action == 'B':
        if len(display) > 0:
            display.pop()
print(''.join(display))
def mk_idx(y,x):
    return y*22+x

H,W=map(int, input().split())
DINF = 100000
S = []
S.append('#' * (W+2))
for i in range(H):
    S.append('#'+ input() + '#')
S.append('#' * (W+2))
dmax = 0
G = [ [] for _ in range( mk_idx(22,22) ) ]
for y in range(1,H+1):
    for x in range(1,W+1):
        if (S[y][x] == '.'):
            idx = mk_idx(y,x)
            if (S[y-1][x] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y-1,x) )
            if (S[y][x-1] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y,x-1) )
            if (S[y+1][x] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y+1,x) )
            if (S[y][x+1] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y,x+1) )

for y in range(1,H+1):
    for x in range(1,W+1):
        if S[y][x] == '.':
            d = [ DINF for _ in range( mk_idx(22,22) ) ]
            d[ mk_idx(y,x) ] = 0
            q = deque( [mk_idx(y,x)] )
            while len(q) != 0:
                v = q.popleft()
                n = d[v];
                dmax = max(dmax, n)
                for nv in G[v]:
                    if d[ nv ] <= n+1 :
                        continue
                    d[ nv ] = n+1
                    q.append(nv)
print(dmax)





### FIXED CODE ###

from collections import deque

def mk_idx(y,x):
    return y*22+x

H,W=map(int, input().split())
DINF = 100000
S = []
S.append('#' * (W+2))
for i in range(H):
    S.append('#'+ input() + '#')
S.append('#' * (W+2))
dmax = 0
G = [ [] for _ in range( mk_idx(22,22) ) ]
for y in range(1,H+1):
    for x in range(1,W+1):
        if (S[y][x] == '.'):
            if (S[y-1][x] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y-1,x) )
            if (S[y][x-1] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y,x-1) )
            if (S[y+1][x] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y+1,x) )
            if (S[y][x+1] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y,x+1) )

for y in range(1,H+1):
    for x in range(1,W+1):
        if S[y][x] == '.':
            d = [ DINF for _ in range( mk_idx(22,22) ) ]
            d[ mk_idx(y,x) ] = 0
            q = deque( [mk_idx(y,x)] )
            while len(q) != 0:
                v = q.popleft()
                n = d[v];
                dmax = max(dmax, n)
                for nv in G[v]:
                    if d[ nv ] <= n+1 :
                        continue
                    d[ nv ] = n+1
                    q.append(nv)
print(dmax)
str = input().split()
a = str[0]
a_len = len(a)
b = str[1]
b_r = str[:-1]


if b_r == a and a_len <= 10 and a_len >= 1:
 	print("Yes")
else:
	print("No")

### FIXED CODE ###

a = input()
b = input()

a_len = len(a)
b_r = b[:-1]

if b_r == a and a_len <= 10 and a_len >= 1:
 	print("Yes")
else:
	print("No")
A = int(input())
B = int(input())

if A == 1:
  A = 14
if B == 1:
  B = 14

if A == B:
  print("Draw")
elif A > B:
  print("Alice")
else:
  print("Bob")

### FIXED CODE ###

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

if A == 1:
  A = 14
if B == 1:
  B = 14

if A == B:
  print("Draw")
elif A > B:
  print("Alice")
else:
  print("Bob")
from fractions import gcd
import math
import numpy as np
N = list(map(int, input().split()))
g = gcd(N[0], N[1])
primes = np.ones(g+2)
primes[0:2] = 0
for i in range(2, int(np.sqrt(g))+1+1):
  if primes[i] and i * 2 < g + 2:
    primes[i*2::i] = 0

count = 0
for i in range(2,g+1):
  if primes[i] and g%i == 0:
    count += 1
print(count + 1)


### FIXED CODE ###

from fractions import gcd
import math
import numpy as np
N = list(map(int, input().split()))
g = gcd(N[0], N[1])

def factorize(g):
  factor = []
  for i in range(2, int(np.sqrt(g))+2):
    if g % i != 0:
      continue
    while g % i == 0:
      g //= i
    factor.append(i)
  if g != 1:
    factor.append(g)
  return factor
print(len(factorize(g))+1)
s=input()
print("2018"+s[4:]

### FIXED CODE ###

s=input()
print("2018"+s[4:])
N = int(input())
a = [int(input()) for i in range(N)]
a.sort()
for k in range(N-1):
    if a[k] == a[k+1]:
        a[k] =-1

b=[a[k] for k in range(N) if a[k] != -1]

a.remove(-1)
print(len(b))


### FIXED CODE ###


N = int(input())
a = [int(input()) for i in range(N)]
a.sort()
for k in range(N-1):
    if a[k] == a[k+1]:
        a[k] =-1

b=[a[k] for k in range(N) if a[k] != -1]
print(len(b))
s=input()
t=input()
cnt=0
for i in rage(len(s)):
  if s[i]==t[i]:
    cnt+=1

print(cnt)

### FIXED CODE ###

s=input()
t=input()
cnt=0
for i in range(len(s)):
  if s[i]==t[i]:
    cnt+=1
 
print(cnt)
N=input()
ST=input()
S=ST.split(0,N)
T=ST.split(N,2*N)

for i in range(N):
  result.append(S[i])
  result.append(T[i])
  
print(result)

### FIXED CODE ###

N=input()
ST=input()
S=ST.split(' ')[0]
T=ST.split(' ')[1]
result=''

for i in range(int(N)):
  result+=S[i]
  result+=T[i]
  
print(result)
N, M = map(int, input().split())

Pi = []
for i in range(M):
     p, y = map(int, input().split())
     Pi.append([p, y, i])

def fill(t):
    s = str(t)
    while len(s) < 6:
        s = "0" + s
    return s

Pi.sort(key=lambda x: x[1])
counts = [1] * (M + 1)
for p in Pi:
    city = p[0]
    num = counts[city]
    counts[city] += 1
    p.append(fill(city) + fill(num))

Pi.sort(key=lambda x: x[2])
for p in Pi:
    print(p[3])


### FIXED CODE ###

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

Pi = []
for i in range(M):
     p, y = map(int, input().split())
     Pi.append([p, y, i])

def fill(t):
    s = str(t)
    while len(s) < 6:
        s = "0" + s
    return s

Pi.sort(key=lambda x: x[1])
counts = [1] * (N + 1)
for p in Pi:
    city = p[0]
    num = counts[city]
    counts[city] += 1
    p.append(fill(city) + fill(num))

Pi.sort(key=lambda x: x[2])
for p in Pi:
    print(p[3])
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
po = sorted([ai for ai in a if ai > 0], reverse=True)
ne = sorted(ai for ai in a if ai < 0)
ze = 0 in a
mod = 10**9 + 7
c = 1
if len(po) == 0 or len(po) + len(ne) // 2 * 2 < k:
    if ze:
        print(0)
    else:
        for bi in sorted(po + ne, key=abs)[:k]:
            c = c * bi % mod
        print(c)
elif len(ne) == 0:
    for ai in sorted(a, reverse=True):
        c = c * ai % mod
    print(c)
else:
    if len(po) >= k:
        pi = k - 1
        ni = -1
        pc = po[:k]
        nc = []
    else:
        if (k - len(po)) % 2:
            pi = len(po) - 2
            pc = po[:-1]
        else:
            pi = len(po) - 1
            pc = po
        ni = k - len(pc) - 1
        nc = ne[:k - len(pc)]
    for _ in range(len(pc) // 2):
        if ne[ni + 1] * ne[ni + 2] < po[pi - 1] * po[pi - 2]:
            break
        nc = nc + ne[ni + 1:ni + 3]
        pc = pc [:-2]
        ni += 2
        pi -= 2
    for pp in pc:
        c = c * pp % mod
    for nn in nc:
        c = c * nn % mod
    print(c)


### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    a = sorted([int(i) for i in input().split()], reverse=True)
    mod = 10**9 + 7
    p = 1
    if n == k:
        for ai in a:
            p = p * ai % mod
        print(p)
        return
    if a[0] < 0 and k % 2:
        for ai in a[:k]:
            p = p * ai % mod
        print(p)
        return
    b = sorted([(abs(ai), ai) for ai in a], reverse=True)
    s = 0
    for ba, bb in b[:k]:
        p = p * ba % mod
        if bb < 0:
            s += 1
    if s % 2 == 0:
        print(p)
        return
    pa, na, pb, nb = [-1] * 4
    for ba, bb in b[:k]:
        if bb < 0:
            na = ba
        else:
            pa = ba
    for ba, bb in b[k:][::-1]:
        if bb < 0:
            nb = ba
        else:
            pb = ba
    if pa == -1 or nb == -1:
        print(p * pb * pow(na, mod - 2, mod) % mod)
    elif pb == -1 or na == -1:
        print(p * nb * pow(pa, mod - 2, mod) % mod)
    elif pa * pb > na * nb:
        print(p * pb * pow(na, mod - 2, mod) % mod)
    else:
        print(p * nb * pow(pa, mod - 2, mod) % mod)


if __name__ == '__main__':
    main()
#
# abc071 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
3 1 2 4 2 1"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 2 3 4"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10
3 3 3 3 4 4 4 5 5 5"""
        output = """20"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    Num = [0] * 10**9
    for a in A:
        Num[a-1] += 1

    l1 = l2 = 0
    for i in range(N-1, -1, -1):
        if l1 == 0:
            if Num[i] >= 2:
                l1 = i+1
                if Num[i] >= 4:
                    l2 = i+1
                    break
        else:
            if Num[i] >= 2:
                l2 = i+1
                break

    print(l1*l2)


if __name__ == "__main__":
    # unittest.main()
    resolve()


### FIXED CODE ###

#
# abc071 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
3 1 2 4 2 1"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 2 3 4"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10
3 3 3 3 4 4 4 5 5 5"""
        output = """20"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    A.sort(reverse=True)
    l1 = l2 = 0
    for i in range(1, N):
        if l1 == 0:
            if A[i] == A[i-1]:
                l1 = A[i-1]
        else:
            if i < N-1 and A[i+1] == A[i]:
                l2 = A[i]
                break

    print(l1*l2)


if __name__ == "__main__":
    # unittest.main()
    resolve()
text = ""
for i in range(1, n+1):
	if i % 3 == 0:
		text += " " + str(i)
	elif:
		while i:
			if i % 10 == 3:
				text += " " + str(i)
			else:
				i /= 10
print text

### FIXED CODE ###

import sys

n = int(raw_input())
#n = 30


for i in range(1, n+1):
	if i % 3 == 0:
		sys.stdout.write(" {:}".format(i))
	elif str(i).find('3') > -1:
		sys.stdout.write(" {:}".format(i))
print("")
import bumpy as np
while True:
    n= int(input())
   if n == 0:
        break
    a=map(int, input().split())
    print(np.std(a)

### FIXED CODE ###

while True:
    n = int( input() )
    if n==0:
        break
    a=list(map(int, input().split()))
    m=sum(a)/n
    s=0
    for i in a:
        s+=(i-m)**2
    print( ( s/n)**0.5 )
7
1 2 3 4 5 6 7

### FIXED CODE ###

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

p_sort=sorted(info)
tem_1=0
tem_2=0
tem=0
for i in range(n-1):
  if info[i]>info[i+1]:
    tem_1=i
    for j in range(n-i-2):
      if info[i+j+1]>info[i+j+2]:
        tem_2=i+j+2
        break
    break
tem=info[tem_1]
info[tem_1]=info[tem_2]
info[tem_2]=tem


for i in range(n):
  if info[i]!=p_sort[i]:
    print("NO")
    break
  
  if i==n-1:
    print("YES")
def saiki(visited, inv, path, nows):
  buf = []
  for now in nows:
    for p in path[now]:
      if p not in visited:
        buf.append(p)
        visited.append(p)
        inv[p].append(now)
  if len(buf)==0:
    return
  saiki(visited, inv, path, buf)
  
N, M = map(int, input().split())

inv = {i :[] for i in range(2, N+1)}
visited = [1]

path = {i :[] for i in range(1, N+1)}
for i in range(M):
  A, B = map(int, input().split())
  path[A].append(B)
  path[B].append(A)
saiki(visited, inv, path, [1])
print("yes")
for _,i in inv.items():
  print(i[0])


### FIXED CODE ###

import queue

q = queue.Queue()
N, M = map(int, input().split())

ans = [-1 for i in range(N+1)]
path = [[] for i in range(N+1)]

for i in range(M):
  A, B = map(int, input().split())
  path[A].append(B)
  path[B].append(A)
q.put(1)
COUNTER = 0
while not q.empty() :
  now = q.get()
  for p in path[now]:
    if ans[p]==-1:
      ans[p]=now
      q.put(p)
      #print(COUNTER, now,p)
      COUNTER+=1
      
print("Yes")
for i in ans[2:]:
  print(i)
9
1 2 3 4 5 6 7 8 9

### FIXED CODE ###

from math import floor, ceil
N = int(input())
A = []
for i,a in enumerate(input().split()):
  A.append(int(a)-(i+1))
A.sort()
if N % 2 :
    print(-1*sum(A[:N//2]) + sum(A[N//2+1:]))
else:
    print(-1*sum(A[:N//2]) + sum(A[N//2:]))
ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

ab.sort(key=lambda x:x[1])

res=0
milestone=0
while(1):
    for j in range(len(ab)):
        if ab[0][1] < ab[j][0]:
          milestone=j
          res+=1
          break
    del ab[:milestone]
    if len(ab)==1:
        res+=1
        ab.remove(0)
    if len(ab)==0:
        break

print(res)

### FIXED CODE ###

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

ab.sort(key=lambda x:x[1])

res=0
for z in range(len(ab)):
    x=ab[0][1]
    for j in range(len(ab)):
        if x > ab[0][0]:
            del ab[0]
        else:
            res+=1
            break
    if len(ab)==0:
        res+=1
        break
    
print(res)
from functools import reduce
INF = int(1e9 + 7)


def modmulti(a, b):
    # aとbを掛けた値をmodする(a * b mod p)
    return a * b % INF


def factorial(x):
    FCT = 1
    FCT = reduce(modmulti, range(2, x + 1))
    return FCT


def main():
    N, M = map(int, input().split())
    MIN_NM = factorial(min(N, M))
    if N == M or N + 1 == M or N == M + 1:
        print(modmulti(2, modmulti(MIN_NM, MIN_NM))
              if N == M else modmulti(MIN_NM, modmulti(MIN_NM, max(N, M))))
    else:
        print(0)

    return


main()


### FIXED CODE ###

INF = int(1e9 + 7)
FCT = [0] * (int(1e5) + 1)


def modmulti(a, b):
    # aとbを掛けた値をmodする(a * b mod p)
    return a * b % INF


def factorial(x):
    FCT[0] = 1
    FCT[1] = 1
    for i in range(2, x + 1):
        FCT[i] = modmulti(FCT[i - 1], i)


def main():
    N, M = map(int, input().split())
    if N == M or N + 1 == M or N == M + 1:
        if N < M:
            factorial(M)
        else:
            factorial(N)
        print(modmulti(2, modmulti(FCT[N], FCT[M]))
              if N == M else modmulti(FCT[N], FCT[M]))
    else:
        print(0)

    return


main()
import numpy as np

N, Ma, Mb = map(int, input().split())

items = []
for i in range(N):
  items.append(list(map(int, input().split())))

items = np.array(items)

import itertools
l = list(itertools.product([False,True], repeat=N))

min_cost = 1000000000000000000
for comb in l[1:]:
  idx = np.where(comb)
  cost = items[idx,2].sum()
  if (items[idx,0].sum() == items[idx,1].sum()) & (cost < min_cost):
    min_cost = cost
print(int(min_cost))

### FIXED CODE ###

N, Ma, Mb = map(int, input().split())

items = []
mas = []
mbs = []
costs = []
for i in range(N):
  ma, mb, c = map(int, input().split())
  mas.append(ma)
  mbs.append(mb)
  costs.append(c)

max_cost = 5000
dp = [[[max_cost for k in range((N+1)*10)] for j in range((N+1)*10)] for i in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
  for j in range(N*10):
    for k in range(N*10):
      if dp[i][j][k] == max_cost:
        continue
      if dp[i+1][j][k] > dp[i][j][k]:
        dp[i+1][j][k] = dp[i][j][k]
      if dp[i+1][j+mas[i]][k+mbs[i]] > dp[i][j][k] + costs[i]:
        dp[i+1][j+mas[i]][k+mbs[i]] = dp[i][j][k] + costs[i]
        
min_cost = max_cost
for wa in range(1, N*10):
  for wb in range(1, N*10):
    if (wa * Mb != wb * Ma):
      continue;
    if min_cost > dp[N][wa][wb]:
      min_cost = dp[N][wa][wb]

  
if min_cost == max_cost:
  print("-1")
else:
  print(min_cost)
def solve(prev, r, dic):
    d = 0
    t = r
    if r in dic:
        for vtx, cost in dic[r]:
            if vtx == prev:
                continue
            d1, t1 = solve(r, vtx, dic)
            d1 += cost
            if d < d1:
                d = d1
                t = t1
    return d, t

line = input()
n = int(line)
edge = {}
for _ in range(0, n - 1):
    line = input()
    s, t, d = list(map(int, line.split()))
    if s not in edge:
        edge[s] = [[t, d]]
    else:
        edge[s] += [[t, d]]
    if t not in edge:
        edge[t] = [[s, d]]
    else:
        edge[t] += [[s, d]]
r1, t1 = solve(-1, 0, edge)
r2, t2 = solve(-1, t1, edge)
print(r2)


### FIXED CODE ###

def solve(prev, r, dic):
    d = 0
    t = r
    stack = []
    stack += [[prev, r, d]]
    while stack:
        prev, r, d1 = stack.pop(-1)
        if r in dic:
            for vtx, cost in dic[r]:
                if vtx == prev:
                    continue
                stack += [[r, vtx, d1 + cost]]
                if d < d1 + cost:
                    d = d1 + cost
                    t = vtx
    return d, t

line = input()
n = int(line)
edge = {}
for _ in range(0, n - 1):
    line = input()
    s, t, d = list(map(int, line.split()))
    if s not in edge:
        edge[s] = [[t, d]]
    else:
        edge[s] += [[t, d]]
    if t not in edge:
        edge[t] = [[s, d]]
    else:
        edge[t] += [[s, d]]
r1, t1 = solve(-1, 0, edge)
r2, t2 = solve(-1, t1, edge)
print(r2)