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
input = sys.stdin.readline
import random
import time
import copy
from operator import itemgetter
time0=time.time()

D=int(input())
C=[0]+list(map(int,input().split()))
S=[0]+[[0]+list(map(int,input().split())) for i in range(D)]


CI=sorted([(v,i) for i,v in enumerate(C)],key=itemgetter(0),reverse=True)
CHO=[i for v,i in CI[:4]]

CHOICES=[[0]]
for i in range(1,D+1):
    SI=sorted([(v,i) for i,v in enumerate(S[i])],key=itemgetter(0),reverse=True)
    CHOICES.append([i for v,i in SI[:4]])
    
ANS=0
T=[0]
LAST=[0]*27
for day in range(1,D+1):
    SCORE=[-1<<30]*27
    for j in range(1,27):
        SC=0
        SC+=S[day][j]

        for k in range(1,27):
            if j==k:
                continue
            SC-=C[k]*(day-LAST[k])
        SCORE[j]=SC

    choose=SCORE.index(max(SCORE))
    T.append(choose)
    LAST[choose]=day

ANS=0
LAST=[[0]*27 for i in range(D+1)]
for day in range(1,D+1):
    for j in range(1,27):
        LAST[day][j]=LAST[day-1][j]
    t=T[day]
    ANS+=S[day][t]
    LAST[day][t]=day

    for j in range(1,27):
        ANS-=C[j]*(day-LAST[day][j])

MAX=ANS
MAXT=copy.deepcopy(T)
d=0
after_t=0

while time.time()-time0<1.8:
    BT=copy.deepcopy(T)
    BLAST=copy.deepcopy(LAST)
    BANS=ANS
    
    d=random.randint(1,D)
    after_t=random.choice(CHO+CHOICES[d])

    before_t=T[d]

    ANS+=S[d][after_t]-S[d][before_t]

    T[d]=after_t

    memolast=[]

    for day in range(d,D+1):
        if T[day]!=before_t:
            ANS+=C[before_t]*(day-LAST[day][before_t])
            memolast.append((day,before_t,LAST[day][before_t]))
            LAST[day][before_t]=LAST[day-1][before_t]
            ANS-=C[before_t]*(day-LAST[day][before_t])
        else:
            break

    ANS+=C[after_t]*(d-LAST[d][after_t])
    memolast.append((d,after_t,LAST[d][after_t]))
    LAST[d][after_t]=d

    for day in range(d+1,D+1):    
        if T[day]!=after_t:
            ANS+=C[after_t]*(day-LAST[day][after_t])
            memolast.append((day,after_t,LAST[day][after_t]))
            LAST[day][after_t]=LAST[day-1][after_t]
            ANS-=C[after_t]*(day-LAST[day][after_t])

    if ANS*10000<MAX*9998:
        T=BT
        ANS=BANS
        for dd,tt,ll in memolast:
            LAST[dd][tt]=ll
    elif ANS>MAX:
        MAX=ANS
        MAXT=copy.deepcopy(T)

print(*MAXT[1:])

Solution (Python):
from time import time
from random import randrange, expovariate
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]+4))
	diff = change(i, order[i][pr])
	if diff is not None:
		res += diff
		priority[i] = pr

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

Solution (Python):
import time
from random import randrange
start = time.time()

D=int(input())
c=list(map(int,input().split()))
def compare(d,q):
  score=maxscore
  changebefore=currentans[d]-1
  changeafter=q-1
  r=contests[changebefore]
  score-=s[d][changebefore]
  score+=s[d][changeafter]
  for j in range(len(r)-1):
    if r[j]==d:
      score-=c[changebefore]*((r[j+1]-r[j-1]-1)*(r[j+1]-r[j-1]))//2
      score+=c[changebefore]*((r[j+1]-d-1)*(r[j+1]-d))//2
      score+=c[changebefore]*((d-r[j-1]-1)*(d-r[j-1]))//2
      break
  r=contests[changeafter]
  for j in range(len(r)-1):
    if r[j+1]>d:
      score+=c[changeafter]*((r[j+1]-r[j]-1)*(r[j+1]-r[j]))//2
      score-=c[changeafter]*((r[j+1]-d-1)*(r[j+1]-d))//2
      score-=c[changeafter]*((d-r[j]-1)*(d-r[j]))//2
      break
  if score>maxscore:
    return score
  else:
    return maxscore

s=[0]
last=[0]*26
currentans=[0]*(D+1)
for i in range(D):
  s.append(list(map(int,input().split())))
contests=[]
for i in range(26):
  contests.append([])
  contests[-1].append(0)
  contests[-1].append(D+1)

for i in range(1,D+1):
  score=0
  t=0
  score+=s[i][t]
  lasttemp=last[t]
  last[t]=i
  for j in range(26):
    score-=c[j]*(i-last[j])
  maxscore=score
  bestans=1
  last[t]=lasttemp
  for t in range(1,26):
    score=0
    score+=s[i][t]
    lasttemp=last[t]
    last[t]=i
    for j in range(26):
      score-=c[j]*(i-last[j])
    if maxscore<score:
      bestans=t+1
      maxscore=score
    last[t]=lasttemp
  last[bestans-1]=i
  currentans[i]=bestans
for i in range(1,D+1):
  contests[currentans[i]-1].append(i)
counter=0
breakflag=0
lastchanged=0
continueflag=0
while True:
  counter+=1
  if counter%100==0:
    now=time.time()
    if now-start>1.75:
      break
  q=randrange(26)+1
  d=randrange(D)+1
  if lastchanged<=d:
    if randrange(2)==0:
      continue
  if currentans[d]==q:
    continue
  score2=compare(d,q)
  if score2>maxscore:
    changebefore=currentans[d]-1
    changeafter=q-1
    contests[changebefore].remove(d)
    contests[changeafter].append(d)
    contests[changeafter].sort()
    currentans[d]=q
    maxscore=score2
    lastchanged=d
for i in range(1,D+1):
  print(currentans[i])

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] * (d - i+1 - last_day[k-1])
        if s > max_score:
            ans = j
            max_score = s
    last_day[ans-1] = i+1
    print(ans)
    k += max_score

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,10)==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):
d = int(input())
C = list(map(int, input().split()))
for i in range(d):
    S = list(map(int, input().split()))
    stf = max(S)
    index = S.index(max(S))
    print(index+1)

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(80):
        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 [10, 20, 40, 80]] + [np.argmax(Ss, axis=1)]
    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):

dd = int(input())
c = list(list(map(int, input().split())))
s = [[0]*26]*dd
v = [[0]*26]*dd
vs = [[0]*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] =  v[i][j]- c[j] *(i-fdate[j]+1)
    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)

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

key = [i+1 for i in range(M)]
minus = [0]*M
while (time.time()-start<1.7):
    
    idx = randint(0,D-1)

    
    mc = zip(minus, key)
    mc = sorted(mc)
    minus, key = zip(*mc)
    val_ = randint(0, 7)
    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):
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)]

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 random
D = int(input())

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


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

for d in range(D):
    print(random.randint(1,26))

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 max(res+10**6, 0)

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 = 1
        next = 1
    elif i == D:
        i = D-2
        next = -1

for t in T:
    print(t)

Solution (Python):
import sys
import numpy as np
TYPE_NUM = 26

def resolve():

    inp = sys.stdin.readlines()
    D = int(inp[0])
    c = np.array(list(map(int, inp[1].split(' '))))
    s = []
    last = np.zeros(TYPE_NUM, dtype=int)
    types = []

    for i in range(2, len(inp)):
        s.append(list(map(int, inp[i].split(' '))))
    s = np.array(s, dtype=int)

    for d in range(D):
        temp_delta_satis = np.zeros([TYPE_NUM, TYPE_NUM], dtype=int)
        for idx in range(TYPE_NUM):
            val = s[d, idx]
            org = last[idx]
            last[idx] = d+1
            temp_delta_satis[:, idx] = (np.sum(-c*(d+1-last)) + val)*4
            if D != d+1:
                for idx2 in range(TYPE_NUM):
                    val2 = s[d+1, idx2]
                    org2 = last[idx2]
                    last[idx2] = d+2
                    temp_delta_satis[idx2, idx] += np.sum(-c*(d+2-last)) + val2
                    last[idx2] = org2
            last[idx] = org
        opt_idx = np.unravel_index(np.argmax(temp_delta_satis), temp_delta_satis.shape)[1]
        types.append(opt_idx+1)
    print(*types, sep='\n')

resolve()

Solution (Python):
import random
from copy import deepcopy

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

def min_max(l):
    l_min = min(l)
    l_max = max(l)
    return [1+(i - l_min) / (l_max - l_min) for i in l]

dd = [max(s[i]) for i in range(d)]
qq = min_max(c)
dd = min_max(dd)

ddd = [i for i in range(d)]
qqq = [i for i in range(26)]

ans = []

for i in range(d):
    ans.append(s[i].index(max(s[i]))+1)

def score(l):
    lastd = [0]*26
    point = 0
    for j,k in enumerate(l):
        kk = k-1
        point += s[j][kk]
        lastd[kk] = j+1
        for l in range(26):
            point -= c[l]*(j+1-lastd[l])
    return point

ma = score(ans)

def random_search():
    global ans,ma
    li = deepcopy(ans)
    D = random.choices(ddd,k=1,weights=dd)[0]
    lin = [p+1 for p in range(26)]
    Q = random.choices(qqq,k=1,weights=qq)[0]
    li[D] = Q+1
    if score(li) > ma:
        ans = deepcopy(li)
        ma = score(li)

for i in range(20000):
    random_search()

for i in ans:
    print(i)

Solution (Python):
import sys
from time import time
from random import randint
input = lambda: sys.stdin.buffer.readline()

st = time()
def get_time():
    return time() - st

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

ans = [randint(1, L) for _ in range(D)]

class BinaryIndexedTree:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (self.n+1)
    
    def sum(self, i):
        res = 0
        while i > 0:
            res += self.data[i]
            i -= i & -i
        return res
    
    def add(self, i, x):
        if i <= 0: raise IndexError
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    def lower_bound(self, x):
        if x <= 0: return 0
        cur, s, k = 0, 0, 1 << (self.n.bit_length()-1)
        while k:
            nxt = cur + k 
            if nxt <= self.n and s + self.data[nxt] < x:
                s += self.data[nxt]
                cur = nxt
            k >>= 1
        return cur + 1

def rsum(x):
    return x*(x+1)//2

b = [BinaryIndexedTree(D) for _ in range(L)]

score = 0
for d, cont in enumerate(ans):
    cont -= 1
    b[cont].add(d+1, 1)
    score += S[d][cont]

for i in range(L):
    m = b[i].sum(D)
    tmp = 0
    s = [0]
    for j in range(1, m+1):
        s.append(b[i].lower_bound(j))
    s.append(D+1)

    for j in range(len(s)-1):
        x = s[j+1] - s[j] - 1
        tmp += rsum(x)
    
    score -= tmp*C[i]

def chg(d, p, q):
    diff = 0
    d += 1

    o = b[p].sum(d)
    d1 = b[p].lower_bound(o-1)
    d2 = b[p].lower_bound(o+1)

    diff += rsum(d-d1) * C[p]
    diff += rsum(d2-d) * C[p]
    diff -= rsum(d2-d1) * C[p]

    o = b[q].sum(d)
    d1 = b[q].lower_bound(o)
    d2 = b[q].lower_bound(o+1)

    diff += rsum(d2-d1) * C[q]
    diff -= rsum(d-d1) * C[q]
    diff -= rsum(d2-d) * C[q]

    d -= 1
    diff -= S[d][p]
    diff += S[d][q] 

    return diff

while True:
    d, q = randint(1, D), randint(1, L)
    p = ans[d-1]
    diff = chg(d-1, p-1, q-1)
    if diff > 0:
        ans[d-1] = q
        b[p-1].add(d, -1)
        b[q-1].add(d, 1)
        score += diff

    if get_time() >= 1.7: break

for x in ans:
    print(x)

Solution (Python):


import random as ra
import copy
import time

start_time = time.time()

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



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


t = []
last = [0]*26
for i in range(D):
    opt1 = s[i].index(max(s[i]))
    opt2 = last.index(min(last))
    if ra.random()<0.5:
        t.append(opt1+1)
        last[opt1] = i+1
    else:
        t.append(opt2+1)
        last[opt2] = i+1



max_score = 0
optimal_t = copy.deepcopy(t)

while (time.time()-start_time)<1.95:

    d = ra.randint(1,D)
    q = ra.randint(1,26)
    td = t[d-1]
    t[d-1] = q
    now = cal_point(t)
    if now > max_score:
        optimal_t = copy.deepcopy(t)
        max_score = now
    else:
        t[d-1] = td

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

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


ma=point()
TT=T[:]
import random
for i in range(200000):
    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>ma:
        ma=new
        TT=T[:]

T=TT[:]
now=ma
for i in range(100000):
    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(100000):
    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):
import random
D = int(input())
c = [int(x) for x in input().split()]
s = [input().split() for l in range(D)]

manzoku = 0
kyounomanzoku = 0
kyounotype = 0
d = 1
last = [0]*26

for p in range(D):
    print(int(random.uniform(1, 26.999)))


"""
for p in range(D):
    
    
    for t in range(26):
        if kyounomanzoku < int(s[p][t]):
            kyounomanzoku = int(s[p][t])
            kyounotype = t
    print(kyounotype+1)
    kyounomanzoku = 0
"""

Solution (Python):
import time
import random

start_time = time.time()

def calc(d, q):
    select_rand = select.copy()
    select_rand[d] = q
    last = [0] * 26
    satisfied_rand = 0
    for i in range(1, D+1):
        t = select_rand[i-1]
        satisfied_rand += s[i-1][t-1]
        last[t-1] = i
        for j in range(26):
            satisfied_rand -= c[j] * (i-last[j])
    return (satisfied_rand, select_rand)

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

last = [0] * 26
select = []
satisfied = 0
for i in range(1, D+1):
    last_d = [c[j]*(i-last[j]) for j in range(26)]
    last_d_sum = sum(last_d)
    
    s_d = s[i-1]
    maxindexA = max(enumerate(s_d), key = lambda x:x[1])[0]
    satis_optA = s_d[maxindexA] - last_d_sum + last_d[maxindexA]
    
    
    last_d = [c[j]*(i-last[j]) for j in range(26)]
    maxindexB = max(enumerate(last_d), key = lambda x:x[1])[0]
    satis_optB = s_d[maxindexB] -last_d_sum + last_d[maxindexB]

    if satis_optA >= satis_optB:
        
        select.append(maxindexA+1)
        satisfied += satis_optA
        last[maxindexA] = i
    else:
        
        select.append(maxindexB+1)
        satisfied += satis_optB
        last[maxindexB] = i

while time.time() - start_time < 1.8:
    d = random.randint(0, D-1)
    q = random.randint(1, 26)
    result = calc(d, q)
    if satisfied < result[0]:
        select = result[1]

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

Solution (Python):
import random

D = int(input())
C = list(map(int,input().split()))
S = []
for i in range(D):
    S.append(list(map(int,input().split())))
t = []
for i in range(D):
    t.append(int(random.uniform(1,27)))
    print(t[i])

Solution (Python):
import numpy as np

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


def s10(c, s, last_date, di, i, mul):
    score = s[di - 1][i]
    score += 0.5 * mul * c[i] * (di - last_date[i])
    return score


def f11(D, c, s):
    last_date = np.zeros(26)

    t = []
    for di in range(1, D + 1):
        mul = np.mean(s[di - 1]) / np.mean(c)
        score_list = []
        for i in range(26):
            score_list.append(s10(c, s, last_date, di, i, mul))

        select_index = score_list.index(max(score_list))
        t.append(select_index)
        last_date[select_index] = di

    return t


for ti in f11(D, c, s):
    print(ti + 1)

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 = 10000
    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.5+start:
        nt = [i for i in t]
        r = random.random()
        if r > 0.5:
            if nt[i] < n:
                nt[i] += 1
        else:
            if nt[i] > 1:
                nt[i] -= 1
        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()