#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define sz(v) ((int)(v).size())
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void out(T a){cout << a << endl;}
template<class T>void die(T a){cout << a << endl; exit(0);}

struct Matrix {
    vector < vector<double> > val;
    Matrix(int n, int m) { val.clear(); val.resize(n, vector<double>(m)); }
    int size() { return val.size(); }
    inline vector<double> &operator[](int i) { return val[i]; }
};


Matrix operator - (Matrix &A, Matrix &B) {
    Matrix R(A.size(), A[0].size());
    for (int i = 0; i < A.size(); ++i)
        for (int j = 0; j < (int)A[0].size(); ++j)
            R[i][j] = A[i][j] - B[i][j];
    return R;
}

Matrix operator * (Matrix &A, Matrix &B) {
    Matrix R(A.size(), B[0].size());
    for (int i = 0; i < A.size(); ++i)
        for (int j = 0; j < (int)B[0].size(); ++j)
            for (int k = 0; k < B.size(); ++k)
                R[i][j] += A[i][k] * B[k][j];
    return R;
}

vector <double> operator * (vector <double> &v, Matrix &M) {
    vector <double> ret(M[0].size());
    for (int i = 0; i < (int)M[0].size(); i++) {
        for (int j = 0; j < (int)v.size(); j++) {
            ret[i] += v[j] * M[j][i];
        }
    }
    return ret;
}

double operator * (vector <double> &v1, vector <double> &v2) {
    double ret = 0.0;
    for (int i = 0; i < (int)v1.size(); i++) {
        ret += v1[i] * v2[i];
    }
    return ret;
}

Matrix getCoFactor(Matrix &A, const int p, const int q) {
    int sz = A.size();
    Matrix co_factor(sz - 1, sz - 1);
    int i = 0, j = 0;
    for (int row = 0; row < sz; row++) {
        for (int col = 0; col < sz; col++) {
            if (row != p && col != q) {
                co_factor[i][j] = A[row][col];
                j++;
                if (j == sz - 1) {
                    j = 0;
                    i++;
                }
            }
        }
    }
    return co_factor;
}

double determinant(Matrix &A) {
    int sz = A.size();
    if (sz == 1) return A[0][0];
    if (sz == 2) return (A[0][0] * A[1][1] - A[1][0] * A[0][1]);//ほんの少し高速化
    double det = 0;
    for (int i = 0; i < sz; i++) {
        Matrix co_factor = getCoFactor(A, 0, i);
        int sign = i % 2 == 0 ? 1 : -1;
        det += sign * A[0][i] * determinant(co_factor);
    }
    return det;
}

Matrix adjoint(Matrix &A) {
    int sz = A.size();
    Matrix adj(sz, sz);
    if (sz == 1) { adj[0][0] = 1; return adj; }//ほんの少し高速化
    for (int j = 0; j < sz; j++) {
        for (int i = 0; i < sz; i++) {
            Matrix co_factor = getCoFactor(A, i, j);
            int sign = (i + j) % 2 == 0 ? 1 : -1;
            adj[j][i] = sign * determinant(co_factor);
        }
    }
    return adj;
}

Matrix Inverse(Matrix &A) {
    int sz = A.size();
    Matrix inv(sz, sz);
    double det = determinant(A);
    Matrix adj = adjoint(A);
    for (int i = 0; i < sz; i++)
        for (int j = 0; j < sz; j++)
            inv[i][j] = adj[i][j] / det;
    return inv;
}





double GetRandomd(double min,double max){
	return min + (double)(rand()*(max-min+1.0)/(1.0+RAND_MAX));
}
int GetRandomi(int min,int max){
	return min + (int)(rand()*(max-min+1.0)/(1.0+RAND_MAX));
}

int Roulette(vector<double> &f){
	double total = 0.0;
	rep(i,f.size()) total += f[i];
	double num = GetRandomd(0.0, total);
	double tmp = 0.0;
	rep(i,f.size()) {
		tmp += f[i];
		if(tmp >= num) return i;
	}
}

void Mutation(vector<int> &jobflow, int jobnum){
	int id = GetRandomi(0, jobflow.size()-1);//変異index
	int ato;
	while(true){
		ato = GetRandomi(1, jobnum);
		if(ato != jobflow[id]) break;
	}
	for(int i = 0; i< jobflow.size(); i++) {
		if(jobflow[i] == ato) { int tmp = jobflow[i]; jobflow[i] = jobflow[id]; jobflow[id] = tmp; break; }
	}
}

void Crossover(vector<int> &p1, vector<int> &p2){ /*順序交叉(TSP)*/
    int ma = p1.size();
    int start = GetRandomi(0, ma - 2);
    int end = GetRandomi(start +1, ma - 1);

    vector<int> p1_left, p2_left;
    for(int i = end + 1; i < ma; i++) {
        p1_left.pb(p1[i]);
        p2_left.pb(p2[i]);
    }

    for(int i = 0; i < end+1; i++) {
        p1_left.pb(p1[i]);
        p2_left.pb(p2[i]);
    }
    vector<int> p1_use, p2_use;
    for(int i = start; i <= end; i ++){
        p1_use.pb(p1[i]);
        p2_use.pb(p2[i]);
    }

    vector<int> p1_use_s = p1_use, p2_use_s = p2_use;
    sort(all(p1_use_s)); sort(all(p2_use_s));

    int id = 0, id2 = 0;
    int i = end+1;
    while(i < p1.size()) {
        if(find(all(p1_use_s), p2_left[id]) == p1_use_s.end()) { p1[i] = p2_left[id]; i++; }
        id++;
    }
    i = 0;
    while(id < p2_left.size()){
        if(find(all(p1_use_s), p2_left[id]) == p1_use_s.end()) { p1[i] = p2_left[id]; i++; }
        id++;
    }
    
    i = end+1;

    while(i < ma) {
        if(find(all(p2_use_s), p1_left[id2]) == p2_use_s.end()) { p2[i] = p1_left[id2]; i++; }
        id2++;
    }
    i = 0;
    while(id2 < p1_left.size()){
        if(find(all(p2_use_s), p1_left[id2]) == p2_use_s.end()) { p2[i] = p1_left[id2]; i++; }
        id2++;
    } 
    
    return ;
}



int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

    //random_device seed_gen;
    //mt19937 engine(seed_gen());

  	//cout << fixed << setprecision(15);
	//srand(time(NULL)); //初期化
	//rand()             //乱数取得
	//(double)rand()/RAND_MAX; //0-1乱数取得
	//int jobnum;//Jobの数
	//int machinenum;//機械の数
	//int popu; //個体数
	//int counter;//世代数
	//vector<int> jobflow(jobnum);
	//vector<double> f(3);//目的関数
	//double crossover_rate = 1.0; //交叉率
	//double mutation_rate = 0.95; //突然変異率

	//vvi gene(3, vi(3));
	//vvi each_machine(3, vi(3));

    //vector<int> v = {1,2,3,4,5,6,7,8,9};
    //shuffle(all(v), engine);
	

	//vector<int> p1, p2;
    //p1={1,2,3,4,5,6,7,8,9};
    //p2={4, 5, 2 , 1 ,8 ,7,6 ,9,3};
	
	//Crossover(p1, p2);
    //dab(p1);
    //dab(p2);

    int D; cin >> D; vi c(26); rep(i,26) cin >> c[i];
    vvi s(D, vi(26)); rep(i,D) rep(j,26) cin >> s[i][j];
    vi t(D); //コンテストタイプ
    rep(i,D) cin >> t[i];

    vi last(26, 0);
    int satisfy = 0;
    rep(i,D){
        satisfy += s[i][t[i]-1];
        last[t[i]-1] = i+1;
        rep(j,26){
            satisfy -= c[j] * (i+1 - last[j]);
        }
        out(satisfy);
    }
    //out(satisfy);
	
    //cout << rand() << endl;
  
	
}

Measured memory_bytes: 3724