atcoder#AGC003E. [AGC003E] Sequential operations on Sequence

[AGC003E] Sequential operations on Sequence

Score : 14001400 points

Problem Statement

Snuke got an integer sequence from his mother, as a birthday present. The sequence has NN elements, and the ii-th of them is ii. Snuke performs the following QQ operations on this sequence. The ii-th operation, described by a parameter qiq_i, is as follows:

  • Take the first qiq_i elements from the sequence obtained by concatenating infinitely many copy of the current sequence, then replace the current sequence with those qiq_i elements.

After these QQ operations, find how many times each of the integers 11 through NN appears in the final sequence.

Constraints

  • 1N1051 \leq N \leq 10^5
  • 0Q1050 \leq Q \leq 10^5
  • 1qi10181 \leq q_i \leq 10^{18}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN QQ

q1q_1

:

qQq_Q

Output

Print NN lines. The ii-th line (1iN)(1 \leq i \leq N) should contain the number of times integer ii appears in the final sequence after the QQ operations.

5 3
6
4
11
3
3
3
2
0

After the first operation, the sequence becomes: 1,2,3,4,5,11,2,3,4,5,1.

After the second operation, the sequence becomes: 1,2,3,41,2,3,4.

After the third operation, the sequence becomes: 1,2,3,4,1,2,3,4,1,2,31,2,3,4,1,2,3,4,1,2,3.

In this sequence, integers 1,2,3,4,51,2,3,4,5 appear 3,3,3,2,03,3,3,2,0 times, respectively.

10 10
9
13
18
8
10
10
9
19
22
27
7
4
4
3
3
2
2
2
0
0