#P8043. Expected Piano Performance
Expected Piano Performance
Expected Piano Performance
Alisa, a young girl, loves to play the piano with just one finger. However, she has never learned to play the piano, so every key press is completely random. More precisely, each time she presses a key she independently and with equal probability chooses one of the tones available on the piano.
Mirta, Alisa's good friend, wishes to hear a piece consisting of a contiguous sequence of tones . Since Alisa plays randomly, Mirta is curious about the expected number of key presses needed until she hears, for the first time, the sequence for each . To avoid issues with floating–point precision, the answer for each prefix must be given modulo .
Formally, for each from 1 to , let be the pattern. When keys are pressed one by one (each chosen uniformly at random among the tones and independently of the past), let be the expected number of presses needed until the pattern appears as a contiguous subsequence for the first time. You are to compute modulo for every prefix of the given sequence.
inputFormat
The input consists of two lines. The first line contains two integers and : the number of piano tones and the length of Mirta’s desired sequence. The second line contains integers , representing the sequence of tones.
outputFormat
Output lines, where the -th line contains a single integer: the expected number of key presses required until the sequence appears for the first time, taken modulo .
sample
2 2
1 2
2
4
</p>