#DSU0000057. Các tập con đặc biệt (Special Subsets)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các tập con đặc biệt (Special Subsets)
Special Subsets
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Let and let be a function from to itself, specified by the values .
A subset of is special if it is nonempty and satisfies two conditions. First, for every , the value must also belong to . Second, for any two distinct elements , their images and must be different. Thus the restriction of to never maps two different selected elements to the same value.
Count all special subsets and print the count modulo . Two subsets are different if their sets of elements differ.
Input
The first line contains ; the next contains .
Output
Print the number of valid subsets modulo .
Subtasks
- Subtask 1 (20 points): ; ; report the count modulo .
- Subtask 2 (30 points): ; ; report the count modulo .
- Subtask 3 (50 points): ; ; report the count modulo .
Examples
Input
3
1 2 3
Output
7
Explanation
There are three self-loops. Any nonempty selection of these three cycles works, giving .