local D=io.read"*n"
local c={}
for i=1,26 do c[i]=io.read"*n"end
local s={}
for i=1,D do s[i]={}for j=1,26 do s[i][j]=io.read"*n"end end
local t={}
for i=1,D do t[i]=io.read"*n"end

local last={}
for i=1,26 do
last[i]=0
end

local a=0
for i=1,D do
	last[t[i]]=i
	for j=1,26 do
		a=a-c[j]*(i-last[j])
	end
	a=a+s[i][t[i]]
	print(a)
end
