Unifying Values
InterviewTime limit0.5sMemory limit1024 MB
Count the ways to split a sequence of N integers into two or more contiguous parts with equal sums, modulo 1,000,000,007.
- Level
Medium6 of 10
- Topics
- Prefix sum, Hash map, Dynamic programming, Math
- Solved
- No attempts yet
Problem
A sequence of integers is given. You may split the sequence into two or more contiguous parts and compute the sum of the numbers in each part. Count the number of ways to split the sequence so that every part has the same sum.
For example, let the sequence be . You can split it into three parts , , , or into three parts , , . In both cases every part sums to . There are no other ways, so the answer for this input is .
Input
The first line contains an integer ().
The second line contains the integers of the sequence in order, separated by single spaces. Each integer is between and , inclusive.
Output
Print the number of ways to split the sequence. Since this number can be very large, print the remainder when divided by .