PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000048. Đếm dãy con có đầu không lớn hơn cuối (LEQ)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm dãy con có đầu không lớn hơn cuối (LEQ)
LEQ
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer sequence , count not necessarily contiguous subsequences of length at least 2 whose first element is at most the last element. Different index sets count separately. Print modulo .
Input
The first line contains . The second line contains integers .
Output
Print the result modulo .
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
3
1 2 1
Output
3
Explanation
Valid index selections are (1,2), (1,3) and (1,2,3). Selection (2,3) fails since 2 is greater than 1.