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):
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],i+1] for i in range(26)]

	ak = 0

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

	ma = [-1,-1]
	for j in range(26):
		if i != 0:
			if ma[0] <= c[j] * (i-day[i-1][j]+1) + s[-1][j]:
				ma[0] = c[j] + (i-day[i-1][j]+1) + s[-1][j]
				ma[1] = j
		else:
			if ma[0] <= c[j] + s[-1][j]:
				ma[0] = c[j] + s[-1][j]
				ma[1] = j
	ans += ma[0] + ak
	sel[i] = ma[1]+1

	for j in range(26):
		if j == ma[1]:
			day[i][j] = i
		else:
			day[i][j] = day[i-1][j] if i - 1 >= 0 else 0



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 = po[random.randrange(10)][1]
		if sel[ima] != data:
			break
	data = data-1
	ppp = 0
	now = sel[ima]-1
	for i in range(ima+1,365):
		if day[i][data] == i:
			ppp += (i - ima) * c[data]
			break
	else:
		ppp += (364-ima) * c[data]
	ppp += s[ima][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]
	ppp -= s[ima][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
		ans += ppp

for i in sel:
	print(i)

Solution (Python):
import time
import copy


class Answer:
    """

    """

    def __init__(self, answer, score):
        self.answer = copy.deepcopy(answer)
        self.score = copy.deepcopy(score)


class Problem:
    def __init__(self, num_day, s, c):
        self.d = num_day
        self.s = s
        self.c = c
        self.last_days = [0] * 26
        self.answer = Answer([0] * self.d, 0)
        self.best_answer = Answer([0] * self.d, 0)

    def scoring(self, day, ind) -> int:
        day_score = self.s[day][ind]
        minus_score = 0
        for i in range(26):
            if i != ind:
                minus_score += self.c[i] * (day + 1 - self.last_days[i])
        day_score -= minus_score
        return day_score

    def get_all_scores(self, day):
        """全ての選択肢のscoreを返す"""
        minus_score = 0
        all_scores = [0] * 26
        for i in range(26):
            if i == 0:
                for j in range(1, 26):
                    minus_score += self.c[j] * (day + 1 - self.last_days[j])
                all_scores[0] = self.s[day][0] - minus_score

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

    def repeat(self):
        self.initialize()
        self.solve()
        self._update_best()

        return copy.deepcopy(self.best_answer)

    def solve(self):

        for day in range(self.d):
            all_scores = self.get_all_scores(day)
            all_scores_with_ind = [[i, all_scores[i]] for i in range(26)]
            all_scores_with_ind.sort(key=lambda x: x[1])
            ind = all_scores_with_ind[-1][0]
            score = self.scoring(day, ind)
            self.last_days[ind] = day + 1
            self.answer.answer[day] = ind
            self.answer.score += score

    def _update_best(self) -> Answer:
        if self.best_answer.score < self.answer.score:
            self.best_answer = copy.deepcopy(self.answer)
        return copy.deepcopy(self.best_answer)

    def initialize(self):
        self.last_days = [0] * 26


def main():
    time_start = time.time()
    limited_time = 2 * 0.90
    D = int(input())
    c = list(map(int, input().split()))
    s = []

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

    
    answer = Answer([0] * D, 0)

    problem = Problem(D, s, c)
    ite = 0
    
    ite += 1
    problem.repeat()

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


main()

Solution (Python):

import random
import numpy as np

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

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


def get_objective_function(output):
    objective_function = 0
    last = [[-1 for i in range(26)] for d in range(D)]
    for d in range(D):
        objective_function += s[d][output[d]]
        last[d][output[d]] = d
        if d < D-1:
            for i in range(26):
                last[d+1][i] = max(last[d][i], last[d+1][i])
        for i in range(26):
            objective_function -= c[i] * (d-last[d][i])
    point = max(10 ** 6 + objective_function, 0)
    return point, objective_function


def local_search_swap(output, num_iter, width):
    for _ in range(num_iter):
        targets = np.random.randint(low=0, high=D-1, size=width)

        changed_output = output.copy()
        for i in range(width):
            changed_output[targets[i]] = changed_output[targets[(i+1)%width]]
        point1, obj1 = get_objective_function(changed_output)
        point2, obj2 = get_objective_function(output)
        print(point1, obj1, point2, obj2, width)

        if get_objective_function(changed_output) > get_objective_function(output):
            output = changed_output
        else:
            pass
    return output



def local_search(output, num_iter=5, width=3):
    for _ in range(num_iter):
        mask = np.random.randint(low=0, high=D-1, size=width)

        changed_output = output.copy()
        changed_output[mask] = (output[mask] + np.random.randint(low=0, high=D-1, size=width)) % 26

        point1, obj1 = get_objective_function(changed_output)
        point2, obj2 = get_objective_function(output)
        print(point1, obj1, point2, obj2, width)

        if get_objective_function(changed_output) > get_objective_function(output):
            output = changed_output
        else:
            pass
    return output



output = []
for d in range(D):
    output.append(d%26)
output = np.array(output)






for d in range(D):
    print(output[d] + 1)

Solution (Python):
D=int(input())
C=list(map(int,input().split()))
S=list()
for i in range(D):
  S.append(list(map(int,input().split())))
t=[0]*D
M=0
N=0
L=-10000000000000000000000
di=[0]*26
ddi=[0]*26
for d in range(D):
  
  for j in range(26):
    for i in range(26): 
      if i==j:
        ddi[i]=0
      else:
        ddi[i]=di[i]+1
    N=S[d][j] 
    for i in range(26): 
      N-=C[i]*ddi[i]
    if N>L:
      L=N
      di=ddi
      t[d]=j+1
  L=-10000000000000000000000 

for i in range(D):
  print(t[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:
                sat_cur -= last[cid] * c[cid]
                last[cid] += 1

    
    out_best = copy(out)
    sat_best = sat_cur
    num_of_try = 10000
    for i in range(1, num_of_try + 1):
        change_num = 1
        out_temp = copy(out_best)
        for j in range(change_num):
            
            swap = random.sample(range(d), k=2)
            out_temp[swap[0]], out_temp[swap[1]] = out_temp[swap[1]], out_temp[swap[0]]

        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:
                    sat_temp -= last[cid] * c[cid]
                    last[cid] += 1
        if sat_temp > sat_best:
            
            out_best = out_temp
            sat_best = sat_temp

    for x in out_best:
        print(x + 1)

    


if __name__ == '__main__':
    main()

Solution (Python):
from bisect import bisect_left
from random import randint
from time import time
 
start = time()

D = int(input())
*C, = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(D)]
T = [randint(1, 26) for _ in range(D)]

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

def init():
    global T, days
    score = 0
    last = [0] * 26
    for d, t in enumerate(T, 1):
        score += S[d - 1][t - 1]
        last[t - 1] = d
        for c, l in zip(C, last): score -= c * (d - l)
        days[t - 1].append(d)
    for i in range(26): days[i].append(D+1)
    return score

def diff(d, q):
    global T, C, S, days
    dif = 0
    p = T[d - 1]
    dif += S[d - 1][q - 1] - S[d - 1][p - 1]
    
    idx_p = bisect_left(days[p - 1], d)
    bef_p, aft_p = days[p - 1][idx_p - 1], days[p - 1][idx_p + 1]
    
    idx_q = bisect_left(days[q - 1], d)
    bef_q, aft_q = days[q - 1][idx_q - 1], days[q - 1][idx_q]
    dif += C[q - 1] * (d - bef_q) * (aft_q - d) - C[p - 1] * (d - bef_p) * (aft_p - d)
    
    return idx_p, idx_q, dif
    
score = init()
while time() - start < 1.8:
    d, q = randint(1, D), randint(1, 26)
    idx_p, idx_q, dif = diff(d, q)
    if dif > 0:
        p = T[d - 1]
        T[d - 1] = q
        del days[p - 1][idx_p]
        days[q - 1].insert(idx_q, d)
        score += dif
print(*T, sep='\n')

Solution (Python):
def main():
    import os

    INF = 10 ** 9 + 10

    D = int(input())
    *C, = map(int, input().split())
    
    
    S = [[int(x) for x in input().split()] for _ in range(D)]
    

    last = [-1] * 26

    def diff(d, t):
        ret = S[d][t]
        ret -= sum(ci * (d - last[i]) for i, ci in enumerate(C) if i != t)
        for k in range(1, 21):
            if d < D - k:
                ret -= sum(ci * (d + k - last[i]) for i, ci in enumerate(C) if i != t)
                ret -= k * C[t]
        return ret

    T = []
    score = 0
    for d in range(D):
        delta = -INF
        take_t = -1
        for t_ in range(26):
            buf = diff(d, t_)
            if delta < buf:
                delta = buf
                take_t = t_
            elif delta == buf and C[t_] > C[take_t]:
                delta = buf
                take_t = t_

        last[take_t] = d
        score += buf
        T.append(take_t + 1)
    print(*T, sep='\n')
    
    
    
    
    

    


if __name__ == '__main__':
    main()

Solution (Python):


import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)

def max_index(lst):
	index = -1
	value = -float("inf")
	for i, vi in enumerate(lst):
		if value < vi:
			value = vi
			index = i
	return index


def main():
	log = Logger(0)
	day_length = int(sys.stdin.readline())
	down_happy = list(map(int, sys.stdin.readline().split()))
	daily_happy = [[] for i in range(day_length)]
	contests_kind = 26
	for i in range(day_length):
		si = list(map(int, sys.stdin.readline().split()))
		for j in range(contests_kind):
			daily_happy[i].append(si[j])
	happy = 0
	last_contest_days = [0]*contests_kind
	for day in range(day_length):
		best_contest = 0
		max_add_happy = -float("inf")
		for contest in range(contests_kind):
			add_happy = 0
			add_happy += daily_happy[day][contest]
			for contest_kind in range(contests_kind):
				if contest_kind != contest:
					add_happy -= down_happy[contest_kind] * (day + 1 - last_contest_days[contest_kind])
			if max_add_happy < add_happy:
				max_add_happy = add_happy
				best_contest = contest
		last_contest_days[best_contest] = day + 1
		print(best_contest + 1)
		happy += max_add_happy
	log.print(happy)





main()

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.82:
        cnt += 1
        ans = best_ans[:]

        x = random.random()
        if x > 0.35:
            si, sj = random.randint(0, 364), random.randint(0, 364)
            if si == sj:
                continue
            ans[si], ans[sj] = ans[sj], ans[si]
        else:
            si = random.randint(0, 364)
            sx = random.randint(0, 25)
            if ans[si] == sx:
                continue
            ans[si] = sx

        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):
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

last = [0]*26
scr = 0 
for d in range(D):
    sts_p = 0
    sts_date = 1
    total = scr
    for i in range(26):
        total += s[d][i]
        for j in range(26):
            if i == j:
                continue
            else:
                total -= (c[j]*(d+1 - last[j]))
        
        if total >= sts_p:
            sts_p = total
            sts_date = i+1
        total = scr

    scr = sts_p
    last[sts_date - 1] = d+1
    print(sts_date)

Solution (Python):
import random
from random import randint
random.seed(0)

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 = 20000
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 time

t0=time.time()
import random
def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print(*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None

def main():
    mod = 1000000007
    

    D = int(input())
    
    cs = tuple(map(int, input().split())) 
    
    S = tuple(tuple(map(int, input().split())) for i in range(D)) 
    lss=[]
    ls=[0]*26
    anss=[-1]*D
    for i in range(D):
        s=S[i]
        if i==0:
            msc=-1000000
            ans=-1
            for j in range(26):
                sc=s[j]+cs[j]

                if msc<sc:
                    ans=j
                    msc=sc
            ls[ans]=1
            
            anss[i]=ans+1
            continue
        msc=0
        ans=-1
        dec=[-cs[j]*(i+1-ls[j]) for j in range(26)]
        msc=-10000000
        ans=-1
        for j in range(26):
            sc=s[j]-dec[j]
            if msc<sc:
                ans=j
                msc=sc
        ls[ans]=i+1
        
        anss[i]=ans+1
    
    def eval(anss):
        ls=[0]*26
        score=0
        for i in range(D):
            j=anss[i]-1
            ls[j]=i+1
            score+=S[i][j]
            dec=sum([cs[k]*(i+1-ls[k]) for k in range(26)])
            score-=dec
        return score
    
    def eval2(anss,score,target,val,pval):
        score=score-S[target][pval-1]+S[target][val-1]
        f1=0
        f2=0
        cp=cv=0
        if target>0:
            for i in range(target-1,-1,-1):
                a=anss[i]
                if a==pval and not f1:
                    cp=i
                    f1=1
                if a==val and not f2:
                    cv=i
                    f2=1
                if f1 and f2:
                    break
        f1=f2=0
        
        csv=cs[val-1]
        csp=cs[pval-1]
        tcv=(target-cv)*csv
        tcp=(target-cp)*csp
        

        score+=tcv-tcp
        for i in range(target+1,D):
            a=anss[i]
            if anss[i]==pval and not f2:
                f2=1
            if anss[i]==val and not f1:
                f1=1
            if not f1:
                score+=tcv
            if not f2:
                score-=tcp
                
            if f1 and f2:
                break

        return score

    csc=eval(anss)
    

    random.seed(1)
    yaki=10000000
    count=0
    while time.time()-t0<1.9:
        count+=1
        target=random.randrange(0,D)
        
        pval=anss[target]
        val=pval
        while val==pval:
            val=random.randrange(0,26)+1
        
        
        nsc=eval2(anss,csc,target,val,pval)
        
        if nsc>csc:
            csc=nsc
            anss[target]=val
            
        else:
            r=random.random()
            if r<2**(-(csc-nsc)/yaki):
                anss[target]=val
            

    printl(anss)
    printe(csc,count)
    
    

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
import time
import random
import collections
import bisect  

start = time.time()

def insert(list, n): 
    bisect.insort(list, n)  
    return list

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

c = np.array(c)
s = np.array(s)
tests = np.argmax(s, axis=1)

def get_dates_for_tests(tests):
  dates_for_tests = [list([-1]) for _ in range(26)]
  for i, t in enumerate(tests):
    dates_for_tests[t].append(i)
  for t in range(26):
    dates_for_tests[t].append(D)
  return dates_for_tests

dates_for_tests = get_dates_for_tests(tests)

def get_score(tests):
  dates_for_tests = get_dates_for_tests(tests)
  score = 0
  d = np.zeros(26, dtype=np.int64)
  for selected, S in zip(tests, s):
    d += 1
    d[selected] = 0
    score += S[selected] - (c * d).sum()
  return score

def score_diff(date, test):
  
  before = tests[date]
  if test == before:
    return 0, None, None
  pos_diff = s[date, test] - s[date, before]
  new_index = bisect.bisect_left(dates_for_tests[test], date, 1)
  new_diff = c[test] * (dates_for_tests[test][new_index] - date) * (date - dates_for_tests[test][new_index-1])

  old_index = bisect.bisect_left(dates_for_tests[before], date, 1)
  
  
  old_diff = c[before] * (dates_for_tests[before][old_index+1] - date) * (date - dates_for_tests[before][old_index-1])
  
  total_diff = pos_diff + new_diff - old_diff
  
  return total_diff, new_index, old_index


while time.time() < start + 1.8:
  for date in range(D):
    for test in range(26):
      
      

      total_diff, new_index, old_index= score_diff(date, test)
      if total_diff > 0:
        
        
        
        
        del dates_for_tests[tests[date]][old_index]
        insert(dates_for_tests[test], date)
        tests[date] = test

        
        
        
        
        
        
        

for t in tests:
  print(t+1)

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

  """
    
  testc=(90,80,85,75,70,65,60,55,50,45,40,35,30,25,20,15,99,98,97,96,95,94,93,92,91)
  for l in testc:
    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]>l:
        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):
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],i+1] for i in range(26)]

	ak = 0

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

	ma = [-1,-1]
	for j in range(26):
		if i != 0:
			if ma[0] <= c[j] * (i-day[i-1][j]+1) + s[-1][j]:
				ma[0] = c[j] + (i-day[i-1][j]+1) + s[-1][j]
				ma[1] = j
		else:
			if ma[0] <= c[j] + s[-1][j]:
				ma[0] = c[j] + s[-1][j]
				ma[1] = j
	ans += ma[0] + ak
	sel[i] = ma[1]+1

	for j in range(26):
		if j == ma[1]:
			day[i][j] = i
		else:
			day[i][j] = day[i-1][j] if i - 1 >= 0 else 0



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 = po[random.randrange(10)][1]
		if sel[ima] != data:
			break
	data = data-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]
	ppp += s[ima][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]
	ppp -= s[ima][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
		ans += ppp

for i in sel:
	print(i)