var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	input = input.map(e => toIntArr(e.split(' ')));
	var d = input[0][0];
	var cs = input[1];
	var ss = input.slice(2);
	var ts = input.slice(d+2).map(e=>e[0]);
	
	var score = 0;
	var ans = '';
	let type;
	let lastday = [];
	lastday.length = 26;
	lastday.fill(-1);

	let scoreDay = [];

	for(let i = 0; i < d; i++){
		type = ts[i];
		//console.log(ss[i][type-1])
		score += ss[i][type-1];
		lastday[type-1] = i;
		for(let j = 0; j < 26; j++){
			//console.log(cs[j] * (i - lastday[j]))
			score -= cs[j] * (i - lastday[j]);
		}

		scoreDay[i] = score;

	}

	console.log(scoreDay.join('\n'));
}