#P8043. Expected Piano Performance

    ID: 21227 Type: Default 1000ms 256MiB

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 NN tones available on the piano.

Mirta, Alisa's good friend, wishes to hear a piece consisting of a contiguous sequence of MM tones A1,A2,,AMA_1, A_2, \dots, A_M. Since Alisa plays randomly, Mirta is curious about the expected number of key presses needed until she hears, for the first time, the sequence A1,A2,,AiA_1, A_2, \dots, A_i for each 1iM1 \le i \le M. To avoid issues with floating–point precision, the answer for each prefix must be given modulo 109+710^9+7.

Formally, for each ii from 1 to MM, let P=A1A2AiP=A_1A_2\cdots A_i be the pattern. When keys are pressed one by one (each chosen uniformly at random among the NN tones and independently of the past), let E(P)E(P) be the expected number of presses needed until the pattern PP appears as a contiguous subsequence for the first time. You are to compute E(P)E(P) modulo 109+710^9+7 for every prefix PP of the given sequence.

inputFormat

The input consists of two lines. The first line contains two integers NN and MM: the number of piano tones and the length of Mirta’s desired sequence. The second line contains MM integers A1,A2,,AMA_1, A_2, \dots, A_M, representing the sequence of tones.

outputFormat

Output MM lines, where the ii-th line contains a single integer: the expected number of key presses required until the sequence A1,A2,,AiA_1, A_2, \dots, A_i appears for the first time, taken modulo 109+710^9+7.

sample

2 2
1 2
2

4

</p>