Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# D - katana Thrower
# モジュールのインポート
import math

# 標準入力の取得
N,H = list(map(int, input().split()))
a,b = [],[]
for n in range(N):
    a_n,b_n = list(map(int, input().split()))
    a.append(a_n)
    b.append(b_n)

# 求解処理
"""
    すでに投げてしまった刀も振ることはできるとしても答えは変わらない。
    以下の攻撃手順を行う：
    0. a_1, a_2, ・・・, a_Nのうち最大値をa_maxとし、攻撃力がa_max以上の投げ刀を「強い投げ刀」とする。
    1. 強い投げ刀を攻撃力が高い順に投げていく。
    2. 強い投げ刀を使い果たしたら、攻撃力a_maxの振り刀を振り続ける。
"""
max_a = max(a)
sorted_b = reversed(sorted(b))
min_count = 0
for b_n in sorted_b:
    if (b_n < max_a) or (H <= 0):
        break
    H -= b_n
    min_count += 1

if H > 0:
    min_count += math.ceil(H / max_a)

# 結果出力
print(min_count)

Fixed submission:
# -*- coding: utf-8 -*-
# C - Otoshidama
# モジュールのインポート
import sys

# 定数の定義
YEN_10000 = 10000
YEN_5000 = 5000
YEN_1000 = 1000

# 標準入力の取得
N,Y = list(map(int, input().split()))

# 探索処理
is_correct = False
for n_10000 in range(N+1):
    for n_5000 in range(N+1-n_10000):
        n_1000 = N - n_10000 - n_5000
        amount = YEN_10000*n_10000 + YEN_5000*n_5000 + YEN_1000*n_1000
        if amount == Y:
            is_correct = True
            print(n_10000, n_5000, n_1000)
            sys.exit()

if not is_correct:
    print("-1 -1 -1")
Buggy python submission (verdict: Runtime Error):
#import numpy as np
#from collections import Counter
#import sys
#sys.setrecursionlimit(10000000)

def main(S_: int):
    MOD = int(10**9+7)
    dp = []
    for _ in range(2002):
        dp.append([0]*2002)
    #dp = np.full((2001, 2001), 0)
    # dp[s][p] = sをp通りに分割する方法
    dp[1][1] = 0
    dp[2][1] = 0
    #print(dp)
    for s in range(3, S+1):
        dp[s][1] = 1
        if s % 3 == 0:
            dp[s][s//3] = 1
        for r in range(2, (s//3)+1):  #s//3個までは分割可能
            #print(f's,r={s},{r}')
            #例えば
            # dp[8,2] = dp[5,1] + dp[4,1]+ dp[3,1] + ...
            # dp[11,3] = dp[8,2] + dp[7,2] + dp[6, 2] + dp[5,2] + ...
            for i in range(s-3+1):
                dp[s][r] += dp[i][r-1]
                dp[s][r] %= MOD
            #dp[s][r] = dp[:s-3+1, r-1].sum() % MOD
            
    for i in range(15):
        #print(dp[i][:15])
    ans = 0
    for i in range(len(dp[0])):
        ans += dp[S_][i]
        ans %= MOD
    return ans % MOD


if __name__ == '__main__':
    S = int(input())
    ans = main(S)
    print(ans)

Fixed submission:
def main(S_: int):
    MOD = int(10**9+7)
    dp = [0] * 2001
    for s in range(3, S_+1):
        dp[s] = 1 #1分割はできる
        for r in range(3, s):
            dp[s] += dp[s-r]
            dp[s] %= MOD

    return dp[S_] % MOD


if __name__ == '__main__':
    S = int(input())
    ans = main(S)
    print(ans)
Buggy python submission (verdict: Runtime Error):
def main():
    K = int(input())
    if K%2 == 0 or K%5==0:
        return -1

    if K % 7 == 0:
        L = K * 9 / 7
    else:
        L = K * 9
    
    for i in range(1, 10000000):
        x = pow(10, i, L)
        if x == 1:
            return i
    else:
        return -1


if __name__ == "__main__":
    ans = main()
    print(ans)

Fixed submission:
def main():
    K = int(input())
    if K%2 == 0 or K%5==0:
        return -1

    if K % 7 == 0:
        L = K * 9 // 7
    else:
        L = K * 9
    
    for i in range(1, 10000000):
        x = pow(10, i, L)
        if x == 1:
            return i
    else:
        return -1


if __name__ == "__main__":
    ans = main()
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
        B = [int(ceil(a/arg))-1 for a in A]
        #print(arg, B)
        if sum(B) <= K:
            return True
        else:
            return False

    def meguru_bisect(ng, ok):
        '''
        初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
        まずis_okを定義すべし
        ng ok は  とり得る最小の値-1 とり得る最大の値+1
        最大最小が逆の場合はよしなにひっくり返す
        '''
        while (abs(ok - ng) > 1):
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok
    
    ans = meguru_bisect(0, int(1e100))
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
from math import ceil

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
        B = [int(ceil(a/arg))-1 for a in A]
        #print(arg, B)
        if sum(B) <= K:
            return True
        else:
            return False

    def meguru_bisect(ng, ok):
        '''
        初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
        まずis_okを定義すべし
        ng ok は  とり得る最小の値-1 とり得る最大の値+1
        最大最小が逆の場合はよしなにひっくり返す
        '''
        while (abs(ok - ng) > 1):
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok
    
    ans = meguru_bisect(0, int(1e20))
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = tuple(int(c) for c in input().split(' '))
    A = [1] + list(int(c) for c in input().split(' '))

    S = 1
    for i in range(1, K+1):
        S *= A[i]
    for i in range(K+1, N+1):
        S2 = S * A[i] // A[i-K]
        if S2 > S:
            print('Yes')
        else:
            print('No')
        S = S2


if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N, K = tuple(int(c) for c in input().split(' '))
    A = [1] + list(int(c) for c in input().split(' '))

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

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):

def main():
    N = int(input())
    if N==1:
        print(1)
        exit()
    elif N==2:
        print(5)
        exit()
 
    divs = [1]*(N+10)
 
    for i in range(2, N+1):
        max_t = N // i
        for j in range(1, max_t+1):
            val = i*j
            divs[val] += 1
    ans = 0
    for i in range(1, N+1):
        ans += i * divs[i]
    print(ans)
if __name__ == "__main__":
    main()

Fixed submission:
#from collections import Counter

def main():
    N = int(input())
    if N==1:
        print(1)
        exit()
    elif N==2:
        print(5)
        exit()

    divs = [1]*(N+10)

    for i in range(2, N+1):
        max_t = N // i
        for j in range(1, max_t+1):
            val = i*j
            divs[val] += 1
    ans = 0
    for i in range(1, N+1):
        ans += i * divs[i]
    print(ans)
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N = int(input())
A = map(int, input().split())
Q = int(input())
ops = []
for _ in range(Q):
  b, c = map(int, input().split())
  ops.append((b,c))

tot = []
cnt = Counter(A)
for b, c in ops:
  #print(cnt)
  #print(b, c)
  cnt[c] += cnt[b]
  cnt[b] = 0
  s = sum(k*v for k, v in cnt.items())
  print(s)

Fixed submission:
from collections import Counter
N = int(input())
A = map(int, input().split())
Q = int(input())
ops = []
for _ in range(Q):
  b, c = map(int, input().split())
  ops.append((b,c))

cnt = Counter(A)
s = sum(k*v for k, v in cnt.items())
for b, c in ops:
  s -= b * cnt[b]
  s += c * cnt[b]
  cnt[c] += cnt[b]
  cnt[b] = 0
  print(s)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
A = [int(c) for c in input().split(' ')]

ret = np.prod(A, dtype='float128')
if int(ret) > 1e18:
  print(-1)
else:
  print(ret)

Fixed submission:
#import functools

def main():
    N = int(input())
    A = [int(c) for c in input().split(' ')]
    A.sort(reverse=True)

    if A[-1] == 0:
        print('0')
        exit()
    elif A[0] > 1e18:
        print('-1')
        exit()

    ret = 1
    for x in A:
        ret = ret * x
        if ret > 1e18:
            print('-1')
            exit()
        elif ret == 0:
            print('0')
            exit()

    if ret == 0:
        print('0')
        exit()
    elif ret > 1e18:
        print('-1')
        exit()
    print(f'{ret}')


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#import functools

def main():
    N = int(input())
    A = [int(c) for c in input().split(' ')]
    A.sort(reverse=True)

    if A[-1] == 0:
        print('0')
        exit()
    elif A[0] > 1e18:
        print('-1')
        exit()

    ret = 1
    for x in A:
        ret = ret * x
        # if ret > 1e18:
        #     print('-1')
        #     exit()
        # elif ret == 0:
        #     print('0')
        #     exit()

    if ret == 0:
        print('0')
        exit()
    elif ret > 1e18:
        print('-1')
        exit()
    print(f'{ret}')


if __name__ == "__main__":
    main()

Fixed submission:
#import functools

def main():
    N = int(input())
    A = [int(c) for c in input().split(' ')]
    A.sort(reverse=True)

    if A[-1] == 0:
        print('0')
        exit()
    elif A[0] > 1e18:
        print('-1')
        exit()

    ret = 1
    for x in A:
        ret = ret * x
        if ret > 1e18:
            print('-1')
            exit()
        elif ret == 0:
            print('0')
            exit()

    if ret == 0:
        print('0')
        exit()
    elif ret > 1e18:
        print('-1')
        exit()
    print(f'{ret}')


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import functools

def main():
    N = int(input())
    A = [int(c) for c in input().split(' ')]

    ret = functools.reduce(lambda x, y: x*y, A)
    if ret > 1e18:
        print('-1')
    else:
        print(f'{ret}')


if __name__ == "__main__":
    main()

Fixed submission:
#import functools

def main():
    N = int(input())
    A = [int(c) for c in input().split(' ')]
    A.sort(reverse=True)

    if A[-1] == 0:
        print('0')
        exit()
    elif A[0] > 1e18:
        print('-1')
        exit()

    ret = 1
    for x in A:
        ret = ret * x
        if ret > 1e18:
            print('-1')
            exit()
        elif ret == 0:
            print('0')
            exit()

    if ret == 0:
        print('0')
        exit()
    elif ret > 1e18:
        print('-1')
        exit()
    print(f'{ret}')


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#from collections import defaultdict, deque
#import itertools
#import numpy as np
#import re

def main():
    N = int(input())
    SS = []
    for _ in range(N):
        SS.append(input())
    S = []
    for s in SS:
        while '()' in s:
            s = s.replace('()', '')
        S.append(s)
    #print(S)
    S = [s for s in S if s != '']
    sum_op = 0
    sum_cl = 0
    S_both_op = []
    S_both_cl = []
    for s in S:
        if not ')' in s:
            sum_op += len(s)
        elif not '(' in s:
            sum_cl += len(s)
        else:
            pos = s.find('(')
            if pos <= len(s) - pos:
                S_both_op.append((pos, len(s)-pos))  #closeのほうが少ない、'))((('など -> (2,3)
            else:
                S_both_cl.append((pos, len(s)-pos))  #closeのほうが多い、')))(('など -> (3,2)

    # S_both_opは、耐えられる中でより伸ばす順にしたほうがいい？
    sort(S_both_op, key=lambda x: x[0])  #closeの数が小さい順にsort
    sort(S_both_cl, key=lambda x: x[0])  #これもcloseの数が小さい順にsort

    for p in S_both_op:
        sum_op -= p[0]
        if(sum_op < 0 ):
            print('No')
            exit()
        sum_op += p[1]
    for p in S_both_cl:
        sum_op -= p[0]
        if(sum_op < 0 ):
            print('No')
            exit()
        sum_op += p[1]
    
    if sum_op == sum_cl:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()

Fixed submission:
#from collections import defaultdict, deque
#import itertools
#import numpy as np
#import re
import bisect

def main():
    N = int(input())
    SS = []
    for _ in range(N):
        SS.append(input())
    S = []
    for s in SS:
        while '()' in s:
            s = s.replace('()', '')
        S.append(s)
    #print(S)
    S = [s for s in S if s != '']
    sum_op = 0
    sum_cl = 0
    S_both_op = []
    S_both_cl = []
    for s in S:
        if not ')' in s:
            sum_op += len(s)
        elif not '(' in s:
            sum_cl += len(s)
        else:
            pos = s.find('(')
            if pos <= len(s) - pos:
                S_both_op.append((pos, len(s)-pos))  #closeのほうが少ない、'))((('など -> (2,3)
            else:
                S_both_cl.append((pos, len(s)-pos))  #closeのほうが多い、')))(('など -> (3,2)

    # S_both_opは、耐えられる中でより伸ばす順にしたほうがいい？
    #S_both_op.sort(key=lambda x: (x[0], x[0]-x[1]))  #closeの数が小さい順にsortかつclose-openが小さい=伸ばす側にsort
    #S_both_cl.sort(key=lambda x: (x[0], x[0]-x[1]))  #これもcloseの数が小さい順にsortかつclose-openが小さい=あまり縮まない順にsort
    S_both_op.sort(key=lambda x: x[0])
    S_both_cl.sort(key=lambda x: -x[1])

    for p in S_both_op:
        sum_op -= p[0]
        if(sum_op < 0 ):
            print('No')
            exit()
        sum_op += p[1]

    for p in S_both_cl:
        sum_op -= p[0]
        if(sum_op < 0 ):
            print('No')
            exit()
        sum_op += p[1]
    
    if sum_op == sum_cl:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
R = float(input)
print(R * 2 * 3.1416)

Fixed submission:
R = int(input())
print(R * 2 * 3.1416)
Buggy python submission (verdict: Runtime Error):
N, M = tuple(int(c) for c in input().split(' '))
A = tuple(int(c) for c in input().split(' '))
if len(sum(A)) > N:
  print(-1)
else:
  print(len(sum(A)) > N)

Fixed submission:
N, M = tuple(int(c) for c in input().split(' '))
A = tuple(int(c) for c in input().split(' '))
if sum(A) > N:
  print(-1)
else:
  print(N - sum(A))
Buggy python submission (verdict: Runtime Error):
# inp.readline()
# int(inp.readline())
# out.write()
# raw_input()
# map(int,raw_input().split())
# map(int,inp.readline().split())
# for _ in xrange(input()):
# print "Case #"+str(_+1)+": "+ 
if __name__ == "__main__":
    from sys import stdin as inp, stdout as out,setrecursionlimit as srl
    from collections import Counter,defaultdict,deque
    from heapq import *
    def upd(idx,v):
      while idx<len(b):
        b[idx]=(b[idx]+v)%mod
        idx+=(idx&-idx)
    def acc(idx):
        s=0
        while idx>0:
            s=(s+b[idx])%mod
            idx-=(idx&-idx)
        return s
    for _ in xrange(1):
        n,k=map(int,inp.readline().split())
        a=[map(int,inp.readline().split()) for i in xrange(k)]
        b=[0]*(n+1)
        b[1]=1
        mod=998244353
        for i in xrange(2,n+1):
          for l,r in a:
            upd(i,acc(i-l+1)-acc(max(0,i-r)))
        print (acc(n+1)-acc(n))%mod

Fixed submission:
# inp.readline()
# int(inp.readline())
# out.write()
# raw_input()
# map(int,raw_input().split())
# map(int,inp.readline().split())
# for _ in xrange(input()):
# print "Case #"+str(_+1)+": "+ 
if __name__ == "__main__":
    from sys import stdin as inp, stdout as out,setrecursionlimit as srl
    from collections import Counter,defaultdict,deque
    from heapq import *
    for _ in xrange(1):
        n,k=map(int,inp.readline().split())
        a=[map(int,inp.readline().split()) for i in xrange(k)]
        b=[0]*(n+1)
        b[1]=1
        mod=998244353
        for i in xrange(2,n+1):
          b[i]=b[i-1]
          for l,r in a:
            b[i]=(b[i]+b[max(0,i-l)]-b[max(0,i-r-1)])%mod
        print (b[-1]-b[-2])%mod
Buggy python submission (verdict: Runtime Error):
print input()^1

Fixed submission:
print input()^1
Buggy python submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(1<<30)
def f(i,b1,b2):
  if i==n:
    return b1 and b2
  if z[i][b1][b2]==-1:
    z[i][b1][b2]=sum(f(i+1,b1 or j==0,b2 or j==9) for j in xrange(10))%(pow(10,9)+7)
  return z[i][b1][b2]
n=input()
z=[[[-1 for _1 in xrange(2)] for _2 in xrange(2)] for _3 in xrange(n+1)]
print f(0,False,False)

Fixed submission:
n=input()
z=[[[0 for _1 in xrange(2)] for _2 in xrange(2)] for _3 in xrange(n+1)]
z[-1][1][1]=1
for i in xrange(n-1,-1,-1):
  for j in xrange(2):
    for k in xrange(2):
      for t in xrange(10):
        z[i][j][k]+=z[i+1][j or t==0][k or t==9]
      z[i][j][k]%=(pow(10,9)+7)
print z[0][0][0]
Buggy python submission (verdict: Runtime Error):
n=input()
a=map(int,raw_input().split())
z=[0]*n
z[1]=abs(a[1]-a[0])
for i in xrange(2,n):
  z[i]=min(z[i-1]+abs(a[i]-a[i-1],z[i-2]+abs(a[i]-a[i-2]))
print z[-1]

Fixed submission:
n=input()
a=map(int,raw_input().split())
z=[0]*n
z[1]=abs(a[1]-a[0])
for i in xrange(2,n):
  z[i]=min(z[i-1]+abs(a[i]-a[i-1]),z[i-2]+abs(a[i]-a[i-2]))
print z[-1]
Buggy python submission (verdict: Time Limit Exceeded):
def f(i,w,d):
  if i==n:
    return 0
  if (i,w) not in d:
    if a[i][0]>w:
      d[i,w]=f(i+1,w,d)
    else:
      d[i,w]=max(f(i+1,w,d),f(i+1,w-a[i][0],d)+a[i][1])
  return d[i,w]
n,w=map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in xrange(n)]
print f(0,w,{})

Fixed submission:
n,w=map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in xrange(n)]
z=[[0]*(w+1)]
for i in xrange(n):
    z.append(z[-1][:])
    for j in xrange(w+1):
        if a[i][0]<=j:
            z[i+1][j]=max(z[i+1][j],z[i][j-a[i][0]]+a[i][1])
print max(z[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in xrange(n)]
z=[[0]*(w+1)]
for i in xrange(n):
    z.append(z[-1][:])
    for j in xrange(a[i][0],w+1):
		z[i+1][j]=max(z[i+1][j],z[i][j-a[i][0]]+a[i][1])
print max(z[-1])


Fixed submission:
n,w=map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in xrange(n)]
z=[[0]*(w+1)]
for i in xrange(n):
    z.append(z[-1][:])
    for j in xrange(w+1):
        if a[i][0]<=j:
            z[i+1][j]=max(z[i+1][j],z[i][j-a[i][0]]+a[i][1])
print max(z[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in xrange(n)]
z=[[0]*(w+1) for _ in xrange(n+1)]
for i in xrange(n):
    for j in xrange(w+1):
        z[i+1][j]=z[i][j]
        if a[i][0]<=j:
            z[i+1][j]=max(z[i+1][j],z[i][j-a[i][0]]+a[i][1])
print max(z[-1])

Fixed submission:
n,w=map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in xrange(n)]
z=[[0]*(w+1)]
for i in xrange(n):
    z.append(z[-1][:])
    for j in xrange(w+1):
        if a[i][0]<=j:
            z[i+1][j]=max(z[i+1][j],z[i][j-a[i][0]]+a[i][1])
print max(z[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in xrange(n)]
z=[[0]*(w+1)]
for i in xrange(n):
    z.append(z[-1][:])
    for j in xrange(w+1):
        if a[i][0]<=j:
            z[i+1][j]=max(z[i+1][j],z[i][j-a[i][0]]+a[i][1])
print max(z[-1])

Fixed submission:
n,w=map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in xrange(n)]
z=[[0]*(w+1)]
for i in xrange(n):
    z.append(z[-1][:])
    for j in xrange(w+1):
        if a[i][0]<=j:
            z[i+1][j]=max(z[i+1][j],z[i][j-a[i][0]]+a[i][1])
print max(z[-1])
Buggy python submission (verdict: Time Limit Exceeded):
s=raw_input().strip()
t=raw_input().strip()
n=len(s)
m=len(t)
z=[[0]*(m+1) for _ in xrange(n+1)]
for i in xrange(n):
    for j in xrange(m):
        if s[i]==t[j]:
            z[i+1][j+1]=z[i][j]+1
        else:
            z[i+1][j+1]=max(z[i+1][j],z[i][j+1])
i=n-1
j=m-1
a=[]
while i>=0 and j>=0:
    if s[i]==t[j]:
        a.append(s[i])
        i-=1
        j-=1
    elif z[i][j+1]>z[i+1][j]:
        i-=1
    else:
        j-=1
print ''.join(a[::-1])

Fixed submission:
s=raw_input().strip()
t=raw_input().strip()
n=len(s)
m=len(t)
z=[[0]*(m+1) for _ in xrange(n+1)]
for i in xrange(n):
    for j in xrange(m):
        if s[i]==t[j]:
            z[i+1][j+1]=z[i][j]+1
        else:
            z[i+1][j+1]=max(z[i+1][j],z[i][j+1])
i=n-1
j=m-1
a=[]
while i>=0 and j>=0:
    if s[i]==t[j]:
        a.append(s[i])
        i-=1
        j-=1
    elif z[i][j+1]>z[i+1][j]:
        i-=1
    else:
        j-=1
print ''.join(a[::-1])
Buggy python submission (verdict: Runtime Error):
def f(x):
  if z[x]==-1:
  	z[x]=max([f(i) for i in v[x]]+[-1])+1
  return z[x]
n,m=map(int,raw_input().split())
v=[[] for _ in xrange(n)]
for x,y in [map(int,raw_input().split()) for _ in xrange(m)]:
  v[x-1].append(y-1)
z=[-1]*n
for i in xrange(n):
  if z[i]==-1:
    f(i)
print max(z)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(1<<30)
def f(x):
  if z[x]==-1:
  	z[x]=max([f(i) for i in v[x]]+[-1])+1
  return z[x]
n,m=map(int,raw_input().split())
v=[[] for _ in xrange(n)]
for x,y in [map(int,raw_input().split()) for _ in xrange(m)]:
  v[x-1].append(y-1)
z=[-1]*n
for i in xrange(n):
  if z[i]==-1:
    f(i)
print max(z)
Buggy python submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(1<<30)
def f(i,j,d):
  if i>=j:
    return 0
  if z[i][j]==-1:
    q=1<<64
    for k in xrange(i,j+1):
      q=min(q,s[j+1]-s[i]+f(i,k,d)+f(k+1,j,d))
    z[i][j]=q
  return z[i][j]
n=input()
a=map(int,raw_input().split())
s=[0]
for i in a:
  s.append(s[-1]+i)
z=[[-1]*n for i in xrange(n)]
print f(0,n-1,{})

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(1<<30)
def f(i,j,d):
  if i>=j:
    return 0
  if z[i][j]==-1:
    q=1<<64
    for k in xrange(i,j):
      q=min(q,s[j+1]-s[i]+f(i,k,d)+f(k+1,j,d))
    z[i][j]=q
  return z[i][j]
n=input()
a=map(int,raw_input().split())
s=[0]
for i in a:
  s.append(s[-1]+i)
z=[[-1]*n for i in xrange(n)]
print f(0,n-1,{})
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
snuke = [1 for i in range(n)]
for _ in range(k):
	d = int(input())
	a = list(map(int, input().split()))
	for i in range(a):
		snuke[i -1] = 0
		
print(sum(snuke))

Fixed submission:
n, k = map(int, input().split())
snuke = [1 for i in range(n)]
for _ in range(k):
	d = int(input())
	a = list(map(int, input().split()))
	for i in a:
		snuke[i -1] = 0
		
print(sum(snuke))
Buggy python submission (verdict: Runtime Error):
S, W = int(input())
if S > W:
	print('safe')
else:
	print('unsafe')

Fixed submission:
s,w = map(int,input().split())
if s > w:
    print("safe")
else:
     print("unsafe")
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,iuput().split()))
a_sum = sum(a)
x = n - a_sum
if x >= 0:
    print(x)
else:
    print(-1)

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

c = list(map(int,input().split()))
c_sum = sum(c)

day_count = n-c_sum

if day_count>=0:
  print(day_count)
else:
  print(-1)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,iuput().split()))
x = n - sum(a)
if x >= 0:
    print(x)
else:
    print(-1)

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

c = list(map(int,input().split()))
c_sum = sum(c)

day_count = n-c_sum

if day_count>=0:
  print(day_count)
else:
  print(-1)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,iuput().split()))
x = n - sum(a)
if x >= 0:
    print(x)
else:
    print("-1")

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

c = list(map(int,input().split()))
c_sum = sum(c)

day_count = n-c_sum

if day_count>=0:
  print(day_count)
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
print(n * (n-1) // 2 + m * (m-1) // 2)

Fixed submission:
n, m = map(int, input().split())
print(n * (n - 1) // 2 + m * (m -1) // 2)