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):
def yumiri(L, n):
  for i in range(len(L)):
    if L[i] > n:
      return i - 1

def parunyasu(a, b, p, q):
  reans = ans
  rd1, rq1, d1, nd1, nq1, q1, newans = naobou(a, q, reans)
  rd2, rq2, d2, nd2, nq2, q2, newans = naobou(b, p, newans)

  if reans <= newans:
    t[d1 - 1] = q1
    t[d2 - 1] = q2
    return newans
  else:
    ayaneru(rd2, rq2, d2, nd2, nq2)
    ayaneru(rd1, rq1, d1, nd1, nq1)
    return reans

def ayaneru(rd, rq, d, nd, nq):
  ZL[rd].insert(rq, d)
  del ZL[nd][nq + 1]

def naobou(d, q, ans):
  newans = ans

  rd = t[d - 1] - 1
  rq = yumiri(ZL[rd], d)
  newans += SUMD[ZL[rd][rq] - ZL[rd][rq - 1] - 1] * c[rd]
  newans += SUMD[ZL[rd][rq + 1] - ZL[rd][rq] - 1] * c[rd]
  newans -= SUMD[ZL[rd][rq + 1] - ZL[rd][rq - 1] - 1] * c[rd] 
  del ZL[rd][rq]

  nd = q - 1
  nq = yumiri(ZL[nd], d)
  newans += SUMD[ZL[nd][nq + 1] - ZL[nd][nq] - 1] * c[nd]
  newans -= SUMD[d - ZL[nd][nq] - 1] * c[nd]
  newans -= SUMD[ZL[nd][nq + 1] - d - 1] * c[nd]
  ZL[nd].insert(nq + 1, d)

  newans -= s[d - 1][rd]
  newans += s[d - 1][nd]

  return rd, rq, d, nd, nq, q, newans

def rieshon():
  ans = 0
  for i in range(D):
    ans += s[i][t[i] - 1]
    for j in range(26):
      if t[i] - 1 == j:
        L[j] = 0
        ZL[j].append(i + 1)
      else:
        L[j] += 1
        ans -= L[j] * c[j]
  for i in range(26):
    ZL[i].append(D + 1)
  return ans

import time
import random
startTime = time.time()

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

L = [0] * 26
ZL = [[0] for _ in range(26)]
SUMD = [0] * (D + 1)
for i in range(1, D + 1):
  SUMD[i] = SUMD[i - 1] + i

RD = [0] * 26
t = [0] * D
for i in range(D):
  RD[0] += 1
  ma = s[i][0] + RD[0] * c[0]
  man = 0
  for j in range(1, 26):
    RD[j] += 1
    k = s[i][j] + RD[j] * c[j]
    if k > ma:
      ma = k
      man = j
  t[i] = man + 1
  RD[man] = 0

ans = rieshon()
while time.time() - startTime < 1.8:
  l = random.randrange(min(D - 1, 13)) + 1
  d = random.randrange(D - l) + 1
  p = t[d - 1]
  q = t[d + l - 1]
  if p == q: continue
  ans = parunyasu(d, d + l, p, q)

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

Solution (Python):
def yumiri(L, n):
  for i in range(len(L)):
    if L[i] > n:
      return i - 1

def parunyasu(a, b, p, q):
  reans = ans
  rd1, rq1, d1, nd1, nq1, q1, newans = naobou(a, q, reans)
  rd2, rq2, d2, nd2, nq2, q2, newans = naobou(b, p, newans)

  if reans <= newans:
    t[d1 - 1] = q1
    t[d2 - 1] = q2
    return newans
  else:
    ayaneru(rd2, rq2, d2, nd2, nq2)
    ayaneru(rd1, rq1, d1, nd1, nq1)
    return reans

def ayaneru(rd, rq, d, nd, nq):
  ZL[rd].insert(rq, d)
  del ZL[nd][nq + 1]

def naobou(d, q, ans):
  newans = ans

  rd = t[d - 1] - 1
  rq = yumiri(ZL[rd], d)
  newans += SUMD[ZL[rd][rq] - ZL[rd][rq - 1] - 1] * c[rd]
  newans += SUMD[ZL[rd][rq + 1] - ZL[rd][rq] - 1] * c[rd]
  newans -= SUMD[ZL[rd][rq + 1] - ZL[rd][rq - 1] - 1] * c[rd] 
  del ZL[rd][rq]

  nd = q - 1
  nq = yumiri(ZL[nd], d)
  newans += SUMD[ZL[nd][nq + 1] - ZL[nd][nq] - 1] * c[nd]
  newans -= SUMD[d - ZL[nd][nq] - 1] * c[nd]
  newans -= SUMD[ZL[nd][nq + 1] - d - 1] * c[nd]
  ZL[nd].insert(nq + 1, d)

  newans -= s[d - 1][rd]
  newans += s[d - 1][nd]

  return rd, rq, d, nd, nq, q, newans

def rieshon():
  ans = 0
  for i in range(D):
    ans += s[i][t[i] - 1]
    for j in range(26):
      if t[i] - 1 == j:
        L[j] = 0
        ZL[j].append(i + 1)
      else:
        L[j] += 1
        ans -= L[j] * c[j]
  for i in range(26):
    ZL[i].append(D + 1)
  return ans

import time
import random
startTime = time.time()

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

L = [0] * 26
ZL = [[0] for _ in range(26)]
SUMD = [0] * (D + 1)
for i in range(1, D + 1):
  SUMD[i] = SUMD[i - 1] + i

RD = [0] * 26
t = [0] * D
for i in range(D):
  RD[0] += 1
  ma = s[i][0] + RD[0] * c[0]
  man = 0
  for j in range(1, 26):
    RD[j] += 1
    k = s[i][j] + RD[j] * c[j]
    if k > ma:
      ma = k
      man = j
  t[i] = man + 1
  RD[man] = 0

ans = rieshon()
while time.time() - startTime < 1.8:
  l = random.randrange(min(D - 1, 26)) + 1
  d = random.randrange(D - l) + 1
  p = t[d - 1]
  q = t[d + l - 1]
  if p == q: continue
  ans = parunyasu(d, d + l, p, q)

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

Solution (Python):
from time import time
start=time()
from copy import deepcopy
from random import randint

d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
    a=list(map(int,input().split()))
    s.append(a)

def score_calculator(l):
    score=0
    las=[0]*26
    for i in range(d):
        for j in range(26):
            las[j]+=1
        las[l[i]]=0
        for j in range(26):
            score-=las[j]*c[j]
        score+=s[i][l[i]]
    return score
    
highest_sum_score=-1000000000000

for i in range(1,13):
    last=[0]*26
    temp_ans_lst=[]
    for j in range(d):
        daily_highest_score=-10000000000000
        for k in range(26):
            temp_score=s[j][k]
            temp_last=deepcopy(last)
            for p in range(26):
                temp_last[p]+=1
            temp_last[k]=0
            for p in range(26):
                down=temp_last[p]
                for q in range(i):
                    qdown=down+i+1
                    down+=qdown
                temp_score-=down*c[p]
            if temp_score>daily_highest_score:
                daily_highest_score=temp_score
                daily_choice=k
        for k in range(26):
            last[k]+=1
        last[daily_choice]=0
        temp_ans_lst.append(daily_choice)
    if score_calculator(temp_ans_lst)>highest_sum_score:
        ans_lst=deepcopy(temp_ans_lst)
        highest_sum_score=score_calculator(temp_ans_lst)
        
while time()-start<1.9:
    a=randint(0,d-1)
    b=randint(0,25)
    temp_ans_lst=deepcopy(ans_lst)
    temp_ans_lst[a]=b
    if score_calculator(temp_ans_lst)>highest_sum_score:
        ans_lst=deepcopy(temp_ans_lst)
        highest_sum_score=score_calculator(temp_ans_lst)

for i in ans_lst:
    print(i+1)

Solution (Python):
from time import time
start=time()
from copy import deepcopy
from random import randint

d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
    a=list(map(int,input().split()))
    s.append(a)

def score_calculator(l):
    score=0
    las=[0]*26
    for i in range(d):
        for j in range(26):
            las[j]+=1
        las[l[i]]=0
        for j in range(26):
            score-=las[j]*c[j]
        score+=s[i][l[i]]
    return score
    
highest_sum_score=-1000000000000

for i in range(1,13):
    last=[0]*26
    temp_ans_lst=[]
    for j in range(d):
        daily_highest_score=-10000000000000
        for k in range(26):
            temp_score=s[j][k]
            temp_last=deepcopy(last)
            for p in range(26):
                temp_last[p]+=1
            temp_last[k]=0
            for p in range(26):
                down=temp_last[p]
                for q in range(i):
                    qdown=down+i+1
                    down+=qdown
                temp_score-=down*c[p]
            if temp_score>daily_highest_score:
                daily_highest_score=temp_score
                daily_choice=k
        for k in range(26):
            last[k]+=1
        last[daily_choice]=0
        temp_ans_lst.append(daily_choice)
    if score_calculator(temp_ans_lst)>highest_sum_score:
        ans_lst=deepcopy(temp_ans_lst)
        highest_sum_score=score_calculator(temp_ans_lst)
        
while time()-start<1.9:
    a=randint(0,d-2)
    temp_ans_lst=deepcopy(ans_lst)
    temp_ans_lst[a],temp_ans_lst[a+1]=temp_ans_lst[a+1],temp_ans_lst[a]
    if score_calculator(temp_ans_lst)>highest_sum_score:
        ans_lst=deepcopy(temp_ans_lst)
        highest_sum_score=score_calculator(temp_ans_lst)

for i in ans_lst:
    print(i+1)

Solution (Python):
def solve(d,c,s,k):
    last=[0]*27
    srate=[]
    ans=[]
    for i in range(1,d+1):
        a=0
        for j in range(1,27):
            a-=c[j-1]*(i-last[j])
        pa=0
        mlast=[0]*2
        for t in range(1,27):
            if s[i-1][t-1]+c[t-1]*(min(k*(k-1)/2,(366-d)*((366-d)-1)/2))>pa:
                mlast=[t,i]
                pa=s[i-1][t-1]+c[t-1]*(i-last[t])
        a+=pa
        last[mlast[0]]=mlast[1]           
        ans.append(mlast[0])
        srate.append(a)
    return [srate[-1]]+ans

def main():
    d=int(input())
    c=list(map(int,input().split()))
    s=[list(map(int,input().split())) for _ in range(d)]
    ans=[]
    for i in range(26):
        ans.append(solve(d,c,s,i))
    ans.sort(reverse=True)
    for i in ans[0][1:]:
        print(i)
    

if __name__ == '__main__':
    main()

Solution (Python):
def yumiri(L, n):
  for i in range(len(L)):
    if L[i] > n:
      return i - 1

def parunyasu(a, b, p, q):
  reans = ans
  rd1, rq1, d1, nd1, nq1, q1, _ = naobou(a, q)
  rd2, rq2, d2, nd2, nq2, q2, newans = naobou(b, p)

  if reans <= newans:
    t[d1 - 1] = q1
    t[d2 - 1] = q2
    return newans
  else:
    ayaneru(rd2, rq2, d2, nd2, nq2)
    ayaneru(rd1, rq1, d1, nd1, nq1)
    return reans

def ayaneru(rd, rq, d, nd, nq):
  ZL[rd].insert(rq, d)
  del ZL[nd][nq + 1]

def naobou(d, q):
  newans = ans

  rd = t[d - 1] - 1
  rq = yumiri(ZL[rd], d)
  newans += SUMD[ZL[rd][rq] - ZL[rd][rq - 1] - 1] * c[rd]
  newans += SUMD[ZL[rd][rq + 1] - ZL[rd][rq] - 1] * c[rd]
  newans -= SUMD[ZL[rd][rq + 1] - ZL[rd][rq - 1] - 1] * c[rd] 
  del ZL[rd][rq]

  nd = q - 1
  nq = yumiri(ZL[nd], d)
  newans += SUMD[ZL[nd][nq + 1] - ZL[nd][nq] - 1] * c[nd]
  newans -= SUMD[d - ZL[nd][nq] - 1] * c[nd]
  newans -= SUMD[ZL[nd][nq + 1] - d - 1] * c[nd]
  ZL[nd].insert(nq + 1, d)

  newans -= s[d - 1][rd]
  newans += s[d - 1][nd]

  return rd, rq, d, nd, nq, q, newans

def rieshon():
  ans = 0
  for i in range(D):
    ans += s[i][t[i] - 1]
    for j in range(26):
      if t[i] - 1 == j:
        L[j] = 0
        ZL[j].append(i + 1)
      else:
        L[j] += 1
        ans -= L[j] * c[j]
  for i in range(26):
    ZL[i].append(D + 1)
  return ans

import time
import random
startTime = time.time()

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

L = [0] * 26
ZL = [[0] for _ in range(26)]
SUMD = [0] * (D + 1)
for i in range(1, D + 1):
  SUMD[i] = SUMD[i - 1] + i

RD = [0] * 26
t = [0] * D
for i in range(D):
  RD[0] += 1
  ma = s[i][0] + RD[0] * c[0]
  man = 0
  for j in range(1, 26):
    RD[j] += 1
    k = s[i][j] + RD[j] * c[j]
    if k > ma:
      ma = k
      man = j
  t[i] = man + 1
  RD[man] = 0

ans = rieshon()
while time.time() - startTime < 1.8:
  l = random.randrange(min(D - 1, 26)) + 1
  d = random.randrange(D - l) + 1
  p = t[d - 1]
  q = t[d + l - 1]
  if p == q: continue
  ans = parunyasu(d, d + l, p, q)

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

Solution (Python):
from copy import deepcopy

d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
    a=list(map(int,input().split()))
    s.append(a)

def score_calculator(l):
    score=0
    las=[0]*26
    for i in range(d):
        for j in range(26):
            las[j]+=1
        las[l[i]]=0
        for j in range(26):
            score-=las[j]*c[j]
        score+=s[i][l[i]]
    return score
    
highest_sum_score=-1000000000000

for i in range(1,26):
    last=[0]*26
    temp_ans_lst=[]
    for j in range(d):
        daily_highest_score=-10000000000000
        for k in range(26):
            temp_score=s[j][k]
            temp_last=deepcopy(last)
            for p in range(26):
                temp_last[p]+=1
            temp_last[k]=0
            for p in range(26):
                down=temp_last[p]
                for q in range(i):
                    qdown=down+i+1
                    down+=qdown
                temp_score-=down*c[p]
            if temp_score>daily_highest_score:
                daily_highest_score=temp_score
                daily_choice=k
        for k in range(26):
            last[k]+=1
        last[daily_choice]=0
        temp_ans_lst.append(daily_choice)
    if score_calculator(temp_ans_lst)>highest_sum_score:
        ans_lst=deepcopy(temp_ans_lst)
        highest_sum_score=score_calculator(temp_ans_lst)
        
for i in ans_lst:
    print(i+1)

Solution (Python):
from copy import deepcopy

d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
    a=list(map(int,input().split()))
    s.append(a)

def score_calculator(l):
    score=0
    las=[0]*26
    for i in range(d):
        for j in range(26):
            las[j]+=1
        las[l[i]]=0
        for j in range(26):
            score-=las[j]*c[j]
        score+=s[i][l[i]]
    return score

for i in range(1,26):
    highest_sum_score=-1000000000000
    last=[0]*26
    temp_ans_lst=[]
    for j in range(d):
        daily_highest_score=-10000000000000
        for k in range(26):
            temp_score=s[j][k]
            temp_last=deepcopy(last)
            for p in range(26):
                temp_last[p]+=1
            temp_last[k]=0
            for p in range(26):
                down=temp_last[p]
                for q in range(i):
                    qdown=down+i+1
                    down+=qdown
                temp_score-=down*c[p]
            if temp_score>daily_highest_score:
                daily_highest_score=temp_score
                daily_choice=k
        for k in range(26):
            last[k]+=1
        last[daily_choice]=0
        temp_ans_lst.append(daily_choice)
    if score_calculator(temp_ans_lst)>highest_sum_score:
        ans_lst=deepcopy(temp_ans_lst)
        
for i in ans_lst:
    print(i+1)

Solution (Python):


import numpy as np
d= int(input())
 
C = list(map(int,input().split()))
CB = [0 for i in range(len(C))]
 
c = sum(C)
 
total = 0
 

L = []
 
for i in range(d):
    L.append(list(map(int,input().split())))
 

 
 

 
def cnt(CB,t):
    for i in range(len(CB)):
        if i != t:
            CB[i] += 1
        else:
            CB[i] = 0
    
    return CB
 
def sumA(C,CB):
    a = 0
    for i in range(len(CB)):
        a += CB[i]*C[i]
    return a
 
def check(L,C,CB):
    a = L[0]+CB[0]*C[0]
    r = 0
    for i in range(len(CB)):
        if a < L[i]+CB[i]*C[i]:
            r = i
    return r
 
for i in range(d):
    



    
    ind = i%26
    CB = cnt(CB,ind)
    total += L[i][ind] - sumA(C,CB)


    print(ind+1)

Solution (Python):
from copy import deepcopy

d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
    a=list(map(int,input().split()))
    s.append(a)

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

for i in range(1,26):
    highest_sum_score=-1000000000000
    last=[0]*26
    temp_ans_lst=[]
    for j in range(d):
        daily_highest_score=-10000000000000
        for k in range(26):
            temp_score=s[j][k]
            temp_last=deepcopy(last)
            for p in range(26):
                temp_last[p]+=1
            temp_last[k]=0
            for p in range(26):
                down=temp_last[p]
                for q in range(i):
                    qdown=down+i+1
                    down+=qdown
                temp_score-=down*c[p]
            if temp_score>daily_highest_score:
                daily_highest_score=temp_score
                daily_choice=k
        temp_ans_lst.append(daily_choice)
    if score_calculator(temp_ans_lst)>highest_sum_score:
        ans_lst=temp_ans_lst
        
for i in ans_lst:
    print(i+1)

Solution (Python):
import time
start = time.time()


import random
from typing import List


def score_by_simple_method(schedule, loss_list, satisfied_matrix):
    prev_list = [-1] * 26
    plus = 0
    minus = 0
    for day, open_contest in enumerate(schedule):
        prev_list[open_contest] = day
        plus += satisfied_matrix[day][open_contest]

        for contest, prev_day in enumerate(prev_list):
            spend = day - prev_day
            loss_base = loss_list[contest]
            minus += loss_base * spend

    return plus - minus


def schedule_to_dict(schedule, days):
    dict = {contest: [-1] for contest in range(26)}
    for day, contest in enumerate(schedule):
        dict[contest].append(day)

    for contest in range(26):
        dict[contest].appned(days)

    return dict


class Node:
    def __init__(self, contest, last_day):
        self.contest = contest
        self.prev_day = -1
        self.next_day = last_day


def schedule_to_linked(schedule, last_day):
    linked_schedule = []
    prev_list = [-1] * 26
    for day, contest in enumerate(schedule):
        cur_node = Node(contest, last_day)
        prev_day = prev_list[contest]
        cur_node.prev_day = prev_day
        if prev_day != -1:
            prev_node = linked_schedule[prev_day]
            prev_node.next_day = day

        prev_list[contest] = day
        linked_schedule.append(cur_node)

    return linked_schedule


def is_exchangeable(day1, day2, linked_schedule: List[Node]):
    """
    swap先が同じコンテストの時 False
    swap先が同コンテストの前後開催を超えている場合 False
    ex. schedule: [1, 2, 3, 4, 3, 5, 6]
        swap target:     ^        ^
    day1 = 2 (0-indexed)
    day2 = 5
    schedule[day1].next = 4

    """

    if linked_schedule[day1].contest == linked_schedule[day2].contest:
        return False

    node1 = linked_schedule[day1]
    node1_prev = node1.prev_day
    node1_next = node1.next_day

    if day2 < node1_prev or node1_next < day2:
        return False

    node2 = linked_schedule[day2]
    node2_prev = node2.prev_day
    node2_next = node2.next_day

    if day1 < node2_prev or node2_next < day1:
        return False

    return True


def swap_contests_in_linked_schedule(day1, day2, linked_schedule: List[Node], last_day):
    node1 = linked_schedule[day1]
    node1_prev = node1.prev_day
    node1_next = node1.next_day

    node2 = linked_schedule[day2]
    node2_prev = node2.prev_day
    node2_next = node2.next_day

    linked_schedule[day1], linked_schedule[day2] = linked_schedule[day2], linked_schedule[day1]  

    if node1_prev != -1:
        linked_schedule[node1_prev].next_day = day2
    if node1_next != last_day:
        linked_schedule[node1_next].prev_day = day2

    if node2_prev != -1:
        linked_schedule[node2_prev].next_day = day1
    if node2_next != last_day:
        linked_schedule[node2_next].prev_day = day1


def calc_score_change_by_shift(contest, prev, before_center, after_center, next, loss_list, satisfied_matrix):
    loss_base = loss_list[contest]
    before_spend1 = before_center - prev
    before_spend2 = next - before_center
    before_loss = loss_base * (before_spend1 * (before_spend1-1) + before_spend2 * (before_spend2-1)) // 2
    before_get = satisfied_matrix[before_center][contest]
    before_score = before_get - before_loss

    after_spend1 = after_center - prev
    after_spend2 = next - after_center
    after_loss = loss_base * (after_spend1 * (after_spend1-1) + after_spend2 * (after_spend2-1)) // 2
    after_get = satisfied_matrix[after_center][contest]
    after_score = after_get - after_loss

    score_change = after_score - before_score
    return score_change


def calc_score_change_by_swap(day1, day2, linked_schedule: List[Node], loss_list, satisfied_matrix):
    node1 = linked_schedule[day1]
    change_score1 = calc_score_change_by_shift(node1.contest, node1.prev_day, day1, day2, node1.next_day, loss_list, satisfied_matrix)
    node2 = linked_schedule[day2]
    change_score2 = calc_score_change_by_shift(node2.contest, node2.prev_day, day2, day1, node2.next_day, loss_list, satisfied_matrix)

    return change_score1 + change_score2


days = int(input())
loss_list = list(map(int, input().split()))
satisfied_matrix = [list(map(int, input().split())) for _ in range(days)]
schedule = [i % 26 for i in range(days)]
linked_schedule = schedule_to_linked(schedule, days)
base_score = score_by_simple_method(schedule, loss_list, satisfied_matrix)

loops = 0
while time.time() - start < 1.8:
    loops += 1
    day1 = random.randint(0, days - 25)
    swap = []
    best = 0
    for day2 in range(day1+1, day1+25):
        if is_exchangeable(day1, day2, linked_schedule):
            change_score = calc_score_change_by_swap(day1, day2, linked_schedule, loss_list, satisfied_matrix)

            if change_score > best:
                swap = [day1, day2]
                best = change_score

    if swap:
        day1, day2 = swap
        swap_contests_in_linked_schedule(day1, day2, linked_schedule, days)
        base_score += best


ans = [node.contest + 1 for node in linked_schedule]
print(*ans, sep="\n")

Solution (Python):
def yumiri(L, n):
  for i in range(len(L)):
    if L[i] > n:
      return i - 1

def parunyasu(a, b, p, q):
  reans = ans
  rd1, rq1, d1, nd1, nq1, q1, _ = naobou(a, q)
  rd2, rq2, d2, nd2, nq2, q2, newans = naobou(b, p)

  if reans <= newans:
    t[d1 - 1] = q1
    t[d2 - 1] = q2
    return newans
  else:
    ayaneru(rd2, rq2, d2, nd2, nq2)
    ayaneru(rd1, rq1, d1, nd1, nq1)
    return reans

def ayaneru(rd, rq, d, nd, nq):
  ZL[rd].insert(rq, d)
  del ZL[nd][nq + 1]

def naobou(d, q):
  newans = ans

  rd = t[d - 1] - 1
  rq = yumiri(ZL[rd], d)
  newans += SUMD[ZL[rd][rq] - ZL[rd][rq - 1] - 1] * c[rd]
  newans += SUMD[ZL[rd][rq + 1] - ZL[rd][rq] - 1] * c[rd]
  newans -= SUMD[ZL[rd][rq + 1] - ZL[rd][rq - 1] - 1] * c[rd] 
  del ZL[rd][rq]

  nd = q - 1
  nq = yumiri(ZL[nd], d)
  newans += SUMD[ZL[nd][nq + 1] - ZL[nd][nq] - 1] * c[nd]
  newans -= SUMD[d - ZL[nd][nq] - 1] * c[nd]
  newans -= SUMD[ZL[nd][nq + 1] - d - 1] * c[nd]
  ZL[nd].insert(nq + 1, d)

  newans -= s[d - 1][rd]
  newans += s[d - 1][nd]

  return rd, rq, d, nd, nq, q, ans

def rieshon():
  ans = 0
  for i in range(D):
    ans += s[i][t[i] - 1]
    for j in range(26):
      if t[i] - 1 == j:
        L[j] = 0
        ZL[j].append(i + 1)
      else:
        L[j] += 1
        ans -= L[j] * c[j]
  for i in range(26):
    ZL[i].append(D + 1)
  return ans

import time
import random
startTime = time.time()

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

L = [0] * 26
ZL = [[0] for _ in range(26)]
SUMD = [0] * (D + 1)
for i in range(1, D + 1):
  SUMD[i] = SUMD[i - 1] + i

RD = [0] * 26
t = [0] * D
for i in range(D):
  RD[0] += 1
  ma = s[i][0] + RD[0] * c[0]
  man = 0
  for j in range(1, 26):
    RD[j] += 1
    k = s[i][j] + RD[j] * c[j]
    if k > ma:
      ma = k
      man = j
  t[i] = man + 1
  RD[man] = 0

ans = rieshon()
while time.time() - startTime < 1.8:
  l = random.randrange(min(D - 1, 26)) + 1
  d = random.randrange(D - l) + 1
  p = t[d - 1]
  q = t[d + l - 1]
  if p == q: continue
  ans = parunyasu(d, d + l, p, q)

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

Solution (Python):
import random
import time
import copy

t1=time.time()
d=int(input())
c=input()
cl=[int(n) for n in c.split()]
sl=list()
for i in range(d):
    s=input()
    sl=sl+[int(n) for n in s.split()]
tl=list()
for i in range(d):
    tl.append(random.randint(1,26))
sat=0
for i in range(d):
    sat+=sl[i*26+tl[i]-1]
last=list()
for i in range(26):
    last.append([a for a, x in enumerate(tl) if x==i+1])
dec=0
for i in range(26):
    if last[i]==list():
        dec+=(d*(d+1)/2)*cl[i]
    else:
        for v in range(len(last[i])):
            if v!=len(last[i])-1:    
                dec+=cl[i]*(last[i][v+1]-last[i][v]-1)*(last[i][v+1]-last[i][v])/2
            else:
                dec+=cl[i]*(d-last[i][v]-1)*(d-last[i][v])/2
        dec+=cl[i]*(last[i][0])*(last[i][0]+1)/2
        
def dechf(c,last):
    decha=0
    if last[c]==list():
        decha+=(d*(d+1)/2)*cl[c]
    else:
        for v in range(len(last[c])):
            if v!=len(last[c])-1:    
                decha+=cl[c]*(last[c][v+1]-last[c][v]-1)*(last[c][v+1]-last[c][v])/2
            else:
                decha+=cl[c]*(d-last[c][v]-1)*(d-last[c][v])/2
        decha+=cl[c]*(last[c][0])*(last[c][0]+1)/2
    return(int(decha))


oldlast=copy.deepcopy(last)
oldans=sat-int(dec)
oldtl=copy.copy(tl)
t2=time.time()
newans=0
while t2-t1<1.85:
    if round(t2)%2==0:
        d1=random.randint(1,d)
        d2=random.randint(1,d)
        if d1==d2:
            continue
        q1=tl[d2-1]
        q2=tl[d1-1]
        cha=sl[(d1-1)*26+q1-1]-sl[(d1-1)*26+tl[d1-1]-1]+sl[(d2-1)*26+q2-1]-sl[(d2-1)*26+tl[d2-1]-1]
        c=tl[d1-1]-1
        dech=dechf(c,last)
        c=tl[d2-1]-1
        dech+=dechf(c,last)
        last[tl[d2-1]-1].remove(d2-1)
        last[tl[d1-1]-1].remove(d1-1)
        last[tl[d1-1]-1].append(d2-1)
        last[tl[d1-1]-1].sort()
        last[tl[d2-1]-1].append(d1-1)
        last[tl[d2-1]-1].sort()
        tl[d2-1]=q2
        tl[d1-1]=q1
        c=tl[d1-1]-1
        dech-=dechf(c,last)
        c=tl[d2-1]-1
        dech-=dechf(c,last)
        newans=oldans+cha+dech
    else:
        da=random.randint(1,d)
        q=random.randint(1,26)
        cha=sl[(da-1)*26+q-1]-sl[(da-1)*26+tl[da-1]-1]
        c=tl[da-1]-1
        dech=dechf(c,last)
        c=q-1
        dech+=dechf(c,last)
        last[tl[da-1]-1].remove(da-1)
        last[q-1].append(da-1)
        last[q-1].sort()
        c=tl[da-1]-1
        dech-=dechf(c,last)
        tl[da-1]=q
        c=tl[da-1]-1
        dech-=dechf(c,last)
        newans=oldans+cha+dech
    r=0
    if newans<oldans:
        if 2.7**((newans-oldans)/(1.85-(t2-t1)))<random.random():
            r=1
    if r==1:
        tl=copy.copy(oldtl)
        last=[i[:] for i in oldlast]
    else:
        oldans=newans
        oldtl=copy.copy(tl)
        oldlast=[i[:] for i in last]
    t2=time.time()
for i in range(d):
    print(tl[i])

Solution (Python):
def yumiri(L, n):
  for i in range(len(L)):
    if L[i] > n:
      return i - 1

def parunyasu(a, b, p, q):
  reans = ans
  rd1, rq1, d1, nd1, nq1, q1, _ = naobou(a, q)
  rd2, rq2, d2, nd2, nq2, q2, newans = naobou(b, p)

  if reans < newans:
    t[d1 - 1] = q1
    t[d2 - 1] = q2
    return newans
  else:
    ayaneru(rd2, rq2, d2, nd2, nq2)
    ayaneru(rd1, rq1, d1, nd1, nq1)
    return ans

def ayaneru(rd, rq, d, nd, nq):
  ZL[rd].insert(rq, d)
  del ZL[nd][nq + 1]

def naobou(d, q):
  newans = ans

  rd = t[d - 1] - 1
  rq = yumiri(ZL[rd], d)
  newans += SUMD[ZL[rd][rq] - ZL[rd][rq - 1] - 1] * c[rd]
  newans += SUMD[ZL[rd][rq + 1] - ZL[rd][rq] - 1] * c[rd]
  newans -= SUMD[ZL[rd][rq + 1] - ZL[rd][rq - 1] - 1] * c[rd] 
  del ZL[rd][rq]

  nd = q - 1
  nq = yumiri(ZL[nd], d)
  newans += SUMD[ZL[nd][nq + 1] - ZL[nd][nq] - 1] * c[nd]
  newans -= SUMD[d - ZL[nd][nq] - 1] * c[nd]
  newans -= SUMD[ZL[nd][nq + 1] - d - 1] * c[nd]
  ZL[nd].insert(nq + 1, d)

  newans -= s[d - 1][rd]
  newans += s[d - 1][nd]

  return rd, rq, d, nd, nq, q, ans

def rieshon():
  ans = 0
  for i in range(D):
    ans += s[i][t[i] - 1]
    for j in range(26):
      if t[i] - 1 == j:
        L[j] = 0
        ZL[j].append(i + 1)
      else:
        L[j] += 1
        ans -= L[j] * c[j]
  for i in range(26):
    ZL[i].append(D + 1)
  return ans

import time
import random
startTime = time.time()

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

L = [0] * 26
ZL = [[0] for _ in range(26)]
SUMD = [0] * (D + 1)
for i in range(1, D + 1):
  SUMD[i] = SUMD[i - 1] + i

RD = [0] * 26
t = [0] * D
for i in range(D):
  RD[0] += 1
  ma = s[i][0] + RD[0] * c[0]
  man = 0
  for j in range(1, 26):
    RD[j] += 1
    k = s[i][j] + RD[j] * c[j]
    if k > ma:
      ma = k
      man = j
  t[i] = man + 1
  RD[man] = 0

ans = rieshon()
while time.time() - startTime < 1.8:
  l = random.randrange(min(D - 1, 26)) + 1
  d = random.randrange(D - l) + 1
  p = t[d - 1]
  q = t[d + l - 1]
  if p == q: continue
  ans = parunyasu(d, d + l, p, q)

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