#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>
#include <time.h>

#define InfL 2000000000
#define InfLL 4000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

bool debug = false; // false : 提出, true : fin - fout
double time_ratio;
clock_t time_ini;
string input_No = "0";

const int A = 26;
int D;
vi c;
vector<vi> s;
vi t;
vector<vi> last;
vector<vi> nxt;

ll sc = 0;

void readProblem() {
	string sample;
	ifstream fin;
	if (debug) {
		string ifname;
		ifname = "sample";
		ifname += input_No;
		ifname += ".in";
		fin.open(ifname);
	}

	if (debug)
	{
		fin >> D;
		c.resize(A);
		rep(i, A)
			fin >> c[i];
		s.resize(D);
		rep(d, D) {
			s[d].resize(A);
			rep(i, A) {
				fin >> s[d][i];
			}
		}
	}
	else {
		cin >> D;
		c.resize(A);
		rep(i, A)
			cin >> c[i];
		s.resize(D);
		rep(d, D) {
			s[d].resize(A);
			rep(i, A) {
				cin >> s[d][i];
			}
		}
	}

	t.resize(D);
	last.resize(D + 1);
	nxt.resize(D + 1);
	rep(d, D + 1) {
		last[d].resize(A, -1);
		nxt[d].resize(A, D);
	}

	if (debug)
		fin.close();

	if (debug)
		time_ratio = 0.115;
	else
		time_ratio = 1;

	return;
}

void writeSolution() {
	ofstream fout;
	if (debug) {
		string ofname;
		ofname = "sample";
		ofname += input_No;
		ofname += ".out";
		fout.open(ofname);
	}

	if (debug)
	{
		rep(d, D)
			fout << (t[d] + 1) << endl;
	}
	else {
		rep(d, D)
			cout << (t[d] + 1) << endl;
	}

	if (debug)
		fout.close();

	return;
}

void write_val(ll val_tmp, string S)
{
	if (!debug)
		cout << val_tmp << S << endl;
	return;
}

double time_diff()
{
	ll time_tmp = clock();
	const double time = time_ratio * static_cast<double>(time_tmp - time_ini) / CLOCKS_PER_SEC * 1000.0;
	return time;
}

int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

double RAND_() {
	while (1) {
		double rand_ = (double)(xor128() % InfL) / (double)InfL;
		if (rand_ > 0 && rand_ < 1)
			return rand_;
	}
}

void solve() {

	sc = 0;
	rep(d, D) {
		last[d + 1] = last[d];
		int scmax = -InfL;
		int scmaxi = 0;
		rep(i, A) {
			int sctmp = 0;
			rep(j, A) {
				if (i == j)
					sctmp += s[d][j];
				else
					sctmp -= c[j] * (d - last[d + 1][j]);
			}
			if (scmax < sctmp) {
				scmax = sctmp;
				scmaxi = i;
			}
		}
		t[d] = scmaxi;
		sc += scmax;
		rep(i, A) {
			if (t[d] == i)
				last[d + 1][i] = d;
		}
	}

	rrep(d, D) {
		nxt[d] = nxt[d + 1];
		rep(i, A) {
			if (t[d] == i)
				nxt[d][i] = d;
		}
	}

	if (debug)
		cout << sc << endl;
	double start_temp = 2000.0;
	double end_temp = 20.0;
	double TIME_LIMIT = 1950;


	while (1) {
		double time_now = time_diff();
		if (time_now > TIME_LIMIT)
			break;
		double temp = start_temp + (end_temp - start_temp) * time_now / TIME_LIMIT;
		rep(p, 10000) {
			if (p % 2 == 0) {
				int d = xor128() % D;
				int i_old = t[d];
				int i_new = xor128() % A;
				if (i_old == i_new)
					continue;
				int scdiff = 0;
				scdiff -= s[d][i_old];
				scdiff += s[d][i_new];
				int d_old_last = last[d][i_old];
				int d_new_last = last[d][i_new];
				int d_old_nxt = nxt[d + 1][i_old];
				int d_new_nxt = nxt[d + 1][i_new];
				int diff_old = d - d_old_last;
				int diff_new = d - d_new_last;
				int len_old = d_old_nxt - d;
				int len_new = d_new_nxt - d;
				scdiff -= c[i_old] * diff_old * len_old;
				scdiff += c[i_new] * diff_new * len_new;
				double prob = exp(scdiff / temp);
				if (prob > RAND_()) {
					sc += scdiff;
					for (int dtmp = d_old_last; dtmp < d_old_nxt; dtmp++) {
						last[dtmp + 1][i_old] = d_old_last;
						nxt[dtmp + 1][i_old] = d_old_nxt;
					}
					for (int dtmp = d_new_last; dtmp < d; dtmp++) {
						last[dtmp + 1][i_new] = d_new_last;
						nxt[dtmp + 1][i_new] = d;
					}
					for (int dtmp = d; dtmp < d_new_nxt; dtmp++) {
						last[dtmp + 1][i_new] = d;
						nxt[dtmp + 1][i_new] = d_new_nxt;
					}
					t[d] = i_new;
					if (debug)
						cout << sc << endl;
				}
			}
			else {
				int d_diff = log((double)InfL / (double)(xor128() % InfL));
				//int d_diff = xor128() % D;
				d_diff = max(1, d_diff);
				d_diff = min(D-1, d_diff);
				int d_old = xor128() % (D - d_diff);
				int d_new = d_old + d_diff;
				int i_old = t[d_old];
				int i_new = t[d_new];
				if (i_old == i_new)
					continue;
				bool X = false;
				for (int dtmp = d_old + 1; dtmp < d_new; dtmp++) {
					if (t[dtmp] == i_old)
						X = true;
					if (t[dtmp] == i_new)
						X = true;
					if (X)
						break;
				}
				if (X)
					continue;
				int scdiff = 0;

				scdiff -= s[d_old][i_old];
				scdiff += s[d_old][i_new];
				scdiff += s[d_new][i_old];
				scdiff -= s[d_new][i_new];
				int d_old_last = last[d_old][i_old];
				int d_new_last = last[d_new][i_new];
				int d_old_nxt = nxt[d_old + 1][i_old];
				int d_new_nxt = nxt[d_new + 1][i_new];

				int diff_old = d_old - d_old_last;
				int diff_new = d_old - d_new_last;
				int diff_2 = d_new - d_old;
				int len_old = d_old_nxt - d_new + 1;
				int len_new = d_new_nxt - d_new + 1;
				scdiff -= c[i_old] * (diff_old * diff_2 - len_old * diff_2);
				scdiff += c[i_new] * (diff_new * diff_2 - len_new * diff_2);

				double prob = exp(scdiff / temp);
				if (prob > RAND_()) {
					sc += scdiff;
					for (int dtmp = d_old_last; dtmp < d_new; dtmp++) {
						last[dtmp + 1][i_old] = d_old_last;
						nxt[dtmp + 1][i_old] = d_new;
					}
					for (int dtmp = d_new; dtmp < d_old_nxt; dtmp++) {
						last[dtmp + 1][i_old] = d_new;
						nxt[dtmp + 1][i_old] = d_old_nxt;
					}
					for (int dtmp = d_new_last; dtmp < d_old; dtmp++) {
						last[dtmp + 1][i_new] = d_new_last;
						nxt[dtmp + 1][i_new] = d_old;
					}
					for (int dtmp = d_old; dtmp < d_new_nxt; dtmp++) {
						last[dtmp + 1][i_new] = d_old;
						nxt[dtmp + 1][i_new] = d_new_nxt;
					}
					t[d_old] = i_new;
					t[d_new] = i_old;
					if (debug)
						cout << sc << endl;
				}

			}
		}
	}
	return;
}

void sample(int time_ms) {
	const double time = time_diff();
	if (time >= time_ms)
		return;
	int _rand = xor128();

	return;
}

int main() {
	if (debug)
		cin >> input_No;
	time_ini = clock();
	readProblem();
	solve();
	writeSolution();
	return 0;
}


Measured memory_bytes: 4384