#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using namespace std;

int main(void){
	int D;
	cin >> D;
	int c[26];
	int s[D][26];
	rep(i,26) cin >> c[i];
	rep(i,D) rep(j,26) cin >> s[i][j];

	int t[D];
	rep(i,D) cin >> t[i];
	long long v = 0;
	int last[26];
	rep(i,26) last[i] = 0;
	rep(i,D){
		v += s[i][t[i]-1];
		int dec = 0;
		last[t[i]-1] = i+1;
		int d = i+1;
		rep(j,26) dec += c[j]*(d-last[j]);
		v -= dec;
		cout << v << endl;
	}


return 0;
}
