input: from typing import List
  from functools import lru_cache as cache
  def number_of_permutations(n: int, requirements: List[List[int]]) -> int:
      """
      You are given an integer n and a 2D array requirements, where requirements[i] = [end_i, cnt_i] represents the end index and the inversion count of each requirement.
  
      A pair of indices (i, j) from an integer array nums is called an inversion if:
  
      i < j and nums[i] > nums[j]
      Return the number of permutations perm of [0, 1, 2, ..., n - 1] such that for all requirements[i], perm[0..endi] has exactly cnti inversions.
  
      Since the answer may be very large, return it modulo 10^9 + 7.
  
      Examples:
      >>> n = 3, requirements = [[2,2],[0,0]]
      2
      >>> n = 3, requirements = [[2,2],[1,1],[0,0]]
      1
  
      Constraints:
      2 <= n <= 300
      1 <= requirements.length <= n
      requirements[i] = [end_i, cnt_i]
      0 <= end_i <= n - 1
      0 <= cnt_i <= 400
      The input is generated such that there is at least one i such that end_i == n - 1.
      The input is generated such that all endi are unique
      """
  
output: 
      MOD = 10**9 + 7
  
      @cache
      def count_inversions(end: int, inversions: int) -> int:
          if inversions < 0:
              return 0
          if end == 0:
              return 1 if inversions == 0 else 0
          return (count_inversions(end - 1, inversions) + count_inversions(end - 1, inversions - 1)) % MOD
  
      requirements.sort()
      dp = [0] * (n + 1)
      dp[0] = 1
  
      for end, cnt in requirements:
          for i in range(end, -1, -1):
              dp[i] = sum(dp[j] * count_inversions(end - j, cnt - (end - i)) for j in range(i)) % MOD
  
      return dp[n]
  