The R2 company has n employees working for it. The work involves constant exchange of ideas, sharing the stories of success and upcoming challenging. For that, R2 uses a famous instant messaging program Spyke.

R2 has m Spyke chats just to discuss all sorts of issues. In each chat, some group of employees exchanges messages daily. An employee can simultaneously talk in multiple chats. If some employee is in the k-th chat, he can write messages to this chat and receive notifications about messages from this chat. If an employee writes a message in the chat, all other participants of the chat receive a message notification.

The R2 company is conducting an audit. Now the specialists study effective communication between the employees. For this purpose, they have a chat log and the description of chat structure. You, as one of audit specialists, are commissioned to write a program that will use this data to determine the total number of message notifications received by each employee.


-----Input-----

The first line contains three space-separated integers n, m and k (2 ≤ n ≤ 2·10^4; 1 ≤ m ≤ 10; 1 ≤ k ≤ 2·10^5) — the number of the employees, the number of chats and the number of events in the log, correspondingly. 

Next n lines contain matrix a of size n × m, consisting of numbers zero and one. The element of this matrix, recorded in the j-th column of the i-th line, (let's denote it as a_{ij}) equals 1, if the i-th employee is the participant of the j-th chat, otherwise the element equals 0. Assume that the employees are numbered from 1 to n and the chats are numbered from 1 to m.

Next k lines contain the description of the log events. The i-th line contains two space-separated integers x_{i} and y_{i} (1 ≤ x_{i} ≤ n; 1 ≤ y_{i} ≤ m) which mean that the employee number x_{i} sent one message to chat number y_{i}. It is guaranteed that employee number x_{i} is a participant of chat y_{i}. It is guaranteed that each chat contains at least two employees.


-----Output-----

Print in the single line n space-separated integers, where the i-th integer shows the number of message notifications the i-th employee receives.


-----Examples-----
Input
3 4 5
1 1 1 1
1 0 1 1
1 1 0 0
1 1
3 1
1 3
2 4
3 2

Output
3 3 1 
Input
4 3 4
0 1 1
1 0 1
1 1 1
0 0 0
1 2
2 1
3 1
1 3

Output
0 2 3 0

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
(n, m, k) = [int(a) for a in input().split()]
table = []
for i in range(n):
	table.append([int(a) for a in input().split()])
event = []
for i in range(k):
	event.append([int(a) for a in input().split()])
multiplier = [0] * m
subtract = [0] * n
sumRes = [0] * n
for i in range(k):
	sumRes[event[i][0] - 1] -= 1
	multiplier[event[i][1] - 1] += 1
for i in range(n):
	for j in range(m):
		sumRes[i] = sumRes[i] + multiplier[j] * table[i][j]
for x in sumRes:
	print(x, end=' ')


R = lambda : list(map(int, input().split()))
(n, m, k) = R()
a = [list(R()) for _ in range(n)]
b = [0] * n
c = [0] * m
for i in range(k):
	(x, y) = R()
	b[x - 1] += 1
	c[y - 1] += 1
print(' '.join(map(str, (sum((a[i][j] * c[j] for j in range(m))) - b[i] for i in range(n)))))


from sys import stdin, stdout
(a, b, c) = map(int, stdin.readline().split())
z = [list(map(int, stdin.readline().split())) for _ in ' ' * a]
k = [0] * a
m = [0] * b
ans = [0] * a
for _ in ' ' * c:
	(u, v) = map(int, stdin.readline().split())
	k[u - 1] += 1
	m[v - 1] += 1
for i in range(a):
	ans[i] = -k[i]
	for j in range(b):
		ans[i] += m[j] * z[i][j]
stdout.write(' '.join(map(str, ans)))


from sys import stdin, stdout
(n, m, k) = map(int, input().split())
l = [[0] * m] * n
for i in range(n):
	l[i] = list(map(int, stdin.readline().split()))
t = [[0] * 2] * k
e = [0] * n
c = [0] * m
for i in range(k):
	(t0, t1) = map(int, stdin.readline().split())
	e[t0 - 1] -= 1
	c[t1 - 1] += 1
p = [''] * n
for i in range(n):
	for j in range(m):
		e[i] = e[i] + c[j] * l[i][j]
	p[i] = str(e[i])
stdout.write(' '.join(p))


(n, m, k) = map(int, input().split())
chats_ = []
for i in range(n):
	a = list(map(int, input().split()))
	chats_.append(a)
sent = [0 for i in range(n)]
chats = [0 for i in range(m)]
for i in range(k):
	(a, b) = map(int, input().split())
	sent[a - 1] += 1
	chats[b - 1] += 1
for i in range(n):
	sum = 0
	for j in range(m):
		sum += chats_[i][j] * chats[j]
	sum -= sent[i]
	print(sum, end=' ')


import sys
i = sys.stdin.readline
(n, m, k) = tuple(map(int, i().split()))
info = [[] for i in range(n)]
for j in range(n):
	info[j] = tuple(map(int, i().split()))
employees = [0] * n
chats = [0] * m
for j in range(k):
	(ei, ci) = map(int, input().split())
	employees[ei - 1] -= 1
	chats[ci - 1] += 1
for i in range(n):
	for j in range(m):
		employees[i] += chats[j] * info[i][j]
print(*employees)


(n, m, k) = map(int, input().split())
matrix = []
for i in range(n):
	mat = list(map(int, input().split()))
	matrix.append(mat)
mat = [0 for i in range(m + 1)]
ans = [0 for i in range(n + 1)]
for i in range(k):
	(a, b) = map(int, input().split())
	mat[b - 1] += 1
	ans[a - 1] -= 1
for i in range(n):
	s = sum([mat[j] for j in range(m) if matrix[i][j] == 1])
	print(ans[i] + s, end=' ')


(n, m, k) = input().split()
n = int(n)
m = int(m)
k = int(k)
l = [[0] * m] * n
for i in range(n):
	l[i] = list(map(int, input().split()))
t = [[0] * 2] * k
e = [0] * n
c = [0] * m
for i in range(k):
	(t0, t1) = map(int, input().split())
	e[t0 - 1] -= 1
	c[t1 - 1] += 1
p = [''] * n
for i in range(n):
	for j in range(m):
		e[i] = e[i] + c[j] * l[i][j]
	p[i] = str(e[i])
print(' '.join(p))


(n, m, k) = map(int, input().split())
chatsmembers = []
chatkol = []
for i in range(n):
	chatsmembers.append(list(map(int, input().split())))
chatkol = [0] * m
chatsents = [0] * n
for i in range(k):
	(a, b) = map(int, input().split())
	chatsents[a - 1] += 1
	chatkol[b - 1] += 1
for i in range(n):
	t = 0
	for j in range(m):
		if chatsmembers[i][j] == 1:
			t += chatkol[j]
	print(t - chatsents[i], end=' ')


R = lambda : map(int, input().split())
(n, m, k) = R()
chat = []
for i in range(n):
	chat.append(list(R()))
man = [0] * n
room = [0] * m
for i in range(k):
	(a, b) = R()
	man[a - 1] += 1
	room[b - 1] += 1
for i in range(n):
	t = 0
	for j in range(m):
		if chat[i][j] == 1:
			t += room[j]
	print(t - man[i], end=' ')


(n, m, k) = map(int, input().split())
chats = list()
for i in range(m):
	chats.append([set(), 0])
emps = [0] * n
for i in range(n):
	e = list(map(int, input().split()))
	for j in range(m):
		if e[j] == 1:
			chats[j][0].add(i)
for i in range(k):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	chats[y][1] += 1
	emps[x] -= 1
for i in chats:
	for j in i[0]:
		emps[j] += i[1]
for i in range(n):
	print(emps[i], end=' ')


(n, m, k) = map(int, input().split())
p = []
for i in range(n):
	o = [int(w) for w in input().split()]
	p.append(o)
t = [0] * n
r = [0] * m
for i in range(k):
	(a, b) = map(int, input().split())
	t[a - 1] += 1
	r[b - 1] += 1
for i in range(n):
	ans = 0
	for j in range(m):
		if p[i][j] == 1:
			ans += r[j]
	print(ans - t[i], end=' ')


(n, m, k) = map(int, input().split())
(a, nc, mc) = ([list(map(int, input().split())) for i in range(n)], [0] * n, [0] * m)
for i in range(k):
	(x, y) = map(int, input().split())
	nc[x - 1] += 1
	mc[y - 1] += 1
print(' '.join(map(str, (sum((mc[j] for j in range(m) if a[i][j])) - nc[i] for i in range(n)))))


(n, m, k) = map(int, input().split())
room = [[] for i in range(m)]
result = [0] * n
cnt = [0] * m
for i in range(n):
	for (n_room, n_be) in enumerate(list(input().split())):
		if n_be == '1':
			room[n_room].append(i)
for i in range(k):
	(n_person, n_room) = map(int, input().split())
	result[n_person - 1] -= 1
	cnt[n_room - 1] += 1
for (n_room, n_cnt) in enumerate(cnt):
	for i in room[n_room]:
		result[i] += n_cnt
print(' '.join(map(str, result)))


(n, m, k) = list(map(int, input().split()))
too = dict()
chat = dict()
chat2 = dict()
for i in range(n):
	too[i] = 0
	chat[i] = list(map(int, input().split()))
for i in range(m):
	chat2[i] = 0
for i in range(k):
	(x, y) = list(map(int, input().split()))
	chat2[y - 1] += 1
	too[x - 1] -= 1
out = []
for i in range(n):
	t2 = 0
	for e in range(m):
		if chat[i][e]:
			t2 += chat2[e]
	t = too[i] + t2
	out.append(str(t))
print(' '.join(out))


import sys
import math
import collections
import heapq
input = sys.stdin.readline
(n, m, k) = (int(i) for i in input().split())
l = []
l2 = [0] * m
for i in range(n):
	l1 = [int(i) for i in input().split()]
	l.append(l1)
l3 = [0] * n
for i in range(k):
	(x, y) = (int(i) for i in input().split())
	l3[x - 1] += 1
	l2[y - 1] += 1
for i in range(n):
	s = 0
	for j in range(m):
		if l[i][j] == 1:
			s += l2[j]
	l3[i] = s - l3[i]
print(*l3)


(n, m, k) = map(int, input().split())
L = []
for i in range(n):
	L.append(list(map(int, input().split())))
K = {}
for i in range(m):
	K[i + 1] = []
	for j in range(n):
		if L[j][i] == 1:
			K[i + 1].append(j + 1)
Ans = [0] * n
Anss = [0] * m
for i in range(k):
	(x, y) = map(int, input().split())
	Anss[y - 1] += 1
	Ans[x - 1] -= 1
for i in range(n):
	for j in range(m):
		if L[i][j] == 1:
			Ans[i] += Anss[j]
for item in Ans:
	print(item, end=' ')


from collections import defaultdict
from sys import stdin, stdout
import math
(n, m, k) = map(int, stdin.readline().split())
mat = []
for _ in range(n):
	mat.append(list(map(int, stdin.readline().split())))
values = [0] * 10
sendby = defaultdict(lambda : 0)
for _ in range(k):
	(x, y) = map(int, stdin.readline().split())
	values[y - 1] += 1
	sendby[x - 1] += 1
for i in range(n):
	temp = 0
	for j in range(m):
		if mat[i][j] == 1:
			temp += values[j]
	print(temp - sendby[i], end=' ')


(n, m, k) = map(int, input().split())
(p, s, t) = ([[] for y in range(m)], [0] * n, [0] * m)
for x in range(n):
	for (y, c) in enumerate(input()[::2]):
		if c == '1':
			p[y].append(x)
for i in range(k):
	(x, y) = map(int, input().split())
	s[x - 1] -= 1
	t[y - 1] += 1
for (y, d) in enumerate(t):
	for x in p[y]:
		s[x] += d
print(' '.join(map(str, s)))


(n, m, k) = map(int, input().split())
a = [set() for i in range(m)]
b = [0 for i in range(n)]
d = [0 for i in range(m)]
for i in range(n):
	s = list(map(int, input().split()))
	for j in range(m):
		if s[j]:
			a[j].add(i)
for i in range(k):
	(x, y) = map(int, input().split())
	d[y - 1] += 1
	b[x - 1] -= 1
for i in range(m):
	if d[i]:
		for elem in a[i]:
			b[elem] += d[i]
for i in range(n):
	print(b[i], end=' ')