Consecutive lectures are hard (Easy)
InterviewTime limit1sMemory limit1024 MB
Count the timetables that include every mandatory period and whose longest run of consecutive chosen periods is exactly k, modulo 1e9+7.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Prefix sum
- Solved
- No attempts yet
Problem
This problem is a subproblem of Consecutive lectures are hard (Hard), and you can get it accepted by submitting the correct solution to Hard.
Dohoon failed to register for courses last semester.
A school day has periods , and each of the distinct classes takes exactly one distinct period. In this registration, Dohoon wants to pick classes so that the longest run of consecutive classes is exactly periods long. The same run of periods may appear more than once.

Some of the possible cases for Sample 1.
In both cases, the longest run of consecutive classes is exactly 2 periods.
Some classes are mandatory, though. Take them into account and help Dohoon register!
Input
The first line contains two integers and , separated by a space.
The second line contains integers , separated by spaces. is 1 if the class in period is mandatory, and 0 otherwise.
Output
Print the number of timetables in which the longest run of consecutive classes is exactly periods among periods , modulo .
Constraints
- .
- .