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

//typedef
//------------------------------------------
using LL = int64_t;
using ULL = u_int64_t;
using VL = vector<LL>;
using VVL = vector<VL>;
using VS = vector<string>;
using PLL = pair<LL, LL>;

//container util
//------------------------------------------
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rwhole(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)
#define EACH(i,c) for(decltype((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(x) ::std::begin(x), ::std::end(x)
#define RALL(x) ::std::rbegin(x), ::std::rend(x)
#define SORT(c) whole(sort, c)
#define RSORT(c) rwhole(sort, c)

//constant
//--------------------------------------------
constexpr double EPS = 1e-10;
constexpr double PI  = 3.14159265358979323846;
constexpr int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

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

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
// declaretion
template<typename T> istream& operator >>(istream& is, vector<T>& vec);
template<typename T1, typename T2> ostream& operator <<(ostream& os, const pair<T1, T2>& p);
template<typename T> ostream& operator <<(ostream& os, const vector<T>& vec);
template<typename T> ostream& operator <<(ostream& os, const vector<vector<T>>& vv);
template<typename T> vector<T> make_v(size_t a);
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts);
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v);
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v);

// implementation
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
	for(T& x: vec) is >> x;
	return is;
}
template<typename T1, typename T2>
ostream& operator <<(ostream& os, const pair<T1, T2>& p) {
	os << p.first << "," << p.second;
	return os;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
	for(int i=0; i<vec.size(); i++){
		os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
	}
	return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

template<class T,class U> void chmax(T&a,U b){if(a<b)a=b;}
template<class T,class U> void chmin(T&a,U b){if(b<a)a=b;}
template<typename T> T gcd(T a, T b) { return b?gcd(b,a%b):a;}
template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b;}

unsigned long xor_x=88172645463325252ULL;
unsigned long rng()
{
	xor_x^=xor_x<<7;
	return xor_x^=xor_x>>9;
}

//main code

LL d; // 全日程の長さ
VL c(26); // 各コンテストタイプの未開催による原点コスト
VVL s(365, VL(26)); // 各日付における各コンテストタイプの加点コスト
VL t(365); // 何日目にどのタイプのコンテストを行うか

// t[i]のタイプをj->kに変えた時，jに関するスコアとkに関するスコアのみ修正すればいい
// -> 各コンテストタイプについてスコアを記録する必要がある
// 前回の開催日を覚えておけば，次に開催した時に纏めて計算できる
// -> 各コンテストタイプについて前回の開催日を記録する必要がある
// -> 各コンテストタイプの開催日を配列に入れればいい

vector<set<int>> dc(26, set<int>()); // 各コンテストタイプの開催日のset
LL score = 0; // 計算するスコア

LL calcScore() {
	LL ret = 0;
	VL being(26,1);
	for (int i = 0; i < d; i++) {
		ret += s[i][t[i]];
		being[t[i]] = 0;
		for (int j = 0; j < 26; j++) {
			ret -= being[j]*c[j];
			being[j]++;
		}
	}
	return ret;
}

void init() {
	for (int i = 0; i < d; i++) {
		t[i] = i%26;
		dc[t[i]].insert(i);
	}
	for (int i = 0; i < 26; i++) {
		dc[i].insert(d);
		dc[i].insert(-1);
	}
}

// t[cd] -> cq にコンテストタイプを変更する
auto change(LL cd, LL cq) {
	LL pq = t[cd];
	LL tmp_c = score;
	auto tmp_dc = dc;
	auto tmp_t = t;
	// 抜けるコンテストによるスコアの修正
	auto itr_a = tmp_dc[pq].find(cd);
	assert(itr_a != tmp_dc[pq].end());
	--itr_a;
	LL pred_a = *itr_a;
	++itr_a;++itr_a;
	LL nextd_a = *itr_a;
	--itr_a;
	tmp_dc[pq].erase(itr_a);
	tmp_c -= s[cd][pq];
	// pred_a -> cd -> nextd_a
	tmp_c += c[pq] * (cd - pred_a) * (cd - pred_a + 1) / 2;
	tmp_c += c[pq] * (nextd_a - cd) * (nextd_a - cd + 1) / 2;
	tmp_c -= c[pq] * (nextd_a - pred_a) * (nextd_a - pred_a + 1) / 2;
	// 入れるコンテストによるスコアの修正
	auto itr_b = tmp_dc[cq].insert(cd).first;
	--itr_b;
	LL pred_b = *itr_b;
	++itr_b;++itr_b;
	LL nextd_b = *itr_b;
	tmp_c += s[cd][cq];
	tmp_c -= c[cq] * (cd - pred_b) * (cd - pred_b + 1) / 2;
	tmp_c -= c[cq] * (nextd_b - cd) * (nextd_b - cd + 1) / 2;
	tmp_c += c[cq] * (nextd_b - pred_b) * (nextd_b - pred_b + 1) / 2;
	// tの入れ替え
	tmp_t[cd] = cq;
	auto ret = make_tuple(tmp_c, tmp_dc, tmp_t);
	return ret;
}

// 日付swp1,swp2のコンテストタイプを入れ替える
bool swapc(LL swp1, LL swp2) {
	LL c1 = t[swp1];
	LL c2 = t[swp2];
	auto pre_score = score;
	auto pre_dc = dc;
	auto pre_t = t;

	{
	auto [tmp_c, tmp_dc, tmp_t] = change(swp1, c2);
	score = tmp_c;
	dc = tmp_dc;
	t = tmp_t;
	}
	auto [tmp_c, tmp_dc, tmp_t] = change(swp2, c1);
	if (tmp_c > pre_score) {
		score = tmp_c;
		dc = tmp_dc;
		t = tmp_t;
		return true;
	} else {
		score = pre_score;
		dc = pre_dc;
		t = pre_t;
		return false;
	}
}

void solve() {
	clock_t start = clock();
	int limit = 2000;
	cin >> d >> c;
	s.resize(d, VL(26));
	t.resize(d);
	cin >> s;
	init();
	score = calcScore();
	//random_device hoge;
	//mt19937 mt(hoge());
	//uniform_int_distribution<> rnd_d(0, d-1);
	//uniform_int_distribution<> rnd_c(0, 25);
	//uniform_int_distribution<> rnd_b(0, 1);
	//uniform_int_distribution<> rnd_swp(0, d-1);
	//uniform_int_distribution<> rnd_swpd(1, swap_d);
	LL swap_d = 15;
	LL loop = 0;
	while (static_cast<double>(clock() - start) / CLOCKS_PER_SEC * 1000.0 < limit - 50) {
		LL rb = rng()%2;
		if (rb) {
			ULL swp1 = rng()%d;
			ULL swp2 = min(swp1 + rng()%swap_d, (ULL)d-1);
			if (t[swp1] == t[swp2]) {
				continue;
			}
			if(swapc(swp1, swp2)) {
				//dump("swap");
				//dump(score);
			}
		} else {
			ULL rd = rng()%d;
			ULL rc = rng()%26;
			if (t[rd] == rc) {
				continue;
			}
			auto [tmp_c, tmp_dc, tmp_t] = change(rd, rc);
			if(tmp_c > score) {
				score = tmp_c;
				dc = tmp_dc;
				t = tmp_t;
				//dump("change");
				//dump(score);
			}
		}
		loop++;
	}
	for (int i = 0; i < d; i++) {
		cout << t[i]+1 << '\n';
	}
	dump(loop);
}

void scoring() {
	cin >> d >> c;
	s.resize(d, VL(26));
	t.resize(d);
	cin >> s >> t;
	for (int i = 0; i < d; i++) {
		t[i]--;
	}
	calcScore();
	return;
}

void incScoring() {
	cin >> d >> c;
	s.resize(d, VL(26));
	t.resize(d);
	cin >> s >> t;
	for (int i = 0; i < d; i++) {
		t[i]--;
	}
	init();
	LL m;
	cin >> m;
	VL d(m), q(m);
	score = calcScore();
	dump(score);
	for (int i = 0; i < m; i++) {
		cin >> d[i] >> q[i];
		d[i]--;
		q[i]--;
		change(d[i], q[i]);
		cout << score << '\n';
	}
	return;
}

int main(int argc, char *argv[])
{
	solve();
	//scoring();
	//incScoring();
	return 0;
}

Measured memory_bytes: 3884