#C6521. T-shirt Distribution
T-shirt Distribution
T-shirt Distribution
In this problem, you are given several test cases. Each test case consists of an integer (N) representing the number of employees, followed by two lists of (N) integers each. The first list gives the required T-shirt sizes for each employee, and the second list gives the available T-shirt sizes in the company. A valid distribution is one where, after assigning T-shirts in any order, the sorted list of given T-shirt sizes matches the sorted list of required sizes. In other words, if the multiset of available T-shirts equals that of the required sizes, then every permutation of the available list is counted as a valid distribution. The answer for a test case is the number of valid distributions, which is (N!) (i.e. factorial of (N)) if the two multisets match, and 0 otherwise.
For example, if there are 3 employees with required sizes [1, 2, 3] and available sizes [3, 2, 1], then there are (3! = 6) valid ways to distribute the shirts.
inputFormat
The input starts with a single integer (T) denoting the number of test cases. For each test case, the first line contains an integer (N) (the number of employees). The next line contains (N) space-separated integers representing the required T-shirt sizes, and the following line contains (N) space-separated integers representing the available T-shirt sizes.
outputFormat
For each test case, output a single line with the number of valid T-shirt distributions. The output for each test case should be printed on a new line.## sample
2
3
1 2 3
3 2 1
2
1 1
1 1
6
2
</p>