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: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

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()  # ignore trailing spaces

D = ni()
c = na()
s = [na() for _ in range(D)]
out = [ni() for _ in range(D)]
sat = 0
last = [0] * 26

for d in range(D):
    assert(1 <= out[d] and out[d] <= 26)
    j = out[d] - 1
    last[j] = d + 1
    for i in range(26):
        sat -= (d + 1 - last[i]) * c[i]
    sat += s[d][j]
    print(sat)

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=[]
last_day = [0]*26
for _ in range(D):
  t.append(int(input()))


sum = 0
for i in range(1,len(t)+1):
  sum += s[i-1][t[i-1]-1]
  last_day[t[i-1]-1]=i
  for j in range(len(c)):
    sum -= c[j]*(i-last_day[j])
  print(sum)

Submission status: Accepted

Solution code:
D = int(input())
C = list(map(int, input().split()))
S = []
con= 0
for _ in range(D):
    S.append(list(map(int, input().split())))
#print(S)
t = []
for _ in range(D):
    t.append(int(input()))

last = [0]*26

for i in range(D):#1日ごと
    con += S[i][t[i]-1]
    #print(S[i][t[i]])
    last[t[i]-1] = i+1
    for j in range(26): #減少量の計算 #問題ごと
        con -= C[j]*(i-last[j]+1)
    
    
    print(con)

Submission status: Accepted

Solution code:
def b_scoring():
    D = int(input())
    Contests = [int(i) for i in input().split()]
    Satisfaction = [[int(i) for i in input().split()] for j in range(D)]
    Training_data = [int(input()) for _ in range(D)]

    ans = []
    s = 0
    last = {i: 0 for i in range(1, 27)}
    for d, t in enumerate(Training_data, 1):
        s += Satisfaction[d - 1][t - 1]
        last[t] = d

        satisfaction_decreasing = 0
        for i in range(1, 27):
            satisfaction_decreasing += Contests[i - 1] * (d - last[i])
        s -= satisfaction_decreasing
        ans.append(s)
    return '\n'.join(map(str, ans))

print(b_scoring())

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)]
now = [0]*26
ans = 0
for i in range(d):
    ans += s[i][t[i]-1]
    now[t[i]-1] = i+1
    for j in range(26):
        ans -= (i+1-now[j])*c[j]
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
D = int(input())
c_list = [int(i) for i in input().split()]
s_list = []
t_list = []
for _ in range(D):
    s = [int(i) for i in input().split()]
    s_list.append(s)
for _ in range(D):
    t_list.append(int(input()))
happy = 0
recent = [0 for _ in range(26)]
for i in range(D):
    happy += s_list[i][t_list[i] - 1]
    recent[t_list[i] - 1] = i + 1
    for j, s in enumerate(s_list[i]):
        happy -= c_list[j] * (i + 1 - recent[j])
    print(happy)

Submission status: Accepted

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):
 t=int(input())
 ans+=s[i][t-1]
 last[t-1]=i+1
 for j in range(26):
  ans+=c[j]*(last[j]-(i+1))
  point[i]=ans
for i in range(D):
 print(point[i])

Submission status: Accepted

Solution code:
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache
import itertools

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    D = int(input())
    c = [int(a) for a in input().split()]
    s = [
        [int(a) for a in input().split()]
        for _ in range(D)
    ]
    t = [
        int(input())
        for _ in range(D)
    ]

    score = 0
    last = [0] * len(c)

    for d, ti in enumerate(t):
        sdi = s[d][ti - 1]
        score += sdi
        last[ti - 1] = d + 1
        for i, ci in enumerate(c):
            score -= ci * ((d + 1) - last[i])
        print(score)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
d = int(input())
clst = list(map(int, input().split()))
slst = []
lastday = [0] * 26
for i in range(d):
  slst.append(list(map(int, input().split())))
res = 0
for i in range(1, d + 1):
  t = int(input())
  lastday[t - 1] = i
  res += slst[i - 1][t - 1]
  c = 0
  for j in range(26):
    c += clst[j] * (i - lastday[j])
  res -= c
  print(res)

Submission status: Accepted

Solution code:
D = int(input())
C = [0]*27
C[1:] = list(map(int,input().split()))
S = [[0]*27 for _ in range(D+1)]
for i in range(1,D+1):
    S[i][1:] = list(map(int,input().split()))

T = [0]*(D+1)
T[1:] = [int(input()) for _ in range(D)]

last = [0]*27
score = 0
for i in range(1,D+1):
    score += S[i][T[i]]
    last[T[i]] = i
    for j in range(1,27):
        score -= (i-last[j])*C[j]
    print(score)

Submission status: Accepted

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 j == t:
                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: Accepted

Solution code:
import numpy as np
D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
  tmp = list(map(int, input().split()))
  s.append(tmp)

total = 0
d = np.zeros(26)
for i in range(D):
  t = int(input())
  
  total += s[i][t-1]
  d[t-1] = (i+1)
  for j in range(26):
    total -= int(c[j]*((i+1)-d[j]))
  print(total)

Submission status: Accepted

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

manzoku = 0
last = [-1]*26

for day in range(D):
    t = int(input())-1
    manzoku += S[day][t]
    last[t] = day
    for i in range(26):
        manzoku -= C[i]*(day-last[i])
    print(manzoku)

Submission status: Accepted

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

### input end ###

# last(d, i)
last = [0] * 26

v = 0

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

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())-1 for i in range(d)]

day = 0
score = 0
last_li = [-1]*26

def incrase(day,probrem_id,last_li,score):
    score+=S[day][problem_id]
    last_li[problem_id]=day+1
    return score,last_li
    
def decrease(day,last_li,score):
    for i in range(26):
        score-=C[i]*(day+1-(0 if last_li[i]==-1 else last_li[i]))
    return score

for i in range(d):
    problem_id = T[i]
    score,last_li = incrase(i,problem_id,last_li,score)
    score = decrease(i,last_li,score)
    print(score)

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int, input().split()))
S = []
last = [0]*26

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

def sat(d):
  s = 0
  for i in range(26):
    s += c[i] * (d - last[i])
  return s

ans = 0

for i in range(D):
  t = int(input())
  ans += S[i][t-1]
  last[t-1] = i+1
  ans -= sat(i+1)
  print(ans)

Submission status: Accepted

Solution code:
import numpy
d = int(input())
c = list(map(int,input().split()))
s = [0]*d
for i in range(d):
    s[i] = list(map(int,input().split()))
t = [0]*d
for i in range(d):
    t[i] = int(input())
ans = 0
lis = [0]*26
for i in range(d):
    ans += s[i][t[i]-1]
    lis[t[i]-1] = -1
    for j in range(26):
        lis[j] += 1
        ans -= lis[j]*c[j]
            
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

last = [0]*26
    
ans = 0
for day in range(D):
    #満足度プラス計算
    ans += s[day][t[day]-1]
    for j in range(26):
        last[j] += 1
    last[t[day]-1] = 0
    #満足度マイナス計算
    minus = 0
    for j in range(26):
        minus += c[j] * (last[j])
    ans -= minus
    print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    D = int(input())
    C = [0] + list(map(int, input().split()))
    S = [[0] * 27]
    for _ in range(D):
        S.append([0] + list(map(int, input().split())))
    T = [0] + [int(input()) for _ in range(D)]

    satisfactory = 0
    last = [0] * 27
    for d in range(1, D + 1):
        last[T[d]] = d
        satisfactory += S[d][T[d]]
        for i in range(1, 27):
            satisfactory -= C[i] * (d - last[i])
        print(satisfactory)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

D = ini()
C = inl()
assert len(C) == 26
S = [None] * D
for i in range(D):
    S[i] = inl()
    assert len(S[i]) == 26
T = [ini() - 1 for _ in range(D)]


def solve():
    ans = 0
    last = [-1] * 26
    for d in range(D):
        ct = T[d]
        ans += S[d][ct]
        last[ct] = d
        for i in range(26):
            ans -= C[i] * (d - last[i])
        print(ans)


solve()

Submission status: Accepted

Solution code:
N =26

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

last = [-1]*(N)
manzoku = 0

for i in range(0,D,1):
    manzoku += s[i][t[i]]
    last[t[i]]=i
    for j in range(0,26,1):
        manzoku -= c[j]*(i-last[j])
    print(manzoku)

Submission status: Accepted

Solution code:
NTEST = 26

D=int(input())

C=list(map(int,input().split()))
lastDay = [0 for i in range(NTEST)]

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

tests=list()
tests.append(0)
for d in range(D):
    tests.append(int(input()))

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

for d in range(D):
  t = int(input())
  ans += s[d][t-1]
  last[t-1] = d+1
  for j in range(26):
    ans -= (d+1-last[j]) * c[j]
  print(ans)

Submission status: Accepted

Solution code:
def resolve():
    D = int(input())
    cost = list(map(int, input().split()))
    sat = [list((map(int, input().split()))) for _ in range(D)]
    last = [0]*26

    sumsat = 0

    for i in range(D):
        pro = int(input())
        pro -= 1
        last[pro] = i + 1
        plussat = sat[i][pro]
        minussat = 0
        for j in range(26):
            minussat += (i+1-last[j])*(cost[j])
        sumsat += (plussat-minussat)

        print(sumsat)
resolve()

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 i in range(D)])

last_day = np.zeros(26, dtype=int)
score = 0

T = [int(input()) for i in range(D)]

ans = []
for d, t in enumerate(T, 1):
    last_day[t-1] = d
    decrease = c * (d - last_day)
    score += S[d-1, t-1] - decrease.sum()
    ans.append(score)

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    D = int(readline())
    C = [int(i) for i in readline().split()]
    S = [[int(i) for i in readline().split()] for _ in range(D)]
    T = [int(readline()) for _ in range(D)]

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

        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)]
sumc = sum(C)
last = [0 for i in range(26)]

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

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)]

N = 26
scores = [0] * N
last = [-1] * N
ans = []
for d in range(D):
    last[t[d]] = d
    scores[t[d]] += s[d][t[d]]

    for i in range(N):
        if last[t[d]] != -1:
            scores[i] -= c[i] * (d - last[i])
    ans.append(sum(scores))

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

Submission status: Accepted

Solution code:
import numpy as np

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

last = np.zeros(26,int)

score = 0

for i in range(D):
    t = int(input())
    t -= 1
    score += s[i][t]
    last += 1 
    last[t] = 0
    score -= np.dot(c,last)
    
    print(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()) for _ in range(d)]
l=[0]*26
ans=0
for i in range(1,d+1):
    ans+=s[i-1][t[i-1]-1]
    l[t[i-1]-1]=i
    for j in range(26):
        ans-=c[j]*(i-l[j])
    print(ans)

Submission status: Accepted

Solution code:
D=int(input())
c=input().split()
c=[int(a) for a in c]
S=[]
for _ in range(D):
    s=input().split()
    s=[int(a) for a in s]
    S.append(s)
T=[]
for _ in range(D):
    t=int(input())-1
    T.append(t)
held=[0 for _ in range(26)]
ans=0
for d in range(D):
    s=S[d]
    place=T[d]
    held[place]=d+1
    ans+=s[place]
    for n in range(26):
        ans-=c[n]*(d+1-held[n])
    print(ans)

Submission status: Accepted

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

t_l = [int(input()) for i in range(d)]

last_l = [-1 for i in range(26)]

ans = 0
for day in range(d):
  contest_num = t_l[day]
  contest_num -= 1

  contest_val = s_l[day][contest_num]

  ans += contest_val
  last_l[contest_num] = day

  for i in range(26):
    ans -= c_l[i] * (day - last_l[i])

  print(ans)

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline().rstrip()
def main():
    def scoring(ans, d, t, C, S, L):
        ans += S[d][t]
        L[t] = d
        ans -= sum([c * (d - l) for (c, l) in zip(C, L)])        
        return ans, L
    D = int(input())
    C = list(map(int, input().split()))
    S = [list(map(int, input().split())) for _ in range(D)]
    L = [-1] * 26
    ans = 0
    for d in range(D):
        t = int(input()) - 1
        ans, L = scoring(ans, d, t, C, S, L)
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    d = int(readline())
    c = list(map(int, readline().split()))
    s = [list(map(int, readline().split())) for _ in range(d)]
    ans = 0
    memo = [0] * 26
    for i in range(1, d + 1):
        t = int(readline()) - 1
        ans += s[i - 1][t]
        memo[t] = i
        for m, cc in zip(memo, c):
            ans -= cc * (i - m)
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

D = int(input())
C = list(map(int, sys.stdin.readline().rsplit()))
S = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(D)]

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

Submission status: Accepted

Solution code:
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
x = [0] * 26
h = 0
for i in range(1, d + 1):
    t = int(input()) - 1
    for j in range(26):
        if j == t:
            h += s[i - 1][j]
            x[t] = i
        else:
            h -= ((i - x[j]) * c[j])
    print(h)

Submission status: Accepted

Solution code:
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
E = [-1] * 26
score = 0
for i in range(D):
    t = int(input())
    score += S[i][t-1]
    E[t-1] = i
    for j in range(26):
        score -= C[j] * (i - E[j])
    print(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)]

scores = []
last = [-1]*26
score = 0
for i in range(D):
    t = int(input())
    t -= 1
    score += S[i][t]
    last[t] = i
    for j in range(26):
        score -= C[j]*(i-last[j])
    scores.append(score)
print(*scores, sep='\n')

Submission status: Accepted

Solution code:
import numpy as np
d=int(input())
c=[0]+[int(j)for j in input().split()]
s=[[0]+[int(j)for j in input().split()]for i in range(d)]
t=[int(input())for i in range(d)]
l=[0]*27
ans=0
for i,j in enumerate(t,1):
    ans+=s[i-1][j]
    l[j]=i
    for k in range(1,27):
        ans-=(i-l[k])*c[k]
    print(ans)

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 d in range(D)])

L = np.empty(26, int)
L[:] = -1

score = 0
for d in range(D):
    t = int(input())-1
    L[t] = d
    score += S[d, t] - np.dot(C, d-L)
    print(score)

Submission status: Accepted

Solution code:
D = int(input())
C = [int(c) for c in input().split()]
S = [[int(s) for s in input().split()] for _ in range(D)]
T = [int(input()) for _ in range(D)]
ans = 0
L = [0]*26
for i in range(D):
    ans += S[i][T[i]-1]
    L[T[i]-1] = i+1
    for j in range(26):
        ans -= C[j]*(i+1-L[j])
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    D = int(_in[0])  # type:int
    c_arr = list(map(int, _in[1].split(' ')))  # type:list(int)
    s_arr = []
    for i in range(D):
        _ = list(map(int, _in[i + 2].split(' ')))  # type:list(int)
        s_arr.append(_)
    t_arr = []
    for i in range(D):
        _ = int(_in[i + D + 2])  # type:list(int)
        t_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    v_arr = [None] * D
    v = 0
    blank = [0] * 26
    for i in range(D):
        t = t_arr[i] - 1
        blank = list(map(lambda x: x + 1, blank))
        blank[t] = 0
        v += s_arr[i][t_arr[i] - 1]
        for j, _blank in enumerate(blank):
            v -= c_arr[j] * _blank
        v_arr[i] = v
        # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        print(v)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

d = int(input())
C = tuple(map(int, input().split()))
S = tuple(tuple(map(int, input().split())) for _ in range(d))
ans = 0
L = [0]*26
for i in range(1, d+1):
  t = int(input())
  t -= 1
  L[t] = i
  ans += S[i-1][t]
  for j, (c, l) in enumerate(zip(C, L)):
    ans -= c*(i-l)
  print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

D = int(input())
c = [int(x) for x in input().split()]
s = []
for _ in range(D):
    s.append([int(x) for x in input().split()])
t = [int(input()) for x in range(D)]
last = [0]*26
ans = 0
for i in range(1, D + 1):
    ans += s[i - 1][t[i - 1] - 1]
    last[t[i - 1] - 1] = i
    for j in range(26):
        ans -= c[j]*(i - last[j])
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np
D = int(input())
C = np.array(input().split(), dtype=int)

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

last = np.ones(26, dtype=int)


ans = 0
for d, t in enumerate(T):
    t -= 1
    last[t] = 0

    score = S[d][t]
    score -= (C * last).sum()
    ans += score
    print(ans)
    last += 1

Submission status: Accepted

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

Submission status: Accepted

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

last = [0] * 26
satisfied = 0
for i in range(1, D+1):
    t = int(input())
    satisfied += s[i-1][t-1]
    last[t-1] = i
    for j in range(26):
        satisfied -= c[j] * (i-last[j])
    print(satisfied)

Submission status: Accepted

Solution code:
d=int(input())
c=list(map(int,input().split()))
ss=[list(map(int,input().split())) for i in range(d)]
ts=[int(input())for i in range(d)]
ans=0

from collections import defaultdict
las=defaultdict(int)

for i in range(d):
    t=ts[i]-1
    ans+=ss[i][t]
    las[t]=i+1
    ans-=sum(c[j]*(i+1-las[j])for j in range(26))
    print(ans)

Submission status: Accepted

Solution code:
D = int(input().strip())

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

score=0
last=[0]*26 # contents: 1 ind
for d in range(1,D+1): # 1 ind
    contest=int(input().strip())
    score+=s[d-1][contest-1]
    last[contest-1]=d
    for i in range(26): # 0ind
        score-=c[i]*(d-last[i])
    print(score)

Submission status: Accepted

Solution code:

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

    ans = 0

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

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)]
MAX = 26

last = [0] * MAX

score = 0
for day, e in enumerate(t, 1):
    score += s[day-1][e-1]
    last[e-1] = day

    for ec, elast in zip(c, last):
        score -= ec * (day - elast)

    print(score)

Submission status: Accepted

Solution code:
from collections import deque
from functools import reduce

d = int(input())
cl = [int(i) for i in input().split()]

sm = []
for _ in range(d):
  sm.append([int(i) for i in input().split()])
sd = deque(sm)

tl = []
for _ in range(d):
  tl.append(int(input()))

hold = [0] * 26
satisfy = 0
for t, num in enumerate(tl):
  hold[num-1] = t + 1
  sl = sd.popleft()
  satisfy += sl[num - 1]
  satisfy -= sum([i * j for i, j in zip(cl, [t - j + 1 for j in hold])])
  print(satisfy)

Submission status: Accepted

Solution code:
import numpy as np

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

v=0
for d in range(1,D+1):
    v+=s[d-1][t[d-1]-1]
    last[t[d-1]-1]=d
    v-=np.dot(c,d-last)
    print(v)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

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

    ret = [0] * (D + 1)
    before = [-1] * 26
    for i in range(D):
        t = int(input()) - 1
        ret[i] += S[i][t]
        before[t] = i
        for j,c in enumerate(C):
            ret[i] -= (i - before[j]) * c
        ret[i + 1] += ret[i]
    print('\n'.join(map(str,ret[:-1])))
if __name__ == '__main__':
    main()