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 perf_counter
tick = perf_counter() + 1.92

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from random import randrange
from bisect import bisect

def resolve():
    G = 26
    it = map(int, sys.stdin.read().split())
    D = next(it)
    C = [next(it) for i in range(G)]
    S = [[next(it) for i in range(G)] for i in range(D)]
    L = [[-1] for i in range(G)]
    T = [0] * D

    def update(di, qi):

        score = 0
        t0 = T[di]
        score += S[di][qi]-S[di][t0]

        a1 = li = L[t0][:]
        ii = li.index(di)
        la = D if len(li)-1 == ii else li[ii+1]
        score -= C[t0] * (di-li[ii-1])*(la-di)
        li.pop(ii)

        a2 = li = L[qi][:]
        ii = bisect(li, di)
        li.insert(ii, di)
        la = D if len(li)-1 == ii else li[ii+1]
        score += C[qi] * (di-li[ii-1])*(la-di)

        return score, (a1, a2)

    U = 7
    def calc(i, j):
        score = S[i][j]
        for k in range(G):
            u = k - L[k][-1]
            score -= C[k] * (u + u + U) * U // 2
        score += C[k] * U * (i-L[j][-1])
        return score

    for di in range(D):
        i, score = 0, calc(di, 0)
        for qi in range(1, G):
            x = calc(di, qi)
            if x > score:
                i, score = qi, x
        T[di] = i
        L[i].append(di)

    while perf_counter() < tick:
        di, qi = randrange(0, D), randrange(0, G)
        diff, swap = update(di, qi)
        if diff > 0:
            score += diff
            q0, T[di] = T[di], qi
            L[q0], L[qi] = swap

    print(*(i+1 for i in T), sep="\n")

if __name__ == "__main__":
    resolve()

Solution (Python):


from time import perf_counter
tick = perf_counter() + 1.92

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from random import randrange
from bisect import bisect

def resolve():
    G = 26
    it = map(int, sys.stdin.read().split())
    D = next(it)
    C = [next(it) for i in range(G)]
    S = [[next(it) for i in range(G)] for i in range(D)]
    L = [[-1] for i in range(G)]
    T = [0] * D

    def update(di, qi):

        score = 0
        t0 = T[di]
        score += S[di][qi]-S[di][t0]

        a1 = li = L[t0][:]
        ii = li.index(di)
        la = D if len(li)-1 == ii else li[ii+1]
        score -= C[t0] * (di-li[ii-1])*(la-di)
        li.pop(ii)

        a2 = li = L[qi][:]
        ii = bisect(li, di)
        li.insert(ii, di)
        la = D if len(li)-1 == ii else li[ii+1]
        score += C[qi] * (di-li[ii-1])*(la-di)

        return score, (a1, a2)

    U = 10
    def calc(i, j):
        score = S[i][j]
        for k in range(G):
            u = k - L[k][-1]
            score -= C[k] * (u + u + U) * U // 2
        score += C[k] * U * (i-L[j][-1])
        return score

    for di in range(D):
        if di + U >= D:
            U = D - di
        i, score = 0, calc(di, 0)
        for qi in range(1, G):
            x = calc(di, qi)
            if x > score:
                i, score = qi, x
        T[di] = i
        L[i].append(di)

    while perf_counter() < tick:
        di, qi = randrange(0, D), randrange(0, G)
        diff, swap = update(di, qi)
        if diff > 0:
            score += diff
            q0, T[di] = T[di], qi
            L[q0], L[qi] = swap

    print(*(i+1 for i in T), sep="\n")

if __name__ == "__main__":
    resolve()

Solution (Python):
import time

START = time.time()

import math
import random
import sys
input = sys.stdin.readline


Days = int(input())
C = list(map(int, input().split())) 
Ss = [list(map(int, input().split())) for _ in range(Days)]








INF = 10**18
TIMELIMIT = 1.9


def outputToScore(T):
    last = [0]*26

    satisfied = 0
    for d, t in enumerate(T):
        t -= 1; d += 1
        satisfied += Ss[d-1][t]
        last[t] = d
        for i, c in enumerate(C):
            satisfied -= c*(d-last[i])
        
    return satisfied

def outputToScore2(T):
    last = [0]*26
    used = [[] for _ in range(26)]
    satisfied = 0
    for d, t in enumerate(T):
        t -= 1; d += 1
        satisfied += Ss[d-1][t]
        used[t].append(d)
        last[t] = d
        for i, c in enumerate(C):
            satisfied -= c*(d-last[i])
        
    return satisfied, used

def greedy():
    last = [0]*26
    T = []
    for d in range(Days):
        satisfied_max = -INF
        selected = -1
        for t in range(26):
            score_t = Ss[d][t]
            for j, c in enumerate(C):
                if t != j:
                    score_t -= c*(d+1-last[j])
            if score_t > satisfied_max:
                satisfied_max = score_t
                selected = t
        T.append(selected+1)
        last[selected] = d+1
    return T


def modifiedScore(d, aft, Used, T):
    bef = T[d-1]-1
    deltaSatis = Ss[d-1][aft] - Ss[d-1][bef]
    

    
    befind = Used[bef].index(d)
    befday0 = 0 if befind == 0 else Used[bef][befind-1]
    befday2 = Days+1 if befind == len(Used[bef])-1 else Used[bef][befind+1]
    
    befd01 = d - befday0
    befd12 = befday2 - d
    befd02 = befday2-befday0
    deltaSatis -= C[bef]*(befd02*(befd02-1)//2) - C[bef]*(befd01*(befd01-1)//2 + befd12*(befd12-1)//2)

    
    if len(Used[aft]) > 0:
        aftday0 = 0
        aftday2 = Days+1
        for a in Used[aft]:
            if a < d:
                aftday0 = a
            elif aftday2 == Days+1:
                aftday2 = a
        aftd01 = d - aftday0
        aftd12 = aftday2 - d
        aftd02 = aftd01 + aftd12
        deltaSatis += C[aft]*(aftd02*(aftd02-1)//2) - C[aft]*(aftd01*(aftd01-1)//2 + aftd12*(aftd12-1)//2)
    else:
        d01 = d
        d12 = Days+1 - d
        deltaSatis += C[aft] * Days*(Days+1)//2 - C[aft]*(d01*(d01-1)//2 + d12*(d12-1)//2)

    return deltaSatis


def update(Used, T, bef, aft, d):
    Used[bef].remove(d)
    inserted = False
    new = []
    for a in Used[aft]:
        if a > d and not inserted:
            inserted = True
            new.append(d)
        new.append(a)
    if not inserted:
        new.append(d)
    Used[aft] = new
    T[d-1] = aft+1
    return T, Used


def goingup(T, Used, Temp):
    d = random.randint(1, Days)
    bef = T[d-1]-1
    aft = random.randint(0, 25)

    if bef == aft:
        return T, Used

    delta = modifiedScore(d, aft, Used, T)
    if delta > 0 or math.exp(delta/Temp) > random.random():
        T, Used = update(Used, T, bef, aft, d)
    return T, Used


def main():
    T = greedy()
    Satisfied, Used = outputToScore2(T)

    TempMax = 10**3
    TempMin = 1
    
    REMAIN = TIMELIMIT - time.time()
    LOOPBEGIN = TIMELIMIT - REMAIN
    while time.time() - START < TIMELIMIT:
        t = (time.time() - LOOPBEGIN)/REMAIN
        Temp = TempMax**(1-t) * TempMin**t
        T, Used = goingup(T, Used, Temp)
        
    print(*T, sep="\n")
    


def test():
    T = [int(input()) for _ in range(Days)] 
    Q = int(input())
    Query = [list(map(int, input().split())) for _ in range(Q)]
    Satisfied, Used = outputToScore2(T)
    for d, aft in Query:
        aft -= 1
        bef = T[d-1]-1
        Satisfied += modifiedScore(d, aft, Used, T)
        T, Used = update(Used, T, T[d-1]-1, aft, d)
        print(Satisfied)


if __name__ == "__main__":
    main()

Solution (Python):


from time import perf_counter
tick = perf_counter() + 1.92

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from random import randrange
from bisect import bisect

def resolve():
    G = 26
    it = map(int, sys.stdin.read().split())
    D = next(it)
    C = [next(it) for i in range(G)]
    S = [[next(it) for i in range(G)] for i in range(D)]
    L = [[-1] for i in range(G)]
    T = [0] * D

    def update(di, qi):

        score = 0
        t0 = T[di]
        score += S[di][qi]-S[di][t0]

        a1 = li = L[t0][:]
        ii = li.index(di)
        la = D if len(li)-1 == ii else li[ii+1]
        score -= C[t0] * (di-li[ii-1])*(la-di)
        li.pop(ii)

        a2 = li = L[qi][:]
        ii = bisect(li, di)
        li.insert(ii, di)
        la = D if len(li)-1 == ii else li[ii+1]
        score += C[qi] * (di-li[ii-1])*(la-di)

        return score, (a1, a2)

    U = 10
    def calc(i, j):
        score = S[i][j]
        for k in range(G):
            u = k - L[k][-1]
            score -= C[k] * (u + u + U) * U // 2
        score += C[k] * U * (i-L[j][-1])
        return score

    for di in range(D):
        i, score = 0, calc(di, 0)
        for qi in range(1, G):
            x = calc(di, qi)
            if x > score:
                i, score = qi, x
        T[di] = i
        L[i].append(di)

    while perf_counter() < tick:
        di, qi = randrange(0, D), randrange(0, G)
        diff, swap = update(di, qi)
        if diff > 0:
            score += diff
            q0, T[di] = T[di], qi
            L[q0], L[qi] = swap

    print(*(i+1 for i in T), sep="\n")

if __name__ == "__main__":
    resolve()

Solution (Python):


from time import perf_counter
tick = perf_counter() + 1.92

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from random import randrange
from bisect import bisect

def resolve():
    G = 26
    it = map(int, sys.stdin.read().split())
    D = next(it)
    C = [next(it) for i in range(G)]
    S = [[next(it) for i in range(G)] for i in range(D)]
    L = [[-1] for i in range(G)]
    T = [0] * D

    def update(di, qi):

        score = 0
        t0 = T[di]
        score += S[di][qi]-S[di][t0]

        a1 = li = L[t0][:]
        ii = li.index(di)
        la = D if len(li)-1 == ii else li[ii+1]
        score -= C[t0] * (di-li[ii-1])*(la-di)
        li.pop(ii)

        a2 = li = L[qi][:]
        ii = bisect(li, di)
        li.insert(ii, di)
        la = D if len(li)-1 == ii else li[ii+1]
        score += C[qi] * (di-li[ii-1])*(la-di)

        return score, (a1, a2)

    def calc(i, j):
        score = S[i][j]
        for k in range(j):
            score -= C[k] * (k - L[k][-1])
        for k in range(j+1, G):
            score -= C[k] * (k - L[k][-1])
        return score

    for di in range(D):
        i, score = 0, calc(di, 0)
        for qi in range(1, G):
            x = calc(di, qi)
            if x > score:
                i, score = qi, x
        T[di] = i
        L[i].append(di)

    while perf_counter() < tick:
        di, qi = randrange(0, D), randrange(0, G)
        diff, swap = update(di, qi)
        if diff > 0:
            score += diff
            q0, T[di] = T[di], qi
            L[q0], L[qi] = swap

    print(*(i+1 for i in T), sep="\n")

if __name__ == "__main__":
    resolve()

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

d = int(input())
cs = list(map(int, input().split()))
cs = np.array(cs, dtype=np.int64)
sm = [list(map(int, input().split())) for _ in range(d)]
sm = np.array(sm, dtype=np.int64)

@njit('i8(i8[:], i8)', cache=True)
def total_satisfaction(ts, d):
    ls = np.zeros(26, dtype=np.int64)
    s = 0
    for i in range(d):
        t = ts[i]
        t -= 1
        s += sm[i][t]
        ls[t] = i + 1

        dv = cs * ((i+1) - ls)
        s -= dv.sum()
    return s

@njit('i8(i8, i8, i8, i8, i8[:])', cache=True)
def differential(s, i, t, d, ls):
    t -= 1
    bk = ls[t]
    s += sm[i][t]
    ls[t] = i + 1

    dv = cs * ((i+1) - ls)
    s -= dv.sum()

    ls[t] = bk
    return s


ts = np.array([], dtype=np.int64)
sc = 0
for i in range(d):
    ls = np.zeros(26, np.int64)
    for i, t in enumerate(ts, 1):
        ls[t-1] = i

    mx = -99999999
    mxt = -1
    for t in range(1, 26+1):
        df = differential(sc, len(ts), t, i + 1, ls)
        s = sc + df
        if s > mx:
            mx = s
            mxt = t
    ts = np.append(ts, [mxt])
    sc += mxt
    print(mxt)

Solution (Python):
import random
import time

t1=time.time()
d=int(input())
c=input()
cl=[int(n) for n in c.split()]
sl=list()
for i in range(d):
    s=input()
    sl=sl+[int(n) for n in s.split()]
tl=list()
for i in range(d):
    tl.append(random.randint(1,26))
sat=0
for i in range(d):
    sat+=sl[i*26+tl[i]-1]

def decr(tl,cl):
    dec=0
    for i in range(26):
        last=[a for a, x in enumerate(tl) if x==i+1]
        if last==list():
            dec+=(d*(d+1)/2)*cl[i]
        else:
            for v in range(len(last)):
                if v!=len(last)-1:    
                    dec+=cl[i]*(last[v+1]-last[v]-1)*(last[v+1]-last[v])/2
                else:
                    dec+=cl[i]*(d-last[v]-1)*(d-last[v])/2
            dec+=cl[i]*(last[0])*(last[0]+1)/2
    return(int(dec))

oldscore=sat
oldans=oldscore-decr(tl,cl)
oldtl=[int(x) for x in tl]
t2=time.time()
while t2-t1<1.85:
    if round(t2)%2==0:
        d1=random.randint(1,d)
        d2=random.randint(1,d)
        q1=tl[d2-1]
        q2=tl[d1-1]
        cha=sl[(d1-1)*26+q1-1]-sl[(d1-1)*26+tl[d1-1]-1]+sl[(d2-1)*26+q2-1]-sl[(d2-1)*26+tl[d2-1]-1]
        tl[d2-1]=q2
        tl[d1-1]=q1
        newscore=oldscore+cha
        newans=newscore-decr(tl,cl)
    else:
        da=random.randint(1,d)
        q=random.randint(1,26)
        cha=sl[(da-1)*26+q-1]-sl[(da-1)*26+tl[da-1]-1]
        tl[da-1]=q
        newscore=oldscore+cha
        newans=newscore-decr(tl,cl)
    r=0
    if newans<oldans:
        if 2.7**((newans-oldans)/(1.85-(t2-t1)))<random.random():
            r=1
    if r==1:
        tl=[int(x) for x in oldtl]
    else:
        oldans=newans
        oldtl=[int(x) for x in tl]
        oldscore=newscore
    t2=time.time()
for i in range(d):
    print(tl[i])

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

dt=[]
last=[-1]*26
v=0
for d in range(D):
    news=[s[d][i]+c[i]*(d-last[i])*(d-last[i]-1) for i in range(26)]
    maxi=0
    tmp=-float('inf')
    for i in range(26):
        if tmp<news[i]:
            maxi=i
            tmp=news[i]
    last[maxi]=d
    v+=s[d][maxi]
    for i in range(26):
        v-=c[i]*(d-last[i])
    dt.append(maxi+1)

def score(T):
    last=[-1]*26
    v=0
    for d in range(D):
        v+=s[d][T[d]-1]
        last[T[d]-1]=d
        for i in range(26):
            v-=c[i]*(d-last[i])
    return v

v0=max(score(dt)+10**6,0)

for _ in range(6):
    for d in range(1,D):
        y=-1
        newdt=dt+[]
        for i in range(26):
            if dt[d]!=i+1:
                newdt[d]=i+1
                v1=max(score(newdt)+10**6,0)
                if v0<v1:
                    y=i+1
                    v0=v1
        if y!=-1:
            dt[d]=y

for i in dt:
    print(i)

Solution (Python):
import random
import time

t1=time.time()
d=int(input())
c=input()
cl=[int(n) for n in c.split()]
sl=list()
for i in range(d):
    s=input()
    sl=sl+[int(n) for n in s.split()]
tl=list()
for i in range(d):
    tl.append(random.randint(1,26))
sat=0
for i in range(d):
    sat+=sl[i*26+tl[i]-1]

def decr(tl,cl):
    dec=0
    for i in range(26):
        last=[a for a, x in enumerate(tl) if x==i+1]
        if last==list():
            dec+=(d*(d+1)/2)*cl[i]
        else:
            for v in range(len(last)):
                if v!=len(last)-1:    
                    dec+=cl[i]*(last[v+1]-last[v]-1)*(last[v+1]-last[v])/2
                else:
                    dec+=cl[i]*(d-last[v]-1)*(d-last[v])/2
            dec+=cl[i]*(last[0])*(last[0]+1)/2
    return(int(dec))

oldscore=sat
oldans=oldscore-decr(tl,cl)
oldtl=[int(x) for x in tl]
t2=time.time()
while t2-t1<1.85:
    if round(t2)/2==0:
        d1=random.randint(1,d)
        d2=random.randint(1,d)
        q1=tl[d2-1]
        q2=tl[d1-1]
        cha=sl[(d1-1)*26+q1-1]-sl[(d1-1)*26+tl[d1-1]-1]+sl[(d2-1)*26+q2-1]-sl[(d2-1)*26+tl[d2-1]-1]
        tl[d2-1]=q1
        tl[d1-1]=q2
        newscore=oldscore+cha
        newans=newscore-decr(tl,cl)
    else:
        da=random.randint(1,d)
        q=random.randint(1,26)
        cha=sl[(da-1)*26+q-1]-sl[(da-1)*26+tl[da-1]-1]
        tl[da-1]=q
        newscore=oldscore+cha
        newans=newscore-decr(tl,cl)
    r=0
    if newans<oldans:
        if 2.7**((newans-oldans)/(1.85-(t2-t1)))<random.random():
            r=1
    if r==1:
        tl=[int(x) for x in oldtl]
    else:
        oldans=newans
        oldtl=[int(x) for x in tl]
        oldscore=newscore
    t2=time.time()
for i in range(d):
    print(tl[i])

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

d = int(input())
cs = list(map(int, input().split()))
cs = np.array(cs, dtype=np.int64)
sm = [list(map(int, input().split())) for _ in range(d)]
sm = np.array(sm, dtype=np.int64)

@njit('i8(i8[:], i8)', cache=True)
def total_satisfaction(ts, d):
    ls = np.zeros(26, dtype=np.int64)
    s = 0
    for i in range(d):
        t = ts[i]
        t -= 1
        s += sm[i][t]
        ls[t] = i + 1

        dv = cs * ((i+1) - ls)
        s -= dv.sum()
    return s

@njit('i8(i8, i8, i8, i8, i8[:])', cache=True)
def differential(s, i, t, d, ls):
    t -= 1
    bk = ls[t]
    s += sm[i][t]
    ls[t] = i + 1

    dv = cs * ((i+1) - ls)
    s -= dv.sum()

    ls[t] = bk
    return s

ts = np.array([], dtype=np.int64)
for i in range(d):
    sc = 0
    if len(ts) > 0:
        tt = np.array(ts, dtype=np.int64)
        sc = total_satisfaction(tt, i)

    ls = np.zeros(26, np.int64)
    for i, t in enumerate(ts, 1):
        ls[t-1] = i

    mx = -99999999
    mxt = -1
    for t in range(1, 26+1):
        df = differential(sc, len(ts), t, i + 1, ls)
        s = sc + df
        if s > mx:
            mx = s
            mxt = t
    ts = np.append(ts, [mxt])
    print(mxt)

Solution (Python):
import time

START = time.time()

import random
import sys
input = sys.stdin.readline
Days = int(input())
C = list(map(int, input().split())) 
Ss = [list(map(int, input().split())) for _ in range(Days)]


INF = 10**18
TIMELIMIT = 1.9


def outputToScore(T):
    last = [0]*26

    satisfied = 0
    for d, t in enumerate(T):
        t -= 1; d += 1
        satisfied += Ss[d-1][t]
        last[t] = d
        for i, c in enumerate(C):
            satisfied -= c*(d-last[i])
        
    return satisfied

def outputToScore2(T):
    last = [0]*26
    used = [[] for _ in range(26)]
    satisfied = 0
    for d, t in enumerate(T):
        t -= 1; d += 1
        satisfied += Ss[d-1][t]
        used[t].append(d)
        last[t] = d
        for i, c in enumerate(C):
            satisfied -= c*(d-last[i])
        
    return satisfied, used

def greedy():
    last = [0]*26
    T = []
    for d in range(Days):
        satisfied_max = -INF
        selected = -1
        for t in range(26):
            score_t = Ss[d][t]
            for j, c in enumerate(C):
                if t != j:
                    score_t -= c*(d+1-last[j])
            if score_t > satisfied_max:
                satisfied_max = score_t
                selected = t
        T.append(selected+1)
        last[selected] = d+1
    return T


def modifiedScore(d, aft, Used, T):
    bef = T[d-1]-1
    deltaSatis = Ss[d-1][aft] - Ss[d-1][bef]
    

    
    befind = Used[bef].index(d)
    befday0 = 0 if befind == 0 else Used[bef][befind-1]
    befday2 = Days+1 if befind == len(Used[bef])-1 else Used[bef][befind+1]
    
    befd01 = d - befday0
    befd12 = befday2 - d
    befd02 = befday2-befday0
    deltaSatis -= C[bef]*(befd02*(befd02-1)//2) - C[bef]*(befd01*(befd01-1)//2 + befd12*(befd12-1)//2)

    
    if len(Used[aft]) > 0:
        aftday0 = 0
        aftday2 = Days+1
        for a in Used[aft]:
            if a < d:
                aftday0 = a
            elif aftday2 == Days+1:
                aftday2 = a
        aftd01 = d - aftday0
        aftd12 = aftday2 - d
        aftd02 = aftd01 + aftd12
        deltaSatis += C[aft]*(aftd02*(aftd02-1)//2) - C[aft]*(aftd01*(aftd01-1)//2 + aftd12*(aftd12-1)//2)
    else:
        d01 = d
        d12 = Days+1 - d
        deltaSatis += C[aft] * Days*(Days+1)//2 - C[aft]*(d01*(d01-1)//2 + d12*(d12-1)//2)

    return deltaSatis


def update(Used, T, bef, aft, d):
    Used[bef].remove(d)
    inserted = False
    new = []
    for a in Used[aft]:
        if a > d and not inserted:
            inserted = True
            new.append(d)
        new.append(a)
    if not inserted:
        new.append(d)
    Used[aft] = new
    T[d-1] = aft+1
    return T, Used


def goingup(T, Used):
    d = random.randint(1, Days)
    bef = T[d-1]-1
    aft = random.randint(0, 25)

    if bef == aft:
        return T, Used

    if modifiedScore(d, aft, Used, T) > 0:
        T, Used = update(Used, T, bef, aft, d)
    return T, Used


def main():
    T = greedy()
    Satisfied, Used = outputToScore2(T)

    while time.time() - START < TIMELIMIT:
        T, Used = goingup(T, Used)
        
    print(*T, sep="\n")


def test():
    T = [int(input()) for _ in range(Days)] 
    Q = int(input())
    Query = [list(map(int, input().split())) for _ in range(Q)]
    Satisfied, Used = outputToScore2(T)
    for d, aft in Query:
        aft -= 1
        bef = T[d-1]-1
        Satisfied += modifiedScore(d, aft, Used, T)
        T, Used = update(Used, T, T[d-1]-1, aft, d)
        print(Satisfied)


if __name__ == "__main__":
    main()

Solution (Python):
from copy import copy
import random
import math
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)]
last = [0]*26
ans = [0]*D
score = 0
for i in range(D):
    ps = [0]*26
    for j in range(26):
        pl = copy(last)
        pl[j] = i+1
        ps[j] += s[i][j]
        for k in range(26):
            ps[j] -= c[k]*(i+1-pl[k])
    idx = ps.index(max(ps))
    last[idx] = i+1
    ans[i] = idx+1
    score += max(ps)
T = 3000
for k in range(41000):
    na = copy(ans)
    x = random.randint(1,365)
    y = random.randint(1,365)
    if x == y:
        continue
    na[x-1],na[y-1] = na[y-1],na[x-1]
    last = [0]*26
    ns = 0
    for i in range(D):
        last[na[i]-1] = i+1
        ns += s[i][na[i]-1]
        for j in range(26):
            ns -= c[j]*(i+1-last[j])
    if k%100 == 0:
        T *= 0.98
    p = pow(math.e,-abs(ns-score)/T)
    if ns > score or random.random() < p:
        ans = na
        score = ns
for a in ans:
    print(a)

Solution (Python):
import numpy as np

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

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

v = 0
cc =  np.array( [0]*26 )
last = np.array( [-1]*26 )
for d in range(D):
  cc += c
  av = s[d] - sum( cc ) + cc
  av2 = av + cc*min((D-d-1),2)
  m = max(av2)
  for t in range(26):
    if av2[t] == m:
      cc[t] = 0
      v += av[t]
      print(t+1)
      break

Solution (Python):
import time

START = time.time()

import random
import sys
input = sys.stdin.readline
Days = int(input())
C = list(map(int, input().split())) 
Ss = [list(map(int, input().split())) for _ in range(Days)]


INF = 10**18
TIMELIMIT = 1.9


def outputToScore(T):
    last = [0]*26

    satisfied = 0
    for d, t in enumerate(T):
        t -= 1; d += 1
        satisfied += Ss[d-1][t]
        last[t] = d
        for i, c in enumerate(C):
            satisfied -= c*(d-last[i])
        
    return satisfied

def outputToScore2(T):
    last = [0]*26
    used = [[] for _ in range(26)]
    satisfied = 0
    for d, t in enumerate(T):
        t -= 1; d += 1
        satisfied += Ss[d-1][t]
        used[t].append(d)
        last[t] = d
        for i, c in enumerate(C):
            satisfied -= c*(d-last[i])
        
    return satisfied, used

def greedy():
    last = [0]*26
    T = []
    for d in range(Days):
        satisfied_max = -INF
        selected = -1
        for t in range(26):
            score_t = Ss[d][t]
            for j, c in enumerate(C):
                if t != j:
                    score_t -= c*(d+1-last[j])
            if score_t > satisfied_max:
                satisfied_max = score_t
                selected = t
        T.append(selected+1)
        last[selected] = d+1
    return T


def modifiedScore(d, aft, Used, T):
    bef = T[d-1]-1
    deltaSatis = Ss[d-1][aft] - Ss[d-1][bef]
    

    
    befind = Used[bef].index(d)
    befday0 = 0 if befind == 0 else Used[bef][befind-1]
    befday2 = Days+1 if befind == len(Used[bef])-1 else Used[bef][befind+1]
    
    befd01 = d - befday0
    befd12 = befday2 - d
    befd02 = befday2-befday0
    deltaSatis -= C[bef]*(befd02*(befd02-1)//2) - C[bef]*(befd01*(befd01-1)//2 + befd12*(befd12-1)//2)

    
    if len(Used[aft]) > 0:
        aftday0 = 0
        aftday2 = Days+1
        for a in Used[aft]:
            if a < d:
                aftday0 = a
            elif aftday2 == Days+1:
                aftday2 = a
        aftd01 = d - aftday0
        aftd12 = aftday2 - d
        aftd02 = aftd01 + aftd12
        deltaSatis += C[aft]*(aftd02*(aftd02-1)//2) - C[aft]*(aftd01*(aftd01-1)//2 + aftd12*(aftd12-1)//2)
    else:
        d01 = d
        d12 = Days+1 - d
        deltaSatis += C[aft] * Days*(Days+1)//2 - C[aft]*(d01*(d01-1)//2 + d12*(d12-1)//2)

    return deltaSatis


def update(Used, T, bef, aft, d):
    Used[bef].remove(d)
    inserted = False
    new = []
    for a in Used[aft]:
        if a > d and not inserted:
            inserted = True
            new.append(d)
        new.append(a)
    if not inserted:
        new.append(d)
    Used[aft] = new
    T[d-1] = aft+1
    return T, Used


def goingup(T, Used):
    d = random.randint(1, Days)
    bef = T[d-1]-1
    aft = random.randint(0, 25)

    if bef == aft:
        return T, Used

    if modifiedScore(d, aft, Used, T) > 0:
        T, Used = update(Used, T, bef, aft, d)
    return T, Used



def main():
    T = greedy()
    Satisfied, Used = outputToScore2(T)

    while time.time() - START < TIMELIMIT:
        T, Used = goingup(T, Used)
        
    print(*T, sep="\n")


def test():
    T = [int(input()) for _ in range(Days)] 
    Q = int(input())
    Query = [list(map(int, input().split())) for _ in range(Q)]
    Satisfied, Used = outputToScore2(T)
    for d, aft in Query:
        aft -= 1
        bef = T[d-1]-1
        Satisfied += modifiedScore(d, aft, Used, T)
        T, Used = update(Used, T, T[d-1]-1, aft, d)
        print(Satisfied)


if __name__ == "__main__":
    main()

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

dt=[]
last=[-1]*26
v=0
for d in range(D):
    news=[s[d][i]+c[i]*(d-last[i])*(d-last[i]-1)//2 for i in range(26)]
    maxi=0
    tmp=-float('inf')
    for i in range(26):
        if tmp<news[i]:
            maxi=i
            tmp=news[i]
    last[maxi]=d
    v+=s[d][maxi]
    for i in range(26):
        v-=c[i]*(d-last[i])
    dt.append(maxi+1)

def score(T):
    last=[-1]*26
    v=0
    for d in range(D):
        v+=s[d][T[d]-1]
        last[T[d]-1]=d
        for i in range(26):
            v-=c[i]*(d-last[i])
    return v

v0=max(score(dt)+10**6,0)

for _ in range(6):
    for d in range(1,D):
        y=-1
        newdt=dt+[]
        for i in range(26):
            if dt[d]!=i+1:
                newdt[d]=i+1
                v1=max(score(newdt)+10**6,0)
                if v0<v1:
                    y=i+1
                    v0=v1
        if y!=-1:
            dt[d]=y

for i in dt:
    print(i)

Solution (Python):
import numpy as np

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

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

v = 0
cc =  np.array( [0]*26 )
last = np.array( [-1]*26 )
for d in range(D):
  cc += c
  av = s[d] - sum( cc ) + cc
  av2 = av + cc*min((D-d-1),6)
  m = max(av2)
  for t in range(26):
    if av2[t] == m:
      cc[t] = 0
      v += av[t]
      print(t+1)
      break

Solution (Python):
def score(c,s,t,lis):
    ans = 0
    lis = [0]*26
    ans += s[t-1]
    lis[t-1] = 0
    for j in range(26):
        if t-1 != j:
            lis[j] +=  1
            ans -= lis[j]*c[j] 
    return ans,lis

d = int(input())
c = list(map(int,input().split()))
s = [0]*d
for i in range(d):
    s[i] = list(map(int,input().split()))
lis = [0]*26
for i in range(d):
    ans = 0
    z = 0
    L = lis
    q = 0
    for j in range(26):
        y,p = score(c,s[i],j,L)
        if ans < y:
            ans = y
            z = j
            q = p
    print(z+1)
    lis = q