eolymp
bolt
Try our new interface for solving problems
Problems

Generic Cow Protests

Generic Cow Protests

Farmer John's n cows are lined up in a row and numbered from 1 to n. The cows are conducting another one of their strange protests, so each cow i is holding up a sign with an integer ai.

FJ knows the mob of cows will behave if they are properly grouped and thus would like to arrange the cows into one or more contiguous groups so that every cow is in exactly one group and that every group has a nonnegative sum.

Help him count the number of ways he can do this, modulo 109 + 9.

By way of example, if n = 4 and the cows' signs are 2, 3, -3 and 1, then the following are the only four valid ways of arranging the cows:

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

Note that this example demonstrates the rule for counting different orders of the arrangements.

Input

First line contains a single integer n (1n105). Each line from 2 to n + 1 contains a single integer ai (-104ai104).

Output

Print a single integer, the number of arrangements modulo 109 + 9.

Time limit 1 second
Memory limit 128 MiB
Input example #1
4
2
3
-3
1
Output example #1
4
Source 2011 USACO February Gold