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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

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

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

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

D = I()
C = IL()
S = ILL(D)

ans = 0
score = 0
last = [-1 for i in range(26)]

for d in range(D):
  t = I()-1
  for i in range(26):
    if i == t:
      last[i] = d
      score += S[d][i]
    else:
      score -= C[i]*(d-last[i])
  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
def last(d,i): return llst[i]

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-last(day,j))
    print(ans)

Submission status: Accepted

Solution code:
def main():
    D = int(input())
    c = list(map(int,input().split()))
    s = []
    for d in range(D):
        s.append(list(map(int,input().split())))
        
    t = []
    for d in range(D):
        t.append(int(input())-1)
    
    last = [0 for i in range(26)]
    
    v = 0
    
    for d in range(D):
        v += s[d][t[d]]
        last[t[d]] = d+1
        for i in range(26):
            v -= c[i]*(d+1-last[i])
        print(v)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy


d = int(input())
c = numpy.array(list(map(int, input().split())))
s = []
for i in range(d):
    s.append(list(map(int, input().split())))

result = []
past = numpy.array([0] * 26)
ans = 0
for i in range(d):
    past += 1
    t = int(input())
    past[t-1] = 0
    ans += sum(past * -c) + s[i][t-1]
    print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

D = int(input())
C = list(map(int,input().split()))
S = []
for i in range(D):
    s = list(map(int,input().split()))
    S.append(s)
    
#S = [0] + S
day_of_problems = [0] * 27
past = []
#def cal_last(i):#満足度低下の計算
 #   if i in past:
  #      return past.index(i)
ans = 0
for i in range(D):#i+1日目
    t = int(input())
    day_of_problems[t] = i+1
    ans += S[i][t-1]
    for j in range(26):
        ans -= C[j] * (i+1-day_of_problems[j+1])
    print(ans)

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
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()))

ld=[-1]*26
sc=0
for i in range(d):
    sc+=s[i][t[i]-1]
    ld[t[i]-1]=i

    C=0
    for j in range(26):
        C+=c[j]*(i-ld[j])
    sc-=C
    print(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)]

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

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

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

Submission status: Accepted

Solution code:
D=int(input())                                          #コンテの日数
c=list(map(int,input().split()))                        #26タイプ(AAC~AZC)のコンテストの満足度低下度
s=[list(map(int,input().split())) for _ in range(D)]    #s[d][i]...d(1<=d<=D)日目にi(1<=i<=26)番目のコンテストを行った時の満足度上昇
types=[int(input()) for _ in range(D)]                  #コンテタイプ(1~26)
#満足度低下はΣ(1<=i<=26)ci*(d-last(d,i))                  #なおlast(d,i)=d日目以前に最後にタイプiのコンテストをやった日にち(ない場合0)
#よって満足度はs[d][i]-Σ(1<=i<=26)ci*(d-last(d,i))
#i日目のスコアはmax(10^6+s[d][i]-Σ(1<=i<=26)ci*(d-last(d,i)),0)
last=[0]*26                                             #typeごとに、最後に使われた日にちを記録するよ
typ=0
ans=0
for i in range(D):
    typ=types[i]-1
    score=s[i][typ]
    dwn=0
    last[typ]=(i+1)
    for j in range(26):
        dwn=dwn+c[j]*((i+1)-last[j])
    ans=ans+(score-dwn)
    #print(score,last)
    print(ans)
    #input()

Submission status: Accepted

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

def loss(today):
  sum = 0
  for i in range(26):
    sum += c[i-1] * (today - last[i-1])
  return sum
  
  
v = 0
for today in range(1, d+1):
  t = int(input())
  last[t-1] = today
  v += s[today-1][t-1]
  v -= loss(today)
  print(v)

Submission status: Accepted

Solution code:
D = int(input())

last_list = [0 for i in range(27)]
c_list = list(map(int, input().split()))
c_list = [""] + c_list
# print(c_list)
S_list = [[]for i in range(D)]
P_list = [0 for i in range(27)]
for i in range(D):
    S_list[i] = list(map(int, input().split()))
    S_list[i] = [""] + S_list[i]
S_list = [""] + S_list
# print(S_list)

for i in range(1,D+1):
    S = 0
    t = int(input())
    for j in range(1,27):
        if j == t:
            P_list[j] += S_list[i][j]
            last_list[j] = i
            # print(S_list[i][j])
        else:
            P_list[j] -= c_list[j] * (i-last_list[j])
    for i in range(1,27):
        S += P_list[i]
    print(S)





# t_list = []
# for i in range(D):
#     t_list.append(int(input()))

Submission status: Accepted

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


dp=[0]*26

ans=0
for i in range(d):
    s_i = s[i][t[i]-1]
    ans+=s_i
    dp[t[i]-1]=i+1
    tmp=0
    for j in range(26):
        tmp+=c[j]*((i+1)-dp[j])

    
    

    ans -= tmp

    print(ans)

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

Submission status: Accepted

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

#print(d,c,s)
t=[int(input()) for _ in range(d)]

cnt=0
last=[0]*27

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

Submission status: Accepted

Solution code:

D = int(input())
c_list = list(map(int, input().split()))
s_list = [list(map(int, input().split())) for _ in range(D)]

last_open = [0] * 26
res = 0

res_list = []
for i in range(D):
    t = int(input())
    res += s_list[i][t-1]

    bad = 0
    last_open[t-1] = i+1
    for ci in range(26):
        bad += c_list[ci]*(i+1 - last_open[ci])

    res -= bad
    print(res)
    res_list.append(res)

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)]
l=[0]*26
v=0
for d in range(D):
    x=[S[d][i]-sum([(d+1-l[j])*C[j] for j in range(26) if i!=j]) for i in range(26)]
    l[T[d]-1]=d+1
    v+=x[T[d]-1]
    print(v)

Submission status: Accepted

Solution code:
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(d)]
t = [int(input()) for i in range(d)]
mem = [0 for i in range(26)]
v = 0
su = sum(c)
for a in range(d):
    v += s[a][t[a]-1]
    mem[t[a]-1] = a+1
    for i in range(26):
        v -= c[i]*(a+1 - mem[i])
    print(v)

Submission status: Accepted

Solution code:
import sys
def input():
	return sys.stdin.readline()[:-1]
d = int(input())
c = list(map(int, input().split()))
C = sum(c)
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]

def score(t):
	res = 0
	minus = 0
	last = [0 for _ in range(26)]
	for i, x in enumerate(t):
		minus += C - c[x-1] * (i - last[x-1] + 1)
		res -= minus
		res += s[i][x-1]
		last[x-1] = i+1
		print(res)
	return

score(t)

Submission status: Accepted

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

last_di = [0] * 26

v = 0
for d in range(D):
    i = t[d]
    v += s[d][i - 1]

    last_di[i - 1] = d + 1

    S = 0
    for j in range(len(c)):
        S += c[j] * (d + 1 - last_di[j])

    v -= S
    print(v)

Submission status: Accepted

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

last = [0]*26
sat = 0
for day,kind in enumerate(t):
  sat += s[day][kind-1]
  last[kind-1] = day+1
  for l_kind,l_day in enumerate(last):
    sat -= c[l_kind] * (day+1-l_day)
  print(sat)

Submission status: Accepted

Solution code:
days = int(input())
clast = list(map(int,input().split()))

allpref = [] #allpref[day][contest]
for i in range(days):
    allpref.append(list(map(int,input().split())))
donelist = [0]*26
resultlist = []
result = 0
for i in range(days):
    held = int(input())

    donelist[held-1] = i+1
    zanen = sum([clast[j]*((i+1)-donelist[j]) for j in range(26)])

    result += allpref[i][held-1] -zanen
    resultlist.append(result)

for num in resultlist:
    print(num)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    D = I()
    c = LI()
    s = LLIN(D)
    lst = [0] * 26
    total = 0
    for i in range(D):
        ans = int(input())-1
        l = s[i]
        for j in range(26):
            lst[j] += c[j]
        lst[ans] = 0
        total += s[i][ans]
        for li in lst:
            total -= li
        print(total)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import random
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
last = [0]*26
for i in range(1,d+1):
    #x = 0
    x = t[i-1]-1
    #x = random.randrange(26)
    last[x] = i
    ans += s[i-1][x]
    for j in range(26):
        ans -= c[j]*(i-last[j])
    print(ans)

Submission status: Accepted

Solution code:
def 一日経過(n):
    return n+1
    
D=int(input())
C=list(map(int,input().split()))
S=[]
Ans=0
last=[0 for i in range(26)]
for i in range(D):
    s=list(map(int,input().split()))
    S.append(s)
for i in range(D):
    last=list(map(一日経過,last))
    t=int(input())-1
    last[t]=0
    Ans+=S[i][t]
    for j in range(26):
        Ans-=C[j]*last[j]
    print(Ans)

Submission status: Accepted

Solution code:
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
D = int(readline())
C = list(map(int,readline().split()))
score = []
for i in range(D):
    s = list(map(int,readline().split()))
    score.append(s)
t = list(map(int,read().split()))
last = [0] * 26
S = 0
for d in range(D):
    select = t[d]-1
    S += score[d][select]
    last[select] = d+1
    for i in range(26):
        S -= C[i] * (d+1-last[i]) 
    print(S)

Submission status: Accepted

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

for i in range(D):
    t_list.append(int(input()))

base = 1000000
S = 0

contests_held_day = []
for i in range(26):
    contests_held_day.append(0)

for i in range(D):
    S += s_list[i][t_list[i]-1]
    contests_held_day[t_list[i]-1] = i + 1
    for j in range(26):
        S -= c_list[j] * ((i+1) - contests_held_day[j])
    print(S)

Submission status: Accepted

Solution code:
d=int(input())
c = list(map(int,input().split()))

s=[None]*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
satis=0
pena=0
for j in range(d):
    ss=s[j]
    tt=t[j]
    satis += ss[tt-1]
    
    last[tt-1]=j+1
    
    pena += sum(c[i]*(j+1-last[i]) for i in range(26))
    print(satis-pena)

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

last = []
for i in range(26):
    last.append(0)

last = np.array(last)
ans = 0
for i in range(D):
    last[t[i]-1] = i+1
    dec = c * (i+1-last)
    #ans = ans + s[i][t[i]] 
    ans = ans + s[i][t[i]-1] - sum(dec)
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

last = {}
for i in range(26):
    last[i] = -1

s = 0
for d in range(D):
    last[T[d]] = d
    s += S[d][T[d]]
    for i in range(26):
        #print(d-last[i])
        s -= C[i] * (d-last[i])
    print(s)

Submission status: Accepted

Solution code:
def main():
    D = int(input())
    C = [0] * 26
    C = list(map(int,input().split()))
    S = [ list(map(int,input().split(" "))) for i in range(D)]
    
    score = 0
    last = [0] * 26
    for i in range(D):
        t = int(input())
        for j in range(26):
            if j+1 == t:
                last[j] = 0
                score += S[i][j]
            else:
                last[j] += 1
                score -= last[j]*C[j]
        print(score)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

ri = lambda: int(sys.stdin.readline())
rl = lambda: list(map(int, sys.stdin.readline().split()))

D = ri()
c = rl()
s = [rl() for _ in range(D)]
t = [ri() for _ in range(D)]

score = 0
li = [0] * 26
c_sum = sum(c)
d = 0
for i in t:
  li = [v+1 for v in li]
  li[i-1] = 0
  tmp = 0
  for cv, liv in zip(c, li):
      tmp += cv*liv
  score += s[d][i-1] - tmp
  print(score)
  d += 1

Submission status: Accepted

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

#print(s)

cs = 0 #満足度
last = [0]*(26+1) #前回開催日
for day in range(1,D+1):
  t=int(input()) #開催コンテストNo.
  cs+=s[day][t]

  for j in range(27):
    if j==t:
      continue
    cs-=c[j]*(day-last[j])
  last[t]=day #前回開催日に追加
  print(cs)

Submission status: Accepted

Solution code:
import numpy as np

D = int(input())
c = np.array(list(map(int, input().split())))
s = np.array([list(map(int, input().split())) for x in range(D)])
t = np.array([int(input()) for x in range(D)])
last = np.zeros(26, dtype=np.int16)

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

Submission status: Accepted

Solution code:
d = int(input())
c = list(map(int, input().split(' ')))

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

t = [int(input()) - 1 for _ in range(d)]
ca = [0] * 26 # 放置された不満の数々
dc = 0 # カレントな満足度
dl = [] # 満足度のログ

for i in range(1, d + 1):
    dc += s[i - 1][t[i - 1]]
    ca[t[i - 1]] = i
    dc -= sum([c[i2] * (i - ca[i2]) for i2 in range(26)])
    dl.append(dc)
print('\n'.join(list(map(str, dl))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split()))for _ in range(d)]
class Score:
  def __init__(self,t):
    self.x=[d*[0]for _ in range(26)]
    self.scor=0
    self.ans=[]
    for i in range(d):
      v=t[i]
      self.scor+=s[i][v]
      for j in range(26):
        if j!=v:
          self.x[j][i]+=1
          if i!=0:self.x[j][i]+=self.x[j][i-1]
        self.scor-=c[j]*self.x[j][i]
      self.ans.append(self.scor)
  def solve(self):
    return [self.scor,self.ans]
t=[int(input())-1 for _ in range(d)]
x=Score(t)
_,ans=x.solve()
for i in ans:print(i)

Submission status: Accepted

Solution code:
total_days = int(input())
c = list(map(int, input().split()))
satis_day = [[0] * 26 for i in range(total_days)]
for i in range(total_days):
    satis_day[i] = list(map(int, input().split()))

total_satis = 0
not_held_count = [0] * 26

for i in range(total_days):
    type = int(input())
    type -= 1
    
    not_held_count = list(map(lambda x: x+1, not_held_count))
    not_held_count[type] = 0
    
    today_decrease = 0
    for j in range(26):
        today_decrease += c[j] * not_held_count[j]
    
    total_satis += (satis_day[i][type] - today_decrease)
    print(total_satis)

Submission status: Accepted

Solution code:
D = int(input())
C = list(map(int, input().split()))
S = [tuple(map(int, input().split())) for _ in range(D)]
T = [int(input()) - 1 for _ in range(D)]
Z = 26

last = [-1] * Z
cnt = 0
for d, t in enumerate(T):
    last[t] = d
    up = S[d][t]
    down = sum(C[i] * (d - last[i]) for i in range(Z))
    cnt += up - down
    print(cnt)

Submission status: Accepted

Solution code:
D=int(input())
c=[]
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)]
for i in range(D):
    t[i]=int(input())






wa=0

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

for i in range(D):
    wa=s[i][t[i]-1]+wa
    last[t[i]-1]=i+1

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

Submission status: Accepted

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

Submission status: Accepted

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

last = []
last_i = [ -1 for _ in range( 26 ) ]
for i in range( D ):
    last_i[ t[ i ] ] = i
    last.append( copy.deepcopy( last_i ) )

# def satisfy( D, c, s, t, last, d ):
satisfy = [ 0 for _ in range( D ) ]
for d in range( D ):
    satisfy[ d ] += s[ d ][ t[ d ] ]
    for i in range( 26 ):
        satisfy[ d ] -= c[ i ] * ( d - last[ d ][ i ] )

v = 0
for v_i in satisfy:
    v += v_i
    print( v )

Submission status: Accepted

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







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

Submission status: Accepted

Solution code:
D = int(input())
C = list(map(int, input().split()))
s = list()
for i in range(D):
  s1 = list(map(int, input().split()))
  s.append(s1)
t = list()
for i in range(D):
  N = int(input())
  t.append(N-1)
done = [0] * 26

ans = 0
for d in range(1, D+1):
  td = t[d-1]
  done[td] = d
  ans += s[d-1][td]
  for i in range(26):
    ans -= C[i]*(d-done[i])
  print(ans)

Submission status: Accepted

Solution code:
def main():
    days = int(input())
    falliness = [int(x) for x in input().split()]
    satisfactions = [0]  # Never use index 0.
    for _ in range(days):
        satisfactions.append([int(x) for x in input().split()])
    types = []
    for _ in range(days):
        types.append(int(input()))

    last = [0] * 26
    sat = 0
    for date, typ in enumerate(types):
        date += 1
        typ -= 1
        last[typ] = date
        sat += satisfactions[date][typ]
        sat -= sum(falliness[i] * (date - last[i]) for i in range(26))
        print(sat)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
D = int(input())
N = 26
c = [int(i) for i in input().split()]
s = list()
last = [0 for i in range(N)]
score = 0

for i in range(D):
  s.append([int(j) for j in input().split()])

for i in range(D):
  n = int(input())
  last[n-1] = i+1
  for j in range(N):
    last_day = i+1-last[j]
    score -= c[j]*last_day
  score += s[i][n-1]
  print(score)

Submission status: Accepted

Solution code:
import numpy as np
#基本入力
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()))
        
#基本入力完了
#得点計算
c = np.array(c)
last_day = np.array([0]*26)
day_pulse = np.array([1]*26)
s = np.array(s)
t = np.array(t)
manzoku = 0
for day in range(1,D+1):
    contest_number = t[day-1] #開催するコンテスト種類
    manzoku += s[day-1,contest_number-1] #開催したコンテストによる満足度上昇
    last_day += day_pulse #経過日数の計算
    last_day[contest_number -1 ] = 0 #開催したコンテスト種類の経過日数を0に
    manzoku -= sum(c*last_day) #開催していないコンテストによる満足度の減少
    print(manzoku)