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

Fixed submission:
N = int(input())
p = [int(x) for x in input().split()]

l = []

for i in range(len(p)):
    if p[i] == i + 1:
        l.append(p[i])
    else:
        l.append(0)

count = 0

for i in range(len(l) - 1):
    if l[i] > 0:
        l[i] = 0
        l[i + 1] = 0
        count += 1
if l[len(l) - 1] != 0:
    count += 1

print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
p = [int(x) for x in input().split()]

l = []

for i in range(len(p)):
    if p[i] == i + 1:
        l.append(p[i])
    else:
        l.append(0)

count = 0
for i in range(len(l)):
    if l[i] > 0:
        l[i] = 0
        l[i + 1] = 0
        count += 1
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
p = [int(x) for x in input().split()]

l = []

for i in range(len(p)):
    if p[i] == i + 1:
        l.append(p[i])
    else:
        l.append(0)

count = 0
for i in renge(len(l)):
    if l[i] > 0:
        l[i] = 0
        l[i + 1] = 0
        count += 1
print(count)
Problem p03633 (python)

Fixed submission:
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

n = int(input())
t = [int(input()) for i in range(n)]


for i in range(n - 1):
    t[i + 1] = t[i] * t[i + 1] // gcd(t[i], t[i + 1])

print(t[n - 1])

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
t = [int(input()) for i in range(n)]

for i in range(n - 1):
    t[i + 1] = t[i] * t[i + 1] // math.gcd(t[i], t[i + 1])

print(t[n - 1])
Problem p03658 (python)

Fixed submission:
n, k = [int(x) for x in input().split()]
l = [int(y) for y in input().split()]

l.sort()

print(sum(l[-k:]))

Buggy submission (verdict: Runtime Error):
n, k = [int(x) for x in input().split()]
l = [int(y) for y in input().split()]

l.sort()

print(l[-1]+l[-2]+l[-3])
Problem p03738 (python)

Fixed submission:
a = int(input())
b = int(input())
print('GREATER' if a > b else 'LESS' if a < b else 'EQUAL')

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
print('GREATER' if a>b else 'LESS' if a<b else 'EQUAL')
Problem p03846 (python)

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

b = [0] * ((n + 1) // 2)

if n % 2 == 0:
    for x in a:
        if x % 2 == 0:
            print(0)
            exit()
        b[x // 2] += 1
    for y in b:
        if y != 2:
            print(0)
            exit()
else:
    for x in a:
        if x % 2 != 0:
            print(0)
            exit()
        b[x // 2] += 1
    for y in b[1:]:
        if y != 2:
            print(0)
            exit()
        if b[0] != 1:
            print(0)
            exit()

print((2 ** (n//2)%(10**9+7)))

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

ans = 1
b = [0] * ((n + 1) // 2)

if n % 2 == 0:
    for x in a:
        if x % 2 == 0:
            print(0)
            exit()
        b[x // 2] += 1
    for y in b:
        if y != 2:
            print(0)
            exit()
else:
    for x in a:
        if x % 2 != 0:
            print(0)
            exit()
        b[x // 2] += 1
    for y in b[1:]:
        if y != 2:
            print(0)
            exit()
        if b[0] != 1:
            print(0)
            exit()

print((2 ** (n//2)%(10**9+7))
Problem p03912 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

n,m = readints()
x = readints()
modx = [i%m for i in x]

a = [0]*(10**5+1)
b = [0]*m
for i in range(n):
    a[x[i]]+=1
    b[modx[i]]+=1

ans = b[0]//2
b[0] = 0
y = m//2
if m%2==0:
    ans += b[m//2]//2
    b[m//2] = 0
else:
    y += 1
for i in range(1,y):
    c = min(b[i],b[m-i])
    b[i] -= c
    b[m-i] -= c
    ans += c
for i in range(10**5+1):
    if b[i%m]>1 and a[i]>1:
        c = min(b[i%m],a[i])//2
        ans += c
        b[i%m] -= c*2

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

n,m = readints()
x = readints()
modx = [i%m for i in x]

a = [0]*10**5
b = [0]*m
for i in range(n):
    a[x[i]]+=1
    b[modx[i]]+=1

ans = b[0]//2
b[0] = 0
y = m//2
if m%2==0:
    ans += b[m//2]//2
    b[m//2] = 0
else:
    y += 1
for i in range(1,y):
    c = min(b[i],b[m-i])
    b[i]-=c
    b[m-i]-=c
    ans += c
for i in range(n):
    if b[i%m]>1 and a[i]>1:
        c = min(b[i%m],a[i])//2
        ans += c
        b[i%m]-=c*2

print(ans)
Problem p03964 (python)

Fixed submission:
n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]

t = 1
a = 1

for i in range(n):
    x = max(t//ta[i][0], a//ta[i][1])
    if t > ta[i][0] * x or a > ta[i][1] * x:
        x += 1
    t = ta[i][0] * x
    a = ta[i][1] * x

print(t+a)

Buggy submission (verdict: Runtime Error):
n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]

t = 1
a = 1

for i in range(n):
    x = max(t//ta[i][0], a//ta[i][1])
    if t > ta[i][0] * x or a > ta[i][1] * x
        x += 1
    t = ta[i][0] * x
    a = ta[i][1] * x

print(t+a)

Buggy submission (verdict: Runtime Error):
 = int(input())
ta = [list(map(int, input().split())) for i in range(n)]

t = ta[0][0]
a = ta[0][1]

for i in range(n):
    tt = ta[i][0]
    aa = ta[i][1]
    while t > tt or a > aa:
        tt += ta[i][0]
        aa += ta[i][1]
    t = tt
    a = aa

print(t+a)
Problem p03988 (python)

Fixed submission:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

c = Counter(a)
m = max(a)

flag = True

if m%2 == 0:
    for i in range(1,m+1):
        if i<m//2:
            if c[i]!=0:
                flag = False
                break
        elif i==m//2:
            if c[i]!=1:
                flag = False
                break
        else:
            if c[i]<2:
                flag = False
                break
else:
    for i in range(1,m+1):
        if i<=m//2:
            if c[i]!=0:
                flag = False
                break
        elif i==m//2+1:
            if c[i]!=2:
                flag = False
                break
        else:
            if c[i]<2:
                flag = False
                break

print('Possible' if flag else 'Impossible')

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

n = int(input())
a = list(map(int, input().split()))

c = Counter(a)
m = max(a)

flag = True

for i in range(1, m+1):
    if i<=m//2:
        if c[i]>1:
            flag = False
    else:
        if c[i]<2:
        flag = False
        break
if m%2==0 and c[m//2]!=1:
    flag = False
print('Possible' if flag else 'Impossible')
Problem p02945 (python)

Fixed submission:
A,B = map(int,input().split())

target = list()

target.append(A+B)
target.append(A-B)
target.append(A*B)

print(max(target))

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())

target = list()

target.append(A+B)
target.append(A-B)
target.append(A*B)

print(map(target))
Problem p02993 (python)

Fixed submission:
from sys import stdin

def judge(S):
	S_list  = list(str(S))  #list化
	
	i_pure = None
	for i in S_list:
		if i == i_pure:
			return 'Bad'
		i_pure = i

	return 'Good'


# S = ['3776','8080','1333','0024']

S = stdin.readline()
# for s in S:
# 	print(judge(s))

print(judge(S))

Buggy submission (verdict: Runtime Error):
def judge(S):
	S_list  = list(str(S))  #list化
	
	i_pure = None
	for i in S_list:
		if i == i_pure:
			return 'Bad'
		i_pure = i

	return 'Good'


# S = ['3776','8080','1333','0024']

S = stdin.readline()
# for s in S:
# 	print(judge(s))

print(judge(S))
Problem p02995 (python)

Fixed submission:
import fractions

A,B,C,D = map(int, input().split())


c_and_d=C*D
#CとDの最小公倍数を求める
lcm = int(C*D//fractions.gcd(C,D))


count_C =0
count_D =0
count_C_and_D =0

count_C = int(B//C)-int((A-1)//C)
count_D = int(B//D)-int((A-1)//D)
count_C_and_D = int(B//lcm)-int((A-1)//lcm)

print(int((B-A+1) -(count_C + count_D - count_C_and_D)))

Buggy submission (verdict: Runtime Error):
import math
A,B,C,D = map(int, input().split())

A = A-1
c_and_d=C*D
#CとDの最小公倍数を求める
lcm = int(C*D/math.gcd(C,D))
# print('最小公倍数:',lcm)

count_C =0
count_D =0
count_C_and_D =0

count_C = int(B/C)-int(A/C)
count_D = int(B/D)-int(A/D)
count_C_and_D = int(B/lcm)-int(A/lcm)
A = A+1
print((B-A+1) -(count_C + count_D - count_C_and_D))

Buggy submission (verdict: Runtime Error):
import math
A,B,C,D = map(int, input().split())

A = A-1
c_and_d=C*D
#CとDの最小公倍数を求める
lcm = int(C*D/math.gcd(C,D))
# print('最小公倍数:',lcm)

count_C =0
count_D =0
count_C_and_D =0

count_C = int(B/C)-int(A/C)
count_D = int(B/D)-int(A/D)
count_C_and_D = int(B/lcm)-int(A/lcm)
A = A+1
# print(A,B,count_C , count_D , count_C_and_D)
print((B-A+1) -(count_C + count_D - count_C_and_D))

Buggy submission (verdict: Runtime Error):
from sys import stdin


class C:
	def __init__(self,A,B,C,D):
		self.A = int(A)
		self.B = int(B)
		self.C = int(C)
		self.D = int(D)
		self.list = list(range(self.A,self.B+1)) #リストの生成
		self.ans_list = list()
	def main(self):
		for i in range(self.A,self.B+1):
			if i % self.C != 0:
				if  i % self.D != 0:
					self.ans_list.append(i)

		print(len(self.ans_list))








Inp = stdin.readline()
Inp = Inp.replace('\n','')
Inp = Inp.split()

do = C(Inp[0],Inp[1],Inp[2],Inp[3])

do.main()
Problem p03071 (python)

Fixed submission:
A,B = map(int,input().split())
target = list(range(1,A+1))
target.extend(list(range(1,B+1)))

target.sort(reverse=True)
print(target[0]+target[1])

Buggy submission (verdict: Runtime Error):
import sys

a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())

gap = [abs(a-e),abs(b-e),abs(c-e),abs(d-e)]

for i in range(len(gap)):
	if gap[i] > k:
		print(':(')
		sys.exit()
print('Yay!')
Problem p03292 (python)

Fixed submission:
A = list(map(int,input().split()))
A.sort()
ans = 0
for i in range(len(A)-1):
	ans += abs(A[i]-A[i+1])
print(ans)

Buggy submission (verdict: Runtime Error):
A = list(input())
A.sort()
cost =0
for i in range(len(A)-1):
  cost += abs(A[i]+A[i+1])
print(cost)
Problem p03469 (python)

Fixed submission:
import datetime
S = str(input())
date_format = datetime.datetime.strptime(S,'%Y/%m/%d')
print('2018/'+str(date_format.strftime("%m/%d")))

Buggy submission (verdict: Runtime Error):
from dateutil.relativedelta import relativedelta
import datetime
S = str(input())
date_format = datetime.datetime.strptime(S,'%Y/%m/%d')
date_format = date_format+ relativedelta(years=1)
print(date_format.strftime("%Y/%m/%d"))
Problem p03470 (python)

Fixed submission:
N= int(input())
d = list()
for i in range(N):
	d.append(int(input()))

d_set = set(d)
d_list = list(d_set)
d_list.sort()

print(len(d_list))

Buggy submission (verdict: Runtime Error):
N= int(input())
d = list()
for i in range(N):
    d.append(int(input())

d_set = set(d)
d_list = list(d_set)
d_list.sort()

print(len(d_list))
Problem p03543 (python)

Fixed submission:
N = list(map(int,input()))
count = 1
for i in range(3):
	if N[i] == N[i+1]:
		count += 1
		if count == 3:
			break
	else:
		count = 1

print('Yes') if count >= 3 else print('No')

Buggy submission (verdict: Runtime Error):
N = list(map(int,input()))
count = 1
count_list = list()
for i in range(3):
	if N[i] == N[i+1]:
		count += 1
	else:
		count_list.append(count)
		count = 1
print('Yes') if max(count_list) >= 3 else print('No')
Problem p02628 (python)

Fixed submission:
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
a.sort()
s = 0
for i in range(k):
  s += a[i]
print(s)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input())
a = [int(i) for i in input().split()]
a.sort()
s = 0
for i in range(k):
  s += a[i]
print(s)
Problem p02600 (python)

Fixed submission:
M = int(input())
if M <= 399:
    pass
elif 400 <= M and M <= 599:
    print("8")
elif M <= 799:
    print("7")
elif M <= 999:
    print("6")
elif M <= 1199:
    print("5")
elif M <= 1399:
    print("4")
elif M <= 1599:
    print("3")
elif M <= 1799:
    print("2")
elif M <= 1999:
    print("1")

Buggy submission (verdict: Runtime Error):
M = int(input())
if M <= 399:
    pass
elif 400 <= M and M <= 599:
    print("8")
elif M <= 799:
    print("7")
elif M <= 999:
    print("6")
elif M <= 1199:
    print("5")
elif M <= 1399:
    print("4")1
elif M <= 1599:
    print("3")
elif M <= 1799:
    print("2")
elif M <= 1999:
    print("1")
Problem p02602 (python)

Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
#N, K = 5, 3
#A = [96, 98, 95, 100, 20]
#N, K = 3, 2
#A = [1001, 869120, 1001]
#N, K = 15, 7
#A = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9]

def getA(i):
    if i < 0:
        return 1
    elif i >= N:
        return 1
    else:
        return A[i]
# 
for i in range(K,N):
    #print(i,getA(i-K), getA(i))
    if getA(i-K) < getA(i):
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
import math
A, B, C = list(map(int, input().split()))
K = int(input())
#A, B, C = [7, 4, 2]
#K = 3

i = math.floor(A/(B+1))
K -= i
B = B * (2 ** i)
j = math.floor(B/(C+1))
K -= j
C = C * (2 ** j)
if K >= 0:
    print("Yes")
else:
    print("No")
Problem p02639 (python)

Fixed submission:
X = list(map(int,input().split()))
for i in range(5):
    if X[i] != i+1 :
        print(i+1)

Buggy submission (verdict: Runtime Error):
X = map(int,input().split())
for i in range(5):
    if X[i] != i :
        print(i+1)
Problem p02657 (python)

Fixed submission:
A,B = list(map(int,input().split()))
print(A*B)

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

def f(A):
    for a in A:
        if a == 0:
            print(0)
            return
    v = 1
    for a in A:
        v *= a
        if v > int(1e+18):
            print(-1)
            return
    print(v)
    return

f(A)
Problem p03136 (python)

Fixed submission:
N = int(input())
L = list(map(int,input().split()))
s = 0
for i in L:
    s += i
s -= max(L)
if max(L) < s:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
L = list(map(int,input().split()))
s = 0
for i in L:
    s += i
s -= max(L)
if L < s:
    print("Yes")
else:
    print("No")
Problem p02588 (python)

Fixed submission:
def main():
    N = int(input())
    cnt = [[0] * 19 for _ in range(44)]
    ans = 0
    for _ in range(N):
        a = input()
        if "." in a:
            b = int(a.replace(".", "")) * 10 ** (10 - (len(a) - a.index(".")))
        else:
            b = int(a) * 10 ** 9
        d2 = 0
        d5 = 0
        while b % 2 == 0:
            d2 += 1
            b //= 2
        while b % 5 == 0:
            d5 += 1
            b //= 5
        for i in range(max(0, 18-d2), 44):
            for j in range(max(0, 18-d5), 19):
                ans += cnt[i][j]
        cnt[d2][d5] += 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    cnt = [[0] * 18 for _ in range(41)]
    ans = 0
    for _ in range(N):
        a = input()
        if "." in a:
            b = int(a.replace(".", "") + "0" * (10 - (len(a) - a.index("."))))
        else:
            b = int(a) * 10 ** 9
        d2 = 0
        d5 = 0
        while b % 2 == 0:
            d2 += 1
            b //= 2
        while b % 5 == 0:
            d5 += 1
            b //= 5
        for i in range(max(0, 18-d2), 41):
            for j in range(max(0, 18-d5), 18):
                ans += cnt[i][j]
        cnt[d2][d5] += 1
    print(ans)


if __name__ == "__main__":
    main()
Problem p02632 (python)

Fixed submission:
MOD = int(1e9) + 7
MAX = int(2e6) + 7


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
    FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
    INV[i-1] = (INV[i] * i) % MOD


def combination(m, n):
    return (FACT[m] * INV[n] * INV[m-n]) % MOD


def main():
    K = int(input())
    S = input()
    N = len(S)
    pow25 = [1] * (K+1)
    pow26 = [1] * (K+1)
    for i in range(K):
        pow25[i+1] = (pow25[i] * 25) % MOD
        pow26[i+1] = (pow26[i] * 26) % MOD
    ans = 0
    for m in range(N, N+K+1):
        tmp = (combination(m-1, N-1) * pow25[m-N] * pow26[N+K-m]) % MOD
        ans = (ans + tmp) % MOD
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
MOD = int(1e9) + 7
MAX = int(1e6) + 7


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
    FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
    INV[i-1] = (INV[i] * i) % MOD


def combination(m, n):
    return (FACT[m] * INV[n] * INV[m-n]) % MOD


def main():
    K = int(input())
    S = input()
    N = len(S)
    pow25 = [1] * (K+1)
    pow26 = [1] * (K+1)
    for i in range(K):
        pow25[i+1] = (pow25[i] * 25) % MOD
        pow26[i+1] = (pow26[i] * 26) % MOD
    ans = 0
    for m in range(N, N+K+1):
        tmp = (combination(m-1, N-1) * pow25[m-N] * pow26[N+K-m]) % MOD
        ans = (ans + tmp) % MOD
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
MAX = int(2e5)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
    FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
    INV[i-1] = (INV[i] * i) % MOD


def combination(m, n):
    return (FACT[m] * INV[n] * INV[m-n]) % MOD


def main():
    K = int(input())
    S = input()
    N = len(S)
    pow25 = [1] * (K+1)
    pow26 = [1] * (K+1)
    for i in range(K):
        pow25[i+1] = (pow25[i] * 25) % MOD
        pow26[i+1] = (pow26[i] * 26) % MOD
    ans = 0
    for m in range(N, N+K+1):
        tmp = (combination(m-1, N-1) * pow25[m-N] * pow26[N+K-m]) % MOD
        ans = (ans + tmp) % MOD
    print(ans)


if __name__ == "__main__":
    main()
Problem p02845 (python)

Fixed submission:
MOD = int(1e9+7)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    cnt = [0] * 3
    ans = 1
    for a in A:
        ans = (ans * cnt.count(a)) % MOD
        try:
            c = cnt.index(a)
        except ValueError:
            print(0)
            return
        cnt[c] += 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
MOD = int(1e9+7)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    cnt = [0] * 3
    ans = 1
    for a in A:
        ans = (ans * cnt.count(a)) % MOD
        c = cnt.index(a)
        cnt[c] += 1
    print(ans)


if __name__ == "__main__":
    main()
Problem p02949 (python)

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline


def bellman_ford(N, adj, start):
    ans = [float("inf")] * N
    q = deque()
    q.append((start, 0, 0))
    while len(q):
        i, cost, path = q.pop()
        if cost >= ans[i]:
            continue
        ans[i] = cost
        for j in adj[i]:
            ncost = cost + adj[i][j]
            if path > N:
                ncost = -float("inf")
            q.append((j, ncost, path+1))
    return ans


def main():
    N, M, P = map(int, input().split())
    adj = [{} for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        if B-1 in adj[A-1]:
            adj[A-1][B-1] = min(P-C, adj[A-1][B-1])
        else:
            adj[A-1][B-1] = P-C
    costs = bellman_ford(N, adj, 0)
    ans = -costs[N-1]
    if ans < 0:
        print(0)
    elif ans == float("inf"):
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    main()

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


def bellman_ford(N, adj, start):
    ans = [float("inf")] * N
    q = deque()
    q.append((start, 0, {}))
    while len(q):
        i, cost, history = q.popleft()
        if cost >= ans[i]:
            continue
        ans[i] = cost
        history = {k: history[k] for k in history}
        history[i] = cost
        for j in adj[i]:
            ncost = cost + adj[i][j]
            if j in history and history[j] > ncost:
                ncost = -float("inf")
            q.append((j, ncost, history))
    return ans


def main():
    N, M, P = map(int, input().split())
    adj = [{} for _ in range(N)]
    for _ in range(N):
        A, B, C = map(int, input().split())
        adj[A-1][B-1] = P-C
    costs = bellman_ford(N, adj, 0)
    ans = -costs[N-1]
    if ans < 0:
        print(0)
    elif ans == float("inf"):
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    main()
Problem p03006 (python)

Fixed submission:
def main():
    N = int(input())
    if N == 1:
        print(1)
        return
    P = [None] * N
    for i in range(N):
        x, y = map(int, input().split())
        P[i] = (x, y)
    P.sort()
    cnt = {}
    for i in range(N):
        for j in range(i+1, N):
            ix, iy = P[i]
            jx, jy = P[j]
            d = (jx - ix, jy - iy)
            if d not in cnt:
                cnt[d] = 0
            cnt[d] += 1
    print(N - max(cnt.values()))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    P = [None] * N
    for i in range(N):
        x, y = map(int, input().split())
        P[i] = (x, y)
    P.sort()
    cnt = {}
    for i in range(N):
        for j in range(i+1, N):
            ix, iy = P[i]
            jx, jy = P[j]
            d = (jx - ix, jy - iy)
            if d not in cnt:
                cnt[d] = 0
            cnt[d] += 1
    print(N - max(cnt.values()))


if __name__ == "__main__":
    main()
Problem p03148 (python)

Fixed submission:
from collections import deque


def main():
    N, K = map(int, input().split())
    sushis = [None] * N
    for i in range(N):
        t, d = map(int, input().split())
        sushis[i] = (t, d)
    sushis.sort(key=lambda a: (-a[1], a[0]))
    tmp = 0
    types = set()
    stack = deque()
    ans = 0
    for i in range(len(sushis)):
        t, d = sushis[i]
        if i < K:
            if t in types:
                stack.append(d)
            types.add(t)
            tmp += d
        else:
            if t not in types and len(stack):
                types.add(t)
                tmp += d
                tmp -= stack.pop()
        ans = max(ans, tmp + len(types)**2)
    print(ans)


if __name__ == "__main__":
    main()

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


def main():
    N, K = map(int, input().split())
    sushis = [None] * N
    for i in range(N):
        t, d = map(int, input().split())
        sushis[i] = (t, d)
    sushis.sort(key=lambda a: (-a[1], a[0]))
    tmp = 0
    types = set()
    stack = deque()
    ans = 0
    for i in range(len(sushis)):
        t, d = sushis[i]
        if i < K:
            if t in types:
                stack.append(d)
            types.add(t)
            tmp += d
        else:
            if t not in types:
                types.add(t)
                tmp += d
                tmp -= stack.pop()
        ans = max(ans, tmp + len(types)**2)
    print(ans)


if __name__ == "__main__":
    main()