#P8434. 「WHOI-2」D&D
「WHOI-2」D&D
Background
Have you noticed that something is missing?
Our miku decided to go shopping. But by an unfortunate coincidence, there are very few decorations in her home, and she only has some numbers that can be used as decorations.
However, miku found that if there is a set of numbers formed by several decorations, then the subset of is the best-looking one (although we do not know why). So this problem was created.
But since you have seen the title, you should know where miku is going (just kidding).
Problem Description
Given a set without duplicates , define its decorative subset as
Here, denotes bitwise OR. Also, means and .
miku has a positive integer sequence of length . You need to partition this sequence into several (at least one) contiguous substrings. It is required that the decorative subsets of the sets without duplicates formed by the elements of these substrings are the same.
Compute the number of valid partitioning schemes modulo .
Input Format
The first line contains one positive integer .
The next line contains a positive integer sequence of length , representing .
Output Format
Output one positive integer, the answer.
10
1 2 3 4 5 5 4 3 2 1
2
9
1 2 2 1 1 1 2 2 1
16
Hint
[Explanation for Sample #1] It can be proven that the two ways are:
The sets without duplicates formed by these three subsets are all . Their decorative subsets are all . The details are as follows:
- , so it does not belong.
- , so it does not belong.
- , so it belongs.
- , so it does not belong.
- , so it belongs.
This problem uses bundled testdata.
- .
- .
- . Where .
- . Where it is not guaranteed that .
- It is guaranteed that is generated randomly.
- No special restrictions. The time limit is .
For of the data, it is guaranteed that .
Input Format
The first line contains one positive integer .
The next line contains a positive integer sequence of length , representing .
Output Format
Output one positive integer, the answer.
Hint
Constraints: For of the data, it is guaranteed that .
Translated by ChatGPT 5