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.

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

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

Solution (Python):
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    
    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) ]
    
    last = [0]*26

    def cp(d, t):
        c = 0
        for i in range(26):
            c += C[i] * (d - last[i])
        return c

    score = 0
    for i in range(D):
        score += S[i][T[i]]
        last[T[i]] = i+1
        c = cp(i+1, T[i])
        score -= c
        print(score)


main()

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

ans = []
val = 0
sch = [0]*26
for d in range(D):
    day = d+1
    t = T[d]-1
    sch[t] = day

    down = 0
    for i in range(26):
        down += C[i]*(day - sch[i])

    val = val + S[d][t] - down
    ans.append(val)

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

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

Solution (Python):


import numpy as np


D = int(input())
c = list(map(int, input().split()))
s = []
for d in range(D):
    s_d = list(map(int, input().split()))
    s.append(s_d)
t = []
for d in range(D):
    t_d = int(input())
    t.append(t_d)

c = np.array(c)
s = np.array(s)
t = np.array(t)


KIND = 26
last = np.array([0 for i in range(KIND)])
S = 0
for d in range(1, D + 1):
    S += s[d - 1][t[d - 1] - 1]
    last[t[d - 1] - 1] = d
    S -= sum(c * (d - last))
    print(S)

Solution (Python):
d = int(input())
c = [0] + list(map(int, input().split()))

s = [0]
for i in range(d):
  s.append([0] + list(map(int, input().split())))
  
t = [0]
for i in range(d):
  t.append(int(input()))
  
sati = [0] * (d+1)
last = [0] * 27

for i in range(1, d+1):
  sati[i] = sati[i-1] + s[i][t[i]]
  unsati = 0
  last[t[i]] = i
  for j in range(1, 27):
    unsati += c[j] * (i - last[j])
  sati[i] -= unsati
  
for i in range(1, d+1):
  print(sati[i])

Solution (Python):
d = int(input())
c = list(map(int,input().split()))
s = []
for i in range(d):
  si = list(map(int,input().split()))
  s.append(si)
lastd = [-1 for _ in range(26)]
ans = 0
for i in range(d):
  di = int(input())
  lastd[di-1] = i
  ans += s[i][di-1]
  for j in range(26):
    ans -= (i-lastd[j])*c[j]
  print(ans)

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)]
t = [int(input()) for _ in range(D)]

M = 26
last = [0]*M
score = 0
for i in range(D):
    score += S[i][t[i]-1]
    last[t[i]-1] = i+1
    for m in range(M):
        score -= C[m]*(i+1-last[m])
    print(score)

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

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

Solution (Python):
D = int(input())
Cs = list(map(int,input().split()))
Ss = [list(map(int,input().split())) for i in range(D)]
ts = []
for i in range(D):
    ts.append(int(input()))

last = [0]*26
satisfy = 0

for day,t in enumerate(ts):
    day += 1
    last[t-1] = day
    satisfy += Ss[day-1][t-1]
    for i in range(26):
        satisfy -= Cs[i]*(day-last[i])
    print(satisfy)

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

def solve(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
        print(ans)
    
    return  
def resolve():
    global D,C,S
    
    D,=pin()
    C=[*pin()]
    S=[[*pin()]for i in range(D)]

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

    

resolve()

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

ans=[0]*(d+1)
v=sum(c)


PL=[0]*26

for i in range(d):
    x=t[i]-1
    ans[i+1]+=ans[i]+D[i][x]
    PL[x]=i+1
    for j in range(26):
        ans[i+1]-=(i+1-PL[j])*c[j]

for i in range(1,d+1):
    print(ans[i])

Solution (Python):
d = int(input())
cs = list(map(int, input().split()))
sm = [list(map(int, input().split())) for _ in range(d)]
ts = [int(input()) for _ in range(d)]
ls = [0] * 26

s = 0
for i in range(d):
    t = ts[i]
    t -= 1
    s += sm[i][t]
    ls[t] = i + 1
    
    
    
    

    dis = sum(c * ((i+1) - l) for c, l in zip(cs, ls))
    
    s -= dis

    print(s)

Solution (Python):
D = int(input())
C = [int(i) for i in input().split()]
scores = [[int(i) for i in input().split()] for j in range(D)]
t = [int(input()) for i in range(D)]

ans = []
S = 0
last = [0]*26
for d in range(1,D+1):
    S += scores[d-1][t[d-1]-1]
    last[t[d-1]-1] = d
    for i in range(26):
        S -= C[i] * (d - last[i])
    ans.append(S)
print("\n".join(map(str, ans)))

Solution (Python):
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)]
v = 0
last = [0] * 26
for d in range(D):
    
    ct= T[d] - 1
    last[ct] = d + 1
    
    v += S[d][ct]
    
    v -= sum([C[t] * (d + 1 - last[t]) for t in range(26)])
    print(v)

Solution (Python):
D = int(input())
c = [int(x) for x in input().split()]
s = []
for i in range(D):
    s.append([int(x) for x in input().split()])
ans = 0
nissuu = [0] * 26
for i in range(D):
    t = int(input())
    for j in range(26):
        if j == t-1:
            nissuu[j] = 0
        else:
            nissuu[j] += 1
        ans -= c[j]*nissuu[j]
    ans += s[i][t-1]
    print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    for _ in range(D):
        si = list(map(int, input().split()))
        s.append(si)
    score = 0
    last_list = [0] * 26
    for i in range(D):
        t = int(input())
        last_list[t-1] = i+1
        current = s[i][t-1]
        minus = 0
        for j in range(26):
            if t - 1 != j:
                minus += c[j] * (i+1-last_list[j])
        current -= minus
        score += current
        print(score)
if __name__ == "__main__":
    main()

Solution (Python):
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(D)]
A = [0 for i in range(26)]
ans = 0
for i in range(D):
  t = int(input())
  A[t-1] = i+1
  c = 0
  for j in range(26):
    c += C[j] * (i+1-A[j])
  ans += S[i][t-1]-c
  print(ans)

Solution (Python):


from collections import defaultdict
from heapq import heappush, heappop
import sys
import numpy as np


sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  


def debug(*x):
    print(*x)


def solve():
    "void()"
    pass


def main():
    D = int(input())
    CS = list(map(int, input().split()))
    data = np.int16(read().split())
    S = data[:D * 26].reshape((D, 26))
    answer = data[D * 26:]

    last = [-1] * 26
    score = 0
    for i in range(D):
        j = answer[i] - 1
        score += S[i, j]
        last[j] = i
        score -= sum(CS[j] * (i - last[j]) for j in range(26))
        print(score)
    


T = """
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
"""

OUT = """
1
17
13
14
13
"""


def _test():
    """
    >>> as_input(T)
    >>> main()
    18398
    35037
    51140
    65837
    79325
    """
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())
    input = f.readline
    read = f.read


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        
        
        from my_module import solve  
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()

Solution (Python):
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 _ in range(26)]

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

Solution (Python):


import sys
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union






























def main():
    Num = Union[int, float]
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def isp():   return input().split()
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    def calc_total_score(schedule):
        ans = []
        last = [-1] * 26
        satisfy = 0
        for day in range(D):
            contest_id = schedule[day]
            last[contest_id] = day
            satisfy += score[day][contest_id]
            for i in range(26):
                satisfy -= c[i] * (day - last[i])
            ans.append(satisfy)
        return ans
    

    D = ii()
    c = lmi()
    score = [lmi() for _ in range(D)]

    schedule = [ii() - 1 for _ in range(D)]
    print(*calc_total_score(schedule), sep='\n')




if __name__ == "__main__":
    main()

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

last=[0]*26
ans=0

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

Solution (Python):
def main():
    d = int(input())
    c = [int(i) for i in input().split()]
    s = [[int(i) for i in input().split()] for _ in range(d)]
    t = [int(input()) - 1 for _ in range(d)]
    score = 0
    last = [0] * 26
    for i in range(d):
        score += s[i][t[i]]
        last[t[i]] = i + 1
        for j in range(26):
            score -= c[j] * (i + 1 - last[j])
        print(score)


if __name__ == '__main__':
    main()

Solution (Python):
d = int(input())
clist = list(map(int,input().split()))
last_c = [0]*26

slist = [0] * d
for i in range(d):
    slist[i] = list(map(int,input().split()))

tlist = [0]*d
for i in range(d):
    tlist[i] = int(input())

satisfy = [0]*(d+1)

for i in range(1,d+1):
    satisfy[i] = slist[i-1][tlist[i-1]-1] + satisfy[i-1]
    last_c[tlist[i-1]-1] = i
    for j in range(26):
        satisfy[i] -= clist[j] * (i - last_c[j])


satisfy.remove(0)

for i in satisfy:
    print(i)

Solution (Python):
def main():
    d = int(input())
    c = [int(v) for v in input().split()]
    last = [-1] * 26
    s = []
    for _ in range(d):
        s.append([int(v) for v in input().split()])
    t = []
    for _ in range(d):
        t.append(int(input()))

    td = 0
    for i in range(d):
        test = t[i]-1
        td += s[i][test]
        last[test] = i
        for j in range(26):
            td -= c[j]*(i-last[j])
        print(td)

main()

Solution (Python):
D = int(input())
c = list(map(int, input().split()))
s = list()
for _ in range(D):
	s.append(list(map(int, input().split())))
t = list()
for _ in range(D):
	t.append(int(input()))
v = 0
l = [0 for _ in range(26)]
def f(date, l):
	tmp = 0
	for i in range(26):
		tmp += c[i]*(date + 1 - l[i])
	return tmp

for i in range(D):
	v += s[i][t[i] - 1]
	l[t[i] - 1] = i + 1
	v -= f(i, l)
	print(v)

Solution (Python):
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)]
ans = 0
for i in range(D):
    ans += S[i][t[i]-1]
    manzoku_down = 0
    for k in range(26):
        last = 0
        for j in range(0,i+1):
            if t[j] == k+1:
                last = j+1
        manzoku_down += C[k]*((i+1)-last)
    ans -= manzoku_down
    print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

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

v = 0

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

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

s_rate = 0

last_days = [0] * 26

for day in range(d):
    s_rate += s[day][t[day]-1]
    last_days[t[day]-1] = day + 1
    for j in range(26):
        s_rate -= c[j] * (day + 1 - last_days[j])
    print(s_rate)

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

satisfaction = 0
last = [0]*26

for i in range(D):
    satisfaction += S[i][T[i]-1]

    last[T[i]-1] = i+1


    satisfaction -= sum([C[k]*((i+1)-last[k]) for k in range(26)])


    print(satisfaction)

Solution (Python):
import sys
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 main():
    D = int(input())
    C = inpl()
    Ss = [inpl() for _ in range(D)]
    T = [int(input()) for _ in range(D)]
    last_d = [-1] * len(C)

    v = 0
    for d in range(D):
        tmp = count_v(last_d, C, Ss[d], T[d], d)
        v += tmp
        print(v)

    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import bisect
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
d=read()
c=list(reads())
s=[[]for i in range(d) ]
for i in range(d):
    s[i]=list(reads())
t=[[]for i in range(d)]
for i in range(d):
    t[i]=read()
    t[i]-=1
contestcount=26
last=[0 for i in range(contestcount)]
score=0
for i in range(d):
    score+=s[i][t[i]]
    last[t[i]]=i+1
    for j in range(contestcount):
        score-=c[j]*(i+1-last[j])
    print(score)

Solution (Python):








import sys

D = int(sys.stdin.readline())
c = tuple(map(int,sys.stdin.readline().split())) 
s = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(D)) 
t = tuple(int(sys.stdin.readline()) for _ in range(D)) 

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

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

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)

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

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

last = [0]*26

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

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

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

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

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

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

Solution (Python):
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json

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

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

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

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

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

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

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

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)

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

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

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

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

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

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