A die simulator generates a random number from 1 to 6 for each roll. You introduced a constraint to the generator such that it cannot roll the number i more than rollMax[i] (1-indexed) consecutive times. 
Given an array of integers rollMax and an integer n, return the number of distinct sequences that can be obtained with exact n rolls.
Two sequences are considered different if at least one element differs from each other. Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:
Input: n = 2, rollMax = [1,1,2,2,2,3]
Output: 34
Explanation: There will be 2 rolls of die, if there are no constraints on the die, there are 6 * 6 = 36 possible combinations. In this case, looking at rollMax array, the numbers 1 and 2 appear at most once consecutively, therefore sequences (1,1) and (2,2) cannot occur, so the final answer is 36-2 = 34.
Example 2:
Input: n = 2, rollMax = [1,1,1,1,1,1]
Output: 30
Example 3:
Input: n = 3, rollMax = [1,1,1,2,2,3]
Output: 181
Constraints:
1 <= n <= 5000
rollMax.length == 6
1 <= rollMax[i] <= 15
class Solution:
    def dieSimulator(self, n: int, rollMax: List[int]) -> int:
        M = pow(10, 9) + 7
        rollMax = [0] + rollMax
        dp = [[[0] * (15 + 1) for _ in range(6 + 1)] for _ in range(n + 1)]
        
        # 抛第一次骰子，出现数字 i 的次数
        for i in range(1, 6 + 1):
            dp[1][i][1] = 1
        
        for i in range(2, n + 1): # 第 i 次抛
            for j in range(1, 6 + 1): # 得到骰子的num数
                for k in range(1, rollMax[j] + 1): # 这个数字第 k次出现
                    if k > 1:
                        dp[i][j][k] = dp[i-1][j][k-1]
                    else:
                        for jj in range(1, 6 + 1):
                            for kk in range(1, rollMax[jj] + 1):
                                if jj != j:
                                    dp[i][j][k] += dp[i-1][jj][kk]
        
        res = 0
        for i in range(1, 7):
            for j in range(1, rollMax[i] + 1):
                res += dp[n][i][j]
        return res % M
class Solution:
    def dieSimulator(self, n: int, rollMax: List[int]) -> int:
        M = pow(10, 9) + 7
        rollMax = [0] + rollMax
        dp = [[[0] * (15 + 1) for _ in range(6 + 1)] for _ in range(n + 1)]
        
        # 抛第一次骰子，出现数字 i 的次数
        for i in range(1, 6 + 1):
            dp[1][i][1] = 1
        
        for i in range(2, n + 1): # 第 i 次抛
            for j in range(1, 6 + 1): # 得到骰子的num数
                for k in range(1, rollMax[j] + 1): # 这个数字第 k次出现
                    if k > 1:
                        dp[i][j][k] = dp[i-1][j][k-1]
                    else:
                        for jj in range(1, 6 + 1):
                            for kk in range(1, rollMax[jj] + 1):
                                if jj != j:
                                    dp[i][j][k] += dp[i-1][jj][kk]
        
        res = 0
        for i in range(1, 7):
            for j in range(1, rollMax[i] + 1):
                res += dp[n][i][j]
        return res % M