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
import random


def main():
    random.seed(0)

    now = time()

    MAX = 26

    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(d)]
    t = []
    for row in s:
        mxi = 1
        mx = 0
        for i, e in enumerate(row, 1):
            if e > mx:
                mx = e
                mxi = i

        t.append(mxi)

    last = [0] * MAX

    score = 0
    for day, e in enumerate(t, 1):
        score += s[day-1][e-1]
        last[e-1] = day

        for ec, elast in zip(c, last):
            score -= ec * (day - elast)

    d_li = []
    for i in range(1, d + 1):
        ln = (-(i - d // 2) ** 2 + d ** 2 // 4) // 500
        d_li += [i] * ln

    di_max = len(d_li) - 1

    c_sum = sum(c)
    c_li = []
    for i, e in enumerate(c, 1):
        c_li += [i] * e

    while time() - now <= 1.85:
        prev_score = score

        di = random.randint(0, di_max)
        ed = d_li[di]
        qi = random.randint(0, c_sum - 1)
        eq = c_li[qi]

        q_old = t[ed-1]
        d_prev = {q_old: 0, eq: 0}

        c_old = c[q_old-1]
        c_new = c[eq-1]

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score += c_old * (day - d_prev[q_old])
            score += c_new * (day - d_prev[eq])

        score -= s[ed-1][q_old-1]
        score += s[ed-1][eq-1]

        t[ed-1] = eq

        d_prev = {q_old: 0, eq: 0}

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score -= c_old * (day - d_prev[q_old])
            score -= c_new * (day - d_prev[eq])

        if prev_score > score:
            t[ed-1] = q_old
            score = prev_score

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


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import heapq
from typing import List, Tuple, Dict
from dataclasses import dataclass, field

import scipy
import numpy as np
from numba import njit

D = int(input())  
C = np.array(list(map(int, input().split())), dtype='int32')  
S = np.array([list(map(int, input().split())) for _ in range(D)], dtype='int32')  


@dataclass()
class Node:
    value: int
    plan: List[int]
    last: List[int]

    def __lt__(self, other) -> bool:
        return self.value > other.value  


def calc_dissatisfaction(d: int, last: List[int]) -> int:
    return sum([C[i] * (d - last[i]) for i in range(26)])


CAPACITY = 15

queue: List[Node] = [Node(0, [], [0 for _ in range(26)])]
for d in range(D):
    next_queue: List[Node] = []

    heapq.heapify(queue)
    while queue:
        node = heapq.heappop(queue)
        dis = calc_dissatisfaction(d + 1, node.last)

        for i in range(26):
            s = S[d][i] + C[i] * (d + 1 - node.last[i]) - dis

            next_queue.append(
                Node(
                    node.value + s,
                    node.plan + [i + 1],
                    node.last[:i] + [d + 1] + node.last[i + 1:]
                ),
            )

    queue = sorted(next_queue)[:CAPACITY]

res_node = heapq.heappop(queue)
print(res_node, file=sys.stderr)
print('\n'.join(map(str, res_node.plan)))

Solution (Python):

from random import randint
import sys
M = 2 * (10**5)
def main(D, C, S):
    def evaluate(i, t, satisfaction, last):
        satisfaction += S[i][t]
        last[t] = i
        for j, c in enumerate(C):
            satisfaction -= c * (i - last[j])
        return (satisfaction, last)

    ans = []
    satisfaction = 0
    last = [-1] * 26
    count = [BinaryIndexedTree(D) for _ in range(26)]
    for i in range(D):
        tt = -1
        ts = -10**10
        tl = None
        ps = satisfaction
        pl = last[:]
        for t in range(26):
            s, l = evaluate(i, t, ps, pl[:])
            if ts < s:
                tt = t
                ts = s
                tl = l
        ans.append(tt + 1)
        satisfaction = ts
        last = tl
        count[tt].add(i, 1)

    for i in range(M):
        tmp_s = satisfaction
        d = randint(0, D - 1)
        new = randint(0, 25)
        old = ans[d] - 1
        tmp_s += S[d][new] - S[d][old]
        cnt_old = count[old].query(d)
        nxt_d_old = count[old].bisect(lambda x: x < cnt_old + 1)
        pre_d_old = count[old].bisect(lambda x: x < cnt_old - 1) if cnt_old > 1 else -1
        tmp_s -= C[old] * (nxt_d_old - d) * (d - pre_d_old)
        ans[d] = new + 1
        count[old].add(d, -1)
        count[new].add(d, 1)
        cnt_new = count[new].query(d)
        nxt_d_new = count[new].bisect(lambda x: x < cnt_new + 1)
        pre_d_new = count[new].bisect(lambda x: x < cnt_new - 1) if cnt_new > 1 else -1
        tmp_s += C[new] * (nxt_d_new - d) * (d - pre_d_new)
        if tmp_s < satisfaction:
            ans[d] = old + 1
            count[old].add(d, 1)
            count[new].add(d, -1)
        else:
            satisfaction = tmp_s

    return ans

class BinaryIndexedTree:
    def __init__(self, n=None, f=lambda x, y: x + y, identity=0, initial_values=None):
        assert(n or initial_values)
        self.__f, self.__id, = f, identity
        self.__n = len(initial_values) if initial_values else n
        self.__d = [identity] * (self.__n + 1)
        if initial_values:
            for i, v in enumerate(initial_values): self.add(i, v)

    def add(self, i, v):
        n, f, d = self.__n, self.__f, self.__d
        i += 1
        while i <= n:
            d[i] = f(d[i], v)
            i += -i & i

    def query(self, r):
        res, f, d = self.__id, self.__f, self.__d
        r += 1
        while r:
            res = f(res, d[r])
            r -= -r & r
        return res

    def bisect(self, func):
        n, f, d, v = self.__n, self.__f, self.__d, self.__id
        x, i = 0, 1 << (n.bit_length() - 1)
        while i > 0:
            if x + i <= n and func(f(v, d[x + i])): v, x = f(v, d[x + i]), x + i
            i >>= 1
        return x

if __name__ == '__main__':
    input = sys.stdin.readline
    D = int(input())
    *C, = map(int, input().split())
    S = [list(map(int, input().split())) for _ in range(D)]
    ans = main(D, C, S)
    for a in ans:
        print(a)

Solution (Python):

import numpy as np
def main():
  d=int(input())
  c=np.array(list(map(int,input().split())))
  s=[None]*d
  r0=[None]*d
  r1=[None]*d
  cm=np.array([0]*26)
  cd=np.array([0]*26)

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


  for j in range(d):  
    
    
    r_i=np.argmax(s[j])
    cd=c*cm
    if np.max(cd>s[i][r_i]):
      r_i=np.argmax(cd)
    r0[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0
  
  
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  rand = np.random.randint(100, size = d) 
  for j in range(d):  
    
    r_i=r0[j]
    cd=c*cm
    if rand[j]>80:
      r_i=np.argmax(cd)
    r1[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0

  score0=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r0[j]
    score0+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score0+=-np.sum(cd)
  score1=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r1[j]
    score1+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score1+=-np.sum(cd)
  if score1>score0:
    r0=r1
    score0=score1
  
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  rand = np.random.randint(100, size = d) 
  for j in range(d):  
    
    r_i=r0[j]
    cd=c*cm
    if rand[j]>75:
      r_i=np.argmax(cd)
    r1[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0
  
  score1=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r1[j]
    score1+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score1+=-np.sum(cd)
  if score1>score0:
    r0=r1
    score0=score1
    
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  rand = np.random.randint(100, size = d) 
  for j in range(d):  
    
    r_i=r0[j]
    cd=c*cm
    if rand[j]>60:
      r_i=np.argmax(cd)
    r1[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0
  
  score1=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r1[j]
    score1+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score1+=-np.sum(cd)
  if score1>score0:
    r0=r1
    score0=score1
    
    cm=np.array([0]*26)
  cd=np.array([0]*26)  
  rand = np.random.randint(100, size = d) 
  for j in range(d):  
    
    r_i=r0[j]
    cd=c*cm
    if rand[j]>50:
      r_i=np.argmax(cd)
    r1[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0
  
  score1=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r1[j]
    score1+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score1+=-np.sum(cd)
  if score1>score0:
    r0=r1
    score0=score1

  for j in range(d):  
    print(r0[j]+1) 
 
main()

Solution (Python):
from bisect import bisect_left
from time import time
t0 = time()
def xorshift(seed=123456789):  
    y = seed
    def randint():
        nonlocal y
        y ^= (y & 0xffffff) << 7
        y ^= y >> 12
        return y
    return randint
randint = xorshift()
D = int(input())
C = list(map(int, input().split()))  
S = [list(map(int, input().split())) for _ in range(D)]
Last = [-1] * 26
def calc_pena(day):
    res = 0
    for l, c in zip(Last, C):
        res += (day-l)*c
    return res
T2 = [[-1] for _ in range(26)]

def change(day, contest):
    diff = 0
    contest_old = T[day]
    T[day] = contest
    idx = bisect_left(T2[contest_old], day)
    
    diff -= C[contest_old] * (T2[contest_old][idx+1] - day) * (day - T2[contest_old][idx-1])
    del T2[contest_old][idx]
    idx = bisect_left(T2[contest], day)
    diff += C[contest] * (T2[contest][idx] - day) * (day - T2[contest][idx-1])
    T2[contest].insert(idx, day)
    diff += S[day][contest] - S[day][contest_old]
    return diff
Check = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 9999]
idx_Check = 0
def check():
    global idx_Check, ans
    if Check[idx_Check] < time()-t0:
        idx_Check += 1
        print(ans, Check[idx_Check-1])

T = []
ans = 0
for day, s in enumerate(S):
    best_gain = -999999
    best_gain_contest = None
    pena = 0
    for cont, (l, c, s_) in enumerate(zip(Last, C, s)):
        p = (day-l)*c
        pena += p
        if best_gain < s_ + p:
            best_gain = s_ + p
            best_gain_contest = cont
    T.append(best_gain_contest)
    Last[best_gain_contest] = day
    ans += best_gain - pena









for i, t in enumerate(T):
    T2[t].append(i)
for i in range(26):
    T2[i].append(D)  





while time()-t0 < 1.9:
    r = randint()
    day = r % D
    r //= D
    contest = r % 26
    contest_old = T[day]
    ch = change(day, contest)
    if ch >= 0 or (time()-t0 < 1.7 and -ch < randint()&0x3ff):
        ans += ch
        
        
    else:
        change(day, contest_old)

print("\n".join(str(a+1) for a in T))

Solution (Python):
import copy
import random
d = int(input())
c = list(map(int,input().split()))
s = []
t = [0 for _ in range(d)]
for i in range(d):
  si = list(map(int,input().split()))
  s.append(si)
lastd = [-1 for _ in range(26)]
for i in range(d):
  mx = 0
  mj = 0
  for j in range(26):
    if s[i][j] + (i-lastd[j])*c[j] > mx:
      mx = s[i][j] + (i-lastd[j])*c[j]
      mj = j
  lastd[mj] = i
  t[i] = mj
lastd = [-1 for _ in range(26)]
ans = 0
for i in range(d):
  di = t[i]
  lastd[di-1] = i
  ans += s[i][di-1]
  for j in range(26):
    ans -= (i-lastd[j])*c[j]
mxans = ans
mxt = copy.deepcopy(t)
for time in range(9000):
  da = random.randint(0, d-1)
  qb = t[da]
  if random.random() < 0.8:
    bord = c[qb]*(0.8)
    qac = []
    cap = qac.append
    for i in range(0,qb):
      if s[da][i] > bord:
        cap(i)
      continue
    for i in range(qb+1,26):
      if s[da][i] > bord:
        cap(i)
      continue
    if len(qac) == 0:
      continue
    qa = random.choice(qac)
  else:
    bord = c[qb]//2
    qac = []
    cap = qac.append 
    for i in range(0,qb):
      if c[i] > bord:
        cap(i)
    for i in range(qb+1,26):
      if c[i] > bord:
        cap(i)
    if len(qac) == 0:
      continue
    qa = random.choice(qac) 
  
  qb1 = -1
  qa1 = -1
  for i in range(da-1,-1,-1):
    if t[i] == qb:
      qb1 = i
      break
  for i in range(da-1,-1,-1):
    if t[i] == qa:
      qa1 = i
      break
  qb2 = d
  qa2 = d
  for i in range(da+1,d):
    if t[i] == qb:
      qb2 = i
      break
  for i in range(da+1,d):
    if t[i] == qa:
      qa2 = i
      break
  delta = -s[da][qb]+s[da][qa]-c[qb]*(qb2-da)*(da-qb1)+c[qa]*(qa2-da)*(da-qa1)
  if delta > -10000:
    t[da] = qa
    ans += delta
    if ans > mxans:
      mxans = ans
      mxt = copy.deepcopy(t)
  
for ansd in mxt:
  print(ansd+1)

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

D = i()
c = l()
C = sorted(c)
C.reverse()
rank = [0]*26
ans = [0]*D
for i in range(D):
    s = l()
    ans[i] = s.index(max(s))+1
for i in range(26):
    rank[i] = C.index(c[i])+1
for i in range(26):
    d = D//rank[i]
    for j in range(i,D,d):
        ans[j] = i+1
for i in ans:
    print(i)

Solution (Python):
def main():
    D = int(input())
    fuman = list(map(int, input().split()))
    manzoku = [[0]*26 for _ in range(D)]
    for i in range(D): manzoku[i] = list(map(int, input().split()))
    
    
    
    
    timepass = [0]*26
    
    x,t = 0,0
    for j in range(26):
        tmp = manzoku[i][j]
        for k in range(26):
            if not j==k: tmp -= fuman[k]*1
        if tmp>x:
            x = tmp
            t = j
    for j in range(26):
        if not j==t: timepass[j] += 1
        else: timepass[j] = 0
    print(t+1)
    for i in range(1,D):
        
        x1 = 0
        t1 = 0
        for j in range(26):
            tmp = manzoku[i][j]
            for k in range(26):
                if not j==k: tmp -= fuman[k]*timepass[k]
            if tmp>x1:
                x1 = tmp
                t1 = j

        
        for j in range(26):
            if not j==t1: timepass[j] += 1
            else: timepass[j] = 0
        print(t1+1)



main()

Solution (Python):
def examA():
    def calc_score(d,k):
        rep = C[k]*(d-used[k]) + S[d][k]
        return rep

    N = 26
    D = I()
    C = LI()
    S = [LI()for _ in range(D)]
    ans = 0
    T = [-1]*D
    used = [0]*N

    for d in range(D):
        s = -inf
        t = -1
        for i in range(N):
            cur = calc_score(d,i)
            if cur>s:
                s = cur
                t = i

        T[d] = t

        ans += S[d][t]
        used[t] = d + 1
        for j in range(N):
            ans -= C[j] * (d + 1 - used[j])


    def local_search(T0):
        def search(d, k):
            l = 0; r = D
            for i in range(d + 1, D):
                if T[i] == k:
                    r = i
                    break
            for i in range(0, d)[::-1]:
                if T[i] == k:
                    l = i + 1
                    break
            return l, r

        def calc_cost(d, k):
            return C[k] * (d + 1) * d // 2

        que = deque()
        que.append(T0)

        for _ in range(100000):
            T = que.pop()
            d = random.randint(0,D-1)

            old = deepcopy(T[d])
            change = -inf
            c = -1
            for q in range(N):
                if q==old:
                    continue
                T[d] = q

                old_l, old_r = search(d, old)
                new_l, new_r = search(d, q)

                cur = S[d][q] - S[d][old] \
                         - (calc_cost(old_r - old_l, old) - calc_cost(d - old_l, old) - calc_cost(old_r - d - 1, old)) \
                         + (calc_cost(new_r - new_l, q) - calc_cost(d - new_l, q) - calc_cost(new_r - d - 1, q))

                if cur>change:
                    change = cur
                    c = q

            if change>0:
                T[d] = c
                que.append(T)
            else:
                T[d] = old
                que.append(T)
                if len(que)>10:
                    continue
                j = random.randint(0,1000+N)
                if j>=1001:
                    T[d] = c
                    que.append(T)

        ans = -inf
        rep = []
        used = [0] * N
        while(que):
            cur = 0
            T = que.pop()
            for i in range(D):
                t = T[i]
                cur += S[i][t]
                used[t] = i + 1
                for j in range(N):
                    cur -= C[j] * (i + 1 - used[j])
            if cur>ans:
                rep = T
        return rep

    
    T = local_search(T)
    

    for t in T:
        print(t+1)

    return

def examB():
    N = 26
    D = I()
    C = LI()
    S = [LI()for _ in range(D)]
    T = [I()for _ in range(D)]
    ans = [0]*D
    used = [0]*N
    for i,t in enumerate(T):
        ans[i] += ans[i-1]
        t -= 1
        ans[i] += S[i][t]
        used[t] = i+1
        for j in range(N):
            ans[i] -= C[j]*(i+1-used[j])
    for v in ans:
        print(v)
    return

def examC():
    def calc_start():
        rep = [0] * D
        used = [0] * N
        for i, t in enumerate(T):
            rep[i] += rep[i - 1]
            rep[i] += S[i][t]
            used[t] = i + 1
            for j in range(N):
                rep[i] -= C[j] * (i + 1 - used[j])
        return rep

    def search(d,k):
        l = 0; r = D
        for i in range(d+1,D):
            if T[i]==k:
                r = i
                break
        for i in range(0,d)[::-1]:
            if T[i]==k:
                l = i + 1
                break
        return l, r

    def calc_cost(d,k):
        return C[k]*(d+1)*d//2

    N = 26
    D = I()
    C = LI()
    S = [LI()for _ in range(D)]
    T = [I()-1 for _ in range(D)]

    ans = calc_start()[D-1]

    

    M = I()
    for i in range(M):
        
        d, q = LI()
        d -= 1; q -= 1
        old = deepcopy(T[d])
        T[d] = q
        

        old_l, old_r = search(d,old)
        new_l, new_r = search(d,q)

        
        

        change = S[d][q] - S[d][old] \
                 - (calc_cost(old_r - old_l, old) - calc_cost(d-old_l, old) - calc_cost(old_r-d - 1, old))\
                 + (calc_cost(new_r - new_l, q) - calc_cost(d - new_l, q) - calc_cost(new_r - d - 1, q))

        ans += change

        print(ans)

    return


from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examA()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):
import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
import random
sys.setrecursionlimit(4100000)


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

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


class Schejule:

    def __init__(self, sche):
        self.base = sche
        self.last = [0] * 26
        self.y = 0

    def get_score(self):
        self.y = 0
        for d in range(D):
            self.y += S[d][self.base[d]]

        for d in range(D):
            self.last[self.base[d]] = d + 1

            for j in range(26):
                self.y -= C[j] * (d+1 - self.last[j])

    def change_one(self, day, to):

        org = self.base[day]

        
        div = 0

        
        div += S[day][to] - S[day][org]

        
        org_loss = 0
        cha_loss = 0

        org_last = 0
        cha_last = 0
        for d in range(D):
            if self.base[d] == org:
                org_last = d + 1
            elif self.base[d] == to:
                cha_last = d + 1

            org_loss +=  C[org] * (d+1 - org_last)
            cha_loss +=  C[to ] * (d+1 - cha_last)

        def_loss = cha_loss + org_loss


        org_loss = 0
        cha_loss = 0

        org_last = 0
        cha_last = 0
        for d in range(D):
            if d != day:
                if self.base[d] == org:
                    org_last = d + 1
                elif self.base[d] == to:
                    cha_last = d + 1
            else:
                cha_last = d+1

            org_loss +=  C[org] * (d+1 - org_last)
            cha_loss +=  C[to ] * (d+1 - cha_last)

        aft_loss = cha_loss + org_loss


        
        div -= aft_loss - def_loss

        
        if div > 0 or random.randint(0, 9) >= 4:
            next_plan = self.base
            next_plan[day] = to

            sche_next = Schejule(next_plan)
            sche_next.y = self.y + div

            return sche_next
        else:
            return self



T = [0] * D

for i in range(D):
    max_day = 0
    for j in range(26):
        if S[i][max_day] < S[i][j]:
            max_day = j
    T[i] = max_day


sche_base = Schejule(T)
sche_base.get_score()


best_score = sche_base.y
best_set = sche_base.base.copy()





for i in range(1000):
    d = random.randint(0, D - 1)
    t = random.randint(0, 26 - 1)

    sche_base  = sche_base.change_one(d, t)

    if best_score < sche_base.y:
        best_score = sche_base.y
        best_set = sche_base.base.copy()
        

    
    
    
    

    

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

Solution (Python):
import random

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

plus=0
minus=0
data=[[1 for i in range(D)] for j in range(26)]
ans=[0]*D
for i in range(D):
    t=random.randint(1,26)
    ans[i]=t
    plus+=s[i][t-1]
    if i!=0:
        for j in range(26):
            data[j][i]=data[j][i-1]+1
    data[t-1][i]=0
    minus+=sum(c[j]*data[j][i] for j in range(26))

eval=plus-minus
count=1200000
check=[]
while count:
    d=random.randint(2,D)
    q=random.randint(1,26)
    if ans[d-1]==q:
        continue
    if c[ans[d-1]-1]*data[ans[d-1]-1][d-2]>c[q-1]*data[q-1][d-2] or s[d-1][q-1]>s[d-1][ans[d-1]-1]:
        testplus=plus+s[d-1][q-1]-s[d-1][ans[d-1]-1]
        testminus=minus
        pre=ans[d-1]
        

        day=0
        for j in range(d-1,D):
            if data[q-1][j]!=0:
                if j==d-1:
                    testminus+=day*c[q-1]-data[q-1][d-1]*c[q-1]
                else:
                    testminus+=(day+1-data[q-1][j])*c[q-1]
                    day+=1
            else:
                break

        day=0
        for j in range(d-1,D):
            if j==d-1:
                if j==0:
                    day=1
                    testminus+=c[pre-1]*day
                else:
                    day=1+data[pre-1][j-1]
                    testminus+=c[pre-1]*day
            elif data[pre-1][j]!=0:
                testminus+=(day+1-data[pre-1][j])*c[pre-1]
                day+=1
            else:
                break

        if testplus-testminus>eval:
            eval=testplus-testminus
            plus=testplus
            minus=testminus
            ans[d-1]=q
            for j in range(d-1,D):
                if data[q-1][j]!=0:
                    if j==d-1:
                        data[q-1][d-1]=0
                    else:
                        data[q-1][j]=data[q-1][j-1]+1
                else:
                    break

            for j in range(d-1,D):
                if j==d-1:
                    if j==0:
                        data[pre-1][j]=1
                    else:
                        data[pre-1][j]=1+data[pre-1][j-1]
                elif data[pre-1][j]!=0:
                    data[pre-1][j]=data[pre-1][j-1]+1
                else:
                    break

    else:
        continue

    count-=1
check.sort(reverse=True)
if check:
    if check[0][0]>eval:
        
        for i in range(1,D+1):
            print(check[0][i])
    else:
        
        for i in range(D):
            print(ans[i])
else:
    
    for i in range(D):
        print(ans[i])

Solution (Python):
import random

random.seed(1)

def calc_point(point_list, interval, choice):
    point = 0

    for i, day in enumerate(interval):
        point -= c[i] * day

    point += point_list[choice - 1]

    return point

d = int(input())

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

s = []

for _ in range(d):
    temp = list(map(int,input().split()))

    s.append(temp)

choices = [(i % 26) + 1 for i in range(d)]

interval = [0] * 26
result = 0

for i in range(d):
    choice = choices[i]

    interval = [x + 1 for x in interval]

    interval[choice - 1] = 0

    result += calc_point(s[i], interval, choice)

for _ in range(10000):
    temp_choices = choices.copy()
    temp_result = 0

    temp_choices[random.randint(0, d - 1)] = random.randint(1, 26)

    interval = [0] * 26
    
    for i in range(d):
        choice = temp_choices[i]

        interval = [x + 1 for x in interval]

        interval[choice - 1] = 0

        temp_result += calc_point(s[i], interval, choice)

    if temp_result > result:
        choices = temp_choices
        result = temp_result

for choice in choices:
    print(choice)

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

cl = sum(c)
D = [0]*26
ans = [0]*d
T = [0]*d

for i in range(d):
    count = 0
    for j in range(26):
        D[j] += 1
    for j in range(26):
        sas = 0
        S = s[i][j]
        C = c[j]
        Ds = copy.copy(D)
        Ds[j] = 0
        dc = 0
        for k in range(26):
            dc += Ds[k]*c[k]
        sas = S - dc + sum(T[:i])
        if sas > count:
            count = sas
            ans[i] = j+1
            T[i] = count

for i in ans:
    print(i)

Solution (Python):

def choose(D, c, s, d, last, depth, p):
    maxpoint = -999999
    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)
            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, 1, 0)
        print(num+1)


main()