Ways to Wear Distinct Hats

Given n people each with a list of hats they like, count the number of ways to assign a distinct hat to each person from hats labeled 1 to 40. Return the answer modulo 10^9 + 7.

Examples
Input: [[3,4],[4,5],[5]]
Output: 1
Hints

Ways to Wear Distinct Hats

Given n people each with a list of hats they like, count the number of ways to assign a distinct hat to each person from hats labeled 1 to 40. Return the answer modulo 10^9 + 7.