#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

#define PROB_B 1
#define LOCAL 1
#define SUBMIT 0

struct Random {
public:
	Random() {
		// std::random_device rd;
		// mt.seed(rd());
		// 初期 seed を固定してみる
		mt.seed(87772);
	}
	
	int next(int min_e, int max_e) {
		std::uniform_int_distribution<> rand(min_e, max_e);
		return rand(mt);
	}
	
	double next(double min_e, double max_e) {
		std::uniform_real_distribution<> rand(min_e, max_e);
		return rand(mt);
	}
	
	template<typename T>
	void shuffleVector(std::vector<T> & v) {
		std::shuffle(std::begin(v), std::end(v), mt);
	}
	
public:
	std::mt19937 mt;
} rnd;

struct Timer {
public:
	Timer() : start(now()) {}
	
	void set() { last = now(); }
	long long time() const { return difference_time(last, now()); }
	long long elapsed_time() const { return difference_time(start, now()); }
	
private:
	using time_point = std::chrono::system_clock::time_point;
	std::chrono::system_clock::time_point start, last;
	
	time_point now() const {
		return std::chrono::system_clock::now();
	}
	
	long long difference_time(const time_point & x, const time_point & y) const {
		return std::chrono::duration_cast<std::chrono::microseconds>(y - x).count();
	}
	
} timer;

template<typename T>
std::string to_string_zero(T n, int keta) {
	std::string res = std::to_string(n);
	while (res.size() < keta) res.insert(res.begin(), '0');
	return res;
}

template<typename T>
std::string to_string_comma(T n) {
	bool minus_flag = n < 0;
	if (minus_flag) n = -n;
	std::string res, s = std::to_string(n);
	for (int i = 0; i < s.size(); ++i) {
		int d = s.size() - i;
		if (i > 0 && (s.size() - i) % 3 == 0) res.push_back(',');
		res.push_back(s[i]);
	}
	if (minus_flag) res.insert(res.begin(), '-');
	return res;
}

bool output_del = 0; // 出力ファイルの削除フラグ
void arg_analysys(int argc, const char * argv[]) {
	if (argc == 1) return;
	std::vector<std::string> vs(argc - 1);
	for (int i = 1; i < argc; ++i) vs[i - 1] = argv[i];
	
	int mode = -1;
	std::map<std::string, int> mm;
	{
		std::vector<std::string> tmp_v = {"aaaa"};
		for (int i = 0; i < tmp_v.size(); ++i) mm[tmp_v[i]] = i;
	}
	for (std::string & s : vs) {
		if (s.size() > 2 && s[0] == '-' && s[1] == '-') {
			s = s.substr(2);
		}
		else {
			assert(mode != -1); // 不正な引数
			
			double num;
			try {
				num = std::stod(s);
			}
			catch (const std::exception & e) {
				std::cerr << e.what() << std::endl;
				exit(EXIT_FAILURE);
			}
			if (mode == mm["aaaa"]) continue;
		}
	}
}

constexpr int TYPE = 26;

struct Input {
	
	int D;
	vector<int> c;
	vector<vector<int>> s;
	
	void read(std::istream& in = std::cin) {
		cin >> D;
		c.resize(TYPE);
		REP(i, TYPE) cin >> c[i];
		
		s.resize(D);
		for (auto &cur : s) {
			cur.resize(TYPE);
			for (auto &v : cur) cin >> v;
		}
	}
};

struct Output {
	Input &input;
	vector<int> t;
	
	Output(Input &input) : input(input) {
		t.resize(input.D, -1);
	}
	
	void add_data(int d, int _t) {
		t[d] = _t;
	}
	
	void print() {
		REP(i, input.D) cout << t[i] << '\n';
		cout.flush();
	}
};

struct ScoreCalculator {
	constexpr static int proc_out = true;
	
	static int calc_satis(Input &input, Output &output) {
		int satis = 0;
		vector<int> last_i(TYPE);
		
		REP(i, input.D) {
			satis += input.s[i][output.t[i]];
			last_i[output.t[i]] = i + 1;
			
			REP(j, TYPE) satis -= input.c[j] * (i + 1 - last_i[j]);
			
			if (proc_out) cout << satis << endl;
		}
		
		return satis;
	}
	
	static int calc_score(Input &input, Output &output) {
		int satis = calc_satis(input, output);
		return max(satis + 1000000, 0);
	}
};

void solve(Input &input) {
	Output output(input);
	
	REP(i, input.D) {
		int t;
		cin >> t;
		--t;
		output.add_data(i, t);
	}
	
	int score = ScoreCalculator::calc_satis(input, output);
}

int main(int argc, const char * argv[]) {
	Input input;
	input.read();
	
	solve(input);
}


Measured memory_bytes: 3664