This page is still under construction.

Parts of this page are still being built. What you see may change.

Christmas Party

Interview

Time limit1sMemory limit256 MB

Summary
Tally each friend's score over M guessing games from the targets and the written names.
Level

Easy1 of 10

Topics
Implementation
Solved
No attempts yet

Problem

JOI went to a Christmas party with NN friends, numbered friend 1 through friend NN. Once the party warmed up, JOI decided to play the following game with them.

  1. JOI picks one of the NN friends. Call that friend the target.
  2. JOI secretly tells only the chosen friend that they are the target. The other friends do not know who the target is.
  3. Each friend who is not the target writes on a slip of paper the name of the person they think is the target. The target writes their own name.
  4. Once everyone has written a name, JOI announces the target's name.
  5. A friend who wrote the target's name earns 1 point. The target wrote their own name, so the target always earns 1 point. A friend who wrote any other name earns nothing.
  6. If XX friends failed to write the target's name, the target earns XX additional points.

JOI and the friends played this game MM times. Compute each friend's total score after all MM games.

Input

The input has 3+M3 + M lines.

The first line contains the number of friends NN (3≤N≤1003 \le N \le 100).

The second line contains the number of games MM (3≤M≤1003 \le M \le 100).

The third line contains MM integers A1,A2,…,AMA_1, A_2, \dots, A_M separated by spaces. AiA_i (1≤Ai≤N1 \le A_i \le N) means that the target of game ii is friend AiA_i.

The ii-th of the following MM lines contains NN integers Bi,1,Bi,2,…,Bi,NB_{i,1}, B_{i,2}, \dots, B_{i,N} separated by spaces. Bi,jB_{i,j} (1≤Bi,j≤N1 \le B_{i,j} \le N) means that in game ii, friend jj wrote the name of friend Bi,jB_{i,j}. The target writes their own name, so whenever j=Aij = A_i it holds that Bi,j=jB_{i,j} = j.

Output

Print NN lines. Line jj contains the total score friend jj earned over the MM games.

Examples2

  1. Example 1

    Input
    3
    4
    1 2 3 2
    1 1 2
    3 2 2
    1 1 3
    2 2 2
    
    Expected output
    3
    4
    5
    
  2. Example 2

    Input
    5
    3
    3 3 1
    2 4 3 3 3
    4 3 3 3 1
    1 3 4 1 1
    
    Expected output
    3
    1
    6
    3
    2