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: Runtime Error

Solution code:
#入力
D = int(input())
C = [int(c) for c in input().split()]
S = []
for _ in range(D):
    s = [int(x) for x in input().split()]
    S.append(s)
T = []
for _ in range(D):
    t = int(input()) - 1
    T.append(t)
    
＃スコア計算
score = 0
last_day = [-1] * 26
for t in range(D):
    test = T[t]
    score += S[t][test]
    last_day[test] = t
    for i in range(26):
        score -= (C * (t - last_day[i]))
    print(score)

Submission status: Runtime Error

Solution code:
def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum += c[i]*(d-last_d[i])
        
    return (score - sum)


def main():
    D = int(input())

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

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

    sche = []
    for i in range(D):
        x = int(input())
        sche.append(x)
    
    last_d = [0 for i in range(26)]
    score = 0
    
    for i in range(D):
        score += s[i][sche[i]]
        last_d[sche[i]] = i+1
        score = down_score(i+1, c, last_d, score)
        print(score)
        
if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
def read_input(filename):
    filein = open(filename, 'r')
    D = int(filein.readline())
    C = filein.readline().split()
    C = [int(i) for i in C]
    S = [list(map(int, filein.readline().split())) for x in range(D)]
    T = [int(filein.readline()) for x in range(D)]
    return D, C, S, T


def scoring(S, D, T, C):
    res = []
    last = [0 for _ in range(26)]
    final = 0
    for i in range(D):
        dec = 0
        for j in range(26):
            for loc, val in enumerate(T[:i + 1]):
                if val == j + 1:
                    last[j] = loc + 1
            dec += C[j] * (i - last[j] + 1)
        final += S[i][T[i] - 1] - dec
        res.append(final)
    return res


D, C, S, T = read_input("sample1.in")
res = scoring(S, D, T, C)
for x in res:
    print(x)

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split()))for _ in range(d)]
t=[int(input())for _ in range(d)]
m=int(input())
dq=[list(map(int,input().split()))for _ in range(m)]
x=[[0]for _ in range(26)]
ans=0
for i in range(d):
  v=t[i]-1
  ans+=s[i][v]-c[v]*(i-x[v][-1]+1)*(i-x[v][-1])//2
  x[v].append(i+1)
for i in range(26):
  ans-=c[i]*(d+1-x[i][-1])*(d-x[i][-1])//2
  x[i].append(d+1)
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
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
import random
# stdin = open("sample.txt")

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): # 入力されたintを桁ごとに分解，リストで出力
    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): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (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): # nの素因数分解の結果を辞書で出力 fuct(24) → {2: 3, 3: 1}
    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())
    for _ in range(d):
        print(random.randint(1,365))
main()

Submission status: Runtime Error

Solution code:
D = map(int, input().split())
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)

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(ans, score):
  LastDay = [0]*26
  for i in range(D):
    score += s[i][ans[i]-1]
  for i in range(D):
    score += (D - i+1) * (i+1 - LastDay[ans[i]-1])*c[i]
  return score

D = I()
c = IL()
s = [IL() for i in range(D)]
ans = [I() for i in range(D)]

score = 0
for i in range(26):
  score -= D * (2*c[i] + (D - 1)*c[i])//2

print(max(0, 10**6 + tami(ans, score)))

Submission status: Runtime Error

Solution code:
import numpy as np
import copy
D = int(input())
c = list(map(int,input().split()))
score = [0]*26
last = [0]*26
s = []
x = []
day = []
point = 0
 
for i in range(D):
  x[i] = np.array(list(map(int, input().split())))
for i in range(D):
  day[i] = int(input())
  
for i in range(D):
  for j in range(26):
    tmp = copy.copy(last)
    tmp[j] = i;
    for k in range(26):
  	  x[i][j] = x[i][j]-(c[k]*(i-last[k]))+point
  #s.append(x.argmax())
  last[day[i]] = i
  point+=max(x)
  s.append(point)
for i in range(D):
  print(s[i]+1)

Submission status: Runtime Error

Solution code:
import numpy as np

d = int(input())    # Day
C = list(map(int, input().split()))  # 満足度の減少係数
S = []  # 各日にち、各タイプの満足度
T = []  # d日目の開催タイプ
L = [0] * 26    # 各コンテストが開催された最後の日付

for _ in range(d):
    S.append(list(map(int, input().split())))  # Si,d type_iをdayDに開いた時の満足度 [5, 26]

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

print("S:", S)
print("T:",T)

sat = 0
S = np.array(S)
print("S_shape:", S.shape)

for i in range(d):
    con_type = T[i]
    print(i)
    print("開催するコンテストタイプ：", con_type)
    complain = 0
    for j in range(26):
        complain = complain + C[j] * (d - L[j])
    L[con_type] = d     # 最終開催日の更新

    sat = sat + S[d][con_type] - complain
    sat = max(10^6 + sat, 0)

    print(sat)

Submission status: Runtime Error

Solution code:
import random
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
#greedyに最大とりまーす
#D=365
types=[(i%26)+1 for i in range(D)]
#print(l)
sc = [0] * D
last=[0]*26
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 = score - dwn
    # print(score,last)
    sc[i] = ans
all = sum(sc)
for _ in range(800):
    types2 = []
    mi=float("inf")
    ind=0
    for i in range(D):
        if mi>sc[i]:
            mi=sc[i]
            ind=i
    l=list(range(1,27))
    lab1=l.pop(types[ind])
    lab2=random.choice(l)
    spans=ind//26
    types2=types
    for i in range(spans*26,min((spans+1)*26,D)):
        if types[i]==lab2:
            types[i]=lab1
            types[ind]=lab2
            break
    sc2=[0]*D
    last=[0]*26
    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 = score - dwn
                # print(score,last)
        sc2[i] = ans
    all2 = sum(sc2)
    if all2<all:
        types=types2
    else:
        sc=sc2
        all=all2
    #print(max(all,all2))
for i in range(D):
    print(types[i])

Submission status: Runtime Error

Solution code:
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])
        score += S[d,i]
        last[i] = d
        score -= np.sum(c*(d-last))
        scores.append(max([10**6+score,0]))
    score = max([10**6+score,0])
    return score,scores

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

Submission status: Runtime Error

Solution code:
from collections import deque

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

ss = sstt[:d]

tt = sum(sstt[d:], [])

print(sum(ss[i][t] for (i, t) in enumerate(tt)))

Submission status: Runtime Error

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

print(sum(clist))

for i in range(D):
  print(slist[i][tlist[i]] - sum(clist))

Submission status: Runtime Error

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

def last(d,i):
    last(d,i)==0
    for d in range(1,366):
        for i in range(1,27):
            if t[d-1] == i:
                last(d,i) == d

def sumc(d):
    for i in range(1,27):
        sum(c[i-1] * (d-last(d,i)))

for d in range(1, 366):
    v = v+s[t[d-1]-1, d-1]-sumc(d)

print(v)

Submission status: Runtime Error

Solution code:
D = int(input())
c_list = list(map(int,input().split()))
s_list = [list(map(int,input().split())) for i in range(D)]
t_list = [int(input()) for i in range(D)]
x = 0; y = 0; z = 0; emp1 = []; emp2 = []; emp3 = []
for d in range(1,D+1):
    x += s_list[d-1][t_list[d-1]]
    emp2.append(x)
for d in range(1,D+1):
    emp1.append(t_list[d-1])
    for j in range(0,26):
        if t_list[d-1] in emp1:
            z += c_list[j] * (emp1.index(t_list[d-1]) + 1)
        else:
            z += c_list[j] * d
    y -= z
    emp3.append(y)
xy = [a+b for (a,b) in zip (emp2,emp3)]
[print(i) for i in xy]

Submission status: Runtime Error

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

def last(d,i):
    last(d,i)==0
    for d in range(1,366):
        for i in range(1,27):
            if t[d-1] == i:
                last(d,i) = d

def sumc(d):
    for i in range(1,27):
        sum(c[i-1] * (d-last(d,i))

for d in range(1, 366):
    v = v+s[t[d-1]-1, d-1]-sumc(d)

print(v)

Submission status: Runtime Error

Solution code:
from operator import mul
def plus(n):
    return n+1


rows = int(input())
c = list(map(int, input().split()))
s = [[int(j) for j in input().split()] for i in range(rows)]

a = [int(input()) for i in range(5)]
#print(x)
#print(a,b,c,d,e)
satis = 0 
day = [0 for i in range(26)]
for i in range(rows):
    day = list(map(plus,day))
    day[a[i]-1] = 0
    satis = satis + s[i][a[i]-1] -  sum(list(map(mul,day,c)))
    
    print(satis)

Submission status: Runtime Error

Solution code:
D = int(input())
C = list(map(int,input().split()))

S = []

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

T = [int(input())-1 for _ in range(D)]
T.reverse()

ans = 0
last = [0] * 26

for i in range(D):
    if D - i > last[T[i]]:
        last[v] = D - i
        tmp += (D - i) * C[T[i]]
    tmp += S[D-i-1][T[i]]

print(ans)

Submission status: Runtime Error

Solution code:
import copy

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

_score_ = 0
_last_ = [0]*26 
ans = []
for i in range(1,D+1):

    """
    nax, nax_i = -float("inf"),-1
    for t in range(26):
        score = copy.deepcopy(_score_)
        last = copy.deepcopy(_last_)

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

        if score >= nax:
            nax, nax_i = score, t-1
    """
    nax_i = int(input())
    nax_i -= 1

    _score_ += s[i-1][nax_i]
    _last_[nax_i] = i
    for j in range(26):
        _score_ -= c[j]*(i-_last_[j])

    ans.append(_score_)

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

Submission status: Runtime Error

Solution code:
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
MOD = 10**9+7

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

_score_ = 0
_last_ = [0]*26 
ans = []
for i in range(1,D+1):

    """
    nax, nax_i = -float("inf"),-1
    for t in range(26):
        score = copy.deepcopy(_score_)
        last = copy.deepcopy(_last_)

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

        if score >= nax:
            nax, nax_i = score, t-1
    """
    nax_i = int(input())
    nax_i -= 1

    _score_ += s[i-1][nax_i]
    _last_[nax_i] = i
    for j in range(26):
        _score_ -= c[j]*(i-_last_[j])

    ans.append(_score_)

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

Submission status: Runtime Error

Solution code:
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
MOD = 10**9+7

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

_score_ = 0
_last_ = [0]*26 
for i in range(1,D+1):

    """
    nax, nax_i = -float("inf"),-1
    for t in range(26):
        score = copy.deepcopy(_score_)
        last = copy.deepcopy(_last_)

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

        if score >= nax:
            nax, nax_i = score, t-1
    """
    nax_i = int(input())
    nax_i -= 1

    _score_ += s[i-1][nax_i]
    _last_[nax_i] = i
    for j in range(26):
        _score_ -= c[j]*(i-_last_[j])

    print(_score_)

Submission status: Runtime Error

Solution code:
import numpy as np
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 = [int(input()) for i in range(D)]
#print(T)
manzoku = [S[i][T[i]-1] for i in range(D)]
#print(manzoku) 
teika = [C[T[i]] for i in range(D)]
teika_s = [sum(teika[:i]) for i in range(D)]
manzoku_np = np.array(manzoku)
teika_np = np.array(teika_s)
total = manzoku_np - teika_np 
#print(total)
for num in total:
  print(num)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

D = int(input())
c = list(map(int, input().split()))
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
s3 = list(map(int, input().split()))
s4 = list(map(int, input().split()))
s5 = list(map(int, input().split()))
t1 = int(input())
t2 = int(input())
t3 = int(input())
t4 = int(input())
t5 = int(input())

t = [0] * 26

ans = 0

# 1日目
ans = ans + s1[t1 - 1]
for i in range(26):
    if (t1 - 1) != i:
        t[i] = t[i] + 1
        ans = ans - (c[i] * t[i])
    elif (t1 - 1) == i:
        t[i] = 0
print(ans)

# 2日目
ans = ans + s2[t2 - 1]
for i in range(26):
    if (t2 - 1) != i:
        t[i] = t[i] + 1
        ans = ans - (c[i] * t[i])
    elif (t2 - 1) == i:
        t[i] = 0
print(ans)

# 3日目
ans = ans + s3[t3 - 1]
for i in range(26):
    if (t3 - 1) != i:
        t[i] = t[i] + 1
        ans = ans - (c[i] * t[i])
    elif (t3 - 1) == i:
        t[i] = 0
print(ans)

# 4日目
ans = ans + s4[t4 - 1]
for i in range(26):
    if (t4 - 1) != i:
        t[i] = t[i] + 1
        ans = ans - (c[i] * t[i])
    elif (t4 - 1) == i:
        t[i] = 0
print(ans)

# 5日目
ans = ans + s5[t5 - 1]
for i in range(26):
    if (t5 - 1) != i:
        t[i] = t[i] + 1
        ans = ans - (c[i] * t[i])
    elif (t5 - 1) == i:
        t[i] = 0
print(ans)

Submission status: Runtime Error

Solution code:
D = int(input())
c_list = list(map(int,input().split(' ')))
s_list = []
for i in range(d):
    s_list.append(list(map(int,input().split(' '))))
t_list = []
for j in range(d):
    t_list.append(int(input()))
last_list = [0 for k in range(26)]
score = 0
for day in range(D):
    point = 0
    point += s_list[day][t_list[day]]
    last_list[t_list[day]] = day+1
    for c in c_list:
        point -= c*((day+1)-last_list[t_list[day]])
    if(point>1000000):
        score += point+1000000
print(score)

Submission status: Runtime Error

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

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

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

def get_objective_function(output):
    objective_function = 0
    last = [[-1 for i in range(26)] for d in range(D)]

    for d in range(D):
        objective_function += s[d][output[d]]

        last[d][output[d]] = d
        if d < D-1:
            for i in range(26):
                last[d+1][i] = max(last[d][i], last[d+1][i])

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

    point = max(10 ** 6 + objective_function, 0)


output = [0, 16, 12, 13, 12]

# 最大効用での戦略
#output = []
#for d in range(D):
#    output.append(s[d].index(max(s[d])))
#for d in output:
#    print(d+1)

get_objective_function(output)

Submission status: Runtime Error

Solution code:
D, C = int(input()),list(map(int,input().split()))
s1, s2, s3, s4, s5 = list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()))
d1,d2,d3,d4,d5 = int(input()), int(input()), int(input()), int(input()), int(input())

sumonw = 0
sumonw += s1[d1-1]
cs = sum(C)
cs = cs - C[d1-1]
sumonw -= cs
print(sumonw)

sumonw += s2[d2-1]
cs = sum(C)*2
cs = cs - C[d2-1] * 2 - C[d1-1]
sumonw -= cs
print(sumonw)
 
sumonw += s3[d3-1]
cs = sum(C)*3
cs = cs - C[d3-1] * 3 - C[d2-1] * 2 - C[d1-1]
sumonw -= cs
print(sumonw)
 
sumonw += s4[d4-1]
cs = sum(C)*4
cs = cs - C[d4-1] * 4 - C[d3-1] * 3 - C[d2-1] * 2 - C[d1-1]
sumonw -= cs
print(sumonw)

sumonw += s5[d5-1]
cs = sum(C)*5
cs = cs - C[d5-1] * 5 - C[d4-1] * 4 - C[d2-1] * 2 - C[d1-1]
sumonw -= cs
print(sumonw)

Submission status: Runtime Error

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

import sys
import random

if len(sys.argv) != 2:
	print("Usage: {} <seed>".format(sys.argv[0]))
	exit(1)

random.seed(int(sys.argv[1]))

D = 365
c = [random.randrange(0, 101) for _ in range(26)]
s = [[random.randrange(0, 20001) for _ in range(26)] for _ in range(D)]

print(D)
print(" ".join(map(str, c)))
for sd in s:
	print(" ".join(map(str, sd)))

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化
def choice_contest(c, data, last, held, day, contest):
    contest -= 1
    #print(last)
    # すでに開催したコンテスト(held)にあればlastに＋1
    last = [i + 1 for i in last]
    # 今回開催するコンテストのlastを0にする
    last[contest] = 0
    #print(last)
    # 開催したコンテストがheldに無ければ追加
    if not contest in held:
        held.append(contest)
    # 不満度の計算
    d_satis = [last[i] * c[i] for i in range(26)]
    # i日目にcontestを選んだ場合の
    return [int(data[day][contest]) - sum(d_satis), last, held]

def main():
    d = int(input())
    c = list(map(int,input().split()))
    data = [input().split() for _ in range(d)]
    last = [0] * 26
    held = [] #すでに行ったコンテスト
    ans = 0
    for i in range(d):
        s, last, held = choice_contest(c, data, last, held, i, contest = int(input()))
        ans += s
        print(ans)
    return 0

if __name__ == "__main__":
    main()import sys
import math
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化
def choice_contest(c, data, last, held, day, contest):
    contest -= 1
    #print(last)
    # すでに開催したコンテスト(held)にあればlastに＋1
    last = [i + 1 for i in last]
    # 今回開催するコンテストのlastを0にする
    last[contest] = 0
    #print(last)
    # 開催したコンテストがheldに無ければ追加
    if not contest in held:
        held.append(contest)
    # 不満度の計算
    d_satis = [last[i] * c[i] for i in range(26)]
    # i日目にcontestを選んだ場合の
    return [int(data[day][contest]) - sum(d_satis), last, held]

def main():
    d = int(input())
    c = list(map(int,input().split()))
    data = [input().split() for _ in range(d)]
    last = [0] * 26
    held = [] #すでに行ったコンテスト
    ans = 0
    for i in range(d):
        s, last, held = choice_contest(c, data, last, held, i, contest = int(input()))
        ans += s
        print(ans)
    return 0

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

D = int(input())
c = list(map(int, input().split()))
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
s3 = list(map(int, input().split()))
s4 = list(map(int, input().split()))
s5 = list(map(int, input().split()))
t1 = int(input())
t2 = int(input())
t3 = int(input())
t4 = int(input())
t5 = int(input())

t = [0] * 26

ans = 0

# 1日目
# 満足度加算
ans = ans + s1[t1 - 1]
# 満足度減算
for i in range(26):
    if (t1 - 1) != i:
        t[i] = t[i] + 1
        ans = ans - (c[i] * t[i])
    elif (t1 - 1) == i:
        t[i] = 0
print(ans)

# 2日目
# 満足度加算
ans = ans + s2[t2 - 1]
# 満足度減算
for i in range(26):
    if (t2 - 1) != i:
        t[i] = t[i] + 1
        ans = ans - (c[i] * t[i])
    elif (t2 - 1) == i:
        t[i] = 0
print(ans)

# 3日目
# 満足度加算
ans = ans + s3[t3 - 1]
# 満足度減算
for i in range(26):
    if (t3 - 1) != i:
        t[i] = t[i] + 1
        ans = ans - (c[i] * t[i])
    elif (t3 - 1) == i:
        t[i] = 0
print(ans)

# 4日目
# 満足度加算
ans = ans + s4[t4 - 1]
# 満足度減算
for i in range(26):
    if (t4 - 1) != i:
        t[i] = t[i] + 1
        ans = ans - (c[i] * t[i])
    elif (t4 - 1) == i:
        t[i] = 0
print(ans)

# 5日目
# 満足度加算
ans = ans + s5[t5 - 1]
# 満足度減算
for i in range(26):
    if (t5 - 1) != i:
        t[i] = t[i] + 1
        ans = ans - (c[i] * t[i])
    elif (t5 - 1) == i:
        t[i] = 0
print(ans)

Submission status: Runtime Error

Solution code:
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(26)]
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: Runtime Error

Solution code:
d = int(input())
c = list(map(int(input().split())))
manzoku = 0
for i in range(0,d):
    s_i = list(map(int(input().split()))
for j in range(0,d):
    t_j = int(input())
c_total = sum(c)
for k in range(0,d):
    manzoku = s_k[t_j-1] - c_toal + c[t_j-1]
    print(manzoku)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int,Int> P;

Int D;
vector<Int> C(26);
vector<vector<Int>> S(365, vector<Int>(26));


// 各日における満足度の配列を返す関数
vector<Int> score(vector<int> schedule){
    vector<int> last_day(26, 0); // 各コンテストを最後に行った日

    vector<Int> res(D, 0);

    rep(d,D){
        int type = schedule[d]-1; // その日に行われるコンテスト

        res[d] += S[d][type];
        rep(i,26){
            if(i == type) continue;
            res[d] -= C[i] * (d+1 - last_day[i]);
        }
        last_day[type] = d+1;

        if(d != D-1) res[d+1] += res[d];
    }

    return res;
}

int main(){
    cin >> D;
    rep(i,26) cin >> C[i];
    rep(i,D) rep(j,26) cin >> S[i][j];

    vector<int> t(D);
    rep(i,D){
        cin >> t[i];
    }

    vector<Int> sc = score(t);
    rep(i,D) cout << sc[i] << endl;
}

Submission status: Runtime Error

Solution code:
n = 26
d = int(input())
c = list(map(int,input().split()))
s = [[] for i in range(n)]
for i in range(d):
    s[i] = list(map(int,input().split()))
a = 0
last = [0]*n
ans = []
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)
    ans.append(a)
for i in ans:
    print(i)