D = int(eval(input()))

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

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

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



last = [0] * 26

score = 0

for d in range(D):

    v = T[d]

    score += S[d][v]

    for i in range(26):

        if i == v:

            last[i] = 0

        else:

            last[i] += 1

        score -= C[i] * last[i]

    print(score)
d = int(eval(input()))

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

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

T = [int(eval(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)

    
D = int(eval(input()))
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
T = [int(eval(input())) - 1 for _ in range(D)]
last = [0] * 26
score = 0
for d in range(D):
    v = T[d]
    score += S[d][v]
    for i in range(26):
        if i == v:
            last[i] = 0
        else:
            last[i] += 1
        score -= C[i] * last[i]
    print(score)

d = int(eval(input()))
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(d)]
T = [int(eval(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)

-D = int(eval(input())) +d = int(eval(input())) -S = [list(map(int, input().split())) for _ in range(D)] -T = [int(eval(input())) - 1 for _ in range(D)] +S = [list(map(int, input().split())) for _ in range(d)] +T = [int(eval(input())) for _ in range(d)] -for d in range(D): -    v = T[d] -    score += S[d][v] -    for i in range(26): -        if i == v: -            last[i] = 0 -        else: -            last[i] += 1 -        score -= C[i] * last[i] +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])