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++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include<bits/stdc++.h>
#define MX 30001000
using namespace std;
struct treaps
{
	int son[MX][2],num[MX],cop[MX],inn[MX],tt;
	long long size[MX],ans[MX];
	int newnode(int s=0)
	{
		if (tt>MX) assert(0); 
		int t=++tt;
		son[t][0]=son[s][0];
		son[t][1]=son[s][1];
		size[t]=size[s];
		num[t]=num[s];
		return t;
	}
	void update(int s) {size[s]=size[son[s][0]]+size[son[s][1]]+1;}
	int merge(int s,int t)
	{
		if (!s) return t;if (!t) return s;
		if (((long long)rand()*rand()*rand()*rand()+rand())%(size[s]+size[t])<size[s])
		{
			int d=newnode(s);
			son[d][1]=merge(son[d][1],t);
			update(d);
			return d;
		}
		else
		{
			int d=newnode(t);
			son[d][0]=merge(s,son[d][0]);
			update(d);
			return d;
		}
	}
	pair<int,int> split(int s,long long k)
	{
		if (!s) return pair<int,int>(0,0);
		if (size[son[s][0]]>=k)
		{
			pair<int,int> ls=split(son[s][0],k);
			int d=newnode(s);
			son[d][0]=ls.second;update(d);
			return pair<int,int>(ls.first,d);
		}
		pair<int,int> ls=split(son[s][1],k-size[son[s][0]]-1);
		int d=newnode(s);
		son[d][1]=ls.first;update(d);
		return pair<int,int>(d,ls.second);
	}
	void clear(int& s){s=0;}
	void push_back(int& s,int w)
	{
		int t=newnode();
		size[t]=1;num[t]=w;
		s=merge(s,t);
	}
	void pop_back(int& s)
	{
		s=split(s,size[s]-1).first;
	}
	/*int findkth(int s,int k)
	{
		if (size[son[s][0]]>=k) return findkth(son[s][0],k);
		if (size[son[s][0]]+1==k) return num[s];
		return findkth(son[s][1],k-(size[son[s][0]]+1));
	}*/
	void work(int n,int root)
	{
		for (int i=1;i<=tt;i++) {inn[son[i][0]]++;inn[son[i][1]]++;size[i]=(i==root);}
		int head=0,tail=0;
		for (int i=1;i<=tt;i++) if (inn[i]==0) cop[++head]=i;
		while (head!=tail)
		{
			int s=cop[++tail];ans[num[s]]+=size[s];
			inn[son[s][0]]--;inn[son[s][1]]--;size[son[s][0]]+=size[s];size[son[s][1]]+=size[s];
			if (inn[son[s][0]]==0) cop[++head]=son[s][0];
			if (inn[son[s][1]]==0) cop[++head]=son[s][1];
		}
		for (int i=1;i<=n;i++) printf("%lld\n",ans[i]);
	}			
}treap; 
long long st[100010];
int top;
int main()
{
	//freopen("01.txt","r",stdin);
	//freopen("my.out","w",stdout);
	int n,q,root=0;scanf("%d%d",&n,&q);
	for (int i=1;i<=n;i++) treap.push_back(root,i);
	for (int i=1;i<=q;i++)
	{
		long long w;scanf("%lld",&w);
		while ((top)&&(st[top]>=w)) top--;
		st[++top]=w;
	}
	for (int i=1;i<=top;i++)
	{
		while (treap.size[root]<st[i]) root=treap.merge(root,root);
		root=treap.split(root,st[i]).first;
	}
	treap.work(n,root);
	//cerr<<treap.tt<<endl;
}