Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
B = input()
S = B
a = 0
if S[0] == "A":
    if S[2:-2].count("C") == 1:
        if "C" in S[2:-2]:
            t = 2 + S[2:-2].index("C")
            S = str(S.lstrip("A"))
            S = str(S[0] + S[1:t-1] + S[t:])
            if S.islower():
                a = 1
if a == 1:
    print("AC")
else:
    print("WA")
    print("A" > 1)

Fixed submission:
B = input()
S = B
a = 0
if S[0] == "A":
    if S[2:-1].count("C") == 1:
        if "C" in S[2:-1]:
            t = 2 + S[2:-1].index("C")
            S = str(S.lstrip("A"))
            S = str(S[0] + S[1:t-1] + S[t:])
            if S.islower():
                a = 1
if a == 1:
    print("AC")
else:
    print("WA")

Buggy python submission (verdict: Runtime Error):
B = input()
A = B
a = 0
if S[0] == "A":
    if S[2:-2].count("C") == 1:
        if "C" in S[2:-2]:
            t = 2 + S[2:-2].index("C")
            S = str(S.lstrip("A"))
            S = str(S[0] + S[1:t-1] + S[t:])
            if S.islower():
                a = 1
if a == 1:
    print("AC")
else:
    print("WA")
    S = S.replace("A", "")
    if S.islower():
        pass


Fixed submission:
B = input()
S = B
a = 0
if S[0] == "A":
    if S[2:-1].count("C") == 1:
        if "C" in S[2:-1]:
            t = 2 + S[2:-1].index("C")
            S = str(S.lstrip("A"))
            S = str(S[0] + S[1:t-1] + S[t:])
            if S.islower():
                a = 1
if a == 1:
    print("AC")
else:
    print("WA")

Buggy python submission (verdict: Runtime Error):
S = input()
a = 0
if S[0] == "A":
    if S.count("C") == 1:
        if S[2] == "C" or S[-2] == "C":
            S = str(S.replace("A", "", 1))
            S = str(S.replace("C", ""), 1)
            A = S.islower()
            if A == True:
                a = 1
if a == 1:
    print("AC")
else:
    print("WA")


Fixed submission:
B = input()
S = B
a = 0
if S[0] == "A":
    if S[2:-1].count("C") == 1:
        if "C" in S[2:-1]:
            t = 2 + S[2:-1].index("C")
            S = str(S.lstrip("A"))
            S = str(S[0] + S[1:t-1] + S[t:])
            if S.islower():
                a = 1
if a == 1:
    print("AC")
else:
    print("WA")
Buggy python submission (verdict: Runtime Error):
n = int(input())

lt = [int(x) for x in input().split()]

s = sum(lt)
ans = 0
for a in lt:
  s = s - a
  ans+= (a*s)%mod 
print(ans%mod)

Fixed submission:
mod = pow(10, 9)+7
n = int(input())
lt = [int(x) for x in input().split()]

s = sum(lt)
ans = 0
for a in lt:
  s = s - a
  ans+= (a*s)%mod 
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
n = int(input())
lt = [int(x) for x in input().split()]
if 0 in lt:
    print(0)
else:
    ans = 1 
    for x in lt:
      ans*=x 
      if ans > 10**18:
        ans='-1'
print(ans)

Fixed submission:
n = int(input())
lt = [int(x) for x in input().split()]
ans =0
if 0 in lt:
    ans=0
else:
    ans = 1 
    for x in lt:
        ans*=x 
        if ans > 10**18:
            ans="-1"
            break 
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
lt = [int(x) for x in input().split()]
if 0 in lt:
    print(0)
else:
    ans = 1 
    for x in lt:
       ans*=x 
       if ans > 10**18:
           ans=-1
print(ans)

Fixed submission:
n = int(input())
lt = [int(x) for x in input().split()]
ans =0
if 0 in lt:
    ans=0
else:
    ans = 1 
    for x in lt:
        ans*=x 
        if ans > 10**18:
            ans="-1"
            break 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lt = [int(x) for x in input().split()]
 
ans = 1 
for x in lt:
    ans*=x 
if ans > 10**18:
    ans=-1
print(ans)

Fixed submission:
n = int(input())
lt = [int(x) for x in input().split()]
ans =0
if 0 in lt:
    ans=0
else:
    ans = 1 
    for x in lt:
        ans*=x 
        if ans > 10**18:
            ans="-1"
            break 
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import cos
a,b,h,m = map(int, input().split())
p = 3.14159265358979323846264338327950
tot_min = h*60 + m 
tot_sec = tot_min * 60 
 
h_angle = float("{:.25f}".format((tot_sec*pi)/(6*3600)))
m_angle = float("{:.25f}".format((tot_sec*pi)/(1800)))
 
while h_angle > 2*p:
    h_angle-=2*p 
while m_angle > 2*p:
    m_angle-=2*p 
r = abs(h_angle - m_angle)
if r > p:
    r-=p 
c = float("{:.25f}".format(cos(r)))
ans = float("{:.25f}".format(a**2 + b**2 -2*a*b*c))
ans = float("{:.25f}".format(ans**(0.5)))
print(ans)

Fixed submission:
from math import cos
a,b,h,m = map(int, input().split())
p = 3.14159265358979323846264338327950

rad = h/12.0 + m/(60*12) - m/60.0
rad = 2*p * rad

ans = a**2 + b**2 -2*a*b*cos(rad)
 

print(ans**(0.5))
Buggy python submission (verdict: Runtime Error):
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

t = int(input())

print(arr[t+1])

Fixed submission:
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
t=int(input())
print(arr[t-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lst = []
sum = 0

while n>0:
  sum += n%10
  n //= 10

if sum%9 == 0:
  print('Yes')
else:
  print('No')

Fixed submission:
n = int(input())

if n%9==0:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lst = []

while n>0:
  lst.append(n%10)
  n //= 10

lst.reverse()

if sum(lst)%9 == 0:
  print('Yes')
else:
  print('No')

Fixed submission:
n = int(input())

if n%9==0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
import itertools
c = itertools.combinations(A, 2)
B=[]
a=0
for v in itertools.combinations(A, 2):
    c=v[0]*v[1]
    a=a+c
print(a%1000000007)

Fixed submission:
D,T,S=map(int,input().split())
if D/S <=T:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
a_1=sum(A)
count=0
for i in range(0,len(A)-1):
    if A[i]>A[i+1]:
        A[i+1]=A[i]
a_2=sum(A)
print(a_2-a_1)
        
    

Fixed submission:
import math
N,X,T=map(int,input().split())
print(math.ceil(N/X)*T)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
a_1=sum(A)
count=0
for i in range(0,4):
    if A[i]>A[i+1]:
        A[i+1]=A[i]
    else:
        A[i+1]=A[i+1]
a_2=sum(A)
print(a_2-a_1)
        
    

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
a_1=sum(A)
count=0
for i in range(0,len(A)-1):
    if A[i]>A[i+1]:
        A[i+1]=A[i]
    else:
        A[0]=A[0]
        A[i+1]=A[i+1]
a_2=sum(A)
print(a_2-a_1)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=1
for i in A:
  B=i*B
  if(B>10**18):
    B=-1
    break
print(B)

Fixed submission:
a,b=map(int,input().split())
print(a*b)

Buggy python submission (verdict: Runtime Error):
N=int(input())
P=list(map(int,input().split()))
import numpy
Q=numpy.array(P)
 
result =numpy.prod(Q)
 
if result>pow(10, 18):
    print('-1')
else:
    print(str(result))

Fixed submission:
a,b=map(int,input().split())
print(a*b)

Buggy python submission (verdict: Runtime Error):
N=int(input())
P=[list(map(int,input().split()))]
from functools import reduce
from operator import add, mul
result =reduce(mul, P[0])

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


Fixed submission:
a,b=map(int,input().split())
print(a*b)

Buggy python submission (verdict: Runtime Error):
N=int(input())
P=[list(map(int,input().split()))]
import numpy
Q=numpy.array(P)
result =numpy.prod(Q[0])

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


Fixed submission:
a,b=map(int,input().split())
print(a*b)

Buggy python submission (verdict: Runtime Error):
N=int(input())
P=[list(map(int,input().split()))]
import numpy
P=numpy.array(P)
result =numpy.prod(P[0])

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


Fixed submission:
a,b=map(int,input().split())
print(a*b)
Buggy python submission (verdict: Runtime Error):
N=int(input())
from decimal import Decimal
P=input().split()
for i in range(0,len(P)):
    P[i]=Decimal(P[i])
import numpy
Q=numpy.array(P)

result =numpy.prod(Q)

if result>pow(10, 18):
    print(-1)
else:
    print(result)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=1
for i in A:
  B*=i
  if(B>10**18):
    B=-1
    break
print(B)

Buggy python submission (verdict: Runtime Error):
N=int(input())
from decimal import Decimal
P=input().split()
for i in range(0,len(P)):
    P[i]=Decimal(P[i])
import numpy
P=numpy.array(P)

result =numpy.prod(P)
 
if result>pow(10, 18):
    print(-1)
else:
    print(result)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=1
for i in A:
  B*=i
  if(B>10**18):
    B=-1
    break
print(B)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
P=list(map(int,input().split()))

from functools import reduce
from operator import add, mul
result =reduce(mul, P)

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


Fixed submission:
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=1
for i in A:
  B*=i
  if(B>10**18):
    B=-1
    break
print(B)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
P=[list(map(int,input().split()))]
import functools
import operator
result = functools.reduce(operator.mul,P[0])
if result>10**18:
    print(-1)
else:
    print(result)
    

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=1
for i in A:
  B*=i
  if(B>10**18):
    B=-1
    break
print(B)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
P= [list(map(int,input().split()))]
a=1

for i in range(0,len(P[0])):
    a=a*P[0][i]

if a> 10**18:
    print(-1)
else:
    print(a)
    

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=1
for i in A:
  B*=i
  if(B>10**18):
    B=-1
    break
print(B)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
P= [list(map(int,input().split()))]
a=1

for i in range(0,len(P[0])):
    a=a*P[0][i]

if a<= 10**18:
    print(a)
else:
    print(-1)
    


Fixed submission:
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=1
for i in A:
  B*=i
  if(B>10**18):
    B=-1
    break
print(B)
Buggy python submission (verdict: Runtime Error):
N=int(input())
P=list(map(int,input().split()))
import numpy
Q=numpy.array(P)
 
result =numpy.prod(Q)
 
if result>pow(10, 18):
    print('-1')
else:
    print(str(result))

Fixed submission:
a,b=input().split()
from decimal import Decimal
f1 = Decimal(a)
f2 = Decimal(b)
print(int(f1 * f2))
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
p = list(map(int,input().split()))

def f(p):
    #(p*(p+1)/2)/p
    return (p+1)/2


p2 = []

for p_tmp in p:
    p2.append(f(p_tmp))

def func1():
    ans = -1000
    tmp = 0
    for i in range(n):
        if(i<k):
            tmp = tmp + p2[i]
        else:
            tmp = tmp - p2[i-k] + p2[i]
            ans = max(ans,tmp)
    return ans

def func2():
    ans = 0
    for i in range(n):
        tmp = 0
        for j in range(k):
            if(i+j >= len(p2)):
                continue
            tmp = tmp + p2[i+j]
        ans = max(ans,tmp)
    return ans

#print('{:.10f}'.format(func1()))
print('{:.10f}'.format(func2()))

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

def f(p):
    #(p*(p+1)/2)/p
    return (p+1)/2


p2 = []

for p_tmp in p:
    p2.append(f(p_tmp))

p3 = [p2[0]]

for i in range(1,len(p2)):
    p3.append(p2[i]+p3[i-1])

ans = p3[k-1]
for i in range(k,n):
    ans = max(ans,p3[i]-p3[i-k])

print('{:.20f}'.format(ans))
Buggy python submission (verdict: Runtime Error):

a,b = map(int,input().split())

if(a== b)
    print("Yes")
else:
    print("No")

Fixed submission:
n,m = map(int,input().split())


if n==m:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import bisect
s = input()
t = input()

s_len = len(s)
t_len = len(t)

n = [[] for i in range(28)]

def get_ord(c):
    return ord(c)-97

for i in range(s_len):
    ord_c = get_ord(s[i])
    n[ord_c].append(i)

#print(n)

#print("s_len",s_len)
#print("t_len",t_len)

def get_ans():
    res = 0
    for i in range(t_len):
        rr = res % s_len
        t_ord = get_ord(t[i])
        words = n[t_ord]
        if(len(words)==0):
            return -1
        if(words[len(words)-1]<=rr):
            res += s_len - rr 
            #print("add",s_len-rr)
            rr = res % s_len
        
        bis = bisect.bisect_right(words,rr)
        w = words[bis]
        res += w - rr
        #print(t[i],words,rr,res)
    
    return res+1

print(get_ans())

Fixed submission:
import bisect
s = input()
t = input()

s_len = len(s)
t_len = len(t)

n = [[] for i in range(28)]

def get_ord(c):
    return ord(c)-97

for i in range(s_len):
    ord_c = get_ord(s[i])
    n[ord_c].append(i)

#print(n)

#print("s_len",s_len)
#print("t_len",t_len)

def get_ans():
    res = 0
    for i in range(t_len):
        
        rr = res % s_len
        t_ord = get_ord(t[i])
        words = n[t_ord]
        
        if(len(words)==0):
            return -1
        if(i==0 and words[0] == 0):
            res = 0
            continue
    
        if(words[len(words)-1]<=rr):
            res += s_len - rr 
            #print("add",s_len-rr)
            rr = -1
        
        bis = bisect.bisect_right(words,rr)
        #print(bis,len(words),rr,words)
        w = words[bis]


        if(rr!=-1):
            res += w - rr
        else:
            res += w
        #print(t[i],words,rr,res)
    
    return res+1

print(get_ans())
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

s_input_list = []

for i in range(n):
    tmp = input()
    s_input_list.append(tmp)

s_sorted_list = []
for s in s_input_list:
    tmp = list(s)
    tmp.sort()
    s_sorted_list.append(tmp)

#print(s_sorted_list)

ans = 0
for i in range(n):
    for j in range(i+1,n):
        if(s_sorted_list[i] == s_sorted_list[j]):
            ans = ans +1
print(ans)

Fixed submission:
n = int(input())
from collections import defaultdict


s_input_list = []

for i in range(n):
    tmp = input()
    s_input_list.append(tmp)


d = defaultdict(list)

s_sorted_list = []
for s in s_input_list:
    tmp = list(s)
    tmp.sort()
    
    s_sorted_list.append("".join(tmp))

#print(s_sorted_list)

ans = 0
for i in range(n):
    d[s_sorted_list[i]].append(i)

for key,value in d.items():
    v = len(value)
    ans = ans + int(v*(v-1)/2)

#print(d)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

#readed editional
MOD = int(1e9)+7
#print(MOD)
S = [int(x) if x != '?' else - 1 for x in input()]

n = len(S)

dp = [[0]*13 for i in range(n+1)]

dp[0][0] = 1
#print(dp)

for i in range(n):
    c = S[i]
    if c == -1:
        for j in range(10):
            for ki in range(13):
                dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki]
    else:
        for ki in range(13):
            dp[i + 1][(ki * 10 + c) % 13] += dp[i][ki]        
    for j in range(13):
        dp[i+1][j] %= MOD

#print(S)
#print(dp)
print(dp[len(dp)-1][5])


Fixed submission:

#readed editional
MOD = int(1e9)+7
#print(MOD)
S = [int(x) if x != '?' else - 1 for x in input()]

n = len(S)

dp = [[0]*13 for i in range(n+1)]

dp[0][0] = 1
#print(dp)

for i in range(n):
    c = S[i]
    if c == -1:
        for j in range(10):
            for ki in range(13):
                dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki]
    else:
        for ki in range(13):
            dp[i + 1][(ki * 10 + c) % 13] += dp[i][ki]        
    for j in range(13):
        dp[i+1][j] %= MOD

#print(S)
#print(dp)
print(dp[len(dp)-1][5])

Buggy python submission (verdict: Time Limit Exceeded):

#readed editional
MOD = int(1e9)+7
#print(MOD)
S = [int(x) if x != '?' else - 1 for x in input()]

n = len(S)

dp = [[0]*13 for i in range(n+1)]

dp[0][0] = 1
#print(dp)

for i in range(n):
    c = S[i]
    for j in range(10):
        if (c != -1 and c!= j):
            continue
        for ki in range(13):
            dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki]
    
    for j in range(13):
        dp[i+1][j] %= MOD

#print(S)
#print(dp)
print(dp[len(dp)-1][5])


Fixed submission:

#readed editional
MOD = int(1e9)+7
#print(MOD)
S = [int(x) if x != '?' else - 1 for x in input()]

n = len(S)

dp = [[0]*13 for i in range(n+1)]

dp[0][0] = 1
#print(dp)

for i in range(n):
    c = S[i]
    if c == -1:
        for j in range(10):
            for ki in range(13):
                dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki]
    else:
        for ki in range(13):
            dp[i + 1][(ki * 10 + c) % 13] += dp[i][ki]        
    for j in range(13):
        dp[i+1][j] %= MOD

#print(S)
#print(dp)
print(dp[len(dp)-1][5])
Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())

import math

#L<=i<j<=R
# i*j mod 2019の最小値

if L - R > 2020:
    L = 0
    R = 2019

result = 2019
for i in range(L, R+1):
    for j in range(i+1, R+1):
        tmp = (i * j) % 2019
        result = min(tmp, result)
        
print(result)

Fixed submission:
L, R = map(int, input().split())

import math

#L<=i<j<=R
# i*j mod 2019の最小値

if R - L > 2030:
    L = 0
    R = 2019

result = 2019
for i in range(L, R+1):
    for j in range(i+1, R+1):
        tmp = (i * j) % 2019
        result = min(tmp, result)
        
print(result)
Buggy python submission (verdict: Runtime Error):
n, a, b, c, d = map(int, input().split())
s = list(str(input()))

a = a - 1
b = b - 1
c = c - 1
d = d - 1


def rec(s, a, b, c, d):
    #ss = s.copy()
    #ss[a] = 'A'
    #ss[b] = 'B'
    #print(str(ss),a,b,c,d)
    if a > c or b > d:
        return False
    if a == c and b == d:
        return True

    if a+1 < len(s) and s[a + 1] == '.' and a+1 != b:
        if rec(s, a + 1, b, c, d):
            return True
    if a+2 < len(s) and s[a + 2] == '.' and a + 2 != b:
        if rec(s, a + 2, b, c, d):
            return True
    if b + 1 < len(s) and s[b + 1] == '.' and b + 1 != a:
        if rec(s, a, b + 1, c, d):
            return True
    if b+2 < len(s) and s[b + 2] == '.' and b + 2 != a:
        if rec(s, a, b + 2, c, d):
            return True

    return False

result = rec(s, a, b, c, d)
if result:
    print("Yes")
else:
    print("No")
    

Fixed submission:
n, a, b, c, d = map(int, input().split())

s = input()
s = '#' +s

def check(s, a, b):
    return not "##" in s[a:b]


def solve(s,a,b,c,d):
    can_swap = "..." in s[b - 1:d + 2]
    can_reach_each = check(s, a, c) and check(s, b, d)
    if not can_reach_each:
        return False
    if (a < b and c < d) or (b < a and d < c):
        return True
    else:
        if can_swap:
            return True
        else:
            return False

if solve(s, a, b, c, d):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

res = 0 3
for i in range(2):
    if a > b:
        res += a
        a -= 1
    else:
        res += b
        b -= 1

print(res)


Fixed submission:
a, b = map(int, input().split())

res = 0
for i in range(2):
    if a > b:
        res += a
        a -= 1
    else:
        res += b
        b -= 1

print(res)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9+7

ps = []
ns = []
zs = []
for i in range(n):
  if a[i] > 0:
    ps.append(a[i])
  elif a[i] < 0:
    ns.append(a[i])
  else:
    zs.append(a[i])
  
if k == 1:
  print(max(a))
elif len(ps) + len(ns) < k:
  print(0)
elif len(ps) == 0:
  ans = 1
  if k % 2 == 0:
    ns = sorted(ns)
    for i in range(k):
      ans = ans * ns[i] % mod
  elif len(zs) > 0:
    print(0)
  else:
    ns = sorted(ns, reverse=True)
    for i in range(k):
      ans = ans * ns[i] % mod
  print(ans)
else:
  ans = 1
  ps = sorted(ps, reverse=True)
  ns = sorted(ns)
  if k % 2 == 0:
    pp = []
    for i in range(0,min(k, len(ps)), 2):
      try:
        pp.append(ps[i] * ps[i+1])
      except:
        pass
  else:
    pp = []
    ans = ps[0]
    for i in range(1,len(ps), 2):
      try:
        pp.append(ps[i] * ps[i+1])
      except:
        pass
  np = []
  for i in range(0, len(ns), 2):
    try:
      np.append(ns[i] * ns[i+1])
    except:
      pass
  pnp = sorted(pp + np, reverse=True)
  if len(pnp) >= k//2:
    for i in range(k//2):
      ans = ans * pnp[i] % mod
    print(ans)
  else:
    print(0)


Fixed submission:
n = int(input())
import math
print(math.ceil(n/1000)*1000 - n)
Buggy python submission (verdict: Runtime Error):
D = map(int, input().split())
c = list(map(int, input().split()))
s = []
for _ in range(D):
  s.append(list(map(int, input().split())))

lasts = [0 for i in range(len(c))]
ans = 0
for d in range(1, D+1):
  t = int(input()) - 1
  lasts[t] = d
  ans += s[d][t]
  for i in range(len(c)):
    ans -= c[i] * (d - lasts[i])
print(ans)

Fixed submission:
D = int(input())
c = list(map(int, input().split()))
s = [[]]
for _ in range(D):
  s.append(list(map(int, input().split())))

lasts = [0 for i in range(len(c))]
ans = 0
for d in range(1, D+1):
  t = int(input()) - 1
  lasts[t] = d
  ans += s[d][t]
  for i in range(len(c)):
    ans -= c[i] * (d - lasts[i])
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(k):
  l = [0 for i in range(n)]
  r = [0 for i in range(n)]
  for i in range(n):
    l[max(0, i-a[i])] += 1
    r[min(i+a[i], n-1)] += 1
    
  lighted = 0
  for i in range(n):
    lighted += l[i]
    a[i] = lighted
    lighted -= r[i]
  if len(set(a)) == 1 and a[0] == n:
    break
print(' '.join(list(map(str, a))))


Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(k):
  l = [0 for i in range(n)]
  r = [0 for i in range(n)]
  for i in range(n):
    l[max(0, i-a[i])] += 1
    r[min(i+a[i], n-1)] += 1
    
  lighted = 0
  for i in range(n):
    lighted += l[i]
    a[i] = lighted
    lighted -= r[i]
  if len(set(a)) == 1 and a[0] == n:
    break
print(' '.join(list(map(str, a))))