Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = input()
total = 0

#a > b
def gcd(a,b):
	if b == 0:
		return a

	return gcd(b, a % b)

total = total + n * (n+1) / 2

for i in range(n):
	for j in range(i+1,n):
		total = total + 6 * gcd(j+1,i+1)

for i in range(n):
	for j in range(i+1,n):
		for k in range(j+1,n):
			l = gcd(j+1,k+1)
			if i < l:
				total = total + 6 * gcd(l,i+1)
			else:
				total = total + 6 * gcd(i+1,l)

print(int(total))

Fixed submission:
n = int(input())
total = 0

#a > b
def gcd(a,b):
	if b == 0:
		return a

	return gcd(b, a % b)

total = total + n * (n+1) / 2

for i in range(n):
	for j in range(i+1,n):
		total = total + 6 * gcd(j+1,i+1)

for i in range(n):
	for j in range(i+1,n):
		for k in range(j+1,n):
			l = gcd(j+1,k+1)
			if i < l:
				total = total + 6 * gcd(l,i+1)
			else:
				total = total + 6 * gcd(i+1,l)

print(int(total))

Buggy python submission (verdict: Runtime Error):
import sys

n = int(sys.argv[1])
total = 0

def gcd(a,b):
	if b == 0:
		return a

	return gcd(b, a % b)

total = total + n * (n+1) / 2

for i in range(n):
	for j in range(i+1,n):
		total = total + 6 * gcd(j+1,i+1)

for i in range(n):
	for j in range(i+1,n):
		for k in range(j+1,n):
			l = gcd(j+1,k+1)
			if i < l:
				total = total + 6 * gcd(l,i+1)
			else:
				total = total + 6 * gcd(i+1,l)

print(int(total))

Fixed submission:
n = int(input())
total = 0

#a > b
def gcd(a,b):
	if b == 0:
		return a

	return gcd(b, a % b)

total = total + n * (n+1) / 2

for i in range(n):
	for j in range(i+1,n):
		total = total + 6 * gcd(j+1,i+1)

for i in range(n):
	for j in range(i+1,n):
		for k in range(j+1,n):
			l = gcd(j+1,k+1)
			if i < l:
				total = total + 6 * gcd(l,i+1)
			else:
				total = total + 6 * gcd(i+1,l)

print(int(total))
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int, input().split())
a=list(map(int, input().split()))

for t in range(k):
      ok=True
      b=[0]*n
      for i in range(n):
            left=max(0,i-a[i])
            b[left]+=1
            if i+a[i]+1 <= n-1:
                  right=i+a[i]+1
                  b[right]-=1
      for i in range(1,n):
            b[i]=b[i-1]+b[i]
      for i in range(n):
            if a[i]!=b[i]:
                  ok=False
            a[i]=b[i]
      if ok==True:
            break

print(*a)



Fixed submission:
n,k=map(int, input().split())
a=list(map(int, input().split()))

for t in range(k):
      ok=True
      b=[0]*n
      for i in range(n):
            left=max(0,i-a[i])
            b[left]+=1
            if i+a[i]+1 <= n-1:
                  right=i+a[i]+1
                  b[right]-=1
      for i in range(1,n):
            b[i]=b[i-1]+b[i]
      for i in range(n):
            if a[i]!=b[i]:
                  ok=False
            a[i]=b[i]
      if ok==True:
            break

print(*a)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int, input().split())
a=list(map(int, input().split()))

for t in range(k):
      ok=True
      b=[0]*n
      for i in range(n):
            left=max(0,i-a[i])
            b[left]+=1
            if i+a[i]+1 <= n-1:
                  right=i+a[i]+1
                  b[right]-=1
      for i in range(1,n):
            b[i]=b[i-1]+b[i]
      for i in range(n):
            if a[i]!=b[i]:
                  ok=False
            a[i]=b[i]
      if ok:
            break

print(*a)



Fixed submission:
n,k=map(int, input().split())
a=list(map(int, input().split()))

for t in range(k):
      ok=True
      b=[0]*n
      for i in range(n):
            left=max(0,i-a[i])
            b[left]+=1
            if i+a[i]+1 <= n-1:
                  right=i+a[i]+1
                  b[right]-=1
      for i in range(1,n):
            b[i]=b[i-1]+b[i]
      for i in range(n):
            if a[i]!=b[i]:
                  ok=False
            a[i]=b[i]
      if ok==True:
            break

print(*a)
Buggy python submission (verdict: Runtime Error):
S = input()

R = []
r = 0
for s in S:
    if s == "R":
        r += 1
    if s == "S":
        R.append(r)
        r = 0

print(max(R))


Fixed submission:
S = input()

R = []
r = 0
for s in S:
    if s == "R":
        r += 1
    if s == "S":
        R.append(r)
        r = 0
    R.append(r)

print(max(R))
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = [int(a) for a in input().split()]

n = 1
c = 0

for i in range(N):
    if i <= K-1:
        n *= A[i]

    else:
        tmp = n
        tmp /= A[c]
        tmp *= A[i]

        if tmp > n:
            print("Yes")
        else:
            print("No")

        c += 1
        n = tmp



Fixed submission:
N,K = map(int,input().split())
A = [int(a) for a in input().split()]

n = 0

for i in range(K,N):
    if A[i] > A[n] :
        print("Yes")
    else:
        print("No")
    n+=1

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = [int(a) for a in input().split()]

n = 1
c = 0

for i in range(N):
    if i <= K-1:
        n *= A[i]

    else:
        tmp = n
        tmp /= A[c]
        tmp *= A[i]

        if tmp > n:
            print("Yes")
        else:
            print("No")

        c += 1



Fixed submission:
N,K = map(int,input().split())
A = [int(a) for a in input().split()]

n = 0

for i in range(K,N):
    if A[i] > A[n] :
        print("Yes")
    else:
        print("No")
    n+=1

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = [int(a) for a in input().split()]

n = 1
c = 0

for j in A[:K]:
    n *= j

for i in range(K,N):
    tmp = n
    tmp /= A[c]
    tmp *= A[i]

    if tmp > n:
        print("Yes")
    else:
        print("No")

    c += 1



Fixed submission:
N,K = map(int,input().split())
A = [int(a) for a in input().split()]

n = 0

for i in range(K,N):
    if A[i] > A[n] :
        print("Yes")
    else:
        print("No")
    n+=1
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
H = [int(h) for h in input().split()]

d = {}

for i in range(N):
    d[i+1] = H[i]

for _ in range(M):
    A,B = map(int,input().split())

    if H[B-1] > H[A]:
        d[A] = 0

    elif H[B-1] < H[A]:
        d[B] = 0

    elif H[B-1] == H[A]:
        d[A] = 0
        d[B] = 0


print(N - list(d.values()).count(0))

Fixed submission:
N,M = map(int,input().split())
H = [int(h) for h in input().split()]

d = {}

for i in range(N):
    d[i+1] = H[i]

for _ in range(M):
    A,B = map(int,input().split())

    if H[B-1] >= H[A-1]:
        d[A] = 0

    if H[B-1] <= H[A-1]:
        d[B] = 0

print(N - list(d.values()).count(0))

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
H = [int(h) for h in input().split()]

d = {}

for i in range(N):
    d[i+1] = H[i]

for _ in range(M):
    A,B = map(int,input().split())

    if H[B-1] > H[A]:
        d[A] = 0

    elif H[B-1] < H[A]:
        d[B] = 0


print(N - list(d.values()).count(0))



Fixed submission:
N,M = map(int,input().split())
H = [int(h) for h in input().split()]

d = {}

for i in range(N):
    d[i+1] = H[i]

for _ in range(M):
    A,B = map(int,input().split())

    if H[B-1] >= H[A-1]:
        d[A] = 0

    if H[B-1] <= H[A-1]:
        d[B] = 0

print(N - list(d.values()).count(0))
Buggy python submission (verdict: Runtime Error):
N, K, Q = map(int,input().split())

A = [int(input()) for _ in range(Q)]

Point = [ 0 for _ in range(Q)]

for a in A:
    Point[a-1] += 1

for p in Point:
    if K - (K - p) > 0:
        print("Yes")
    else:
        print("No")

Fixed submission:
N, K, Q = map(int,input().split())

A = [int(input()) for _ in range(Q)]

Point = [ 0 for _ in range(N)]

if K-1 >= Q:
    for _ in range(N):
        print("Yes")

else:
    for a in A:
        Point[a-1] += 1

    for p in Point:
        if K - Q + p > 0:
            print("Yes")
        else:
            print("No")
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

flag = 0

words = ("dream","erase","dreamer","eraser")
count = 0

while len(S) >= 5:
    
    for i in words:
        N = len(i)

        if S[-N:] in words:
            n = len(S) - N
            S = S[:n]

            flag = 1
            break
        else:
            continue
 
    if flag == 0:
        break

if len(S) == 0:
    print("YES")
else:
    print("NO")

Fixed submission:
S = input()

flag = 0

words = ("dream","erase","dreamer","eraser")
count = 0

while len(S) >= 5:

    for i in words:
        N = len(i)
        if S[-N:] in words:
            n = len(S) - N
            S = S[:n]
            flag = 1
            break
        else:
            flag = 0
            continue


    if flag == 0:
        break



if len(S) == 0:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
N = int(input())

def Couter(n):
    return n + Couter(n-1)

Couter(N)


Fixed submission:
N = int(input())

C = 0

for i in range(1,N+1):
    C += i

print(C)
Buggy python submission (verdict: Runtime Error):
from itertools import permutations

Num = [int(n) for n in input().rstrip().split()]

D = [int(n) for n in input().rstrip().split()]

for i in range(Num[0],10000):
    if len(set([str(n) for n in D]) & set(str(i))) == 0:
        print(i)
        break


Fixed submission:
num  = [int(n) for n in input().rstrip().split()]

if num.count(5) == 2 and num.count(7) == 1:
    print("YES")

else:
    print("NO")

Buggy python submission (verdict: Runtime Error):
num  = [int(n)] for n in input().rstrip().split()]

if num.count(5) == 2 and num.count(7) == 1:
    print("YES")

else:
    print("NO")


Fixed submission:
num  = [int(n) for n in input().rstrip().split()]

if num.count(5) == 2 and num.count(7) == 1:
    print("YES")

else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
Num = [int(n) for n in input().rstrip().split()]

D = [int(n) for n in input().rstrip().split()]

for i in rang:e(Num[0],10000):
    if len(set([str(n) for n in D]) & set(str(i))) == 0:
        print(int(i))
        break


Fixed submission:
Num = [int(n) for n in input().rstrip().split()]

D = [int(n) for n in input().rstrip().split()]

for i in range(Num[0],100000):
    if len(set([str(n) for n in D]) & set(str(i))) == 0:
        print(int(i))
        break

Buggy python submission (verdict: Runtime Error):
Num = [int(n) for n in input().rstrip().split()][0]

D = [int(n) for n in inut().rstrip().split()]

numberlist = [n if n not in D for n in range(9)]

anslist = []

for num in numberlist:
    if num >= Num:
        anslist.append(num)
    else:pass

print(min(anslist))


Fixed submission:
Num = [int(n) for n in input().rstrip().split()]

D = [int(n) for n in input().rstrip().split()]

for i in range(Num[0],100000):
    if len(set([str(n) for n in D]) & set(str(i))) == 0:
        print(int(i))
        break
Buggy python submission (verdict: Time Limit Exceeded):
N= int(input())
A = list(map(int, input().split()))
Q = int(input())

baseline = sum(A)
seq = ''.join(str(n) for n in A)

for i in range(Q):
    b, c = input().split()
    n = seq.count(b)
    diff = int(c) - int(b)
    baseline += n * diff
    seq = seq.replace(b, c)

    print(baseline)

Fixed submission:
from collections import Counter

N= int(input())
A = list(map(int, input().split()))
Q = int(input())

counter = Counter(A)

baseline = sum(k*v for k, v in counter.items())
#print(baseline)

for i in range(Q):
    b, c = map(int, input().split())
    n = counter.pop(b, 0)
    baseline += n * (c - b)
    counter[c] += n
    print(baseline)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

result = 1
for n in map(int, input().split()):
    result *= n

if result > 10 ** 18:
    result = -1
print(result)

Fixed submission:
import math
import sys
from collections import *
from itertools import *

N = int(input())

OVERFLOW = 10 ** 18

seq = list(map(int, input().split()))
seq.sort()
if seq[0] == 0:
    print(0)
    sys.exit(0)

result = 1
for n in reversed(seq):
    result *= n
    if result > OVERFLOW:
        print(-1)
        sys.exit(0)
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ppl = list(input())


buff = []

for i in range(N):
    n = ppl[:i].count('W') + ppl[i+1:].count('E')
    buff.append(n)

print(min(buff))

Fixed submission:
N = int(input())

ppl = list(input())

buff = []
w = 0
e = ppl[1:].count('E')
for i in range(N):
    if i > 0:
        w += (ppl[i-1] == 'W' and 1 or 0)
    if i > 0:
        e -= (ppl[i] == 'E' and 1 or 0)
    n = w+e
    buff.append(n)

print(min(buff))
Buggy python submission (verdict: Runtime Error):
def dump(a,b,c):
    if a == operator.add:
        a = '+'
    else:
        a = '-'
    if b == operator.add:
        b = '+'
    else:
        b = '-'
    if c == operator.add:
        c = '+'
    else:
        c = '-'
    print(vals[0] + a + vals[1] + b + vals[2] + c + vals[3] + '=7')

for a in (operator.add, operator.sub):
    for b in (operator.add, operator.sub):
        for c in (operator.add, operator.sub):
            if c(b(a(nums[0], nums[1]), nums[2]), nums[3]) == 7:
                dump(a, b, c)
                exit(0)

Fixed submission:
import operator

vals = input()
nums = list(map(int, tuple(vals)))

def dump(a,b,c):
    if a == operator.add:
        a = '+'
    else:
        a = '-'
    if b == operator.add:
        b = '+'
    else:
        b = '-'
    if c == operator.add:
        c = '+'
    else:
        c = '-'
    print(vals[0] + a + vals[1] + b + vals[2] + c + vals[3] + '=7')

for a in (operator.add, operator.sub):
    for b in (operator.add, operator.sub):
        for c in (operator.add, operator.sub):
            if c(b(a(nums[0], nums[1]), nums[2]), nums[3]) == 7:
                dump(a, b, c)
                exit(0)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]
A_uniq = sorted(set(A))

result = 0
for n in A_uniq:
    tmp = 0
    tmp += A.count(n-1)
    tmp += A.count(n)
    tmp += A.count(n+1)
    if tmp > result:
        result = tmp

print(result)


Fixed submission:
from collections import Counter

c = Counter()  

N = int(input())
for x in input().split():
    c[int(x)] += 1

A_uniq = sorted(c.keys())

def gen_candiate(seq):
    s = set()
    for n in seq:
        s.add(n-1)
        s.add(n)
        s.add(n+1)
    return sorted(s)

#print(gen_candiate(A_uniq))

result = 0
for n in gen_candiate(A_uniq):
    tmp = c.get(n-1, 0) + c.get(n, 0) + c.get(n+1, 0)
    if tmp > result:
        result = tmp

print(result)
Buggy python submission (verdict: Runtime Error):
FACTOR = 10 ** 9 + 7

num = 1
for i in range(1, N+1):
    num *= i
    k, r = divmod(num, FACTOR)
    num = r

k, r = divmod(num, FACTOR)
print(r)

Fixed submission:
import math

N = int(input())

num = math.factorial(N)

k, r = divmod(num, 10**9 + 7)
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())

idx = 0
for x in range(k+1):
    for y in range(k+1):
        if x+y > s:
            continue
        for z in range(k+1):
            if s == x+y+z:
                idx += 1


print(idx)


Fixed submission:
k, s = map(int, input().split())

idx = 0


for x in range(k+1):
    for y in range(k+1):
        if 0 <= s - x - y <= k:
            idx += 1

print(idx)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math

k, s = map(int, input().split())

idx = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if s == x+y+z:
                idx += 1
print(idx)


Fixed submission:
k, s = map(int, input().split())

idx = 0


for x in range(k+1):
    for y in range(k+1):
        if 0 <= s - x - y <= k:
            idx += 1

print(idx)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split(' ')]
result = 0
max_height = 0

for i in range(n):
  an = a[i]
  if i == 0:
    max_height = an
    max_height_idx = 0
    continue

  if an >= max_height:
    max_height = an
    max_height_idx = i
    continue

  max_height = max(a[max_height_idx:i])
  result += (max_height - an)

print(result)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split(' ')]
result = 0
max_height = 0

for i in range(n):
  an = a[i]
  if i == 0:
    max_height = an
    max_height_idx = 0
    continue

  if an >= max_height:
    max_height = an
    max_height_idx = i
    continue

  result += (max_height - an)

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split(' ')]
result = 0
max_height = 0

for i in range(n):
  an = a[i]
  if i == 0:
    max_height = an
    continue

  if an >= max_height:
    max_height = an
    continue

  max_height = max(a[0:i])
  result += (max_height - an)

print(result)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split(' ')]
result = 0
max_height = 0

for i in range(n):
  an = a[i]
  if i == 0:
    max_height = an
    max_height_idx = 0
    continue

  if an >= max_height:
    max_height = an
    max_height_idx = i
    continue

  result += (max_height - an)

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def getFumidai(arr, idx):
  if idx == 0:
    return 0

  my_height = arr[idx]
  target = arr[0:idx]
  max_height = max(target)

  if (my_height >= max_height):
    return 0

  return max_height - my_height

n = int(input())
a = [int(i) for i in input().split(' ')]

result = 0

for i in range(n):
  result += getFumidai(a, i)

print(result)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split(' ')]
result = 0
max_height = 0

for i in range(n):
  an = a[i]
  if i == 0:
    max_height = an
    max_height_idx = 0
    continue

  if an >= max_height:
    max_height = an
    max_height_idx = i
    continue

  result += (max_height - an)

print(result)
Buggy python submission (verdict: Runtime Error):
S = input()
S = S.split()
if ((S[2]==S[3])&(S[4]==S[5])):
	print("Yes")
else: 
    print("No")


Fixed submission:
S = input()
#S = S.split()
if ((S[2]==S[3])&(S[4]==S[5])):
	print("Yes")
else: 
	print("No")

Buggy python submission (verdict: Runtime Error):
S = S.split()
if S[2]==S[3]:
  if S[4]==S[5]:
    return "Yes"
  else: return "No"
else: return "No"

Fixed submission:
S = input()
#S = S.split()
if ((S[2]==S[3])&(S[4]==S[5])):
	print("Yes")
else: 
	print("No")

Buggy python submission (verdict: Runtime Error):
S = S.split()
if (S[2]=="f")&(S[3]=="f"):
  if (S[4]=="e")&(S[5]=="e"):
    return Yes
  else: return No
else: return No

Fixed submission:
S = input()
#S = S.split()
if ((S[2]==S[3])&(S[4]==S[5])):
	print("Yes")
else: 
	print("No")
Buggy python submission (verdict: Runtime Error):
s=input();
int sum=0;
for i in range(len(s)):
  sum=sum+int(s[i])
if(sum%9==0):
  print("Yes")
else:
  print("No")

Fixed submission:
s=input();
sum=0;
for i in range(len(s)):
  sum=sum+int(s[i])
if(sum%9==0):
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
sum_n = 0
while n > 0:
    sum_n += n % 10
    n //= 10
flag = 'Yes' if sum_n % 9 == 0 else 'No'
print(flag)

Fixed submission:
n = input()
sum_n = 0
for i in n:
    sum_n += int(i)

flag = 'Yes' if sum_n % 9 == 0 else 'No'
print(flag)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
k = int(input())
count = 0
while a >= b:
  count += 1
  b *= 2
while b >= c:
  count += 1
  c *= 2
return(['No','Yes'][count<=k])

Fixed submission:
a,b,c = map(int,input().split())
k = int(input())
count = 0
while a >= b:
  count += 1
  b *= 2
while b >= c:
  count += 1
  c *= 2
print(['No','Yes'][count<=k])

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
k = int(input())
count = 0
while A >= B:
  count += 1
  B *= 2
while B >= C:
  count += 1
  C *= 2
return(['No','Yes'][count<=k])

Fixed submission:
a,b,c = map(int,input().split())
k = int(input())
count = 0
while a >= b:
  count += 1
  b *= 2
while b >= c:
  count += 1
  c *= 2
print(['No','Yes'][count<=k])

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
k = int(input())
count = 0
while A >= B:
  count += 1
  B *= 2
while B >= C:
  count += 1
  C *= 2
return(['Yes', 'No'][count<=k])

Fixed submission:
a,b,c = map(int,input().split())
k = int(input())
count = 0
while a >= b:
  count += 1
  b *= 2
while b >= c:
  count += 1
  c *= 2
print(['No','Yes'][count<=k])
Buggy python submission (verdict: Runtime Error):
L, R, d = map(int, input().split())

count = 0
for i in range(L, R+1):
  if i % d == 0:
    count += 1
    
return count

Fixed submission:
L, R, d = map(int, input().split())
 
count = 0
for i in range(L, R+1):
    if i % d == 0:
        count+=1
 
print(count)

Buggy python submission (verdict: Runtime Error):
ans = 0
for i in range(L, R):
  if i % d == 0:
    ans += 1
return ans

Fixed submission:
L, R, d = map(int, input().split())
 
count = 0
for i in range(L, R+1):
    if i % d == 0:
        count+=1
 
print(count)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))

n,=I()
if sum(n)%9==0:
  print("Yes")
else:
  print("No")


Fixed submission:
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))

n=I()
if sum(n)%9==0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
#!/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)

Fixed submission:
#!/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の作成
# IOに基づくパターン
output = []
for _ in range(D):
    output.append(int(input())-1)

# 最大効用での戦略
#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)