You are given a int[] S containing a set of distinct integers. A sequence is called a p-sequence of S if it satisfies both of the following conditions:
1. It contains each element of S exactly once.
2. For each pair of consecutive sequence elements s1 and s2, (s1 - s2) is not divisible by p.
Return the number of p-sequences of S, modulo 1234567891.
Definition |
|||||||||||||
|
|||||||||||||
Constraints |
|||||||||||||
- | S will contain between 1 and 30 elements, inclusive. | ||||||||||||
- | All elements of S will be distinct. | ||||||||||||
- | Each element of S will be between -1,000,000 and 1,000,000, inclusive. | ||||||||||||
- | p will be between 1 and 1,000, inclusive. | ||||||||||||
Examples |
|||||||||||||
0) | |||||||||||||
|
|||||||||||||
1) | |||||||||||||
|
|||||||||||||
2) | |||||||||||||
|
|||||||||||||
3) | |||||||||||||
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2006, TopCoder, Inc. All rights reserved.