D = int(eval(input()))

c = [None] + list(map(int, input().split()))

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

t = [None] + [int(eval(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)

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



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)

D = int(eval(input()))
c = [None] + list(map(int, input().split()))
s = [None] + [[None] + list(map(int, input().split())) for _ in range(D)]
t = [None] + [int(eval(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)

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

-c = [None] + list(map(int, input().split())) -s = [None] + [[None] + list(map(int, input().split())) for _ in range(D)] -t = [None] + [int(eval(input())) for _ in range(D)] +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] * 27 +last = [-1] * 26 -for d in range(1, D + 1): +for d in range(D): -    for i in range(1, 27): +    for i in range(26):