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 math import inf
from random import randint,random
import time
START=time.time()
PROB=0.9999

def f(a,d,T):
    try:
        return T[d:].index(a)+d
    except ValueError:
        return len(T)

from random import randint
A=26

D=int(input())

C=[0]+list(map(int,input().split())) 
S=[0]*(D+1) 

for i in range(1,D+1):
    S[i]=[0]+list(map(int,input().split()))
 
def g(d,q,S,C,T):
    p=T[d]

    a=f(p,d+1,T)
    b=f(q,d+1,T)
    
    Y=0
    h=L[d-1][p]
    for i in range(d,a):
        h+=1
        Y+=h-L[i][p]
        
    m=0
    Z=0
    for j in range(d,b):
        Z-=m-L[j][q]
        m+=1
        
    return (S[d][q]-S[d][p])+Z*C[q]-Y*C[p]

T=[0]
L=[[0]*(A+1) for _ in range(D+1)]
for d in range(1,D+1):
    M=-inf
    E=0

    for j in range(1,A+1):
        X=0
        for k in range(1,A+1):
            if j!=k:
                X-=C[k]*L[d][k]
                
        if M<=X+S[d][j]:
            M=X+S[d][j]
            E=j

    T.append(E)
    for j in range(1,A+1):
        if j!=E:
            L[d][j]=L[d-1][j]+1
        else:
            L[d][j]=0

while time.time()-START<=1.72:
    e=randint(1,D)
    q=randint(1,A)

    V=g(e,q,S,C,T)
    if V>0 or random()>PROB:
        p=T[d]

        a=f(p,d+1,T)
        b=f(q,d+1,T)
        
        h=L[d-1][p]
        for i in range(d,a):
            h+=1
            L[i][p]=h

        m=0
        for j in range(d,b):
            L[j][q]=m
            m+=1
        T[d]=q

for i in range(1,D+1):
    print(T[i])

Solution (Python):
import random
D = int(input())
C = input().split()
C = [int(c) for c in C]
S = []
for i in range(D):
  s = input().split()
  s = [int(j) for j in s]
  S.append(s)

T = [26] * D
def value():
  M = 0
  last = [0] * 26
  for d in range(1,D+1):
    N = 0
    t = T[d-1]
    last[t-1] = d
    
    for j in range(26):
      N = N + C[j]*(d-last[j])
    M = M + S[d-1][t-1] - N
  return(M)
Vmax = value()

Q = []
for i in range(1000):
  Q.append([random.randint(1,D), random.randint(1,26)])
for i in range(1000):
  Tprev = T
  T[Q[i][0]-1] = Q[i][1]
  V = value()
  if V > Vmax:
    Vmax = V
  else:
    T = Tprev
  

for t in T:
  print(t)

Solution (Python):
import time
import random


class Problem:

    def __init__(self, D, s, c):
        self.last_days = [0] * 26
        self.D = D
        self.s = s
        self.c = c
        self.answer = [0] * self.D
        self.best_answer = [0] * self.D

    def scoring(self, day, ind):
        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.last_days[j])
                all_scores[0] = self.s[day][0] - minus_score

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

    def _strategy_greedy(self, day):
        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)
        return score, ind

    def solve(self):
        self.init()

        sum_score = 0
        for i in range(self.D):
            score, ind = self._strategy_greedy(i)
            self.last_days[ind] = i + 1
            self.answer[i] = ind
            sum_score += score
        return sum_score, self.answer

    def _strategy_perturbation(self):
        
        
        day = random.randint(0, 3)

        

        random.randint(0, 3)

    def solve_greed(self):
        self.init()

    def init(self):
        self.last_days = [0] * 26
        self.answer = [0] * self.D


def main():
    time_start = time.time()
    DO_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())))

    max_score = 0

    problem = Problem(D, s, c)
    ite = 0
    while time.time() - time_start < DO_TIME:
        ite += 1
        score, answer = problem.solve()

        if score > max_score:
            
            
            max_score = score
            problem.best_answer = answer

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


main()

Solution (Python):


import sys
import numpy as np
def main():
    DEBUG_MODE=False

    if DEBUG_MODE:
        f = open('tester/example/sample2.in')
        fo=open('tester/example/sample2.out','w')
    
    if DEBUG_MODE:
        D = int(f.readline())
    else:
        D = int(sys.stdin.readline())
    Dur = np.zeros(26)
    S = np.zeros((D, 26))
    if DEBUG_MODE:
        C = np.array(list(map(int, f.readline().split())))
    else:
        C = np.array(list(map(int, sys.stdin.readline().split())))
    
    for i in range(D):
        if DEBUG_MODE:
            S[i] = list(map(int, f.readline().split()))
        else:
            S[i] = list(map(int, sys.stdin.readline().split()))

    now=0
    already=set()
    for d in range(D):
        argSS=np.argsort(S[d])
        for c in argSS[::-1]:
            if c not in already:
                already.add(c)
                out=c+1
                break

        if DEBUG_MODE:
            fo.write(str(out)+'\n')
        else:
            print(out)

        now+=1
        if now==26:
            now=0
            already=set()

    if DEBUG_MODE:
        f.close()
        fo.close()
main()

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

def main():
    D = int(input())
    c = [0] + list(map(int, input().split()))
    s = [[0]*27]
    for _ in range(D):
        s.append([0] + list(map(int, input().split())))
    for i in range(1, D+1):
        print(s[i].index(max(s[i])))

if __name__ == '__main__':
    main()

Solution (Python):
import time
s = time.time()
import numpy as np

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

last_day = np.zeros(26, dtype=int)

ans = []
for d in range(1, D+1):
    decrease = c * (d - last_day)
    sd = decrease.sum()
    diff = [S[d-1, i] - sd + decrease[i] for i in range(26)]
    choice = np.argmax(diff)
    ans.append(choice+1)
    last_day[choice] = d

def calc_pre(ans, pre_t, t, d):
    flag1 = flag2 = True
    res = [-1, -1]
    for day in range(d-1, -1, -1):
        td = ans[day]
        if td == pre_t and flag1:
            res[0] = day
            flag1 = False
        if td == t and flag2:
            res[1] = day
            flag2 = False
        if not (flag1 or flag2):
            return res
    return res

def calc_next(ans, pre_t, t, d):
    flag1 = flag2 = True
    res = [D, D]
    for day in range(d+1, D):
        td = ans[day]
        if td == pre_t and flag1:
            res[0] = day
            flag1 = False
        if td == t and flag2:
            res[1] = day
            flag2 = False
        if not (flag1 or flag2):
            return res
    return res

while time.time() - s < 1.9:
    d = np.random.randint(0, D, 1)[0]
    t = np.random.randint(0, 26, 1)[0]
    pre_t = ans[d] - 1
    if pre_t == t:
        continue
    dm1, dm2 = calc_pre(ans, pre_t, t, d)
    dp1, dp2 = calc_next(ans, pre_t, t, d)
    diff = S[d, t] - S[d, pre_t] + c[pre_t]*(dm1-d)*(dp1-d) - c[t]*(dm2-d)*(dp2-d)
    if diff > 0:
        ans[d] = t + 1

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

import numpy as np
import time
import random
start = time.time()
D = int(input())
Cs = np.array(list(mapint()))
Ss = np.array([list(mapint()) for _ in range(D)], dtype=np.float64)
last = np.zeros(26, dtype=np.float64)

lis = []
for i in range(D):
    last_2 = i-last
    last_2.astype(np.float64)
    arr = Ss[i] + Cs*last_2
    idx = np.argmax(arr)
    last[idx] = i+1
    lis.append(idx+1)

def check(Ts):
    last_day = np.zeros(26)
    sati = 0
    for i in range(D):
        t = Ts[i]-1
        sati += Ss[i][t]
        last_day[t] = i+1
        sati += sum((last_day-(i+1))*Cs)
    return sati

now = check(lis)
while time.time()-start<1.7:
    lis_2 = lis[:]
    for i in range(10):
        num = random.randint(1, 26)
        num2 = random.randint(0, 364)
        if num==num2:
            continue
        lis_2[num2] = num
    nx = check(lis_2)
    if nx>now:
        lis = lis_2
        now = nx

for d in lis:
    print(d)

Solution (Python):

from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

from random import randint
import time

def score(t):
    last = [-1]*26
    sm = 0
    for i in range(d):
        tt = t[i]
        sm += s[i][tt]
        for j in range(26):
            sm -= c[j]*(i-last[j])
    return sm

t1 = time.time()
d = inn()
c = inl()
s = []
for i in range(d):
    s.append(inl())
t = []
for i in range(d):
    t.append(randint(0,25))
last = [[-1]*26 for i in range(d)]
for i in range(d):
    td = t[i]
    for j in range(i,d):
        last[j][td] = j-i

cnt = 0
mx = -BIG
mxt = []
while True:
    cnt += 1
    if cnt==100:
        t2 = time.time()
        if t2>t1+1.8:
            break
        cnt = 0
    v = score(t)
    if v>mx:
        mx = v
        mxt = t
    dd = randint(0,d-1)
    LAS = 4
    SD = 4
    typ = randint(0,LAS+SD)
    if typ==0:
        while True:
            qq = randint(0,25)
            if qq!=t[dd]:
                break
    elif typ<=LAS:
        mn = BIG
        td = t[dd]
        last = [-1]*26
        for k in range(dd,-1,-1):
            if last[t[k]]<0:
                last[t[k]] = k
        for j in range(26):
            if last[j]<mn and j!=td:
                mn = last[j]
                qq = j
    else:
        mx = -1
        td = t[dd]
        for j in range(26):
            if s[dd][j]>mx and j!=td:
                mx = s[dd][j]
                qq = j
    t[dd] = qq
    

for i in range(d):
    print(mxt[i]+1)

Solution (Python):
D = int(input())
c = list(map(int, input().split()))
sdi = [list(map(int, input().split())) for i in range(D)]



lastdi = [0 for i in range(26)]
ans_c = []

d = 0
while True:
  if d == D:
    break
  if d > D - 2:
    day_s = sdi[d]
    
    sloss = [day_s[i] + c[i]*(d - lastdi[i]) for i in range(26) ]
    ans = sloss.index(max(sloss))
    ans_c.append( ans+1 )
    
    lastdi[ans] = d
    d += 1
    
  else:
    
    a = [sdi[d][i] + sdi[d+1][i2] - sum([c[k]*( 2*d-lastdi[k]+1) for k in range(26) if k not in [i,i2]] ) -c[i] -c[i2]*(d-lastdi[i2]) for i in range(26) for i2 in range(26) ]
    idx = a.index(max(a))
    best_i2 = idx % 26 + 1
    best_i1 = (idx // 26) % 26 + 1
    
    ans_c.append(best_i1)
    ans_c.append(best_i2)
    lastdi[best_i1-1] = d
    lastdi[best_i2-1] = d+1
    
    d += 2

for i in range(D):
  print(ans_c[i])

Solution (Python):
import numpy as np

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

last = np.array( [-1]*26 )
av = np.array( [0]*26 )
id = np.identity(4,dtype=int)

def fav(d,c):
  return( s[d] - sum( c*(d-last) ) + c*(d-last) )

c2 = c*2
v = 0
for d in range(D):
  av = fav( d, c )
  av2 = fav( d, c2 )
  av2 += av
  m = max(av2)
  for t in range(26):
    if av2[t] == m:
      last[t] = d
      v += av[t]
      print(t+1)
      break

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

TMPMAX = -float('inf')
for j in range(2):
    cands = [0] * D

    types = []
    last = [-1] * 26
    S = 0
    for d in range(D):
        
        M = -float('inf')
        for tt in range(26):
            _last = last[:]
            tmp = s[d][tt]

            _last[tt] = d
            for i in range(26):
                tmp -= c[i] * (d - _last[i])

            if tmp > M:
                M = tmp
                M_tt = tt

        S += s[d][M_tt]

        last[M_tt] = d
        for i in range(26):
            S -= c[i] * (d - last[i])
        types.append(M_tt)


    last = [-1] * 26
    S = 0

    if j == 0:
        r = list(range(D))
    else:
        r = list(reversed(range(D)))
    for d in r:
        seq = []
        for tt in range(26):
            _last = last[:]
            tmp = s[d][tt]

            _last[tt] = d
            for i in range(26):
                tmp -= c[i] * (d - _last[i])

            seq.append([tmp, tt])

        seq.sort(reverse=True)

        tmpmax = -float('inf')
        for i in range(15):
            tt = seq[i][1]
            _last = last[:]
            _types = types[:]
            _types[d] = tt
            _S = S

            for dd in range(d, D):
                _S += s[dd][_types[dd]]
                _last[_types[dd]] = dd
                for i in range(26):
                    _S -= c[i] * (dd - _last[i])

            if _S > tmpmax:
                cand = tt
                tmpmax  = _S

        cands[d] = cand + 1
        S += s[d][cand]
        last[cand] = d
        for i in range(26):
            S -= c[i] * (d - last[i])

    if S > TMPMAX:
        TMPMAX = S
        ans = cands

for _ans in ans:
    print(_ans)

Solution (Python):
from time import time
start = time()
import random
from sys import stdin
input = stdin.readline
D = int(input())
*c, = map(int, input().split())
S = []
for _ in [None] * D:
    *s, = map(int, input().split())
    S += s,
INF = float("inf")

def Tread(D):
    return [int(input()) for i in [None] * D]

def check(T):
    M = 0
    MM = []
    last = [-1] * 26
    for d, t in enumerate(T):
        M += S[d][t] - sum((d - last[i]) * c[i] for i in range(26) if i != t)
        last[t] = d
        
    return M 

def 貪欲():
    M = 0
    T = []
    last = [-1] * 26
    for d in range(D):
        m = -INF
        for j in range(26):
            Q = S[d][j] - sum((d - last[i]) * c[i] for i in range(26) if i != j)
            if m < Q:
                t, m = j, Q
        T += t,
        last[t] = d
        M += m
        
    return T, M

def 局所探索():
    T, M = 貪欲()
    
    while time() - start < 1.91:
        d, q = random.randrange(D), random.randrange(26)
        Check = T[:]
        Check[d] = q
        C = check(Check)
        if C > M:
            M, T = C, Check
    for s in T:print(s + 1)
    

局所探索()

Solution (Python):
from random import *
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=[0]*26
P=[]
Y,Z=0,0
V,W=0,0
T,U=0,0
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
    XX[j]+=X[j]
  Y,Z=-1,-10**20
  V,W=Y,Z
  T,U=V,W
  for j in range(26):
    if Y==-1:
      Y,Z=0,X[0]+S[i][0]
    if Z<X[j]+S[i][j]:
      T,U=V,W
      V,W=Y,Z
      Y,Z=j,X[j]+S[i][j]
    elif W<X[j]+S[i][j]:
      T,U=V,W
      V,W=j,X[j]+S[i][j]
    elif T<X[j]+S[i][j]:
      T,U=j,X[j]+S[i][j]
  XX[Y]-=X[Y]
  X[Y]=0
  P.append([Y,V,T])
  if randrange(0,50)==0:
    P[i][1]=randrange(0,26)
  if randrange(0,5)==0:
    P[i][2]=randrange(0,26)
  P[i]=tuple(P[i])
SCORE=0
X=[0]*26
for i in range(D):
  SCORE+=S[i][P[i][0]]
  for j in range(26):
    X[j]+=C[j]
  X[P[i][0]]=0
  SCORE-=sum(X)
SCORE2=0
YY=[]
for i in range(D):
  for k in range(2):
    d,q=i,P[i][k+1]
    SCORE2=SCORE
    YY=XX[:]
    SCORE2-=S[d][P[d][0]]
    SCORE2+=S[d][q]
    for j in range(26):
      X[j]=0
    YY[P[d][0]],YY[q]=0,0
    for j in range(D):
      if j==d:
        Z=q
      else:
        Z=P[j][0]
      X[P[d][0]]+=C[P[d][0]]
      X[q]+=C[q]
      X[Z]=0
      YY[P[d][0]]+=X[P[d][0]]
      YY[q]+=X[q]
    if SCORE2-sum(YY)>SCORE-sum(XX):
      z=[P[i][k+1]]
      for l in range(3):
        if l!=k:
          z.append(P[i][l])
      P[i]=tuple(z)
      XX=YY[:]
      SCORE=SCORE2
for i in range(D):
  print(P[i][0]+1)

Solution (Python):
import numpy as np
from sys import argv
import time


def input_from_file():
    with open(argv[1], "r") as f:
        D = int(f.readline())
        C = np.array(f.readline().split(), dtype=int)
        S = tuple(tuple(map(int, f.readline().split())) for _ in range(D))
    return D, C, S


def input_from_console():
    D = int(input())
    C = np.array(input().split(), dtype=int)
    
    S = np.array([input().split() for _ in range(D)], dtype=int)
    cand = np.argsort(C * S)[:, 10:] + 1
    return D, C, S, cand.tolist()


def greed(D, C, S):
    last = np.ones(26, dtype=int)
    ans = []
    for s in S:
        s = np.array(s)
        tmp = s + C * last
        i = np.argmax(tmp)
        last[i] = 0
        last += 1
        ans.append(i + 1)
    return ans


def calc_score(D, C, S, T):
    res = 0
    last = np.ones(26, dtype=int)
    for d, t in enumerate(T):
        t -= 1
        last[t] = 0
        score = S[d][t]
        score -= (C * last).sum()
        res += score
        last += 1
    return res


def output_to_file(ans):
    with open("output.txt", "w", newline="") as f:
        for a in ans:
            f.write("{}\n".format(a))


def main():
    start = time.time()
    lim = 1.800
    D, C, S, cand = input_from_console()
    
    
    sol = greed(D, C, S)
    score = calc_score(D, C, S, sol)
    while True:
        d = np.random.randint(0, D)
        q = np.random.choice(cand[d])
        old = sol[d]
        sol[d] = q
        new_score = calc_score(D, C, S, sol)
        if new_score > score:
            score = new_score
        else:
            sol[d] = old
        if time.time() - start >= lim:
            break
    print(*sol, sep="\n")
    


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import unittest
import random

T = 26


def solve(d, c, s):
    best = [0] * d
    last = [-1]*T

    for i in range(d):
        max_v = -float('inf')
        for j in range(T):
            v = s[i][j] + c[j] * (i - last[j])
            if max_v < v:
                max_v = v
                best[i] = j
        last[best[i]] = i

    score = get_score(d, c, s, best)
    for i in range(1500):
        a = random.randint(0, d-1)
        b = random.randint(0, T-1)
        old = best[a]
        best[a] = b
        t_score = get_score(d, c, s, best)
        if t_score > score:
            score = t_score
        else:
            best[a] = old
    return best


def get_score(d, c, s, t):
    last = [-1]*T
    total = 0
    for i in range(d):
        total += s[i][t[i]]
        last[t[i]] = i
        for j in range(T):
            total -= c[j] * (i - last[j])
    return total


def main():
    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for i in range(d)]
    t = solve(d, c, s)
    print(get_score(d, c, s, t), file=sys.stderr)
    for i in range(d):
        print(t[i]+1)


if __name__ == "__main__":
    main()


class Test(unittest.TestCase):
    def test_score(self):
        pass

Solution (Python):
inf = 10**12


def main():
    import sys
    from random import randint
    input = sys.stdin.readline

    class Bit:
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x):
            while i <= self.size:
                self.tree[i] += x
                i += i & -i

        def lower_bound(self, w):
            if w <= 0:
                return 0
            x = 0
            k = 1 << (self.size.bit_length() - 1)
            while k:
                if x + k <= self.size and self.tree[x + k] < w:
                    w -= self.tree[x + k]
                    x += k
                k >>= 1
            return x + 1

    D = int(input())
    C = list(map(int, input().split()))
    S = [[]]
    for _ in range(D):
        S.append(list(map(int, input().split())))
    ans = 0
    last = [0] * 26
    days = [Bit(D+1) for _ in range(26)]
    for i in range(26):
        days[i].add(D+1, 1)
    T = [-1]
    
    for d in range(1, D+1):
        plus = -inf
        t = -1
        for tt in range(26):
            plus_new = S[d][tt] + C[tt] * (d - last[tt])
            if plus_new > plus:
                t = tt
                plus = plus_new
        T.append(t)
        ans += S[d][t]
        last[t] = d
        days[t].add(d, 1)
        for i in range(26):
            ans -= C[i] * (d - last[i])

    def calc(d_list, q_list, cur):
        for d, q in zip(d_list, q_list):
            t = T[d]
            cur += S[d][q]
            cur -= S[d][t]
            k = days[q].sum(d)
            i = days[q].lower_bound(k)
            j = days[q].lower_bound(k+1)
            cur += C[q] * (d - i) * (j - d)
            k = days[t].sum(d)
            i = days[t].lower_bound(k-1)
            j = days[t].lower_bound(k+1)
            cur -= C[t] * (d - i) * (j - d)

            T[d] = q
            days[q].add(d, 1)
            days[t].add(d, -1)
        return cur


    
    size = 5
    try_num = 200
    loop_num = 10
    for _ in range(loop_num):
        for x in range(D // size):
            d_list = list(range(x*size+1, (x+1)*size+1))
            for _ in range(try_num):
                t_new = [randint(0, 25) for _ in range(size)]
                for i, d in enumerate(d_list):
                    if t_new[i] == T[d]:
                        t_new[i] = (t_new[i] + 1)%26
                t_ori = []
                for d in d_list:
                    t_ori.append(T[d])
                ans_new = calc(d_list, t_new, ans)
                if ans_new < ans:
                    for i in range(size-1, -1, -1):
                        d = d_list[i]
                        T[d] = t_ori[i]
                        days[t_ori[i]].add(d, 1)
                        days[t_new[i]].add(d, -1)
                else:
                    ans = ans_new
    
    for t in T[1:]:
        print(t+1)


if __name__ == '__main__':
    main()

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)
for i in range(D):
    print(i % 26 + 1)

Solution (Python):
import sys
import numpy as np

ri = lambda: int(sys.stdin.readline())
rl = lambda: list(map(int, sys.stdin.readline().split()))

D = ri()
c = np.array(rl())
s = np.array([np.array(rl()) for _ in range(D)])
li = np.zeros(26)
li_one = np.ones(26)
c_sum = sum(c)
for lis in s:
  idx_list = np.argsort(lis/c)[:-21:-1]
  li += li_one
  max_idx = 0
  max_score = -10**10
  for i in idx_list:
    tmp = li
    li[i] = 0
    sum_c_li = np.sum(c*li)
    score = lis[i] - sum_c_li
    if score >= max_score:
      max_idx = i
      max_score = score
    li = tmp
  print(max_idx + 1)

Solution (Python):
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json

import bisect
import sys
import random
import math
import time
import bisect
from functools import lru_cache
import itertools

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    start_time = time.time()
    D = int(input())
    c = [int(a) for a in input().split()]
    s = [
        [int(a) for a in input().split()]
        for _ in range(D)
    ]

    def calc_score(t):
        score = 0
        last = [0] * len(c)
        res = []

        for d, ti in enumerate(t):
            sdi = s[d][ti - 1]
            score += sdi
            last[ti - 1] = d + 1
            for i, ci in enumerate(c):
                score -= ci * ((d + 1) - last[i])
            res.append(score)
        return res

    def calc_score_diff(t, di, qi):
        old_q = t[di - 1]
        last_old_q_date = 0
        for i in range(di - 2, -1, -1):
            if t[i] == old_q:
                last_old_q_date = i + 1
                break
        next_old_q_date = D + 1
        for i in range(di, D):
            if t[i] == old_q:
                next_old_q_date = i + 1
                break

        old_d_last = di - last_old_q_date
        old_d_next = next_old_q_date - di
        old_diff = old_d_next * old_d_last * c[old_q - 1]

        new_q = qi
        last_new_q_date = 0
        for i in range(di - 2, -1, -1):
            if t[i] == new_q:
                last_new_q_date = i + 1
                break
        next_new_q_date = D + 1
        for i in range(di, D):
            if t[i] == new_q:
                next_new_q_date = i + 1
                break

        new_d_last = di - last_new_q_date
        new_d_next = next_new_q_date - di
        new_diff = new_d_next * new_d_last * c[new_q - 1]

        old_score = s[di - 1][old_q - 1]
        new_score = s[di - 1][new_q - 1]
        return new_diff - old_diff + new_score - old_score

    t = [1] * D
    score = calc_score(t)[-1]
    update_count = 0
    aa = 0
    best_t = [a for a in t]
    best_score = score
    ii = 0
    while True:
        ii += 1
        elapsed_time = time.time() - start_time
        if elapsed_time > 1.7:
            break

        di = random.randint(1, D)
        
        p = 0.1
        if random.random() < p:
            qi = random.randint(1, len(c))
        else:
            qi = 1
            max_diff = 0
            for i in range(len(c)):
                diff = calc_score_diff(t, di, i + 1)
                if diff > max_diff:
                    max_diff = diff
                    qi = i + 1

        diff = calc_score_diff(t, di, qi)
        if diff > 0:
            score += diff
            t[di - 1] = qi
            if score > best_score:
                best_t = [a for a in t]
                best_score = score
            update_count += 1
            aa = 0
        else:
            aa += 1
            if aa > 500:
                
                
                for i in range(10):
                    di = random.randint(1, D)
                    qi = random.randint(1, len(c))
                    t[di - 1] = qi
                aa = 0

    for ti in best_t:
        print(ti)


if __name__ == "__main__":
    main()