Harryxun/stf_run huggingface dataset:
N = int(input())
table = [[-1]*(N) for i in range(N)]
for i in range(N):
    A = int(input())
    for j in range(A):
        x,y = map(int,input().split())
        table[i][x] = y
# print(table)
# table[i][x] 人iが人xを正直者;1,真偽不明:0,未言及:-1
def my_shift(i,k):
    return int(str(bin(i))[-1]) if k == 0 else i>>k
ans = 0
for i in range(2**N):

    hito = [0]*N
    for j in range(N):
        if i >> j & 1:
            hito[j] = 1

    flag = True
    cnt = 0
    for j in range(N):
        if i >> j & 1:
            cnt += 1
            for k in range(N):
                if table[j][k] != -1:
                    if table[j][k] != hito[k]:
                        flag = False
    if flag:
        if cnt > ans:
            ans = cnt
print(ans)
#print(3 >> 0) # 3????



### FIXED CODE ###

N = int(input())
table = [[-1]*(N) for i in range(N)]
for i in range(N):
    A = int(input())
    for j in range(A):
        x,y = map(int,input().split())
        table[i][x-1] = y
# print(table)
# table[i][x] 人iが人xを正直者;1,真偽不明:0,未言及:-1

ans = 0
for i in range(2**N):

    hito = [0]*N
    for j in range(N):
        if i >> j & 1:
            hito[j] = 1

    flag = True
    cnt = 0
    for j in range(N):
        if i >> j & 1:
            cnt += 1
            for k in range(N):
                if table[j][k] != -1:
                    if table[j][k] != hito[k]:
                        flag = False
    if flag:
        if cnt > ans:
            ans = cnt
print(ans)
#print(3 >> 0) # 3????
n = list(input())
s = 0
for a in n:
    s += int(a)

if len(n) >= 2:
    if int(n[0]) >= 2:
        print(max(s, (len(n)-1)*9+int(n[0])-1))
    else:
        print(max(s, (len(n)-1)*9))
else:
    print(int(n))

### FIXED CODE ###

n = list(input())
s = 0
for a in n:
    s += int(a)

if len(n) >= 2:
    if int(n[0]) >= 2:
        print(max(s, (len(n)-1)*9+int(n[0])-1))
    else:
        print(max(s, (len(n)-1)*9))
else:
    print(int(n[0]))
a= input()

list1 = [ a for items in list1 list1[items]=input() ]



### FIXED CODE ###

# a= int(input())
# list1 =[]

n = int(input())
a = list(map(int,input().split()))
# print(a)
# a.sort(reverse=True)
# print(a)
if 0 in a :
    ans  = 0
    print(ans)
else :
    ans = 1
    for i in range(n):
        ans *= a[i]
        if ans > 10**18 :
            print(-1)
            break
if ans <= 10**18 and ans != 0 :
    print(ans)
n=int(input())
print((10**n-9**n*2+8**n)%(1e9+7))

### FIXED CODE ###

n = int(input())
print((10**n-2*9**n+8**n)%1000000007)
#!/usr/bin/env python3

a = int(input())
a, b = map(int, input().split())
a = list(str(input()))


### FIXED CODE ###

#!/usr/bin/env python3

a, b, c = map(int, input().split())
print("{} {} {}".format(c, a, b))
while 1:
   x, y = map(int, raw_input().split())
   if x <= y:
      print '%d %d' %(x, y)
   if y < x:
      print '%d %d' %(y, x)
   if x == y == 0:
      break

### FIXED CODE ###

while 1:
   x, y = map(int, raw_input().split())
   if x == 0 and y == 0:
      break
   elif x > y:
      print '%s %s' % (y,x)
   else:
      print '%s %s' % (x,y)
W, H, x, y, r = map(int, raw_input().split())
print 'Yes' if 0 =< (x + r) =< W and 0 =< (y + r) =< H else 'No'

### FIXED CODE ###

W, H, x, y, r = map(int, raw_input().split())
print 'Yes' if 0 <= x - r and 0 <= y -r and x + r <= W and y + r <= H else 'No'
#N = str(input())
N,A,B = map(int,input().split())
#X=list(map(int,input().split()))

if A==0:
    print(0)
else:
    b=N//(A+B)
    x=N%(A+B)

if x>A:
    x=A

    print(b*A+x)


### FIXED CODE ###

#N = str(input())
N,A,B = map(int,input().split())
#X=list(map(int,input().split()))

if A==0:
    print(0)
    exit()
else:
    b=N//(A+B)
    x=N%(A+B)

    if x>A:
        print(b*A+A)
    else:
        print(b*A+x)
a=input()
b=input()
c=0
for i in range(a):
  if(a[i]!=b[i]):
    c=c+1
print(c)

### FIXED CODE ###

a=input()
b=input()
c=0
for i in range(len(a)):
  if(a[i]!=b[i]):
    c=c+1
print(c)
N, M = map(int,input().split())
A_B = [list(map(int, input().split())) for i in range(N)]

#日数ごとの集合を作る
jobs = {m: [] for m in range(1, M + 1)}
for ab in A_B:
  if a in jobs:
    jobs[ab[0]].append(ab[1])
#print(jobs)

#日数の少ない仕事からループして最適解を見つける
import heapq
q = []
ans = 0
#仕事にかかる日数のループであって経過日のループではない
for m in range(1, M + 1):
    for b in jobs[m]:
      #qには小さい順で格納される
      heapq.heappush(q, -b)
    #print(q)
    #qが空でないとき
    if len(q) > 0:
      #現時点での日数以下の仕事で一番稼げるものを取り出す
      neg_b = heapq.heappop(q)
      ans += -neg_b

print(ans)

### FIXED CODE ###

N, M = map(int,input().split())
A_B = [list(map(int, input().split())) for i in range(N)]

#日数ごとの集合を作る
jobs = {m: [] for m in range(1, M + 1)}
for ab in A_B:
  if ab[0] in jobs:
    jobs[ab[0]].append(ab[1])
#print(jobs)

#日数の少ない仕事からループして最適解を見つける
import heapq
q = []
ans = 0
#仕事にかかる日数のループであって経過日のループではない
for m in range(1, M + 1):
    for b in jobs[m]:
      #qには小さい順で格納される
      heapq.heappush(q, -b)
    #print(q)
    #qが空でないとき
    if len(q) > 0:
      #現時点での日数以下の仕事で一番稼げるものを取り出す
      neg_b = heapq.heappop(q)
      ans += -neg_b

print(ans)
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math

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

if "1"*M in S:
  print(-1)
  exit()  

S = [int(S[i]) for i in range(N+1)]

max_n = [0]
mask = (1<<M) -1
b = 0
for i in range(N+1):
  b = ((b<<1) + (1- S[i])) & mask
  max_n.append(math.floor(math.log(b)/math.log(2))+1)

now = N
deme = []
while now != 0:
  x = max_n[now]
  now = now-x
  deme.append(x)
print(*deme[::-1])

### FIXED CODE ###

import sys
input = sys.stdin.readline

import math
import bisect

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

if "1"*M in S:
  print(-1)
  exit()  

S = [int(S[i]) for i in range(N+1)]

L = [(1<<i) -1 for i in range(1,M+1)]

max_n = [0]
mask = (1<<M) -1
b = 0
for i in range(N):
  b = ((b<<1) + (1- S[i])) & mask
  max_n.append(bisect.bisect_left(L,b)+1)

now = N
deme = []
while now != 0:
  x = max_n[now]
  now -= x
  deme.append(x)
print(*deme[::-1])
import numpy as np

N, M, X = map(int, input().split())
C = np.zeros(N)
A = np.zeros((N, M))


for n in range(N):
    s = list(map(int, input().split()))
    C[n] = s[0]
    A[n] = s[1:]

C_MIN = 9999999999
for i in range(2 ** N):
    C_SUM = 0
    A_SUM = np.zeros(M)
    for j in range(N):
        if ((i >> j) & 1):
            C_SUM += C[j]
            A_SUM += A[j]
    if np.all(A_SUM >= X):
        if C_SUM < C_MIN:
            C_MIN = C_SUM
            
if C_MIN == 9999999999:
    print("-1")
else:
    print(C_MIN)

### FIXED CODE ###

import numpy as np

N, M, X = map(int, input().split())
C = np.zeros(N)
A = np.zeros((N, M))


for n in range(N):
    s = list(map(int, input().split()))
    C[n] = s[0]
    A[n] = s[1:]

C_MIN = -1
for i in range(2 ** N):
    C_SUM = 0
    A_SUM = np.zeros(M)
    for j in range(N):
        if ((i >> j) & 1):
            C_SUM += C[j]
            A_SUM += A[j]
    if np.all(A_SUM >= X):
        if C_SUM < C_MIN or C_MIN == -1:
            C_MIN = C_SUM
            
if C_MIN == -1:
    print("-1")
else:
    print(int(C_MIN))
a_dict = {chr(a): 0 for a in range(97, 123)}
while True:
    S = input().lower()
    '''if not S:
        break'''
    for c in S:
        if c in a_dict:
            a_dict[c] += 1

    for k, v in a_dict.items():
        print('{0} : {1}'.format(k, v))



### FIXED CODE ###

import fileinput
a_dict = {chr(c): 0 for c in range(97, 123)}
for line in fileinput.input():
    line = line.lower()
    for c in line:
        if c in a_dict:
            a_dict[c] += 1

for k, v in a_dict.items():
    print('{0} : {1}'.format(k, v))
c_list = []
for i in range(3):
    c_list.append(input().split())
    
print(c_list[0] + c_list[3] + c_list[5])

### FIXED CODE ###

c_list = []
for i in range(3):
    c_list.append(input())

print(c_list[0][0] + c_list[1][1] + c_list[2][2])
def insertionSort( nums, n, g ):
	cnt = 0
	i = g
	n = len( nums )
	while i < n:
		v = nums[i]
		j = i - g
		while 0 <= j and v < nums[j] and j+g < n:
			nums[ j+g ] = nums[j]
			j -= g
			cnt += 1
		nums[ j+g ] = v
		i += 1
	
	return cnt


def shellSort( nums, n ):
	cnt = 0
	g = []
	val =0
	for i in range( 0, n ):
		val = 3*val+1
		if  n < val:
			break
		g.append( val )

	g.reverse( )
	m = len( g )
	print( m )
	print( " ".join( map( str, g ) ) )
	for i in range( 0, m ):
		cnt += insertionSort( nums, n, g[i] )
	print( cnt )


n = int( raw_input( ) )
nums = []
for i in range( 0, n ):
	nums.append( int( raw_input( ) ) )

shellSort( nums, n )
for val in nums:
	print( val )

### FIXED CODE ###

import sys
 
def insertionSort( nums, n, g ):
    cnt = 0
    i = g
    while i < n:
        v = nums[i]
        j = i - g
        while 0 <= j and v < nums[j]:
            nums[ j+g ] = nums[j]
            j -= g
            cnt += 1
        nums[ j+g ] = v
        i += 1
    return cnt
         
def shellSort( nums, n ):
    g = []
    val = 1
    while val <= n:
        g.append( val )
        val = 3*val+1
     
    g.reverse( )
    m = len( g )
    print( m )
    print( " ".join( map( str, g ) ) )
    cnt = 0
    for i in range( m ):
        cnt += insertionSort( nums, n, g[i] )
    print( cnt )
     
n = int( sys.stdin.readline( ) )
nums = []
for i in range( n ):
    nums.append( int( sys.stdin.readline( ) ) )
 
shellSort( nums, n )
print( "\n".join( map( str, nums ) ) )
import numpy as np
a = [list(input()) for i in range(3)]
a = np.ravel(a)
n = int(input())
b = [input() for i in range(n)]
ans = 'No'
for i in range(3):
    if b in a[i*3:i*3+2] or b in a[i:i+6:3] or b in a[0:8:4] or b in a[2:6:2]:
        ans = 'Yes'
print(ans)


### FIXED CODE ###

# ABC157 B
import numpy as np
a = [[input().split() for l in range(3)]]
a = np.ravel(a)
n = int(input())
b = [input() for i in range(n)]
ans = 'No'

def check(a,b):
    return set(a).issubset(b)

for i in range(3):
    if check(a[i*3:(i*3)+3],b) or check(a[i:i+7:3],b) or check(a[0:9:4],b) or check(a[2:7:2],b):
        ans = 'Yes'

print(ans)
i = 0
wa = 0
while i < len(str(N)):
    wa = wa + int(str(N)[i:i+1])
    i += 1
if N % wa == 0:
    print("Yes")
elif N % wa != 0:
    print("No")

### FIXED CODE ###

from sys import stdin
N = int(stdin.readline().rstrip())
i = 0
wa = 0
while i < len(str(N)):
    wa = wa + int(str(N)[i:i+1])
    i += 1
if N % wa == 0:
    print("Yes")
elif N % wa != 0:
    print("No")
n.k = map(int,input().split())
if n%k ==0:
  print(0)
else:
  print(1)

### FIXED CODE ###

n,k = map(int,input().split())
if n%k ==0:
  print(0)
else:
  print(1)
# ABC153
# B Common Raccoon VS Monster
h, n = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
if a <= s:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

# ABC153
# B Common Raccoon VS Monster
h, n = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
if h <= s:
    print("Yes")
else:
    print("No")
n = int(input())
print("Yes" if 7 in n else "No")

### FIXED CODE ###

n = input()
print("Yes" if "7" in n else "No")
n,a,b = map(int, input().split())
res = ''

while len(res) < n:
  res += 'b'*a
  res += 'r'*b
  
res = res[:n]
print(res.count('b'))

### FIXED CODE ###

n, a, b = map(int, input().split())
period = a+b
times = n//period
k = n%period
n =  a if k >a else k
print(times*a + n)
N, Q = map(int, input().split())
S = input()
t= [0]*(N+1)
for i in range(N):
  t[i+1] = t[i] +(1 if S[i:i+2]=='AC' else 0)
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1]-t[l-1])


### FIXED CODE ###

dic={}
dic['A'] = 'T'
dic['C'] = 'G'
dic['G'] = 'C'
dic['T'] = 'A'
b = input()
print(dic[b])
def main():
    N, M = map(int, input().split())
    cnt = [0] * N
    for _ in range(N):
        a, b = map(int, input().split())
        cnt[a-1] += 1
        cnt[b-1] += 1
    for i in range(N):
        if cnt[i] % 2 == 1:
            print("NO")
            return
    print("YES")


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N, M = map(int, input().split())
    cnt = [0] * N
    for _ in range(M):
        a, b = map(int, input().split())
        cnt[a-1] += 1
        cnt[b-1] += 1
    for i in range(N):
        if cnt[i] % 2 == 1:
            print("NO")
            return
    print("YES")


if __name__ == "__main__":
    main()
n = int(input())
A = [int(i) for i in input().split()]

A.sort()
m = 2 ** 30
used = set()
ans = 0

def search(ok, ng, n):
    if abs(ok-ng) <= 1:
            return ok
    mid = (ok+ng) // 2
    if A[mid] < n or (A[mid] == n and mid in used):
        return search(mid, ng, n)
    else:
        return search(ok, mid, n)

for i in range(30):
    m //= 2
    for j in range(n):
        if j in used or A[j] >= m:
            continue
        a = search(-1, n, m - A[j]) + 1
        if a >= n:
            continue
        if A[a] == m - A[j]:
            if a == j:
                if not A[a+1] == A[j]:
                    continue
                a += 1
            used.add(a)
            used.add(j)
            ans += 1

ans2 = 0
used = set()

for i in range(30):
    m *= 2
    for j in range(n):
        if j in used or A[j] >= m:
            continue
        a = search(-1, n, m - A[j]) + 1
        if a >= n:
            continue
        if A[a] == m - A[j]:
            if a == j:
                if not A[a+1] == A[j]:
                    continue
                a += 1
            used.add(a)
            used.add(j)
            ans2 += 1

print(max(ans, ans2))

### FIXED CODE ###

from collections import Counter

n = int(input())
A = [int(i) for i in input().split()]

A.sort(reverse=True)
C = Counter(A)
m = 1 << 30
ans = 0

for a in A:
    if C[a] <= 0:
        continue
    C[a] -= 1
    while m > a * 2:
        m >>= 1
    v = m - a
    if v in C and C[v] > 0:
        C[v] -= 1
        ans += 1

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

mnr = 10**9
for a in range(1, W//2 + 1):
    b1 = (H*W)//(a + W)
    b2 = b1+1
    mc = max(abs((W-a)*b1-a*b1), abs(b1*(a+W) - H*W))
    mc2 = max(abs((W-a)*b2-a*b2), abs(b2*(a+W) - H*W))
    mnr = min([mnr, mc, mc2])
H, W = W, H
for a in range(1, W//2 + 1):
    b1 = (H*W)//(a + W)
    b2 = b1+1
    mc = max(abs((W-a)*b1-a*b1), abs(b1*(a+W) - H*W))
    mc2 = max(abs((W-a)*b2-a*b2), abs(b2*(a+W) - H*W))
    mnr = min([mnr, mc, mc2])
if H % 3 == 0 or W % 3== 0:
    mnr = 0
elif H % 3:
    mnr = min(W, mnr)
else:
    mnr = min(H, mnr)
print(mnr)


### FIXED CODE ###

# ABC140E
class SegTree:
    def __init__(self, init_val, ide_ele, seg_func):
        self.segfunc = seg_func
        N = len(init_val)
        self.num = 2**(N-1).bit_length()
        self.ide_ele = ide_ele
        self.seg=[self.ide_ele]*2*self.num
        for i in range(N):
            self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res
N, = map(int, input().split())
A = list(map(int, input().split()))
B = sorted([(a, i) for i, a in enumerate(A)], key=lambda x:x[0])
z = dict()
for i, (b, j) in enumerate(B):
    z[(b, j)] = i

ss = SegTree([3*N]*3*N, 3*N, min)
bs = []
y = 0
for i, x in enumerate(A):
    if i == 2*N:
        break
    ss.update(z[(x, i)], z[(x, i)])
    y += x
    if i < N-1:
        continue
    if i == N-1:
        bs.append(y)
    else:
        mx = ss.query(0, 3*N)
        y = y - B[mx][0]
        ss.update(mx, 3*N)
        bs.append(y)

ss = SegTree([-1]*3*N, -1, max)
nbs = []
#tmp = set()
y = 0
for i, x in enumerate(A[::-1]):
    if i == 2*N:
        break
    ss.update(z[(x, 3*N-i-1)], z[(x, 3*N-i-1)])
#    tmp.add((x, i))
    y += x
    if i < N-1:
        continue
    if i == N-1:
        nbs.append(y)
    else:
        mx = ss.query(0, 3*N)
#        print(max(tmp), B[mx])
#        tmp.remove(max(tmp))
        y = y - B[mx][0]
        ss.update(mx, -1)
        nbs.append(y)

#print(B)
#print(bs)
#print(nbs)
r = -10**18
for i in range(N+1):
    r = max(r, bs[i] - nbs[N-i])
print(r)
import itertools
import heapq
import sys
import functools
import operator
import numpy as np
input = sys.stdin.readline
#-------------
n,k = map(int,input().split())
a = list(map(int,input().split()))
#-------------
a.sort(reverse = True)
w = 10**9 + 7
ans = 1
if k%2 == 1:
  for i in range(k):
    ans *= a[i]
  print(ans % w)

else:
  if n%2 == 0:
    a_new = [a[2*i]*a[2*i+1] for i in range(n//2)]
    a_new.sort(reverse = True)
    for j in range(k//2):
      ans *= a_new[j]
    print(ans % w)
      
  else:
    a_plus = heapq.nlargest(k, a)
    a_minus = heapq.nsmallest(k, a)
    a_plus.sort(reverse = True)
    a_minus.sort()
    a_plus_new = [a_plus[2*i]*a_plus[2*i+1] for i in range(len(a_plus)-1)]
    a_minus_new = [a_minus[2*i]*a_minus[2*i+1] for i in range(len(a_minus)-1)]
    a_new = a_plus_new + a_minus_new
    a_new.sort(revserse = True)
    for j in range(k//2):
      ans *= a_new[j]
    print(ans % w)

### FIXED CODE ###

import sys
 
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0:
  if zero and k%2:
    ans = 0
  else:
    if k%2:
      minus.reverse()
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((len(plus)-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(len(minus)//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod
 
print(ans)
s = str(input())
t = str(input())

Z =False

if i in range(len(s)):
    s = s[-1] + s[:-1]
    if s == t:
        Z =True
        exit()
        
print('Yes' if Z else 'No')

### FIXED CODE ###

s = str(input())
t = str(input())

for i in range(len(s)):
    ss = s[-i:]+s[:-i]
    if ss == t:
        print('Yes')
        exit()
print('No')
import math as m
a, b, h, m = map(int, input().split())
diff_hm = abs(h*30 - m*60)
print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(diff_hm))))

### FIXED CODE ###

import math
a, b, h, m = map(int, input().split())
diff_hm = abs(h*30 + m*0.5 - m*6)
print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(diff_hm))))
n = int(input().rstrip())
s = [str(input().rstrip()z) for i in range(n)]
for v in ["AC","WE","TLE","RE"]
         print(f"{v} x {s.count(v)}")
  

### FIXED CODE ###

n = int(input().rstrip())
s = [str(input().rstrip()) for i in range(n)]
for v in ["AC","WA","TLE","RE"]:
         print(f"{v} x {s.count(v)}")
def BC132_D():
    n, k = list(map(int, input().split(' ')))
    f = [1] * max(k, n - k + 2)
    for i in range(1, len(f) + 1):
        f[i] = f[i - 1] * i

    def comb(n, r, f):
        if n < r: return 0
        return f[n] // f[r] // f[n - r]

    for i in range(1, k + 1):
        print(comb(k - 1, i - 1, f) * comb(n - k + 1, i, f) % (10**9 + 7))

BC132_D()

### FIXED CODE ###

import math
def bi(x, y):
  if x < y or y < 0 or x < 0: return 0
  if y == 0: return 1
  return math.factorial(x) // math.factorial(y) // math.factorial(x - y)

n, k = list(map(int, input().split(' ')))
for i in range(1, k + 1):
  print(bi(k - 1, i - 1) * bi(n - k + 1, i) % (10**9 + 7))
import math.factorial as F
N, M = map(int, input().split())
N, M = min(N, M), max(N, M)
mod = 10**9+7

if M-N > 1:
    print(0)
elif M-N == 1:
    print(F(M)*F(N) % mod)
else:
    print(F(M)**2*2 % mod)


### FIXED CODE ###

N, M = map(int, input().split())
N, M = min(N, M), max(N, M)
mod = 10**9+7

g1 = [1, 1]
for i in range(2, M+1):
    g1.append((g1[-1] * i) % mod)

if M-N > 1:
    print(0)
elif M-N == 1:
    print(g1[M]*g1[N] % mod)
else:
    print(g1[M]**2*2 % mod)
N, K = map(int, input().split())
V = list(map(int, input().split()))

def calc(l, r, d):
    hold = []
    for i in range(l):
        hold.append(V[i])
    for i in range(N-r, N):
        hold.append(V[i])
    hold.sort()
    return 0 if d >= len(hold) else sum(hold[d:]) 

ret = 0
for l in range(K+1):
    for r in range(K+1-l):
        d = K - l - r
        ret = max(ret, calc(l, r, d))
print(ret)

### FIXED CODE ###

N, K = map(int, input().split())
V = list(map(int, input().split()))
U = V[::-1]
ret = 0

m = min(N, K)
for l in range(m+1):
    for r in range(m+1-l):
        hold = V[:l] + U[:r]
        hold.sort()
        for d in range(K+1-l-r):
            ret = max(ret, sum(hold[d:]))

print(ret)
import math
n, k = map(int, input().split())


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


for i in range(1, k + 1):
    answer = combinations_count(k - 1, i - 1) * combinations_count(n - k + 1, i)
    # print(combinations_count(i - 1 + k, i - 1), combinations_count(n - k + 1, i))
    print(answer % (10 ** 9 + 7))


### FIXED CODE ###

import math

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


def combinations_count(N, R):
    return math.factorial(N) // (math.factorial(N - R) * math.factorial(R))


for i in range(1, k + 1):
    # 注意！もし青玉の置く場所がiより少なかったら置くことができないので、0通り
    if n - k + 1 < i:
        print(0)
    else:
        answer = combinations_count(k - 1, i - 1) * combinations_count(n - k + 1, i)
        # print(combinations_count(i - 1 + k, i - 1), combinations_count(n - k + 1, i))
        print(answer % (10 ** 9 + 7))
flag = True
i = 0
inNums = []
while flag:
    input = raw_input().strip().split()
    inNums.append(input)
    if input == []:
        flag = False
for i in range(len(inNums)-1):
    a = int(inNums[i][0])
    b = int(inNums[i][1])
    temp = a+b
    x = 0
    while temp // (10**x) > 0:
        x += 1
    print(x)

### FIXED CODE ###

import sys

for s in sys.stdin:
  a,b = map(int,s.split())
  print(len(str(a+b)))
while 1:
H , W = map(int, raw_input().split())

if H == W == 0:
  break

for i in range(W):
  width[i] = '#'
for j in range(H):
  print width
    
    

### FIXED CODE ###

while 1:
  h, w = map(int, raw_input().split())
  if h == 0 and w == 0:
    break
  for i in range(h):
    print "#" * w
  print""
import sys
import numpy as np
read = sys.stdin.read

N, W, *wv = map(int, read().split())
dp = np.zeros((W + 1, N + 1), np.int64)
idx = 1

for w, v in zip(*[iter(wv)] * 2):
    if w > W:
        continue

    dp[:, idx] = dp[:, idx - 1]
    dp[w:, idx] = np.maximum(dp[w:, idx], dp[:-w, idx] + v)
    idx += 1

print(dp[-1, -1])

### FIXED CODE ###

import sys
from itertools import accumulate, product
from operator import itemgetter
read = sys.stdin.read

N, W, *wv = map(int, read().split())
w1 = wv[0]
V = [[0] for _ in range(4)]

for w, v in sorted(zip(*[iter(wv)] * 2), key=itemgetter(1), reverse=True):
    V[w - w1].append(v)


V = list(map(list, map(accumulate, V)))
n = [len(V[i]) for i in range(4)]
answer = 0
for a, b, c, d in product(range(n[0]), range(n[1]), range(n[2]), range(n[3])):
    if b + c * 2 + d * 3 + (a + b + c + d) * w1 > W:
        continue

    v = V[0][a] + V[1][b] + V[2][c] + V[3][d]
    if v > answer:
        answer = v

print(answer)