Problem:
 (Please read problem A first. The maximum score you can get by solving this problem B is 1, which will have almost no effect on your ranking.)    Beginner's Guide Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.      Problem Statement You will be given a contest schedule for D days.
For each d=1,2,\ldots,D , calculate the satisfaction at the end of day d .        Input Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.  D  c_1  c_2  \cdots  c_{26}  s_{1,1}  s_{1,2}  \cdots  s_{1,26}  \vdots  s_{D,1}  s_{D,2}  \cdots  s_{D,26}  t_1  t_2  \vdots  t_D    The constraints and generation methods for the input part are the same as those for Problem A.  For each d , t_d is an integer satisfying 1\leq t_d \leq 26 , and your program is expected to work correctly for any value that meets the constraints.       Output Let v_d be the satisfaction at the end of day d .
Print D integers v_d to Standard Output in the following format:  v_1  v_2  \vdots  v_D         Sample Input 1 5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
1
17
13
14
13      Sample Output 1 18398
35037
51140
65837
79325  Note that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case.      Next Step We can build a solution (schedule) for this problem in the order of day 1, day 2, and so on. And for every partial solution we have built, we can calculate the goodness (satisfaction) by using the above score calculator. So we can construct the following algorithm: for each d=1,2,\ldots,D , we select the contest type that maximizes the satisfaction at the end of day d . You may have already encountered this kind of "greedy algorithms" in algorithm contests such as ABC. Greedy algorithms can guarantee the optimality for several problems, but unfortunately, it doesn't ensure optimality for this problem. However, even if it does not ensure optimality, we can still obtain a reasonable solution in many cases. Let's go back to Problem A and implement the greedy algorithm by utilizing the score calculator you just implemented!  Greedy methods can be applied to a variety of problems, are easy to implement, and often run relatively fast compared to other methods. Greedy is often the most powerful method when we need to process huge inputs.
We can further improve the score by changing the greedy selection criteria (evaluation function), keeping multiple candidates instead of focusing on one best partial solution (beam search), or using the output of greedy algorithms as an initial solution of other methods.
For more information, please refer to the editorial that will be published after the contest.

Solution (Python):
D = int(input())
c = [0] + [int(x) for x in input().split()]
s = [[0 for _ in range(26 + 1)]] + \
    [[0] + [int(x) for x in input().split()] for _ in range(D)]
t = [0] + [int(input()) for _ in range(D)]

def calcScore():
    score = [[0] * (26 + 1) for _ in range(D + 1)]
    sinceLast = [[0] * (26 + 1) for _ in range(D + 1)]

    for d in range(1, D + 1):
        id = t[d]  
        sinceLast[d][id] = 0
        score[d][id] = s[d][id]


        for i in range(1, 26 + 1):
            if i == id:  continue
            sinceLast[d][i] = sinceLast[d - 1][i] + 1
            score[d][i] = -c[i] * sinceLast[d][i]

    total = sum(sum(row) for row in score)

    ans = 0
    for d in range(1, D + 1):
        ans += sum(score[d])
        print(ans)

    return ans

calcScore()

Solution (Python):
D = int(input())
C = [int(T) for T in input().split()]
S = [[] for TD in range(0,D)]
for TD in range(0,D):
    S[TD] = [int(T) for T in input().split()]
Type = 26
Last = [0]*Type
SatD = [0]*D
SatA = [0]*(D+1)
for TD in range(0,D):
    Test = int(input())-1
    Last[Test] = TD+1
    SatD[TD] = S[TD][Test]
    for TC in range(0,Type):
        SatD[TD] -= C[TC]*(TD+1-Last[TC])
    SatA[TD+1] = SatA[TD]+SatD[TD]
print('\n'.join(str(T) for T in SatA[1:]))

Solution (Python):
D = int(input())
C = [int(T) for T in input().split()]
S = [[] for TD in range(0,D)]
for TD in range(0,D):
    S[TD] = [int(T) for T in input().split()]
Type = 26
Last = [0]*Type
Sats = 0
for TD in range(0,D):
    Test = int(input())-1
    Last[Test] = TD+1
    Sats += S[TD][Test]
    for TC in range(0,Type):
        Sats -= C[TC]*(TD+1-Last[TC])
    print(Sats)

Solution (Python):
def penalty(day, last, c):
    val = 0
    for i in range(26):
        val += c[i] * (day - last[i])
    return val

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

last = [-1]*26
ans = [0]*(d+1)

for day in range(d):
    ans[day+1] = ans[day] + s[day][t[day]-1]
    last[t[day]-1] = day
    ans[day+1] -= penalty(day, last, c)

for v in ans[1:]:
    print(v)

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

last = [0] * 26
score = 0

for i, (s, t) in enumerate(zip(S, T), 1):
    score += s[t-1]
    last[t-1] = i
    for j in range(26):
        score -= C[j] * (i - last[j])
    print(score)

Solution (Python):
from bisect import bisect_left


class score:
    def __init__(self,t) -> None:
        self.t = t
        score = 0
        last = [[] for i in range(26)]
        for i,ti in enumerate(t):
            score += s[i][ti-1]
            last[ti-1].append(i+1)
            for tj in range(26):
                if last[tj-1] == []:
                    score -= c[tj-1]*(i+1)
                else:
                    
                    score -= c[tj-1]*((i+1)-last[tj-1][-1])
            print(score)
        self.score = score
    def a__init__(self,t) -> None:
        score = 0
        last = [[] for i in range(26)]
        for i,ti in enumerate(t):
            
            score += s[i][ti-1]
            
            if last[ti-1] == []:
                score -= c[i]*i+1
            else:
                score -= c[i]*((i+1)-last[ti-1][-1])
            last[ti-1].append(i+1)
            print(score)
        for i in range(26):
            if last[i] == []:
                score -= c[i]*D
            else:
                score -= c[i]*(D-last[i][-1])
        self.score = score
        self.t = t


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

sc = score(t)

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


def cal_score():
  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)
    

if __name__ == "__main__":
  cal_score()

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

kaisai = [0] * 26
manzoku = 0
date = 0
for t in T:
    date += 1
    kaisai[t] = date
    manzoku += S[date - 1][t]

    for i in range(26):
        manzoku -= C[i] * (date - kaisai[i])
    
    print(manzoku)

Solution (Python):

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[i] * (t - last_day[i]))
    print(score)

Solution (Python):
import bisect
import random
import sys

input = sys.stdin.readline


class score:
    def __init__(self, t):
        self.t = t

    def first_score(self):
        last = [0]*26
        score = 0
        for i,ti in enumerate(self.t):
            score += S[i][ti - 1]
            last[ti-1] = i + 1
            for j in range(26):
                score -= C[j] * ((i+1) - last[j])
        self.score = score
        return score


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


T = []
for i in range(D):
    T.append(int(input()))
    s = score(T)
    print(s.first_score())

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

L = [0]*26

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

Solution (Python):

D = int(input())


last = [0 for i in range(26)]
s = [[0 for j in range(26)] for i in range(D)]
c = list(map(int, input().split(" ")))
result = []

for i in range(D):
    a = list(map(int, input().split(" ")))
    for j, k in enumerate(a):
        
        s[i][j] = int(k)
        
        
for i in range(D):  
    result.append(int(input()))
score_max=0
for i in range(D):
    
    score_index = 0
    tmp=result[i]-1
    score=s[i][tmp]+(i + 1 - last[tmp]) * c[tmp]
    
    for j in range(26):
        score -= (i + 1 - last[j]) * c[j]
    
    score_max+=score
    print(score_max)
    last[tmp] = i+1

Solution (Python):
def main():
    D = int(input())
    C = [int(i) for i in input().split()]
    S = [[int(i) for i in input().split()] for j in range(D)]
    T = [int(input()) for i in range(D)]
    contest_last_opened = [0]*26  
    score = 0
    for d, t in enumerate(T, start=1):
        get_score = S[d-1][t-1]
        score += get_score
        contest_last_opened[t-1] = d
        loss_score = 0
        for i in range(26):
            ld = contest_last_opened[i]
            loss_score += C[i]*(d-ld)
        score -= loss_score
        print(score)


if __name__ == '__main__':
    main()

Solution (Python):
s=list()
t=list()
v=list()
last=[0]*26
D=int(input())
c=list(map(int,input().split()))
for i in range(D):
    s.append(list(map(int,input().split())))
for i in range(D):
    t.append(int(input()))
legacy=0
for i in range(D):
    minus=0
    v.append(legacy)
    v[i]+=s[i][t[i]-1]
    last[t[i]-1]=i+1
    for j in range(26):
        minus+=c[j]*(i+1-last[j])
    v[i]-=minus
    legacy=v[i]
for i in range(D):
    print(v[i])

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

last = [0] * 26
score = 0
for i,(s,a) in enumerate(zip(S,T)):
    score += s[a-1]
    last[a-1] = i+1
    for j,c in enumerate(C):
        score -= c * (i+1 - last[j])
    print(score)

Solution (Python):
import random

def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum = sum + c[i]*(d-last_d[i])
        
    return int(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]-1]
        last_d[sche[i]-1] = i+1
        score = down_score(i+1, c, last_d, score)
        print(score)
        
if __name__ == "__main__":
    main()

Solution (Python):
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
t=[int(input()) for i in range(D)]
C=sum(c)
l=[0]*26
a=0
m=0
for i in range(D):
    b=t[i]-1
    m+=C-c[b]*(i-l[b]+1)
    a+=s[i][b]-m
    l[b]=i+1
    print(a)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    

    
    
    

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

if __name__ == '__main__':
    main()

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

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

Solution (Python):
def scoring(d, t):
    last[t] = d
    return S[d][t] - sum((d - l) * c for l, c in zip(last, C))

D = int(input())
C = list(map(int, input().split()))
S = []
for _ in range(D):
    s = list(map(int, input().split()))
    S.append(s)
T = [int(input()) - 1 for _ in range(D)]
last = [-1] * 26
score = 0
for i in range(D):
    score += scoring(i, T[i])
    print(score)

Solution (Python):

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

s_grid = []
for i in range(D):
    array = list(map(int, input().strip().split(' ')))
    s_grid.append(array)

t_list = [int(input()) -1 for i in range(D)]
last_list = [0 for i in range(26)]

def calculate_score(last_list):
    score = 0
    for d in range(D):
        score += s_grid[d][t_list[d]]
        last_list = [n+1 for n in last_list]
        last_list[t_list[d]] = 0
        for i in range(26):
            score -= c_list[i]*last_list[i]
        print(score)


calculate_score(last_list)

Solution (Python):
D=int(input())
c=[int(i) for i in input().split()]
s=[]
for d in range(D):
    s.append([int(i) for i in input().split()])

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

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

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

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

v_sum=0
for d in range(D):
    v_sum+=v[d]
    print(v_sum)

Solution (Python):
d,*s,=map(int,open(i:=0).read().split())
c,*l=[0]*27
for v in s[-d:]:
  i+=1
  l[v-1]=i
  print(c:=c+s[i*26+v-1]-sum(x*(i-y)for x,y in zip(s,l)))

Solution (Python):
def func(s,x):
    last=[0]*26
    score=0
    for i,v in enumerate(x,1):
        last[v]=i
        c=0
        for j in range(26):
            c+=s[j]*(i-last[j])
        score=score+s[i*26+v]-c
        print(score)
    return score
def main():
    d,*s=map(int,open(0).read().split())
    func(s,[t-1for t in s[-d:]])
main()

Solution (Python):
import numpy as np
import numba


i4 = numba.int32


@numba.njit((i4, i4[:], i4[:, :], i4[:]), cache=True)
def solve(dd, c_arr, s_arr, t_arr):
    last_d = np.zeros(26, dtype=np.int32) - 1
    score = 0
    score_arr = np.zeros(dd, dtype=np.int32)
    for d in range(dd):
        score += s_arr[d, t_arr[d] - 1]
        last_d[t_arr[d] - 1] = d
        score -= (c_arr * (d - last_d)).sum()
        score_arr[d] = score
    return score_arr


def main():
    d = np.int32(input())
    c_arr = np.array(list(map(int, input().split()))).astype(np.int32)
    s_arr = np.array([list(map(int, input().split())) for _ in range(d)]).astype(np.int32)
    t_arr = np.array([int(input()) for _ in range(d)]).astype(np.int32)
    res = solve(d, c_arr, s_arr, t_arr)
    for r in res:
        print(r)


if __name__ == "__main__":
    main()

Solution (Python):
from time import time
from random import randint

from numba import njit
from numpy import int64

@njit('i8(i8[:],i8[:])')
def func(s,x):
    last=[0]*26
    score=0
    for i,v in enumerate(x,1):
        last[v]=i
        c=0
        for j in range(26):
            c+=s[j]*(i-last[j])
        score=score+s[i*26+v]-c
        print(score)
    return score

def main():
    start=time()
    d,*s=map(int,open(0).read().split())
    s=int64(s)
    func(s,s[-d:]-1)
main()

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

def calc_score(day, contest, score, last):
  last[contest] = day + 1

  contest_score = s[day][contest]
  score += contest_score

  dis = 0
  for i in range(26):
    dis += c[i] * ((day + 1) - last[i])
  score -= dis

  return score, last


score = 0
last = [0 for i in range(26)]
for day in range(d):
  contest = t[day]
  contest -= 1
  score, last = calc_score(day, contest, score, last)
  print(score)

Solution (Python):
import numpy as np
D = int(input())
c = np.array(list(map(int,input().split())))
s = np.array([list(map(int,input().split())) for _ in range(D)])
t = np.array([int(input())-1 for _ in range(D)])

last = np.full(26,-1)

S = 0
score = 0;
for i,v in enumerate(t):
    S += s[i][v]
    last[v] = i
    tmp =c*(i - last)
    S -= sum(tmp) 
    score +=max(10**6+S,0)
    print(S)

Solution (Python):
import numpy as np
D = int(input())
c = np.array(list(map(int,input().split())))
s = np.array([list(map(int,input().split())) for _ in range(D)])
t = np.array([int(input())-1 for _ in range(D)])

last = np.full(26,-1)

S = 0
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)

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

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)

Solution (Python):
D, *I = map(int, open(0).read().split())
C, S, T = I[:26], list(zip(*[iter(I[26:-D])] * 26)), I[-D:]

last = [0] * 26
ans = 0
for d, i in enumerate(T, 1):
    ans += S[d - 1][i - 1]
    last[i - 1] = d
    ans -= sum(c * (d - l) for c, l in zip(C, last))
    print(ans)

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

Solution (Python):


D = int(input())
C = list(map(int, input().split()))
S_2d = []
for i in range(D):
    s_1d = list(map(int, input().split()))
    S_2d.append(s_1d)
T = []
for i in range(D):
    t = int(input())
    T.append(t)

last_days = [0] * 26
tot_score = 0

for i in range(D):
    today_contest = T[i]
    last_days[today_contest - 1] = i + 1
    today_plus = S_2d[i][today_contest - 1]
    today_minus = 0
    for j, c in enumerate(C):
        today_minus += c * (i + 1 - last_days[j])
    tot_score += today_plus - today_minus
    print(tot_score)

Solution (Python):
def read_input():
    D = int(input())
    C = input().split()
    C = [int(i) for i in C]
    S = [list(map(int, input().split())) for _ in range(D)]
    T = [int(input()) for _ 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
        last[T[i] - 1] = i + 1
        for j in range(26):
            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()
res = scoring(S, D, T, C)
for x in res:
    print(x)

Solution (Python):

def read_input():
    D = int(input())
    C = input().split()
    C = [int(i) for i in C]
    S = [list(map(int, input().split())) for _ in range(D)]
    T = [int(input()) for _ 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()
res = scoring(S, D, T, C)
for x in res:
    print(x)

Solution (Python):
NUM_CONTESTS = 26

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

    t_list = [int(input()) for _ in range(D)]
    v_list = calc_score_list(s_list, c_list, t_list)

    for v in v_list:
        print(v)


def calc_score_list(s_list, c_list, t_list):
    last = [-1 for _ in range(NUM_CONTESTS)]
    score_list = []
    score = 0
    for d, t in enumerate(t_list):
        last[t - 1] = d
        score += s_list[d][t - 1] - sum([c * (d - l) for c, l in zip(c_list, last)])
        score_list.append(score)
    return score_list



if __name__ == "__main__":
    main()

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

TYPES = 26
history = [-1] * TYPES
satisfaction_level = [0] * (d+1)

def last(day, i):
    if history[i] == -1:
        return 0
    else:
        return history[i]

def satisfaction(day, typ):
    
    history[typ] = day
    
    decrease = sum((c[i]*(day-last(day,i)) for i in range(TYPES)))
    value = s[day-1][typ] - decrease + satisfaction_level[day-1]
    satisfaction_level[day] = value
    return value

for day, typ in enumerate(t):
    print(satisfaction(day+1, typ-1))

Solution (Python):
class Heruistics:
    allpref = [] 
    donelist = [0]*26
    resultlist = []
    contestlist = []

    def __init__(self,days):
        self.days = days
        self.clast = list(map(int,input().split()))
        for i in range(days):
            self.allpref.append(list(map(int,input().split())))

    def scoring(self,contlist):
        result = 0
        for i in range(self.days):
            cont = contlist[i]
            self.donelist[cont-1] = i+1
            zanen = sum([self.clast[j]*((i+1)-self.donelist[j]) for j in range(26)])

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

b_heru = Heruistics(int(input()))
for i in range(b_heru.days):
    b_heru.contestlist.append(int(input()))

b_heru.scoring(b_heru.contestlist)

for result in b_heru.resultlist:
    print(result)

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

lastdi=[None]+[0]*26

v=0

for i in range(1, D+1):
  v+=s[i][T[i]-1]
  lastdi[T[i]]=i
  for x in range(1, 27):
    v-=(i-lastdi[x])*c[x]
    
  print(v)

Solution (Python):
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

D = INT()
C = LIST()
S = [[]] * D
for i in range(D):
    S[i]  = LIST()
T = [t-1 for t in LIST(D)]
M = 26

last = [0] * M
ans = 0
for i, t in enumerate(T):
    ans += S[i][t]
    for j in range(M):
        last[j] += 1
    last[t] = 0
    for j in range(M):
        ans -= C[j] * last[j]
    print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

d = inp()
c = inpl()
s = [inpl() for _ in range(d)]
res = 0
last = [0]* 26
for day in range(d):
    t = inp(); t -= 1
    res += s[day][t]
    for i in range(26):
        last[i] += 1
        if i == t:
            last[t] = 0
        res -= c[i] * last[i]
    print(res)

Solution (Python):
def down(d, last, c):
    result = 0
    for i in range(26):
        result += c[i] * (d - last[i])
    return result


def main():
    D = int(input())
    C = [int(c) for c in input().split()]

    S = [0] * D

    for d in range(D):
        S[d] = [int(s) for s in input().split()]

    last = [0] * 26

    score = 0
    scores = [0] * D
    for d in range(D):
        t = int(input()) - 1

        score += S[d][t]
        last[t] = d + 1

        score -= down(d + 1, last, C)
        scores[d] = score

    for score in scores:
        print(score)


if __name__ == "__main__":
    main()

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

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

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

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

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

ans = 0
for i in range(1,D+1):
  m = S[i-1][T[i-1]-1]
  tot = 0
  rh[i-1][T[i-1]-1] += 1 
  for j in range(26):
    last = 0
    for k in range(D):
        if rh[k][j] == 1:
          last = (k+1)
    tot += (c[j]*(i - last))
  ans += m-tot
  print(ans)

Solution (Python):
import numpy

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 = []
score = 0
past_list = [0] * 26

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

for i in range(D):
    for j in range(26):
        if(t_list[i] == j):
            score += s_list[i][j]
            past_list[j] = i + 1
        else:
            score -= c_list[j] * (i + 1 - past_list[j])
    print(score)

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

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

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

Solution (Python):
import numpy as np

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

def last(d):
    l=np.zeros(26,int)
    for i in range(d):
        l[T[i]-1]=i+1
    return l

def decrease(d):
    return np.dot(C,(d-last(d)))



manzoku=0
res=[]
for i in range(D):
    manzoku+=S[i][T[i]-1]
    manzoku-=decrease(i+1)
    res.append(manzoku)

for x in res:
    print(x)

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

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

contest = [0 for _ in range(26)]
ans = 0

for i in range(D):
    t = int(input())
    contest[t-1] = i+1
    ans += S[i][t-1]
    for j, con in enumerate(contest):
        if con:
            ans -= C[j]*(i+1-con)
        else:
            ans -= C[j]*(i+1)
    print(ans)

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


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

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

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

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

Solution (Python):
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(date, LastDay, type, score):
  res = score
  res += s[date-1][type]
  for i in range(26):
    if i == type:
      continue
    res -= (date - LastDay[i]) *c[i]
  return res

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

LastDay = [0]*26
score = 0
for d in range(D):
  score = tami(d+1, LastDay, ans[d]-1, score)
  LastDay[ans[d]-1] = d+1
  print(score)

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

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

Solution (Python):



d= int(input())

C = list(map(int,input().split()))
CB = [0 for i in range(len(C))]

c = sum(C)

total = 0


L = []

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



T = []

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



def cnt(CB,t):
    for i in range(len(CB)):
        if i != t-1:
            CB[i] += 1
        else:
            CB[i] = 0
    
    return CB

def sumA(C,CB):
    a = 0
    for i in range(len(CB)):
        a += CB[i]*C[i]
    return a

for i in range(len(T)):
    CB = cnt(CB,T[i])
    total += L[i][T[i]-1] - sumA(C,CB)
    print(total)