Congress of Young Enthusiasts
InterviewTime limit2sMemory limit256 MB
Count the ways to seat n mathematicians and n philosophers in 2n chairs of types 1, 2, and 3, modulo 10^9 + 7.
- Level
Medium4 of 10
- Topics
- Combinatorics, Math
- Solved
- No attempts yet
Problem
On February 37, 3015, the Congress of Young Enthusiasts of Mathematics and Philosophy was declared open. Each of the countries sent one mathematician and one philosopher. A meeting with all participants will take place in two hours, and the organizers have not yet decided how to seat them. The meeting hall has chairs in a row. There are three types of chairs: a type 1 chair can seat only a mathematician, a type 2 chair can seat only a philosopher, and a type 3 chair can seat any participant.
Input
The first line contains one positive integer , the number of tests. Each test is described by two lines. The first line contains one integer , the number of countries. The second line contains positive integers from 1 to 3, where the -th number gives the type of the -th chair. The sum of over all tests does not exceed 100.
Output
For each test, print the number of ways to seat the participants, modulo .