#include <bits/stdc++.h>
using namespace std;

int main()
{
	int d;
	cin >> d;

	vector<int> c(26+1);
	for (int i=1;i<=26;++i)
	{
		cin >> c[i];
	}

	vector<vector<int>> s(d+1,vector<int>(26+1));
	for (int i=1;i<=d;++i)
	{
		for (int j=1;j<=26;++j)
		{
			cin >> s[i][j];
		}
	}
	vector<int> t(d+1);
	for (int i=1;i<=d;++i)
	{
		cin >> t[i];
	}

	vector<int> last(26+1);
	for (int i=1;i<=26;++i)
	{
		last[i]=0;
	}

	int64_t score=0;
	for (int i=1;i<=d;++i)
	{
		score+=s[i][t[i]];
		last[t[i]]=i;
		for (int j=1;j<=26;++j)
		{
			score-=c[j]*(i-last[j]);
		}
		cout << score << endl;
	}
}




