Generic Cow Protests#2599

Generic Cow Protests

1 second
128 megabytes
Very easy

cows are lined up in a row and numbered from to . Each cow holds a sign with an integer a_i.

It is required to divide the cows into one or more contiguous groups so that each cow belongs to exactly one group, and the sum of the numbers in each group is nonnegative.

Count the number of ways to do this, modulo 10^9 + 9.

For example, if n = 4 and the numbers on the cows' signs are 2, 3, -3, 1, there are four possible ways to group the cows:

(2 3 -3 1)
(2 3 -3) (1)
(2) (3 -3 1)
(2) (3 -3) (1)

Input

The first line contains one integer (1 \leq n \leq 10^5). Each of the following lines contains one integer a_i (-10^4 \leq a_i \leq 10^4).

Output

Print a single integer — the number of ways to group the cows, modulo 10^9 + 9.

Examples

Example 1

Loading
Loading