Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    from bisect import bisect_left,bisect_right
    from time import perf_counter
    from random import random
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10
    start_time  = perf_counter()

    D = II()
    C = LMIIS()
    S = []
    for i in range(D):
        S.append(LMIIS())
    



    T = [0]*D
    for i in range(D):
        max_sat = -1
        max_type = -1
        L = S[i]
        for j in range(26):
            if max_sat < L[j]:
                max_sat = L[j]
                max_type = j
        T[i] = max_type
    
    

    # M = 1000
    # Q = []
    # for i in range(M):
    #     Q.append((int(random()*(D-1)),int(random()*25)))
    satisfaction = 0
    last_helds = []
    for i in range(26):
        last_helds.append([-1])

    satisfactions = [0] * D
    for i,t in enumerate(T):
        last_helds[t-1].append(i)
        for j in range(26):
            satisfaction -= C[j] * (i-last_helds[j][-1])
        satisfaction += S[i][t-1]
    first_sat = satisfaction
    for i in range(26):
        last_helds[i].append(D)


    #for d,q in Q:
    while perf_counter() - start_time < 1.9:
        d,q = int(random()*(D-1)),int(random()*25)
        old = T[d-1]
        old_sat = satisfaction

        satisfaction -= S[d-1][old-1]
        satisfaction += S[d-1][q-1]

        old_idx = bisect_left(last_helds[old-1],d-1)
        #dbg(last_helds[old-1],d-1,old_idx)
        x = last_helds[old-1][old_idx - 1]
        y = last_helds[old-1][old_idx + 1]
        #dbg('old x,y',d-1,x,y,(1+(y-1-(d-1)))*(y-(d-1)-1)//2,(1+(d-1)-x-1)*((d-1)-x-1)//2,(1+ y-x-1)*(y-x-1)//2)
        satisfaction += C[old-1] * ((1+(y-1-(d-1)))*(y-(d-1)-1)//2  + (1+(d-1)-x-1)*((d-1)-x-1)//2)
        satisfaction -= C[old-1] * ((1+ y-x-1)*(y-x-1)//2)
        
        new_idx = bisect_left(last_helds[q-1],d-1)

        x = last_helds[q-1][new_idx-1]
        y = last_helds[q-1][new_idx]
        satisfaction += C[q-1]*((1+y-x-1)*(y-x-1)//2)
        satisfaction -= C[q-1]*((1+(d-1)-x-1)*((d-1)-x-1)//2+(1+y-(d-1)-1)*(y-(d-1)-1)//2)
        if old_sat < satisfaction:
            last_helds[old-1].pop(old_idx)
            # dbg('insert')
            # dbg(last_helds[q-1])
            last_helds[q-1].insert(new_idx,d-1)
            # dbg(last_helds[q-1])
            T[d-1] = q
        else:
            satisfaction = old_sat
    for t in T:
        print(t+1)
    dbg(satisfaction,first_sat)




    
main()

Fixed submission:
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    D = II()
    C = LMIIS()
    S = []
    for i in range(D):
        S.append(LMIIS())
    
    T = [0]*D
    for i in range(D):
        max_sat = -1
        max_type = -1
        L = S[i]
        for j in range(26):
            if max_sat < L[j]:
                max_sat = L[j]
                max_type = j
        T[i] = max_type
    
    for t in T:
        print(t+1)
    

    
main()