output_description: If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974",
  print `YES`; if they cannot, print `NO`.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N_1 N_2 N_3 N_4
attempt: # 問題D
  M, N = list(map(int, input().split()))
  ROW = list(map(int, input().split()))
  COL = list(map(int, input().split()))
  # M= 3
  # N= 3
  # ROW = [8,9,7]
  # COL = [6,9,8]
  # N,M = 14,13
  # ROW = [158, 167, 181, 147, 178, 151, 179, 182, 176, 169, #180, 129, 175, 168]
  # COL = [181, 150, 178, 179, 167, 180, 176, 169, 182, 177, #175, 159, 173]
  import numpy as np
  
  row = 0
  col = 0
  nums = np.arange(1, M * N + 1)[::-1]
  pattern = np.zeros(M * N)
  ans = 1
  # print(nums)
  for i in nums:
      if i in ROW and i in COL:
          row += 1
          col += 1
      #        pattern[i-1] = 1
      elif i in ROW and i not in COL:
          row += 1
          #        pattern[i-1] = col
          ans *= col
      elif i not in ROW and i in COL:
          col += 1
          #        pattern[i-1] = row
          ans *= row
  
      elif i not in ROW and i not in COL:
          #        pattern[i-1] = row * col - (M*N-i)
          ans *= row * col - (M * N - i)
  
          if row * col - (M * N - i) <= 0:
              ans = 0
              break
      ans %= 10**9 + 7
  #    print(i,row,col,pattern[i-1])
  # print(pattern)
  # ans = int(pattern.prod())
  # ans = ans % (10**9+7)
  print(ans)
  
problem_description: Statement
  
  You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be
  arranged into the sequence of digits "1974".
samples: [{"input": "1 7 9 4", "output": "YES\n    \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n    \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n    \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]