We are going to take a photo of N students in a line. We want to take the best photo. A photo is considered to be the best when the maximum number of students are satisfied. A student is satisfied if he is the right neighbor of his best friend. Each student has only one best friend. You have to find the number of satisfied students in the best photo and the number of different best photos. Print these values modulo (109+7).
The first line contains an integer T indicating the total number of test cases. Each test case begins with an integer N, the number of students.
The second line contains N integers denoting the array A where A[i] is the best friend of the ith student.
Constraints
Print two integers, the number of satisfied students in the best photo and the number of different best photos. Print these values modulo 1000000007.
1 3 2 3 1
2 3
Maximum two students can be satisfied.
There are three possible arrangements of students that result in a photo with maximum number of satisfied students:
1) 1 3 2
2) 3 2 1
3) 2 1 3
Migrated from old NTUJ.
CounterCode 2015
No. | Testdata Range | Score |
---|