Problem:
   Problem Statement AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.   The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.  Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i} .  If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i , and at the end of each day d=1,2,...,D , the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d ) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0 . At the end of day d , the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)) .   Please schedule contests on behalf of AtCoder.
If the satisfaction at the end of day D is S , you will get a score of \max(10^6 + S, 0) .
There are 50 test cases, and the score of a submission is the total scores for each test case.
You can make submissions multiple times, and the highest score among your submissions will be your score.      Constraints  D = 365  Each c_i is an integer satisfying 0\leq c_i \leq 100 .  Each s_{d,i} is an integer satisfying 0\leq s_{d,i} \leq 20000 .         Input Input is given from Standard Input in the following format:  D  c_1  c_2  \cdots  c_{26}  s_{1,1}  s_{1,2}  \cdots  s_{1,26}  \vdots  s_{D,1}  s_{D,2}  \cdots  s_{D,26}       Output Let t_d ( 1\leq t_d \leq 26 ) be the type of the contest that will be held at day d .
Print D integers t_d to Standard Output in the following format:  t_1  t_2  \vdots  t_D   Any output that does not follow the above format may result in 0 points WA for that test case.      Input Generation Each integer c_i and s_{d,i} is generated independently and uniformly at random from the integers in the range described in the problem statement.        Sample Input 1 5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192      Sample Output 1 1
17
13
14
13  Note that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case. The final satisfaction with this output is 79325, so the score is 1079325.  Input generator, score calculator, and visualizer      Beginner's Guide If you don't know what to do, proceed to problem B or C.

Solution (Python):


from time import time
from math import exp
key = 1
rnd_mod = 12345678901234567891
rnd_x = 9876543210987654321 + 1234567890123456789 * key % rnd_mod
def rnd():
    global rnd_x
    rnd_x = rnd_x**2 % rnd_mod
    return (rnd_x>>10) % (1<<40)
def randrange(a, b=-1):
    if b > 0: return randrange(b-a) + a
    return rnd() % a

def calc():
    s = 0
    last = [-1] * 26
    for i, t in enumerate(A):
        s += S[i][t]
        last[t] = i
        for j, c in enumerate(C):
            s -= c * (i - last[j])
    return s

sTime = time()
D = int(input())
C = [int(a) for a in input().split()]
S = [[int(a) for a in input().split()] for _ in range(D)]
A = [randrange(26) for _ in range(D)]



ans = calc()


def day_all(d):
    global ans
    i = A[d]
    for k in range(d)[::-1]:
        if A[k] == i:
            prev = k
            break
    else:
        prev = -1
    for k in range(d + 1, D):
        if A[k] == i:
            prev_ne = k
            break
    else:
        prev_ne = D
    for j in range(26):
        t = S[d][j] - S[d][i]
        for k in range(d)[::-1]:
            if A[k] == j:
                new = k
                break
        else:
            new = -1
        for k in range(d + 1, D):
            if A[k] == j:
                new_ne = k
                break
        else:
            new_ne = D
        t += C[j] * (d - new) * (new_ne - d) - C[i] * (d - prev) * (prev_ne - d)
        if (T < 1 and t > 0) or (T >= 1 and randrange(1 << 10) < exp(max(min(t / T, 0), -10)) * (1 << 10)):
            A[d] = j
            ans += t
            prev, prev_ne = new, new_ne
            i = j
            if 0:
                print("A =", A)
                print("ans =", ans)
                print("calc =", calc())

def swap(d1, d2):
    global ans
    i = A[d1]
    j = A[d2]
    for d in range(d1 + 1, d2):
        if A[d] == i:
            d1 = d
        if A[d] == j:
            d2 = d
            break
    for d in range(d1)[::-1]:
        if A[d] == i:
            previ = d
            break
    else:
        previ = -1
    for d in range(d1)[::-1]:
        if A[d] == j:
            prevj = d
            break
    else:
        prevj = -1
    for d in range(d2 + 1, D):
        if A[d] == i:
            nei = d
            break
    else:
        nei = D
    for d in range(d2 + 1, D):
        if A[d] == j:
            nej = d
            break
    else:
        nej = D
    
    t = S[d1][j] - S[d1][i] - S[d2][j] + S[d2][i]
    t -= (nei - d1 - d1 + previ) * (d2 - d1)
    t += (nej - d2 - d2 + prevj) * (d2 - d1)
    if (T < 1 and t > 0) or (T >= 1 and randrange(1 << 10) < exp(max(min(t / T, 0), -10)) * (1 << 10)):
        A[d1], A[d2] = j, i
        ans += t


ans = calc()
loop = 0
while 1:
    if loop % 100 == 0:
        tt = (time() - sTime) / 1.8
        if tt >= 1:
            break
        T = 2500 * (1 - tt)
    loop += 1
    
    if randrange(1 << 10) < tt:
        d1 = randrange(D)
        d2 = d1
        while A[d1] == A[d2]:
            d2 = randrange(max(d1 - 10, 0), min(d1 + 10, D))
        if d2 < d1: d1, d2 = d2, d1
        swap(d1, d2)
        if 0:
            print("2")
            print("ans =", ans)
            print("calc =", calc())
        
    else:
        d = randrange(D)
        day_all(d)
        if 0:
            print("1")
            print("ans =", ans)
            print("calc =", calc())
    
print(*[a + 1 for a in A], sep = "\n")
if 0:
    print(ans)
    print("A =", A)

Solution (Python):
import sys, random
input = sys.stdin.readline
def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    for _ in range(D):
        si = list(map(int, input().split()))
        s.append(si)
    last_list = [0] * 26
    minus_sat_list = [0] * 26
    for i in range(D):
        for j in range(26):
            minus_sat_list[j] += c[j] * (i+1-last_list[j])
        best_idx = 0
        worst_sat, worst_sat_idx  = 0, -1
        worst2_sat, worst2_sat_idx  = 0, -1
        worst3_sat, worst3_sat_idx  = 0, -1
        worst4_sat, worst4_sat_idx  = 0, -1
        worst5_sat, worst5_sat_idx  = 0, -1
        for j in range(26):
            if (minus_sat_list[j] > worst_sat) or (minus_sat_list[j] == worst_sat and s[i][j] > s[i][worst_sat_idx]):
                worst_sat = minus_sat_list[j]
                worst_sat_idx = j
            elif (minus_sat_list[j] > worst2_sat) or (minus_sat_list[j] == worst2_sat and s[i][j] > s[i][worst2_sat_idx]):
                worst2_sat = minus_sat_list[j]
                worst2_sat_idx = j
            elif (minus_sat_list[j] > worst3_sat) or (minus_sat_list[j] == worst3_sat and s[i][j] > s[i][worst3_sat_idx]):
                worst3_sat = minus_sat_list[j]
                worst3_sat_idx = j
            elif (minus_sat_list[j] > worst4_sat) or (minus_sat_list[j] == worst4_sat and s[i][j] > s[i][worst4_sat_idx]):
                worst4_sat = minus_sat_list[j]
                worst4_sat_idx = j
            elif (minus_sat_list[j] > worst5_sat) or (minus_sat_list[j] == worst5_sat and s[i][j] > s[i][worst5_sat_idx]):
                worst5_sat = minus_sat_list[j]
                worst5_sat_idx = j
        worst_val = s[i][worst_sat_idx] * (i + 1) // 2 + worst_sat
        worst2_val = s[i][worst2_sat_idx] * (i + 1) // 2 + worst2_sat
        worst3_val = s[i][worst3_sat_idx] * (i + 1) // 2 + worst3_sat
        worst4_val = s[i][worst4_sat_idx] * (i + 1) // 2 + worst4_sat
        worst5_val = s[i][worst5_sat_idx] * (i + 1) // 2 + worst5_sat
        best_val = max(worst_val, worst2_val, worst3_val, worst4_val, worst5_val)
        if best_val == worst_val:
            best_idx = worst_sat_idx
        elif best_val == worst2_val:
            best_idx = worst2_sat_idx
        elif best_val == worst3_val:
            best_idx = worst3_sat_idx
        elif best_val == worst4_val:
            best_idx = worst4_sat_idx
        elif best_val == worst5_val:
            best_idx = worst5_sat_idx
        minus_sat_list[best_idx] = 0
        last_list[best_idx] = i + 1
        print(best_idx+1)
if __name__ == "__main__":
    main()

Solution (Python):
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
t = [0] * D
for i in range(D):
    r=((i+1)%26)+1
    t[i] = r

    
M=2
day=[1,4]
q=[7,11]
    
m=[0]*D

a=[[0 for i in range(26)] for j in range(D)]
for u in range(D):
    i=t[u]
    for y in range(u,D):
        a[y][i-1]=u+1
    if u==0:
        m[u]=s[u][i-1]
    else:
        m[u]=m[u-1]+s[u][i-1]
mm=[0]*D
for d  in range(D):
    for i in range(26):
        mm[d]+=c[i]*(d+1-a[d][i])
    if not d==0:
        mm[d]+=mm[d-1]
for d in range(D):
    m[d]-=mm[d]
mmm=m[D-1]



for p in range(M):
    new_type=q[p]
    old_type=t[day[p]-1]
    
    A=0
    B=0
    C=0
    
    for d in range(D):
        A+=c[new_type-1]*(d+1-a[d][new_type-1])+c[old_type-1]*(d+1-a[d][old_type-1])
    xday=day[p]
    if xday>1:
        before_new=a[xday-2][new_type-1]
        before_old=a[xday-2][old_type-1]
        now_new=a[day[p]-1][new_type-1]
        now_old=a[day[p]-1][old_type-1]
        for d in range(day[p]-1,D):
            if a[d][new_type-1]==now_new:
                a[d][new_type-1]=xday
            if a[d][old_type-1]==now_old:
                a[d][old_type-1]=before_old
    else:
        for d in range(day[p]-1,D):
            if a[d][old_type-1]==1:
                a[d][old_type-1]=0
            if a[d][new_type-1]==0:
                a[d][new_type-1]=1   
    t[day[p]-1]=new_type
    for d in range(D):
        B+=c[new_type-1]*(d+1-a[d][new_type-1])+c[old_type-1]*(d+1-a[d][old_type-1])
    s=mmm-(B-A+C)
    if s>mmm:
        mmm=s
    
for i in range(len(t)):
    print(t[i])

Solution (Python):
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]

for i in range(d):
    print(1)

Solution (Python):
import random
import copy
import numpy as np


def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(D)]

    t = [0] * D

    
    penalty = np.array(c)
    for i in range(D):
        ind = 0
        tmp = 0
        for j in range(26):
            if penalty[j] + s[i][j] > tmp:
                tmp = penalty[j] + s[i][j]
                ind = j
        penalty[ind] = 0
        t[i] = ind + 1
        for j in range(26):
            penalty[j] += c[j]

    for tt in t:
        print(tt)


def calc(s, c, t):
    d = [0] * 26

    ans = 0
    days = 0
    for tt in t:
        for i in range(26):
            d[i] += 1
        d[tt-1] = 0
        ans += s[days][tt-1]
        for i in range(26):
            ans -= d[i] * c[i]
        days += 1
        print(ans)

    return ans


if __name__ == "__main__":
    main()

Solution (Python):
import sys 
import time

t0=time.time()
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
    

    D = int(input())
    
    cs = tuple(map(int, input().split())) 
    
    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
            
            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
        
        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=-1
        if target>0:
            for i in range(target-1,-1,-1):
                a=anss[i]
                if a==pval and not f1:
                    cp=i
                    f1=1
                elif a==val and not f2:
                    cv=i
                    f2=1
                if f1 and f2:
                    break
        f1=f2=0
        
        csv=cs[val-1]
        csp=cs[pval-1]
        tcv=(target-cv)*csv
        tcp=(target-cp)*csp
        

        score+=tcv-tcp
        for i in range(target+1,D):
            a=anss[i]
            if anss[i]==pval and not f2:
                f2=1
            elif 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)
    

    random.seed(1)
    yaki=1000.0
    count=0
    abest=anss.copy()
    tsc=csc
    lc=0
    while time.time()-t0<1.9:
        count+=1
        target=random.randrange(0,D)
        
        pval=anss[target]
        val=pval
        while val==pval:
            val=random.randrange(0,26)+1
        
        
        nsc=eval2(anss,tsc,target,val,pval)
        
        if nsc>csc:
            csc=nsc
            tsc=nsc
            anss[target]=val
            abest=anss.copy()
            lc=count
        else:
            if count-lc>2000:
                anss=abest.copy()
                tsc=csc
                lc=count
                continue
            r=random.random()
            if r<2**(-(csc-nsc)/(yaki+1e-9)):
                anss[target]=val
                tsc=nsc
            
            

    printl(abest)
    printe(csc,count,lc,abest[0])
    
    

if __name__ == "__main__":
    main()

Solution (Python):
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
lastday=[0 for j in range(26)]
points=[0 for i in range(D)]
t=[0 for i in range(D)]
total=[0 for i in range(D)]

lastday=[lastday[i]+1 for i in range(26)]
bestpoint=0
for i in range(26):
    temp=[con for con in lastday]
    temp[i]=0
    minus=sum([x*y for (x,y) in zip(c,temp)])
    temppoint=s[0][i]-minus
    if bestpoint<temppoint:
        today=i
        bestpoint=temppoint
        minusb=minus
lastday[today]=0
t[0]=today+1
total[0]=s[0][today]-minusb



for days in range(1,D):
    lastday=[lastday[i]+1 for i in range(26)]
    bestpoint=0
    for i in range(26):
        temp=[con for con in lastday]
        temp[i]=0
        minus=sum([x*y for (x,y) in zip(c,temp)])
        temppoint=s[days][i]-minus
        if bestpoint<temppoint:
            today=i
            bestpoint=temppoint
            minusb=minus
    lastday[today]=0
    t[days]=today+1
    total[days]=total[days-1]+s[days][today]-minusb
    
for ts in t:
    print(ts)

Solution (Python):
import random
import copy
D=int(input())                                          
c=list(map(int,input().split()))                        
s=[list(map(int,input().split())) for _ in range(D)]    





typ=0
ans=0

types=[(i%26)+1 for i in range(D)]

sc = [0] * D
last=[0]*26
for i in range(D):
    typ = types[i] - 1
    score = s[i][typ]
    dwn = 0
    last[typ] = (i + 1)
    for j in range(26):
        dwn = dwn + c[j] * ((i + 1) - last[j])
    ans = score - dwn
    
    sc[i] = max(ans+10**6,0)
all = sum(sc)
for _ in range(17000):
    types2 = [0]*D
    mi=float("inf")
    ind=0
    for i in range(D):
        if mi>sc[i]:
            mi=sc[i]
            ind=i
    l=list(range(1,D+1))
    
    
    l.pop(ind-1)
    ind2=random.choice(l)
    spans=ind//26
    for i in range(D):
        types2[i]=types[i]
    buf=types[ind]
    types[ind]=types[ind2-1]
    types[ind2-1]=buf
    sc2=[0]*D
    last=[0]*26
    for i in range(D):
        typ = types[i] - 1
        score = s[i][typ]
        dwn = 0
        last[typ] = (i + 1)
        for j in range(26):
            dwn = dwn + c[j] * ((i + 1) - last[j])
        ans = score - dwn
                
        sc2[i] = max(ans+10**6,0)
    all2 = sum(sc2)
    if all2<=all:
        types=types2
    else:
        sc=sc2
        all=all2
        sc2=[]
        
    
    
for i in range(D):
    print(types[i])

Solution (Python):


import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  

D = I()
c = [0] + LI()
s = [0] + [[0] + LI() for _ in range(D)]

last = [[0]*27 for _ in range(D+1)]
t = [0]

for i in range(1,D+1):
    r = 0
    manzoku = 0
    for j in range(1,27):
        m = s[i][j]
        for k in range(1,27):
            if k != j:
                m -= c[k]*(i-last[i-1][k])
            else:
                continue
        if j == 1:
            r = 1
            manzoku = m
        else:
            if manzoku < m:
                manzoku = m
                r = j
    t.append(r)
    for j in range(1,27):
        if j == r:
            last[i][j] = i
        else:
            last[i][j] = last[i-1][j]


dq = []
for i in range(1,D+1):
    for j in range(1,27):
        dq.append([i,j])

from copy import deepcopy

for d,q in dq:
    t0 = t[d]
    manzoku = s[d][q] - s[d][t0]
    for j in range(d,D+1):
        if j == d:
            last[d][t0] = last[d-1][t0]
            manzoku -= c[t0] * (d - last[d][t0])
            last[d][q] = d
            manzoku += c[q] * (d - last[d-1][q])
        else:
            if last[j][t0] == d:
                last[j][t0] = last[d-1][t0]
                manzoku -= c[t0] * (d - last[d][t0])
            if last[j][q] == last[d-1][q]:
                last[j][q] = d
                manzoku += c[q] * (d - last[d-1][q])
    if manzoku > 0:
        t[d] = q
    else:
        for j in range(d,D+1):
            if j == d:
                last[d][t0] = d
                last[d][q] = last[d-1][q]
            else:
                if last[j][t0] == last[d-1][t0]:
                    last[j][t0] = d
                if last[j][q] == d:
                    last[j][q] = last[d-1][q]

del t[0]

print(*t,sep='\n')

Solution (Python):
import time
import copy
import random


class Answer:
    """

    """

    def __init__(self, answer, score):
        self.answer = copy.deepcopy(answer)
        self.score = copy.deepcopy(score)
        self.last_days = [0] * 26


class Problem:
    def __init__(self, num_day, s, c):
        self.d = num_day
        self.s = s
        self.c = c
        self.last_days = [0] * 26
        self.answer = Answer([0] * self.d, 0)
        self.best_answer = Answer([0] * self.d, 0)
        self.not_change_duration = 0

        self.solve_greedy()
        self.answer = copy.deepcopy(self.best_answer)
        self.answer.score = 0

    def scoring(self, day, ind) -> int:
        day_score = self.s[day][ind]
        minus_score = 0
        for i in range(26):
            if i != ind:
                minus_score += self.c[i] * (day + 1 - self.last_days[i])
        day_score -= minus_score
        return day_score

    def get_all_scores(self, day):
        """全ての選択肢のscoreを返す"""
        minus_score = 0
        all_scores = [0] * 26
        for i in range(26):
            if i == 0:
                for j in range(1, 26):
                    minus_score += self.c[j] * (day + 1 - self.answer.last_days[j])
                all_scores[0] = self.s[day][0] - minus_score

            else:
                minus_score += self.c[i - 1] * (day + 1 - self.answer.last_days[i - 1])
                minus_score -= self.c[i] * (day + 1 - self.answer.last_days[i])
                all_scores[i] = self.s[day][i] - minus_score
        return all_scores

    def repeat(self):
        self.initialize()
        self.solve()
        self._update_best()

        return copy.deepcopy(self.best_answer)

    def solve(self):
        self.initialize()

        change_day = set([random.randint(0, self.d - 1) for _ in range(10)])
        for day in range(self.d):
            if day in change_day:
                pert = random.randint(1, 6)
            else:
                pert = 1
            all_scores = self.get_all_scores(day)
            all_scores_with_ind = [[i, all_scores[i]] for i in range(26)]
            all_scores_with_ind.sort(key=lambda x: x[1])
            ind = all_scores_with_ind[-pert][0]
            score = self.scoring(day, ind)
            self.answer.last_days[ind] = day + 1
            self.answer.answer[day] = ind
            self.answer.score += score
            

    def score_answer(self, answer: Answer):
        score = 0
        answer.last_days = [0] * 26
        for day in range(self.d):
            score += self.scoring(day, answer.answer[day])
            answer.last_days[answer.answer[day]] = day + 1

        return score

    def solve_greedy(self):
        for day in range(self.d):
            all_scores = self.get_all_scores(day)
            all_scores_with_ind = [[i, all_scores[i]] for i in range(26)]
            all_scores_with_ind.sort(key=lambda x: x[1])
            ind = all_scores_with_ind[-1][0]
            score = self.scoring(day, ind)
            self.answer.last_days[ind] = day + 1
            self.answer.answer[day] = ind
            self.answer.score += score

    def _update_best(self):
        self.not_change_duration += 1
        if self.best_answer.score < self.answer.score:
            print("fgooo")
            print(self.answer.answer)
            self.best_answer = copy.deepcopy(self.answer)
        if self.not_change_duration > 10:
            
            self.answer = copy.deepcopy(self.best_answer)
            self.not_change_duration = 0

    def initialize(self):
        
        
        self.answer.score = 0


def main():
    time_start = time.time()
    limited_time = 2 * 0.90
    D = int(input())
    c = list(map(int, input().split()))
    s = []

    for _ in range(D):
        s.append(list(map(int, input().split())))

    problem = Problem(D, s, c)
    ite = 0
    while time.time() - time_start < limited_time:
        ite += 1
        problem.repeat()

    
    for i in range(D):
        print(problem.best_answer.answer[i] + 1)


main()

Solution (Python):


from time import time
from math import exp
key = 1
rnd_mod = 12345678901234567891
rnd_x = 9876543210987654321 + 1234567890123456789 * key % rnd_mod
def rnd():
    global rnd_x
    rnd_x = rnd_x**2 % rnd_mod
    return (rnd_x>>10) % (1<<40)
def randrange(a, b=-1):
    if b > 0: return randrange(b-a) + a
    return rnd() % a

def calc():
    s = 0
    last = [-1] * 26
    for i, t in enumerate(A):
        s += S[i][t]
        last[t] = i
        for j, c in enumerate(C):
            s -= c * (i - last[j])
    return s

sTime = time()
D = int(input())
C = [int(a) for a in input().split()]
S = [[int(a) for a in input().split()] for _ in range(D)]
A = [randrange(26) for _ in range(D)]



ans = calc()


def day_all(d):
    global ans
    i = A[d]
    for k in range(d)[::-1]:
        if A[k] == i:
            prev = k
            break
    else:
        prev = -1
    for k in range(d + 1, D):
        if A[k] == i:
            prev_ne = k
            break
    else:
        prev_ne = D
    for j in range(26):
        t = S[d][j] - S[d][i]
        for k in range(d)[::-1]:
            if A[k] == j:
                new = k
                break
        else:
            new = -1
        for k in range(d + 1, D):
            if A[k] == j:
                new_ne = k
                break
        else:
            new_ne = D
        t += C[j] * (d - new) * (new_ne - d) - C[i] * (d - prev) * (prev_ne - d)
        if (T < 1 and t > 0) or (T >= 1 and randrange(1 << 10) < exp(max(min(t / T, 0), -10)) * (1 << 10)):
            A[d] = j
            ans += t
            prev, prev_ne = new, new_ne
            i = j
            if 0:
                print("A =", A)
                print("ans =", ans)
                print("calc =", calc())

def swap(d1, d2):
    global ans
    i = A[d1]
    j = A[d2]
    for d in range(d1 + 1, d2):
        if A[d] == i:
            d1 = d
        if A[d] == j:
            d2 = d
            break
    for d in range(d1)[::-1]:
        if A[d] == i:
            previ = d
            break
    else:
        previ = -1
    for d in range(d1)[::-1]:
        if A[d] == j:
            prevj = d
            break
    else:
        prevj = -1
    for d in range(d2 + 1, D):
        if A[d] == i:
            nei = d
            break
    else:
        nei = D
    for d in range(d2 + 1, D):
        if A[d] == j:
            nej = d
            break
    else:
        nej = D
    
    t = S[d1][j] - S[d1][i] - S[d2][j] + S[d2][i]
    t -= (nei - d1 - d1 + previ) * (d2 - d1)
    t += (nej - d2 - d2 + prevj) * (d2 - d1)
    if (T < 1 and t > 0) or (T >= 1 and randrange(1 << 10) < exp(max(min(t / T, 0), -10)) * (1 << 10)):
        A[d1], A[d2] = j, i
        ans += t


ans = calc()
loop = 0
while 1:
    if loop % 100 == 0:
        tt = (time() - sTime) / 1.8
        if tt >= 1:
            break
        T = 2500 * (1 - tt)
    loop += 1
    
    if randrange(1 << 10) < tt:
        d1 = randrange(D)
        d2 = d1
        while A[d1] == A[d2]:
            d2 = randrange(D)
        if d2 < d1: d1, d2 = d2, d1
        swap(d1, d2)
        if 0:
            print("2")
            print("ans =", ans)
            print("calc =", calc())
        
    else:
        d = randrange(D)
        day_all(d)
        if 0:
            print("1")
            print("ans =", ans)
            print("calc =", calc())
    
print(*[a + 1 for a in A], sep = "\n")
if 0:
    print(ans)
    print("A =", A)

Solution (Python):
import sys 
import time

t0=time.time()
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
    

    D = int(input())
    
    cs = tuple(map(int, input().split())) 
    
    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
            
            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
        
        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=-1
        if target>0:
            for i in range(target-1,-1,-1):
                a=anss[i]
                if a==pval and not f1:
                    cp=i
                    f1=1
                elif a==val and not f2:
                    cv=i
                    f2=1
                if f1 and f2:
                    break
        f1=f2=0
        
        csv=cs[val-1]
        csp=cs[pval-1]
        tcv=(target-cv)*csv
        tcp=(target-cp)*csp
        

        score+=tcv-tcp
        for i in range(target+1,D):
            a=anss[i]
            if anss[i]==pval and not f2:
                f2=1
            elif 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)
    

    random.seed(1)
    yaki=1000.0
    count=0
    abest=anss.copy()
    tsc=csc
    while time.time()-t0<1.9:
        count+=1
        target=random.randrange(0,D)
        
        pval=anss[target]
        val=pval
        while val==pval:
            val=random.randrange(0,26)+1
        
        
        nsc=eval2(anss,tsc,target,val,pval)
        
        if nsc>csc:
            csc=nsc
            tsc=nsc
            anss[target]=val
            abest=anss.copy()
        else:
            r=random.random()
            if r<2**(-(csc-nsc)/(yaki+1e-9)):
                anss[target]=val
                tsc=nsc
            
            

    printl(abest)
    
    
    

if __name__ == "__main__":
    main()