Arrange and Count!
Time limit5sMemory limit512 MB
Given a sequence, count modulo 1e9+7 how many distinct orderings the prefix-reversal-then-append operation can produce, over multiple test cases.
- Level
Hard8 of 10
- Topics
- Combinatorics, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
Alice has a sequence . She can rearrange the sequence using the following operation any number of times:
- Select an integer () and change the sequence to .
Alice wants to know how many different sequences can be obtained, modulo .
Input
The input consists of several test cases terminated by end-of-file. For each test case:
The first line contains an integer , the length of the sequence.
The second line contains integers .
Output
For each test case, print an integer which denotes the result.
Constraints
- The sum of does not exceed .