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

Solution (Python):
from time import time
from random import random

limit_secs = 2
start_time = time()

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

def calc_score():
    score = 0
    S = 0
    last = [-1] * 26
    for d in range(D):
        S += s[d][t[d]]
        last[t[d]] = d
        for i in range(26):
            S -= c[i] * (d - last[i])
        score += max(10 ** 6 + S, 0)
    return score

def solution():
    return [i % 26 for i in range(D)]

t = solution()
score = calc_score()
while time() - start_time + 0.14 < limit_secs:
    d = int(random() * D)
    q = int(random() * 26)
    old = t[d]
    t[d] = q
    new_score = calc_score()
    if new_score < score:
        t[d] = old
    else:
        score = new_score
print('\n'.join(str(e + 1) for e in t))

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!=i) & (k!=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):
from time import time
import random


def main():
    random.seed(145)

    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 = max(1, (-(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):
D=int(input())
C=list(map(int, input().split()))
S=[list(map(int,input().split())) for i in range(D)]








def dissat(day):
  dissat = 0
  for i in range(26):
    if T[day-1]-1 == i:
      continue
    dissat += C[i]*(day-lastdays[i])

  return dissat    
    
def last(day):
  lastdays[T[day-1]-1] = day


def calcscore(D):
  sat = 0
  for i in range(D):
    
    last(i)
    sat += S[i][T[i]-1] - dissat(i+1)
  
  return sat













import random

T = [0]*D
for i in range(D):
  T[i] = random.randrange(1,26)

lastdays = [0]*26
oldscore = calcscore(D)

count = 0
while count < 300:
  T = [0]*D
  for i in range(D):
    T[i] = random.randrange(1,26)

  lastdays = [0]*26
  newscore = calcscore(D)
  if oldscore > 0 and newscore > oldscore:
    oldscore = newscore
    break
  count += 1


count = 0
while count < 10000:
  count += 1
  d=random.randrange(1,D)
  q=random.randrange(1,26)
  old = T[d-1] 
  T[d-1] = q
  lastdays = [0]*26
  newscore = calcscore(D)
  if newscore < oldscore:
    T[d-1] = old
  else:
    oldscore = newscore

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

Solution (Python):
import sys
from random import randint
input = sys.stdin.readline
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [randint(0, 25) for i in range(D)]
last = [0] * 26
def score(day, score):
  for i in range(26): score -= (day - last[i]) * c[i]
  return score
def run(day):
  global last
  last = [0] * 26
  res = 0
  for d in range(day):
    contest = t[d]
    last[contest] = d + 1
    res = score(d + 1, res) + s[d][contest]
  return res


for d in range(1, D + 1):
  mx = -float("inf")
  mxx = randint(0, 25)
  for x in range(26):
    t[d - 1] = x
    res = run(d)
    if mx < res:
      mx = res
      mxx = x
  t[d - 1] = mxx

for l in range(360, 366):
  last = [0] * 26
  run(l)
  
  zmx = -float("inf")
  zmxz = 0
  for z in range(26):
    t[l - 1] = z

    for d in range(l + 1, D + 1):
      mx = -float("inf")
      mxx = t[d - 1]
      for x in range(26):
        t[d - 1] = x
        res = score(d, 0) + s[d - 1][x]
        if mx < res:
          mx = res
          mxx = x
      t[d - 1] = mxx
      last[mxx] = d
    zres = run(D)
    if zres > zmx:
      zmx = zres
      zmxz = z
  t[l - 1] = zmxz

for x in t: print(x + 1)

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

    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)


    cands = [0] * D
    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
stime = time()

from copy import copy
from random import randint

def get_fav_contest(s, t):
    s = copy(s)
    t = copy(t)
    dc = 0
    d = len(t)
    for i in range(1, d):
        dc += s[i][t[i]]
        ca[t[i]] = i
        dc -= sum([c[i2] * (i - ca[i2]) for i2 in range(1, 27)])
    return dc

d = int(input())
c = [0] + list(map(int, input().split(' ')))

s = [[]] + [[0] + list(map(int, input().split(' '))) for _ in range(d)]

t = 0 
tl = [0]

ca = [0] * (1 + 26) 
cat = [] 
cat2 = []

for i in range(1, d + 1):
    cat = [0]
    for i2 in range(1, 27):
        cat2 = copy(ca)
        cat2[i2] = i
        cat.append(s[i][i2] + sum(c[i3] * (i - ca[i3]) for i3 in range(1, 27)))
    t = cat.index(max(cat))
    ca[t] = i
    tl.append(t)

default_t = get_fav_contest(s, tl)

ch = 0 
temp1 = 0 
tempt = 0
while time() - stime < 1.95:
    ch = randint(1, 365)
    temp1 = tl[ch]
    tl[ch] = randint(1, 26)
    tempt = get_fav_contest(s, tl)
    if tempt < default_t:
        tl[ch] = temp1
    else:
        default_t = tempt
print('\n'.join(map(str, tl[1:])))

Solution (Python):
import sys
import random
import time
my_input = sys.stdin.readline

start = time.time()
D = int(input())
C = list(map(int, my_input().split()))
S = [list(map(int, my_input().split())) for _ in range(D)]


def main():
    cnt = 0
    best_ans, best_score = generate_first_ans()
    while time.time() - start < 1.81:
        cnt += 1
        ans = best_ans[:]
        si, sj = random.randint(0, 364), random.randint(0, 364)
        if si == sj:
            continue
        ans[si], ans[sj] = ans[sj], ans[si]
        score = calc_score(ans)
        if score > best_score:
            best_score = score
            best_ans = ans

    
    for a in best_ans:
        print(a + 1)


def generate_first_ans():
    best_ans = []
    best_score = 0
    last_day = [-1] * 26
    for d in range(365):
        d_ans = -1
        d_score = -float('inf')
        d_last_day = [-1] * 26
        for t in range(26):
            d_tmp_score = 0
            d_tmp_score += S[d][t]
            d_tmp_last_day = last_day[:]
            d_tmp_last_day[t] = d
            for c, ld in zip(C, d_tmp_last_day):
                d_tmp_score -= c * (d - ld)

            if d_tmp_score > d_score:
                d_ans = t
                d_score = d_tmp_score
                d_last_day = d_tmp_last_day[:]

        best_ans.append(d_ans)
        best_score += d_score
        last_day = d_last_day[:]

    return best_ans, best_score


def calc_score(T):
    score = 0
    last_day = [-1] * 26
    for d, t in enumerate(T):
        score += S[d][t]
        last_day[t] = d
        for c, ld in zip(C, last_day):
            score -= c * (d - ld)
    return score


if __name__ == "__main__":
    main()

Solution (Python):
import sys,collections as cl,bisect as bs,random
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
	return list(map(int,input().split()))
def m(): 
	return map(int,input().split())
def onem(): 
	return int(input())
def s(x): 
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): 
	return " ".join(map(str,x))
def max2(x): 
	return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

d = onem()

c = l()

s = []
sel = [0 for i in range(365)]

day = [[0 for i in range(26)] for j in range(365)]
ans = 0
for i in range(d):
	s.append(l())
	ss = [[s[-1][i]-c[i],i+1] for i in range(26)]
	ss.sort(reverse = True)
	data = i % 26
	sel[i] = ss[data-1][1]
	ans += s[i][data-1]

	for j in range(26):
		if j == data - 1:
			day[i][j] = i
		else:
			day[i][j] = day[i-1][j]
			ans -= c[j] * (i - day[i][j] + 1)



for _ in range(140000):
	ima = random.randrange(365)
	po = [[s[ima][i]-c[i],i+1] for i in range(26)]
	po.sort(reverse = True)
	while True:
		data = random.randrange(10)
		if sel[ima] != data+1:
			break
	data = po[data][1]-1
	ppp = 0
	for i in range(26):
		if ima == day[ima][i]:
			now = i
			break
	else:
		while True:
			now = random.randrange(26)
			if now != data:
				break 
	for i in range(ima+1,365):
		if day[i][data] == i:
			ppp += (i - ima) * c[data]
			break
	else:
		ppp += (364-ima) * c[data]

	for i in range(ima+1,365):
		if day[i][now] == i:
			ppp += (i - ima) * c[now]
			break
	else:
		ppp -= (364-ima) * c[now]
	if ppp > 0:
		for i in range(ima,365):
			if day[i][data] != i:
				day[i][data] = ima
			else:
				break
		po = ima - 1 if ima != 0 else 0
		for i in range(ima,365):
			if day[i][now] != i:
				day[i][now] = po
			else:
				break
		sel[ima] = data+1

for i in sel:
	print(i)

Solution (Python):

import math
import copy
import random
import time
import numpy as np

start = time.time()
limit_time = 1.8


d = int(input())
c = [int(i) for i in input().split()]
s = [[int(i) for i in input().split()] for j in range(d)]

c_num = np.array(c)
s_num = np.array(s)



def point(t):
    result = 0
    map = {
        0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0,
        10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0, 17: 0, 18: 0, 19: 0,
        20: 0, 21: 0, 22: 0, 23: 0, 24: 0, 25: 0
    }
    for i in range(d):
        comp = t[i] - 1
        day = i + 1
        map[comp] = day
        
        result = result + s[i][comp]
        for cc in range(26):
            result = result - c[cc] * (day - map[cc])
    return result

t = np.argmax(s_num, axis=1) + 1


p = point(t)











t_list = [(t, p)]
while time.time() - start < limit_time:
    new_d = math.floor(d * random.random())
    new_t = math.floor(26 * random.random()) + 1
    for i in range(3):
        l = copy.copy(t_list[i][0])
        l[new_d] = new_t if l[new_d] != new_t else (new_t + 1) % 26
        t_list.append((l, point(l)))
    t_list = sorted(t_list, key=lambda x: x[1], reverse=True)[:3]

print("\n".join([str(i) for i in t_list[0][0]]))

Solution (Python):
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
t = []
last = [[-1] for i in range(26)]


for i in range(D):
    op = 0
    mx = 0
    for j in range(26):
        if s[i][j]*c[j] > mx:
            mx = s[i][j]*c[j]
            op = j
    t.append(op+1)
    last[op].append(i)
    
    
    
    
    
    


from bisect import *
import random
m = 400000
def suminc(a,b):
    return b*(b-1)//2-a*(a-1)//2
while m:
    m-=1
    update = 0
    d = random.randint(1,D)
    q = random.randint(1,26)
    d-=1
    q-=1
    oq = t[d]-1
    update += s[d][q]-s[d][oq]
    idx = bisect_left(last[oq],d)
    if idx == len(last[oq])-1:
        cnt = D - last[oq][idx]
    else:
        cnt = last[oq][idx+1] - last[oq][idx]
    update += c[oq]*suminc(0,cnt)
    cntprv = last[oq][idx] - last[oq][idx-1]
    update -= c[oq]*suminc(cntprv,cntprv+cnt)

    idx2 = bisect_left(last[q],d)-1
    if idx2 == len(last[q])-1:
        cnt = D - d
    else:
        cnt = last[q][idx2+1] - d
    if idx2 == len(last[q])-1:
        cntprv = D - last[q][idx2] - cnt
    else:
        cntprv = last[q][idx2+1] - last[q][idx2] - cnt
    update += c[q]*suminc(cntprv,cntprv+cnt)
    update -= c[q]*suminc(0,cnt)

    if update > 0:
    
        del last[oq][idx]
        last[q].insert(idx2+1,d)
        
        t[d] = q+1





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

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

last=[0]*26


for d in range(1,D+1):
    ans=[]
    for choice in range(1,27):
        ans_tmp=0
        ans_tmp+=s[d-1][choice-1]
        for i in range(26):
            if i+1==choice:
                continue
            ans_tmp-=c[i]*(d-last[i])*(10+(D-d)//36)
        ans.append((ans_tmp,choice))
    _,case=max(ans)
    last[case-1]=d
    print(case)

Solution (Python):
from collections import deque
(d,), cc, *ss = [list(map(int, s.split())) for s in open(0)]

ss = deque(ss)

acc = [0]*len(cc)

while d:
    acc = [sum(x) for x in zip(acc, cc)]
    gain = [sum(x) for x in zip(acc, ss.popleft())]
    m = max(gain)
    for i, g in enumerate(gain):
        if m == g:
            cur = i
            break
    print(cur+1)
    acc[cur] = 0
    d -= 1

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


ans = [s[k].index(max(s[k]))+1 for k in range(D)]

p = 0


scheduled = [0 for _ in range(26)]

for k in range(D):
    t = ans[k]
    scheduled[t-1] = -1
    for j in range(26):
        scheduled[j] +=1
        p -= c[j]*scheduled[j]
    p += s[k][t-1]

np = p

for n in range(D):
    op = 0+ np
    oa = 0 + ans[n]
    ans[n] = 0 
    for k in range(D):
        t = ans[k]
        scheduled[t-1] = -1
        for j in range(26):
            scheduled[j] +=1
            np -= c[j]*scheduled[j]
        np += s[k][t-1]
    if np > op:
        continue
    else:
        ans[n] = oa



for k in range(D):
    print(ans[k])

Solution (Python):
import random
import time


t1 = time.time() 

def f_last(d, i, lt):
  idx = []
  if i in lt[0:d]:
    idx = [j+1 for j, x in enumerate(lt[0:d]) if x == i]
  else:
    idx.append(0)
  return idx[-1]

d = int(input())
lc = list(map(int, input().split()))
ls = []
for _ in range(d):
  ls.append(list(map(int, input().split())))

v_max = -(10**5)
lt_max = [1]*d
while 1:
  lt = [random.randint(1, len(lc)) for i in range(d)]
  v = 0
  for dd in range(1, d+1):
    v_d = 0
    for i in range(len(lc)):
      v_d += lc[i]*(dd-f_last(dd, i+1, lt))
    v = v + ls[dd-1][lt[dd-1]-1] - v_d
  if v_max < v:
    v_max = v
    lt_max = lt[:]
  t2 = time.time()
  if t2-t1 > 1.85:
    break

for t in lt_max:
  print(t)

Solution (Python):
from time import time
start_time = time()
D = int(input())
C = list(map(int,input().split()))
S = [list(map(int,input().split())) for i in range(D)]

INF = float('inf')
DF = 7000
last = [0] * 26
cur_ans = []
nexts = []
for i,s in enumerate(S):
    best_k = -1
    best_score = -INF
    scores = []
    for k,s in enumerate(s):
        score = s
        for j,c in enumerate(C):
            if j==k: continue
            score -= c * (i+1 - last[j])
        if score > best_score:
            best_score = score
            best_k = k
        scores.append((score,k))
    last[best_k] = i+1
    cur_ans.append(best_k + 1)
    for sc,k in scores:
        if k==best_k: continue
        if sc < best_score - DF: continue
        nexts.append((best_score-sc, i,k))
nexts.sort(key=lambda x:x[0])

def evaluate(ans):
    last = [0] * 26
    score = 0
    for i,(s,a) in enumerate(zip(S,ans)):
        score += s[a-1]
        last[a-1] = i+1
        for j,c in enumerate(C):
            score -= c * (i+1 - last[j])
    return score + 10**6

cur_score = evaluate(cur_ans)
selects = [-1] * D
for _,ni,nk in nexts:
    if selects[ni] >= 0: continue
    last = [0] * 26
    ans = []
    for i,s in enumerate(S):
        if selects[i] >= 0:
            last[selects[i]] = i+1
            ans.append(selects[i] + 1)
            continue
        if i==ni:
            last[nk] = i+1
            ans.append(nk + 1)
            continue
        best_k = -1
        best_score = -INF
        for k,s in enumerate(s):
            score = s
            for j,c in enumerate(C):
                if j==k: continue
                score -= c * (i+1 - last[j])
            if score > best_score:
                best_score = score
                best_k = k
        last[best_k] = i+1
        ans.append(best_k + 1)
    sc = evaluate(ans)
    if sc > cur_score:
        cur_score = sc
        cur_ans = ans
        selects[ni] = nk
    if time() - start_time > 1.9:
        break

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

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import numpy as np

d = ni()
c = na()
s = []

for i in range(d):
    ss = na()
    s.append(ss)

c = np.array(c) 
s = np.array(s) 
s_t = s.T 
last = np.zeros(26)




def eva(n, cc, ss):
    return (d-n)*cc + 30*ss

score = 0

for i in range(d): 
    last += 1 
    tow = c * last 
    sc = -100000
    M = -1
    for j in range(26):
        k = eva(i, tow[j], s[i][j])
        if sc < k:
            sc = k
            M = j
    last[M] = 0
    score -= np.dot(c,last)
    score += s[i][M]
    print(M+1)

Solution (Python):
import random
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
ans = 0
a = []
last = [0]*26
for i in range(1,d+1):
    res = -float("inf")
    index = 0
    for k in range(26):
        x = k
        tnplast = last
        tnplast[x] = i
        tnp = 0
        tnp += s[i-1][x]
        for j in range(26):
            tnp -= c[j]*(i-last[j])
        if (tnp > res):
            res = tnp
            index = k+1
    ans += res
    a.append(index)

def rec(t,x,y,ans):
    ans -= s[x-1][t[x-1]-1]
    ans += s[x-1][y-1]
    ma = d+1
    mi = 0
    for j in range(x+1,d+1):
        if (t[j-1]==t[x-1]):
            ma = j
            break
    for j in range(x-1,0,-1):
        if (t[j-1]==t[x-1]):
            mi = j
            break
    ans -= c[t[x-1]-1]*(x-mi)*(ma-x)
    ma = d+1
    mi = 0
    for j in range(x+1,d+1):
        if (t[j-1]==y):
            ma = j
            break
    for j in range(x-1,0,-1):
        if (t[j-1]==y):
            mi = j
            break
    ans += c[y-1]*(x-mi)*(ma-x)
    return ans
    
for i in range(190000):
    x = random.randrange(1,d+1)
    y = random.randrange(1,27)
    t = a
    A = rec(t,x,y,ans)
    if (ans < A):
        t[x-1] = y
        a = t
        ans = A

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

Solution (Python):
from random import randint

D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(D)]

def score_calc(T):
    total = 0
    last = [0] * 26
    for i in range(1, D+1):
        t = T[i-1]
        total += S[i-1][t-1]
        last[t-1] = i
        for j in range(26):
            total -= C[j] * (i - last[j])
    return total

total = 0
last = [0] * 26
ans = []
for i in range(1, D+1):
    score = [0] * 26
    for t in range(26):
        score[t] += S[i-1][t]
        for j in range(26):
            if j != t:
                score[t] -= C[j] * (i - last[j])
    total += max(score)
    last[score.index(max(score))] = i
    ans.append(score.index(max(score))+1)

N = 1000
Q = [[randint(0, (D-1)), randint(0, 25)] for i in range(N)]
for d, q in Q:
    old = ans[d]
    ans[d] = q + 1
    if score_calc(ans) > total:
        total = score_calc(ans)
    else:
        ans[d] = old

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

Solution (Python):
import sys
import random
from copy import copy
from math import floor, e

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def write_output(out):
    with open("my_sample3.out", mode="w") as f:
        for x in out:
            f.write(str(x + 1) + "\n")


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

    sat_cur = 0
    last = [1] * 26
    out = [-1] * d

    for day in range(d):
        estimate = [0.0] * 26
        for cid in range(26):
            if s[day][cid] > 16000:
                estimate[cid] = last[cid] * c[cid] + c[cid] ** 1
        cur = estimate.index(max(estimate))
        out[day] = cur
        sat_cur += s[day][cur]
        last[cur] = 1
        for cid in range(26):
            if cid != cur:
                last[cid] += 1
                sat_cur -= last[cid] * c[cid]

    
    out_best = copy(out)
    sat_best = sat_cur
    num_of_try = 3000
    for i in range(1, num_of_try + 1):
        te = 0
        change_num = floor((num_of_try - i) / 500)
        out_temp = copy(out)
        for j in range(change_num):
            c_day = int(random.triangular(0, 365 - 0.01, 50))
            c_cid = random.randint(0, 25)
            out_temp[c_day] = c_cid

        last = [1] * 26
        sat_temp = 0
        for day in range(d):
            cur = out_temp[day]
            sat_temp += s[day][cur]
            last[cur] = 1
            for cid in range(26):
                if cid != cur:
                    last[cid] += 1
                    sat_temp -= last[cid] * c[cid]
        
        
        if sat_temp > sat_cur:
            out_best = out_temp
            sat_cur = sat_temp

    for x in out_best:
        print(x + 1)

    


if __name__ == '__main__':
    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)  





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

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