The contest is over, but organizers and contestants are still thanking each other:
“Thank you!”
“No, thank you!”
“No, no, thank you!”
“No, no, no, thank you!”
This could go on forever! To save everyone some typing, they created
a messaging app with just one button: . After some effort, we were able to obtain a
screenshot of the app installed on Paulo’s device. We include it below
for your convenience.
Of course, Paulo is not the only person using this wonderful app.
There are
people using it, numbered from
to
.
Initially, nobody has received any messages. Whenever person
presses , that person sends exactly one message to a
recipient
.
The app chooses
as follows:
If the sender has already received any messages, then the recipient is the person who most recently sent a message to .
If the sender has not yet received any messages, then the recipient is , unless , in which case is .
The message is delivered immediately, before the next button press, and the sender becomes the person who most recently sent a message to the recipient .
Receiving a message does not send an automatic reply. Sending a message does not delete or change any of the sender’s received messages. A person can press the button repeatedly, even without receiving new messages between their button presses.
Given the sequence of button presses, determine how many messages each person receives. Count each message separately, including repeated messages from the same person.
The first line contains two integers () and (), indicating respectively the number of people and the number of button presses. Each person is identified by a distinct integer from to .
The second line contains integers (), where is the person who makes the -th button press. The presses are made in the given order.
Output a single line with integers , such that is the number of messages received by person during the button presses.
4 4 1 2 3 2
2 1 0 1
In this sample there are N = 4 people who make M = 4 button presses. The messages are sent from 1 to 2 (no messages received yet by 1), from 2 to 1 (last message received by 2 is from 1), from 3 to 4 (no messages received yet by 3), and from 2 to 1 (last message received by 2 is still from 1).
2 3 2 2 2
3 0
Here N = 2 and M = 3. Person 2 never receives a message, so each of their three button presses sends a message to person 1.
3 4 1 2 3 1
2 1 1
Now N = 3 and M = 4. The messages are sent from 1 to 2, from 2 to 1, from 3 to 1, and from 1 to 3.