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:
d = int(input())
c = list(map(int,input().split()))
like=0
but=0
s=[]
last=[]
for i in range(26):
    last.append(0)
for i in range(d):
    keys=list(map(int,input().split()))
    s.append(keys)
t=[]
for i in range(d):
    t.append(int(input())-1)
for i in range (d):
    like+=s[i][t[i]]
    #print(like)
    last[t[i]]=i+1
    for j in range(26):
        like-=c[j]*(i+1-last[j])
    print(like)

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int, input().split()))
s = [input().split() for _ in range(D)]
t = [int(input()) for _ in range(D)]
last = [0] * 26  # コンテストを開催した最後の日
v = 0 # 満足度
for d in range(1, D + 1):
    last[t[d - 1] - 1] = d
    v += int(s[d - 1][t[d - 1] - 1])
    for i in range(26):
        v -= c[i] * (d - last[i])
    print(v)

Submission status: Accepted

Solution code:
D = int(input())
C = list(map(int, input().split()))
S = list()
for i in range(D):
    tmp_ = list(map(int, input().split()))
    S.append(tmp_)
T = list()
for i in range(D):
    T.append(int(input()))
ret = 0
lastd = [0] * 26
for i in range(D):
    ret += S[i][T[i]-1]
    lastd[T[i] - 1] = i + 1
    for j in range(26):
        ret -= C[j] * (i + 1 - lastd[j])
    print(ret)

Submission status: Accepted

Solution code:
D=int(input())
ListC = list(map(int, input().split()))
dictC={}
for i in range (1,27):
   dictC[i] = int(0) 
ListS = []
for i in range (D):
   ListS.append(list(map(int, input().split())))
ListT = []
for i in range (D):
   ListT.append(int(input()))
res = 0
for j in range(D):
  res += ListS[j][ListT[j]-1]
  for i in range(1,27):
    if ListT[j] == i:
      pass
    else:
      res += -1*(j+1-dictC[i])*ListC[i-1]
  dictC[ListT[j]] = j+1
  print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import time
import numpy as np

start = time.time()
limit_time = 1.8

# 整数の入力
d = int(input())
c = [int(i) for i in input().split()]
s = [[int(i) for i in input().split()] for j in range(d)]

def point(t):
    result = 0
    map = {
        0: 0, 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
    }
    for i in range(d):
        comp = t[i] - 1
        day = i + 1
        map[comp] = day
        result = result + s[i][comp]
        for cc in range(26):
            result = result - c[cc] * (day - map[cc])
        print(result)
    return result

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

point(t)

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

    print(v)

Submission status: Accepted

Solution code:
D = int(input())
C = [0] + list(map(int, input().split())) # type_iのvの下がりやすさ = C[i]
S = [0] + [[0] + list(map(int, input().split())) for _ in range(D)]

T = [0] + [int(input()) for _ in range(D)]
last = [0] + [0 for _ in range(26)]

v = 0 # 現在の満足度
for d in range(1, 1+D): # d = 1, 2, ..., Dについて
    v += S[d][T[d]] # s_di満足度が増える
    last[T[d]] = d # type_T[d]を開催した最後の日をdに設定
    # 満足度現象の計算
    for i in range(1, 27): # type1～27まで
        v -= C[i] * (d - last[i])
    print(v)

Submission status: Accepted

Solution code:
D=int(input())
c=list(map(int,input().split()))
c_memo=[0]*26
s=[]
for i in range(D):
    ss=list(map(int,input().split()))
    s.append(ss)
ans_b=[]
for i in range(D):
    t=int(input())
    c_down=0
    for j in range(26):
        if j==t-1:
            c_memo[t-1]=i+1
            continue
        else:
            c_down+=(i+1-c_memo[j])*c[j]
    ans=s[i][t-1]-c_down
    ans_b.append(ans)
ans=0
for x in ans_b:
    ans+=x
    print(ans)

Submission status: Accepted

Solution code:
N = 26
D = int(input())
C = [int(i) for i in input().split()]

S = []
for i in range(D):
  s = [int(i) for i in input().split()]
  S.append(s)
  
SUM = 0
L = [0] * 26
  
T = []
for i in range(D):
  t = int(input())
  T.append(t-1)

for i in range(D):
  d = i + 1
  for j in range(N):
    if j == T[i]:
      SUM += S[i][j]
      L[j] = d
    else:
   	  SUM -= C[j] * (d - L[j])
  else:
    print(SUM)

Submission status: Accepted

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

last = [0] * 27
ans = 0
d = 0
for i in t:
    d += 1
    for j in range(1, 27):
        if j == i:
            continue
        ans -= c[j] * (d - last[j])
    last[i] = d
    ans += s[d][i]
    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()) for _ in range(D)]


lasts = [[-1] * 26 for _ in range(D + 1)]
S = 0
for d in range(D):
    S += s[d][t[d] - 1]

    for i in range(26):
        if i == t[d] - 1:
            lasts[d+1][i] = d
        else:
            lasts[d+1][i] = lasts[d][i]

    for i in range(26):
        S -= c[i] * (d - lasts[d+1][i])

    print(S)

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

distance_list = [0] * 26

sum_ = 0
for i in range(D):
    sum_ += S[i][T[i]-1]
    down = 0
    for j in range(26):
        if T[i] - 1 == j:
            distance_list[j] = 0
            continue
        distance_list[j] += 1
        down += distance_list[j] * C[j]
    sum_ -= down

    print(sum_)

Submission status: Accepted

Solution code:
d = int(input())
c = list(map(int, input().split()))
s = []
li = [0]*26

for i in range(d):
    si = list(map(int, input().split()))
    s.append(si)

t = []

for i in range(d):
    t.append(int(input()))

ans = []
day = 0

for i in range(d):
    ti = t[i]
    day += s[i][ti-1]
    li[ti-1] = i+1
    for j in range(26):
        day -= c[j]*(i+1-li[j])
    ans.append(day)

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

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
import bisect

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    D = ii()
    c = list(mi())
    s = [list(mi()) for i in range(D)]

    t = [ii()-1 for i in range(D)]

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

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

        k = sum(c[i]*(d+1-last[d][i]) for i in range(26))
        v[d] = v[d-1] + s[d][t[d]] - k
    
    print(*v, sep='\n')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
D = int(input())
c = [int(_) for _ in input().split()]
s = [[int(_) for _ in 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)

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


test=[int(input()) for i in range(D)]
lastday=[0 for j in range(26)]
points=[0 for i in range(D)]

lastday=[lastday[i]+1 for i in range(26)]
lastday[test[0]-1]=0
minus=sum([x*y for (x,y) in zip(c,lastday)])
points[0]=s[0][test[0]-1]-minus


for i in range(1,D):
    lastday=[lastday[i]+1 for i in range(26)]
    lastday[test[i]-1]=0
    minus=sum([x*y for (x,y) in zip(c,lastday)])
    points[i]=points[i-1]+s[i][test[i]-1]-minus


for ps in points:
    print(ps)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# 入出力から得点を計算する
import sys
input = lambda: sys.stdin.readline().rstrip()
D = int(input())
c = list(map(int, input().split()))
s = [[int(i) for i in input().split()] for _ in range(D)]
t = []
for i in range(D):
    tmp = int(input())
    t.append(tmp)

# 得点
result = 0

# 最後に開催された日を保存しておく
last_day = [0 for _ in range(26)]

for i in range(len(t)):
    # 選んだコンテスト
    choose = t[i] - 1

    # 最終開催日を更新
    last_day[choose] = i + 1

    # そのコンテストを選んだ時の本来のポイント
    result += s[i][choose]


    # そこから満足度低下分をマイナス
    for j in range(26):
        result -= c[j] * ((i+1) - last_day[j])
    # result += tmp_point
    print(result)
# print(c,s,t)

Submission status: Accepted

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

ans = 0


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

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

    print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    sat = 0
    last = [0] * 26
    for d in range(D):
        t = T[d] - 1
        sat += S[d][t]
        dsat = 0
        for i in range(26):
            if i == t:
                continue
            dsat += C[i] * ((d + 1) - last[i])
        last[t] = d + 1
        sat -= dsat
        print(sat)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def main():
	D = int(input())  # days
	vC = [0,]+linput()     # decrine rate
	
	#sumC = sum(vC)
	
	# satis (d,i)
	mS = [[0,]+linput() for _ in [0,]*D]
	
	## sample output
	vT = [int(input()) for _ in [0,]*D] ## for p.B

	vL = [-1,]*(26+1)   # last day of Type
	
	#day = -1
	res = 0      # manzoku
	vR = []
	rapp = vR.append
	
	for d in range(D): #[0,364] day
		t = vT[d] ## sample output
		vS = mS[d]
		Sdt = vS[t]
		res += Sdt
		
		vL[t] = d
		C = sum(c*(d-l) for c,l in zip(vC,vL))
		res -= C
		
		rapp(res)
	
	
	#sT = "No Yes".split()
	#print(sT[res])
	#print(res)
	print(*vR, sep='\n')

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
#B

import numpy as np
D = int(input())
C = list(map(int,input().split()))
S = np.empty((D,26))
for i in range(D):
    l = list(map(int,input().split()))
    for j in range(26):
        S[i][j] = l[j]
        
#開催日時の記録
R = np.zeros(26)

sc = 0

#与えられたtでスコアを計算
for i in range(1,D+1):
    
    #ランダムに開催するコンテストを選ぶ
    con = int(input()) - 1
    
    #スコア計算
    #コンテスト開催による上昇
    sc += S[i-1][con]
    R[con] = i
    
    #コンテスト非開催による減少
    for j in range(26):
        sc -= C[j]*(i-R[j])
        
    print(int(sc))

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

cl = sum(c)
D = [0]*26
sas = 0

for i in range(d):
    for j in range(26):
      D[j] += 1
    T = t[i] 
    S = s[i][T-1]
    C = c[T-1]
    D[T-1] = 0
    dc = 0
    for j in range(26):
      dc += D[j]*c[j]
    sas += S - dc
    print(sas)

Submission status: Accepted

Solution code:
import numpy as np
np
d = int(input())
c = [None] + list(map(int, input().split()))
s = [None] + [[None] + list(map(int, input().split())) for _ in range(d)]
t = [None] + [int(input()) for _ in range(d)]
last = np.zeros(27, dtype="i8")

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

Submission status: Accepted

Solution code:
D = int(input())#D=365
c = list(map(int, input().split()))#0<=c<=100
s = [list(map(int, input().split())) for _ in range(D)]#0<=s<=20000

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


v = []
last = [0] * 26
value = 0
for d in range(D):
    type = t[d]
    value += s[d][type - 1]
    last[type - 1] = d + 1
    for i in range(26):
        value -= c[i] * (d + 1 - last[i])
    v.append(value)

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))

d = []
isheld = [0] * 26
for i in range(n):
    b = list(map(int, input().split()))
    d.append(b)
# print(d)

score = 0
minus = 0
for i in range(1, n + 1):
    s = int(input())
    s -= 1

    isheld[s] = i

    for j in range(26):
        score -= a[j] * (i - isheld[j])

    score += d[i - 1][s]
    print(score)

Submission status: Accepted

Solution code:
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)]
ans = 0
llst = [0]*26

for day,i in enumerate(range(D),1):
    llst[t[i]] = day
    ans += s[i][t[i]]
    for j in range(26): ans -= c[j]*(day-llst[j])
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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):
	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:
#create date: 2020-06-28 21:05

import sys
stdin = sys.stdin
import numpy as np

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    d = ni()
    c = np.array(na())
    s = list()
    for i in range(d):
        a = na()
        s.append(a)
    t = list()
    for i in range(d):
        t.append(ni()-1)

    period = np.zeros(26)
    last_day = np.zeros(26)
    v = 0

    for day in range(1, d+1):
        last_day[t[day-1]] = day
    
        v += s[day-1][t[day-1]]
        v -= (sum(c * (day - last_day)))
        print(int(v))
        
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) for _ in range(D)]
now = 1
score = 0
contest = [0] * 26

def down(num):
    ret = 0
    for i, z in enumerate(contest):
        if i == num:
            contest[num] = now
            z = now
        ret += c[i] * (now - z if z != 0 else now)
    return ret

for i in range(D):
    score += s[now - 1][t[i] - 1] - down(t[i] - 1)
    now += 1
    print(score)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

d = I()
contest = LI()
mylist = [LI() for i in range(d)]
day = [0] * 26
result = 0

for i in range(d):
    temp = I()
    result += mylist[i][temp-1]
    day = [j+1 for j in day]
    day[temp-1] = 0
    for k in range(26):
        result -= day[k] * contest[k]
    print(result)

Submission status: Accepted

Solution code:
f=lambda:[*map(int,input().split())]
d=int(input())
c=f()
S,t=[],[]
for i in range(d): S+=[f()]
for i in range(d): t+=[int(input())]
v=0
D=[0]*26
for i in range(d):
  D[t[i]-1]=i+1
  v+=S[i][t[i]-1]
  for j in range(26):
    v-=c[j]*(i+1-D[j])
  print(v)

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int, input().split()))
last = [0] * 26
S = []
for d in range(1, D+1):
    sd = list(map(int, input().split()))
    S += [sd]
score = 0
for d in range(1, D+1):
    td = int(input()) - 1

    cumsump = 0
    for i in range(26):
        if td != i:
            tmp = -c[i] * (d - last[i])
            cumsump += tmp
    last[td] = d
    score += S[d-1][td]+cumsump
    
    print(score)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce


D = a_int()
C = ints()
S = read_tuple(D)
T, = read_col(D)  # これをもとにスコアを計算する
T = mina(*T)

last = [-1] * len(C)
scores = [0]
for d in range(D):
    scores.append(scores[-1] + S[d][T[d]])
    last[T[d]] = d
    for i in range(26):
        scores[-1] -= C[i] * (d - last[i])
print(*scores[1:], sep='\n')

Submission status: Accepted

Solution code:
""" スコア計算機 """

contest_types = 26
days = int(input())
cs = list(map(int, input().strip().split()))
ss = [list(map(int, input().strip().split())) for _ in range(days)]
ts = [int(input()) - 1 for _ in range(days)]

# 満足度
satisfaction = 0

last_days = [-1] * contest_types

for d in range(days):
    # d日目の満足度の増加
    c_type = ts[d]
    increase = ss[d][c_type]
    satisfaction += increase

    # 開催日の更新
    last_days[c_type] = d

    # d日目の満足度の減少
    for i in range(contest_types):
        last = last_days[i]
        decrease = cs[i] * (d - last)
        satisfaction -= decrease

    print(satisfaction)

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

v=[]
S=0


last=[0]*27
for d in range(D):
    S+=s[d][t[d]]

    last[t[d]]=d+1

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math

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

lastday = [0] * 26
sat = 0

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

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 = [0]*D
for i in range(D):
    t[i] =int(input())
m=[0]*D
last_day=[0]*26
a=[[0 for i in range(26)] for j in range(D)]
for u in range(D):
    i=t[u]
    for y in range(u,D):
        a[y][i-1]=u+1
    if u==0:
        m[u]=s[u][i-1]
    else:
        m[u]=m[u-1]+s[u][i-1]
mm=[0]*D
for d  in range(D):
    for i in range(26):
        mm[d]+=c[i]*(d+1-a[d][i])
    if not d==0:
        mm[d]+=mm[d-1]
for d in range(D):
    m[d]-=mm[d]
    print(m[d])

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

manzoku = 0
log = [-1] * 26
for i in range(d):
    q = t[i]-1
    manzoku += s[i][q]
    log[q] = i
    for j in range(26):
        manzoku -= c[j] * (i-log[j])
    print(manzoku)

Submission status: Accepted

Solution code:
import numpy as np
import copy

d=int(input())
c=np.array(list(map(int,input().split())))
curc=copy.deepcopy(c)
s=[]
ans=[]
score=0
for i in range(d):
    s.append(list(map(int,input().split())))

for i in range(d):
    t=int(input())
    score+=s[i][t-1]
    curc[t-1]=0
    score-=sum(curc)
    curc+=c
    print(score)

Submission status: Accepted

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

last = {}
for i in range(1,27):
    last[i] = 0

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
def calc(day, i, m, d, S, c):
    m += S[day][i]
    d[i] = day
    for i in range(26):
        m -= c[i] * (day - d[i])
    return m, d
def main():
    D = int(input())
    c = list(map(int, input().split()))
    S = []
    d = {i:-1 for i in range(26)}
    for _ in range(D):
        s = list(map(int, input().split()))
        S.append(s)
    m = 0
    for i in range(D):
        t = int(input())
        t -= 1
        m, d = calc(i, t, m, d, S, c)
        print(m)
main()

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int,input().split()))
m = sum(c)
S = []
d = []
ans = 0
for i in range(D) :
    s = list(map(int,input().split()))
    S.append(s)
for i in range(D) :
    t = int(input())
    d.append(t)
    ans += S[i][t-1]
    for j in range(26) :
        if j+1 not in d :
            ans -= c[j] * (i+1)
        else :
            a = [k for k, x in enumerate(d) if x == j+1 ]
            ans -= c[j] * (i-a[-1])
    print(ans)

Submission status: Accepted

Solution code:
def resolve():
    d = int(input())
    ci = list(map(int, input().split()))
    si = []
    for _ in range(d):
        si.append(list(map(int, input().split())))
    answers = [int(input()) for _ in range(d)]

    # 和の計算
    score_now = 0

    # コンテストごとの最後の実行日
    last_dates = [-1]*26
    for date in range(d):
        answer = answers[date]
        score_now += si[date][answer-1]

        last_dates[answer-1] = date
        for c, last_date in zip(ci, last_dates):
            score_now -= c*(date - last_date)
        print(score_now)
resolve()

Submission status: Accepted

Solution code:
D = int(input())
cs = list(map(int,input().split()))
ss =[]
for i in range(D):
  ss.append(list(map(int,input().split())))
ts = []
for i in range(D):
  ts.append(int(input()))
last = [0] * 26
total =0
for i in range(len(ts)):
  t = ts[i]
  last[t-1] = i+1
  genten = 0
  for j in range(len(cs)):
    genten += cs[j] *(i+1 - last[j])
  total += ss[i][t-1]-genten
  print(total)

Submission status: Accepted

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


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 i in range(d):
    t = int(input())
    ans += s[i][t-1]
    last[t-1] = i+1
    ans -= dec(i+1)
    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 = [0]
for i in range(d):
    T.append(int(input()))
#print(S)
#print(T)

#最終開催日
Last = [0] * 26

#各Scores
Scores = [0] * 26

for day in range(1, d+1):
    contest = T[day] - 1
    Last[contest] = day
    Scores[contest] += S[day-1][contest]
    for num in range(26):
        Scores[num] -= C[num] * (day - Last[num])
    print(sum(Scores))

Submission status: Accepted

Solution code:


def inputs():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    for d in range(D):
        sd = list(map(int, input().split()))
        s.append(sd)
    t = []
    for d in range(D):
        t.append(int(input()))
    return D, c, s, t


def score(D, c, s, t):
    S = 0
    last = [0 for _ in range(26)]
    score_by_day = []

    for day in range(1, D+1):
        ctype = t[day-1]-1
        S += s[day-1][ctype]
        last[ctype] = day

        S -= sum(c[i]*(day-last[i]) for i in range(26))
        score_by_day.append(S)

    return score_by_day


if __name__ == "__main__":
    D, c, s, t = inputs()

    sbd = score(D, c, s, t)
    for sc in sbd:
        print(sc)