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

Fixed submission:
from heapq import *
# from itertools import permutations
# from math import pi
# from operator import itemgetter
# from operator import mul
# from operator import xor
# from os import linesep


# def isprime(n: int) -> bool:
#     if n <= 1:
#         return False
#     if n in (2, 3, 5):
#         return True
#     if n % 2 == 0:
#         return False
#     if n % 3 == 0:
#         return False
#     lst = int(n**0.5)
#     f = 5
#     while f <= lst:
#         if n % f == 0:
#             return False
#         if n % (f + 2) == 0:
#             return False
#         f += 6
#     return True


# def strmat(matrix, lnsep: str = linesep, fieldsep: str = ' ') -> str:
#     return lnsep.join(map(lambda row: fieldsep.join(map(str, row)), matrix))


# def strbool(boolval: int) -> str:
#     return ['No', 'Yes'][boolval]


def solve() -> None:
    # read here
    n, m, *t = map(int, open(0).read().split())

    # solve here
    d = [[] for i in range(m+1)]
    for i in range(n):
        a, b = t[2*i], t[2*i+1]
        if a > m:
            continue
        d[a].append(b)

    ans = 0
    tasks = []
    for t in range(m + 1):
        # from (m days after) to today
        for tasksize in d[t]:
            heappush(tasks, -tasksize)
        if tasks:
            # do task
            ans -= heappop(tasks)

    # print here
    print(ans)


if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
import heapq
N,M = map(int,input().split())
days = [[] for _ in range(M + 1)]
for n in range(N):
	a,b = map(int,input().split())
	if a > M:
		continue
	days[a].append(-b)

total_reward = 0
q = []
for day in range(M + 1):
	this_day = days[day]
	for reward in this_day:
		heapq.heappush(q,reward)
	if len(q):
		total_reward -= heapq.heappop(q)
print(total_reward

Buggy submission (verdict: Runtime Error):
import heapq
N,M = map(int,input().split())
days = [[] for _ in range(M + 1)]
for n in range(N):
	a,b = map(int,input().split())
	days[a].append(-b)

total_reward = 0
q = []
for day in range(M + 1):
	this_day = days[day]
	for reward in this_day:
		heapq.heappush(q,reward)
	if len(q):
		total_reward -= heapq.heappop(q)
print(total_reward)
Problem p02990 (python)

Fixed submission:
import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)
n,k = map(int,input().split())
for i in range(1,k + 1):
    if n - k + 1 < i:
        print(0)
        continue
    else:
        print(C(n - k + 1,i) * C(k - 1,i - 1) % 1000000007)

Buggy submission (verdict: Runtime Error):
import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)
n,k = map(int,input().split())
for i in range(1,k + 1):
    print(C(n - k + 1,i) * C(k - 1,i - 1) % 1000000007)
Problem p03013 (python)

Fixed submission:
n,m = map(int,input().split())
stair = [0,1] + [0 for i in range(n)]
ba = 2
for i in range(m):
	a = int(input()) + 1
	for j in range(ba,a):
		stair[j] = stair[j - 1] + stair[j - 2]
	ba = a + 1
for i in range(ba,n + 2):
	stair[i] = stair[i - 1] + stair[i - 2]
print(stair[n + 1] % 1000000007)

Buggy submission (verdict: Runtime Error):
import math
n,m = map(int,input().split())
before = -1
alls = 1
a = -1
if m != 0:
        for i in range(m):
                a = int(input())
                b = (a - before - 2) // 2
                c = a - before - 2
                ptr = 0
                for j in range(b + 1):
                        ptr += math.factorial(c - j) / (math.factorial(j) * math.factorial(c - 2 * j))
                alls = alls * ptr
                before = a
ptr = 0
b = (n - a - 1) // 2
c = n - a - 1
for j in range(b + 1):
        ptr += math.factorial(c - j) / (math.factorial(j) * math.factorial(c - 2 * j))
alls = alls * ptr
print(int(alls % 1000000007))

Buggy submission (verdict: Runtime Error):
import math
n,m = map(int,input().split())
before = -1
alls = 1
for i in range(m):
        a = int(input())
        b = (a - before - 2) // 2
        c = a - before - 2
        ptr = 0
        for j in range(b + 1):
                ptr += math.factorial(c - j) / (math.factorial(j) * math.factorial(c - 2 * j))
        alls = alls * ptr
        before = a
ptr = 0
b = (n - a - 1) // 2
c = n - a - 1
for j in range(b + 1):
        ptr += math.factorial(c - j) / (math.factorial(j) * math.factorial(c - 2 * j))
alls = alls * ptr
print(int(alls % 1000000007))
Problem p03077 (python)

Fixed submission:
n = int(input())
move = [int(input()) for i in range(5)]
div,mod = divmod(n,min(move))
if mod == 0:
    print(div + 4)
else:print(div + 5)

Buggy submission (verdict: Runtime Error):
import heapq
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
asort,bsort,csort = sorted(A,reverse=True),sorted(B,reverse=True),sorted(C,reverse=True)
already = set((0,0,0))
print(asort[0] + bsort[0] + csort[0])
x,y,z = 0,0,0
check = []
for k in range(K - 1):
    if (x + 1,y,z) not in already and x + 1 < X:
        already.add((x + 1,y,z))
        heapq.heappush(check,(-(asort[x + 1] + bsort[y] + csort[z]),x + 1,y,z))
    if (x,y + 1,z) not in already and y + 1 < Y:
        already.add((x,y + 1,z))
        heapq.heappush(check,(-(asort[x] + bsort[y + 1] + csort[z]),x,y + 1,z))
    if (x,y,z + 1) not in already and z + 1 < Z:
        already.add((x,y,z + 1))
        heapq.heappush(check,(-(asort[x] + bsort[y] + csort[z + 1]),x,y,z + 1))
    maxsum = heapq.heappop(check)
    print(-maxsum[0])
    x,y,z = maxsum[1],maxsum[2],maxsum[3]
Problem p03127 (python)

Fixed submission:
import fractions
n = int(input())
a = list(map(int,input().split()))
for N in range(n - 1):
    a[N + 1] = fractions.gcd(a[N],a[N + 1])
print(a[n - 1])

Buggy submission (verdict: Runtime Error):
import fractions
n = int(input())
a = list(map(int,input().split()))
for N in range(n - 1):
    a[N + 1] = math.gcd(a[N],a[N + 1])
print(a[n - 1])
Problem p03252 (python)

Fixed submission:
S = input()
T = input()
check = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}
alll = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
alfa = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
count_s = set()
count_t = set()
nums = 0
numt = 0
for s in range(len(S)):
    if count_s == alfa:
        break
    if S[s] in check:
        continue
    count_s.add(S[s])
    S = S.replace(S[s],str(alll[nums]))
    nums += 1
for t in range(len(T)):
    if count_t == alfa:
        break
    if T[t] in check:
        continue
    count_t.add(T[t])
    T = T.replace(T[t],str(alll[numt]))
    numt += 1
if S == T:
    print('Yes')
else:print('No')

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
alll = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
alfa = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
count_s = set()
count_t = set()
for s in range(len(S)):
    if count_s == alfa:
        break
    if S[s] in count_s:
        continue
    count_s.add(S[s])
    S = S.replace(S[s],str(alll[s]))
for t in range(len(T)):
    if count_t == alfa:
        break
    if t in count_t:
        continue
    count_t.add(T[t])
    T = T.replace(T[t],str(alll[t]))
if S == T:
    print('Yes')
else:print('No')
Problem p02580 (python)

Fixed submission:
from collections import defaultdict

H,W,M=map(int,input().split())
hw = defaultdict(int)
sum1=[0]*H
sum2=[0]*W
for i in range(M):
  h,w=map(int,input().split())
  hw[(h-1,w-1)] += 1
  sum1[h-1] += 1
  sum2[w-1] += 1

sum1 = sorted(enumerate(sum1),key=lambda x:x[1],reverse=True)
sum2 = sorted(enumerate(sum2),key=lambda x:x[1],reverse=True)

max1,max2=set([sum1[0][0]]),set([sum2[0][0]])
for i in range(1,H):
  if sum1[i][1]<sum1[0][1]:
    break
  else:
    max1.add(sum1[i][0])
    
for i in range(1,W):
  if sum2[i][1]<sum2[0][1]:
    break
  else:
    max2.add(sum2[i][0])

ans = sum1[0][1]+sum2[0][1]
count=0
for k in hw.keys():
  h,w=k
  if h in max1 and w in max2:
    count += 1
    
if count < len(max1)*len(max2):
  print(ans)
else:
  print(ans-1)

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

H,W,M=map(int,input().split())
hw = np.zeros([H,W],dtype=int)
for i in range(M):
  h,w=map(int,input().split())
  hw[h-1,w-1] = 1

sum1 = hw.sum(1)
sum2 = hw.sum(0)

sum1 = sorted(enumerate(sum1),key=lambda x:x[1],reverse=True)
sum2 = sorted(enumerate(sum2),key=lambda x:x[1],reverse=True)

ans=0
for idx1,val1 in sum1[:min(3,len(sum1))]:
  for idx2,val2 in sum2:
    tmp = val1+val2-hw[idx1,idx2]
    ans = max(ans,tmp)
    
print(ans)

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

H,W,M=map(int,input().split())
hw = np.zeros([H,W],dtype=int)
for i in range(M):
  h,w=map(int,input().split())
  hw[h-1,w-1] = 1

sum1 = hw.sum(1)
sum2 = hw.sum(0)

sum1 = sorted(enumerate(sum1),key=lambda x:x[1],reverse=True)
sum2 = sorted(enumerate(sum2),key=lambda x:x[1],reverse=True)

ans=0
for idx1,val1 in sum1[:min(3,len(sum1))+1]:
  for idx2,val2 in sum2:
    tmp = val1+val2-hw[idx1,idx2]
    ans = max(ans,tmp)
    
print(ans)
Problem p02659 (python)

Fixed submission:
A,B=input().split()
A = int(A)
B = int(float(B)*100+.5)
print(A*B//100)

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

for x in (A,B):
  if float(x)==int(float(x)):
    x = int(x)
  else:
    x = float(x)

def dicimal2int(d):
  d = str(d)
  if '.' not in d:
    return int(d),0
  if d[:2]=="0.":
    for i in range(2,len(d)):
      if d[i] != '0':
        break
    n_move = len(d)-2
    return int(d[i:]),n_move
  idx = d.index('.')
  n_move = len(d)-idx-1
  return int(d[:idx]+d[idx+1:]),n_move

C1,n1 = dicimal2int(A)
C2,n2 = dicimal2int(B)

D = C1*C2
n = n1+n2

if n==0:
  print(D)
  exit()
  
def int2dicimal(N,n_move):
  if n_move==0:
    return N
  N = str(N)
  for i in range(len(N)):
    if N[-i-1] != '0':
      break
  n_zero = i
  if n_zero>n_move:
    return int(N[:-n_move])
  if n_zero>0:
    N = N[:-n_zero]
    n_move -= n_zero
  if len(N)-1>=n_move:
    return float(N[:-n_move]+'.'+N[-n_move:])
  return float("0."+'0'*(n_move-len(N))+N)

print(int(int2dicimal(D,n)))

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

for x in (A,B):
  if float(x)==int(float(x)):
    x = int(x)
  else:
    x = float(x)

def dicimal2int(d):
  d = str(d)
  if '.' not in d:
    return int(d),0
  if d[:2]=="0.":
    for i in range(2,len(d)):
      if d[i] != '0':
        break
    n_move = len(d)-2
    return int(d[i:]),n_move
  idx = d.index('.')
  n_move = len(d)-idx-1
  return int(d[:idx]+d[idx+1:]),n_move

C1,n1 = dicimal2int(A)
C2,n2 = dicimal2int(B)

D = C1*C2
n = n1+n2

if n==0:
  print(D)
  exit()
  
def int2dicimal(N,n_move):
  if n_move==0:
    return N
  N = str(N)
  for i in range(len(N)):
    if N[-i-1] != '0':
      break
  n_zero = i
  if n_zero>n_move:
    return int(N[:-n_move])
  N = N[:-n_zero]
  n_move -= n_zero
  if len(N)-1>=n_move:
    return float(N[:-n_move]+'.'+N[-n_move:])
  return float("0."+'0'*(n_move-len(N))+N)

print(int(int2dicimal(D,n)))

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

if float(A)==int(float(A)):
  A = int(A)
else:
  A = float(A)
  
if float(B)==int(float(B)):
  B = int(B)
else:
  B = float(B)
    
print(int(A*B))
Problem p02912 (python)

Fixed submission:
from heapq import heappop, heappush

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

B = []
for i in range(N):
  heappush(B,-A[i])

for i in range(M):
  a = heappop(B)
  a /= 2
  heappush(B,a)

print(sum([int(-B[i]) for i in range(N)]))

Buggy submission (verdict: Runtime Error):
from math import log

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

B = [log(A[i]) for i in range(N)]
sumB=sum(B)
C = [B[i]/sumB*M for i in range(N)]
intC = [int(C[i]) for i in range(N)]
r = M - sum(intC)

res = [A[i]//(2**intC[i]) for i in range(N)]

res = sorted(res,reverse=True)

for i in range(r):
  res[i] //= 2

print(sum(res))
Problem p03104 (python)

Fixed submission:
from math import log2

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

def bitpos(x,digit=1):
  bit = x % (2**digit) // (2**(digit-1))
  pos = x % (2**digit)
  return int(bit),pos

if B == 0:
  print(0)
  exit()
else:
  max_digit=int(log2(B))+1

xor=[]
for i in range(max_digit):
  abit,apos = bitpos(A,i+1)
  bbit,bpos = bitpos(B,i+1)
  if i == 0:
    ar,br = A%4,B%4
    if (ar,br) in {(0,1),(0,2),(1,1),(1,2),(2,3),(2,0),(3,3),(3,0)}:
      xor.append('1')
      continue
    else:
      xor.append('0')
      continue
  
  if abit == 0 and bbit==0:
    xor.append('0')
    continue
  elif abit == 1 and bbit==0:
    if apos % 2 == 1:
      xor.append('1')
      continue
    else:
      xor.append('0')
      continue
  elif abit == 0 and bbit == 1:
    if bpos % 2 == 0:
      xor.append('1')
      continue
    else:
      xor.append('0')
      continue
  else:
    if abs(apos-bpos) % 2 == 1:
      xor.append('0')
      continue
    else:
      xor.append('1')
      continue
xor = xor[::-1]
print(int(''.join(xor),2))

Buggy submission (verdict: Runtime Error):
from math import log2

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

def bitpos(x,digit=1):
  bit = x % (2**digit) // (2**(digit-1))
  pos = x % (2**digit)
  return int(bit),pos

max_digit=int(log2(B))+1

xor=[]
for i in range(max_digit):
  abit,apos = bitpos(A,i+1)
  bbit,bpos = bitpos(B,i+1)
  if i == 0:
    ar,br = A%4,B%4
    if (ar,br) in {(0,1),(0,2),(1,1),(1,2),(2,3),(2,0),(3,3),(3,0)}:
      xor.append('1')
      continue
    else:
      xor.append('0')
      continue
  
  if abit == 0 and bbit==0:
    xor.append('0')
    continue
  elif abit == 1 and bbit==0:
    if apos % 2 == 1:
      xor.append('1')
      continue
    else:
      xor.append('0')
      continue
  elif abit == 0 and bbit == 1:
    if bpos % 2 == 0:
      xor.append('1')
      continue
    else:
      xor.append('0')
      continue
  else:
    if abs(apos-bpos) % 2 == 1:
      xor.append('0')
      continue
    else:
      xor.append('1')
      continue
xor = xor[::-1]
print(int(''.join(xor),2))
Problem p02580 (python)

Fixed submission:
h,w,m=map(int,input().split())
hw=[list(map(int,input().split())) for _ in range(m)]
numh=[[i,0] for i in range(h)]
numw=[[i,0] for i in range(w)]
d=set(())
for hi,wi in hw:
  numh[hi-1][1]+=1
  numw[wi-1][1]+=1
  d.add((hi-1,wi-1))
numh.sort(key=lambda x:x[1])
numw.sort(key=lambda x:x[1])
ansh=numh[-1][1]
answ=numw[-1][1]
if ansh+answ==1:
  print(1)
  exit()
# 答えはansh+answまたはansh+answ-1
hk=set(())
while numh and numh[-1][1]==ansh:
  hk.add(numh.pop()[0])
wk=set(())
while numw and numw[-1][1]==answ:
  wk.add(numw.pop()[0])

for wi in wk:
  for hi in hk:
    if (hi,wi) not in d:
      print(ansh+answ)
      exit()
print(ansh+answ-1)

Buggy submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
hw=[list(map(int,input().split())) for _ in range(m)]
numh=[[i,0] for i in range(h)]
numw=[[i,0] for i in range(w)]
m=[[0]*w for _ in range(h)]
for hi,wi in hw:
  numh[hi-1][1]+=1
  numw[wi-1][1]+=1
  m[hi-1][wi-1]=1
numh.sort(key=lambda x:x[1])
numw.sort(key=lambda x:x[1])
ansh=numh[-1][1]
answ=numw[-1][1]
if ansh+answ==1:
  print(1)
  exit()
# 答えはansh+answまたはansh+answ-1
hk=set(())
while numh and numh[-1][1]==ansh:
  hk.add(numh.pop()[0])
wk=set(())
while numw and numw[-1][1]==answ:
  wk.add(numw.pop()[0])

for wi in wk:
  for hi in hk:
    if m[hi][wi]==0:
      print(ansh+answ)
      exit()
print(ansh+answ-1)
Problem p02623 (python)

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

tmp=0
ca=[0]
for ai in a:
  tmp+=ai
  ca.append(tmp)
tmp=0
cb=[0]
for bi in b:
  tmp+=bi
  cb.append(tmp)
import bisect
s=bisect.bisect_right(ca,k)-1
ans=ca[s]
now_a=s
z=k-ca[now_a]
now_b=bisect.bisect_right(cb,z)-1
t=ca[now_a]+cb[now_b]
#print(now_a,now_b)
ans=now_a+now_b
for i in range(s):
  now_a-=1
  t-=a[now_a]
  while now_b<m and t+b[now_b]<=k:
    t+=b[now_b]
    now_b+=1
  ans=max(ans,now_a+now_b)
print(ans)

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

tmp=0
ca=[0]
for ai in a:
  tmp+=ai
  ca.append(tmp)
tmp=0
cb=[0]
for bi in b:
  tmp+=bi
  cb.append(tmp)
import bisect
s=bisect.bisect_right(ca,k)-1
ans=ca[s]
now_a=s
z=k-ca[now_a]
now_b=bisect.bisect_right(cb,z)-1
t=ca[now_a]+cb[now_b]
ans=now_a+now_b
for i in range(s):
  now_a-=1
  t-=a[now_a]
  while t+b[now_b]<=k:
    t+=b[now_b]
    now_b+=1
  ans=max(ans,now_a,now_b)
print(ans)
Problem p02815 (python)

Fixed submission:
n=int(input())
c=sorted(list(map(int,input().split())))
#n=200000
#c=list(range(n))
mod=pow(10,9)+7
# T=000000..とおいて計算し最後に2^nをかける。
# 各コストCiごとにそれが何回足されるかを求める。
# 一番大きいコストc[-1]の係数は必ず1にするのが最適。同様に一番小さいコストc[0]は必要な係数の中で一番大きなものをかけるのがいい。
ans=0
for i,ci in enumerate(c):
  l=i
  r=n-i
  b=pow(2,r-1,mod)+(r-1)*pow(2,r-2,mod) if r>1 else 1
  b*=pow(2,l,mod)
  ans+=ci*b
  ans%=mod
ans*=pow(2,n,mod)
print(ans%mod)

Buggy submission (verdict: Runtime Error):
n=int(input())
c=sorted(list(map(int,input().split())))
mod=pow(10,9)+7
# T=000000..とおいて計算し最後に2^nをかける。
# 各コストCiごとにそれが何回足されるかを求める。
# 一番大きいコストc[-1]の係数は必ず1にするのが最適。同様に一番小さいコストc[0]は必要な係数の中で一番大きなものをかけるのがいい。
ans=0
for i,ci in enumerate(c):
  l=i
  r=n-i
  b=pow(2,r-1,mod)+(r-1)*pow(2,r-2,mod) if r>0 else 1
  b*=pow(2,l,mod)
  ans+=ci*b
  ans%=mod
ans*=pow(2,n,mod)
print(ans%mod)
Problem p02884 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
inf=float('inf')

def main(n,m,g,uv):
    # 1<=E<=n-1
    eary=[inf]*m
    vary=[inf]*n
    vary[-1]=0
    todo=[n-1]
    def dfs(v,x):
        if vary[v]<inf:return vary[v]
        ret=0
        cnt=0
        for i,nv in g[v]:
            if i==x:continue
            tmp=dfs(nv,x)+1
            eary[i]=tmp
            ret+=tmp
            cnt+=1
        if cnt==0:
            for i in range(n):
                vary[i]=inf
            return inf
        vary[v]=ret/cnt
        return ret/cnt
    e0=dfs(0,-1)
    ary=[-1]*m
    bary=[0]*n
    bary[0]=1
    for v in range(n):
        k=len(g[v])
        e=vary[v]
        for i,nv in g[v]:
            bary[nv]+=1/k*bary[v]
            if k>1 and bary[v]:
                ary[i]=max(0,e-(e*k-eary[i])/(k-1))
                ary[i]*=bary[v]
    return e0-max(0,max(ary))

n,m=map(int,input().split())
uv=[list(map(int,input().split())) for _ in range(m)]
g=[[] for _ in range(n)]
for i,(u,v) in enumerate(uv):
    u,v=u-1,v-1
    g[u].append((i,v))
print(main(n,m,g,uv))

Buggy submission (verdict: Runtime Error):

def main(n,m,g,uv):
    # 1<=E<=n-1
    eary=[inf]*m
    vary=[inf]*n
    vary[-1]=0
    todo=[n-1]
    def dfs(v,x):
        if vary[v]<inf:return vary[v]
        ret=0
        cnt=0
        for i,nv in g[v]:
            if i==x:continue
            tmp=dfs(nv,x)+1
            eary[i]=tmp
            ret+=tmp
            cnt+=1
        if cnt==0:
            for i in range(n):
                vary[i]=inf
            return inf
        vary[v]=ret/cnt
        return ret/cnt
    e0=dfs(0,-1)
    ary=[-1]*m
    bary=[0]*n
    bary[0]=1
    for v in range(n):
        k=len(g[v])
        e=vary[v]
        for i,nv in g[v]:
            bary[nv]+=1/k*bary[v]
            if k>1 and bary[v]:
                ary[i]=max(0,e-(e*k-eary[i])/(k-1))
                ary[i]*=bary[v]
    #print(e0)
    #print(vary)
    #print(ary)
    #print(bary)
    return e0-max(0,max(ary))

n,m=map(int,input().split())
uv=[list(map(int,input().split())) for _ in range(m)]
g=[[] for _ in range(n)]
for i,(u,v) in enumerate(uv):
    u,v=u-1,v-1
    g[u].append((i,v))
print(main(n,m,g,uv))
Problem p02925 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
def main():
  n=int(input())
  a=[list(map(int,input().split())) for _ in range(n)]
  f=lambda x:((x[0]-1)*(n-1+n-x[0]+1))//2+x[1]-x[0]-1
  m=(n*(n-1))//2
  g=[[] for _ in range(m)]
  for i in range(n):
    for j in range(n-2):
      if i+1>a[i][j]:
        t0=f((a[i][j],i+1))
      else:
        t0=f((i+1,a[i][j]))
      if i+1>a[i][j+1]:
        t1=f((a[i][j+1],i+1))
      else:
        t1=f((i+1,a[i][j+1]))
      g[t0].append(t1)
  def dfs(t):
    if v[t]:
      if c[t]==0:
        return -1
      else:
        return dp[t]
    v[t]=1
    for l in g[t]:
      ret=dfs(l)
      if ret==-1:return -1
      dp[t]=max(dp[t],ret+1)
    c[t]=1
    mi.discard(t)
    return dp[t]
  ans=0
  v=[0]*m
  c=[0]*m
  dp=[0]*m
  #print(g)
  mi=set(list(range(m)))
  while mi:
    i=mi.pop()
    tmp=dfs(i)
    if tmp==-1:
      print(-1)
      exit()
    ans=max(ans,tmp)
    #print(dp)
  print(ans+1)

if __name__=='__main__':
  main()

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
f=lambda x:((x[0]-1)*(n-1+n-x[0]+1))//2+x[1]-x[0]-1
m=(n*(n-1))//2
g=[[] for _ in range(m)]
for i in range(n):
  for j in range(n-2):
    if i+1>a[i][j]:
      t0=f((a[i][j],i+1))
    else:
      t0=f((i+1,a[i][j]))
    if i+1>a[i][j+1]:
      t1=f((a[i][j+1],i+1))
    else:
      t1=f((i+1,a[i][j+1]))
    g[t0].append(t1)

def dfs(t):
  if v[t]:
    if c[t]==0:
      return -1
    else:
      dp[t]
  v[t]=1
  for l in g[t]:
    ret=dfs(l)
    if ret==-1:return -1
    dp[t]=max(dp[t],ret+1)
  c[t]=1
  return dp[t]
ans=0
for i in range(m):
  v=[0]*m
  c=[0]*m
  dp=[0]*m
  tmp=dfs(i)
  if tmp==-1:
    print(-1)
    exit()
  ans=max(ans,tmp)
print(ans+1)
Problem p03013 (python)

Fixed submission:
n,m=map(int,input().split())
a=[]
for _ in range(m):
    a.append(int(input()))
ans=1
a.sort()
d={0:1,1:1,2:2,3:3,4:5,5:8,6:13,99500:49759705584609,99501:49760296517401}
def func(n):
    if n in d:
        return d[n]
    else:
        v = (func(n-1)+func(n-2))%(10**9+7)
        d[n]=v
        return v
ps=-1
a.append(n+1)
for ai in a:
    c=ai-ps-2
    ps=ai
    if c<0:
        print(0)
        exit()
    c=func(c)
    ans*=c
    ans%=10**9+7

print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
dp=[1]*n
mod=10**9+7
for i in range(m):
  a=int(input())
  dp[a-1]=0

ans=[]
ans.append(1 if dp[0]==1 else 0)
if dp[0]==1 and dp[1]==1:
    ans.append(2)
elif dp[0]==1 and dp[1]==0:
    ans.append(0)
elif dp[0]==0 and dp[1]==1:
    ans.append(1)
elif dp[0]==0 and dp[1]==0:
    print(0)
    exit()
for i in range(2,n):
    ans.append((ans[i-1]+ans[i-2])*dp[i]%mod)
print(ans[-1]%mod)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]
for _ in range(m):
    a.append(int(input()))
ans=1
a.sort()
d={0:1,1:1,2:2,3:3,4:5,5:8,6:13}
def func(n):
    if n in d:
        return d[n]
    else:
        v = func(n-1)+func(n-2)%(10**9+7)
        d[n]=v
        return v
ps=-1
a.append(n+1)
for ai in a:
    c=ai-ps-2
    ps=ai
    if c<0:
        print(0)
        exit()
    c=func(c)
    ans*=c
    ans%=10**9+7

print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]
for _ in range(m):
    a.append(int(input()))
ans=1
a.sort()
def func(n):
    if n<=3:
        return max(1,n)
    else:
        return func(n-1)+func(n-2)
ps=-1
a.append(n+1)
for ai in a:
    c=ai-ps-2
    ps=ai
    if c<0:
        print(0)
        exit()
    c=func(c)
    ans*=c
    ans%=10**9+7

print(ans%(10**9+7))