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

n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
mod=10**9+7
ans=0
MOD=10**9+7

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

for i in range(n-k+1):
    ans-=a[i]*cmb(n-i-1,k-1)%mod
    ans%=mod
a=a[::-1]
for i in range(n-k+1):
    ans+=a[i]*cmb(n-i-1,k-1)%mod
    ans%=mod

print(ans%mod)

### FIXED CODE ###

n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
mod=10**9+7
ans=0
MOD=10**9+7

factorial = [1]
inverse = [1]
for i in range(1, n+2):
    factorial.append(factorial[-1] * i % MOD)
    inverse.append(pow(factorial[-1], MOD - 2, MOD))
 
 
# 組み合わせ計算
def nCr(n, r):
    if n < r or r < 0:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % MOD
for i in range(n-k+1):
    ans-=a[i]*nCr(n-i-1,k-1)%mod
    ans%=mod
a=a[::-1]
for i in range(n-k+1):
    ans+=a[i]*nCr(n-i-1,k-1)%mod
    ans%=mod

print(ans%mod)
### BUGGY CODE ###

n = int(input())
# a= 4, 1, 2, 3
# b= 1, 2, 3, 4 # modのmaxは 0, 1, 2, 3 なので最大6
# ----------
#    0, 1, 2, 3 
#print(int(n*(n-1)/2))  # 合わない...
print(sum([b%a for a, b in zip([i for i in range(1, n+1)], [n] + [i for i in range(1, n)])]))

### FIXED CODE ###

n = int(input())
#答えが違う
#print(int(n*(n-1)/2))  # 合わない...
#print(int(n*(n-1)//2))  # 合わない...
print(n*(n-1)//2)
### BUGGY CODE ###

N, K = [int(a) for a in input().split()]
A = [int(a) for a in input().split()]
marks = []
MOD = 1000000007

prev = -1
for i in range(K-1, N):
    prod = 1
    for k in range(K):
        prod *= A[i-k] % MOD
    if prev != -1:
        if prev < prod:
            print('Yes')
        else:
            print('No')
    prev = prod

### FIXED CODE ###

N, K = [int(a) for a in input().split()]
A = [int(a) for a in input().split()]
marks = []

for i in range(K, N):
    prev = A[i-K]
    next_ = A[i]
    if prev < next_:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

import itertools

def f(n):
  m = int(n**0.5)
  out = sum([True for x, y, z in itertools.product(range(1, m+1), repeat=3) if x**2+y**2+z**2+x*y+y*z+z*x==n])
  return out

N = int(input())
for n in range(1, N+1):
  print(f(n))


### FIXED CODE ###

import itertools
import collections



N = int(input())
count = [0]*N*100
m = int(N**0.5)
for x, y, z in itertools.combinations_with_replacement(range(1, m+1), 3):
  n = x**2+y**2+z**2+x*y+y*z+z*x
  k = len(set({x, y, z}))
  if k == 1:
    count[n] += 1
  elif k == 2:
    count[n] += 3
  else:
    count[n] += 6

for n in range(1, N+1):
  print(count[n])
### BUGGY CODE ###

import sys
import numpy as np
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import math


A, B, N = MAP()


def f(x, A, B):
    return math.floor(A * x / B) - A * math.floor(x / B)


x = 0
flag = 0
while True:
    if f(x, A, B) > 0:
        flag = 1
    if f(x, A, B) == 0:
        y = x - 1
        if flag == 1:
            break
    x += 1

if N < y:
    print(f(N, A, B))
else:
    print(f(y, A, B))


### FIXED CODE ###

import sys
import numpy as np
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import math


A, B, N = MAP()


def f(x, A, B):
    return math.floor(A * x / B) - A * math.floor(x / B)


if N < B - 1:
    print(f(N, A, B))
else:
    print(f(B - 1, A, B))
### BUGGY CODE ###

import collections, itertools, sys
import numpy as np
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, K = LI()
    xy = [LI() for _ in range(N)]

    # x, y全ての重複あり組み合わせに対して含まれる点の個数を算出する

    x_cnt = collections.Counter([i[0] for i in xy])
    x_coordinate = np.array(list((x_cnt.keys())))
    x_coordinate.sort()
    len_x_c = len(x_coordinate)
    y_cnt = collections.Counter([i[1] for i in xy])
    y_coordinate = np.array(list(y_cnt.keys()))
    y_coordinate.sort()
    len_y_c = len(y_coordinate)

    ans = INF
    for k in range(len_x_c - 1):
        xl = x_coordinate[k]
        for l in range(k + 1, len_y_c):
            xh = x_coordinate[l]
            # 4番目の辺の探索は、個数条件を満たしたら終了していよい
            for i in range(len_y_c - 1):
                yl = y_coordinate[i]
                for j in range(i + 1, len_y_c):
                    yh = y_coordinate[j]
                    cnt = len([(i, j) for i, j in xy if xl <= i <= xh and yl <= j <= yh])
                    if cnt >= K:
                        ans = min((xh - xl) * (yh - yl), ans)
                        break

    print(ans)

if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import collections, itertools, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, K = LI()
    xy = [LI() for _ in range(N)]

    # x, y全ての重複あり組み合わせに対して含まれる点の個数を算出する

    x_cnt = collections.Counter([i[0] for i in xy])
    x_coordinate = list(x_cnt.keys())
    x_coordinate.sort()
    # len_x_c = len(x_coordinate)
    y_cnt = collections.Counter([i[1] for i in xy])
    y_coordinate = list(y_cnt.keys())
    y_coordinate.sort()
    len_y_c = len(y_coordinate)

    ans = INF
    for xl, xh in itertools.combinations(x_coordinate, 2):
        # 4番目の辺の探索は、個数条件を満たしたら終了していよい
        for i in range(len_y_c - 1):
            yl = y_coordinate[i]
            for j in range(i + 1, len_y_c):
                yh = y_coordinate[j]
                cnt = len([(i, j) for i, j in xy if xl <= i <= xh and yl <= j <= yh])
                if cnt >= K:
                    ans = min((xh - xl) * (yh - yl), ans)
                    break

    print(ans)

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





def mk_row(data1,data2,table,row_num):
    for column in range(1,len(data2)+1):
        if(data1[row_num-1] ==data2[column-1]):
            table[row_num][column]=table[row_num-1][column-1]+1
        else:
            table[row_num][column]=max([table[row_num-1][column],table[row_num][column-1]])




n=int(input())

for loop in range(n):
    data1=input()
    data2=input()
    data1=list(data1)
    data2=list(data2)
    table=[[0]*(len(data2)+1) for i in range(len(data1)+1)]#0行、0列は空集合に対応

    for i in range(1,len(data1)+1):
        mk_row(data1,data2,table,i)
    print(table[len(data1)][len(data2)])


### FIXED CODE ###





def lsc(str1,str2):
    table1=[0]*(len(str2)+1)
    for i in range(len(str1)):
       table2=table1[:]
       for j in range(len(str2)):
            if(str1[i] == str2[j]):
               table1[j+1] = table2[j] +1
            else:
                if(table1[j+1] < table1[j]):
                    table1[j+1]=table1[j]
    return table1[-1]




n=int(input())

for loop in range(n):
    str1=input()
    str2=input()
    print(lsc(str1,str2))
### BUGGY CODE ###

N=input()
a=0
for i in range(1,int(N)+1,2):
    j=str(i)
    if "3"in j and "5"in j and "7"in j:
        if len(j)==j.count("3")+j.count("5")+j.count("7"):
            a+=1
print(a)

### FIXED CODE ###

N = int(input())
def dfs(s):
    if int(s)>N:
        return 0 
    ret = 1 if all(s.count(c)>0 for c in '753') else 0
    for c in '753':
        ret += dfs(s + c)
    return ret
print(dfs('0'))
### BUGGY CODE ###

N = int(input())
P = list(map(float, input().split()))

dp = [[0] * (N+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    p = P[i-1]
    for j in range(N+1):
        if j == 0:
            dp[i][j] = dp[i-1][j] * p
        else:
            dp[i][j] = dp[i-1][j-1] * (1-p) + dp[i-1][j] * p


print(sum(dp[N][:N//2+1]))

### FIXED CODE ###

N = int(input())
P = list(map(float, input().split()))

dp = [[0] * (N+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    p = P[i-1]
    for j in range(N+1):
        if j == 0:
            dp[i][j] = dp[i-1][j] * p
        else:
            dp[i][j] = dp[i-1][j-1] * (1-p) + dp[i-1][j] * p


print(sum(dp[N][:N//2+1]))
### BUGGY CODE ###

import collections


n = int(input())
ss = []
for i in range(n):
    s = input()
    ss.append(s)


tmp = collections.Counter(ss).most_common()

target = tmp[0][1]
ans = ''
for i in tmp:
    if i[1] == target:
        ans += i[0] + ' '
    else:
        break
ans = sorted(ans.split(), key=str.lower)
print(*ans)


### FIXED CODE ###

import bisect

n = int(input())
sl = ['']*n
for i in range(n):
    sl[i] = input()
sl = sorted(sl, key=str.lower)
# print(sl)
c = 0
anss = []
max_n = 0
for i, t in enumerate(sl):
    if i == 0:
        c += 1
        target = t
        continue

    if t == target:
        c += 1
    else:
        if max_n < c:
            anss = []
            anss.append(target)
            max_n = c
        elif max_n == c:
            anss.append(target)
            max_n = c
        target = t
        c = 1

if max_n < c:
    anss = []
    anss.append(t)
elif max_n == c:
    anss.append(t)


print(*anss)
### BUGGY CODE ###

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

b = list(set(a))
delete = 0

for i in b:
  c = a.count(i)
  if c < i:
    delete += c
  elif c > i:
    delete += c - i
    
print(delete)

### FIXED CODE ###

import collections

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

b = collections.Counter(a)
delete = 0

for i,j in b.items():
  i = int(i)
  if i > j:
    delete += j
  elif i < j:
    delete += j - i
    
print(delete)
### BUGGY CODE ###

n,m=map(int,input().split())
l=[]
for _ in range(m):
    l.append(list(map(int,input().split())))
d=[0]*(n+1)
for i in range(m):
    for j in range(l[i][0],l[i][1]+1):
        d[j]+=1
print(d.count(m))


### FIXED CODE ###

n,m=map(int,input().split())
l=0;r=10**6
for i in range(m):
    ln,rn=map(int,input().split())
    l=max(l,ln);r=min(r,rn)
if l>r:
    print(0)
else:
    print(r-l+1)
### BUGGY CODE ###

from sys import stdin

def main():

    input = stdin.readline

    N = int(input())

    A = [0] * N

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

    all_case = 0

    for i in set(A):
        num_count = A.count(i)
        all_case += (num_count * (num_count - 1)) // 2

    for i in A:
        ans = all_case - (A.count(i) - 1)
        print(ans)
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

from sys import stdin
from collections import Counter

def main():

    input = stdin.readline

    N = int(input())

    A = [0] * N

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

    all_case = 0

    num_all = Counter(A) 

    for k in num_all.values():
        all_case += (k * (k-1)) // 2

    for i in A:
        ans = all_case - (num_all[i] - 1)
        print(ans)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

n = int(input())
p = list(map(int, input().split()))
result_list = [0]*n

for i in range(n):
    for j in range(i):
        if p[i] > p[j]:
            result_list[i] = 1
            break

print(result_list.count(0))


### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
# result_list = [0]*n
result = 1
com_val = p[0]

for i in range(1, n):
    if com_val < p[i]:
        continue
    else:
        result += 1
        com_val = p[i]

print(result)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
p = [pow(2, i, mod) for i in range(60)]
l0 = [0] * 60
l1 = [0] * 60
for i in a:
    t = list(format(i, "b"))
    for j in range(len(t)):
        if int(t[j]) == 0:
            l0[len(t) - 1 - j] += 1
        else:
            l1[len(t) - 1 - j] += 1
    for j in range(len(t), 60):
        l0[j] += 1
ans = 0
for i in range(60):
    ans += (l0[i] * l1[i] * p[i]) % mod
    ans %= mod
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
p = [pow(2, i, mod) for i in range(60)]
ans = 0
for i in range(60):
    c = 0
    for j in a:
        if (j >> i) & 1:
            c += 1
    ans += (c * (n - c) * p[i]) % mod
    ans %= mod
print(ans)
### BUGGY CODE ###

from collections import defaultdict
N = int(input())
S = [''.join(sorted(list(str(input())))) for i in range(N)]

countDict = defaultdict(int)
for s in S:
    countDict[s] += 1


def makeTable(N):
    fac = [1 for i in range(N)]
    for i in range(2, N):
        fac[i] = fac[i - 1] * i
    return fac


fac = makeTable(N+1)


def binomialCoefficient(N, r):
    if N < r:
        return 0
    else:
        return fac[N] // (fac[r] * fac[N - r])


ans = 0
for v in countDict.values():
    if v >= 2:
        ans += binomialCoefficient(v, 2)

print(ans)

### FIXED CODE ###

from collections import defaultdict
N = int(input())
S = [''.join(sorted(list(str(input())))) for i in range(N)]

countDict = defaultdict(int)
ans = 0
for s in S:
    ans += countDict[s]
    countDict[s] += 1
print(ans)
### BUGGY CODE ###

N = int(input())
S = input()

count=[]
for i in range(len(S)+1):
    left = S[:i]
    right = S[i:]
    count.append(left.count('#')+right.count('.'))

print(min(count))

### FIXED CODE ###

N = int(input())
S = input()

count = [0]*(len(S)+1)
count[0] = S.count('.')
for i in range(1, len(S)+1):
    count[i] = count[i-1] + (1 if S[i-1]=='#' else 0) - (1 if S[i-1]=='.' else 0)

print(min(count))
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for i in range(Q)]
# print(N)
# print(A)
# print(Q)
# print(B)

for i in range(Q):
    Bi = BC[i][0]
    Ci = BC[i][1]

    for j in range(len(A)):
        if A[j] == Bi:
            A[j] = Ci
    
    print(sum(A))


### FIXED CODE ###

import itertools

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for i in range(Q)]
# print(N)
# print(A)
# print(Q)
# print(B)

distribution = {}
max_A = max(A)
max_BC = max(list(itertools.chain.from_iterable(BC)))
maximum = max([max_A, max_BC])
# print(max_A, max_BC, maximum)
for i in range(maximum + 1):
    distribution[i] = 0

for Ai in A:
    distribution[Ai] += 1
# print(distribution)

total = sum(A)
for i in range(Q):
    Bi = BC[i][0]
    Ci = BC[i][1]
    num_Bi = distribution.get(Bi)
    diff = (Ci - Bi) * num_Bi

    distribution[Bi] = 0
    # print(num_Bi, distribution.get(Bi), Ci)
    distribution[Ci] += num_Bi

    total += diff
    print(total)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

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

A2=[(num,ind) for ind,num in enumerate(A)]
A2.sort(reverse=True)

L=[0]*N

for i in range(N):
    num,ind=A2[i]
    NL=[0]*N
    for j in range(i+1):
        right=N-1-(i-j)
        NL[j]=max(NL[j],abs(right-ind)*num+L[j])

        if j!=N-1:
            NL[j+1]=max(NL[j+1],abs(j-ind)*num+L[j])
        #print(i,j,right,num,ind,NL)
    L=NL
print(max(L))

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

A2=[(num,ind) for ind,num in enumerate(A)]
A2.sort(reverse=True)

L=[0]*N

for i in range(N):
    num,ind=A2[i]
    NL=[0]*N
    for j in range(i+1):
        right=N-1-(i-j)
        NL[j]=max(NL[j],abs(right-ind)*num+L[j])

        if j!=N-1:
            NL[j+1]=max(NL[j+1],abs(j-ind)*num+L[j])
    L=NL
print(max(L))
### BUGGY CODE ###

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

ans = float("inf")
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            for kk in range(k+1,N):
                x1,y1 = XY[i]
                x2,y2 = XY[j]
                x3,y3 = XY[k]
                x4,y4 = XY[kk]
                u = max(y1,y2,y3,y4)
                d = min(y1,y2,y3,y4)
                r = max(x1,x2,x3,x4)
                l = min(x1,x2,x3,x4)
                num = 0
                for m in range(N):
                    x,y = XY[m]
                    if l<=x<=r and d<=y<=u:
                        num += 1
                if num >= K:
                    tmp = (u-d)*(r-l)
                    if tmp < ans:
                        ans = tmp
        for k in range(j+1,N):
            x1,y1 = XY[i]
            x2,y2 = XY[j]
            x3,y3 = XY[k]
            u = max(y1,y2,y3)
            d = min(y1,y2,y3)
            r = max(x1,x2,x3)
            l = min(x1,x2,x3)
            num = 0
            for m in range(N):
                x,y = XY[m]
                if l<=x<=r and d<=y<=u:
                    num += 1
            if num >= K:
                tmp = (u-d)*(r-l)
                if tmp < ans:
                    ans = tmp
        x1,y1 = XY[i]
        x2,y2 = XY[j]
        u = max(y1,y2)
        d = min(y1,y2)
        r = max(x1,x2)
        l = min(x1,x2)
        num = 0
        for m in range(N):
            x,y = XY[m]
            if l<=x<=r and d<=y<=u:
                num += 1
        if num >= K:
            tmp = (u-d)*(r-l)
            if tmp < ans:
                ans = tmp
print(ans)

### FIXED CODE ###

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

ans = float("inf")
for i in range(N):
    x1,y1 = XY[i]
    for j in range(i+1,N):
        x2,y2 = XY[j]
        u2 = max(y1,y2)
        d2 = min(y1,y2)
        r2 = max(x1,x2)
        l2 = min(x1,x2)
        for k in range(j+1,N):
            x3,y3 = XY[k]
            u3 = max(u2,y3)
            d3 = min(d2,y3)
            r3 = max(r2,x3)
            l3 = min(l2,x3)
            for kk in range(k+1,N):
                x4,y4 = XY[kk]
                u4 = max(u3,y4)
                d4 = min(d3,y4)
                r4 = max(r3,x4)
                l4 = min(l3,x4)
                num = 0
                for m in range(N):
                    x,y = XY[m]
                    if l4<=x<=r4 and d4<=y<=u4:
                        num += 1
                if num >= K:
                    tmp = (u4-d4)*(r4-l4)
                    if tmp < ans:
                        ans = tmp
            num = 0
            for m in range(N):
                x,y = XY[m]
                if l3<=x<=r3 and d3<=y<=u3:
                    num += 1
            if num >= K:
                tmp = (u3-d3)*(r3-l3)
                if tmp < ans:
                    ans = tmp
        num = 0
        for m in range(N):
            x,y = XY[m]
            if l2<=x<=r2 and d2<=y<=u2:
                num += 1
        if num >= K:
            tmp = (u2-d2)*(r2-l2)
            if tmp < ans:
                ans = tmp
print(ans)
### BUGGY CODE ###

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

if X==Y:
    print(-1)
else:
    for i in range(10**18):
        X1 = int(X*(i+5))
        if X1 % Y != 0:
            print(str(X1))
            break
    



### FIXED CODE ###

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

if X % Y == 0:
    print(-1)
else:
   print(X)
### BUGGY CODE ###

x,y,z,k = map(int, input().split())
a= list(map(int, input().split()))
b= list(map(int, input().split()))
c= list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ansListab=[]
for i in range(x):
  for j in range(y):
    ansListab.append(a[i]+b[j])

ansListab.sort(reverse= True)

if len(ansListab)>k:
  ansListab=ansListab[0:k]

ansList=[]

for j in ansListab:
  for i in c:
    ansList.append(i+j)

ansList.sort(reverse= True)

for i in range(k):
  print(ansList[i])


### FIXED CODE ###

x,y,z,k = map(int, input().split())
a= list(map(int, input().split()))
b= list(map(int, input().split()))
c= list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ansListab=[]
for i in range(x):
  for j in range(y):
    ansListab.append(a[i]+b[j])

ansListab.sort(reverse= True)

if len(ansListab)>k:
  ansListab=ansListab[0:k]

ansList=[]

for i in c:
  for j in ansListab:
    ansList.append(i+j)

ansList.sort(reverse= True)

for i in range(k):
  print(ansList[i])
### BUGGY CODE ###

import itertools
import collections

n = int(input())
name = []
for i in range(n):
    a = input()
    if a[0] in 'MARCH':
        name.append(a)

b = list(itertools.combinations(name,3))
total = 0
for tap in b:
    d = []
    for c in tap:
        d.append(c[0])
        
    d.sort()    
    e = collections.Counter(d)

    cnt = 0
    for v in e.values():
        if v == 1:
            cnt += 1
    if cnt == 3:
        total += 1

print(total)

### FIXED CODE ###

import itertools
import collections

n = int(input())
name = []
for i in range(n):
    a = input()
    if a[0] in 'MARCH':
        name.append(a[0])

b = collections.Counter(name)
d = []
for v in b.values():
    d.append(v)

c = list(itertools.combinations(list(range(len(b))), 3))

total = 0
for tap in c:
    total += d[tap[0]] * d[tap[1]] * d[tap[2]]
print(total)
### BUGGY CODE ###

import numpy as np

MOD = 10 ** 9 + 7
N = int(input())
x = list(map(int, input().split()))
x.sort()
x_arr = np.array(x)
x_diff = np.diff(x_arr)

a = np.zeros(N - 1, dtype=int)
a[0] += 1
for i in range(1, N - 1):
    a[i] = a[0]
    a[:i] = a[:i] * (i + 1) % MOD
a = np.cumsum(a) % MOD

print(np.dot(a, x_diff) % MOD)


### FIXED CODE ###

MOD = 10 ** 9 + 7
N = int(input())
x = list(map(int, input().split()))
x.sort()

kaijo = [1]
for i in range(1, N):
    kaijo.append(kaijo[-1] * i % MOD)

ans = 0
for i in range(N - 1):
    ans = (ans * (i + 1) + (x[-1] - x[i]) * kaijo[i]) % MOD

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

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

ans = 1
cnta = 0
cntb = 0
mod = 10**9+7
for num in range(n*m,0,-1):
    if num in a and num in b:
        cnta += 1
        cntb += 1
        cnta%=mod
        cntb%=mod
    elif num in a:
        ans *= cntb
        ans %= mod
        cnta += 1
    elif num in b:
        ans *= cnta
        ans %= mod
        cntb += 1
    else:
        ans *= (cnta*cntb - (n*m - num))%mod
        ans %= mod

print(ans)

### FIXED CODE ###

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
A=set(a);B=set(b)
ans = 1
cnta = 0
cntb = 0
mod = 10**9+7
for num in range(n*m,0,-1):
    if num in A and num in B:
        cnta += 1
        cntb += 1
    elif num in A:
        ans *= cntb
        cnta += 1
    elif num in B:
        ans *= cnta
        cntb += 1
    else:
        ans *= (cnta*cntb - (n*m - num))%mod
    ans %= mod
print(ans)