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

T = []

for i in range(D):

    T.append(int(eval(input())))

    s = score(T)

    print((s.first_score()))
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:

                    #print(last)

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

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

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

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



sc = score(t)

#print(sc.score)
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(eval(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)]
T = []
for i in range(D):
    T.append(int(eval(input())))
    s = score(T)
    print((s.first_score()))

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:
                    # print(last)
                    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(eval(input()))
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
t = [int(eval(input())) for i in range(D)]
sc = score(t)
# print(sc.score)

-import bisect -import random -import sys - -input = sys.stdin.readline +from bisect import bisect_left -    def __init__(self, t): +    def __init__(self, t) -> None: +        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: +                    # print(last) +                    score -= c[tj - 1] * ((i + 1) - last[tj - 1][-1]) +            print(score) +        self.score = score -    def first_score(self): -        last = [0] * 26 +    def a__init__(self, t) -> None: -        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]) +        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]) -        return score +        self.t = t -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)] -T = [] -for i in range(D): -    T.append(int(eval(input()))) -    s = score(T) -    print((s.first_score())) +c = list(map(int, input().split())) +s = [list(map(int, input().split())) for i in range(D)] +t = [int(eval(input())) for i in range(D)] +sc = score(t) +# print(sc.score)