Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03555 (python)

Fixed submission:
a = list(input())
b = list(input())
if a == list(reversed(b)):
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a = list(input())
b = list(input())
if a == reverse(b):
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a = input().split()
b = input().split()
if a == reverse(b):
    print("YES")
else:
    print("NO")
Problem p03860 (python)

Fixed submission:
a,b,c = input().split()
print("A" + b[0] +"C")

Buggy submission (verdict: Runtime Error):
a,b,c = input().split()
print("A" + B[0] +"C")
Problem p04012 (python)

Fixed submission:
li = list(input())
li.sort()
while True:
    if len(li) == 0:
        print("Yes")
        break
    elif not len(li) % 2 == 0:
        print("No")
        break
    elif li[0] == li[1]:
        li.pop(0)
        li.pop(0)
    else:
        print("No")
        break

Buggy submission (verdict: Runtime Error):
li = list(input())
li.sort()
while True:
    if len(li) == 0:
        print("Yes")
        break
    elif li[0] == li[1]:
        li.pop(0)
        li.pop(0)
    else:
        print("No")
        break
Problem p04030 (python)

Fixed submission:
li = input()
li2 =[]
for n in li:
    if n == "0":
        li2.append("0")
    elif n == "1":
        li2.append("1")
    elif n == "B":
        if not len(li2) == 0:
            li2.pop()
print("".join(li2))

Buggy submission (verdict: Runtime Error):
li = input()
li2 =[]
for n in li:
    if n == "0":
        li2.append("0")
    elif n == "1":
        li2.append("1")
    elif n == "B":
        if not len.li2 == 0:
            li2.pop()
print("".join(li2))

Buggy submission (verdict: Runtime Error):
li = input()
li2 =[]
for n in li:
    if n == "0":
        li2.append("0")
    elif n == "1":
        li2.append("1")
    elif n == "B":
        li2.pop()
print("".join(li2))
Problem p02579 (python)

Fixed submission:
from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(lambda x: int(x) - 1, input().split())
Dh, Dw = map(lambda x: int(x) - 1, input().split())
maze = [input() for _ in range(H)]

INF = 10 ** 12
path = [[INF] * W for _ in range(H)]  # path: 各マスへの移動コスト

walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

q = deque()
path[Ch][Cw] = 0
q.append((Ch, Cw, 0))

while q:
    x, y, s = q.popleft()
    for dx, dy in walk:  # 移動A
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s:
            path[nx][ny] = s
            q.appendleft((nx, ny, s))  # 移動Aの場合はコスト0. キューの先頭に追加する.
    for dx, dy in warp:  # 移動B
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s + 1:
            path[nx][ny] = s + 1
            q.append((nx, ny, s + 1))  # 移動Bの場合はコスト1. キューの最後尾に追加する.
    
ans = path[Dh][Dw] if path[Dh][Dw] < INF else '-1'
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(lambda x : int(x) - 1, input().split())
Dh, Dw = map(lambda x : int(x) - 1, input().split())
maze = [input() for _ in range(H)]

INF = 10**12

#各マスへの移動コスト
path = [[INF] * W for _ in range(H)]

#walk:移動A　warp:移動B
walk = [(0, 1), (0, 1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0,0) + walk]]

q = deque()
path[Ch][Cw] = 0
q.append((Ch, Cw, 0))

while q : 
    x, y, s = q.popleft()
    #移動A
    for dx, dy in walk :
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s:
            path[nx][ny] = s
            #移動Aの場合はコスト0, キューの先頭に追加する
            q.appendleft((nx, ny, s))
    #移動B
    for dx, dy in warp : 
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s + 1:
            path[nx][ny] = s + 1
            #移動Bの場合はコスト1, キューの最後尾に追加
            q.appendleft((nx, ny, s+1))
ans = path[Dh][Dw] if path[Dh][Dw] < INF else '-1'
print(ans)
Problem p02583 (python)

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

n = len(L)
c = 0
result = []
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if L[i]!=L[j] and L[j]!=L[k] and L[i]!=L[k]:
                if L[i]+L[j]>L[k] and L[j]+L[k]>L[i] and L[i]+L[k]>L[j]:
                    #print(L[i], L[j], L[k])
                    c += 1
print(c)

Buggy submission (verdict: Runtime Error):
n = len(L)
c = 0
result = []
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            
            if abs(L[i]-L[j])<L[k]<L[i]+L[j] and  L[i]!=L[j] and L[j]!=L[k]:
                #print(L[i], L[j], L[k])
                c += 1
print(c)

Buggy submission (verdict: Runtime Error):
n = len(L)
c = 0
result = []
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            
            if abs(L[i]-L[j])<L[k]<L[i]+L[j] and  L[i]!=L[j] and L[j]!=L[k]:
                print(L[i], L[j], L[k])
                c += 1
print(c)
Problem p02608 (python)

Fixed submission:
n = int(input())
ans = [0 for _ in range(10050)]
for i in range(1,105):
	for j in range(1,105):
		for k in range(1,105):
			v = i*i+j*j+k*k+i*j+j*k+k*i;
			if v<10050:
				ans[v]+=1
for i in range(n):
	print(ans[i+1])

Buggy submission (verdict: Runtime Error):
import collections
import sys
input = sys.stdin.readline

n = int(input())
ans = [0] * n
tmp = []
#可能なすべてのx,y,zについてx^2+y^2+z^2+xy+yz+zxの値を求める
for x in range(1, int(n**0.5) + 1):
	for y in range(1, int(n**0.5) + 1):
		for z in range(1, int(n**0.5) + 1)
			tmp.append(x**2+y**2+z**2+x*y+y*z+z*x)
#x^2+y^2+z^2+xy+yz+zxの値の個数を数える
cnt = collections.Counter(tmp)
#各iについて、x^2+y^2+z^2+xy+yz+zxの値がiであるものの個数が答えとなる
for i in range(1, n+1):
	print(cnt[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = [0]
for i in range(1, 105):
	for j in range(1, 105):
		for k in range(1, 105):
			v = i*i+j*j+k*k+i*j+j*k+k*i;
			if v < 10050:
				#個数を数える
				ans[v] += 1
for i in range(n):
	print(ans[i+1])
Problem p02641 (python)

Fixed submission:
X, N = map(int, input().split())
p = list(map(int, input().split()))

p = set(p)
for i in range(200):
    if X - i not in p:
        print(X - i)
        break
    if X + i not in p:
        print(X + i)
        break

Buggy submission (verdict: Runtime Error):
X, N = list(map(int, input().split()))
p = list(map(int, input().split()))
p_max = max(p)
p = set(p)
#リストに含まれるものは飛ばす
for i in range(1, 101):
    if X - i not in p:
        print(X -1)
        break
    if X + i not in p:
        print(X + i)
        break

Buggy submission (verdict: Runtime Error):
X, N = list(map(int, input().split()))
p = list(map(int, input().split()))
p_max = max(p)
diff = [0]
#リストに含まれるものは飛ばす
for i in range(1, 101):
    if X - i not in p:
        print(X -1)
        break
    if X + i not in p:
        print(X + i)
        break

Buggy submission (verdict: Runtime Error):
X, N = list(map(int, input().split()))
p = list(map(int, input().split()))
p_max = max(p)
diff = [0]
#リストに含まれるものは飛ばす
for i in range(1, 101):
    if X - i not in P:
        print(X -1)
        break
    if X + i not in P:
        print(X + i)
        break

Buggy submission (verdict: Runtime Error):
import numpy as np


def getNearestValue(list, num):

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]


if __name__ == "__main__":

    X, N = list(map(int, input().split()))
    p = list(map(int, input().split()))
    print(np.sort(p))
    print(getNearestValue(p, X-1))
    for i in range(np.sort(p)):
Problem p02702 (python)

Fixed submission:
from collections import Counter
S = input()[::-1]
MOD = 2019

X = [0]
for i, s in enumerate(S):
    X.append((X[-1] + int(s) * pow(10, i, MOD)) % MOD)

C = Counter(X)
ans = 0
for v in C.values():
    ans += v * (v - 1) // 2
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
S = input()[::-1]
MOD = 2019

X = [0]

for i, s in enumerate(S):
    X.append((X[-1] + int(s) * pow(10, i, MOD)) %MOD)
    print(X)

C = Counter(X)
ans = 0

for v in C.values():
    ans += v * (v-1) // 2

print(ans)
Problem p02719 (python)

Fixed submission:
N, K = list(map(int, input().split()))
a = N // K
b = N % K
print(min(abs(N - K * a), abs(b - K)))

Buggy submission (verdict: Runtime Error):
X, N = map(int, input().split())
p = list(map(int, input().split()))

for i in range(200):
    if X - i not in p:
        print(X - i)
        break
    if X + i not in p:
        print(X + i)
        break
Problem p02761 (python)

Fixed submission:
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
 
for X in range(10**N):
  X = str(X)
  
  #all　すべてがtrueならという意味
  if len(X) == N and all(X[s-1] == str(c) for s, c in SC):
    print(X)
    break
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]

for X in range(10**N):
  X = str(X)
  
  #all　すべてがtrueならという意味
  if len(X) == N and all(X[s-1] == str(c) for s, c in SC):
    print(X[s-1])
    break
else:
  print(-1)
Problem p02813 (python)

Fixed submission:
import itertools
import math
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
Nl = list(range(1, N+1))
p = list(itertools.permutations(Nl,N))
NN = math.factorial(N)
c1 = 1
c2 = 1
for v in range(NN):
    if list(p[v]) == P:
        break
    else:
        c1 += 1
for v in range(NN):
    if list(p[v]) == Q:
        break
    else:
        c2 += 1
print(abs(c1-c2))

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
Nl = list(range(1, N+1))
p = list(itertools.permutations(Nl,N))
c1 = 1
c2 = 1
for v in range(math.factorial(N)):
    if list(p[v]) == P:
        break
    else:
        c1 += 1
for v in range(math.factorial(N)):
    if list(p[v]) == Q:
        break
    else:
        c2 += 1
print(abs(c1-c2))
Problem p02818 (python)

Fixed submission:
A, B ,K = list(map(int, input().split()))
if A > K:
  print(A-K, B)
else:
  b = B-(K-A) if B>(K-A) else "0"
  print(0, b)

Buggy submission (verdict: Runtime Error):
A, B ,K = list(map(int, input(),split()))
for k in range(K):
  if A>0:
    A -= 1
  elif A=0 and B>0:
    B -= 1
  else:
    break
else:
  print(A B)
Problem p02830 (python)

Fixed submission:
N = int(input())

S, T = map(str, input().split())

#print(S)
#print(len(S))
#print(len(T))

moji = ""

if(len(S) == len(T) == N):
  for i in range(0, N):
    str = (S + T)[i::N]
    moji += str
print(moji)

Buggy submission (verdict: Runtime Error):
N = int(input())

S = input()
T = input()

#print(S)
#print(len(S))
#print(len(T))

moji = ""

if(len(S) == len(T) == N):
  for i in range(0, N):
    str = (S + T)[i::N]
    moji += str
print(moji)

Buggy submission (verdict: Runtime Error):
N = int(input())

S = input()
T = input()

if(len(S) == len(T) == N):
  print("OK")
Problem p02837 (python)

Fixed submission:
N = int(input())
 
testimony = [[] for _ in range(N)]
 
for i in range(N):
    num = int(input())
    for j in range(num):
        person, state = map(int, input().split())
        testimony[i].append([person-1, state])
        
honest = 0
for i in range(1, 2**N):
    flag = 0
    for j in range(N):
        if (i>>j)&1 == 1: # j番目は正直と仮定
            for x,y in testimony[j]:
                if (i>>x)&1 != y: # j番目は正直だが矛盾を発見
                    flag = 1
                    break
    if flag == 0:  # 矛盾がある場合はflag == 1になる
        honest = max(honest, bin(i)[2:].count('1'))  # 1の数をカウントし最大となるものを選択
print(honest)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = []
xy = []
for i in range(N):
    a =  int(input())
    A.append(a)
    for j in range(a):
        x, y = map(int, input().split())
        #２次元配列
        xy.append([x, y])
print(xy)

honest = 0

for i in range(1, 2**N):
    flag = 0
    for j in range(N):
        # j番目が正直と仮定する
        if (i>>j)&1 == 1:
            for x,y in xy[j]:
                # j番目は正直だが矛盾を発見
                if (i>>x)&1 != y:
                    flag = 1
                    break
    # 矛盾がある場合はflag == 1になる
    if flag == 0:
        honest = max(honest, bin(i)[2:].count('1'))
print(honest)
Problem p02848 (python)

Fixed submission:
a = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
N = int(input())
S = input()
 
for i in S:
    b = a.index(i) + N
    if b <= 25:
        print(a[b], end="")
    else:
        print(a[b-26], end="")

Buggy submission (verdict: Runtime Error):
a = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
S = input()
N = int(input())

for i in S:
  b = a.index(i) + N
  if b<=25:
    print(a[b], end="")
  else:
    print(a[b-26], end="")

Buggy submission (verdict: Runtime Error):
a = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
S = input()
N = int(input())

for i in S:
  b = a.index(i) + N
  if b<=25:
    print(a[b], end="")
  else:
    print(a[b-25], end="")
Problem p02861 (python)

Fixed submission:
import math
N = int(input())
#https://qiita.com/jamjamjam888/items/e066b8c7bc85487c0785
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]
l = 0

for j in range(N):
    for k in range(N):
        if j >= k:
            continue
        l += math.sqrt((x[j] - x[k])**2 + (y[j] - y[k]) ** 2)

print(l * 2/N)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())

xi = []
yi = []

for i in range(N):
    x = int(input())
    y = int(input())
    xi.append(x)
    yi.append(x)
    
result = 0
for i in range(N):
    for j in range(N):
        if i != j : 
            result += math.sqrt((xi[j] - xi[i])**2 + (yi[j] - yi[i])**2)
            
print(result/N)
Problem p02886 (python)

Fixed submission:
N = int(input())
d = [int(x) for x in input().split()]
t = 0
for i in range(N-1):
    for j in range(i+1, N):
      t += d[i]*d[j]
print(t)

Buggy submission (verdict: Runtime Error):
N = int(input())
d = [int(x) for x in input().split()]
t = 0
for i in itertools.permutations(d, N):
    t += i[0]*i[1]
print(total)

Buggy submission (verdict: Runtime Error):
N = int(input())
d = [int(x) for x in input().split()]
total = 0
for i in itertools.permutations(d, N):
    total = i[0]*i[1]
print(total)
Problem p02909 (python)

Fixed submission:
S = input()
if(S == "Sunny"):
  print("Cloudy")
elif(S == "Cloudy"):
  print("Rainy")
else:
  print("Sunny")

Buggy submission (verdict: Runtime Error):
S = input()
if(S == "Sunny"):
  print("Cloudy")
elif(S == "Cloudy"):
  print("Rainy")
else;
  print("Sunny")
Problem p02957 (python)

Fixed submission:
A, B = list(map(int, input().split()))
result = (A+B)//2 if (A+B)%2 == 0 else "IMPOSSIBLE"
print(result)

Buggy submission (verdict: Runtime Error):
A, B = list(map(int, input().split()))
result = (A+B)/2 if A%2 == B%2 else "IMPOSSIBLE"
print(int(result))

Buggy submission (verdict: Runtime Error):
A, B = list(map(int, input().split()))
result = (A+B)/2 if (A+B)%2 == 0 else "IMPOSSIBLE"
print(int(result))

Buggy submission (verdict: Runtime Error):
A, B = list(map(int, input().split()))
resutl = (A+B)/2 if (A+B)%2 == 0 else "IMPOSSIBLE"
print(result)
Problem p02958 (python)

Fixed submission:
N = int(input())
p = list(map(int, input().split()))
c = 0
for i in range(1, N+1):
    if i != p[i-1]:
        c += 1
if c == 0 or c == 2:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
N = int(input())
p = list(map(int, input().split()))
c = 0
for i in range(1, N+1):
    if i == p[i]:
        c += 1
if c == 0 or c == 2:
    print("YES")
else:
    print("NO")
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
N = (a * b) % 2

if N == 0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
a, b = int(input().split())
N = (a * b) % 2

if N == 0:
  print("Even")
else:
  print("Odd")
Problem p03719 (python)

Fixed submission:
a, b, c = map(int, input().split())
if(c >= a and c <= b):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
if(c >= a && c <= b):
  print("Yes")
else:
  print("No")
Problem p02719 (python)

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

if N<=K:
    while K<2*N:
        N=abs(N-K)
    print(N)
else:
    R=N%K
    print(min(R,K-R))

Buggy submission (verdict: Runtime Error):
N,K = map(int, input().split())

if N<=K:
    while K<2*N:
        N=abs(N-k)
    print(N)
else:
    R=N%K
    print(min(R,K-R))
Problem p02747 (python)

Fixed submission:
S = input()

if S=='hi' or S=='hihi' or S=='hihihi' or S=='hihihihi' or S=='hihihihihi':
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
S = input()

if S==hi or S==hihi or S==hihihi or S==hihihihi or S==hihihihihi:
    print('Yes')
else:
    print('No')
Problem p02756 (python)

Fixed submission:
from collections import deque

S=input()
Q=int(input())
Query=[[j for j in input().split()] for i in range(Q)]

c=0
S0=deque(S)

for i in range(Q):
    if Query[i][0]=='1':
        c=c+1
    else:
        if ((Query[i][1]=='1')and(c%2==0)) or ((Query[i][1]=='2')and(c%2==1)):
            S0.appendleft(Query[i][2])
        else:
            S0.append(Query[i][2])

if c%2==0:
    print(''.join(S0))
else:
    print(''.join(reversed(S0)))

Buggy submission (verdict: Runtime Error):
S=input()
Q=int(input())
Query=[[j for j in input().split()] for i in range(Q)]

c=0
S0=list(S)

for i in range(Q):
    if Query[i][0]=='1':
        c=c+1
    else:
        if ((Query[i][1]=='1')and(c%2==0)) or ((Query[i][1]=='2')and(c%2==1)):
            S0.appendleft(Query[i][2])
        else:
            S0.append(Query[i][2])

if c%2==0:
    print(''.join(S0))
else:
    print(''.join(reversed(S0)))
Problem p02765 (python)

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

if N>=10:
    print(R)

else:
    print(R+100*(10-N))

Buggy submission (verdict: Runtime Error):
n,a,b = map(int,input().split())
s=0
 
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
 
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
 
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
 
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
 
    return result
 
s=(2**n)-cmb(n,a)-cmb(n,b)-1
 
print(s%(10**9+7))
Problem p02784 (python)

Fixed submission:
H, N = map(int,input().split())
A = list(map(int, input().split()))
s=0
for i in range(len(A)):
    s=s+A[i]
if s<H:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
H, N = map(int,input().split())
A = list(map(int, input().split()))
if A[0]+A[1]+A[2]<H:
    print('No')
else:
    print('Yes')
Problem p03455 (python)

Fixed submission:
a,b=map(int,input().split())
if a%2==0 or b%2==0:
    print('Even')
else:
    print('Odd')

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())
if a%2==0 or b%2==0:
  print('Even')
else:
  print('Odd')

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())
if a%2==0 or a%2==0:
  print('Even')
else:
  print('Odd')
Problem p02585 (python)

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

lastans = -1e20

for i in range(n):
    now = p[i] - 1 
    score = [c[now]]
    while True:
        now = p[now] - 1
        score.append(score[-1] + c[now])
        if now == i:
            break
    loopsum = score[-1]
    looplen = len(score)
#    print(score)
    if looplen >= k:
        ans = max(score[:k])
    elif loopsum <= 0:
        ans = max(score)
    else:
        loopnum = k//looplen
        loopnum_mod = k % looplen
        ans1 = loopsum * (loopnum - 1) + max(score)
        ans2 = loopsum * loopnum
        if loopnum_mod != 0:
            ans2 = ans2 +max(0,max(score[:loopnum_mod]))
        ans =max(ans1,ans2)
    lastans = max(lastans,ans)

print(lastans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = -1e18

for i in range(n):
    now = p[i] - 1 
    score = [c[now]]
    while True:
        now = p[now] - 1
        score.append(score[-1] + c[now])
        if now == i:
            break
    loopsum = score[-1]
    looplen = len(score)
    if looplen >= k:
        ans = max(ans,max(score[:k]))
    if loopsum <= 0:
        ans = max(ans,max(score))
    else:
        loopnum = k//looplen
        loopnum_mod = k % looplen
        ans = max(ans,(loopnum-1)*loopsum + max(score))    
        ans = max(ans,loopnum*loopsum+max(score[:loopnum_mod]))

print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))


ans = -1e18

for i in range(n):
    now = i
    score = []
    while True:
        now = p[now] - 1
        score.append(c[now])
        if now == i:
            break
    print(score)
    loopsum = sum(score)
    if loopsum <= 0:
        point = 0
        for j in range(len(score)):
            if j > k - 1:
                break 
            point = point + score[j]
            ans = max(ans,point)
    else:
        point = 0      
        for j in range(len(score)-1):
            if j > k - 1:
                break
            point = point + score[j]
            loopnum = (k - (j + 1))//len(score)
            ans = max(ans,point+loopnum*loopsum)
print(ans)
Problem p02663 (python)

Fixed submission:
H1, M1, H2, M2, K = map(int,input().split())

time1 = 60*H1 + M1
time2 = 60*H2 + M2

ans = time2 - K - time1
if ans < 0:
    ans = 0

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
V = [0]*(N+1)
flug = 0
Lsum= sum(A)

V[0] = 1
for i in range(N):
    V[i+1] = (V[i]*2 - A[i+1])
    if V[i+1] <= 0 and i != N-1 :
        flug = 1
    if V[i+1] < 0 and i == N-1 :
        flug = 1
    Lsum = Lsum - A[i+1]
    if V[i+1] > Lsum :
        V[i+1] = Lsum

ans = sum(V)+sum(A)
if A[0] != 0:
    ans = -1
if flug == 1:
   ans = -1
if N == 0:
    ans = -1

print(ans)
Problem p02665 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
V = [0]*(N+1)
flug = 0
Lsum= sum(A)
 
V[0] = 1
for i in range(N):
    V[i+1] = (V[i]*2 - A[i+1])
    if V[i+1] < 0 :
        flug = 1
    Lsum = Lsum - A[i+1]
    if V[i+1] > Lsum :
        V[i+1] = Lsum
 
ans = sum(V)+sum(A)
if A[0] != 0 or A[N] == 0:
    ans = -1
if flug == 1:
   ans = -1
if N == 0 and A[0] != 1:
    ans = -1
elif N == 0 and A[0] == 1:
    ans = 1
 
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
V = [[] for _ in range(N+1)]

for i in range(N):
    if i == 0:
        V[0] = 1
        continue
    V[i] = (V[i-1]*2 - A[i])
V[N]=0

for i in range(N):
    j = N - i -1
    if V[j] > A[j+1] + V[j+1]:
        V[j] = A[j+1] + V[j+1]
 
ans = sum(V)+sum(A)

if A[0] != 0:
    ans = -1

if min(V[:N-1]) <= 0:
    ans = -1

print(ans)