import sys
import numpy as np
import numba
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

i4 = numba.int32

def get_input():
    D = int(readline())
    C = np.array(readline().split(), np.int32)
    S = np.array([readline().split() for _ in range(D)], np.int32)
    return D, C, S

@njit((i4, i4[:], i4[:, :], i4[:]), cache=True)
def first_computation(D, C, S, T):
    x = 0
    last = np.zeros((26, D), np.int32)
    for d in range(D):
        if d:
            last[:, d] = last[:, d - 1]
        i = T[d]
        x += S[d, i]
        last[i, d] = d + 1
        for i in range(26):
            x -= C[i] * (d + 1 - last[i, d])
    return last, x

@njit((i4, i4[:], i4[:, :], i4[:], i4[:, :], i4, i4), cache=True)
def difference_update(D, C, S, T, last_day, d, q):
    p = T[d]
    T[d] = q
    x = S[d, q] - S[d, p]

    i = np.searchsorted(last_day[p], d + 1)
    d_p = last_day[p, i - 1] if i >= 1 else 0
    coef = 0
    for k in range(d, D):
        if last_day[p, k] == d + 1:
            # k 日目に入るスコアの変更
            coef += d_p - d - 1
            last_day[p, k] = d_p
        else:
            break
    x += coef * C[p]

    coef = 0
    for k in range(d, D):
        if last_day[q, k] < d + 1:
            coef += (d + 1 - last_day[q, k])
            last_day[q, k] = d + 1
        else:
            break
    x += coef * C[q]
    return x

@njit((i4, i4[:], i4[:, :], i4[:], i4[:, :], i4), cache=True)
def swap_update(D, C, S, T, last_day, d):
    p = T[d]
    q = T[d+1]
    if p == q:
        return 0
    x = 0
    
    x -= C[p] * (d - last_day[p, d-1])
    last_day[p,d] = last_day[p,d-1] + 1
    for k in range(d+1, D):
        if last_day[p,k] == d + 1:
            last_day[p,k] += 1
            x += C[p]
        else:
            break
            
    x += (d - last_day[q, d]) * C[p]
    for k in range(d+1, D):
        if last_day[q, k] == d + 2:
            last_day[q,k] -= 1
            x -= C[q]
        else:
            break
    
    x += S[d+1,p] + S[d, q] - S[d,p] - S[d+1,q]
    T[d], T[d+1] = q,p
    return x

def output(T):
    T += 1
    print(*T, sep='\n')

@njit((i4, i4[:], i4[:, :], i4[:], i4[:, :]), cache=True)
def random_update(D, C, S, T, last_days):
    d = np.random.randint(0, D, 1)[0]
    p = T[d]
    xcum = 0
    for q in range(26):
        if p == q:
            continue
        xcum += difference_update(D, C, S, T, last_days, d, q)
        if xcum > 0:
            return q, xcum
    difference_update(D, C, S, T, last_days, d, p)
    return p, 0

@njit((i4, i4[:], i4[:, :], i4[:], i4[:,:]), cache=True)
def main(D, C, S, T, last_days):
    for _ in range(3000):
        d = np.random.randint(1, D-1, 1)[0]
        #x = swap_update(D,C,S,T,last_days,d)
        #if x < 0:
        #    swap_update(D,C,S,T,last_days,d)
        random_update(D, C, S, T, last_days)[1]
    return T

def first_strategy(D, C, S):
    T = np.empty(D, np.int32)
    for d in range(D):
        T[d] = d % 26
    return T

D, C, S = get_input()

res = []
for _ in range(100):
    T = first_strategy(D, C, S)
    last_days, score = first_computation(D, C, S, T)
    T = main(D,C,S,T,last_days)
    _, x = first_computation(D,C,S,T)
    res.append((T, x))

T,x = max(res, key=lambda x: x[1])

output(T)

Measured memory_bytes: 108092