Problem:
   Problem Statement AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.   The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.  Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i} .  If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i , and at the end of each day d=1,2,...,D , the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d ) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0 . At the end of day d , the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)) .   Please schedule contests on behalf of AtCoder.
If the satisfaction at the end of day D is S , you will get a score of \max(10^6 + S, 0) .
There are 50 test cases, and the score of a submission is the total scores for each test case.
You can make submissions multiple times, and the highest score among your submissions will be your score.      Constraints  D = 365  Each c_i is an integer satisfying 0\leq c_i \leq 100 .  Each s_{d,i} is an integer satisfying 0\leq s_{d,i} \leq 20000 .         Input Input is given from Standard Input in the following format:  D  c_1  c_2  \cdots  c_{26}  s_{1,1}  s_{1,2}  \cdots  s_{1,26}  \vdots  s_{D,1}  s_{D,2}  \cdots  s_{D,26}       Output Let t_d ( 1\leq t_d \leq 26 ) be the type of the contest that will be held at day d .
Print D integers t_d to Standard Output in the following format:  t_1  t_2  \vdots  t_D   Any output that does not follow the above format may result in 0 points WA for that test case.      Input Generation Each integer c_i and s_{d,i} is generated independently and uniformly at random from the integers in the range described in the problem statement.        Sample Input 1 5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192      Sample Output 1 1
17
13
14
13  Note that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case. The final satisfaction with this output is 79325, so the score is 1079325.  Input generator, score calculator, and visualizer      Beginner's Guide If you don't know what to do, proceed to problem B or C.

Solution (Python):
import sys
from random import randint
input = sys.stdin.readline
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [randint(0, 25) for i in range(D)]
last = [0] * 26
def score(day, score):
  for i in range(26): score -= (day - last[i]) * c[i]
  return score
def run(day):
  global last
  last = [0] * 26
  res = 0
  for d in range(day):
    contest = t[d]
    last[contest] = d + 1
    res = score(d + 1, res) + s[d][contest]
  return res


for d in range(1, D + 1):
  mx = -float("inf")
  mxx = randint(0, 25)
  for x in range(26):
    t[d - 1] = x
    res = run(d)
    if mx < res:
      mx = res
      mxx = x
  t[d - 1] = mxx

for _ in range(75):
  l = randint(1, 365)
  last = [0] * 26
  run(l)
  
  zmx = -float("inf")
  zmxz = 0
  for z in range(26):
    t[l - 1] = z

    for d in range(l + 1, D + 1):
      mx = -float("inf")
      mxx = t[d - 1]
      for x in range(26):
        t[d - 1] = x
        res = score(d, 0) + s[d - 1][x]
        if mx < res:
          mx = res
          mxx = x
      t[d - 1] = mxx
      last[mxx] = d
    zres = run(D)
    if zres > zmx:
      zmx = zres
      zmxz = z
  t[l - 1] = zmxz

for x in t: print(x + 1)

Solution (Python):
t=1
for i in range(365):
  print(t)
  if t == 26:
    t = 1
  else:
    t +=1

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=[1]*d
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.8:
    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)
    if newans<oldans:
        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):
import time
import random

def check(j,r):
    global point
    last=[0]*26
    sum_=0
    t=ans.copy()
    t[j]=r
    for i in range(D):
        d=i+1
        sum_+=s[i][t[i]]
        for k in range(26):
            if t[i]==k:
                continue
            sum_-=c[k]*(d-last[k])
        last[t[i]]=d
    if sum_>point:
        point=sum_
        return True
    else:
        return False

start=time.time()
INF=10**30
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
last=[0]*26
ans=[]
point=0
for i in range(D):
    d=i+1
    res=-INF
    z=-1
    for j in range(26):
        p=s[i][j]
        for k in range(26):
            if k==j:
                continue
            p-=c[k]*(d-last[k])
        res=max(res,p)
        if res==p:
            z=j
    ans.append(z)
    last[z]=i+1
    point+=res
while True:
    if time.time()-start>1.80:
        break
    for i in range(D):
        if time.time()-start>1.80:
            break
        r=random.randrange(26)
        if check(i,r):
            ans[i]=r
for i in range(D):
    print(ans[i]+1)

Solution (Python):
from collections import Counter
import sys
from random import randint
from time import time
start = time()
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline


def get_sat():
    sat = 0
    when = [-1] * 26
    for i in range(d):
        sat += s[i][t[i]]
        when[t[i]] = i
        for j in range(26):
            sat -= c[j] * (i - when[j])
    return sat


d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [randint(0, 25) for i in range(d)]
ans = get_sat()
while time() - start < 1.8:
    p, q = randint(0, d - 1), randint(0, 25)
    x = t[p]
    t[p] = q
    y=get_sat()
    if ans >= y:
        t[p] = x
    else:
        ans=y
for i in t:
    print(i + 1)

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

from random import randrange
from itertools import accumulate
from bisect import bisect_left
import time


def calc(LIST):
    ans=0
    last=[0]*26
    for i in range(len(LIST)):
        a=i+1 
        x=LIST[i]-1
        
        ans+=S[i][x]
        
        last[x]=a
        temp=0
        for j in range(26):
            temp+=C[j]*(a-last[j])
        
        ans-=temp
        

    return ans

def answerer(c):
    """
    
    最初にですが乱択をします。ただし、CとDの積に応じてあたりやすさをでかくします
    """
    acc=list(accumulate(c))
    ret=[]
    for d in range(D):
        acc=list(accumulate(c))
        miru=[]
        for i in range(len(c)):
            miru.append(acc[i]+S[d][i])
        temp=randrange(0,miru[-1])
        s=bisect_left(miru,temp)
        ret.append(s+1)

        
    return ret

def resolve():
    global D,C,S
    
    D,=pin()
    C=[*pin()]
    S=[[*pin()]for i in range(D)]
    answerer(C)


    
    start=time.time()
    king=[1]*365
    max_score=calc(king)
    

    while(time.time()-start<1.8):
        temp=answerer(C)
        challenge=calc(temp)
        if challenge>max_score:
            max_score=challenge
            king=temp[:]
        

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

resolve()

Solution (Python):
D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
  tmp = [int(j) for j in input().split()]
  s.append(tmp)
  
sat = 0
lst = [0 for i in range(26)]

for i in range(D):
  satlst = [0 for j in range(26)]
  for j in range(26):
    sattmp = sat + s[i][j]
    for k in range(26):
      if j != k:
        sattmp -= c[k] * ((i + 1) - lst[k])
    satlst[j] = sattmp
  sat = max(satlst)
  lst[satlst.index(sat)] = (i + 1)
  print(satlst.index(sat) + 1)

Solution (Python):
import numpy as np
from time import time
start = time()
def scoring(c,s,t):
    score = 0
    from_last = np.zeros(26)
    for i in range(s.shape[0]):
        from_last = from_last+1
        score += s[i,t[i]-1]
        from_last[t[i]-1] = 0
        score = score - (c*from_last).sum()
    return score



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

from_last = np.zeros(26)
t = []
for i in range(D):
    from_last = from_last+1
    chosen = (s[i,:]-c*from_last).flatten().argmax()+ 1
    from_last[chosen-1] = 0
    t.append(chosen)

freq = np.zeros(26)
for i in t:
    freq[i-1] += 1
w = c*(365-freq)
num = np.arange(1,27)
score = scoring(c,s,t)
while time()-start < 1.85:
    i = np.random.randint(D)
    old = t[i]
    t[i] = np.random.choice(num, p = w/w.sum())
    new_score = scoring(c,s,t)
    if new_score > score:
        score = new_score
        w[t[i]-1] -= c[t[i]-1]
        w[old-1] += c[old-1]
    else:
        t[i] = old


for i in t:
	print(i)

Solution (Python):
for i in range(365):print(i%26+1)

Solution (Python):
from random import randrange

def score(c,s,t):
    ans = 0
    scorelast = [0] * 26
    for i in range(d,365):
        ans += s[i][t[i]]
        scorelast[t[i]] = i + 1
        for j in range(26):
            ans -= c[j] * (i + 1 - scorelast[j])
    return ans

def diffscore(old,q,c,s,t):
    cq = c[q]
    scorelast = [0] * 2
    diff = 0
    for i in range(365):
        if t[i] == q:
            diff += s[i][q]
            scorelast[0] = i + 1
        elif t[i] == old:
            diff += s[i][old]
            scorelast[1] = i + 1
        diff -= cq * (i + 1 - scorelast[0])
        if cq != old:
            diff -= c[old] * (i + 1 - scorelast[1])

    return diff
D = int(input())
c = list(map(int,input().split()))
s = []
for i in range(D): s.append(list(map(int,input().split())))
d = 0
t = []
last = [-1] * 26
for i in range(D):
    maximum = 0
    maxs = 0
    for j in range(26):
        if maximum < s[i][j] + c[j] * (i - last[j]):
            maxs = j
            maximum = s[i][j] + c[j] * (i - last[j])
    last[maxs] = i
    t.append(maxs)

for i in range(100000):
    d = randrange(D)
    q = randrange(26)
    old = t[d]
    before = diffscore(old,q,c,s,t)
    t[d] = q
    if before > diffscore(old,q,c,s,t): t[d] = old
for i in t: print(i + 1)

Solution (Python):


from time import perf_counter
tick = perf_counter() + 1.80

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

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

    def update(di, qi):
        T1, L1 = T[:], L[:]

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

        L1[t0] = 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)

        L1[qi] = 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, T1, L1

    score = 0
    x = (1+D)*D//2
    for i in range(D):
        score += S[i][0]
        L[0].append(i)

    for i in range(1, 26):
        score -= C[i] * x

    while perf_counter() < tick:
        diff, T1, L1 = update(randrange(0, D), randrange(0, 26))
        if diff > 0:
            score += diff
            T, L = T1, L1

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

if __name__ == "__main__":
    resolve()

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





typ=0
ans=0


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

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

Solution (Python):
from collections import deque
days = int(input())
clast = list(map(int,input().split()))


def scoreing(givenlist):
    global days,clast,allpref
    resultlist = []
    result = 0
    donelist = [deque([0])]*26
    for i in range(days):
        held = givenlist[i]

        donelist[held-1].append(i+1)
        zanen = sum([clast[j]*((i+1)-donelist[j][-1]) for j in range(26)])

        result += allpref[i][held-1] - zanen
        resultlist.append(result)
    donelist.append(resultlist[days-1])
    return donelist

allpref = [] 
for i in range(days):
    allpref.append(list(map(int,input().split())))
donelist = [0]*26
contestlist = []
for i in range(days):
    max = -10**10
    result = 0
    contest = False
    for held in range(26):
        tempdonelist = donelist[:]
        tempdonelist[held] = i+1
        zanen = sum([clast[j]*((i+1)-tempdonelist[j]) for j in range(26)])
        result = allpref[i][held] - 0.5*zanen
        if result >= max:
            max = result;contest = held


    donelist[contest] = i+1
    contestlist.append(contest+1)

for cont in contestlist:
    print(cont)

Solution (Python):
d = int(input())
c = list(map(int, input().split()))
score = []
for i in range(d):
    score.append(list(map(int, input().split())))
last_day = [0 for i in range(26)]
k = 0
for i in range(d):
    ans = 0
    max_score = -10**9
    for j in range(1, 27):
        s = score[i][j-1]
        for k in range(1,27):
            if j == k:
                continue
            else:
                s -= c[k-1] * (i+1 - last_day[k-1])
        if s > max_score:
            ans = j
            max_score = s
    last_day[ans-1] = i+1
    print(ans)

Solution (Python):
import sys,collections as cl,bisect as bs,random
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
	return list(map(int,input().split()))
def m(): 
	return map(int,input().split())
def onem(): 
	return int(input())
def s(x): 
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): 
	return " ".join(map(str,x))
def max2(x): 
	return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

d = onem()

c = l()

s = []
sel = [0 for i in range(365)]

day = [[0 for i in range(26)] for j in range(365)]
ans = 0
for i in range(d):
	s.append(l())
	ss = [[s[-1][i],i+1] for i in range(26)]

	ak = 0

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

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



for _ in range(140000):
	ima = random.randrange(365)
	po = [[s[ima][i]-c[i],i+1] for i in range(26)]
	po.sort(reverse = True)
	while True:
		data = random.randrange(10)
		if sel[ima] != data+1:
			break
	data = po[data][1]-1
	ppp = 0
	for i in range(26):
		if ima == day[ima][i]:
			now = i
			break
	else:
		while True:
			now = random.randrange(26)
			if now != data:
				break 
	for i in range(ima+1,365):
		if day[i][data] == i:
			ppp += (i - ima) * c[data]
			break
	else:
		ppp += (364-ima) * c[data]

	for i in range(ima+1,365):
		if day[i][now] == i:
			ppp -= (i - ima) * c[now]
			break
	else:
		ppp -= (364-ima) * c[now]
	if ppp > 0:
		for i in range(ima,365):
			if day[i][data] != i:
				day[i][data] = ima
			else:
				break
		po = ima - 1 if ima != 0 else 0
		for i in range(ima,365):
			if day[i][now] != i:
				day[i][now] = po
			else:
				break
		sel[ima] = data+1
		ans += ppp

for i in sel:
	print(i)

Solution (Python):
import random

NTEST = 26

D=int(input())

C=list(map(int,input().split()))

SL=list()
SL.append([0 for i in range(NTEST)])
for d in range(D):
    S=list(map(int,input().split()))
    SL.append(S)

def calcSat(test_applied):
    lastDay = [0 for i in range(NTEST)]

    sat = 0
    for d in range(1,D+1):
        tst = test_applied[d] - 1
        lastDay[tst] = d
        sat += SL[d][tst]
        for itst in range(NTEST):
            sat -= C[itst] * (d-lastDay[itst])
    return sat

satList = list()
satList.append(0)

def calcSat_with_memo(test_applied, lastDay):

    total_sat = 0
    for d in range(1,D+1):
        lastDay.append(list(lastDay[d-1]))
        sat = 0
        tst = test_applied[d] - 1
        lastDay[d][tst] = d
        sat += SL[d][tst]
        for itst in range(NTEST):
            sat -= C[itst] * (d-lastDay[d][itst])
        satList.append(sat)
        total_sat += sat

    return total_sat

def recalcSat_with_memo(total_sat_before, tday, t_from, t_to, test_applied, lastDay):

    d_total_sat = 0

    lastDay[tday][t_from -1]=lastDay[tday-1][t_from -1]
    d_sat=0
    d_sat += (SL[tday][t_to -1]-SL[tday][t_from -1])
    d_sat += C[t_to -1]*(tday - lastDay[tday][t_to -1])
    d_sat -= C[t_from -1]*(tday - lastDay[tday][t_from -1])

    lastDay[tday][t_to -1]=tday

    satList[tday]+= d_sat
    d_total_sat  += d_sat

    old_last = tday
    new_last = lastDay[tday][t_from -1]
    for d in range(tday+1,D+1):
        if test_applied[d] == t_from :
            break
        d_sat = C[t_from -1]*(- old_last + new_last)
        lastDay[d][t_from -1] = new_last
        satList[d]+= d_sat
        d_total_sat += d_sat

    old_last = lastDay[tday-1][t_to -1]
    new_last = tday
    for d in range(tday+1,D+1):
        if test_applied[d] == t_to :
            break
        d_sat = C[t_to -1]*(- old_last + new_last)
        lastDay[d][t_to -1] = new_last
        satList[d]+= d_sat
        d_total_sat += d_sat
            
    return d_total_sat






tests=list()
tests.append(0)
for d in range(D):
    tests.append((d % 26) +1)

lastDay = [[0 for i in range(NTEST)]]

sat = calcSat_with_memo(tests,lastDay)


for i in range(10000):
    day = random.randint(1,D) 
    new_tst = random.randint(1,NTEST)

    trial = list(tests)
    new_lastDay = list(lastDay)

    d_sat = recalcSat_with_memo(sat, day, tests[day], new_tst, trial, new_lastDay)

    if d_sat > 0:
        sat += d_sat
        tests[day] = new_tst
        lastDay = new_lastDay
        

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

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
import random
import time
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def scorei(ti, i, last, minus):
        k = [i for i in last]
        mi = minus-(i+1-last[ti])*c[ti]
        v = s[i][ti]-mi
        mi += sum_
        k[ti] = i+1
        return v, k, mi

    def score(t):
        n = 26
        v = 0
        minus = sum_ = sum(c)
        last = [0]*n
        for i in range(d):
            ti = t[i]-1
            minus -= (i+1-last[ti])*c[ti]
            v += s[i][ti]-minus
            minus += sum_
            last[ti] = i+1
        return v
    start = time.time()
    d = I()
    c = LI()
    s = LIR(d)
    n = 26
    m = 20000
    sum_ = sum(c)
    q = [(0, 0, [0]*n, sum_)]
    pre = [[None]*n for i in range(d)]
    sc = [[float("inf")]*n for i in range(d)]
    argmax = 0
    for i in range(d):
        nq = []
        for _ in range(m):
            if not q:
                break
            v, x, last, minus = heappop(q)
            if i > 0 and v > sc[i-1][x]:
                continue
            for ti in range(n):
                vi,nl,nm = scorei(ti,i,last,minus)
                nv = v-vi
                heappush(nq,(nv,ti,nl,nm))
                if sc[i][ti] > nv:
                    sc[i][ti] = nv
                    pre[i][ti] = x
        q = [i for i in nq]
    t = []
    argmax = 0
    m = sc[-1][0]
    for i in range(1,n):
        sci = sc[-1][i]
        if m > sci:
            m = sci
            argmax = i
    t.append(argmax)
    x = argmax
    for i in range(1,d)[::-1]:
        y = pre[i][x]
        t.append(y)
        x = y
    t = [i+1 for i in t[::-1]]
    v = score(t)
    i = 0
    while time.time() < 1.8+start:
        nt = [i for i in t]
        r = random.randrange(1,n+1)
        nt[i] = r
        nv = score(nt)
        if v < nv:
            t = [i for i in nt]
            v = nv
        i += 1
        i %= d
    for i in t:
        print(i)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
from random import randint

D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(D)]

def score_calc(T):
    total = 0
    last = [0] * 26
    for i in range(1, D+1):
        t = T[i-1]
        total += S[i-1][t-1]
        last[t-1] = i
        for j in range(26):
            total -= C[j] * (i - last[j])
    return total

total = 0
last = [0] * 26
ans = []
for i in range(1, D+1):
    score = [0] * 26
    for t in range(26):
        score[t] += S[i-1][t]
        for j in range(26):
            if j != t:
                score[t] -= C[j] * (i - last[j])
    total += max(score)
    last[score.index(max(score))] = i
    ans.append(score.index(max(score))+1)

N = 20000
Q = [[randint(0, (D-1)), randint(0, 25)] for i in range(N)]
for d, q in Q:
    old = ans[d]
    ans[d] = q + 1
    if score_calc(ans) > total:
        total = score_calc(ans)
    else:
        ans[d] = old

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

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import numpy as np

d = ni()
c = na()
s = []

for i in range(d):
    ss = na()
    s.append(ss)

c = np.array(c) 
s = np.array(s) 
s_t = s.T 
last = np.zeros(26)




def eva(n, cc, ss):
    r = np.random.rand()/2+1
    return (d-n)*cc + 30*ss

score = 0

for i in range(d): 
    last += 1 
    tow = c * last 
    sc = -100000
    M = -1
    for j in range(26):
        k = eva(i, tow[j], s[i][j])
        if sc < k:
            sc = k
            M = j
    last[M] = 0
    score -= np.dot(c,last)
    score += s[i][M]
    print(M+1)

Solution (Python):
import numpy as np

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

s=np.array(s,dtype=int).reshape((D,26))
dt=[]
cnt=np.array([0]*26)

for d in range(D):
    y=np.argmax(c*(d-cnt))
    cnt[y]=d+1
    dt.append(y+1)

for i in dt:
    print(i)

Solution (Python):
import bisect
import time

start = time.time()

D = int(input())
c = [0] + list(map(int, input().split()))
s = [0] + [[0] + list(map(int, input().split())) for _ in range(D)]
sch, held = [0], [[0] for _ in range(27)]

for d in range(1, D+1):
    SLvar = [s[d][i] + c[i] * (d - held[i][-1]) for i in range(1, 27)]
    t = SLvar.index(max(SLvar)) + 1
    sch.append(t)
    held[t].append(d)

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

s_sort = [0] + [[0] + sorted([[s[d][i], i] for i in range(1, 27)], key=lambda x: x[0], reverse=True) for d in range(1, D+1)]

i, j = 1, 1
while time.time() - start < 1.8 and i <= D and j < 27:
    d, q = i, s_sort[i][j][1]

    if sch[d] != q:
        SLvar = s[d][q] - s[d][sch[d]]

        ind_p = bisect.bisect_left(held[sch[d]], d)
        k = d - held[sch[d]][ind_p-1]
        l = held[sch[d]][ind_p+1] - d
        SLvar -= c[sch[d]] * k * l

        ind_n = bisect.bisect_left(held[q], d)
        k = d - held[q][ind_n-1]
        l = held[q][ind_n] - d
        SLvar += c[q] * k * l

        if SLvar > 0:
            del held[sch[d]][ind_p]
            held[q].insert(ind_n, d)
            sch[d] = q

    i += 1
    if i > D:
        i = 1
        j += 1

for i in range(1, D+1):
    print(sch[i])

Solution (Python):


import sys
read = sys.stdin.read
readline = sys.stdin.readline
import time


_, = map(int,readline().split())
D = 365
*c, = map(int,readline().split())
s = tuple(tuple(map(int,readline().split())) for _ in range(D))

def output(ans):
    for i in ans: print(i+1)

def score(ans,s,c): 
    last = [-1]*26
    score = 0
    for i, ai in enumerate(ans):
        score += s[i][ai]
        last[ai] = i
        for ci,li in zip(c,last):
            score -= ci*(i-li)
        
    return score





def first_solution(s,c):
    minus = c[:]
    ans = [0]*365
    for i, si in enumerate(s):
        ans[i] = idx = max(range(26), key=lambda x:si[x]+minus[x])
        for i in range(26):
            minus[i] += c[i]
        minus[idx] = 0
    return ans        


"""
solution = 初期解(ランダム生成や、貪欲法など他の手法で求めたものを利用)
while 時間のある限り:
    solution を(ランダムに)少し変形
    if 変形前より解が悪化:
        solution を変形前の状態に戻す
"""


from bisect import bisect_left, bisect_right
"""
i 日目と i+1 日目を入れ替え
"""
def swap(i,ans,days,c,s):
    j = i+1
    ai = ans[i]
    aj = ans[j]
    di = days[ai]
    dj = days[aj]
    idx_i = bisect_left(di,-i)
    idx_j = bisect_left(dj,-j)
    
    
    
    
    
    i_prev = -di[idx_i - 1]
    i_next = -di[idx_i + 1] if di[-1] != -i else -1

    j_prev = -dj[idx_j - 1]
    j_next = -dj[idx_j + 1] if dj[-1] != -j else -1

    delta_i = -c[ai]*(2*i-i_prev-i_next) + s[j][ai] - s[i][ai]
    delta_j = -c[aj]*(j_prev+j_next-2*i) - s[j][aj] + s[i][aj]
    

    return delta_i + delta_j,idx_i,idx_j


def main(ans,s,c):
    from random import randrange,random
    from math import exp
    best = ans[:]
    start = time.time()
    days = [[-365] for _ in range(26)]
    for i in range(364,-1,-1):
        days[ans[i]].append(-i)

    while time.time() - start < 1.79:
        T = 200000*(max(2.0 - (time.time() - start),0.1))
        i = randrange(364)
        if ans[i] != ans[i+1]:
            delta,idx_i,idx_j = swap(i,ans,days,c,s)
            if delta > 0 or exp(-delta/T) >= random():
                days[ans[i]][idx_i] -= 1
                days[ans[i+1]][idx_j] += 1
                ans[i],ans[i+1] = ans[i+1],ans[i]
                if score(ans,s,c) > score(best,s,c):
                    best = ans[:]

        idx = randrange(26)
        a0 = ans[0]
        if a0 != idx:
            delta = s[0][idx] - s[0][a0] + c[a0]*(days[a0][-2]) - c[idx]*(days[idx][-1]+1)
            
            if delta > 0 or exp(-delta/T) >= random():
                ans[0] = idx
                days[idx].append(0)
                days[a0].pop()
                
                if score(ans,s,c) > score(best,s,c):
                    best = ans[:]
        
                

    return best


output(main(first_solution(s,c),s,c))

Solution (Python):

dd = int(input())
c = list(list(map(int, input().split())))
s = [[0]*26]*dd
v = [[0]*26]*dd
vs = [[-10000000]*26]*dd
vs1 = [[-10000000]*26]*dd
vs2 = [[-10000000]*26]*dd
vs3 = [[-10000000]*26]*dd
ans = [0]*dd
ans2 = [0]*dd
fdate = [0]*26
for i in range(dd):
    s[i] = list(list(map(int, input().split())))



for i in range(dd):

    for j in range(26):
        v[i][j] = s[i][j] + c[j] *(i-fdate[j]) *(i-fdate[j])
        if not i+1 == dd:
            vs[i][j] =s[i+1][j] + c[j] *(i-fdate[j]) *(i-fdate[j])- c[j] *(i-fdate[j]+1)
        if i+2 < dd:
            vs1[i][j] =s[i+2][j] + c[j] *(i-fdate[j]) *(i-fdate[j])- c[j] *(2*i-2*fdate[j]+3)
        if i+3 < dd:
            vs2[i][j] =s[i+3][j] + c[j] *(i-fdate[j]) *(i-fdate[j])- c[j] *(3*i-3*fdate[j]+6)
    vm = max(v[i])
    vsm = max(vs[i])
    vs1m = max(vs1[i])
    vs2m = max(v[i])


    maxv = -100000000
    for j in range(26):
        if maxv < v[i][j] and vs[i][j]<v[i][j]:
            maxv = v[i][j]
            ans[i]=j+1
    fdate[ans[i]-1] =i+1

for a in ans:
    print(a)