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


class Answer:
    """

    """

    def __init__(self, answer, score):
        self.answer = copy.deepcopy(answer)
        self.score = copy.deepcopy(score)
        self.last_days = [0] * 26


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)
        self.not_change_duration = 1000

        self.solve_greedy()
        self._update_best()
        self.answer.score = 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.answer.last_days[j])
                all_scores[0] = self.s[day][0] - minus_score

            else:
                minus_score += self.c[i - 1] * (day + 1 - self.answer.last_days[i - 1])
                minus_score -= self.c[i] * (day + 1 - self.answer.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):
        self.initialize()

        change_day = set([random.randint(0, self.d - 1) for _ in range(10)])
        for day in range(self.d):
            if day in change_day:
                pert = random.randint(1, 10)
            else:
                pert = 1
            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[-pert][0]
            score = self.scoring(day, ind)
            self.answer.last_days[ind] = day + 1
            self.answer.answer[day] = ind
            self.answer.score += score
            

    def score_answer(self, answer: Answer):
        score = 0
        answer.last_days = [0] * 26
        for day in range(self.d):
            score += self.scoring(day, answer.answer[day])
            answer.last_days[answer.answer[day]] = day + 1

        return score

    def solve_greedy(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.answer.last_days[ind] = day + 1
            self.answer.answer[day] = ind
            self.answer.score += score

    def _update_best(self):
        self.not_change_duration += 1
        
        if self.best_answer.score < self.answer.score:
            
            
            self.best_answer = copy.deepcopy(self.answer)
        if self.not_change_duration > 10:
            
            self.answer = copy.deepcopy(self.best_answer)
            self.not_change_duration = 0

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


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

    problem = Problem(D, s, c)
    while time.time() - time_start < limited_time:
        problem.repeat()

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


main()

Solution (Python):
import sys, random
input = sys.stdin.readline
def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    for _ in range(D):
        si = list(map(int, input().split()))
        s.append(si)
    last_list = [0] * 26
    minus_sat_list = [0] * 26
    for i in range(D):
        for j in range(26):
            minus_sat_list[j] += c[j] * (i+1-last_list[j])
        best_idx = 0
        worst_sat, worst_sat_idx  = 0, -1
        worst2_sat, worst2_sat_idx  = 0, -1
        worst3_sat, worst3_sat_idx  = 0, -1
        worst4_sat, worst4_sat_idx  = 0, -1
        worst5_sat, worst5_sat_idx  = 0, -1
        for j in range(26):
            if (minus_sat_list[j] > worst_sat) or (minus_sat_list[j] == worst_sat and s[i][j] > s[i][worst_sat_idx]):
                worst_sat = minus_sat_list[j]
                worst_sat_idx = j
            elif (minus_sat_list[j] > worst2_sat) or (minus_sat_list[j] == worst2_sat and s[i][j] > s[i][worst2_sat_idx]):
                worst2_sat = minus_sat_list[j]
                worst2_sat_idx = j
            elif (minus_sat_list[j] > worst3_sat) or (minus_sat_list[j] == worst3_sat and s[i][j] > s[i][worst3_sat_idx]):
                worst3_sat = minus_sat_list[j]
                worst3_sat_idx = j
            elif (minus_sat_list[j] > worst4_sat) or (minus_sat_list[j] == worst4_sat and s[i][j] > s[i][worst4_sat_idx]):
                worst4_sat = minus_sat_list[j]
                worst4_sat_idx = j
            elif (minus_sat_list[j] > worst5_sat) or (minus_sat_list[j] == worst5_sat and s[i][j] > s[i][worst5_sat_idx]):
                worst5_sat = minus_sat_list[j]
                worst5_sat_idx = j
        worst_val = s[i][worst_sat_idx] * 2 + worst_sat
        worst2_val = s[i][worst2_sat_idx] * 2 + worst2_sat
        worst3_val = s[i][worst3_sat_idx] * 2 + worst3_sat
        worst4_val = s[i][worst4_sat_idx] * 2 + worst4_sat
        worst5_val = s[i][worst5_sat_idx] * 2 + worst5_sat
        best_val = max(worst_val, worst2_val, worst3_val, worst4_val, worst5_val)
        if best_val == worst_val:
            best_idx = worst_sat_idx
        elif best_val == worst2_val:
            best_idx = worst2_sat_idx
        elif best_val == worst3_val:
            best_idx = worst3_sat_idx
        elif best_val == worst4_val:
            best_idx = worst4_sat_idx
        elif best_val == worst5_val:
            best_idx = worst5_sat_idx
        minus_sat_list[best_idx] = 0
        last_list[best_idx] = i + 1
        print(best_idx+1)
if __name__ == "__main__":
    main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
import random
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def decrease(d, j):  
    tmp = 0
    for i in range(26):
        if i == j: continue
        tmp += C[i]*(d-last[i])
    return tmp 

def init():  
    global now
    for i in range(D):  
        ma = -INF
        ma_idx = None
        for j in range(26):  
            tmp = now
            tmp += s[i][j]
            tmp -= decrease(i+1, j)
            if tmp > ma:
                ma = tmp
                ma_idx = j
        now = ma
        last[ma_idx] = i+1
        score[ma_idx] += s[i][ma_idx]
        for j in range(26):
            score[j] -= C[j]*(i+1-last[j])
        last[ma_idx] = i+1
        ans[i] = ma_idx+1

def update(d, q):  
    d -= 1
    q -= 1
    c = ans[d]-1  
    ans[d] = q+1
    last_c = 0
    last_q = 0
    score_c = 0
    score_q = 0
    for j in range(D):
        if ans[j]-1 == c:
            last_c = j+1
            score_c += s[j][c]
        elif ans[j]-1 == q:
            last_q = j+1
            score_q += s[j][q]
        score_c -= C[c] * (j+1 - last_c)
        score_q -= C[q] * (j+1 - last_q)
    score[c] = score_c
    score[q] = score_q

D = INT()
C = LIST()
s = [LIST() for _ in range(D)]
ans = [0]*D
last = [0]*26
score = [0]*26
now = 0

init()
rand = random.randint
for _ in range(10**5):
    d = rand(1, D)
    q = rand(1, 26)
    old = ans[d-1]
    old_score = score.copy()
    update(d, q)
    if sum(score) <= sum(old_score):
        score = old_score
        ans[d-1] = old

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

Solution (Python):


import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  

D = I()
c = [0] + LI()
s = [0] + [[0] + LI() for _ in range(D)]

last = [[0]*27 for _ in range(D+1)]
t = [0]

for i in range(1,D+1):
    r = 0
    manzoku = 0
    for j in range(1,27):
        m = s[i][j]
        for k in range(1,27):
            if k != j:
                m -= c[k]*(i-last[i-1][k])
            else:
                continue
        if j == 1:
            r = 1
            manzoku = m
        else:
            if manzoku < m:
                manzoku = m
                r = j
    t.append(r)
    for j in range(1,27):
        if j == r:
            last[i][j] = i
        else:
            last[i][j] = last[i-1][j]


dq = []
for i in range(1,D+1):
    for j in range(1,27):
        dq.append([i,j])

from copy import deepcopy

for i in range(60):
    for d, q in dq:
        t0 = t[d]
        manzoku = s[d][q] - s[d][t0]
        for j in range(d, D + 1):
            if j == d:
                last[d][t0] = last[d - 1][t0]
                manzoku -= c[t0] * (d - last[d][t0])
                last[d][q] = d
                manzoku += c[q] * (d - last[d - 1][q])
            else:
                if last[j][t0] == d:
                    last[j][t0] = last[d - 1][t0]
                    manzoku -= c[t0] * (d - last[d][t0])
                if last[j][q] == last[d - 1][q]:
                    last[j][q] = d
                    manzoku += c[q] * (d - last[d - 1][q])
        if manzoku > 0:
            t[d] = q
        else:
            for j in range(d, D + 1):
                if j == d:
                    last[d][t0] = d
                    last[d][q] = last[d - 1][q]
                else:
                    if last[j][t0] == last[d - 1][t0]:
                        last[j][t0] = d
                    if last[j][q] == d:
                        last[j][q] = last[d - 1][q]

del t[0]

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

Solution (Python):
import sys 
import time

t0=time.time()
import random
random.seed(1)
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=-1
        if target>0:
            for i in range(target-1,-1,-1):
                a=anss[i]
                if a==pval and not f1:
                    cp=i
                    f1=1
                elif 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
            elif 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)
    

    
    yaki=1000.0
    count=0
    abest=anss.copy()
    tsc=csc
    lc=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,tsc,target,val,pval)
        
        if nsc>csc:
            csc=nsc
            tsc=nsc
            anss[target]=val
            abest=anss.copy()
            lc=count
        else:           
            r=random.random()
            if r<2**(-(csc-nsc)/(yaki+1e-9)):
                anss[target]=val
                tsc=nsc
            if count-lc>500:
                anss=abest.copy()
                tsc=csc
                lc=count
    printl(abest)
    printe(csc,count,lc,abest[0])

if __name__ == "__main__":
    main()

Solution (Python):
import time
import copy
import random


class Answer:
    """

    """

    def __init__(self, answer, score):
        self.answer = copy.deepcopy(answer)
        self.score = copy.deepcopy(score)
        self.last_days = [0] * 26


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)
        self.not_change_duration = 1000

        self.solve_greedy()
        self._update_best()
        self.answer.score = 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.answer.last_days[j])
                all_scores[0] = self.s[day][0] - minus_score

            else:
                minus_score += self.c[i - 1] * (day + 1 - self.answer.last_days[i - 1])
                minus_score -= self.c[i] * (day + 1 - self.answer.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):
        self.initialize()

        change_day = set([random.randint(0, self.d - 1) for _ in range(10)])
        for day in range(self.d):
            if day in change_day:
                pert = random.randint(1, 10)
            else:
                pert = 1
            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[-pert][0]
            score = self.scoring(day, ind)
            self.answer.last_days[ind] = day + 1
            self.answer.answer[day] = ind
            self.answer.score += score
            

    def score_answer(self, answer: Answer):
        score = 0
        answer.last_days = [0] * 26
        for day in range(self.d):
            score += self.scoring(day, answer.answer[day])
            answer.last_days[answer.answer[day]] = day + 1

        return score

    def solve_greedy(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.answer.last_days[ind] = day + 1
            self.answer.answer[day] = ind
            self.answer.score += score

    def _update_best(self):
        self.not_change_duration += 1
        
        if self.best_answer.score < self.answer.score:
            
            
            self.best_answer = copy.deepcopy(self.answer)
        if self.not_change_duration > 10:
            
            self.answer = copy.deepcopy(self.best_answer)
            self.not_change_duration = 0

    def initialize(self):
        
        
        self.answer.score = 0


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

    problem = Problem(D, s, c)
    ite = 0
    while time.time() - time_start < limited_time:
        ite += 1
        problem.repeat()

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


main()

Solution (Python):
import sys, random
input = sys.stdin.readline
def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    for _ in range(D):
        si = list(map(int, input().split()))
        s.append(si)
    last_list = [0] * 26
    minus_sat_list = [0] * 26
    for i in range(D):
        for j in range(26):
            minus_sat_list[j] += c[j] * (i+1-last_list[j])
        best_idx = 0
        worst_sat, worst_sat_idx  = 0, -1
        worst2_sat, worst2_sat_idx  = 0, -1
        worst3_sat, worst3_sat_idx  = 0, -1
        worst4_sat, worst4_sat_idx  = 0, -1
        worst5_sat, worst5_sat_idx  = 0, -1
        for j in range(26):
            if (minus_sat_list[j] > worst_sat) or (minus_sat_list[j] == worst_sat and s[i][j] > s[i][worst_sat_idx]):
                worst_sat = minus_sat_list[j]
                worst_sat_idx = j
            elif (minus_sat_list[j] > worst2_sat) or (minus_sat_list[j] == worst2_sat and s[i][j] > s[i][worst2_sat_idx]):
                worst2_sat = minus_sat_list[j]
                worst2_sat_idx = j
            elif (minus_sat_list[j] > worst3_sat) or (minus_sat_list[j] == worst3_sat and s[i][j] > s[i][worst3_sat_idx]):
                worst3_sat = minus_sat_list[j]
                worst3_sat_idx = j
            elif (minus_sat_list[j] > worst4_sat) or (minus_sat_list[j] == worst4_sat and s[i][j] > s[i][worst4_sat_idx]):
                worst4_sat = minus_sat_list[j]
                worst4_sat_idx = j
            elif (minus_sat_list[j] > worst5_sat) or (minus_sat_list[j] == worst5_sat and s[i][j] > s[i][worst5_sat_idx]):
                worst5_sat = minus_sat_list[j]
                worst5_sat_idx = j
        indices = [worst_sat_idx, worst2_sat_idx, worst3_sat_idx, worst4_sat_idx, worst5_sat_idx]
        best_idx = indices[random.randrange(5)]
        minus_sat_list[best_idx] = 0
        last_list[best_idx] = i + 1
        print(best_idx+1)
if __name__ == "__main__":
    main()

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

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





typ=0
ans=0
types=[(i%26)+1 for i in range(D)]

sc = [0] * D
last=[0]*26

for i in range(D):
    typ = types[i] - 1
    score = s[i][typ]
    dwn = 0
    last[typ] = (i + 1)
    for j in range(26):
        dwn = dwn + c[j] * ((i + 1) - last[j])
    ans = score - dwn
    
    sc[i] = max(ans+10**6,0)
all = sum(sc)
for _ in range(25000):
    types2 = [0]*D
    mi=float("inf")
    ind=0
    for i in range(D):
        if mi>sc[i]:
            mi=sc[i]
            ind=i
    l=list(range(1,D+1))
    
    
    l.pop(ind-1)
    ind2=random.choice(l)
    spans=ind//26
    for i in range(D):
        types2[i]=types[i]
    buf=types[ind]
    types[ind]=types[ind2-1]
    types[ind2-1]=buf
    sc2=[0]*D
    last=[0]*26
    for i in range(D):
        typ = types[i] - 1
        score = s[i][typ]
        dwn = 0
        last[typ] = (i + 1)
        for j in range(26):
            dwn = dwn + c[j] * ((i + 1) - last[j])
        ans = score - dwn
                
        sc2[i] = max(ans+10**6,0)
    all2 = sum(sc2)
    if all2<=all:
        types=types2
    else:
        sc=sc2
        all=all2
        sc2=[]
        
    
    
for i in range(D):
    print(types[i])

Solution (Python):





import time
 
START = (int(time.time() * 1000))

import random
import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

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

schedule = []


for d in range(D):
  MAX = -10**20
  temp = None
  last = [-1 for i in range(26)]
  for j in range(26):
    s = 0
    for i in range(26):
      if i == j:
        last[i] = d
        s += S[d][i]
      else:
        s -= C[i]*(d-last[i])
    if s > MAX:
      MAX = s
      temp = j
  schedule.append(temp)
  
score = 0
last = [[-1] for i in range(26)]  

for d in range(D):
  t = schedule[d]
  last[t].append(d)
  score += S[d][t]
  

for i in range(26):
  last[i].append(D)
  for k in range(len(last[i])-1):
    g = last[i][k+1]-last[i][k]-1
    score -= C[i]*g*(g+1)//2

while True:
  d = random.choice(range(D))
  for q in range(26):
    prev = score
    p = schedule[d]
    schedule[d] = q
    score -= S[d][p]
    score += S[d][q]

    pos = last[p].index(d)
    score -= C[p]*(last[p][pos]-last[p][pos-1])*(last[p][pos+1]-last[p][pos])
    last[p].remove(d)

    pos = bisect.bisect(last[q],d)
    score += C[q]*(d-last[q][pos-1])*(last[q][pos]-d)
    bisect.insort(last[q],d)
    if score<prev:
      score = prev
      bisect.insort(last[p],d)
      last[q].remove(d)
      schedule[d] = p

  if int(time.time() * 1000)-START>1900:
    break

for i in schedule:
  print(i+1)

Solution (Python):


import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  

D = I()
c = [0] + LI()
s = [0] + [[0] + LI() for _ in range(D)]

last = [[0]*27 for _ in range(D+1)]
t = [0]

for i in range(1,D+1):
    r = 0
    manzoku = 0
    for j in range(1,27):
        m = s[i][j]
        for k in range(1,27):
            if k != j:
                m -= c[k]*(i-last[i-1][k])
            else:
                continue
        if j == 1:
            r = 1
            manzoku = m
        else:
            if manzoku < m:
                manzoku = m
                r = j
    t.append(r)
    for j in range(1,27):
        if j == r:
            last[i][j] = i
        else:
            last[i][j] = last[i-1][j]


dq = []
for i in range(1,D+1):
    for j in range(1,27):
        dq.append([i,j])

from copy import deepcopy

for i in range(10):
    for d, q in dq:
        t0 = t[d]
        manzoku = s[d][q] - s[d][t0]
        for j in range(d, D + 1):
            if j == d:
                last[d][t0] = last[d - 1][t0]
                manzoku -= c[t0] * (d - last[d][t0])
                last[d][q] = d
                manzoku += c[q] * (d - last[d - 1][q])
            else:
                if last[j][t0] == d:
                    last[j][t0] = last[d - 1][t0]
                    manzoku -= c[t0] * (d - last[d][t0])
                if last[j][q] == last[d - 1][q]:
                    last[j][q] = d
                    manzoku += c[q] * (d - last[d - 1][q])
        if manzoku > 0:
            t[d] = q
        else:
            for j in range(d, D + 1):
                if j == d:
                    last[d][t0] = d
                    last[d][q] = last[d - 1][q]
                else:
                    if last[j][t0] == last[d - 1][t0]:
                        last[j][t0] = d
                    if last[j][q] == d:
                        last[j][q] = last[d - 1][q]

del t[0]

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