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

import bisect
import math
N = int(input())
x = list(map(int, input().split()))
L = int(input())

m = int(math.log(max(x), 2) + 1)
#i番目のホテルから2 ** k 日以内に到達可能な
#もっとも右にあるホテル
r = [[-1] * N for k in range(m)]
for i in range(N):
  base = x[i] + L
  p = bisect.bisect_right(x, base)
  #print(p)
  r[0][i] = p - 1

#ダブリング
for k in range(m - 1):
  for i in range(N):
    r[k + 1][i] = r[k][r[k][i]]
#print(r)    
   
def isOK(mid):
  now = a
  pp = int(math.log(mid, 2) + 1)
  for i in range(pp):
    if (mid >> i) & 1:
      now = r[i][now]
      #print(now, a + 1, b + 1, mid)
  if now >= b:
    return True
  else:
    return False
  
Q = int(input())
for i in range(Q):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  if a > b:
    a, b = b, a
  ng = 0
  ok = 2 ** m
  while (abs(ok - ng) > 1):
    mid = int((ok + ng) / 2)
    #print(mid)
    if isOK(mid):
      ok = mid
    else:
      ng = mid
  print(ok)
         

         
         
         

### FIXED CODE ###

import bisect
import math
N = int(input())
x = list(map(int, input().split()))
L = int(input())

m = int(math.log(max(x), 2) + 1)
#i番目のホテルから2 ** k 日以内に到達可能な
#もっとも右にあるホテル
r = [[-1] * N for k in range(m)]
for i in range(N):
  base = x[i] + L
  p = bisect.bisect_right(x, base)
  #print(p)
  r[0][i] = p - 1

#ダブリング
for k in range(m - 1):
  for i in range(N):
    r[k + 1][i] = r[k][r[k][i]]
#print(r)    
   
def isOK(mid):
  now = a
  pp = int(math.log(mid, 2) + 1)
  for i in range(pp):
    if (mid >> i) & 1:
      now = r[i][now]
      #print(now, a + 1, b + 1, mid)
  if now >= b:
    return True
  else:
    return False
  
Q = int(input())
for i in range(Q):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  if a > b:
    a, b = b, a
  ng = 0
  ok = 2 ** m
  while (abs(ok - ng) > 1):
    mid = int((ok + ng) / 2)
    #print(mid)
    if isOK(mid):
      ok = mid
    else:
      ng = mid
  print(ok)
### BUGGY CODE ###

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

res = True
if N >= 2:
    for i in range(N - 1):
        for j in range(1, N - i):
            if H[i] - H[i + j] >= 2:
                res = False
                break

if res == True:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

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

res = True
if N >= 2:
    for i in range(N - 1):
        if H[i] - H[i + 1] >= 2:
            res = False

y_card = 0
if N >= 3 and res == True:
    for i in range(N - 1):
        if H[i] - H[i + 1] == 1:
            y_card += 1
            if y_card == 2:
                res = False
                break
        elif H[i] == H[i + 1]:
            pass
        elif H[i + 1] - H[i] >= 1:
            y_card -= H[i + 1] - H[i]
            if y_card < 0:
                y_card = 0


if res == True:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

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

ans = S.count('R') * S.count('G') * S.count('B')
for i in range(N):
  a = S[i]
  for j in range(i+1,N):
    b = S[j]
    if (i+j)%2 :
      continue
    k = (i+j)//2
    if len(set([a,S[k],b])) == 3:
      ans -= 1
      
print(ans)

### FIXED CODE ###

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

ans = S.count('R') * S.count('G') * S.count('B')
for i in range(N):
  for j in range(i+1,N):
    if (i+j)%2 :
      continue
    k = (i+j)//2
    if len(set([S[i],S[k],S[j]])) == 3:
      ans -= 1
      
print(ans)
### BUGGY CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
town = 1
record = [1]
for i in range(N):
    town = A[town-1]
    if town in record:
        break
    record.append(town)
    
newrecord = record[record.index(town):]
roop = len(newrecord)
newK = K-(len(record)-roop)
if newK>=0:
    answer = newrecord[newK%roop]
else:
    answer = record[K]

print(answer)

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
town = 1
record = [1]
record2 = [0]*N
for i in range(N):
    town = A[town-1]
    if record2[town-1]==1:
        break
    record.append(town)
    record2[town-1] += 1
    
newrecord = record[record.index(town):]
roop = len(newrecord)
newK = K-(len(record)-roop)
if newK>=0:
    answer = newrecord[newK%roop]
else:
    answer = record[K]

print(answer)
### BUGGY CODE ###

n=int(input())
s=[input() for _ in range(n)]
cnt=0
for i in range(n):
  for j in range(i+1,n):
    for k in s[i]:
      if s[j].count(k)!=s[i].count(k):
        break
    else:
      cnt+=1
print(cnt)

### FIXED CODE ###

from collections import Counter
n=int(input())
s=[]
for _ in range(n):
  s.append(''.join(sorted([i for i in input()])))
s=Counter(s)
ans=0
for i in Counter(s).values():
  ans+=i*(i-1)//2
print(ans)
### BUGGY CODE ###

#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

cnt = 1
node = [1]*N

# from functools import lru_cache
# @lru_cache(None)
def f(depth, leaf, nodec):
    # print(depth, leaf, nodec)
    if depth == N:
        # print(' ', depth, leaf, nodec)
        if leaf == A[depth]:
            # OK!
            print(nodec)
            exit()
            return
        else:
            # NG
            return
    
    # NG
    if leaf < A[depth]:
        return 0

    # OK
    not_leaf = leaf - A[depth]
    for j in range(not_leaf*2, not_leaf-1, -1):
        f(depth+1, j, nodec+j)

f(0, 1, 1)
print(-1)

### FIXED CODE ###

# import numpy as np
import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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

if N == 0:
    if A[0] == 1:
        print(1)
        exit()
    else:
        print(-1)
        exit()
if N != 0 and A[0] > 0:
    print(-1)
    exit()

rcA = [0] * (N)
rcA[-1] = A[-1]
for i in range(1, N):
    rcA[-i - 1] = rcA[-i] + A[-i - 1]
# print(rcA)

cnt = 1
node = 1
for a, rca in zip(A, rcA):
    min_node = node - a
    max_node = 2 * (node - a)
    if rca < min_node or min_node < 0:
        print(-1)
        exit()
    node = min(max_node, rca)
    # print(node)
    cnt += node
if node != A[-1]:
    print(-1)
    exit()
print(cnt)
### BUGGY CODE ###

#E
n=int(input())
a=list(map(int,input().split()))
import fractions
lcm=a[0]
b_sum=0
for i in range(1,n):
    lcm=lcm*a[i]//fractions.gcd(lcm,a[i])

num=10**9+7
for i in range(n):
    b_sum+=(lcm//a[i])%num

print(b_sum%num)

### FIXED CODE ###

#E
n=int(input())
a=tuple(map(int,input().split()))
import fractions
lcm=a[0]
b_sum=0
for i in range(1,n):
    lcm=lcm*a[i]//fractions.gcd(lcm,a[i])

num=10**9+7
for i in range(n):
    b_sum+=(lcm//a[i])

print(b_sum%num)
### BUGGY CODE ###

A, B, C, K = map(int, input().split())
sum = 0
while K !=0:
    K = K - 1
    if A == 0 and B == 0:
        sum = sum - 1
    else :
        if A == 0:
            B = B -1
            sum = sum
        else:
            A = A -1
            sum = sum + 1
print(sum)

### FIXED CODE ###

A,B,C,K = map(int,input().split())
if A >= K:
    print(K)
else :
    if (K-A) <= B:
        print(A)
    else:
        print(A-(K-A-B))
### BUGGY CODE ###

N, W = map(int, input().split())
wv = []
for _ in range(N):
    wv.append(list(map(int, input().split())))
INF = 10**10
V = [v for w, v in wv]
v_max = sum(V)
dp = [[INF]*(v_max+1) for _ in range(N+1)]
dp[0][0] = 0
ans = 0
for i in range(N):
    for j in range(wv[i][1]):
        dp[i+1][j] = dp[i][j]
    for j in range(wv[i][1], v_max+1):
        dp[i+1][j] = min(dp[i][j], dp[i][j-wv[i][1]]+wv[i][0])
for j in range(v_max, 0, -1):
    if dp[N][j] <= W:
        print(j)
        break

### FIXED CODE ###

N, W = map(int, input().split())
wv = []
for _ in range(N):
    wv.append(list(map(int, input().split())))
INF = 10**10
v_max = 10**5
dp = [[INF]*(v_max+1) for _ in range(N+1)]
dp[0][0] = 0
ans = 0
for i in range(N):
    for j in range(v_max+1):
        if j >= wv[i][1]:
            dp[i+1][j] = min(dp[i][j], dp[i][j-wv[i][1]]+wv[i][0])
            #print(i, j, dp[i+1][j], dp[i][j], wv[i][0])
        else:
            dp[i+1][j] = dp[i][j]
        if i+1 == N and dp[i+1][j] <= W:
            ans = j
print(ans)
### BUGGY CODE ###

import numpy as np

n, m = map(int, input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
c = []
for i in range(m):
    a[i], b[i] = map(int, input().split())
    c.append(list(map(int, input().split())))

dp = [np.inf for i in range(2**n)]
dp[0] = 0

string = [0 for i in range(n)]
for i in c[0]:
    string[i-1] = 1
string = ''.join(map(str, string))
num = int(string, 2)
dp[num] = a[0]

for i in range(1, m):
    string = [0 for i in range(n)]
    for j in c[i]:
        string[j-1] = 1
    string = ''.join(map(str, string))
    di = int(string, 2)
    for j in range(2**n):
        dp[j|di] = min(dp[j|di], dp[j]+a[i])

if dp[2**n-1] != np.inf:
    print(dp[2**n-1])
else:
    print(-1)

### FIXED CODE ###

n, m = map(int, input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
c = []
for i in range(m):
    a[i], b[i] = map(int, input().split())
    c.append(list(map(int, input().split())))

dp = [10**6 for i in range(2**n)]
dp[0] = 0

string = [0 for i in range(n)]
for i in c[0]:
    string[i-1] = 1
string = ''.join(map(str, string))
num = int(string, 2)
dp[num] = a[0]

for i in range(1, m):
    string = [0 for i in range(n)]
    for j in c[i]:
        string[j-1] = 1
    string = ''.join(map(str, string))
    di = int(string, 2)
    for j in range(2**n):
        dp[j|di] = min(dp[j|di], dp[j]+a[i])

if dp[2**n-1] != 10**6:
    print(dp[2**n-1])
else:
    print(-1)
### BUGGY CODE ###

import math

def combination(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
eps = 10**9 + 7

x, y = map(int, input().split())
if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
    print(0)
elif 2 * y - x < 0 or 2 * x - y < 0:
    print(0)
else:
    vertical = (2 * y - x) // 3
    horizontal = (2 * x - y) // 3
    total = vertical + horizontal
    print(int(combination(total, horizontal) % eps))

### FIXED CODE ###

def multiple_of_n(x, y, n=3):
    return (x - y) % n == 0

def combination(g1, g2, inverse, n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min([r, n - r])
    return g1[n] * g2[r] * g2[n - r] % mod

def make_inv(mod, N):
    g1 = [1, 1]
    g2 = [1, 1]
    inverse = [0, 1]
    for i in range(2, N + 1):
        g1.append((g1[-1] * i) % mod)
        inverse.append((- inverse[mod % i] * (mod // i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)
    return g1, g2, inverse

mod = 10 ** 9 + 7

x, y = map(int, input().split())
if multiple_of_n(2 * x, y) and multiple_of_n(2 * y, x):
    vertical = (2 * y - x) // 3
    horizontal = (2 * x - y) // 3
    total = vertical + horizontal
    g1, g2, inverse = make_inv(mod, total)
    print(combination(g1, g2, inverse, total, horizontal, mod))
else:
    print(0)
### BUGGY CODE ###

N = int(input())
H = list(map(int, input().split()))
result = 0
tempres = 0
for i in range(0, N):
    for j in range(i, N - 1):
        if H[j] >= H[j + 1]:
            tempres += 1
        else:
            break
    result = max(result, tempres)
    tempres = 0
    if result >= N - i - 1:
        break
print(result)


### FIXED CODE ###

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

result = 0
tempres = 0
for i in range(0, N):
    if tempres != 0:
        tempres -= 1
        continue
    for j in range(i, N - 1):
        if H[j] >= H[j + 1]:
            tempres += 1
        else:
            break
    result = max(result, tempres)
    if result >= N - i - 1:
        break
print(result)
### BUGGY CODE ###

n = int(input())

dish_list = []
for i in range(n):
    ai, bi = list(map(int, input().split()))
    dish_list.append([ai, bi, ai+bi])




a, b = 0, 0
def dfs(dish_list, turn):
    if dish_list==[]:
        return
    # print("=================")
    # print(dish_list)
    global a
    global b


    #評価値が最大の皿をみつける
    max_id = 0
    max_p = 0
    for i, dish in enumerate(dish_list):
        if dish[2] > max_p:
            max_p = dish[2]
            max_id = i

    #幸福度を加算
    # print(max_id, max_p)
    if turn == -1:
        a+=dish_list[max_id][0]
    elif turn == 1:
        b+=dish_list[max_id][1]

    #評価値最大のさらを削除した新しい皿のリストを作る
    new_list = [list for i, list in enumerate(dish_list) if i!=max_id]
    dfs(new_list, turn*(-1))

dfs(dish_list, -1)

# print(a, b, a-b)

print(a-b)

### FIXED CODE ###

n = int(input())

dish_list = []
for i in range(n):
    ai, bi = list(map(int, input().split()))
    dish_list.append([ai, bi, ai+bi])


dish_list.sort(key = lambda x:x[2], reverse=True)


a, b =0, 0
turn = 1
for i in range(n):
    if turn ==1:
        a+=dish_list[i][0]
    else:
        b+=dish_list[i][1]
    turn*=-1

# print(a, b)
# a, b = 0, 0
# def dfs(dish_list, turn):
#     if dish_list==[]:
#         return
#     # print("=================")
#     # print(dish_list)
#     global a
#     global b
#
#
#     #評価値が最大の皿をみつける
#     max_id = 0
#     max_p = 0
#     for i, dish in enumerate(dish_list):
#         if dish[2] > max_p:
#             max_p = dish[2]
#             max_id = i
#
#     #幸福度を加算
#     # print(max_id, max_p)
#     if turn == -1:
#         a+=dish_list[max_id][0]
#     elif turn == 1:
#         b+=dish_list[max_id][1]
#
#     #評価値最大のさらを削除した新しい皿のリストを作る
#     new_list = [list for i, list in enumerate(dish_list) if i!=max_id]
#     dfs(new_list, turn*(-1))
#
# dfs(dish_list, -1)

# print(a, b, a-b)

print(a-b)
### BUGGY CODE ###

n = int(input())
ans = 0

p = []

for i in range(n-1):
  ans += (i+1) % (i+2)

print(ans)



### FIXED CODE ###

n = int(input())
ans = 0

p = []

if (n-1) % 2 == 0:
  ans = n * ((n-1) // 2)
else:
  ans = n * ((n-1) // 2) + (n // 2)

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

n = int(input())
s = str(input())
count = 0
for i in range(0,n):
    for j in range(0,n):
        for k in range(0,n):
            if i >= j or j >= k or i >= k :
                continue
            if (s[i] != s[j] and s[i] != s[k] and s[j] != s[k] )and (j - i != k - j):
                count += 1
                #print(i,j,k)
print(count)

### FIXED CODE ###

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

R = s.count("R")
G = s.count("G")
B = s.count("B")

counter = R * G * B 
#j-i != k-j
# 1 2 3 ,1 3 5

for i in range(n-1):
    for j in range(i+1,(n+i+1)//2):
        if s[i] != s[j] and s[i] != s[2*j-i] and s[2*j -i] != s[j] :
            counter -= 1

print(counter)
### BUGGY CODE ###

S=__import__('collections').deque(input())
for _ in range(int(input())):
	T=input()
	if T<'2':S.reverse()
	else:(S.appendleft if T[2]<'2'else S.append)(T[4])
print(*S,sep='')

### FIXED CODE ###

S,f=__import__('collections').deque(input()),0
for _ in range(int(input())):
	T=input()
	if T<'2':f=1-f
	else:(S.appendleft if (T[2]<'2')^f else S.append)(T[4])
if f:S.reverse()
print(*S,sep='')
### BUGGY CODE ###

S = input()
Q = int(input())

add_to_last = []
add_to_beginning = []

mode = 1
for i in range(Q):
  query = input()
  if query=='1':
    mode *= -1
  else:
    _, F, C = query.split()
    if F=='1':
      if mode==1:
        add_to_beginning.insert(0,C)
      else:
        add_to_last.append(C)
    else:
      if mode==1:
        add_to_last.append(C)
      else:
        add_to_beginning.insert(0,C)

S = "".join(add_to_beginning+[S]+add_to_last)

if mode==-1:
  S = S[::-1]

print(S)


### FIXED CODE ###

S = input()
Q = int(input())

add_to_last = []
add_to_beginning = []

queries = [input() for _ in range(Q)]

mode = 1
for i in range(Q):
  query = queries[i]
  if query=='1':
    mode *= -1
  else:
    _, F, C = query.split()
    if F=='1':
      if mode==1:
        add_to_beginning.append(C)
      else:
        add_to_last.append(C)
    else:
      if mode==1:
        add_to_last.append(C)
      else:
        add_to_beginning.append(C)   

if mode==1:
  add_to_beginning.reverse()
  print("".join(add_to_beginning), end="")
  print(S, end="")
  print("".join(add_to_last))
else:
  add_to_last.reverse()
  print("".join(add_to_last), end="")
  print(S[::-1], end="")
  print("".join(add_to_beginning))
### BUGGY CODE ###

n = int(input())
s = list(input())
def count_combination(x):
    if sum(x) != n:
        return(0)
    total_count = 1
    false_count = 0
    for i in range(2*n):
        if x[i]:
            total_count *= false_count
            false_count -= 1
        else:
            false_count += 1
        if false_count == -1:
            return(0)
    return(total_count)
sb = list(map(lambda x: False if x == 'W' else True, s))
sb[::2] = list(map(lambda x: not x, sb[::2]))

total_count = count_combination(sb)

permutation = 1
for _ in range(n):
    permutation = permutation * (_ + 1) % (10**9+7)

print(total_count * permutation % (10**9+7))

### FIXED CODE ###

from functools import reduce
n = int(input())
s = list(input())
def count_combination(x):
    if sum(x) != n:
        return(0)
    total_count = 1
    false_count = 0
    for i in range(2*n):
        if x[i]:
            total_count = total_count*false_count%(10**9+7)
            false_count -= 1
        else:
            false_count += 1
        if false_count == -1:
            return(0)
    return(total_count)
sb = list(map(lambda x: False if x == 'W' else True, s))
sb[::2] = list(map(lambda x: not x, sb[::2]))

total_count = count_combination(sb)

permutation = reduce(lambda x, y: x*y%(10**9+7), range(1,n+1))

print(total_count * permutation % (10**9+7))
### BUGGY CODE ###

N=int(input())
P=[list(map(int,input().split()))]
import functools
import operator
result = functools.reduce(operator.mul,P[0])
if result>10**18:
    print(-1)
else:
    print(result)
    

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
A.sort()
B=1
for i in A:
  B*=i
  if(B>10**18):
    B=-1
    break
print(B)
### BUGGY CODE ###

from fractions import gcd
from functools import reduce

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def solve(N, A):
    mod = 10 ** 9 + 7
    lcm = lcm_list(A)
    ans = [lcm//a for a in A]
    return sum(ans) % mod


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    ans = solve(N, A)
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

from fractions import gcd
from functools import reduce
import sys
def lcm_base(x, y):
    return (x * y) // gcd(x, y)
 
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
 
def solve(N, A):
    mod = 10 ** 9 + 7
    lcm = lcm_list(A)
    ans = [lcm//a for a in A]
    return sum(ans) % mod
    
 
def main():
    read = sys.stdin.buffer.read
    N,*A = map(int,read().split())
    ans = solve(N, A)
    print(ans)
 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

def main():
  from collections import deque
  s,*c=open(0)
  h,w=map(int,s.split())
  c=''.join(t[:w]for t in c)
  f=[-1]*h*w
  q=deque()
  for i in range(h*w):
    if c[i]=='#':
      q.append(i)
      f[i]=0
  while q:
    y=q.popleft()
    v=f[y]
    y,x=divmod(y,w)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
      k=i*w+j
      if h>i>=0<=j<w and'.'==c[k]*(f[k]<0):
        f[k]=v+1
        q.append(k)
  print(v)
if __name__=='__main__':
  main()

### FIXED CODE ###

from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)
### BUGGY CODE ###

H,W=map(int,input().split())
hlen = list(map(int,input().split()))
wlen =	list(map(int,input().split()))
hlen.sort(reverse=True)
wlen.sort(reverse=True)
hhlen =[0 for _ in range(H*W+1)]
wwlen =[0 for _ in range(H*W+1)]
for x,xx in zip([hlen,wlen],[hhlen,wwlen]):
	for y in x:
		if xx[y] == 1:
			print(0)
			exit()
		else:
			xx[y] = 1

def is_unique(l):
    return len(l) == len(set(l))
if not is_unique(hlen) or not is_unique(wlen):
	print(0)
	exit()

def Count(x,l):
	ret = 0
	while l[ret] > x :
		ret += 1
		if ret == len(l):
			break
	return ret	


m = max(hlen[0],wlen[0])
count = 1
for num in range(1,H*W+1)[::-1]:
	flagh = 0
	flagw = 0
	if hhlen[num]:
		flagh = 1
	if wwlen[num]:
		flagw = 1
	if flagh and flagw:
		count *= 1
	elif flagh:
		count *= wwlen[num:].count(1)
	elif flagw:
		count *= hhlen[num:].count(1)
	else:
		count *= hhlen[num:].count(1)*wwlen[num:].count(1) - (m-num)
	#print(num,flagh,flagw,count)
print(count % (10**9+7))

### FIXED CODE ###

H,W=map(int,input().split())
hlen = list(map(int,input().split()))
wlen =	list(map(int,input().split()))
hlen.sort(reverse=True)
wlen.sort(reverse=True)
hlen.append(0)
wlen.append(0)

m = H*W
count = 1
h=0
w=0
for num in range(1,H*W+1)[::-1]:
	if hlen[h] == num and wlen[w] == num:
		count *= 1
		h += 1
		w += 1
	elif hlen[h] == num:
		count *= w
		h += 1
	elif wlen[w] == num:
		count *= h
		w += 1
	else:
		count *= h*w - (m-num)
	#print(num,flagh,flagw,count)
	count %= (10**9+7)
print(count)
### BUGGY CODE ###

# input
K, S = map(int, input().split())

ans = 0

for i in range(min([S + 1, K + 1])):
    for j in range(min([S -i + 1, K + 1])):
        for k in range(min([S - i - j + 1, K + 1])):
            if i + j + k == S:
                ans += 1

print(ans)

### FIXED CODE ###

# input
K, S = map(int, input().split())

ans = 0

for i in range(min([S + 1, K + 1])):
    for j in range(min([S -i + 1, K + 1])):
        if S - i - j <= K:
            ans += 1

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


n = int(input())
numbers = list(map(int, input().split(' ')))

for i in range(n):
    used_list = []
    sonuc = 0
    for j in range(n):
        if j == i:
            continue
        if numbers[j] not in used_list:
            counter = numbers.count(numbers[j])
            used_list.append(numbers[j])
        else:
            continue
        if numbers[j] == numbers[i]:
            counter -= 1
        # print("count", counter)
        sonuc += int(counter*(counter-1)/2)
    print(sonuc)

### FIXED CODE ###

n = int(input())
numbers = list(map(int, input().split(' ')))

counters = {}
cevap_list = {}
sayilar = set(numbers)
for i in numbers:
    if i in counters:
        counters[i] += 1
    else:
        counters[i] = 1

sonuc = 0
for sayi in counters:
    count = counters[sayi]
    sonuc += int(count * (count - 1) / 2)


for i in range(n):
    print(sonuc-counters[numbers[i]]+1)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    print(a.index(i + 1) + 1, end=" ")


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
count = 1
for i in a:
    ans[i - 1] = count
    count+=1
for i in ans:
    print(i,end=" ")
### BUGGY CODE ###

from functools import reduce
import math

num = int(input())
sum = 0

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

for a in range(1, num + 1):
  for b in range(1, num + 1):
    for c in range(1, num + 1):
      sum += gcd(a, b, c)

print(sum)

### FIXED CODE ###

import math

num = int(input())
sum = 0

for a in range(1, num + 1):
  for b in range(1, num + 1):
    gcd_ab = math.gcd(a, b)
    for c in range(1, num + 1):
      sum += math.gcd(gcd_ab, c)

print(sum)
### BUGGY CODE ###

NKQ = list(map(int,input().split()))
point = [NKQ[1]]*NKQ[0]

for i in range(NKQ[2]):
    A = int(input())
    for j in range(NKQ[0]):
        if j != A-1:
            point[j] -= 1

for k in range(NKQ[0]):
    if point[k] > 0:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

NKQ = list(map(int,input().split()))
point = [0]*NKQ[0]

for i in range(NKQ[2]):
    A = int(input())
    point[A-1] += 1

for j in range(NKQ[0]):
    if NKQ[1] - NKQ[2] + point[j] > 0:
        print('Yes')
    else:
        print('No')