Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]

from collections import Counter
from math import factorial

c = Counter(s)
keys, values = zip(*c.most_common())
#print(keys)
#print(values)
ans = 0
n = 0
for i in range(len(values)):
    if values[i] > 1:
        n = values[i]
        ans += factorial(n) / factorial(2) / factorial(n - 2)
        
print(int(ans))

Fixed submission:
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]

from collections import Counter

c = Counter(s)
keys, values = zip(*c.most_common())
#print(keys)
#print(values)
ans = 0
n = 0
for i in range(len(values)):
    if values[i] > 1:
        n = values[i]
        ans += n*(n-1)//2
        
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]

from collections import Counter
from math import factorial

c = Counter(s)
keys, values = zip(*c.most_common())
#print(keys)
#print(values)
ans = 0
n = 0
for i in range(len(values)):
    if values[i] != 1:
        n = values[i]
        ans += factorial(n) / factorial(2) / factorial(n - 2)
        
print(int(ans))

Fixed submission:
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]

from collections import Counter

c = Counter(s)
keys, values = zip(*c.most_common())
#print(keys)
#print(values)
ans = 0
n = 0
for i in range(len(values)):
    if values[i] > 1:
        n = values[i]
        ans += n*(n-1)//2
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
MOD = 10**9+7
dp = [[0]*(14) for i in range(100010)]
dp[0][0] = 1

for i in range(N):
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])
        
    for j in range(10):
        if c != -1 and c != j:
            continue
        else:
            for k in range(13):
                dp[i+1][(k*10+j)%13] += dp[i][k]
        
    for j in range(13):
        dp[i+1][j] %= MOD
        
print(dp[N][5])

Fixed submission:
S = input()
N = len(S)
MOD = 10**9+7
dp = [[0]*(14) for i in range(100010)]
dp[0][0] = 1

for i in range(N):
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])
        
    for j in range(10):
        if c != -1 and c != j:
            continue
        else:
            for k in range(13):
                dp[i+1][(k*10+j)%13] += dp[i][k]
        
    for j in range(13):
        dp[i+1][j] %= MOD
        
print(dp[N][5])
Buggy python submission (verdict: Runtime Error):
N,D = list(map(int,input().split()))
human = 1
hani = 2*D+1
while hani < N:
    hani = hani + (2*D+1)
    human +=1
    
print(human)


Fixed submission:
r = int(input())

print(3*r*r)

Buggy python submission (verdict: Runtime Error):
N,D = list(map(int,input().split()))
human = 1
hani = 2*D+1
haniwhile hani < N:
    hani = hani + (2*D+1)
    human +=1
    
print(human) = kanshi


Fixed submission:
r = int(input())

print(3*r*r)
Buggy python submission (verdict: Runtime Error):
N,D = list(map(int,input().split()))
human = 1
hani = 2*D+1
while hani < N:
    hani = hani + (2*D+1)
    human +=1
    
print(human) = kanshi


Fixed submission:
N,D = list(map(int,input().split()))
human = 1
hani = 2*D+1
while hani < N:
    hani = hani + (2*D+1)
    human +=1
    
print(human)

Buggy python submission (verdict: Runtime Error):
N,D = list(map(int,input().split()))
human = 1
hani = 2*D+1
haniwhile hani < N:
    hani = hani + (2*D+1)
    human +=1
    
print(human) = kanshi


Fixed submission:
N,D = list(map(int,input().split()))
human = 1
hani = 2*D+1
while hani < N:
    hani = hani + (2*D+1)
    human +=1
    
print(human)

Buggy python submission (verdict: Runtime Error):
N,D = list(map(int,input().split()))
human = 1
kanshi = 2*D+1
haniwhile hani < N:
    hani = hani + kanshi
    human +=1
    
print(human) = kanshi


Fixed submission:
N,D = list(map(int,input().split()))
human = 1
hani = 2*D+1
while hani < N:
    hani = hani + (2*D+1)
    human +=1
    
print(human)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for i in range(N)]

for i in range(N):
    a = A.pop(i)
    print(max(A))
    A.insert(i,a)

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]

Asort = sorted(A,reverse=True)
first = max(Asort)
second = max(Asort[1:N])

for i in range(N):
    if A[i] != first:
        print(max(first,A[i]))
    else:
        print(second)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for i in range(N)]

for i in range(N):
    for j in range(N):
        A_list[j] = A[j]
    
    A_list[i] = 0
    print(max(A_list))

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]

Asort = sorted(A,reverse=True)
first = max(Asort)
second = max(Asort[1:N])

for i in range(N):
    if A[i] != first:
        print(max(first,A[i]))
    else:
        print(second)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for i in range(N)]

for i in range(N):
    for j in range(N):
        A_list[j] = A[j]
    
    A_list[i] = 0
    print(max(A_list))

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]

Asort = sorted(A,reverse=True)
first = max(Asort)
second = max(Asort[1:N])

for i in range(N):
    if A[i] != first:
        print(max(first,A[i]))
    else:
        print(second)
Buggy python submission (verdict: Time Limit Exceeded):
L,R = list(map(int,input().split()))

minimum = 2020

for i in range(L,R):
    for j in range(i+1,R+1):
        mod = (i*j)%2019
        if minimum > mod:
            minimum = mod
print(minimum)

Fixed submission:
L,R=map(int,input().split())
if (R-L)>=673:
  print(0)
else:
  ans=2019
  for i in range(L,R):
    for j in range(i+1,R+1):
      ans=min(ans,(i*j)%2019)
  print(ans)
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

A,B,C,D = list(map(int,input().split()))
lcm = C*D/math.gcd(C,D)
a = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)
b = (B) - ((B)//C + (B)//D - (B)//lcm)
print(int(b-a))

Fixed submission:
from fractions import gcd

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

lcm = C*D/gcd(C,D)

a = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//int(lcm))
b = (B) - ((B)//C + (B)//D - (B)//int(lcm))
print(int(b-a))

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

 
lcm = C*D/math.gcd(C,D)
a = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)
b = (B) - ((B)//C + (B)//D - (B)//lcm)
print(int(b-a))

Fixed submission:
from fractions import gcd

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

lcm = C*D/gcd(C,D)

a = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//int(lcm))
b = (B) - ((B)//C + (B)//D - (B)//int(lcm))
print(int(b-a))

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

lcm = C*D/math.gcd(C,D)
a = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)
b = (B) - ((B)//C + (B)//D - (B)//lcm)
print(int(b-a))

Fixed submission:
from fractions import gcd

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

lcm = C*D/gcd(C,D)

a = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//int(lcm))
b = (B) - ((B)//C + (B)//D - (B)//int(lcm))
print(int(b-a))
Buggy python submission (verdict: Runtime Error):
N = int(input())
AB = [list(map(int,input().split())) for i in range(N)]

sort_AB = sorted(AB, key= lambda x: x[1])
ans = 'Yes'
tmp = 0

for i in range(N):
    tmp += sortedAB[i][0]
    if tmp > sortedAB[i][1]:
        ans = 'No'
        break
        
print(ans)

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

sortedAB = sorted(AB, key= lambda x: x[1])

import sys
work = 0

for i in range(N):
    work += sortedAB[i][0]
    if work > sortedAB[i][1]:
        print('No')
        sys.exit()
        
print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split())
S = [input() for i in range(H)]

U = [[0]*W for i in range(H)]
D = [[0]*W for i in range(H)]
R = [[0]*W for i in range(H)]
L = [[0]*W for i in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            U[i][j] = 0
        elif i == 0 and S[i][j] == '.':
            U[i][j] = 1
        else:
            U[i][j] = U[i-1][j] + 1
            
    for j in range(W):
        if S[i][j] == '#':
            L[i][j] = 0
        elif j == 0 and S[i][j] == '.':
            L[i][j] = 1
        else:
            L[i][j] = L[i][j-1] + 1
            
for i in range(H-1,-1,-1):
    for j in range(W-1,-1,-1):
        if S[i][j] == '#':
            D[i][j] = 0
        elif i == H-1 and S[i][j] == '.':
            D[i][j] = 1
        else:
            D[i][j] = D[i+1][j] + 1
            
    for j in range(W-1,-1,-1):
        if S[i][j] == '#':
            R[i][j] = 0
        elif j == W-1 and S[i][j] == '.':
            R[i][j] = 1
        else:
            R[i][j] = R[i][j+1] + 1
            
ans = 0 

for i in range(H):
    for j in range(W):
        ans = max(ans,U[i][j]+R[i][j]+D[i][j]+L[i][j]-3)        
print(ans)    

Fixed submission:
H,W = map(int,input().split())
S = [input() for i in range(H)]

U = [[0]*W for i in range(H)]
D = [[0]*W for i in range(H)]
R = [[0]*W for i in range(H)]
L = [[0]*W for i in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            U[i][j] = 0
        elif i == 0 and S[i][j] == '.':
            U[i][j] = 1
        else:
            U[i][j] = U[i-1][j] + 1
            
    for j in range(W):
        if S[i][j] == '#':
            L[i][j] = 0
        elif j == 0 and S[i][j] == '.':
            L[i][j] = 1
        else:
            L[i][j] = L[i][j-1] + 1
            
for i in range(H-1,-1,-1):
    for j in range(W-1,-1,-1):
        if S[i][j] == '#':
            D[i][j] = 0
        elif i == H-1 and S[i][j] == '.':
            D[i][j] = 1
        else:
            D[i][j] = D[i+1][j] + 1
            
    for j in range(W-1,-1,-1):
        if S[i][j] == '#':
            R[i][j] = 0
        elif j == W-1 and S[i][j] == '.':
            R[i][j] = 1
        else:
            R[i][j] = R[i][j+1] + 1
            
ans = 0 

for i in range(H):
    for j in range(W):
        ans = max(ans,U[i][j]+R[i][j]+D[i][j]+L[i][j]-3)        
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

L = []
R = []

for i in range(M):
    inp = input().split()
    L.append(inp[0])
    R.append(inp[1])
    
if max(L) <= min(R):
    print(min(R)-max(L)+1)
else:
    print(0)

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

L = []
R = []

for i in range(M):
    inp = input().split()
    L.append(int(inp[0]))
    R.append(int(inp[1]))
    
if max(L) <= min(R):
    print(min(R)-max(L)+1)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for i in range(M)]

temp = []
for i in range(M):
    temp += [BC[i][1]]*BC[i][0]
    
A += temp

A.sort(reverse = True)

print(sum(A[:N]))

Fixed submission:
from operator import itemgetter

N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = []
for i in range(M):
    B,C = map(int,input().split())
    BC.append([B,C])

BC.sort(key = itemgetter(1),reverse=True)

change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break
A += change
A.sort(reverse=True)
answer = sum(A[:N])
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for i in range(M)]

B = []
C = []

for i in range(M):
    B.append(BC[i][0])
    C.append(BC[i][1])
    
for i in range(M):
    A.sort()
    card = 0
    for j in range(N):
        if A[j] < C[i]:
            A[j] = C[i]
            card += 1
        if card == B[i]:
            break
            
print(sum(A))

Fixed submission:
from operator import itemgetter

N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = []
for i in range(M):
    B,C = map(int,input().split())
    BC.append([B,C])

BC.sort(key = itemgetter(1),reverse=True)

change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break
A += change
A.sort(reverse=True)
answer = sum(A[:N])
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N = map(int,input().split())

ans = 0

for i in range(N//R + 1):
    for j in range(N//G + 1):
        if (N - i*R - j*G)%B == 0 and N - i*R - j*G >= 0:
            ans += 1
            
print(ans)

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

ans = 0

for i in range(N//R + 1):
    for j in range(N//G + 1):
        if (N - i*R - j*G)%B == 0 and N - i*R - j*G >= 0:
            ans += 1
            
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[21]:


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


# In[22]:


maxans = 0
for j in range(N):
    Anew = []
    for i in range(N):
        Anew.append(A[i])
    Anew.pop(j)    
    ans = Anew[0]
    for i in range(1,N-1):
        ans = fractions.gcd(ans, Anew[i]) 
    if ans > maxans:
        maxans = ans
print(maxans)



Fixed submission:
import fractions
N = int(input())
A = list(map(int, input().split()))

L = [0]
R = [0]

for i in range(N):
    L.append(fractions.gcd(L[i],A[i]))
    R.append(fractions.gcd(R[i],A[N-i-1]))
R.reverse()

ans = 0

for i in range(N):
    ans = max(ans,fractions.gcd(L[i],R[i+1]))
    
print(ans)
Buggy python submission (verdict: Runtime Error):
antenna = [int(input()) for i in range(5)]
k = int(input())

if max(antenna) - min(antenna) =< k:
    print('Yay!')
else:
    print(':(')

Fixed submission:
antenna = [int(input()) for i in range(5)]
k = int(input())

if max(antenna) - min(antenna) <= k:
    print('Yay!')
else:
    print(':(')
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()

for i in range(Q):
    l,r = map(int,input().split())
    ans = S[l-1:r].count('AC')
    print(ans)

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

csum = [0,0]
for i in range(1, N):
    if S[i-1] + S[i] == 'AC':
        csum.append(csum[i-1] + 1)
    else:
        csum.append(csum[i])
        
#文字番号に合わせた形になっている
for i in range(Q):
    l, r = map(int, input().split())
    print(csum[r]-csum[l])
Buggy python submission (verdict: Runtime Error):
S = input()

S = list(S)

from collections import Counter
c = Counter(S)
d = c.most_common()

print(2*min(d[0][1],d[1][1]))

Fixed submission:
S = input()
print(2 * min(S.count('1'),S.count('0')))
Buggy python submission (verdict: Runtime Error):
N = int(input())
h = list(map(int,input().split()))

dp = [0 for i in range(1010)]

for i in range(N-1):
    if i > 0:
        dp[i+1] = min(dp[i-1]+abs(h[i+1]-h[i-1]),dp[i]+abs(h[i+1]-h[i]))
    else:
        dp[i+1] = dp[i] + abs(h[i+1]-h[i])
        
print(dp[N-1])

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

cost1 = 0
cost2 = 0
cost = [0]
cost.append(abs(h[0]-h[1]))
    
for flog in range(2,len(h)):
    cost1 = cost[flog-2] + abs(h[flog] - h[flog-2])
    cost2 = cost[flog-1] + abs(h[flog] - h[flog-1])
    cost.append(min(cost1,cost2))
    #print(cost)
    
print(cost[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = tuple(map(int,input().split()))

dp = [10**9+7]*N
dp[0] = 0

# 足場 i までにたどり着くまでに最小のコスト
for i in range(1,N):
    #for j in range(max(i-K,0),i)はジャンプして位置iまで行ける足場の範囲
    for j in range(max(i-K,0),i):
        dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]))

print(dp[-1])

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

dp = [0]*N

#iは知りたいdp[i]
for i in range(1,N):
    #for j in range(max(i-K,0),i)はジャンプできる段数
    dp[i] = min(dp[j]+abs(h[j]-h[i]) for j in range(max(i-K,0),i))
print(dp[N-1])

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

dp = [10**9+7]*N
dp[0] = 0

# 足場 i までにたどり着くまでに最小のコスト
for i in range(1,N):
    #for j in range(max(i-K,0),i)はジャンプして位置iまで行ける足場の範囲
    for j in range(max(i-K,0),i):
        dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]))

print(dp[-1])

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

dp = [0]*N

#iは知りたいdp[i]
for i in range(1,N):
    #for j in range(max(i-K,0),i)はジャンプできる段数
    dp[i] = min(dp[j]+abs(h[j]-h[i]) for j in range(max(i-K,0),i))
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*N

#iは知りたいdp[i]
for i in range(1,N):
    #for j in range(max(i-K,0),i)はジャンプできる段数
    dp[i] = min(dp[j]+abs(h[j]-h[i]) for j in range(max(i-K,0),i))
print(dp[N-1])

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

dp = [0]*N

#iは知りたいdp[i]
for i in range(1,N):
    #for j in range(max(i-K,0),i)はジャンプできる段数
    dp[i] = min(dp[j]+abs(h[j]-h[i]) for j in range(max(i-K,0),i))
print(dp[N-1])

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

dp = [0]*N

#iは知りたいdp
for i in range(1,N):
    #for j in range(max(i-K,0),i)はジャンプできる段数
    dp[i] = min(dp[j]+abs(h[j]-h[i]) for j in range(max(i-K,0),i))
print(dp[-1])

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

dp = [0]*N

#iは知りたいdp[i]
for i in range(1,N):
    #for j in range(max(i-K,0),i)はジャンプできる段数
    dp[i] = min(dp[j]+abs(h[j]-h[i]) for j in range(max(i-K,0),i))
print(dp[N-1])

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

dp = [0 for i in range(N)]

#iは知りたいdp
for i in range(1,N):
    #for j in range(max(i-K,0),i)はジャンプできる段数
    dp[i] = min(dp[j]+abs(h[j]-h[i]) for j in range(max(i-K,0),i))
print(dp[-1])

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

dp = [0]*N

#iは知りたいdp[i]
for i in range(1,N):
    #for j in range(max(i-K,0),i)はジャンプできる段数
    dp[i] = min(dp[j]+abs(h[j]-h[i]) for j in range(max(i-K,0),i))
print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
w,v = [0]*N,[0]*N
for i in range(N):
    w[i],v[i] = map(int,input().split())
    
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if j >= w[i]:
            dp[i+1][j] = max(dp[i][j-w[i]]+v[i],dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]
            
print(dp[N][W])

Fixed submission:
N,W = map(int,input().split())
w,v = [0]*N,[0]*N
for i in range(N):
    w[i],v[i] = map(int,input().split())
    
dp = [[10**9+1]*(sum(v)+1) for i in range(N+1)]
dp[0][0] = 0

#v[i]を使うかどうか
for i in range(N):
    #価値がjのときの最小の重さ総量
    for j in range(sum(v)+1):
        if j >= v[i]:
            dp[i+1][j] = min(dp[i][j-v[i]]+w[i],dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]
            
ans = 0

for i in range(sum(v)+1):
    if dp[N][i] <= W:
        ans = max(ans,i)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 9)

n,m = map(int,input().split())
g = [[] for i in range(n)]

# xは始点、yは次点
for i in range(m):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    g[x].append(y)
    
dp = [-1]*n
 
def solve(i): # 始点iから行ける場所を探索
    # すでに計算されているなら、後の距離は計算できている
    if dp[i] != -1:
        return dp[i]
    # 初期は長さ0
    tmp = 0
    # 始点iから次点にDFS
    for j in g[i]:
        #今までの距離と比較
        tmp = max(tmp, dfs(j) + 1)
    # dp[i]はiからスタートして最長距離が記録される
    # 空のリスト（もう次点が存在しない）にたどり着いたらDFS終わり
    dp[i] = tmp
    return tmp
 
for i in range(n):
    solve(i)

print(max(dp))

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

n,m = map(int,input().split())
g = [[] for i in range(n)]
 
for i in range(m):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    g[x].append(y)
dp = [-1]*n
 
def dfs(i):
    #すでに計算されているなら
    if dp[i] != -1:
        return dp[i]
    #初期は長さ0
    tmp = 0
    #iからスタートしてつながっているところにDFS
    for j in g[i]:
        #今までの距離と比較
        tmp = max(tmp, dfs(j) + 1)
    #dp[i]はiからスタートして最長距離が記録される
    #空のリストにたどり着いたらDFS終わり
    dp[i] = tmp
    return tmp
 
for i in range(n):
    dfs(i)

print(max(dp))

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
g = [[] for i in range(n)]
 
for i in range(m):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    g[x].append(y)
    
dp = [-1]*n
 
def dfs(i):
    #すでに計算されているなら
    if dp[i] != -1:
        return dp[i]
    #初期は長さ0
    tmp = 0
    #iからスタートしてつながっているところにDFS
    for j in g[i]:
        #今までの距離と比較
        tmp = max(tmp, dfs(j) + 1)
    #dp[i]はiからスタートして最長距離が記録される
    #空のリストにたどり着いたらDFS終わり
    dp[i] = tmp
    return tmp
 
for i in range(n):
    dfs(i)

print(max(dp))

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

n,m = map(int,input().split())
g = [[] for i in range(n)]
 
for i in range(m):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    g[x].append(y)
dp = [-1]*n
 
def dfs(i):
    #すでに計算されているなら
    if dp[i] != -1:
        return dp[i]
    #初期は長さ0
    tmp = 0
    #iからスタートしてつながっているところにDFS
    for j in g[i]:
        #今までの距離と比較
        tmp = max(tmp, dfs(j) + 1)
    #dp[i]はiからスタートして最長距離が記録される
    #空のリストにたどり着いたらDFS終わり
    dp[i] = tmp
    return tmp
 
for i in range(n):
    dfs(i)

print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
p = list(map(float,input().split()))

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

dp[0][0] = 1-p[0]
dp[0][1] = p[0]

for i in range(1,N):
    dp[i][0] = (1-p[i])*dp[i-1][0]
    for j in range(1,i+2):
        dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i])
        
print(sum(dp[-1][(N+1)//2:]))

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

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

dp[0][0] = 1-p[0]
dp[0][1] = p[0]

for i in range(1,N):
    dp[i][0] = (1-p[i])*dp[i-1][0]
    for j in range(1,i+2):
        dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i])
        
print(sum(dp[-1][(N+1)//2:]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
v = list(map(int,input().split()))

count = 0

if max(v) == min(v):
    print(int(n/2))
else:
    for i in range(int(n/2)):
        if v[0] != v[j+2]:
            count += 1
        if v[1] != v[j+3]:
            count =+ 1
        j = j+2
    print(count)    

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

v1 = []
v2 = []

j=0
for i in range(int(n/2)):
    v1.append(v[j])
    j+=2
    
j=0
for i in range(int(n/2)):
    v2.append(v[j+1])
    j+=2

import collections

v1n = collections.Counter(v1)
v2n = collections.Counter(v2)

if v1n.most_common()[0][0] != v2n.most_common()[0][0]:
    print(n - v1n.most_common()[0][1] - v2n.most_common()[0][1])
else:
    if len(v1n) == 1 and len(v2n) == 1:
        print(int(n/2))
    else:
        xxx=(len(v1)-v1n.most_common()[0][1])+(len(v2)-v2n.most_common()[1][1])
        yyy=(len(v1)-v1n.most_common()[1][1])+(len(v2)-v2n.most_common()[0][1])
        print(min(xxx,yyy))
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())

a = [input() for i in range(H)]

y = [False]*H
x = [False]*H

for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            y[i] == True
            x[j] == True
            
for i in range(H):
    if y[i] == True:
        for j in range(W):
            if x[j] == True:
                print(a[i][j],end="")
        print()

Fixed submission:
H,W = map(int,input().split())
a = [input() for i in range(H)]

y = [False]*H
x = [False]*W

for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            y[i] = True
            x[j] = True
            
for i in range(H):
    if y[i] == True:
        for j in range(W):
            if x[j] == True:
                print(a[i][j],end="")
        print()
Buggy python submission (verdict: Runtime Error):
R = int(input())

if R < 1200:
    print("ABC"):
elif 1200 <= R and R < 2800:
    print("ARC")
else:
    print("AGC")

Fixed submission:
R = int(input())

if R < 1200:
    print("ABC")
elif 1200 <= R and R < 2800:
    print("ARC")
else:
    print("AGC")