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

from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np


MOD = 1000000007
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): 
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): 
    return reduce(math.gcd, numbers)

def combination(m,n): 
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): 
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr

def main():
    d = int(stdin.readline().rstrip())
    c = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    table = []
    last = [0]*26
    score = 0
    for _ in range(d):
        table.append(list(map(int,[int(x) for x in stdin.readline().rstrip().split()])))
    for D in range(d):
        go = int(stdin.readline().rstrip()) - 1
        for i in range(26):
            if i == go:
                score += table[D][i]
                last[i] = D+1
                
            else:
                score -= c[i]*(D+1-last[i])
                
        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)]

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

ans = 0
for i in range(d):
    type = t[i]  
    contest = c[type-1]
    satisfy = s[i][type-1]
    ans += satisfy
    last[type-1][i:] = [i+1] * (d-i)

    for j in range(26):
        ans -= c[j] * ((i+1)-last[j][i])
    print(ans)

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

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

Solution (Python):
def scoring(last, c, s, t, d, score):
    score += s[d][t[d]-1]
    for i in range(len(c)):
        score -= c[i] * (d+1 - last[d][i])
    return score

score = 0
D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
    s.append([int(i) for i in input().split()])
t = []
for i in range(D):
    t.append(int(input()))

last = [[0 for i in range(len(c))] for j in range(D+1)] 

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

    for i in range(len(c)):
        last[d+1][i] = last[d][i]

    score = scoring(last, c, s, t, d, score)
    print(score)

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

lasts = [0 for i in range(len(c))]
ans = 0
for d in range(1, D+1):
  t = int(input()) - 1
  lasts[t] = d
  ans += s[d][t]
  for i in range(len(c)):
    ans -= c[i] * (d - lasts[i])
  print(ans)

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


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


def main():
    d = I()
    c = LI()
    s = LIR(d)
    t = IR(d)
    last = [0] * 26
    satis = 0
    for day in range(d):
        j = t[day] - 1
        last[j] = day + 1
        satis += s[day][j]
        satis -= satisfaction(day + 1, last, c)
        print(satis)


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())-1 for _ in range(D)]

last = [0] * 26
score = 0
for d in range(D):
    v = T[d]
    score += S[d][v]
    for i in range(26):
        if i == v:
            last[i] = 0
        else:
            last[i] += 1
        score -= C[i] * last[i]
    print(score)

Solution (Python):
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
ans = 0
for i in range(d):
    v = T[i]
    ans += S[i][v]
    for j in range(26):
        if j == v:
            last[j] = 0
        else:
            last[j] += 1
        ans -= C[j] * last[j]
    print(ans)

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)]
tmp = 0
last = [0]*(26)
v = [0]*(D+1) 


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

for i in range(1,D+1):
	print(v[i])

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

res = 0
count = 0

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

Solution (Python):

import numpy as np
D = int(input())
C = np.array(list(map(int, input().split())))
S = np.zeros((D,26),int)
for i in range(D):
    S[i] = list(map(int, input().split()))

t = np.zeros(D,int)
for i in range(D):
    t[i] = int(input())

score = int(0)
ld = -np.ones(26,int)
tscore = np.zeros(26,int)
for i in range(D):
    cid = t[i]-1
    ld[cid] = i
    score -= np.sum(C*(i-ld))
    score += S[i,cid]
    print(score)

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

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

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

D = int(readline())
C = list(map(int,readline().split()))
S = [None] * D
for i in range(D):
  s = list(map(int,readline().split()))
  S[i] = s
  
def calc_score(arr):
  point = 0
  last_submit = [-1] * 26
  for i in range(len(arr)):
    point += S[i][arr[i]]
    last_submit[arr[i]] = i
    for j in range(len(last_submit)):
      point -= (i - last_submit[j]) * C[j]
    print(point)
  return point

T = [None] * D
for i in range(D):
  T[i] = int(readline()) - 1
  
ans = calc_score(T)

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

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

Solution (Python):
import numpy as np

d = int(input())    
C = list(map(int, input().split()))  
S = []  
T = []  
L = [0] * 26    

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

for _ in range(d):
    T.append(int(input()))






sat = 0
S = np.array(S)

for i in range(d):
    con_type = T[i]
    
    complain = 0
    L[con_type - 1] = i + 1     
    for j in range(26):
        
        complain = complain + C[j] * (i + 1 - L[j])

    
    
    

    sat = sat + S[i][con_type - 1] - complain

    print(sat)

Solution (Python):
import copy
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()))
u = [] 
x = [0] * 26
u.append(x)
for i in range(D):
  v = copy.deepcopy(u)
  y = v[-1]
  y[t[i]-1] = i+1
  u.append(y)
del u[0]

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

Solution (Python):
D = int(input())
clist = list(map(int, input().split()))
slist = [list(map(int, input().split())) for _ in range(D)]
tlist = [int(input()) for _ in range(D)]
zlist = []
dlist = [0] * 26
ans = 0
'''
print(sum(clist))
print('--------------')
print(slist[0][0])
print(slist[1][16])
print(clist[16])

print('--------------')
'''
for i in range(D):
  
  zlist.append(clist[tlist[i]-1] * ((i+1) - dlist[tlist[i]-1]))
  dlist[tlist[i]-1] = i+1
  ans += slist[i][tlist[i]-1] - ((i+1) * sum(clist)) + sum(zlist)
  print(ans)

Solution (Python):
D = int(input())

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


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


t = [int(input()) for j in range(D)]

last = [0]*26 

SP = 0
dis = 0

for k in range(D): 
    SP += s[k][t[k]-1]
    last[t[k]-1] = k + 1 
    for m in range(26):
        SP -= c[m] * (k + 1 - last[m])
    print(SP)

Solution (Python):
d = int(input())
C = list(map(int, input().split()))
S = []
for _ in range(d):
    S.append(list(map(int, input().split())))
v = 0
LDs = [0 for _ in range(26)]
for i in range(d):
    t = int(input()) - 1
    R = [(i + 1 - LDs[j]) * C[j] for j in range(26)]
    del R[t]
    v += S[i][t] - sum(R)
    LDs[t] = i + 1
    print(v)

Solution (Python):
import numpy as np
import numba


@numba.njit('i4[:](i4, i4[:], i4[:, :], i4[:])')
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()

Solution (Python):
D=int(input())
C=list(map(int,input().split()))
S=list()
for i in range(D):
  S.append(list(map(int,input().split())))
t=list()
for i in range(D):
  t.append(int(input()))

M=0
di=[0]*26
for d in range(D):
  for i in range(26):
    if i==t[d]-1:
      di[i]=0
    else:
      di[i]+=1
  M+=S[d][t[d]-1]
  for i in range(26):
    M-=C[i]*(di[i])
  print(M)

Solution (Python):
D = int(input())
c = list(map(int, input().split()))
s_tbl = [list(map(int, input().split())) for _ in range(D)]
ans = 0
last = [0] * 26

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

Solution (Python):
D=int(input())
c=[int(x) for x in input().split()]
s=[[0]*i for i in range(D)]
t=[]
last_d=[0]*26
for i in range(D):
  s[i]=[int(x) for x in input().split()]
for i in range(D):
  t.append(int(input()))

v=0
for i in range(D):
  a=0
  for j in range(26):
    if j!=t[i]-1:
      n=i+1-last_d[j]
      a+=c[j]*n
  v=v+s[i][t[i]-1]-a
  print(v)
  last_d[t[i]-1]=i+1

Solution (Python):
import numpy as np


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

T = np.array([])
for i in range(D):
    T = np.append(T,int(input()))

"""
D = 365
c = np.random.randint(0,100,size=(26))
S = np.random.randint(0,20000,size=(D,26))
"""

def calc_score(T,D,c,S):
    last = np.ones(26) * (-1)
    scores = []
    score = 0
    for d in range(D):
        i = int(T[d])-1
        score += S[d,i]
        last[i] = d
        score -= np.sum(c*(d-last))
        scores.append(score)
    score = max([10**6+score,0])
    return score,scores

_,ans = calc_score(T,D,c,S)
for a in ans:
    print(int(a))

Solution (Python):
D=int(input())
*c,=map(int,input().split())

ci=[(c[i-1],i) for i in range(1,27)]
ci=[(0,0)]+ci


last=[[0]*27]*(D+1)
S=[[0]*27]*(D+1)
DP=[[0]*27]*(D+1)
T=[0]*(D+1)

for d in range(1,D+1):
    *S[d],=map(int,input().split())
    S[d]=[0]+S[d]
    
for d in range(1,D+1):
    T[d] = int(input())

def do_id(i,d):
    dn=0
    last[d][i]=d    
    for k in range(1,27):
      if k!=i:
        dn += ci[k][0]*(d-last[d][k])
    return S[d][i]-dn

Satis=0  
for d in range(1,D+1):
    Satis+=do_id(T[d],d)
    print(Satis)
  
def cal():  
  for d in range(1,D+1):
    mxid=0
    mxi,mxd=0,0
    for i in range(1,27):
      tc,ti=ci[i]
      doid=do_id(ti,d)
      if doid>mxid:
           mxid=doid
           mxi,mxd=ti,d
    DP[mxd][mxi]=mxid             
    last[mxd][mxi]=d
  print(DP)

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

res = 0
count = 0

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

Solution (Python):
(d,), cc, *sstt = [list(map(int, s.split())) for s in open(0)]

ss = sstt[:d]

tt = list(map(lambda x: x-1, sum(sstt[d:], [])))

comp = [0]*len(cc)

ans = 0

for i in range(d):
    comp = [sum(x) for x in zip(comp, cc)]
    t = tt[i]
    ans += ss[i][t]
    comp[t] = 0
    ans -= sum(comp)
    print(ans)

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

ans = [0]*d
last = [0]*26

def score(day, last, today, C, S):
    res = 0
    res += S[day][today]
    last[today] = day+1
    for i in range(26):
        res -= C[i]*(day+1 - last[i])
    return res        

for i in range(d):
    t = int(input())
    if i > 0:ans[i] += ans[i-1]
    ans[i] += score(i,last,t-1,C,S)
print("\n".join(str(i) for i in ans))

Solution (Python):
N = 26
D = int(input())

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

s_table = []
for _ in range(D):
	s_table.append(list(map(int, input().split())))

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

def calc(data):
	last = [-1] * N
	satisfaction = 0
	for i in range(D):
		j = data[i]
		satisfaction += s_table[i][j]
		last[j] = i
		for k in range(N):
			satisfaction -= c_list[k] * (i - last[k])
		print(satisfaction)
	return satisfaction

calc(data)

Solution (Python):


import numpy as np
import copy

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



lists = np.array([0 for i in range(26)])
Y = 0
for i,j in zip(contest,inputs):
    lists += 1
    lists[j-1] = 0
    X = C * lists.T
    
    
    
    
    Y = i[j-1]-sum(X)+Y
    print(Y)
    Y = copy.deepcopy(Y)

Solution (Python):
d=int(input())
a=[]
for x in range(d+1):
  b=list(map(int,input().split()))
  a.append(b)
nittei=[]
for x in range(d):
  nittei.append(int(input()))
  

sum1=sum(a[0][0:26])
ans=[0]*d
humann=a[0]*d
humann=humann+[0]*26



for n in range(d):
  date=nittei[n]
  ans[n]=(a[n+1][date-1])
  try:
    for z in range(26):
      humann[n*26+z]=int(humann[(n-1)*26+z])+int(humann[n*26+z])
  except:
    True
  humann[n*26+date-1]=0
  sum2=sum(humann[n*26+0:n*26+26])
  ans[n]=int(ans[n]) - int(sum2)
  
  
  try:
    ans[n]=ans[n]+ans[n-1]
  except:
    True
    
for y in range(d):
  print(ans[y])

Solution (Python):
D = int(input())
c = list(map(int, input().split()))
s = []
c_sum = sum(c)
for i in range(D):
    tmp = list(map(int, input().split()))
    s.append(tmp)
t = []
for i in range(D):
    tmp = int(input())
    t.append(tmp-1)
cnt = [-1 for j in range(26)]
now = 0
for i in range(D):
    cnt[t[i]] = i
    now += s[i][t[i]]
    tmp = 0
    for j in range(26):
        if j != t[i]:
            if cnt[t[i]] == -1:
                tmp += c[j] * (i + 1)
            else:
                tmp += c[j] * (i - cnt[j])
    now -= tmp
    print(now)

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

def main():
    D = int(input())
    c = [0] + list(map(int, input().split()))
    s = [[0]*27]
    t = [0]
    satisfy = 0
    last = [0] * 27
    for _ in range(D):
        s.append([0] + list(map(int, input().split())))
    for _ in range(D):
        t += [int(input())]
    for i in range(1, D+1):
        decrease = 0
        last[t[i]] = i
        for j in range(1, 27):
            decrease += (c[j] * (i - last[j]))
        satisfy += (s[i][t[i]] - decrease)
        print(satisfy)

if __name__ == '__main__':
    main()

Solution (Python):
import copy

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

V = []
for _ in range(D):
    v = int(input())
    V.append(v)

results = []


last = [0 for i in range(26)]
next_costs = [0 for i in range(26)]

result = 0
for d in range(D):
    for i in range(26):
        next_costs[i] = C[i] * (d+1-last[i])

    index = V[d] - 1
    next_costs_sum = sum(next_costs)
    result += S[d][index] - (next_costs_sum - C[index] * (d+1-last[index]))
    last[index] = d + 1
    results.append(result)

for result in results:
    print(result)

Solution (Python):
import time
import random


class Problem:

    def __init__(self, D, s, c):
        self.last_days = [0] * 26
        self.D = D
        self.s = s
        self.c = c
        self.answer = [0] * self.D
        self.best_answer = [0] * self.D
        self.best_score = 0
        self.days = [0] * self.D
        self.best_answer_scores = [0] * self.D

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

    def get_all_scores(self, day):
        """全ての選択肢のscoreを返す"""
        minus_score = 0
        all_scores = [0] * 26
        for i in range(26):
            if i == 0:
                for j in range(1, 26):
                    minus_score += self.c[j] * (day + 1 - self.last_days[j])
                all_scores[0] = self.s[day][0] - minus_score

            else:
                minus_score += self.c[i - 1] * (day + 1 - self.last_days[i - 1])
                minus_score -= self.c[i] * (day + 1 - self.last_days[i])
                all_scores[i] = self.s[day][i] - minus_score
        return all_scores

    def _strategy_greedy(self, day):
        score = self.scoring(day, self.days[day])
        return score, self.days[day]

    def solve(self):
        self.init()

        sum_score = 0
        scores = []
        for i in range(self.D):
            score, ind = self._strategy_greedy(i)
            self.last_days[ind] = i + 1
            self.answer[i] = ind
            sum_score += score
            scores.append(sum_score)
        return sum_score, self.answer, scores

    def _strategy_perturbation(self):
        
        
        day = random.randint(0, 3)

        

        random.randint(0, 3)

    def solve_greed(self):
        self.init()

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


def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    for _ in range(D):
        s.append(list(map(int, input().split())))
    days = []
    for _ in range(D):
        days.append(int(input()) - 1)

    max_score = 0

    problem = Problem(D, s, c)
    problem.days = days
    score, answer,scores = problem.solve()

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


main()

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

d=[0]*(26)
v=[0]*(D+1)


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

Solution (Python):

import sys
from typing import NamedTuple, List

class Game(NamedTuple):
    c: List[int]
    s: List[List[int]]

def solve(D: int, c: "List[int]", s: "List[List[int]]", t: "List[int]"):
    from functools import reduce        
    ans = [0]
    lasts = [0] * 26
    sum_c = sum(c)
    daily_loss = sum_c
    bits = [BIT(D*2) for _ in range(26)]    
    for day, tt in enumerate(t, 1):
        a = s[day-1][tt-1]
        lasts[tt-1] = day
        for i in range(26):
            bits[i].add(day, lasts[i]*c[i])
        a -= daily_loss
        a += sum(b.sum(day)-b.sum(day-1) for b in bits)
        ans.append(ans[-1]+a)
        daily_loss += sum_c
    return ans[1:]


class BIT:
    def __init__(self, node_size):
        self._node = node_size+1
        self.bit = [0]*self._node
 
    def add(self, index, add_val):
        index += 1
        while index < self._node:
            self.bit[index] += add_val
            index += index & -index
 
    def sum(self, index):
        index += 1
        res = 0
        while index > 0:
            res += self.bit[index]
            index -= index & -index
        return res


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    D = int(next(tokens))  
    c = [int(next(tokens)) for _ in range(26)]  
    s = [[int(next(tokens)) for _ in range(26)] for _ in range(D)]  
    t = [int(next(tokens)) for _ in range(D)]  
    print(*solve(D, c, s, t), sep="\n")

def test():
    import doctest
    doctest.testmod()

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

socre = 0
his = [0] * len(C)

for i in range(D):
    t = int(input())
    t -= 1
    his[t] = i + 1
    sat = 0
    for j in range(len(C)):
        sat += C[j] * (i - his[j] + 1)
    socre += S[i][t] - sat

    print(socre)

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

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


ans = 0
last_date = [0]*26
for day in range(D):
  contest = t[day]-1
  ans += s[day][contest]
  last_date[contest] = day+1
  for j in range(26):
    ans -= c[j] * (day+1 - last_date[j])

  print(ans)

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

Solution (Python):
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
out = [int(input()) 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 i in range(D)]
t = [int(input()) for i in range(D)]
cnt = [0]*26
ans = 0
for i in range(D):
  ans += s[i][t[i]-1]
  cnt[t[i]-1] = i+1
  for j in range(26):
     ans -= c[j] * (i+1-cnt[j])
  print(ans)

Solution (Python):


def main():
    d = int(input())
    c = [0] + list(map(int,input().split()))
    last = [0] * 27
    s = [0]
    for i in range(d):
        s.append([0] + list(map(int,input().split())))
    total = 0
    for j in range(1,d+1):
        t = int(input())
        last[t] = j
        total += s[j][t]
        for k in range(1,27):
            total -= c[k] * (j - last[k])
        print(total)






if __name__ == '__main__':
    main()

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 = [int(input()) for _ in range(D)]
def my_index(l,x,d,default=False):
    if x in l:
        return l.index(x)
    else:
        return d
def last(d,i):
    a= t[:d]
    a.reverse()
    day = -1*(my_index(a,i,d))+d
    return day
score = 0
for d in range(1,D+1):
    score += s[d-1][t[d-1]-1]
    for i in range(1,27):
        score -= c[i-1]*(d-last(d,i))
    print(score)

Solution (Python):



def down(i,t):
    max = 0
    for k in range(26):
        max += c[k+1]*(i-last[k+1])
    return max

def manzoku(i,t):
    return s[i][t-1]-down(i+1,t)

last = { 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0,
         8:0, 9:0, 10:0, 11:0, 12:0, 13:0, 14:0, 15:0,
        16:0, 17:0, 18:0, 19:0, 20:0, 21:0, 22:0, 23:0,24:0, 25:0, 26:0
        }


D = int(input())

line = input().split(" ")
c = [0]
for i in range(26):
    c.append(int(line[i]))

s = []
for i in range(D):
    line = input().split(" ")
    sSub = []
    for j in range(26):
        sSub.append(int(line[j]))
    s.append(sSub)

m = 0
for i in range(D):
    t = int(input())
    last[t] = i+1
    m += manzoku(i,t)
    print(m)