#B3867. Savings Jar Accumulation

    ID: 11524 Type: Default 1000ms 256MiB

Savings Jar Accumulation

Savings Jar Accumulation

You are given N savings jars numbered from 0 to N-1. Starting on day 1, for each day i you deposit i dollars into one jar. On day i you choose a jar a_i and deposit i dollars into it. After D days, your task is to determine how much money is in each jar. In mathematical terms, if jar j is chosen on days i_1, i_2, \(\ldots\), i_k, then its total money is given by:

\[ \text{Money}_j = \sum_{\substack{i=1 \\ a_i=j}}^{D} i \]

Help solve this accumulation problem!

inputFormat

The first line contains two integers N and D, representing the number of jars and the number of days respectively. The second line contains D space-separated integers: \(a_1, a_2, \ldots, a_D\), where \(0 \le a_i < N\) indicating the jar chosen on day i.

outputFormat

Output N integers separated by a space. The jth integer should represent the total amount of money in jar j after D days.

sample

3 4
0 1 2 1
1 6 3