#include <bits/stdc++.h>
using namespace std;
int main(){
	int D; cin >> D; 
	int C[30] = {}; 
	for(int i = 1; i <= 26; i++) cin >> C[i]; 
	int S[370][30] = {}; 
	for(int i = 1; i <= D; i++){
		for(int j = 1; j <= 26; j++){
			cin >> S[i][j]; 
		}
	}
	int T[370] = {}; 
	for(int i = 1; i <= D; i++) cin >> T[i]; 
	int now = 0; 
	int L[30] = {}; 
	for(int i = 1; i <= D; i++){
		now += S[i][T[i]]; 
		L[T[i]] = i; 
		for(int j = 1; j <= 26; j++){
			if(j == T[i]) continue; 
			now -= C[j] * (i - L[j]); 
		}
		cout << now << endl; 
	}
}