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 bisect import bisect_left, bisect_right
from random import randint

class Set(): 
    def __init__(self, valuelist, INF=10**18+1):
        self.n = len(valuelist) + 1
        self.value = sorted(valuelist) + [INF]
        self.comp = {v : k for k, v in enumerate(self.value, 1)}
        self.bit = BinaryIndexedTree(self.n)

    def insert(self, x, k=1):
        self.bit.add(self.comp[x], k)

    def delete(self, x, k=1):
        self.bit.add(self.comp[x], -k)

    def count(self, x):
        return self.bit.get(self.comp[x])

    def sum(self, x):
        return self.bit.sum(self.comp[x])

    def get(self, k): 
        return self.value[self.bit.bisect_left(k) - 1]

class BinaryIndexedTree(): 
    def __init__(self, n):
        self.n = n
        self.tree = [0 for _ in range(n + 1)]

    def sum(self, idx):
        res = 0
        while idx:
            res += self.tree[idx]
            idx -= idx & -idx
        return res

    def get(self, idx):
        return self.sum(idx) - self.sum(idx - 1)

    def add(self, idx, x):
        while idx <= self.n:
            self.tree[idx] += x
            idx += idx & -idx

    def bisect_left(self, x):
        if x <= 0: return 0
        res, tmp = 0, 2**((self.n).bit_length() - 1)
        while tmp:
            if res + tmp <= self.n and self.tree[res + tmp] < x:
                x -= self.tree[res + tmp]
                res += tmp
            tmp >>= 1
        if res >= self.n:
            return self.n
        return res + 1

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

res = 0
last = [0 for _ in range(26)]
T = [0 for _ in range(D)]
used = [Set(list(range(D))) for i in range(26)]

for d in range(D):
    maxtmp = -10**18
    for i in range(26):
        tmp = 0
        lasttmp = last[:]
        tmp += S[d][i]
        lasttmp[i] = d + 1
        for j in range(26):
            tmp -= C[j] * ((d + 1) - lasttmp[j])
        if maxtmp <= tmp:
            maxtmp = tmp
            contest = i
    res += S[d][contest]
    last[contest] = d + 1
    used[contest].insert(d)
    for j in range(26):
        res -= C[j] * ((d + 1) - last[j])
    T[d] = contest + 1

for i in range(500000):
    tmp = res
    d = randint(1, D - 1)
    q = randint(1, 25)
    if T[d - 1] == q:
        continue
    tmp -= S[d - 1][T[d - 1] - 1]
    tmp += S[d - 1][q - 1]
    k = used[T[d - 1] - 1].sum(d - 1)
    l = used[T[d - 1] - 1].get(k - 1) if k != 1 else -1
    r = used[T[d - 1] - 1].get(k + 1)
    if r == 1000000000000000001:
        r = D
    tmp -= (d - 1 - l) * C[T[d - 1] - 1] * (r - d + 1)
    used[T[d - 1] - 1].delete(d - 1)
    used[q - 1].insert(d - 1)
    k = used[q - 1].sum(d - 1)
    l = used[q - 1].get(k - 1) if k != 1 else -1
    r = used[q - 1].get(k + 1)
    if r == 1000000000000000001:
        r = D
    tmp += (d - 1 - l) * C[q - 1] * (r - d + 1)
    if tmp >= res:
        res = tmp
        T[d - 1] = q
    else:
        used[T[d - 1] - 1].insert(d - 1)
        used[q - 1].delete(d - 1)

for t in T:
    if t >= 27 or t <= 0:
        print('hoge')
        break
    print(t)

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007




def main():
	D = inputInt()
	C = inputList()
	S = []
	ans = []
	for i in range(D):
		s = inputList()
		S.append(s)

	minC = max(C)
	minCn = 0
	for i,val in enumerate(C):
		if val == minC:
			minCn = i+1

	for i,val in enumerate(S):
		tmp = max(val)
		mins = 0
		for j,vol in enumerate(val):
			if tmp == vol:
				mins = j+1
				break
		aaa = random.randint(0, 100)
		if aaa >= 25:
			ans.append(mins)
		else:
			ans.append(minCn)

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



if __name__ == "__main__":
	main()

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
lastchangeq=0
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 lastchangeq==q:
    continue
  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
    lastchangeq=q
for i in range(1,D+1):
  print(currentans[i])

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(miru[-1])
        s=bisect_left(miru,temp)
        if s<1:s+=1
        elif s>=len(miru):s=len(miru)
        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):
import numpy as np
import time
import random
import collections
import bisect  
  
def insert(list, n): 
    bisect.insort(list, n)  
    return list
    
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

start = time.time()


c = np.array(c)
s = np.array(s)
d = np.zeros(26, dtype=np.int64)
tests = np.argmax(s, axis=1)

def get_dates_for_tests(tests):
  dates_for_tests = [list([0]) for _ in range(26)]
  for i, t in enumerate(tests):
    dates_for_tests[t].append(i)
  for t in range(26):
    dates_for_tests[t].append(D-1)
  return dates_for_tests

dates_for_tests = get_dates_for_tests(tests)

def score_diff(date, test):
  before = tests[date]
  if test == before:
    return 0, None, None
  pos_diff = s[date, test] - s[date, before]
  new_index = bisect.bisect_left(dates_for_tests[test], date, 1)
  new_diff = c[test] * (dates_for_tests[test][new_index] - date) * (date - dates_for_tests[test][new_index-1])

  old_index = bisect.bisect_left(dates_for_tests[before], date, 1)
  
  
  old_diff = c[before] * (dates_for_tests[before][old_index+1] - date) * (date - dates_for_tests[before][old_index-1])
  
  total_diff = pos_diff - new_diff + old_diff
  
  return total_diff, new_index, old_index

while time.time() < start + 1.8:
  for date in range(D):
    for test in range(26):
      total_diff, new_index, old_index= score_diff(date, test)
      if total_diff > 0 :
        del dates_for_tests[tests[date]][old_index]
        insert(dates_for_tests[test], date)
        tests[date] = test
        
        
for t in tests:
  print(t+1)

Solution (Python):
import numpy as np

d = int(input())
C = np.array(list(map(int, input().strip().split())))
S = np.array([list(map(int, input().strip().split())) for i in range(d)])

D = np.zeros(26)
s_d = np.zeros(d)
W = np.ones(26) + C / 100
out = np.zeros(d)
t = 0
for i in range(d):
    day = i + 1
    temp_score = 0
    con = 0
    d_l = [day]*26
    for j in range(26):
        score = S[i][j]
        score -= sum((d_l - D) * C)
        score += (day - D[j]) * C[j] * W[j]
        if score > temp_score:
            con = j
            temp_score = score
    out[i] = con + 1
    D[con] = i + 1
    t += temp_score
    s_d[i] = t
    W = W * 1.1
    W[j] = W[j] * 0.9
for i in out:
    print(int(i))

Solution (Python):
import sys
from random import randint
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def count_v(last_d, C, S, t, d):
    ret = S[t - 1]
    last_d[t - 1] = d
    for i in range(len(last_d)):
        ret -= C[i] * (d - last_d[i])
    return ret


def count_v_virtual(last_d, C, S, t, d):
    ret = S[t]
    tmp = last_d[t]
    last_d[t] = d
    for i in range(len(last_d)):
        ret -= C[i] * (d - last_d[i])
    last_d[t] = tmp
    return ret


def get_diff_score(T, d, q, C, D, Ss):
    diff = 0
    original_t = T[d - 1]
    last_d_q = 0
    last_d_ori = 0
    for i in range(d):
        if T[i] == q:
            last_d_q = i + 1
        if T[i] == original_t and i < d - 1:
            last_d_ori = i + 1
    
    for i in range(d - 1, D):
        if T[i] == q:
            break
        diff += C[q - 1] * (d - last_d_q)
    
    T[d - 1] = q
    for i in range(d - 1, D):
        if T[i] == original_t:
            break
        diff -= C[original_t - 1] * (d - last_d_ori)
    
    diff += Ss[d - 1][q - 1] - Ss[d - 1][original_t - 1]
    return diff


def main():
    D = int(input())
    C = inpl()
    Ss = [inpl() for _ in range(D)]
    T = []
    last_d = [-1] * len(C)
    Contest = 26

    v = 0
    for d in range(D):
        tmp_t, tmp_v = -1, -float('inf')
        for i in range(Contest):
            tmp_score = count_v_virtual(last_d, C, Ss[d], i, d)
            if tmp_score > tmp_v:
                tmp_v = tmp_score
                tmp_t = i
        last_d[tmp_t] = d
        v += tmp_v
        T.append(tmp_t + 1)

    Cs = [i + 1 for i, c in enumerate(C)]
    Cs.sort(key=lambda x: C[x - 1])
    c_set = set(Cs[:int(0.1 * len(Cs))])
    c_set_m = Cs[int(0.9 * len(Cs)):]

    for _ in range(30000):
        tmp = [i for i, t in enumerate(T) if t in c_set]
        if len(tmp) < 2:
            break
        i = randint(0, len(tmp) - 1)
        d = randint(0, len(c_set_m) - 1)
        d, q = T[i], c_set_m[d]
        ori_q = T[d - 1]
        diff = get_diff_score(T, d, q, C, D, Ss)
        if diff < -(0.01 * v):
            T[d - 1] = ori_q
        else:
            v += diff

    for _ in range(5000):
        d, q = randint(1, D), randint(1, Contest)
        ori_q = T[d - 1]
        diff = get_diff_score(T, d, q, C, D, Ss)
        if diff < -(0.01 * v):
            T[d - 1] = ori_q
        else:
            v += diff

    for t in T:
        print(t)

    return


if __name__ == '__main__':
    main()

Solution (Python):
ans = [1]*365
for i in range(365):
    ans[i]=(i+25)%26 + 1
for i in range(365):
    print(ans[i])

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
import numpy as np
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

start = time.time()

D = ni()
c = na()
s = [na() for _ in range(D)]

sat = 0
last = [0] * 26
t = []
for d in range(D):
    li = []
    for k in range(26):
        last_t = last.copy()
        sat_t = sat
        j = k
        last_t[j] = d + 1
        for i in range(26):
            sat_t -= (d + 1 - last_t[i]) * c[i]
        sat_t += s[d][j]
        li.append(sat_t)
    sat = max(li)
    day = np.argmax(li)
    last[day] = d + 1
    
    t.append(day+1)

now = sat
while time.time() - start < 1.855:
    d = random.randint(1, D)
    q = random.randint(1, 26)
    if t[d - 1] == q:
        continue
    old = t[d-1]
    t[d-1] = q
    sat = 0
    last = [0] * 26
    for k in range(D):
        j = t[k] - 1
        last[j] = k + 1
        for i in range(26):
            sat -= (k + 1 - last[i]) * c[i]
        sat += s[k][j]
    if now > sat:
        t[d-1] = old
    else:
        now = sat
for i in range(D):
    print(t[i])

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
    if ans >= get_sat():
        t[p] = x
for i in t:
    print(i + 1)

Solution (Python):
from time import time
from random import randrange
start = time()
d = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(d):
    s.append(list(map(int, input().split())))
t = []
v = 0
last = [-1]*26
for i in range(d):
    bst = -10**10
    for j in range(26):
        tmp = s[i][j]
        for k in range(26):
            if j!=k:
                tmp -= c[k]*(i-last[k])
        if tmp>bst:
            bst = tmp
            bst_idx = j
    last[bst_idx] = i
    t.append(bst_idx)
    v += s[i][bst_idx]
    for j in range(26):
        v -= c[j]*(i-last[j])
mx = v
while time()-start<1.85:
    newt = t[:]
    nd = randrange(d)
    now = newt[nd]
    nq = randrange(25)
    newt[nd] = nq if nq<now else nq+1
    v = 0
    last = [-1]*26
    for i in range(d):
        v += s[i][newt[i]]
        last[newt[i]] = i
        for j in range(26):
            v -= c[j]*(i-last[j])
    if v>mx:
        mx = v
        t = newt
for i in t:
    print(i+1)

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

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

D = int(readline())
C = list(map(int,readline().split()))
S = [list(map(int,readline().split())) for i in range(D)]
t = [0]*D
for j,s in enumerate(S):
    ansidx = 0
    anssum = 0
    for i,si in enumerate(s,start=1):
        if anssum < si:
            ansidx = i
            anssum = si
    t[j] = ansidx
def score():
    ans = 0
    minus = 0
    last = [0]*26
    for i in range(D):
        ans += S[i][t[i]-1]
        minus = 0
        last[t[i]-1] = i+1
        for j in range(26):
            minus += C[j]*(i-last[j]+1)
        ans -= minus
    return ans
a = score()
import random
for k in range(800):
    d,q = random.randint(1,D),random.randint(1,26)
    told = t[::]
    t[d-1] = q
    b = score()
    if a > b:
        t = told
    else:
        a = b
for ti in t:
    print(ti)

Solution (Python):

import numpy as np
def main():
  d=int(input())
  c=np.array(list(map(int,input().split())))
  s=[None]*d
  r0=[None]*d
  r1=[None]*d
  cm=np.array([0]*26)
  cd=np.array([0]*26)

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


  for j in range(d):  
    
    
    r_i=np.argmax(s[j])
    cd=c*cm
    if np.max(cd>s[i][r_i]):
      r_i=np.argmax(cd)
    r0[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0
  
  
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  rand = np.random.randint(100, size = d) 
  for j in range(d):  
    
    r_i=r0[j]
    cd=c*cm
    if rand[j]>80:
      r_i=np.argmax(cd)
    r1[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0

  score0=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r0[j]
    score0+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score0+=-np.sum(cd)
  score1=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r1[j]
    score1+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score1+=-np.sum(cd)
  if score1>score0:
    r0=r1
    score0=score1
  
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  rand = np.random.randint(100, size = d) 
  for j in range(d):  
    
    r_i=r0[j]
    cd=c*cm
    if rand[j]>75:
      r_i=np.argmax(cd)
    r1[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0
  
  score1=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r1[j]
    score1+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score1+=-np.sum(cd)
  if score1>score0:
    r0=r1
    score0=score1
    
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  rand = np.random.randint(100, size = d) 
  for j in range(d):  
    
    r_i=r0[j]
    cd=c*cm
    if rand[j]>60:
      r_i=np.argmax(cd)
    r1[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0
  
  score1=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r1[j]
    score1+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score1+=-np.sum(cd)
  if score1>score0:
    r0=r1
    score0=score1
    
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  rand = np.random.randint(100, size = d) 
  for j in range(d):  
    
    r_i=r0[j]
    cd=c*cm
    if rand[j]>50:
      r_i=np.argmax(cd)
    r1[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0
  
  score1=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r1[j]
    score1+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score1+=-np.sum(cd)
  if score1>score0:
    r0=r1
    score0=score1

      
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  rand = np.random.randint(100, size = d) 
  for j in range(d):  
    
    r_i=r0[j]
    cd=c*cm
    if rand[j]>45:
      r_i=np.argmax(cd)
    r1[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0
  
  score1=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r1[j]
    score1+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score1+=-np.sum(cd)
  if score1>score0:
    r0=r1
    score0=score1  
  
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  rand = np.random.randint(100, size = d) 
  for j in range(d):  
    
    r_i=r0[j]
    cd=c*cm
    if 70< rand[j] < 90:
      r_i=np.argmax(cd)
    r1[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0
  
  score1=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r1[j]
    score1+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score1+=-np.sum(cd)
  if score1>score0:
    r0=r1
    score0=score1  
      
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  rand = np.random.randint(100, size = d) 
  for j in range(d):  
    
    r_i=r0[j]
    cd=c*cm
    if 10< rand[j] < 30:
      r_i=np.argmax(cd)
    r1[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0
  
  score1=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r1[j]
    score1+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score1+=-np.sum(cd)
  if score1>score0:
    r0=r1
    score0=score1
  
        
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  rand = np.random.randint(100, size = d) 
  for j in range(d):  
    
    r_i=r0[j]
    cd=c*cm
    if 20< rand[j] < 40:
      r_i=np.argmax(cd)
    r1[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0
  
  score1=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r1[j]
    score1+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score1+=-np.sum(cd)
  if score1>score0:
    r0=r1
    score0=score1
  
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  rand = np.random.randint(100, size = d) 
  for j in range(d):  
    
    r_i=r0[j]
    cd=c*cm
    if 60< rand[j] < 75:
      r_i=np.argmax(cd)
    r1[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0
  
  score1=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r1[j]
    score1+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score1+=-np.sum(cd)
  if score1>score0:
    r0=r1
    score0=score1
   
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  rand = np.random.randint(100, size = d) 
  for j in range(d):  
    
    r_i=r0[j]
    cd=c*cm
    if 80< rand[j] < 95:
      r_i=np.argmax(cd)
    r1[j]=r_i
    for k in range(26):
      cm[k]+=1
    cm[r_i]=0
  
  score1=0
  cm=np.array([0]*26)
  cd=np.array([0]*26)  
  for j in range(d):
    r0_j=r1[j]
    score1+=s[j][r0_j]
    for k in range(26):
      cm[k]+=1
      cm[r0_j]=0
    cd=c*cm
    score1+=-np.sum(cd)
  if score1>score0:
    r0=r1
    score0=score1 
  
  for j in range(d):  
    print(r0[j]+1) 
 
main()

Solution (Python):
D = int(input())
C = list(map(int, input().split()))
S = []
con= 0
for _ in range(D):
    S.append(list(map(int, input().split())))
t = [-1]*D
best = [0]*D
last = [0]*26

for i in range(D-30):
    
    score = [-1]*26
    
    for x in range(26):
        if i==0:
            con = 0
        else:
            con = best[i-1]
        
        con += S[i][x]
        
        for j in range(26): 
            if not j==x:
                con -= C[j]*(i-last[j]+1)

        score[x]=con
    m = -100000
    ii = 0
    for k in range(26):
        if m<score[k]:
            m=score[k]
            ii=k
    
    last[ii]=i+1
    best[i]=score[ii]
    t[i]=ii+1

for g in reversed(range(1, 16)):

    p2 = [0]*(26**2)
    for i in range(26):
        for j in range(26):
            
            p2[i*26+j]+=S[D-2*g][i]
            p2[i*26+j]+=S[D-2*g+1][j]
            for k in range(26):
                if not k==i:
                    p2[i*26+j] -= C[k]*(25-last[k])
            for k in range(26):
                if not k==j:
                    if k==i:
                        p2[i*26+j] -= C[k]*2
    ma = 0
    ind = 0
    for h in range(26**2):
        if p2[h]>ma:
            ma=p2[h]
            ind = h
    t[D-2*g]= ind//26+1
    t[D-2*g+1]=ind%26+1
    last[t[D-2*g]-1]=D-2*g+1
    last[t[D-2*g+1]-1]=D-2*g+2      

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

Solution (Python):
import numpy as np
import copy


def cost(c, d, lastdi):
    total = 0
    for i in range(26):
        total += c[i]*(d - lastdi[i])
    return total


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


lastdi = [0 for _ in range(26)]

for d in range(D):
    
    sd_sort = np.argsort(s[d])
    max_ans = 0
    typei = -1
    
    for i in range(26):
        tmp_lastdi = copy.deepcopy(lastdi)
        choicei = sd_sort[i]
        tmp_lastdi[choicei] = d+1 
        ans = s[d][choicei] - cost(c, d+1, tmp_lastdi)
        if ans > max_ans:
            
            typei = choicei

    lastdi[typei] = d+1 
    typei = s[d].index(max(s[d])) + 1
    print(typei)