#include <assert.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
					  << " " << __FILE__ << endl;

using namespace std;

const int64_t CYCLES_PER_SEC = 2800000000;
const double TIMELIMIT = 2.95;
struct Timer {
	int64_t start;
	Timer() { reset(); }
	void reset() { start = getCycle(); }
	void plus(double a) { start -= (a * CYCLES_PER_SEC); }
	inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; }
	inline int64_t getCycle() {
		uint32_t low, high;
		__asm__ volatile("rdtsc"
						 : "=a"(low), "=d"(high));
		return ((int64_t)low) | ((int64_t)high << 32);
	}
};
class XorShift {
   public:
	unsigned int x, y, z, w;
	double nL[65536];

	XorShift() {
		init();
	}

	void init() {
		x = 314159265;
		y = 358979323;
		z = 846264338;
		w = 327950288;
		double n = 1 / (double)(2 * 65536);
		for (int i = 0; i < 65536; i++) {
			nL[i] = log(((double)i / 65536) + n);
		}
	}

	inline unsigned int next() {
		unsigned int t = x ^ x << 11;
		x = y;
		y = z;
		z = w;
		return w = w ^ w >> 19 ^ t ^ t >> 8;
	}

	inline double nextLog() {
		return nL[next() & 0xFFFF];
	}

	inline int nextInt(int m) {
		return (int)(next() % m);
	}

	int nextInt(int min, int max) {
		return min + nextInt(max - min + 1);
	}

	inline double nextDouble() {
		return (double)next() / ((long long)1 << 32);
	}
};
XorShift rnd;
struct FastSet {
	vector<int> list;
	vector<int> pos;
	void init(int N) {
		pos.resize(N, -1);
		list.reserve(N);
	}
	void insert_all() {
		list.clear();
		list.resize(pos.size());
		for (int i = 0; i < list.size(); i++) {
			pos[i] = list[i] = i;
		}
	}
	void insert(int a) {
		if (pos[a] == -1) {
			pos[a] = list.size();
			list.push_back(a);
		}
	}
	void erase(int a) {
		if (pos[a] >= 0) {
			swap(list[pos[a]], list.back());
			pos[list[pos[a]]] = pos[a];
			pos[a] = -1;
			list.pop_back();
		}
	}
	void flip(int a) {
		if (pos[a] == -1) {
			pos[a] = list.size();
			list.push_back(a);
		} else {
			swap(list[pos[a]], list.back());
			pos[list[pos[a]]] = pos[a];
			pos[a] = -1;
			list.pop_back();
		}
	}
	inline int size() {
		return list.size();
	}
	inline int rand() {
		return list[rnd.nextInt(list.size())];
	}
	inline void erase_all() {
		for (int i : list) {
			pos[i] = -1;
		}
		list.clear();
	}
};
struct FastSet2 {
	vector<int> list;
	vector<int> pos;
	int sz;
	void init(int N) {
		sz = 0;
		pos.resize(N);
		list.resize(N);
		for (int i = 0; i < N; i++) {
			pos[i] = list[i] = i;
		}
	}
	void insert_all() {
		sz = list.size();
	}
	int getAny() {
		return list[sz++];
	}
	void insert(int a) {
		if (pos[a] >= sz) {
			pos[list[sz]] = pos[a];
			swap(list[pos[a]], list[sz]);
			pos[a] = sz;
			sz++;
		}
	}
	void erase(int a) {
		if (pos[a] < sz) {
			sz--;
			pos[list[sz]] = pos[a];
			swap(list[pos[a]], list[sz]);
			pos[a] = sz;
		}
	}
	inline int size() {
		return sz;
	}
	inline int rand() {
		return list[rnd.nextInt(sz)];
	}
	inline void erase_all() {
		sz = 0;
	}
};

const int N = 26;
//const int D = 365;
int D;
int C[N];
//int S[N][D + 1];
//int res[D + 1];
//int A[N][D + 1];

int S[N][366];
int res[366];
int A[N][366];

struct Solver {
	Timer timer;

	void init() {
		for (int i = 1; i <= D; i++) {
			res[i] = i % N;
		}
	}

	int calcScore() {
		int score = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j <= D; j++) {
				A[i][j] = -1;
			}
		}
		for (int i = 1; i <= D; i++) {
			A[res[i]][i] = 0;
			score += S[res[i]][i];
		}
		for (int i = 0; i < N; i++) {
			A[i][0] = 0;
		}
		for (int i = 0; i < N; i++) {
			for (int j = 1; j <= D; j++) {
				if (A[i][j] == -1) {
					A[i][j] = A[i][j - 1] + 1;
				}
				score -= A[i][j] * C[i];
			}
		}
		score = 0;
		for (int j = 1; j <= D; j++) {
			score += S[res[j]][j];
			for (int i = 0; i < N; i++) {
				score -= A[i][j] * C[i];
				
			}
			cout << score << endl;
		}
		return score;
	}

	void SA(double timelimit) {
		double st = timer.get();
		double ti = st;
		double dd = st;
		double interval = (timelimit - st) / 10;
		double T0 = 10000;
		double T;
		while (true) {
			ti = timer.get();
			if (ti > timelimit) break;
			double rem = (timelimit - ti) / (timelimit - st);
			T = T0 * rem;
			if (ti > dd) {
				dd += interval;
				cerr << T << endl;
			}
		}
	}

	int solve() {
		//init();
		//SA();
		calcScore();
		return 0;
	}

	void input() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		int _;
		cin >> D;
		for (int i = 0; i < N; i++) {
			cin >> C[i];
		}
		for (int j = 1; j <= D; j++) {
			for (int i = 0; i < N; i++) {
				cin >> S[i][j];
			}
		}
		for (int i = 1; i <= D; i++) {
			cin >> res[i];
			res[i]--;
		}
	}

	void output() {
	}
};

Solver solver;
int main(int argc, char *argv[]) {
	solver.input();
	solver.solve();
	solver.output();
	cerr << "timer = " << solver.timer.get() << endl;
	return 0;
}

Measured memory_bytes: 4640