Problem:
Score : 1400 points

Problem Statement

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

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

After these Q operations, find how many times each of the integers 1 through N appears in the final sequence.

Constraints

1 ≦ N ≦ 10^5

0 ≦ Q ≦ 10^5

1 ≦ q_i ≦ 10^{18}

All input values are integers.

Input

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

N Q
q_1
:
q_Q

Output

Print N lines. The i-th line (1 ≦ i ≦ N) should contain the number of times integer i appears in the final sequence after the Q operations.

Sample Input 1

5 3
6
4
11

Sample Output 1

3
3
3
2
0

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

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

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

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

Sample Input 2

10 10
9
13
18
8
10
10
9
19
22
27

Sample Output 2

7
4
4
3
3
2
2
2
0
0

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

const int MAX_LG = 17;
const int MAX_N = 1e5 + 5;
const ll INF = 1e18 + 5;

ll _qry [MAX_N];
ll keep [MAX_N];
vector<pair<ll, ll>> prevs [MAX_N];
// <idx, coef>; positive idx is query idx, negative is basis vector

ll lin [MAX_N];
ll bas [MAX_N];

int main () {
  ll n, q;
  cin >> n >> q;
  
  for (ll i = 0; i < q; i++) {
    cin >> _qry[i];
  }

  ll suffm = INF;
  for (ll i = q - 1; i >= 0; i--) {
    if (_qry[i] < suffm) {
      keep[i] = 1;
      suffm = _qry[i];
    }
  }

  vector<ll> qs;
  if (n < suffm) {
    qs.push_back(n);
  }
  for (ll i = 0; i < q; i++) {
    if (keep[i]) {
      qs.push_back(_qry[i]);
    }
  }

  q = qs.size();
  
  prevs[0] = vector<pair<ll, ll>> (1, make_pair(-qs[0], 1));
  for (ll i = 1; i < q; i++) {
    ll cur = qs[i];

    while (true) {
      if (cur == 0) {
        break;
      } else if (cur < qs[0]) {
        prevs[i].push_back(make_pair(-cur, 1));
        break;
      } else {
        // search for the largest k with qs[k] <= cur
        ll idx = 0;
        for (ll k = 1 << MAX_LG; k != 0; k /= 2) {
          if (idx + k < i && qs[idx + k] <= cur) {
            idx += k;
          }
        }

        prevs[i].push_back(make_pair(idx, cur / qs[idx]));
        cur %= qs[idx];
      }
    }

    /*
    for (auto pr : prevs[i]) {
      cout << "(" << pr.first << " " << pr.second << ") ";
    }
    cout << endl;
    */
  }

  lin[q - 1] = 1;
  for (ll i = q - 1; i >= 0; i--) {
    ll coef = lin[i];
    lin[i] = 0;
    for (auto pr : prevs[i]) {
      if (pr.first < 0) {
        bas[-pr.first] += coef * pr.second;
      } else {
        lin[pr.first] += coef * pr.second;
      }
    }
  }

  for (ll i = n - 1; i >= 0; i--) {
    bas[i] += bas[i + 1];
  }
  for (ll i = 1; i <= n; i++) {
    cout << bas[i] << '\n';
  }
}