#FT0000102. Phân nhóm đàn bò biểu tình (Generic Cow Protests)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phân nhóm đàn bò biểu tình (Generic Cow Protests)
Generic Cow Protests
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
Farmer John has cows standing in a line, numbered through . Cow has an integer rationality level , which may be negative, zero, or positive.
John wants to partition the entire line into one or more nonempty consecutive groups. Every cow must belong to exactly one group. A partition is valid if the sum of rationality levels within every group is nonnegative.
Count all ways to place boundaries between cows such that the resulting partition is valid. Different boundary sets count as different partitions. Print the count modulo .
Input
- The first line contains integer , the number of cows.
- Each of the next lines contains integer , the rationality level of cow in order.
Output
Print one integer: the number of valid partitions modulo .
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Example 1
Input
4
2
3
-3
1
Output
4
Explanation
The rationality levels are . The four valid partitions are with sum ; with sums ; with sums ; and with sums . Every group's sum is nonnegative. All other boundary choices create a negative-sum group, so print 4.
Example 2
Input
1
-1
Output
0
Explanation
There is one cow with level . The only partition is the single group , whose sum is negative. No valid partition exists, so print 0.