Problem:


クリスマスパーティー (Christmas Party)

 問題

JOI 君は友達 1 から友達 N までの N 人の友達を招いてクリスマスパーティーを行った．クリスマスパーティーも盛り上がってきたところで，友達と一緒に次のようなゲームを行うことになった．

最初に JOI 君は N 人の友達の中から 1 人を選ぶ．以降はその友達をターゲットと呼ぶことにする．

JOI 君は，ターゲットとして選んだ友達に，その人がターゲットであることをこっそり伝える．ターゲット以外の友達は，誰がターゲットかを知ることはできない．

ターゲット以外の友達はそれぞれ，ターゲットが誰かを予想して，その人の名前を紙に記入する．ターゲットは自分自身の名前を紙に記入する．

すべての人の記入が終わった後，JOI 君はターゲットの名前を発表する．

予想が当たった人は 1 点を得る．なお，ターゲットは自分自身の名前を紙に記入しているので，必ず 1 点を得る．予想が外れた人には得点は与えられない．

それに加えて，予想が外れた人の人数を X 人としたとき，ターゲットは追加で X 点を得る．

JOI 君たちはこのゲームを M 回行った．それぞれの友達に対して，M 回のゲームにおける合計得点を求めよ．

入力

入力は 3 + M 行からなる．

1 行目には，友達の人数 N (3 ≤ N ≤ 100) が書かれている．

2 行目には，JOI 君たちが行ったゲームの回数 M (3 ≤ M ≤ 100) が書かれている．

3 行目には，M 個の整数 A1, A2, ..., AM が空白を区切りとして書かれている．これは，i 回目 (1 ≦ i ≦ M) のゲームのターゲットが友達 Ai (1 ≤ Ai ≤ N) であることを表す．

続く M 行のうちの i 行目 (1 ≦ i ≦ M) には，N 個の整数 Bi,1, Bi,2, ..., Bi,N が空白を区切りとして書かれている．これは，i 回目のゲームにおいて友達 j (1 ≤ j ≤ N) が友達 Bi,j (1 ≤ Bi,j ≤ N) の名前を紙に記入したことを表す．ターゲットは自分自身の名前を紙に記入するので，j = Ai のとき，常に Bi,j = j である．

出力

それぞれの友達に対して，M 回のゲームにおける合計得点を出力せよ．出力は N 行からなる．j 行目 (1 ≤ j ≤ N) に友達 j の合計得点を出力せよ．

入出力例

入力例 1

3
4
1 2 3 2
1 1 2
3 2 2
1 1 3
2 2 2

 
出力例 1

   

3
4
5

入力例 2

5
3
3 3 1
2 4 3 3 3
4 3 3 3 1
1 3 4 1 1

 
出力例 1

3
1
6
3
2

入出力例 1 では 3 人の友達が 4 回のゲームを行う．

1 回目のゲームのターゲットは友達 1 であり，友達 1 は 2 点，友達 2 は 1 点，友達 3 は 0 点を得る．

2 回目のゲームのターゲットは友達 2 であり，友達 1 は 0 点，友達 2 は 2 点，友達 3 は 1 点を得る．

3 回目のゲームのターゲットは友達 3 であり，友達 1 は 0 点，友達 2 は 0 点，友達 3 は 3 点を得る．

4 回目のゲームのターゲットは友達 2 であり，友達 1 は 1 点，友達 2 は 1 点，友達 3 は 1 点を得る．

4 回のゲーム終了後の合計得点は，友達 1 は 3 点，友達 2 は 4 点，友達 3 は 5 点である．

問題文と自動審判に使われるデータは、情報オリンピック日本委員会が作成し公開している問題文と採点用テストデータです。



Sample input:
3
4
1 2 3 2
1 1 2
3 2 2
1 1 3
2 2 2


Sample output:
3
4
5

Submission status: Accepted

Solution code:
n = int(input())
m = int(input())
targets = list(map(int, input().split()))
points = [0] * n
for i in range(m):
  lst = list(map(int, input().split()))
  target = targets[i]
  cnt = 0
  for i, p in enumerate(lst):
    if p == target:
      points[i] += 1
      cnt += 1
  points[target - 1] += (n - cnt)
print(*points, sep="\n")

Submission status: Accepted

Solution code:
# coding: utf-8

N = int(input())
M = int(input())
A = list(map(int, input().split(' '))) # M個
B = [list(map(int, input().split(' '))) for i in range(M)]

scores = [0 for i in range(N)]
for i in range(M):
    target = A[i]
    for j in range(N):
        if B[i][j] == target:
            scores[j] += 1
        else:
            scores[target-1] += 1

for score in scores:
    print(score)

Submission status: Accepted

Solution code:
# solve problem
def solve(n, m, targets, games):
    counter = [0 for i in range(n+1)]

    for i in range(m):
        for j in range(n):
            if games[i][j] == targets[i]:
                counter[j+1] += 1
            else:
                counter[targets[i]] += 1

    return counter


# main function
if __name__ == '__main__':
    n = int(input())
    m = int(input())
    tmp_targets = input().split()

    targets = []
    for i in range(m):
        targets.append(int(tmp_targets[i]))

    games = [[0 for i in range(n)] for j in range(m)]
    tmp_games = []
    for i in range(m):
        tmp_games = input().split()
        for j in range(n):
            games[i][j] = int(tmp_games[j])

    results = solve(n, m, targets, games)
    for i in range(1, n+1, 1):
        print(results[i])

Submission status: Accepted

Solution code:
N = int(input())
M = int(input())
A = list(map(int, input().split()))
p = [0] * N
for i in range(M):
    for bi, b in enumerate(map(int, input().split())):
        if b == A[i]:
            p[bi] += 1
        else:
            p[A[i] - 1] += 1
print('\n'.join(map(str, p)))

Submission status: Accepted

Solution code:
N = input()
M = input()
A = [int(a)-1 for a in raw_input().split()]
S = [0]*N
for i in range(M):
    B = [int(b)-1 for b in raw_input().split()]
    for j in range(N):
        if B[j]==A[i]:
            S[j] += 1
        else:
            S[A[i]] += 1
for s in S:
    print s

Submission status: Accepted

Solution code:
N, M= int(input()), int(input())
A= list(map(int, input().split()))
score= dict(zip([i+1 for i in range(N)], [0 for _ in range(N)]))
for i in range(M):
    B= list(map(int, input().split()))
    t= 0
    for j in range(N):
        if A[i]==B[j]: score[j+1]+= 1
        else: t+= 1
    score[A[i]]+= t
print("\n".join(map(str, score.values())))

Submission status: Accepted

Solution code:
N=int(input())
M=int(input())
target_list=[int(i) for i in input().split(" ")]
vote_list=[[int(i) for i in input().split(" ")] for j in range(M)]
score_list=[0 for i in range(N)]

for i in range(M):
    target=target_list[i]
    vote=vote_list[i]
    for j in range(N):
        if vote[j]==target:
            score_list[j]+=1
        else:
            score_list[target-1]+=1


for i in score_list:
    print(i)

Submission status: Accepted

Solution code:
p,t=[int(input())for i in range(2)]
tg=[int(s)for s in input().split(" ")]
pts=[0 for i in range(p)]
for i in range(t):
    ex=[int(s)for s in input().split(" ")]
    c_wr=0
    for j in range(p):
        if ex[j]==tg[i]:pts[j]+=1
        else:c_wr+=1
    pts[tg[i]-1]+=c_wr
for pt in pts:print(pt)

Submission status: Accepted

Solution code:
N = int(input())
M = int(input())
*A, = map(int, input().split())
sc = [0]*N
for i in range(M):
    *B, = map(int, input().split())
    for j in range(N):
        if A[i] == B[j]:
            sc[j] += 1
        else:
            sc[A[i]-1] += 1
*_,=map(print, sc)

Submission status: Accepted

Solution code:
n, m, t = int(input()), int(input()), list(map(int, input().split()))
p = [0 for _ in range(n)]
for i in t:
    k = list(map(int, input().split()))
    for j in range(n):
        if k[j] == i:
            p[j] += 1
        else:
            p[i - 1] += 1
for i in p:
    print(i)

Submission status: Accepted

Solution code:
# AOJ 0609: Christmas Party
# Python3 2018.7.2 bal4u

import sys
from sys import stdin
input = stdin.readline

n, m = [int(input()) for i in range(2)]
a = list(map(int, input().split()))
s = [0]*n
for i in range(m):
	k = list(map(int, input().split()))
	x = 0
	for j in range(n):
		if k[j] == a[i]: s[j] += 1
		else: x += 1
	s[a[i]-1] += x
print(*s, sep='\n')

Submission status: Accepted

Solution code:
import math
n = int(input())
m = int(input())
A = list(map(int,input().split()))
B = [list(map(int,input().split())) for i in range(m)]
p = [0 for i in range(n+1)]

for i in range(m):
    for j in range(n):
        if B[i][j] == A[i]:
            p[j+1] += 1
        else:
            p[A[i]] += 1
for i in range(1,n+1):
    print(p[i])

Submission status: Accepted

Solution code:
n=int(input())
m=int(input())
s=list(map(int,input().split()))
ss=[0]*n

for f in range(m):
    z=list(map(int,input().split()))
    count=0
    for k in range(n):
        if z[k]==s[f]:
            ss[k]+=1
        else:
            count+=1
    ss[s[f]-1]+=count
for i in range(n):
    print(ss[i])

Submission status: Accepted

Solution code:
N = int(input())  #参加人数
M = int(input())  #ゲーム回数
t = list(map(int, input().split()))  #ゲーム毎のターゲット
r = [0 for _ in range(N)]  #参加者毎の点数
for i in range(M):
	e = list(map(int, input().split()))  #予想
	for j in range(len(e)):
		if t[i] == e[j]: #予想があったったら
			r[j] += 1
		else:
			r[t[i]-1] += 1

for i in r: print(i)  #結果出力

Submission status: Accepted

Solution code:
N = int(input())
M = int(input())

target = list(map(int, input().split()))
yosou = [list(map(int, input().split())) for i in range(M)]


ten = [0 for _ in range(N)]
for i in range(M) :
    hazure = 0
    for j in range(N) :
        if target[i] == yosou[i][j] :
            ten[j] += 1
        else :
            hazure += 1
    ten[target[i]-1] += hazure

for i in range(N) :
    print(ten[i])

Submission status: Accepted

Solution code:
N=int(input())
M=int(input())
A=list(map(int,input().split()))
L=list()
S=[0]*N
for i in range(M):
  L=list(map(int,input().split()))
  for j in range(N):
    if L[j]==A[i]:
      S[j]=S[j]+1
    else:
      S[A[i]-1]=S[A[i]-1]+1
for i in range(N):
  print(S[i])

Submission status: Accepted

Solution code:
results = [0] * int(input())
m = int(input())
a = list(map(int, input().split()))

for i in range(m):
    target = a[i]
    result = list(map(int, input().split()))
    for i, r in enumerate(result):
        if r == target:
            results[i] += 1
    results[target-1] += len(results) - result.count(target)

print(*results, sep="\n")

Submission status: Accepted

Solution code:
N = int(input())
M = int(input())
T = [int(i) - 1 for i in input().split()]
P = [0] * N
for i in range(M):
    t = T[i]
    E = [int(_) - 1 for _ in input().split()]
    ap = 0
    for j in range(N):
        if E[j] == t:
            P[j] += 1
        else:
            ap += 1
    P[t] += ap

for p in P:
    print(p)

Submission status: Accepted

Solution code:
peopleCounts = int(input())
gameCounts = int(input())
targets = list(map(int, input().split()))

result = [0] * peopleCounts

for i in range(gameCounts):
  judges = list(map(int, input().split()))
  
  ans = targets[i]

  for judgeIndex in range(len(judges)):
    if ans == judges[judgeIndex]:
      result[judgeIndex] += 1
    else:
      result[ans - 1] += 1

for v in result:
  print(v)

Submission status: Accepted

Solution code:
n = int(input())
m = int(input())
a = list(map(int,input().split()))
b = []
point = {}
for i in range(m):
    b.append(list(map(int,input().split())))
for i in range(n):
    point[i] = 0
for i in range(m):
    target = a[i]
    for j in range(n):
        if b[i][j] == target:
            point[j] += 1
        else:
            point[target - 1] += 1
for key in point:
    print(point[key])

Submission status: Accepted

Solution code:

N = int(input())
M = int(input())

A = list(map(int,input().split()))
p = [0] * N

for i in range(M):

    B = list(map(int,input().split()))

    x = 0

    for j in range(N):

        if A[i] == B[j]:
            p[j] += 1
        else:
            x += 1

    p[A[i]-1] += x

for i in range(N):
    print (p[i])

Submission status: Accepted

Solution code:
n=int(input())
m=int(input())
ans=[0]*n
a=list(map(int,input().split()))
for i in range(m):
	cnt=0
	b=list(map(int,input().split()))
	for j in range(n):
		if b[j]==a[i]:
			ans[j]+=1
		else:
			cnt+=1
	ans[a[i]-1]+=cnt
for i in range(n):
	print(ans[i])

Submission status: Accepted

Solution code:
#B問題
N = int(input())
M = int(input())
A = list(map(int,input().split()))
B = [list(map(int,input().split())) for i in range(M)]
C = [0 for i in range(N)]

for i in range(M):
    a = A[i]
    b = B[i]
    for j in range(N):
        if j == a-1:
            C[j]+=1
        else:
            if b[j] == a:
                C[j]+=1
            else:
                C[a-1]+=1
    #print(C)
                
for c in C:
    print(c)

Submission status: Accepted

Solution code:
n = int(input())
m = int(input())

a = list(map(int, input().split()))
p = [0]*n

for i in range(m):
    b = list(map(int, input().split()))
    for j in range(n):
        if a[i] == b[j]:
            p[j] += 1
        else:
            p[a[i]-1] += 1

for i in range(n):
    print(p[i])

Submission status: Accepted

Solution code:
N = int(input())
M = int(input())
A = list(map(int, input().split()))
S = [0 for i in range(N)]

for i in range(M) :
    B = list(map(int, input().split()))
    for j in range(N) :
        if(B[j] == A[i]) :
            S[j] += 1
        else :
            pass
    S[A[i] - 1] += N - B.count(A[i])

for i in range(N) :
    print(S[i])

Submission status: Accepted

Solution code:
n=int(input())
m=int(input())
a=list(map(int,input().split()))
b=[list(map(int,input().split())) for _ in range(m)]
point=[0]*n
for i in range(m):
    for j in range(n):
        x=n-b[i].count(a[i]) #only target gets the point
        if a[i]==b[i][j]:
            point[j]+=1
            if a[i]==j+1:
                point[j]+=x
for i in point:
    print(i)

Submission status: Accepted

Solution code:
N = int(raw_input())
M = int(raw_input())
target = map(int, raw_input().split())
score = []
for i in range(0, N):
	score.append(0)
for i in range(0, M):
	guess = map(int, raw_input().split())
	wrongcount = 0
	for j in range(0, N):
		if guess[j] == target[i]:
			score[j] += 1
		else: wrongcount += 1
	score[target[i]-1] += wrongcount
for i in range(0, N):
	print score[i]

Submission status: Accepted

Solution code:
n=int(input())
m=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(m):
    b=list(map(int,input().split()))
    hit=0
    for j in range(n):
        if b[j]==a[i]:ans[j]+=1
        else:hit+=1
    ans[a[i]-1]+=hit
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
m = int(input())
target = list(map(int, input().split()))
score = [0] * n

for t in target:
    vote = list(map(int, input().split()))
    cnt = 0
    for i, v in enumerate(vote):
        if t == v:
            score[i] += 1
        else:
            cnt += 1
    score[t-1] += cnt

for s in score:
    print(s)