import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python

import random
def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print(*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    D = int(input())
    #N, K = map(int, input().split())
    cs = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    S = tuple(tuple(map(int, input().split())) for i in range(D)) #改行行列
    lss=[]
    ls=[0]*26
    anss=[-1]*D
    for i in range(D):
        s=S[i]
        if i==0:
            msc=-1000000
            ans=-1
            for j in range(26):
                sc=s[j]+cs[j]

                if msc<sc:
                    ans=j
                    msc=sc
            ls[ans]=1
            #lss.append(ls)
            anss[i]=ans+1
            continue
        msc=0
        ans=-1
        dec=[-cs[j]*(i+1-ls[j]) for j in range(26)]
        msc=-10000000
        ans=-1
        for j in range(26):
            sc=s[j]-dec[j]
            if msc<sc:
                ans=j
                msc=sc
        ls[ans]=i+1
        #lss.append(ls)
        anss[i]=ans+1
    
    def eval(anss):
        ls=[0]*26
        score=0
        for i in range(D):
            j=anss[i]-1
            ls[j]=i+1
            score+=S[i][j]
            dec=sum([cs[k]*(i+1-ls[k]) for k in range(26)])
            score-=dec
        return score
    
    def eval2(anss,score,target,val,pval):
        score=score-S[target][pval-1]+S[target][val-1]
        f1=0
        f2=0
        cp=cv=0
        if target>0:
            for i in range(target-1,-1,-1):
                a=anss[i]
                if a==pval and not f1:
                    cp=i
                    f1=1
                if a==val and not f2:
                    cv=i
                    f2=1
                if f1 and f2:
                    break
        f1=f2=0
        #printe(cp,cv)
        csv=cs[val-1]
        csp=cs[pval-1]
        tcv=(target-cv)*csv
        tcp=(target-cp)*csp
        #printe(tcv,tcp)

        score+=tcv-tcp
        for i in range(target+1,D):
            a=anss[i]
            if anss[i]==pval and not f2:
                f2=1
            if anss[i]==val and not f1:
                f1=1
            if not f1:
                score+=tcv
            if not f2:
                score-=tcp
                
            if f1 and f2:
                break

        return score

    csc=eval(anss)
    #nans=copy(anss)

    random.seed(0)
    yaki=0.005
    for _ in range(1400000):
        target=random.randrange(0,D)
        
        pval=anss[target]
        val=pval
        while val==pval:
            val=random.randrange(0,26)+1
        #val=pval
        #nans[target]=val
        nsc=eval2(anss,csc,target,val,pval)
        
        if nsc>csc:
            csc=nsc
            anss[target]=val
        
            #printe(csc)
        #printe(csc,eval(anss))
            
            
            



    printl(anss)
    printe(csc)
    #printe(eval(anss))
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 82128