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: import sys
  N, M = map(int, input().split())
  A = [int(a) for a in input().split()]
  B = [int(b) for b in input().split()]
  
  A.sort(reverse=True)
  B.sort(reverse=True)
  
  if len(set(A))!=len(A) or len(set(B))!=len(B):
      print(0)
      sys.exit()
  
  ans = 1
  rows, columna = 0,0
  mod = 10**9+7
  for x in range(N*M, 0, -1):
  
      if x in A and x in B:
          rows += 1
          columna += 1
  
      elif x in A and not x in B:
          rows += 1
          ans = ans * (columna)
  
      elif x in B and not x in A:
          columna += 1
          ans = ans *(rows)
  
      else:
          ans = ans * (rows * columna -(N*M-x
  
      ans %= mod    
  
  print(ans%(10**9+7))
  
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"}]