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 random import randrange, random
import time
START_TIME = time.time()


def is_valid(ans_types: list, ans_val: int) -> bool:
    """ans_types(1-indexed)を選んだときに、
    答えがans_valになるかどうかを確かめる。"""
    res = 0

    tmp_last_days = {}
    for c_type in range(1, C_TYPES + 1):
        tmp_last_days[c_type] = 0
   
    for day in range(1, DAYS + 1):
        c_type = ans_types[day - 1]
        res += s[day][c_type]

        tmp_last_days[c_type] = day
        for c_type in range(1, C_TYPES + 1):
            res -= c[c_type] * (day - tmp_last_days[c_type])

    return res == ans_val


def search_max_point(day: int, last_days: dict):
    """day-1日目までに選んだコンテストが確定している状態で
    day日目にどのコンテストを選べば満足度を最適化できるか貪欲に探索する。
    dayは1-indexedに注意。
    返値として、選ぶコンテスト(1-indexed)、そのときに得られる満足度を返す。
    """
    max_val = -INF
    max_type = -1
    for c_type in range(1, C_TYPES + 1):
        tmp = s[day][c_type]
        for c_type2 in range(1, C_TYPES + 1):
            if c_type2 == c_type:
                continue
            tmp -= c[c_type2] * (day - last_days[c_type2])
        if max_val < tmp:
            max_val = tmp
            max_type = c_type
    return max_type, max_val


def change(ans_types: list, day: int, from_type: int, to_type:int):
    """day日目のコンテストをfrom_typeからto_typeに変更する。
    dayは1-indexed、選ぶコンテストは1-indexedに注意。
    返値として、そのときに得られる満足度の変化量を返す。
    """
    res_diff = 0
    res_diff = -s[day][from_type] + s[day][to_type]

    from_t = ans_types
    to_t = ans_types[0:]
    to_t[day - 1] = to_type

    l_day = {from_type: 0, to_type: 0}
    for day, type_c in enumerate(from_t):
        day += 1
        if type_c in l_day:
            l_day[type_c] = day
        for type_c2 in l_day:
            res_diff += c[type_c2] * (day - l_day[type_c2])

    l_day = {from_type: 0, to_type: 0}
    for day, type_c in enumerate(to_t):
        day += 1
        if type_c in l_day:
            l_day[type_c] = day
        for type_c2 in l_day:
            res_diff -= c[type_c2] * (day - l_day[type_c2])
    return res_diff




d = int(input())  
c = tuple([0] + list(map(int, input().split())))
s = tuple([tuple([0 for i in range(27)])] + [tuple([0] + list(map(int, input().split()))) for i in range(d)])







                                                 

DAYS = d
C_TYPES = 26
INF = 10 ** 18
NAPIER = 2.71828182846


last_days = {}
for c_type in range(1, C_TYPES + 1):
    last_days[c_type] = 0



ans_val = 0
ans_types = []
for day in range(1, DAYS + 1):
    c_type, val = search_max_point(day, last_days)
    ans_types.append(c_type)
    ans_val += val
    last_days[c_type] = day


if not is_valid(ans_types, ans_val):
    print(re)
    exit()



T = 100
cool = 0.9999
best_score = ans_val
best_types = ans_types[0:]
score = ans_val
types = ans_types[0:]

while time.time() - START_TIME < 1.8:

    
    day = randrange(1, DAYS + 1)
    from_type = types[day - 1]
    while True:
        to_type = randrange(1, C_TYPES + 1)
        if to_type != from_type:
            break

    
    diff = change(types, day, from_type, to_type)
    
    
    p = pow(NAPIER, -abs(diff) / T)
    
    
    if (diff > 0 or random() < p):
        types[day - 1] = to_type
        score = score + diff
        
    
    if score > best_score:
        best_score = score
        best_types = types[0:]
        
    
    T = T * cool


if not is_valid(best_types, best_score):
    print(re)
    exit()

for i in best_types:
    print(i)

Solution (Python):
import sys
import numpy as np
import numba
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

i4 = numba.int32

def get_input():
    D = int(readline())
    C = np.array(readline().split(), np.int32)
    S = np.array([readline().split() for _ in range(D)], np.int32)
    return D, C, S

@njit((i4, i4[:], i4[:, :], i4[:]), cache=True)
def first_computation(D, C, S, T):
    x = 0
    last = np.zeros((26, D), np.int32)
    for d in range(D):
        if d:
            last[:, d] = last[:, d - 1]
        i = T[d]
        x += S[d, i]
        last[i, d] = d + 1
        for i in range(26):
            x -= C[i] * (d + 1 - last[i, d])
    return last, x

@njit((i4, i4[:], i4[:, :], i4[:], i4[:, :], i4, i4), cache=True)
def difference_update(D, C, S, T, last_day, d, q):
    p = T[d]
    T[d] = q
    x = S[d, q] - S[d, p]

    i = np.searchsorted(last_day[p], d + 1)
    d_p = last_day[p, i - 1] if i >= 1 else 0
    coef = 0
    for k in range(d, D):
        if last_day[p, k] == d + 1:
            
            coef += d_p - d - 1
            last_day[p, k] = d_p
        else:
            break
    x += coef * C[p]

    coef = 0
    for k in range(d, D):
        if last_day[q, k] < d + 1:
            coef += (d + 1 - last_day[q, k])
            last_day[q, k] = d + 1
        else:
            break
    x += coef * C[q]
    return x

@njit((i4, i4[:], i4[:, :], i4[:], i4[:, :], i4), cache=True)
def swap_update(D, C, S, T, last_day, d):
    p = T[d]
    q = T[d+1]
    if p == q:
        return 0
    x = 0
    
    x -= C[p] * (d - last_day[p, d-1])
    last_day[p,d] = last_day[p,d-1] + 1
    for k in range(d+1, D):
        if last_day[p,k] == d + 1:
            last_day[p,k] += 1
            x += C[p]
        else:
            break
            
    x += (d - last_day[q, d]) * C[p]
    for k in range(d+1, D):
        if last_day[q, k] == d + 2:
            last_day[q,k] -= 1
            x -= C[q]
        else:
            break
    
    x += S[d+1,p] + S[d, q] - S[d,p] - S[d+1,q]
    T[d], T[d+1] = q,p
    return x

def output(T):
    T += 1
    print(*T, sep='\n')

@njit((i4, i4[:], i4[:, :], i4[:], i4[:, :]), cache=True)
def random_update(D, C, S, T, last_days):
    d = np.random.randint(0, D, 1)[0]
    p = T[d]
    xcum = 0
    for q in range(26):
        if p == q:
            continue
        xcum += difference_update(D, C, S, T, last_days, d, q)
        if xcum > 0:
            return q, xcum
    difference_update(D, C, S, T, last_days, d, p)
    return p, 0

@njit((i4, i4[:], i4[:, :], i4[:], i4[:,:]), cache=True)
def main(D, C, S, T, last_days):
    for _ in range(3000):
        d = np.random.randint(1, D-1, 1)[0]
        
        
        
        random_update(D, C, S, T, last_days)[1]
    return T

def first_strategy(D, C, S):
    T = np.empty(D, np.int32)
    for d in range(D):
        T[d] = d % 26
    return T

D, C, S = get_input()

res = []
for _ in range(100):
    T = first_strategy(D, C, S)
    last_days, score = first_computation(D, C, S, T)
    T = main(D,C,S,T,last_days)
    _, x = first_computation(D,C,S,T)
    res.append((T, x))

T,x = max(res, key=lambda x: x[1])

output(T)

Solution (Python):

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

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

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

    return ans

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

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

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

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

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

Solution (Python):
import sys
input = sys.stdin.buffer.readline
import numpy as np

D = int(input())
c = np.array(input().split(), dtype=np.int32)
s = np.array([input().split() for _ in range(D)], dtype=np.int32)
last = np.zeros(26, dtype=np.int32)



ans = []
point = 0
for i in range(D):
    down = (i+1-last)*c
    loss = down * 4 + s[i,:]
    idx = np.argmax(loss)
    ans.append(idx+1)
    last[idx] = i+1
    down = (i+1-last)*c
    point += s[i, idx] - down.sum()
    
    

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

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

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

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

        T[d] = t

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


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

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

        que = deque()
        que.append(T0)

        for loop in range(120000):
            T = que.popleft()
            d = random.randint(0,D-1)

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

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

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

                if cur>change:
                    change = cur
                    c = q

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

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

    
    T = local_search(T)
    

    for t in T:
        print(t+1)

    return

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

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

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

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

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

    ans = calc_start()[D-1]

    

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

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

        
        

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

        ans += change

        print(ans)

    return


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

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examA()

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

Solution (Python):
from time import time

t0 = time()

from random import randrange

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

N = 26

si = []
t = [max(range(26), key=lambda x: si[x]) for si in s]


while time() - t0 < 1.85:
    
    diff = 0

    di = randrange(D)
    qi = randrange(N)
    if t[di] == qi:
        continue

    
    old_type = t[di]

    for next_d in range(di + 1, D):
        if t[next_d] == old_type:
            break
    else:
        next_d = D

    for prev_d in range(di - 1, -1, -1):
        if t[prev_d] == old_type:
            break
    else:
        prev_d = -1

    diff -= s[di][old_type]
    diff -= (next_d - di) * (di - prev_d) * c[old_type]

    
    for next_d in range(di + 1, D):
        if t[next_d] == qi:
            break
    else:
        next_d = D

    for prev_d in range(di - 1, -1, -1):
        if t[prev_d] == qi:
            break
    else:
        prev_d = -1

    diff += s[di][qi]
    diff += (next_d - di) * (di - prev_d) * c[qi]

    
    if diff >= 0:
        t[di] = qi

ans = [ti + 1 for ti in t]
print(*ans, sep="\n")

Solution (Python):
import random

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

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

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

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

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

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

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

    count-=1

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

Solution (Python):
d = int(input())
c_l = list(map(int,input().split()))
s_l = [list(map(int,input().split())) for i in range(d)]

def calc(t_l, last_l, day):
  ans = 0
  for day in range(d):

    contest_num = t_l[day]
    contest_num -= 1

    contest_val = s_l[day][contest_num]
    ans += contest_val

    t_last_l = last_l[:]
    t_last_l[contest_num] = day

    for i in range(26):
      ans -= c_l[i] * (day - t_last_l[i])

    return ans

last_l = [-1 for i in range(26)]
ans = []
point = 0

for day in range(d):
  each_point = 0
  each_contest_num = 0

  t_ans = ans[:]
  for temp_contest_num in range(26):
    temp_point = calc(t_ans+[temp_contest_num], last_l, day)
    if temp_point > each_point:
      each_point = temp_point
      each_contest_num = temp_contest_num

  last_l[each_contest_num] = day
  ans.append(each_contest_num + 1)
  point += each_point

for i in ans:
  print(i)

Solution (Python):





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

ans = 0
score = 0
last = [[-1] for i in range(26)]
schedule = []

for d in range(D):
  t = random.choice(range(26))
  last[t].append(d)
  score += S[d][t]
  schedule.append(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

count = 2000000

while count:
  count -= 1
  prev = score
  d,q = random.choice(range(D)),random.choice(range(26))
  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
    
for i in schedule:
  print(i+1)

Solution (Python):
import time
import random


class Problem:

    def __init__(self, D, s, c):
        self.last_days = [0] * 26
        self.D = D
        self.s = s
        self.c = c
        self.answer = [0] * self.D
        self.best_answer = [0] * self.D

    def scoring(self, day, ind):
        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 _strategy_greedy(self, day):
        perturbation = random.randint(0, 5)
        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[-perturbation][0]
        score = self.scoring(day, ind)
        return score, ind

    def solve(self):
        self.init()

        sum_score = 0
        for i in range(self.D):
            score, ind = self._strategy_greedy(i)
            self.last_days[ind] = i + 1
            self.answer[i] = ind
            sum_score += score
        return sum_score, self.answer

    def _strategy_perturbation(self, day):
        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]
        

    def solve_perturbation(self):
        self.init()

        for i in range(4):
            day = random.randint(1, self.D)
            self.best_answer[day] = self._strategy_perturbation(day)

    
    
    
    



    def init(self):
        self.last_days = [0] * 26
        self.answer = [0] * self.D


def main():
    time_start = time.time()
    DO_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())))

    max_score = 0

    problem = Problem(D, s, c)
    ite = 0
    while time.time() - time_start < DO_TIME:
        ite += 1
        score, answer = problem.solve()

        if score > max_score:
            
            
            max_score = score
            problem.best_answer = answer

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


main()

Solution (Python):
from random import randrange, random
from bisect import bisect
from math import exp
from time import perf_counter as timer
def simulated_annealing(C, S, duration=1.8):
    
    D = len(S)
    K = len(C)

    helper = lambda i,j: (j-i-1)*(j-i)//2
    
    class State:
        def __init__(self,d2c,c2d):
            self.c2d = c2d
            self.d2c = d2c
            self.score = self._score()

        @classmethod
        def random(cls):
            d2c = [randrange(K) for _ in range(D)]
            c2d = [[-1] for _ in range(K)]
            for d,c in enumerate(d2c):
                c2d[c].append(d)
            for c in range(K):
                c2d[c].append(D)
            return State(d2c,c2d)

        def _score(self):
            s = 0
            for d,c in enumerate(self.d2c):
                s += S[d][c]

            for c,ds in enumerate(self.c2d):
                k = C[c]
                for a,b in zip(ds,ds[1:]):
                    s -= k*helper(a,b)
            return s

        def random_move(self):
            d = randrange(D)
            c = self.d2c[d]
            nc = randrange(K-1)
            if nc >= c:
                nc += 1

            delta = S[d][nc] - S[d][c]

            cd = self.c2d[c]
            i = bisect(cd,d)-1
            delta += C[c]*(helper(d,cd[i+1]) + helper(cd[i-1],d))
            delta -= C[c]*helper(cd[i-1],cd[i+1])

            cd = self.c2d[nc]
            i = bisect(cd,d)
            delta += C[nc]*helper(cd[i-1],cd[i])
            delta -= C[nc]*(helper(d,cd[i]) + helper(cd[i-1],d))

            return (d,nc),delta

        def make_move(self, move, delta):
            '''
            move = (d,nc)
            '''
            d,nc = move
            c = self.d2c[d]
            self.d2c[d] = nc

            i = bisect(self.c2d[c], d)-1
            self.c2d[c].pop(i)

            i = bisect(self.c2d[nc],d)
            self.c2d[nc].insert(i, d)
            self.score += delta

    ALPHA = 7000

    state = State.random()

    START = timer()
    deadline = START + duration
    now = START
    while now < deadline:
        temp = ALPHA*(deadline-now)/duration
        
        move, delta = state.random_move()
        if delta >= 0 or exp(delta/temp) > random():
            state.make_move(move, delta)
        now = timer()
    return (v+1 for v in state.d2c)

if __name__ == '__main__':
    D = int(input())
    C = tuple(map(int,input().split()))
    S = tuple(tuple(map(int,input().split())) for _ in range(D))
    print(*simulated_annealing(C,S), sep='\n')

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

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def main():
	D = int(input())  
	vC = [0,]+linput()     
	
	
	
	
	mS = [[0,]+linput() for _ in [0,]*D]
	
	
	vL = [-1,]*(26+1)   
	
	
	res = 0      
	vR = []
	vT = []
	rapp = vR.append
	tapp = vT.append
	
	
	res = 0      
	vR = []
	rapp = vR.append

	def get_scoreA(vtt):
		res = 0
		for d in range(D): 
			t = vtt[d] 
			vS = mS[d]
			Sdt = vS[t]
			res += Sdt
		
			vL[t] = d
			C = sum(c*(d-l) for c,l in zip(vC,vL))
			res -= C
		
			
		return res

	
	
	MR = 5050
	
	for m in range(MR):
		vTtmp = []
		for d in range(D):
			vTtmp.append(getr(1,26))
		resTmp = get_scoreA(vTtmp)
		if resTmp>res:
			res = resTmp
			rapp(res)
			vT = [t for t in vTtmp]
	
	
	
	
	print(*vT, sep='\n')
	print(*vR, file=sys.stderr)
	

if __name__ == "__main__":
	main()