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 collections import defaultdict
from heapq import heappush, heappop
import sys
import numpy as np
from random import random
from time import perf_counter

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  


def debug(*x):
    print(*x, file=sys.stderr)


def solve(D, CS, S):
    "void()"
    time = perf_counter()

    answer = []
    last = [-1] * 26
    for i in range(D):
        dscore = np.zeros(26)
        for j in range(26):
            dscore[j] += S[i, j]
            dscore[j] -= sum(CS[k] * (i - last[k])
                             for k in range(26) if j != k)

        j = dscore.argmax()
        answer.append(j + 1)
        last[j] = i
    s = calcScore(answer, D, CS, S)

    bestscore = s
    bestanswer = answer

    ORIG_S = S.astype(np.float)
    while perf_counter() - time < 1.5:
        answer = []
        last = [-1] * 26
        k1 = random() * 0.2
        k2 = random()
        S = ORIG_S.copy()
        S[:-1] = S[:-1] - k1 * ORIG_S[1:]
        S[:-2] = S[:-2] - k2 * ORIG_S[2:]
        for i in range(D):
            dscore = np.zeros(26)
            for j in range(26):
                dscore[j] += S[i, j]
                dscore[j] -= sum(CS[k] * (i - last[k])
                                 for k in range(26) if j != k)

            j = dscore.argmax()
            answer.append(j + 1)
            last[j] = i
        s = calcScore(answer, D, CS, ORIG_S)
        if s > bestscore:
            
            bestscore = s
            bestanswer = answer
    print(*bestanswer, sep="\n")


def calcScore(answer, D, CS, S):
    last = [-1] * 26
    score = 0
    for i in range(D):
        j = answer[i] - 1
        score += S[i, j]
        last[j] = i
        score -= sum(CS[j] * (i - last[j]) for j in range(26))
    return score






def main():
    D = int(input())
    CS = list(map(int, input().split()))
    S = np.int16(read().split())
    S = S.reshape((D, 26))

    
    solve(D, CS, S)


def _test():
    import doctest
    doctest.testmod()
    as_input(T)
    main()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())
    input = f.readline
    read = f.read


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        
        
        from my_module import solve  
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()

Solution (Python):

from random import randint
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split()))for _ in range(d)]
for i in range(d):s.append(s[i][:])
for i in range(d):s.append(s[i][:])
def xyz(start):
  ans=[0]*d
  score=0
  for i in range(start,start+d,26):
    dd=set()
    uu=set()
    h=[]
    for j in range(i,min(i+26,start+d)):
      for k in range(26):
        h.append([s[j][k],j,k])
    h.sort(reverse=1)
    if randint(0,4)==0:del h[0]
    for t,j,k in h:
      if j in dd or k in uu:continue
      score+=t
      ans[j%d]=k
      dd.add(j)
      uu.add(k)
  return [score,ans]
score,ans=xyz(0)
for i in range(1,d):
  ss,aa=xyz(i)
  if ss>score:
    score,ans=ss,aa
for i in ans:print(i+1)

Solution (Python):

def choose(D, c, s, d, last, depth, p):
    maxpoint = -999999999
    maxnum = 0
    if depth > 0 and d < D:
        for i in range(26):
            point = p
            point += s[d][i]
            point += changepoint(c, d, i, last)*1
            nlast = []
            nlast.extend(last)
            nlast[i] = d
            z, point = choose(D, c, s, d+1, nlast, depth-1, point)
            if point > maxpoint:
                maxpoint = point
                maxnum = i
        return maxnum, maxpoint
    return 0, p


def changepoint(c, d, num, last):
    point = 0
    for j in range(26):
        if j != num:
            point -= c[j]*(d-last[j])
    return point


def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    last = [-1]*26
    for _ in range(D):
        s.append(list(map(int, input().split())))
    point = 0
    for i in range(D):
        num, point = choose(D, c, s, i, last, 1, 0)
        last[num] = i
        print(num+1)


main()

Solution (Python):
from bisect import bisect_left as bl 
from copy import deepcopy as dc
from time import time
from random import randint
start=time()
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for _ in range(D)]

T=[randint(1,26) for _ in range(D)]

for i in range(D):
    best=1
    bestscore=0
    for j in range(26):
        if S[i][j]>bestscore:
            best=j+1
            bestscore=S[i][j]
    T[i]=best


last=[[0] for _ in range(26)]
score=[0]*D
for i in range(D):
    contest=T[i]-1
    if i == 0:
        score[i]=S[i][contest]
    else:
        score[i]=score[i-1]+S[i][contest]
    last[contest].append(i+1)
    for j in range(26):
        blank=i+1-last[j][-1]
        score[i]-=blank*C[j]

def research(day,query,border):
    global last,T,score
    T2=T[:]
    last2=[[0] for _ in range(26)]
    for i in range(D):
        contest=T[i]-1
        last2[contest].append(i+1)
    score2=score[:]
    T2[day-1]=query+1
    for i in range(26):
        ind=bl(last2[i],day)
        last2[i]=last2[i][:ind]

    for i in range(day-1,D):
        contest=T2[i]-1
        if i == 0:
            score2[i]=S[i][contest]
        else:
            score2[i]=score2[i-1]+S[i][contest]
        last2[contest].append(i+1)
        for j in range(26):
            blank=i+1-last2[j][-1]
            score2[i]-=blank*C[j]
    if score2[-1]>=border:
        T=T2[:]
        last=dc(last2)
        score=score2[:]
    return

while time()-start<=1.5:
    research(randint(1,D),randint(0,25),score[-1])

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

Solution (Python):
import sys, time, random
ts = time.time()
import numpy as np

input = sys.stdin.readline

D = int(input())
c = np.array(list(map(int, input().split())), dtype=int)
S = np.array([list(map(int, input().split())) for _ in range(D)], dtype=int)
T = np.zeros(D, dtype=int)
dissatisfactions = np.zeros((D+1, 26), dtype=int)
v = 0


def findzero(a, after):
    try:
        return after+np.where(a[after:]==0)[0][0]
    except IndexError:
        return len(a)


for i, s in enumerate(S):
    dissatisfactions[i+1] = dissatisfactions[i] + c
    t = np.argmax(s+dissatisfactions[i+1])
    dissatisfactions[i+1, t] = 0
    T[i] = (t+1)
    v += s[t]
    v -= np.sum(dissatisfactions[i+1])

while time.time()-ts<1.8:
    
    d = np.random.randint(1, D)
    q = np.random.randint(1, 26)
    
    pre = T[d - 1]
    new = q
    pre0 = findzero(dissatisfactions[:, pre - 1], d + 1)
    new0 = findzero(dissatisfactions[:, new - 1], d + 1)

    
    diff = S[d - 1, new - 1] - S[d - 1, pre - 1] +(dissatisfactions[d, new - 1]) * (new0 - d) \
           - (dissatisfactions[d - 1, pre - 1] + c[pre - 1]) * (pre0 - d)
    if diff < 0:
        continue
    v += diff
    
    T[d - 1] = new
    dissatisfactions[d:new0, new - 1] -= dissatisfactions[d, new - 1]
    dissatisfactions[d:pre0, pre - 1] += dissatisfactions[d - 1, pre - 1] + c[pre - 1]


print('\n'.join([str(int(t)) for t in T]))

Solution (Python):

d=int(input())
c= list(map(int, input().split()))
D= [list(map(int, input().split())) for i in range(d)]
cc=[0]*26
for i in range(26):
    cc[i]=[c[i],i+1]
cc.sort(reverse=True)

ans=[0]*d

PL=[0]*26

for i in range(d):
    cnt=0
    cntt=-10**9
    x=1
    for k in range(len(c)):
        v=PL[:]
        cnt = D[i][cc[k][1]-1]
        v[cc[k][1]-1] = i+1
        for j in range(len(c)):
            cnt-=(i+1-v[j])*c[j]
        if cnt>cntt+10:
            x=cc[k][1]
            cntt=max(cnt,cntt)
    ans[i]=x
    PL[x-1]=i


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

Solution (Python):
d = int(input())
C = list(map(int, input().split()))
T = []
for i in range(d):
    S = list(map(int, input().split()))
    index = S.index(max(S))
    T.append(index+1)
for t in T:
    print(t)

Solution (Python):
def getLast(d, i):
    if last_d[i] == 0:
        return 0
    return d - last_d[i]

def calcC(d):
    res = 0
    for i in range(26):
        res = res + C[i] * getLast(d, i)
    return res

def getBestd(d):
    preLast_d = last_d[25]
    last_d[25] = d
    res = S[d][25] - calcC(d)
    last_d[25] = preLast_d
    res_i = 25
    now = 0
    for i in range(25):
        preLast_d = last_d[i]
        now = S[d][i] - calcC(d)
        last_d[i] = preLast_d
        if res < now:
            res = now
            res_i = i
    return res, res_i



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

score = 0

last_d = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

T = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]

resT = []

for d in range(D):
    now, i = getBestd(d)
    score = score + now
    last_d[i] = d
    resT.append(T[i])

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

Solution (Python):
dur=int(input())
c=list(map(int,input().split()))
d=[0]*26
r=4.17
for i in range(dur):
  t=0
  s=list(map(int,input().split()))
  m=-1<<64
  for j in range(26):
    alt=s[j]+r*c[j]*(i+1-d[j])+sum([-r*c[k]*(i+1-d[k]) for k in range(26)])
    if alt>m:
      m=alt
      t=j
  print(t+1)
  d[t]=i+1

Solution (Python):
import random
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def score(tt):
    ans=0
    for i,t in enumerate(tt):
        t-=1
        ans += ss[i][t]
        p = i - last[t]
        ans -= p * (p + 1) // 2 * cc[t]
        last[t] = i + 1
    for t in range(26):
        p = d - last[t]
        ans -= p * (p + 1) // 2 * cc[t]
    return ans

inf=10**16
d = II()
cc = LI()
ss = LLI(d)
ans = 0
last = [0] * 26
tt=list(range(1,27))*(d//26+1)
tt=tt[:d]
mx = score(tt)
for _ in range(20000):
    i=random.randrange(d)
    best=tt[i]
    for j in range(1,27):
        tt[i]=j
        cur=score(tt)
        if cur>mx:
            mx=cur
            best=j
    tt[i]=best

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

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

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def prob(e1,e2,T):
    if e2 < e1:
        return 1
    else:
        return np.exp((e1-e2)/T)

def solve():
    m = 26
    start = time.time()
    dT = 0.993
    T = 180
    D = ni()
    c = nl()
    s = [nl() for _ in range(D)]
    H = [None]*D
    for i in range(D):
        g = [s[i][j] + 25 * c[j] for j in range(m)]
        y = min(g)
        h = sum(g) - m * y
        g = [(x-y)/h for x in g]
        for j in range(1, m):
            g[j] += g[j-1]
        H[i] = g

    def calc(sche, m=26):
        last = [-1] * m
        ans = 0
        for i in range(D):
            t = sche[i]
            ans += s[i][t]
            last[t] = i
            for j in range(m):
                ans -= c[j] * (i - last[j])
        return ans

    def change(d, q, sc):
        b = sche[d]
        fq, bq = -1, D
        fb, bb = -1, D
        for i in range(d):
            if sche[i] == q:
                fq = i
            if sche[i] == b:
                fb = i
        for i in range(D-1, d, -1):
            if sche[i] == q:
                bq = i
            if sche[i] == b:
                bb = i
        sc += ((bb - d) * (bb - d - 1) // 2 + (d - fb) * (d - fb - 1) // 2) * c[b]
        sc += ((bq - fq) * (bq - fq - 1) // 2) * c[q]
        sc -= s[d][b]
        sc -= ((bq - d) * (bq - d - 1) // 2 + (d - fq) * (d - fq - 1) // 2) * c[q]
        sc -= ((bb - fb) * (bb - fb - 1) // 2) * c[b]
        sc += s[d][q]
        return sc

    sche = [0] * D
    for i in range(D):
        sche[i] = s[i].index(max(s[i]))
    sc = calc(sche)
    bestst = sche[:]
    best = sc

    while time.time() - start < 1.85:
        for _ in range(200):
            d = random.randint(0, D-1)
            q = bisect.bisect(H[d], random.random())
            nsc = change(d, q, sc)
            if best < nsc:
                bestst = sche[:]
                best = nsc
            if random.random() < prob(-sc, -nsc, T):
                sche[d] = q
                sc = nsc
        T *= dT
    prn([1 + x for x in bestst])
    return

solve()

Solution (Python):
import time
t1 = time.time()

def calc(T):
    res = 0
    L = [0]*26
    for i in range(D):
        res += S[i][T[i]-1]
        L[T[i]-1] = i+1
        for j in range(26):
            res -= C[j]*(i+1-L[j])
    return res

D = int(input())
C = [int(c) for c in input().split()]
S = [[int(s) for s in input().split()] for _ in range(D)]

T = [0]*D
for i in range(D):
    temp = -1
    for j in range(26):
        if temp < S[i][j]:
            temp = S[i][j]
            idx = j+1
    T[i] = idx

T2 = [0]*D
L = [0]*26
for i in range(D):
    p = -10**15
    for j in range(26):
        d = S[i][j]
        for k in range(26):
            if k == j:
                continue
            d -= C[k]*(i+1-L[k])
        if p < d:
            p = d
            idx = j+1
    T2[i] = idx

p1 = calc(T)
p2 = calc(T2)
if p2 > p1:
    T = T2
    p = p2
else:
    p = p1

i = D-1
next = -1
while time.time()-t1 < 1.9:
    temp = T[i]
    for j in range(1, 27):
        T[i] = j
        newp = calc(T)
        if p < newp:
            p = newp
            temp = j
    T[i] = temp
            
    i += next
    if i == -1:
        i = D-1

for t in T:
    print(t)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

import numpy as np
import time
import random
start = time.time()
D = int(input())
Cs = np.array(list(mapint()))
Ss = np.array([list(mapint()) for _ in range(D)], dtype=np.float64)
last = np.zeros(26, dtype=np.float64)
last += D

lis = []
for i in range(D):
    last_2 = last-i
    last_2.astype(np.float64)
    arr = Ss[i] + Cs*last_2
    idx = np.argmax(arr)
    last[idx] = i+1
    lis.append(idx+1)

def check(Ts):
    last_day = np.zeros(26)
    sati = 0
    for i in range(D):
        t = Ts[i]-1
        sati += Ss[i][t]
        last_day[t] = i+1
        sati += sum((last_day-(i+1))*Cs)
    return sati

now = check(lis)
while time.time()-start<1.7:
    lis_2 = lis[:]
    for i in range(2):
        num = random.randint(1, 26)
        num2 = random.randint(0, 364)
        if num==num2:
            continue
        lis_2[num2] = num
    nx = check(lis_2)
    if nx>now:
        lis = lis_2
        now = nx

for d in lis:
    print(d)

Solution (Python):
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())

D=N()
c=[0]+L()
s=[[0]*27]+[[0]+L() for i in range(D)]

dp=[]
T=[0]
ld=[0]*(27)
for i in range(1,D+1):
    ma=0
    t=0
    for j in range(1,27):
        tmp=s[i][j]+(i-ld[j])*(D-i+1)*c[j]
        if tmp>ma:
            ma=tmp
            t=j
    T.append(t)
    ld[t]=i
        
sc=sum(c)
def point():
    ld=[0]*(27)
    score=-sc*((D+1)*D//2)
    for i in range(1,D+1):
        t=T[i]
        score+=s[i][t]+(i-ld[t])*(D-i+1)*c[t]
        ld[t]=i
    return score

now=point()
import random
for i in range(250000):
    d1,q1=random.randrange(1,D+1),random.randrange(1,27)
    d2,q2=random.randrange(1,D+1),random.randrange(1,27)
    old1=T[d1]
    old2=T[d2]
    T[d1]=q1
    T[d2]=q2
    new=point()
    if new>now:
        now=new
    else:
        T[d1]=old1
        T[d2]=old2
for i in range(300000):
    d1,q1=random.randrange(1,D+1),random.randrange(1,27)

    old1=T[d1]

    T[d1]=q1

    new=point()
    if new>now:
        now=new
    else:
        T[d1]=old1

for i in T[1:]:
    print(i)

Solution (Python):
from time import time
from random import randrange
from bisect import bisect_left
import sys
def input():
	return sys.stdin.buffer.readline()[:-1]
start = time()
d = int(input())
c = list(map(int, input().split()))
C = sum(c)
s = [list(map(int, input().split())) for _ in range(d)]

t = []
day = [[0] for _ in range(26)]
order = []

def score(t):
	res = 0
	minus = 0
	last = [0 for _ in range(26)]
	for i, x in enumerate(t):
		minus += C - c[x-1] * (i - last[x-1] + 1)
		res -= minus
		res += s[i][x-1]
		last[x-1] = i+1
		
	return res

def tri(n):
	return n * (n-1) // 2

def change(i, to):
	diff = 0
	fr = t[i]-1
	
	
	if fr == to:
		return None
	fr_ind = bisect_left(day[fr], i+1)
	diff += (tri(day[fr][fr_ind] - day[fr][fr_ind-1]) + tri(day[fr][fr_ind+1] - day[fr][fr_ind])) * c[fr]
	diff -= (tri(day[fr][fr_ind+1] - day[fr][fr_ind-1])) * c[fr]
	diff -= s[i][fr]
	
	to_ind = bisect_left(day[to], i+1)
	diff += (tri(day[to][to_ind] - day[to][to_ind-1])) * c[to]
	diff -= (tri(day[to][to_ind] - (i+1)) + tri(i+1 - day[to][to_ind-1])) * c[to]
	diff += s[i][to]

	if diff > -1000:
		day[fr].pop(fr_ind)
		after = day[to][:to_ind] + [i+1] + day[to][to_ind:]
		day[to] = after
		t[i] = to+1
		
		
		
		return diff
	else:
		return None


res = 0
minus = 0
last = [0 for _ in range(26)]
for i in range(d):
	minus += C
	li = sorted(list(range(26)), key=lambda x: - c[x] * (i - last[x] + 1) - s[i][x])
	order.append(li)
	M_ind = li[0]
	minus -= c[M_ind] * (i - last[M_ind] + 1)
	last[M_ind] = i+1
	res -= minus - s[i][M_ind]
	t.append(M_ind+1)
	day[M_ind].append(i+1)

for i in range(26):
	day[i].append(d+1)





priority = [0 for _ in range(d)]
while time() - start < 1.8:
	i = randrange(d)
	pr = randrange(max(0, priority[i]-4), min(26, priority[i]+3))
	diff = change(i, order[i][pr])
	if diff is not None:
		res += diff
		priority[i] = pr

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

Solution (Python):
import random
D = int(input())
C = list(map(int, input().split()))

for i in range(D):
    input()













j = 27
for i in range(D):
    c = 26
    while(True):
        j -= 1
        c -= 1
        if C[j-1] > 0 :
            break
        if c == 0:
            break
        if j == 1:
            j = 27
    print(j)
    if j == 1:
        j = 27

Solution (Python):
import numpy as np
D = int(input())
s = [input() for i in range(D+1)]
for i in range(0,D+1):
    s[i] = s[i].split()
    s[i] = [int(p) for p in s[i]]
a = []
b = [0]*len(s[0])
S = 0
for i in range (1,D+1):
    ak = []
    for k in range(0,len(s[0])):
        Sk = S
        n = [0]*len(s[0])
        for j in range(0,len(s[0])):
            if j == k:
                n[j] = 0
            else:
                n[j] = b[j] + s[0][j]
        Sk = Sk + s[i][k] - sum(n)
        ak.append(Sk)
    mx = np.argmax(ak)
    an = [0]*len(s[0])
    for j in range(0,len(s[0])):
            if j == k:
                an[j] = 0
            else:
                an[j] = b[j] + s[0][j]
    S = S + s[i][mx] - sum(an)
    a.append(mx+1)
for i in (a):
    print(i)

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


t = []
memo = [0 for _ in range(26)]
for i in range(d):
    scores = []
    for j in range(26):
        delta_score = 0
        delta_score += s[i][j]
        for k in range(26):
            if j == k:
                continue
            delta_score -= c[k] * (i+1 - memo[k])
        scores.append((delta_score, j))

    scores.sort(key=lambda x: -x[0])
    choice = scores[0][1]
    t.append(choice)
    memo[choice] = i+1


def delta_scoring(t, x, y):
    delta_score = 0
    before_ti, after_ti = 0, d+1
    before_y, after_y = 0, d+1

    for i in range(x):
        if t[i] == t[x]:
            before_ti = i+1
        if t[i] == y:
            before_y = i+1

    for i in range(x+1, d):
        if t[i] == t[x]:
            after_ti = i+1
            break
    for i in range(x+1, d):
        if t[i] == y:
            after_y = i+1
            break

    delta_score -= s[x][t[x]]
    delta_score += s[x][y]
    delta_score -= c[t[x]] * (x + 1 - before_ti) * (after_ti - x - 1)
    delta_score += c[y] * (x + 1 - before_y) * (after_y - x - 1)

    return delta_score

for _ in range(10 ** 5):
    x = random.randint(0, d-1)
    y = random.randint(0, 25)
    if delta_scoring(t, x, y) > 0:
        t[x] = y


for i in range(d):
    print(t[i] + 1)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

D = int(input())
C = list(map(int,input().split()))
S = [list(map(int,input().split())) for _ in range (D)]
M = 26
INF = 10**20

def judge(t,idx,val):
    last = [0]*M
    minus = [0]*M
    score = 0
    for i in range(D):
        ti = t[i]
        if i==idx:
            ti = val
        score += S[i][ti-1]
        last[ti-1] = i+1
        for m in range(M):
            temp = C[m]*(i+1-last[m])
            score -= temp
            minus[m] -= temp
    return score, minus

from random import randint
import time
start = time.time()
ans = [0]*D
lasts = [0]*(M+1)


score = 0
for i in range(D):
    contest = 0
    max_score = -INF
    for m in range(M):
        new_score = score
        new_score += S[i][m]
        for m2 in range(M):
            if m==m2:continue
            new_score -= C[m2]*(i+1-lasts[m2])
        if new_score>max_score:
            contest = m+1
            max_score = new_score
    
    ans[i] = contest
    lasts[contest-1] = i+1
    score = max_score

minus = [0]*M
while (time.time()-start<1.7):
    
    idx = randint(0,D-1)

    
    key = [i+1 for i in range(M)]
    mc = zip(minus, key)
    mc = sorted(mc)
    minus, key = zip(*mc)
    val_ = randint(0, 3)
    val = key[val_]
    
    new_score, minus = judge(ans, idx, val)
    if new_score>score:
        score = new_score
        ans[idx] = val  

for a in ans:
    print(a)

Solution (Python):
import numpy as np

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

Ss = np.array(Ss)


def scoring(solution):
    sat = 0
    last = [0] * 26
    for d in range(D):
        assert 1 <= solution[d] <= 26
        j = solution[d] - 1
        last[j] = d + 1
        for i in range(26):
            sat -= (d + 1 - last[i]) * Cs[i]
        sat += Ss[d][j]
    return sat


def update_days_till_next(days_till_next, solution, d, erase=False):
    contest = solution[d]
    delta = days_till_next[d + 1, contest] + 1 if d < D - 1 else 0
    days_till_next[d, contest] = delta
    for _d in range(d - 1, -1, -1):
        if solution[_d] == contest or _d == 0:
            days_till_next[_d:d, contest] = (d - _d) - np.arange(d - _d) + (delta if erase else 0)
            break


def get_solution(seed):
    solution = np.array(seed)
    days_till_next = np.ones_like(Ss) * (D - 1) - np.arange(D).reshape((D, 1))
    for d in range(D - 1, -1, -1):
        update_days_till_next(days_till_next, solution, d)

    for _ in range(150):
        n_contests = len(Ss[0])
        days_since_last = np.zeros(n_contests)
        for d, i in enumerate(solution):
            days_since_last += 1
            new_scores = days_till_next[d] * days_since_last * Cs + Ss[d]
            new_i = new_scores.argmax()
            days_since_last[new_i] = 0
            if new_i != i:
                update_days_till_next(days_till_next, solution, d, erase=True)
                solution[d] = new_i
                update_days_till_next(days_till_next, solution, d)

    return solution


def get_best_solution():
    seeds = [np.argmax(Ss + Cs.reshape(1, -1) * e, axis=1) for e in [100, 400, 1600, 6400, 25600]]
    best_sol = None
    best_score = -np.inf
    for seed in seeds:
        sol = get_solution(seed) + 1
        score = scoring(sol)
        if score > best_score:
            best_sol = sol

    return best_sol


solution = get_best_solution()


for s in solution:
    print(s)

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

fuman=[]
for i in range(26):
    fuman.append(c[i]*66795)

for i in range(d):
    p=fuman.index(max(fuman))
    if s[i][p]>10000:
        print(p+1)
        q=364-i
        fuman[p]=(q**2+q)*c[p]//2
        for j in range(26):
            if j!=p:
                fuman[j]-=c[j]*(i+1)
    else:
        p=s[i].index(max(s[i]))
        print(p+1)
        q=364-i
        fuman[p]=(q**2+q)*c[p]//2
        for j in range(26):
            if j!=p:
                fuman[j]-=c[j]*(i+1)

Solution (Python):
import sys
input=sys.stdin.readline
import time
import random
from bisect import bisect_left


def query(p,q,d):
    b=bisect_left(play[p],d)
    bp=play[p][b-1]
    np=play[p][b+1]
    minus=((0+np-d)*(np-d+1)//2*c[p])-((np-bp+d-bp)*(d-np)//2*c[p])
    b=bisect_left(play[q],d)
    bp=play[q][b-1] if b!=0 else 0
    np=play[q][b+1] if b!=len(play[q])-1 else 366
    plus=((np-bp+d-bp)*(d-np)//2*c[q])-((0+np-d)*(np-d+1)//2*c[q])
    if plus-minus>0:
        play[p].remove(d)
        play[q].append(d)
        play[q].sort()
        t[d]=q
start=time.time()
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
t=[random.randrange(26) for i in range(D)]
play=[[-1]*D for i in range(26)]
for i in range(D):
    play[t[i]].append(i)
for i in range(26):
    play[i].append(366)
while(True):
    if time.time()-start>1.70:
        break
    for i in range(D):
        if time.time()-start>1.70:
            break
        q=random.randrange(26)
        p=t[i]
        query(p,q,i)
for i in range(D):
    print(t[i]+1)