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):
D=int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
A = []
for i, c in enumerate(C):
    A.append((i, c))
A.sort(key=lambda x: x[1])
for i in range(D):
    j, c = A[i%26]
    print(j+1)

Solution (Python):
def choose(D, c, s, d, last, depth, p):
    maxpoint = -999999999
    maxnum = 0
    if depth > 0 and d < D:
        for i in range(26):
            point = p
            point += s[d][i]
            point += changepoint(c, d, i, last)*1
            nlast = []
            nlast.extend(last)
            nlast[i] = d
            z, point = choose(D, c, s, d+1, nlast, depth-1, point)
            if point > maxpoint:
                maxpoint = point
                maxnum = i
        return maxnum, maxpoint
    return 0, p


def changepoint(c, d, num, last):
    point = 0
    for j in range(26):
        if j != num:
            point -= c[j]*(d-last[j])
    return point


def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    last = [-1]*26
    for _ in range(D):
        s.append(list(map(int, input().split())))
    point = 0
    for i in range(D):
        num, point = choose(D, c, s, i, last, 2, 0)
        last[num] = i
        print(num+1)


main()

Solution (Python):
import random
D=int(input())
c=input().split()
c=[int(a) for a in c]
S=[]
for _ in range(D):
    s=input().split()
    s=[int(a) for a in s]
    S.append(s)
answers=[]
scores=[]
numbers=[]
for _ in range(100000):
    d=random.randrange(0,26,1)
    q=random.randrange(0,26,1)
    numbers.append([d,q])
whole=sum(c)
suuji=1
T=[]
while suuji<=365:
    T.append(random.randrange(0,26,1))
    suuji+=1
for m in range(100000):
    anss=[]
    ans = 0
    held = [0 for _ in range(26)]
    e=numbers[m][0]
    q=numbers[m][1]
    a=T[e]
    T[e]=q
    wholes=0
    for d in range(D):
        s = S[d]
        place = T[d]
        ans += s[place]
        wholes+=whole
        wholes-=c[place]*((d+1)-held[place])
        held[place] = d + 1
        ans-=wholes
    scores.append(ans)
    answers.append(T)
saidai=max(scores)
basho=scores.index(saidai)

answer=answers[basho]
for answer_ in answer:
    print(answer_+1)

Solution (Python):
import time
t0 =time.time()
D=int(input())
c = list(map(int,input().split()))

s=[None]*D
for i in range(D):
    s[i] = list(map(int,input().split()))

def maxarg(l):
    nl=len(l)
    ma=-10**20
    idx=-1
    for i in range(nl):
        if l[i]>ma:
            ma=l[i]
            idx=i
    return (idx,ma)

last=[0]*26
t_greed = []
for j,ss in enumerate(s):
    
    cand = [ss[i]+c[i]*(j+1-last[i]) for i in range(26)]
    idx,val = maxarg(cand)
    last[idx]=j+1
    t_greed.append(idx+1)

sumc=sum(c)
def calc_score(t):
    last=[0]*26
    satis=0
    pena=0
    delta_pena=0
    for j in range(D):
        ss=s[j]
        tt=t[j]
        satis += ss[tt-1]
        delta_pena += sumc - c[tt-1]*(j+1-last[tt-1])
        last[tt-1]=j+1   
        pena += delta_pena
    return satis-pena

import random
t_old=t_greed[:]
while True:
    if time.time()-t0>=1.8:
        break
    d = random.randrange(D+1)
    q = random.randrange(26)
    
    t_new = t_old[:]
    t_new[d-1] = q+1
    if calc_score(t_new)>calc_score(t_old):
        t_old=t_new[:]
        
for tt in t_old:
    print(tt)

Solution (Python):
D = int(input())
c = list(map(int, input().split()))
s = []

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


ans = 0
for l in s:
    for i in range(26):
        l[i] = (l[i], i)
    l.sort(reverse=True)
    print(l[0][1]+1)

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 

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=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
        
        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
            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)
    

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



    printl(anss)
    printe(csc)
    
    

if __name__ == "__main__":
    main()

Solution (Python):


D = int(input())
c = list(map(int, input().split()))

last = [0] * 26

ans = 0
max_M = 0
tmp_t = 0
t = []
mm = []
ll = []

for i in range(D):
    
    s = list(map(int, input().split()))
    
    last = list(map(lambda x: x + 1, last))
    
    minus = 0
    for x in range(26):
        minus = minus + (c[x] * last[x])
    
    max_M = 0                                                       
    for y in range(26):
        if max_M < s[y] + (c[y] * last[y]) - minus:
            max_M = s[y] + (c[y] * last[y]) - minus
            tmp_t = y                                                               
    
    mm.append(max_M)
    ll.append(last)
    t.append(tmp_t + 1  )
    last[tmp_t] = 0

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

Solution (Python):
import sys
import numpy as np
TYPE_NUM = 26
WEIGHT = 2

def resolve():

    inp = sys.stdin.readlines()
    D = int(inp[0])
    c = np.array(list(map(int, inp[1].split(' '))))
    s = []
    last = np.zeros(TYPE_NUM, dtype=int)
    types = []

    for i in range(2, len(inp)):
        s.append(list(map(int, inp[i].split(' '))))
    s = np.array(s, dtype=int)

    for d in range(D):
        temp_delta_satis = np.zeros([TYPE_NUM, TYPE_NUM], dtype=int)
        for idx in range(TYPE_NUM):
            val = s[d, idx]
            org = last[idx]
            last[idx] = d+1
            temp_delta_satis[:, idx] = (np.sum(-c*(d+1-last)) + val)*WEIGHT
            if D != d+1:
                for idx2 in range(TYPE_NUM):
                    val2 = s[d+1, idx2]
                    org2 = last[idx2]
                    last[idx2] = d+2
                    temp_delta_satis[idx2, idx] += np.sum(-c*(d+2-last)) + val2
                    last[idx2] = org2
            last[idx] = org
        opt_idx = np.unravel_index(np.argmax(temp_delta_satis), temp_delta_satis.shape)[1]
        last[opt_idx] = d+1
        types.append(opt_idx+1)
    print(*types, sep='\n')

resolve()

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
import random
import time
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def scorei(ti, i, last, minus):
        k = [i for i in last]
        mi = minus-(i+1-last[ti])*c[ti]
        v = s[i][ti]-mi
        mi += sum_
        k[ti] = i+1
        return v, k, mi

    def score(t):
        n = 26
        v = 0
        minus = sum_ = sum(c)
        last = [0]*n
        for i in range(d):
            ti = t[i]-1
            minus -= (i+1-last[ti])*c[ti]
            v += s[i][ti]-minus
            minus += sum_
            last[ti] = i+1
        return v
    start = time.time()
    d = I()
    c = LI()
    s = LIR(d)
    n = 26
    m = 10000
    sum_ = sum(c)
    q = [(0, 0, [0]*n, sum_)]
    pre = [[None]*n for i in range(d)]
    sc = [[float("inf")]*n for i in range(d)]
    argmax = 0
    for i in range(d):
        nq = []
        for _ in range(m):
            if not q:
                break
            v, x, last, minus = heappop(q)
            if i > 0 and v > sc[i-1][x]:
                continue
            for ti in range(n):
                vi,nl,nm = scorei(ti,i,last,minus)
                nv = v-vi
                heappush(nq,(nv,ti,nl,nm))
                if sc[i][ti] > nv:
                    sc[i][ti] = nv
                    pre[i][ti] = x
        q = [i for i in nq]
    t = []
    argmax = 0
    m = sc[-1][0]
    for i in range(1,n):
        sci = sc[-1][i]
        if m > sci:
            m = sci
            argmax = i
    t.append(argmax)
    x = argmax
    for i in range(1,d)[::-1]:
        y = pre[i][x]
        t.append(y)
        x = y
    t = [i+1 for i in t[::-1]]
    v = score(t)
    i = 0
    while time.time() < 1.5+start:
        nt = [i for i in t]
        r = random.randrange(1,n+1)
        nt[i] = r
        nv = score(nt)
        if v < nv:
            t = [i for i in nt]
            v = nv
        i += 1
        i %= d
    for i in t:
        print(i)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
import numpy as np

D = int(input())
c = np.array(list(map(int, input().split())))
s = np.array([list(map(int, input().split())) for _ in range(D)])


def s11(c, s, last_date, di, i, mul):
    score = s[di - 1][i]
    score += 0.01 * mul * c[i] * (di - last_date[i])
    return score


def f12(D, c, s):
    last_date = np.zeros(26)

    t = []
    for di in range(1, D + 1):
        mul = np.mean(s[di - 1]) / np.mean(c)
        score_list = []
        for i in range(26):
            score_list.append(s11(c, s, last_date, di, i, mul))

        select_index = score_list.index(max(score_list))
        t.append(select_index)
        last_date[select_index] = di

    return t


for ti in f12(D, c, s):
    print(ti + 1)

Solution (Python):
import sys
import math
import random
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate 
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache 
def choice_contest(c, data_day, last, day, contest):
    contest -= 1
    
    last = [i + 1 for i in last]
    
    last[contest] = 0
    
    
    
    d_satis = sum([last[i] * c[i] for i in range(26)])
    
    return [int(data_day[contest]) - d_satis, last]

def main():
    d = int(input())
    c = list(map(int,input().split()))
    data = [input().split() for _ in range(d)]
    last = [0] * 26
    ans = 0

    """
    hold_consets = [random.randrange(1, 26) for _ in range(d)]
    for i in range(d):
        s, last = choice_contest(c, data[i], last, i, contest = hold_consets[i])
        ans += s
    ans_hold_contest = hold_consets
    
    for _ in range(3):
        last_t = [0] * 26
        ans_t = 0
        hold_contest = [random.randrange(1, 26) for _ in range(d)]
        for i in range(d):
            s_t, last_t = choice_contest(c, data[i], last_t, i, contest = hold_contest[i])
            ans_t += s_t
        
        if ans < ans_t:
            ans = ans_t
            ans_hold_contest = hold_contest
    """
    for i in range(d):
        hold_contest = 1
        for j in range(26):
            last_t = [0] * 26
            if j == 0:
                s, last = choice_contest(c, data[i], last, i, contest = j + 1)
            else:
                s_t, last_t = choice_contest(c, data[i], last, i, contest = j + 1)
                if s < s_t:
                    s = s_t
                    last = last_t
                    hold_contest = j + 1
        print(hold_contest)
    

    return 0

if __name__ == "__main__":
    main()

Solution (Python):
import copy
import random
D = int(input())
cs = list(map(int,input().split()))
ss =[]
for i in range(D):
  ss.append(list(map(int,input().split())))
for r in range(100):
  ts = []
  for i in range(D):
    ts.append(random.randint(1, 26))
  if r ==0:
    maxts = copy.copy(ts)
  last = [0] * 26
  total =0
  for i in range(D):
    t = ts[i]
    last[t-1] = i+1
    genten=0
    for j in range(26):
      genten += cs[j] *(i+1 - last[j])
      total += ss[i][t-1]-genten
    if r==0:
      maxtsscore = total
    else:
      if maxtsscore < total:
        maxtsscore = total
        maxts = copy.copy(ts)
for z in maxts:
  print(z)

Solution (Python):
D = int(input())
C = list(map(int, input().split()))
S = []
for i in range(D):
    a = list(map(int, input().split()))
    S.append(a)
last_d = [0] * 26  
threshould = 100  
for i in range(D):
    idx = 1
    tmp_max = 0
    for j in range(26):
        
        if C[j] * (i + 1 - last_d[j]) / ((C[j] + 0.1) ** 0.5) >= threshould:
            idx = j
            break
        if tmp_max <= S[i][j]:
            tmp_max = S[i][j]
            idx = j

            
    print(idx + 1)
    last_d[idx] = i + 1

Solution (Python):
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
    
    

    
    
    
    
    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)


    
    while perf_counter() - start_time < 1.5:
        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)
        
        x = last_helds[old-1][old_idx - 1]
        y = last_helds[old-1][old_idx + 1]
        
        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)
            
            
            last_helds[q-1].insert(new_idx,d-1)
            
            T[d-1] = q
        else:
            satisfaction = old_sat
    for t in T:
        print(t+1)
    dbg(satisfaction,first_sat)
    dbg(perf_counter()-start_time)




    
main()

Solution (Python):
import random
d=int(input())
c=list(map(int,input().split()))
num=[0]*26
ans=[]
numans=0
s=[]
for i in range(1,d+1):
    num1=1
    num2=-(10**100)
    num3=[0]*26
    for j in range(26):
        num3[j]=-1*((i-num[j])*c[j])
    s.append(list(map(int,input().split())))
    for j in range(26):
        num5=s[i-1][j]-num3[j]
        if num5>num2:
            num1=j+1
            num2=num5
    ans.append(num1)
    numans+=num2+s[i-1][num1-1]
    num[num1-1]=i
def sco(n1,n2,n3):
    n0=0
    n01=[0]*26
    old=ans[n1]
    ans[n1]=n2
    for k in range(n3):
        n0+=s[k][ans[k]-1]
        n01[ans[k]-1]=k+1
        for l in range(26):
            n0-=(k+1-n01[l])*c[l]
    return n0
for i in range(1545):
    num6=random.randint(1,26)
    num7=random.randint(2,364)
    num100=sco(num7-1,num6,d)
    if num100>numans:
        ans[num7-1]=num6
for i in range(d):
    print(ans[i])

Solution (Python):
from collections import defaultdict
dic = defaultdict(list)
D = int(input())
C = list(map(int,input().split())) 
S = [] 
for i in range(D): 
    temp = list(map(int,input().split()))
    S.append(temp)
T = [] 
since = [0 for _ in range(26)] 
for i in range(26):
    since[i] += C[i]
for i in range(D):
    contest= max(since)
    idx = since.index(contest)
    T.append(idx)
    dic[idx].append(i)
    
    for j in range(26):
        if j != idx:
            since[j] += C[j]
        else:
            since[j] = C[j]
for i in range(len(dic)):
    dic[i].sort()

def cycle(T):
    manzoku = 0
    since = [0 for _ in range(26)]
    for i in range(26):
        since[i] += C[i]
    for i in range(D):
        contest = T[i] 
        manzoku += S[i][contest]
        for j in range(26):
            if j != contest:
                manzoku -= since[j]
        
        for j in range(26):
            if j != contest:
                since[j] += C[j]
            else:
                since[j] = C[j]
    return manzoku
score = cycle(T)
M = 26
DQ = []
for i in range(26):
    for j in range(D):
        DQ.append((j+1,i+1))
for i in range(M):
    
    d,q = DQ[i] 
    d-=1;q-=1 
    old = T[d]
    try:
        oscore = nscore*1
    except:
        oscore= score*1
    dic[old].remove(d)
    T[d] = q
    if old == q:
        nscore = oscore
    else:
        impact = S[d][q]-S[d][old] 
        
        if not dic[q]:
            impact += C[q]*(D-d)*(d+1)
        else:
            for j in range(len(dic[q])):
                if d < dic[q][0]:
                    impact += C[q]*(d+1)*(dic[q][0]-d)
                    break
                elif d > dic[q][-1]:
                    impact += C[q]*(D-d)*(d-dic[q][-1])
                    break
                else:
                    if dic[q][j] < d and d < dic[q][j+1]:
                        impact += C[q]*(d-dic[q][j])*(dic[q][j+1]-d)
                        break
        dic[q].append(d)
        dic[q].sort()
        if not dic[old]:
            impact -= C[old]*(D-d)*(d+1)
        else:
            for j in range(len(dic[old])):
                if d < dic[old][0]:
                    impact -= C[old]*(d+1)*(dic[old][0]-d)
                    break
                elif d > dic[old][-1]:
                    impact -= C[old]*(D-d)*(d-dic[old][-1])
                    break
                else:
                    if dic[old][j] < d and d < dic[old][j+1]:
                        impact -= C[old]*(d-dic[old][j])*(dic[old][j+1]-d)
                        break
        nscore = oscore+impact
        if nscore < oscore:
            nscore = oscore
            T[d] = old
            dic[q].remove(d)
            dic[old].append(d)
for ans in T:
    print(ans+1)

Solution (Python):
from time import perf_counter
t0 = perf_counter()


import sys
sys.setrecursionlimit(300000)
from collections import defaultdict
from random import randint

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


D = I()
C = LMI()
S = [LMI() for _ in range(D)]



last = defaultdict(int)
ans0 = []
for d in range(D):
    m = -INF
    ans = -1
    for i in range(26):
        lans = S[d][i]
        for j in range(26):
            if i == j:
                lans -= C[j] * (d + 1 - d - 1)
            else:
                lans -= C[j] * (d + 1 - last[j])
        if lans > m:
            m = lans
            ans = i
    ans0.append(ans)



T = ans0
last = [[i + 1] * 26 for i in range(D)]
for d in range(D):
    i = T[d]
    j = 0
    for dd in range(d, D):
        last[dd][i] = j
        j += 1

def eval(d, q):
    i = T[d]
    val = S[d][q] - S[d][i]

    contrib = 0
    if d == 0:
        j = 1
    else:
        j = last[d - 1][i] + 1
    for dd in range(d, D):
        if dd > d and last[dd][i] == 0:
            break
        contrib += j - last[dd][i]
        
        j += 1
    val -= contrib * C[i]

    contrib = 0
    j = 0
    for dd in range(d, D):
        if last[dd][q] == 0:
            break
        contrib += last[dd][q] - j
        
        j += 1
    val += contrib * C[q]

    

    return val

def apply(d, q):
    i = T[d]

    if d == 0:
        j = 1
    else:
        j = last[d - 1][i] + 1
    for dd in range(d, D):
        if dd > d and last[dd][i] == 0:
            break
        last[dd][i] = j
        j += 1

    j = 0
    for dd in range(d, D):
        if last[dd][q] == 0:
            break
        last[dd][q] = j
        j += 1

    T[d] = q

while perf_counter() - t0 < 1.8:
    d = randint(0, D - 1)
    q = randint(0, 25)
    if eval(d, q) > 0:
        apply(d, q)
    else:
        if randint(0, 10) == 3:
            apply(d, q)
for t in T:
    print(t + 1)

Solution (Python):
import random
import time
import copy
import math
start=time.time()
d=int(input())
c=list(map(int, input().split()))
cli=[]
for i in range(d+1):
  ch=[]
  for j in c:
    ch.append(i*j)
  cli.append(ch)
s=[]
solution=[]
last=[0]*26
sco=0
for i in range(d):
  s.append(list(map(int, input().split())))
for day in range(1,d+1):
  man=[]
  for i in range(26):
    man.append(s[day-1][i]+last[i]*c[i])
  con=man.index(max(man))
  sco+=s[day-1][con]
  last[con]=day
  for (i,j) in zip(last,range(26)):
    sco-=cli[i][j]
  solution.append(con)

stemp=1000000
etemp=10
def tem():
  return stemp-((stemp-etemp)*(time.time()-start)/1.9)
while time.time()-start<1.9:
  sc=0
  sol=copy.deepcopy(solution)
  for x in [random.randrange(d) for i in range(10)]:
    sol[x]=random.randrange(26)
  last=[0]*26
  for (day,i) in zip(range(1,d+1),sol):
    sc+=s[day-1][i]
    last[i]=day
    for (i,j) in zip(last,range(26)):
      sc-=cli[i][j]
  try:
    prob = math.exp((sc-sco)/tem())
  except:
    prob=0

  
  if prob>random.random():
    solution=copy.deepcopy(sol)
    sco=sc
for i in solution:
  print(i+1)

Solution (Python):

from copy import deepcopy
import random
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(D)]

last = {}
for i in range(26):
    last[i] = -1

s = 0
Ret = []
for d in range(D):
    sr = {}
    ll = {}
    for c in range(26):
        last_cp = deepcopy(last)
        s_cp = deepcopy(s)
        last_cp[c] = d
        s_cp += S[d][c]
        for i in range(26):
            s_cp -= C[i] * (d-last_cp[i])
        sr[c] = s_cp
        ll[c] = last_cp
    sr = sorted(sr.items(), key=lambda x:x[1])
    x = random.randint(1,2)
    ret = sr[-x][0]
    s = sr[-x][1]
    last = deepcopy(ll[ret])
    Ret.append(ret+1)

for r in Ret:
    print(r)

Solution (Python):
import sys
input=sys.stdin.readline

d=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for _ in range(d)]
A=[sorted([[j,S[i][j]] for j in range(26)],key=lambda x:x[1],reverse=True) for i in range(d)]


DP=[0]*26
for i in range(d):
    num,index=0,0
    for j in range(26):
        if A[i][j][1]-(C[j]*(i-DP[j]))>num:
            num=A[i][j][1]-C[j]*(i-DP[j])
            index=j
    DP[index]=i
    print(index+1)

Solution (Python):
import random
import sys
input = sys.stdin.readline
d=int(input())
c=list(map(int,input().split()))
cn=sorted(c)
h=cn[3]
P=[k+1 for k,v in enumerate(c) if v>=h]
s=[]
for _ in range(d):
    s.append(list(map(int,input().split())))




t=[]
for _ in range(d):
    z=random.randrange(len(P))
    t.append(P[z])

m=1000
q=[]
for _ in range(m):
    z2=random.randrange(len(P))
    z1=random.randrange(d)
    q.append([z1,P[z2]])
p=0
for k in range(m):
    ld=[-1]*26
    sc=0
    od=t[q[k][0]-1]
    t[q[k][0]-1]=q[k][1]

    for i in range(d):
        sc+=s[i][t[i]-1]
        ld[t[i]-1]=i

        C=0
        for j in range(26):
            C+=c[j]*(i-ld[j])
        sc-=C
    if p<sc:
        p=sc
    else:
        t[q[k][0]-1]=od

for f in range(len(t)):
    print(t[f])

Solution (Python):
import sys
input = sys.stdin.readline

d = int(input())
C = list(map(int,input().split()))
S = [list(map(int,input().split())) for i in range(d)]

c = 26



ans = 0
L = [[-1] * c for i in range(d)]
T = [-1] * d  
K = [[] for i in range(d)]  
pp = 6

for i in range(d):
    ANS = [0] * c
    L[i] = L[i-1][:]
    for k in range(c):
        ANS[k] = S[i][k] + C[k] * (i - L[i][k])
    ANSS = [[ANS[j], j] for j in range(c)]
    ANSS.sort(reverse=True)
    for j in range(pp):
        
        
        K[i].append(ANSS[j][1])
    ind = ANSS[0][1]
    ans += S[i][ind]
    L[i][ind] = i
    for j in range(c):
        ans -= C[j] * (i - L[i][j])
    
    
    T[i] = ind

fans = ans




KP = [[0] * pp for i in range(d)]

















    
from random import randint

m = 10*10**5












ndd = -1
nq = -1

for i in range(m):
    
    
    dd = ndd if ndd != -1 else randint(0, d-1)
    qind = randint(0, len(K[dd])-1)
    q = nq if nq != -1 else K[dd][qind]
    nans = ans
    
    nans -= S[dd][T[dd]]
    nans += S[dd][q]
    for j in range(dd, d):
        
        if T[j] == q:
            
            break
        nans += C[q] * (j - L[j][q])
        nans -= C[q] * (j - dd)
        L[j][q] = dd
    
    old = T[dd]
    T[dd] = q

    for j in range(dd, d):
        
        if T[j] == old:
            
            break
        oldl = L[j-1][old] if j > 0 else -1
        nans += C[old] * (j - dd)
        nans -= C[old] * (j - oldl)
        L[j][old] = oldl

    

    if nans < ans:
        KP[dd][qind] += 1
        if KP[dd][qind] == 10:
            _ = K[dd].pop(qind)
        if i != m-1:
            ndd = dd
            nq = old
        else:
            T[dd] = old
    else:
        ndd = -1
        nq = -1
    
    ans = nans


for i in T:
    print(i+1)