#P8043. [COCI 2016/2017 #7] KLAVIR

[COCI 2016/2017 #7] KLAVIR

Problem Description

Young Alisa likes to play the piano using only one finger. However, since Alisa has never learned how to play the piano, her playing process is completely random. More precisely, she chooses any one of the NN notes on the piano with equal probability, and this choice is independent of all previously chosen notes.

Alisa's good friend Mirta wants to hear a piece consisting of MM consecutive notes A1,A2,,AMA_1, A_2, \dots, A_M. But since Alisa's playing is completely random, Mirta only wants to know, for every 1iM1\leqslant i\leqslant M, the expected number of choices Alisa makes until Mirta hears the consecutive notes A1,A2,,AiA_1, A_2, \dots, A_i for the first time. To avoid precision loss, take the answers modulo 109+7\bf 10^9+7.

Input Format

The first line contains an integer NN, the number of notes.
The second line contains an integer MM, the number of notes in the piece that Mirta wants to hear.
The third line contains MM integers AiA_i, where AiA_i is the ii-th note of the piece.

Output Format

Output MM lines, each containing a positive integer. The ii-th line should be the expected number of choices Alisa makes until Mirta hears the consecutive notes A1,A2,,AiA_1, A_2, \dots, A_i for the first time, taken modulo 109+7\bf 10^9+7.

2
2
1 2
2
4
2
2
1 1
2
6
3
3
1 2 3
3
9
27

Hint

Constraints

For 40%40\% of the testdata, 1M2001\leqslant M\leqslant 200.
For all testdata, 1N1001\leqslant N\leqslant 100, 1M1061\leqslant M\leqslant 10^6, 1AiN1\leqslant A_i\leqslant N.

Source

This problem is from COCI 2016-2017 CONTEST 7 T6 KLAVIR, with the original testdata settings and a full score of 160160 points.

Translated and organized by Eason_AC.

Translated by ChatGPT 5