#SRD0000016. Trò chơi nhảy ô Sugoroku (Hop Sugoroku)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Trò chơi nhảy ô Sugoroku (Hop Sugoroku)
Hop Sugoroku
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are squares numbered through , along with positive integers . Initially, square is black, all other squares are white, and a game piece starts at square .
You may perform zero or more moves:
- When the piece is at square , choose a positive integer .
- Move to square , provided , then paint square black.
Since , the piece always moves right. After stopping at any time, consider the set of indices of black squares. Two plays count as distinct if and only if their final black-square sets differ. Count the achievable sets modulo .
Every actual move paints a new square to the right of all previously visited squares, so visited squares never repeat.
Input
The first line contains . The second line contains integers .
Output
Print the number of achievable sets of black squares modulo .
Subtasks
- Subtask 1 (10 points): ; ; mọi đầu vào là số nguyên. Kết quả lấy modulo .
- Subtask 2 (15 points): ; ; mọi đầu vào là số nguyên. Kết quả lấy modulo .
- Subtask 3 (25 points): ; ; mọi đầu vào là số nguyên. Kết quả lấy modulo .
- Subtask 4 (50 points): ; ; mọi đầu vào là số nguyên. Kết quả lấy modulo .
Examples
Input
5
1 2 3 1 1
Output
8
Explanation
The eight possible black-square sets are , , , , , , , and . Each set corresponds to a strictly increasing visited-square sequence. Making zero moves gives .