Problem:


(Please read problem A first. The maximum score you can get by solving this problem B is 1, which will have almost no effect on your ranking.)

Beginner's Guide

Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.

Problem Statement

You will be given a contest schedule for D days.
For each d=1,2,\ldots,D, calculate the satisfaction at the end of day d.

Input

Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.

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}
t_1
t_2
\vdots
t_D

The constraints and generation methods for the input part are the same as those for Problem A.

For each d, t_d is an integer satisfying 1\leq t_d \leq 26, and your program is expected to work correctly for any value that meets the constraints.

Output

Let v_d be the satisfaction at the end of day d.
Print D integers v_d to Standard Output in the following format:

v_1
v_2
\vdots
v_D

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
1
17
13
14
13

Sample Output 1

18398
35037
51140
65837
79325

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.

Next Step

We can build a solution (schedule) for this problem in the order of day 1, day 2, and so on. And for every partial solution we have built, we can calculate the goodness (satisfaction) by using the above score calculator. So we can construct the following algorithm: for each d=1,2,\ldots,D, we select the contest type that maximizes the satisfaction at the end of day d. You may have already encountered this kind of "greedy algorithms" in algorithm contests such as ABC. Greedy algorithms can guarantee the optimality for several problems, but unfortunately, it doesn't ensure optimality for this problem. However, even if it does not ensure optimality, we can still obtain a reasonable solution in many cases. Let's go back to Problem A and implement the greedy algorithm by utilizing the score calculator you just implemented!

Greedy methods can be applied to a variety of problems, are easy to implement, and often run relatively fast compared to other methods. Greedy is often the most powerful method when we need to process huge inputs.
We can further improve the score by changing the greedy selection criteria (evaluation function), keeping multiple candidates instead of focusing on one best partial solution (beam search), or using the output of greedy algorithms as an initial solution of other methods.
For more information, please refer to the editorial that will be published after the contest.



Sample input:
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
1
17
13
14
13


Sample output:
18398
35037
51140
65837
79325

Submission status: Wrong Answer

Solution code:
def score(tl,sl,cl):
    sat=0
    last=[0]*26
    satl=list()
    for i in range(365):    
        sat+=sl[i*26+tl[i]-1]
        dec=0
        for l in range(26):
            if l+1!=tl[i]:  
                last[l]+=1
                dec+=cl[l]*last[l]
            else:
                last[l]=0
        sat-=dec
        satl.append(sat)
    return(satl)







d=int(input())
c=input()
cl=[int(n) for n in c.split()]
sl=list()
for i in range(365):
    s=input()
    sl=sl+[int(n) for n in s.split()]
tl=list()
for i in range(365):
    t=int(input())
    tl.append(t)

print(score(tl,sl,cl))

Submission status: Wrong Answer

Solution code:
def main():
    from builtins import int, map, list, print, len
    from collections import defaultdict
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    D = input_number()
    c = input_number_list()
    last = defaultdict(lambda: 0)
    s = []
    for i in range(D):
        s.append(input_number_list())
    for i in range(D):
        t_idx = 0
        t_pt = 0
        for j in range(len(s[i])):
            pt = s[i][j] + (i - last[j]) * c[j]
            if t_pt < pt:
                t_idx = j
                t_pt = pt
            elif t_pt == pt:
                if c[t_idx] < c[j]:
                    t_idx = j
                    t_pt = pt
        print(t_idx + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
D = int(input())
listC = list(map(int, input().split()))
answerL = []
for i in range(D):
    listS = list(map(int, input().split()))
    maxi = min(listS)
    target = listS.index(maxi)
    answerL.append(target+1)
for ans in answerL:
    print(ans)

Submission status: Wrong Answer

Solution code:
d=int(input())
*c,=map(int, input().split())
s=[]
for _ in range(d):
    *si,=map(int, input().split())
    s.append(si)
t=[int(input())-1 for _ in range(d)]
last=[-1]*26
smx=0
ss=0
for i in range(d):
    ss+=s[i][t[i]]
    last[t[i]]=i
    for j in range(26):
        ss-= c[j]*(i-last[j])
    smx=max(ss,smx)
    print(smx)

Submission status: Wrong Answer

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

last=[-1]*26
v=0
for d in range(D):
    v+=s[d][T[d]]
    last[T[d]]=d
    for i in range(26):
        v-=c[i]*(d-last[i])
    print(max(v,0))

Submission status: Wrong Answer

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

dp=[0]*26

for i in range(d):
    s_i = max(s[i])
    index=s[i].index(max(s[i]))
    dp[index]=i+1

    tmp=0

    for j in range(26):
        tmp+=c[j]*(d-dp[j])

    ans = s_i = tmp
    print(ans)

Submission status: Wrong Answer

Solution code:
D=int(input())
c = list(map(int,input().split()))
s=[[0 for e in range(26)] for f in range(D)]
for i in range(D):
 s[i]=list(map(int,input().split()))
last=[0]*26
ans=0
point=[0]*D
for i in range(D):
 saidai=-(10**10)
 kouho=0
 for j in range(26):
  if s[i][j]+c[j]*((i+1)-last[j])>=saidai:
   kouho=j+1
   saidai=s[i][j]+c[j]*((i+1)-last[j])
 print(kouho)

Submission status: Wrong Answer

Solution code:
import os
import sys

import numpy as np


def solve(inp):
    d = inp[0]
    ccc = inp[1:27]
    sss = np.zeros((d, 26), dtype=np.int64)
    for r in range(d):
        sss[r] = inp[27 + r * 26:27 + (r + 1) * 26]
    ttt = inp[27 + d * 26:] - 1
    last = np.full(26, -1, dtype=np.int64)
    sat = 0
    buf = np.zeros(d, dtype=np.int64)
    for i in range(d):
        t = ttt[i]
        sat += sss[i][t]
        for j in range(26):
            if i == j:
                continue
            sat -= ccc[j] * (i - last[j])
        last[t] = i
        buf[i] = sat
    return buf


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print('\n'.join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
D = int(input())
C = [int(i) for i in input().split()]
S = []
for _ in range(D):
    s = [int(i) for i in input().split()]
    S.append(s)

sum = 0
for i in range(D):
    t = int(input())
    s = S[i]
    sum += s[t - 1]
    print(sum)

Submission status: Wrong Answer

Solution code:
0

Submission status: Time Limit Exceeded

Solution code:
D = int(input())

c_list = list(map(int, input().split()))
s_list = []
t_list = []
for i in range(D):
    s_list.append(list(map(int, input().split())))
for i in range(D):
    t_list.append(int(input()))
v_list = []
for k in range(D):
    point = 0
    d = k
    minus = 0
    while d >= 0:
        t_l = t_list[0:d+1]
        point += s_list[d][t_list[d] - 1]
        for minus_rate in c_list:
            if c_list.index(minus_rate) + 1 in t_l and\
                d >= t_l.index(c_list.index(minus_rate) + 1):
                rev_t_l = list(reversed(t_l))
                index_t_l = len(t_l) - rev_t_l.index(c_list.index(minus_rate) + 1) - 1
                minus += minus_rate * (d - index_t_l)
            else:
                minus += minus_rate * (d + 1)

        d -= 1
    v_list.append(point - minus)
#
[print(i) for i in v_list]

Submission status: Time Limit Exceeded

Solution code:
import math

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

nocontest = [2 for i in range(26)]

for i in range(D):
    s = S[i]
    contest = [0 for j in range(26)]
    for j in range(26):
        contest[j] = c[j] * nocontest[j] * s[j]
    #print(contest)
    max_contest = max(contest)
    ans = contest.index(max_contest)
    print(ans + 1)
    
    for j in range(26):
        if j == ans:
            nocontest[j] = 2
        else:
            nocontest[j] = nocontest[j] * (nocontest[j]+1) // 2
    #print(nocontest)

Submission status: Time Limit Exceeded

Solution code:
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())))
    

t = []
for i in range(D):
    chosen = s[i,:].flatten().argmax()+ 1
    t.append(chosen)


score = scoring(c,s,t)
while time()-start < 1.995:
    i = np.random.randint(D)
    old = t[i]
    t[i] = np.random.randint(1,27)
    new_score = scoring(c,s,t)
    if new_score > score:
        score = new_score
    else:
        t[i] = old

for i in t:
	print(i)

Submission status: Time Limit Exceeded

Solution code:
import time

import random

time_start = time.time()


class Problem:

    def __init__(self, D, s, c):
        self.last_days = [0] * 26
        self.D = D
        self.s = s
        self.c = c

    def scoring(self, day, ind):
        day_score = self.s[day - 1][ind]
        self.last_days[ind] = day
        minus_score = 0
        for i in range(26):
            minus_score += self.c[i] * (day - self.last_days[i])
        day_score -= minus_score
        return day_score

    def _strategy(self, day):
        ind = random.randint(0, 25)
        score = self.scoring(day, ind)
        return score, ind

    def solve(self):
        answer = []
        sum_score = 0
        for i in range(self.D):
            score, ind = self._strategy(i)
            answer.append(ind)
            sum_score += score
        return sum_score, answer

    def init(self):
        self.last_days = [0] * 26


def main():
    DO_TIME = 2
    D = int(input())
    c = list(map(int, input().split()))
    s = []

    for _ in range(D):
        s.append(list(map(int, input().split())))

    max_score = 0
    max_answer = [1] * D
    problem = Problem(D, s, c)
    ite = 0
    while time.time() - time_start < DO_TIME:
        ite += 1
        score, answer = problem.solve()

        if score > max_score:
            max_score = score
            max_answer = answer

    for i in range(D):
        max_answer[i] += 1
        print(max_answer[i])
    # print(ite)
    # print(max_answer)
    # print(max_score)



main()

# tmp = [1, 17, 13, 14, 13]
# sum_s = 0
# problem.init()
# for i in range(5):
#     score = problem.scoring(i + 1, tmp[i] -1 )
#     sum_s += score
#     print(last_days)
#     print(score)
#
# print(sum_s)

Submission status: Time Limit Exceeded

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

nocontest = [1 for i in range(26)]

for i in range(D):
    s = S[i]
    contest = [0 for j in range(26)]
    for j in range(26):
        contest[j] = c * nocontest[j] * s[j]
    max_contest = max(contest)
    ans = contest.index(max_contest)
    print(ans + 1)
    
    for i in range(26):
        if i == ans:
            nocontest[i] = 1
        else:
            nocontest[i] += 1
    #print(nocontest)

Submission status: Accepted

Solution code:
D = int(input())
c = [0] + [int(x) for x in input().split()]
s = [[0 for _ in range(26 + 1)]] + \
    [[0] + [int(x) for x in input().split()] for _ in range(D)]
t = [0] + [int(input()) for _ in range(D)]

def calcScore():
    score = [[0] * (26 + 1) for _ in range(D + 1)]
    sinceLast = [[0] * (26 + 1) for _ in range(D + 1)]

    for d in range(1, D + 1):
        id = t[d]  # この日に開催するコンテスト
        sinceLast[d][id] = 0
        score[d][id] = s[d][id]


        for i in range(1, 26 + 1):
            if i == id:  continue
            sinceLast[d][i] = sinceLast[d - 1][i] + 1
            score[d][i] = -c[i] * sinceLast[d][i]

    total = sum(sum(row) for row in score)

    ans = 0
    for d in range(1, D + 1):
        ans += sum(score[d])
        print(ans)

    return ans

calcScore()

Submission status: Accepted

Solution code:
D = int(input())
C = [int(T) for T in input().split()]
S = [[] for TD in range(0,D)]
for TD in range(0,D):
    S[TD] = [int(T) for T in input().split()]
Type = 26
Last = [0]*Type
SatD = [0]*D
SatA = [0]*(D+1)
for TD in range(0,D):
    Test = int(input())-1
    Last[Test] = TD+1
    SatD[TD] = S[TD][Test]
    for TC in range(0,Type):
        SatD[TD] -= C[TC]*(TD+1-Last[TC])
    SatA[TD+1] = SatA[TD]+SatD[TD]
print('\n'.join(str(T) for T in SatA[1:]))

Submission status: Accepted

Solution code:
D = int(input())
C = [int(T) for T in input().split()]
S = [[] for TD in range(0,D)]
for TD in range(0,D):
    S[TD] = [int(T) for T in input().split()]
Type = 26
Last = [0]*Type
Sats = 0
for TD in range(0,D):
    Test = int(input())-1
    Last[Test] = TD+1
    Sats += S[TD][Test]
    for TC in range(0,Type):
        Sats -= C[TC]*(TD+1-Last[TC])
    print(Sats)

Submission status: Accepted

Solution code:
def penalty(day, last, c):
    val = 0
    for i in range(26):
        val += c[i] * (day - last[i])
    return val

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

last = [-1]*26
ans = [0]*(d+1)

for day in range(d):
    ans[day+1] = ans[day] + s[day][t[day]-1]
    last[t[day]-1] = day
    ans[day+1] -= penalty(day, last, c)

for v in ans[1:]:
    print(v)

Submission status: Accepted

Solution code:
d = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(d)]
T = [int(input()) for _ in range(d)]

last = [0] * 26
score = 0

for i, (s, t) in enumerate(zip(S, T), 1):
    score += s[t-1]
    last[t-1] = i
    for j in range(26):
        score -= C[j] * (i - last[j])
    print(score)

Submission status: Accepted

Solution code:
from bisect import bisect_left


class score:
    def __init__(self,t) -> None:
        self.t = t
        score = 0
        last = [[] for i in range(26)]
        for i,ti in enumerate(t):
            score += s[i][ti-1]
            last[ti-1].append(i+1)
            for tj in range(26):
                if last[tj-1] == []:
                    score -= c[tj-1]*(i+1)
                else:
                    #print(last)
                    score -= c[tj-1]*((i+1)-last[tj-1][-1])
            print(score)
        self.score = score
    def a__init__(self,t) -> None:
        score = 0
        last = [[] for i in range(26)]
        for i,ti in enumerate(t):
            # 開催分を加算
            score += s[i][ti-1]
            # 減らす
            if last[ti-1] == []:
                score -= c[i]*i+1
            else:
                score -= c[i]*((i+1)-last[ti-1][-1])
            last[ti-1].append(i+1)
            print(score)
        for i in range(26):
            if last[i] == []:
                score -= c[i]*D
            else:
                score -= c[i]*(D-last[i][-1])
        self.score = score
        self.t = t


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

sc = score(t)
#print(sc.score)

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) - 1 for _ in range(D)]


def cal_score():
  S = 0
  last = [-1] * 26
  score = 0
  for d in range(D):
    S += s[d][t[d]]
    last[t[d]] = d
    for i in range(26):
        S -= c[i] * (d - last[i])
    score += max(10 ** 6 + S, 0)
    print(S)
    

if __name__ == "__main__":
  cal_score()

Submission status: Accepted

Solution code:
d = int(input())
C = list(map(int, input().split()))
S = list(list(map(int, input().split())) for i in range(d))
T = list(int(input()) - 1 for i in range(d))

kaisai = [0] * 26
manzoku = 0
date = 0
for t in T:
    date += 1
    kaisai[t] = date
    manzoku += S[date - 1][t]

    for i in range(26):
        manzoku -= C[i] * (date - kaisai[i])
    
    print(manzoku)

Submission status: Accepted

Solution code:
#入力
D = int(input())
C = [int(c) for c in input().split()]
S = []
for _ in range(D):
    s = [int(x) for x in input().split()]
    S.append(s)
T = []
for _ in range(D):
    t = int(input()) - 1
    T.append(t)
    
#スコア計算
score = 0
last_day = [-1] * 26
for t in range(D):
    test = T[t]
    score += S[t][test]
    last_day[test] = t
    for i in range(26):
        score -= (C[i] * (t - last_day[i]))
    print(score)

Submission status: Accepted

Solution code:
import bisect
import random
import sys

input = sys.stdin.readline


class score:
    def __init__(self, t):
        self.t = t

    def first_score(self):
        last = [0]*26
        score = 0
        for i,ti in enumerate(self.t):
            score += S[i][ti - 1]
            last[ti-1] = i + 1
            for j in range(26):
                score -= C[j] * ((i+1) - last[j])
        self.score = score
        return score


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

#T = [int(input()) for i in range(D)]
T = []
for i in range(D):
    T.append(int(input()))
    s = score(T)
    print(s.first_score())

Submission status: Accepted

Solution code:
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

L = [0]*26

v = 0
for i in range(1, D+1):
    t = int(input())
    t -= 1
    v += S[i-1][t]
    L[t] = i
    for j in range(26):
        v -= C[j]*(i-L[j])
    print(v)

Submission status: Accepted

Solution code:

D = int(input())
# with open("sample1.in") as f:

last = [0 for i in range(26)]
s = [[0 for j in range(26)] for i in range(D)]
c = list(map(int, input().split(" ")))
result = []
# opened = []  #開催したやつを保存
for i in range(D):
    a = list(map(int, input().split(" ")))
    for j, k in enumerate(a):
        #print(i, j, k)
        s[i][j] = int(k)
        # スコア計算
        
for i in range(D):  
    result.append(int(input()))
score_max=0
for i in range(D):
    #score_max = 0
    score_index = 0
    tmp=result[i]-1
    score=s[i][tmp]+(i + 1 - last[tmp]) * c[tmp]
    #print("score",s[i][tmp])
    for j in range(26):
        score -= (i + 1 - last[j]) * c[j]
    #print("score-",score)
    score_max+=score
    print(score_max)
    last[tmp] = i+1
    
    # print(s.index(max(s[i])))
    # print(result[i]+1)

Submission status: Accepted

Solution code:
def main():
    D = int(input())
    C = [int(i) for i in input().split()]
    S = [[int(i) for i in input().split()] for j in range(D)]
    T = [int(input()) for i in range(D)]
    contest_last_opened = [0]*26  # コンテストiを前回開催した日
    score = 0
    for d, t in enumerate(T, start=1):
        get_score = S[d-1][t-1]
        score += get_score
        contest_last_opened[t-1] = d
        loss_score = 0
        for i in range(26):
            ld = contest_last_opened[i]
            loss_score += C[i]*(d-ld)
        score -= loss_score
        print(score)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=list()
t=list()
v=list()
last=[0]*26
D=int(input())
c=list(map(int,input().split()))
for i in range(D):
    s.append(list(map(int,input().split())))
for i in range(D):
    t.append(int(input()))
legacy=0
for i in range(D):
    minus=0
    v.append(legacy)
    v[i]+=s[i][t[i]-1]
    last[t[i]-1]=i+1
    for j in range(26):
        minus+=c[j]*(i+1-last[j])
    v[i]-=minus
    legacy=v[i]
for i in range(D):
    print(v[i])

Submission status: Accepted

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

last = [0] * 26
score = 0
for i,(s,a) in enumerate(zip(S,T)):
    score += s[a-1]
    last[a-1] = i+1
    for j,c in enumerate(C):
        score -= c * (i+1 - last[j])
    print(score)

Submission status: Accepted

Solution code:
import random

def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum = sum + c[i]*(d-last_d[i])
        
    return int(score - sum)


def main():
    D = int(input())

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

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

    sche = []
    for i in range(D):
        x = int(input())
        sche.append(x)
    
    last_d = [0 for i in range(26)]
    score = 0
    
    for i in range(D):
        score += s[i][sche[i]-1]
        last_d[sche[i]-1] = i+1
        score = down_score(i+1, c, last_d, score)
        print(score)
        
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
t=[int(input()) for i in range(D)]
C=sum(c)
l=[0]*26
a=0
m=0
for i in range(D):
    b=t[i]-1
    m+=C-c[b]*(i-l[b]+1)
    a+=s[i][b]-m
    l[b]=i+1
    print(a)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7
    #epsilon = 10**-9

    d = int(input())
    c = list(map(int, input().split()))
    last = [0]*26
    s = [list(map(int, input().split())) for _ in range(d)]
    res = 0
    for i in range(d):
        t = int(input())
        last[t-1] = i+1
        res += s[i][t-1]
        for j in range(26):
            res -= c[j] * (i+1-last[j])
        print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) for _ in range(D)]
last = [0 for i in range(26)]
sat = 0

for d in range(D):
  sat += s[d][t[d]-1]
  last[t[d]-1] = d+1
  for i in range(26):
    sat -= c[i] * (d+1 - last[i])
  print(sat)

Submission status: Accepted

Solution code:
def scoring(d, t):
    last[t] = d
    return S[d][t] - sum((d - l) * c for l, c in zip(last, C))

D = int(input())
C = list(map(int, input().split()))
S = []
for _ in range(D):
    s = list(map(int, input().split()))
    S.append(s)
T = [int(input()) - 1 for _ in range(D)]
last = [-1] * 26
score = 0
for i in range(D):
    score += scoring(i, T[i])
    print(score)

Submission status: Accepted

Solution code:
#input
D = int(input())
c_list = list(map(int, input().split()))

s_grid = []
for i in range(D):
    array = list(map(int, input().strip().split(' ')))
    s_grid.append(array)

t_list = [int(input()) -1 for i in range(D)]
last_list = [0 for i in range(26)]

def calculate_score(last_list):
    score = 0
    for d in range(D):
        score += s_grid[d][t_list[d]]
        last_list = [n+1 for n in last_list]
        last_list[t_list[d]] = 0
        for i in range(26):
            score -= c_list[i]*last_list[i]
        print(score)


calculate_score(last_list)

Submission status: Accepted

Solution code:
D=int(input())
c=[int(i) for i in input().split()]
s=[]
for d in range(D):
    s.append([int(i) for i in input().split()])

t=[]
for d in range(D):
    t.append(int(input()) - 1)

v = [0]*D
last = [[0 for i in range(26)] for d in range(D)]

for d in range(D):
    if d>=1:
        last[d] = last[d-1][:]
    last[d][t[d]] = d+1

for d in range(D):
    v[d] = s[d][t[d]] - sum([c[i]*(d+1 - last[d][i]) for i in range(26)])

v_sum=0
for d in range(D):
    v_sum+=v[d]
    print(v_sum)

Submission status: Accepted

Solution code:
d,*s,=map(int,open(i:=0).read().split())
c,*l=[0]*27
for v in s[-d:]:
  i+=1
  l[v-1]=i
  print(c:=c+s[i*26+v-1]-sum(x*(i-y)for x,y in zip(s,l)))

Submission status: Accepted

Solution code:
def func(s,x):
    last=[0]*26
    score=0
    for i,v in enumerate(x,1):
        last[v]=i
        c=0
        for j in range(26):
            c+=s[j]*(i-last[j])
        score=score+s[i*26+v]-c
        print(score)
    return score
def main():
    d,*s=map(int,open(0).read().split())
    func(s,[t-1for t in s[-d:]])
main()

Submission status: Accepted

Solution code:
import numpy as np
import numba


i4 = numba.int32


@numba.njit((i4, i4[:], i4[:, :], i4[:]), cache=True)
def solve(dd, c_arr, s_arr, t_arr):
    last_d = np.zeros(26, dtype=np.int32) - 1
    score = 0
    score_arr = np.zeros(dd, dtype=np.int32)
    for d in range(dd):
        score += s_arr[d, t_arr[d] - 1]
        last_d[t_arr[d] - 1] = d
        score -= (c_arr * (d - last_d)).sum()
        score_arr[d] = score
    return score_arr


def main():
    d = np.int32(input())
    c_arr = np.array(list(map(int, input().split()))).astype(np.int32)
    s_arr = np.array([list(map(int, input().split())) for _ in range(d)]).astype(np.int32)
    t_arr = np.array([int(input()) for _ in range(d)]).astype(np.int32)
    res = solve(d, c_arr, s_arr, t_arr)
    for r in res:
        print(r)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from time import time
from random import randint

from numba import njit
from numpy import int64

@njit('i8(i8[:],i8[:])')
def func(s,x):
    last=[0]*26
    score=0
    for i,v in enumerate(x,1):
        last[v]=i
        c=0
        for j in range(26):
            c+=s[j]*(i-last[j])
        score=score+s[i*26+v]-c
        print(score)
    return score

def main():
    start=time()
    d,*s=map(int,open(0).read().split())
    s=int64(s)
    func(s,s[-d:]-1)
main()

Submission status: Accepted

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

def calc_score(day, contest, score, last):
  last[contest] = day + 1

  contest_score = s[day][contest]
  score += contest_score

  dis = 0
  for i in range(26):
    dis += c[i] * ((day + 1) - last[i])
  score -= dis

  return score, last


score = 0
last = [0 for i in range(26)]
for day in range(d):
  contest = t[day]
  contest -= 1
  score, last = calc_score(day, contest, score, last)
  print(score)

Submission status: Accepted

Solution code:
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)])
t = np.array([int(input())-1 for _ in range(D)])

last = np.full(26,-1)

S = 0
score = 0;
for i,v in enumerate(t):
    S += s[i][v]
    last[v] = i
    tmp =c*(i - last)
    S -= sum(tmp) 
    score +=max(10**6+S,0)
    print(S)

Submission status: Accepted

Solution code:
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)])
t = np.array([int(input())-1 for _ in range(D)])

last = np.full(26,-1)

S = 0
score = 0;
for d in range(D):
    S += s[d][t[d]]
    last[t[d]] = d
    for i in range(26):
        S-=c[i]*(d - last[i])
    score +=max(10**6+S,0)
    print(S)

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(D)]
t = [int(input())-1 for _ in range(D)]

S = 0
last = [-1]*26
score = 0;
for d in range(D):
    S += s[d][t[d]]
    last[t[d]] = d
    for i in range(26):
        S-=c[i]*(d - last[i])
    score +=max(10**6+S,0)
    print(S)

Submission status: Accepted

Solution code:
D, *I = map(int, open(0).read().split())
C, S, T = I[:26], list(zip(*[iter(I[26:-D])] * 26)), I[-D:]

last = [0] * 26
ans = 0
for d, i in enumerate(T, 1):
    ans += S[d - 1][i - 1]
    last[i - 1] = d
    ans -= sum(c * (d - l) for c, l in zip(C, last))
    print(ans)

Submission status: Accepted

Solution code:
d = int(input())
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
X = [int(input()) - 1 for i in range(d)]
L = [-1 for j in range(26)]
score = 0
for i in range(d):
    L[X[i]] = i
    score += S[i][X[i]]
    score -= sum([C[j] * (i - L[j]) for j in range(26)])
    print(score)