Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = [int(i) for i in input().split()]

dp = [-1 for i in range(n+5)]
import sys
sys.setrecursionlimit(100000)
def brute(i):
    if i>=n-1:
        return 0
    if dp[i]!=-1:
        return dp[i]
    ans = 10**10
    if i+1 < n:
        ans = min(ans, abs(A[i] - A[i+1]) + brute(i+1))
    if i+2 < n:
        ans = min(ans, abs(A[i] - A[i+2]) + brute(i+2))
    dp[i] = ans
    return ans

print(brute(0))


Fixed submission:
n = int(input())
A = [int(i) for i in input().split()]

dp = [-1 for i in range(n+50)]
import sys
sys.setrecursionlimit(1000000)
def brute(i):
    if i>=n-1:
        return 0
    if dp[i]!=-1:
        return dp[i]
    ans = 10**10
    if i+1 < n:
        ans = min(ans, abs(A[i] - A[i+1]) + brute(i+1))
    if i+2 < n:
        ans = min(ans, abs(A[i] - A[i+2]) + brute(i+2))
    dp[i] = ans
    return ans

print(brute(0))

Buggy python submission (verdict: Runtime Error):
n = int(input())
A = [int(i) for i in input().split()]

dp = [-1 for i in range(n+1)]
import sys
sys.setrecursionlimit(10000)
def brute(i):
    if i>=n-1:
        return 0
    if dp[i]!=-1:
        return dp[i]
    ans = 10**10
    if i+1 < n:
        ans = min(ans, abs(A[i] - A[i+1]) + brute(i+1))
    if i+2 < n:
        ans = min(ans, abs(A[i] - A[i+2]) + brute(i+2))
    dp[i] = ans
    return ans

print(brute(0))


Fixed submission:
n = int(input())
A = [int(i) for i in input().split()]

dp = [-1 for i in range(n+50)]
import sys
sys.setrecursionlimit(1000000)
def brute(i):
    if i>=n-1:
        return 0
    if dp[i]!=-1:
        return dp[i]
    ans = 10**10
    if i+1 < n:
        ans = min(ans, abs(A[i] - A[i+1]) + brute(i+1))
    if i+2 < n:
        ans = min(ans, abs(A[i] - A[i+2]) + brute(i+2))
    dp[i] = ans
    return ans

print(brute(0))

Buggy python submission (verdict: Runtime Error):
n = int(input())
A = [int(i) for i in input().split()]

dp = [-1 for i in range(n+1)]

def brute(i):
    if i>=n-1:
        return 0
    if dp[i]!=-1:
        return dp[i]
    ans = 10**10
    if i+1 < n:
        ans = min(ans, abs(A[i] - A[i+1]) + brute(i+1))
    if i+2 < n:
        ans = min(ans, abs(A[i] - A[i+2]) + brute(i+2))
    dp[i] = ans
    return ans

print(brute(0))


Fixed submission:
n = int(input())
A = [int(i) for i in input().split()]

dp = [-1 for i in range(n+50)]
import sys
sys.setrecursionlimit(1000000)
def brute(i):
    if i>=n-1:
        return 0
    if dp[i]!=-1:
        return dp[i]
    ans = 10**10
    if i+1 < n:
        ans = min(ans, abs(A[i] - A[i+1]) + brute(i+1))
    if i+2 < n:
        ans = min(ans, abs(A[i] - A[i+2]) + brute(i+2))
    dp[i] = ans
    return ans

print(brute(0))
Buggy python submission (verdict: Runtime Error):
n = int(input())
joy = []

for i in range(n):
    cur = [int(i) for i in input().split()]
    joy.append(cur)

dp = [[0 for i in range(n+5)] for j in range(3)]
import sys
sys.setrecursionlimit(100000)
def brute(curday, prvmove):
    if curday>=n:
        return 0
    if dp[prvmove][curday]!=0:
        return dp[prvmove][curday]
    ans = 0
    
    for i in range(3):
        if prvmove == i:
            continue
        ans = max(ans, brute(curday+1, i) + joy[curday][i])

    #print('with', daysleft)
    #print('returning', ans)
    dp[prvmove][curday] = ans
    return ans

ans = 0

for i in range(3):
    ans = max(ans, brute(0, i))
print(ans)


Fixed submission:
n = int(input())
joy = []

for i in range(n):
    cur = [int(i) for i in input().split()]
    joy.append(cur)

dp = [[0 for i in range(n+5)] for j in range(3)]
import sys
sys.setrecursionlimit(10000000)
def brute(curday, prvmove):
    if curday>=n:
        return 0
    if dp[prvmove][curday]!=0:
        return dp[prvmove][curday]
    ans = 0
    
    for i in range(3):
        if prvmove == i:
            continue
        ans = max(ans, brute(curday+1, i) + joy[curday][i])

    #print('with', daysleft)
    #print('returning', ans)
    dp[prvmove][curday] = ans
    return ans

ans = 0

for i in range(3):
    ans = max(ans, brute(0, i))
print(ans)
Buggy python submission (verdict: Runtime Error):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
import numpy as np
[N,K]=i2()
a=i2()
mod = 10**9+7
comb = np.zeros((N+1,N+1),dtype=np.int64)
comb[:,0] = 1
for i in range(1,N+1):
    comb[i, 1:i+1] = comb[i-1, :i] + comb[i-1, 1:i+1]
    comb[i] %= mod
ans=0
a.sort()
for i in range(N):
 if i>=K-1:
   ans+=a[i]*comb[i][K-1]
 if i<=N-K+1:
   ans-=a[i]*comb[N-i-1][K-1]
 ans%=mod
print(ans)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

[N,K]=i2()
a=i2()
mod = 10**9+7
c=[0 for i in range(N+1)]
ci=[0 for i in range(N+1)]
c[0]=1
for i in range(1,N+1):
 c[i]=c[i-1]*i
 c[i]%=mod
def bp(x,n):
        r=1
        while(n):
           if n%2:
              r=r*x%mod
           x=x*x%mod
           n>>=1
        return r
for i in range(N+1):
  ci[i]=bp(c[i],10**9+5)
ans=0
a.sort()
for i in range(N):
 if i>=K-1:
   ans+=a[i]*((c[i]*ci[i-K+1]*ci[K-1])%mod)
 if i<=N-K:
   ans-=a[i]*((c[N-i-1]*ci[N-i-1-K+1]*ci[K-1])%mod)
 ans%=mod
print(ans%mod)

Buggy python submission (verdict: Runtime Error):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
import numpy as np
[N,K]=i2()
a=i2()
mod = 10**9+7
comb = np.zeros((N+1,N+1),dtype=np.int64)
comb[:,0] = 1
for i in range(1,N+1):
    comb[i, 1:i+1] = comb[i-1, :i] + comb[i-1, 1:i+1]
    comb[i] %= mod
ans=0
a.sort()
for i in range(N):
 if i>=K-1:
   ans+=a[i]*comb[i][K-1]
 if i<=N-K+1:
   ans-=a[i]*comb[N-i-1][K-1]
 ans%=mod
print(ans)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

[N,K]=i2()
a=i2()
mod = 10**9+7
c=[0 for i in range(N+1)]
ci=[0 for i in range(N+1)]
c[0]=1
for i in range(1,N+1):
 c[i]=c[i-1]*i
 c[i]%=mod
def bp(x,n):
        r=1
        while(n):
           if n%2:
              r=r*x%mod
           x=x*x%mod
           n>>=1
        return r
for i in range(N+1):
  ci[i]=bp(c[i],10**9+5)
ans=0
a.sort()
for i in range(N):
 if i>=K-1:
   ans+=a[i]*((c[i]*ci[i-K+1]*ci[K-1])%mod)
 if i<=N-K:
   ans-=a[i]*((c[N-i-1]*ci[N-i-1-K+1]*ci[K-1])%mod)
 ans%=mod
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
import sys
sys.setrecursionlimit(10**6)
n=i1()
s=i2()
m=10**9+1
import heapq
import bisect
s.sort()
x=[s[-1]]
s[-1]=m
a="Yes"
for i in range(n):
 y=[]
 for j in range(1<<i):
   s.sort()
   z=bisect.bisect_left(s,x[j])-1
   if z<0:
     a="No"
   y.append(s[z])
   s[z]=m
 x+=y
 x.sort(reverse=True)
print(a)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
s=i2()
m=10**9+1
s.sort(reverse=True)
x=[s[0]]
s[0]=m
a="Yes"
for i in range(n):
 y=[]
 k=0
 for j in range(len(s)):
   if k>=len(x):
      break
   if s[j]<x[k]:
     y.append(s[j])
     s[j]=m
     k+=1
 x+=y
 x.sort(reverse=True)
if k==(1<<(n-1)):
   print("Yes")
else:
   print("No")

Buggy python submission (verdict: Time Limit Exceeded):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
import sys
sys.setrecursionlimit(10**6)
n=i1()
s=i2()
import heapq
import bisect
s.sort()
heapq.heapify(s)
x=[s[-1]]
s.pop(-1)
a="Yes"
for i in range(n):
 y=[]
 for j in range(1<<i):
   z=bisect.bisect_left(s,x[j])-1
   if z<0:
     a="No"
   y.append(s[z])
   s.pop(z)
 x+=y
 x.sort(reverse=True)
print(a)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
s=i2()
m=10**9+1
s.sort(reverse=True)
x=[s[0]]
s[0]=m
a="Yes"
for i in range(n):
 y=[]
 k=0
 for j in range(len(s)):
   if k>=len(x):
      break
   if s[j]<x[k]:
     y.append(s[j])
     s[j]=m
     k+=1
 x+=y
 x.sort(reverse=True)
if k==(1<<(n-1)):
   print("Yes")
else:
   print("No")
Buggy python submission (verdict: Time Limit Exceeded):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
e=[[] for i in range(3*10**5+10)]

[n,m]=i2()
for i in range(m):
 [u,v]=i2()
 u-=1
 v-=1
 e[3*u].append(3*v+1)
 e[3*u+1].append(3*v+2)
 e[3*u+2].append(3*v)
 
[s,t]=i2()
s-=1
t-=1
d=[-1 for i in range(3*10**5+10)]
def bfs(v):
   d[v]=0
   q=[v]
   while len(q):
    v=q.pop(0)
    for i in e[v]:
      if d[i]<0:
         d[i]=d[v]+1
         q.append(i)
   if d[3*t]>-1:
     return d[3*t]//3
   return d[3*t]  
print(bfs(3*s))

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
e=[[] for i in range(3*10**5+10)]

[n,m]=i2()
for i in range(m):
 [u,v]=i2()
 u-=1
 v-=1
 e[3*u].append(3*v+1)
 e[3*u+1].append(3*v+2)
 e[3*u+2].append(3*v)
 
[s,t]=i2()
s-=1
t-=1
from collections import deque
d=[-1 for i in range(3*10**5+10)]
def bfs(v):
   d[v]=0
   q=deque([v])
   while len(q):
    v=q.popleft()
    for i in e[v]:
      if d[i]<0:
         d[i]=d[v]+1
         q.append(i)
   if d[3*t]>-1:
     return d[3*t]//3
   return d[3*t]  
print(bfs(3*s))

Buggy python submission (verdict: Time Limit Exceeded):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
e=[[] for i in range(10**5)]
ee=[[] for i in range(10**5)]
[n,m]=i2()
for i in range(m):
 [u,v]=i2()
 e[u-1].append(v-1)
 
[s,t]=i2()

d=[-1 for i in range(n)]
import sys
sys.setrecursionlimit(10**6)
d=[-1 for i in range(n)]
def dfs(v,u,uv):
   d[v]=u
   if u==3:
      ee[uv].append(v)
      return 0
   for i in e[v]:
         dfs(i,u+1,uv)
for i in range(n):
 d=[-1 for j in range(n)]
 dfs(i,0,i)
for i in range(n):
   ee[i]=list(set(ee[i]))

d=[-1 for i in range(n)]
def bfs(v):
   d[v]=0
   q=[v]
   while len(q):
    v=q.pop(0)
    for i in ee[v]:
      if d[i]<0:
         d[i]=d[v]+1
         q.append(i)
   print(d[t-1])
bfs(s-1)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
e=[[] for i in range(3*10**5+10)]

[n,m]=i2()
for i in range(m):
 [u,v]=i2()
 u-=1
 v-=1
 e[3*u].append(3*v+1)
 e[3*u+1].append(3*v+2)
 e[3*u+2].append(3*v)
 
[s,t]=i2()
s-=1
t-=1
from collections import deque
d=[-1 for i in range(3*10**5+10)]
def bfs(v):
   d[v]=0
   q=deque([v])
   while len(q):
    v=q.popleft()
    for i in e[v]:
      if d[i]<0:
         d[i]=d[v]+1
         q.append(i)
   if d[3*t]>-1:
     return d[3*t]//3
   return d[3*t]  
print(bfs(3*s))
Buggy python submission (verdict: Time Limit Exceeded):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

L=input()
a=0
x=10**9+7
c=len(L)
y=0
for i in range(c):
 if L[i]=="1":
  a+=(3**(c-1-i)*2**y)%x
  a%=x
  y+=1
print((a+2**y)%x)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

L=input()
a=0
x=10**9+7
def bp(a,n):
        r=1
        while(n):
           if n%2:
              r=r*a%x
           a=a*a%x
           n>>=1
        return r
c=len(L)
y=0
for i in range(c):
 if L[i]=="1":
  a+=(bp(3,c-1-i)*bp(2,y))%x
  a%=x
  y+=1
print((a+2**y)%x)
Buggy python submission (verdict: Time Limit Exceeded):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
a=i2()
c=[0 for i in range(n)]
b=sum(a)

for i in range(n):
 if i: c[i]+=c[i-1]
 c[i]+=a[i]
f=float("inf")
import bisect
e=[]
b=a[0]
d=c[n-1]-c[0]
for i in range(1,n-2):
 b+=a[i]
 d-=a[i]
 x=bisect.bisect_left(c[:i+1],b/2)
 
 if abs(c[i]-2*c[x])>abs(c[i]-2*c[x-1]) and x>0:
   e.append(c[i]-c[x-1])
   e.append(c[x-1])
 else:
   e.append(c[i]-c[x])
   e.append(c[x])
 y=bisect.bisect_left(c[i+1:],d/2+c[i])+i+1
 if abs(c[n-1]-c[y]-(c[y]-c[i]))>abs(c[n-1]-c[y-1]-(c[y-1]-c[i])) and y>0:
   e.append(c[n-1]-c[y-1])
   e.append(c[y-1]-c[i])
 else:
   e.append(c[n-1]-c[y])
   e.append(c[y]-c[i])

 f=min(f,max(e)-min(e))
 e=[]
print(f)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
a=i2()
c=[0 for i in range(n)]


for i in range(n):
 if i: c[i]+=c[i-1]
 c[i]+=a[i]

l=0
r=2
f=float("inf")
for i in range(1,n-1):
 while abs(c[l]-(c[i]-c[l]))>abs(c[l+1]-(c[i]-c[l+1])):
   l+=1
 while abs(c[r]-c[i]-(c[n-1]-c[r]))>abs(c[r+1]-c[i]-(c[n-1]-c[r+1])):
   r+=1
 e=[c[l],c[i]-c[l],c[r]-c[i],c[n-1]-c[r]]
 f=min(f,max(e)-min(e))
print(f)
Buggy python submission (verdict: Runtime Error):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
k=i1()


x=list(range(1,10))

y=[]
z=[]
for i in range(1,15):
 for j in range(1,10):
  y.append((10**i*(j+1)-1)/(j+i*9))
  z.append(10**i*(j+1)-1)
for i in range(len(z)-1):
  s=z[i]+1
  x.append(z[i])
  while s/sum(list(map(int, list(str(s)))))<=y[i+1]:
        x.append(s)
        s+=1

for i in range(k):
  print(x[i])

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
x=[]
k=i1()
for s in range(1,10):
 x.append([s/sum(list(map(int, list(str(s))))),s])

for i in range(1,1000):
 for j in range(1,15):
   s=10**j*i+10**j-1
   x.append([s/sum(list(map(int, list(str(s))))),s])

y=sorted(x)
m=0
n=0
for i,j in y:
  if n>k-1:
     break
  if j>10**15:
     break
  if j>m:
     m=j
     print(j)
     n+=1
Buggy python submission (verdict: Runtime Error):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
p=[]
q=[0 for i in range(n)]
for i in range(n):   
 p.append(i1())
 q[p[-1]-1]=i
k=1
s=0
while n-1>j:
  if q[i+1]-q[i]>0:
     k+=1
  else:
     s=max(s,k)
     k=1
  j+=1
s=max(s,k)
print(n-s)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
p=[]
q=[0 for i in range(n)]
for i in range(n):   
 p.append(i1())
 q[p[-1]-1]=i
k=1
s=0
for i in range(n-1):
  if q[i+1]-q[i]>0:
     k+=1
  else:
     s=max(s,k)
     k=1
s=max(s,k)
print(n-s)

Buggy python submission (verdict: Time Limit Exceeded):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
p=[]
for i in range(n):   
 p.append(i1())

s=0
while p[0]!=1 or p[-1]!=n:
 j=0
 if p[0]==1 and p[-1]!=n:
   k=p[-1]
   s+=n-p[-1]
   while len(p)>j:
       if p[j]>k:
         p.pop(j)
         j-=1
       j+=1
   p=p+list(range(k+1,n+1))
 if p[0]!=1 and  p[-1]==n:
   k=p[0]
   s+=p[0]-1
   while len(p)>j:
       if p[j]<k:
          p.pop(j)
          j-=1
       j+=1
   p=list(range(1,k))+p
 if p[0]!=1 and  p[-1]!=n:

  if n-p[-1]>p[0]-1:
   k=p[0]
   s+=p[0]-1
   while len(p)>j:
       if p[j]<k:
          p.pop(j)
          j-=1
       j+=1
   p=list(range(1,k))+p
  else:
   k=p[-1]
   s+=n-p[-1]
   while len(p)>j:
       if p[j]>k:
         p.pop(j)
         j-=1
       j+=1
   p=p+list(range(k+1,n+1))
j=0

while n-1>j:
   if p[j]>p[j+1]:
     s+=1
     if p[j+1]-1<n-p[j]:
        p.insert(0,p[j+1])
        p.pop(j+2)
        j+=1
     else:
        p.append(p[j])
        p.pop(j)
   else:
        j+=1
print(s)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
p=[]
q=[0 for i in range(n)]
for i in range(n):   
 p.append(i1())
 q[p[-1]-1]=i
k=1
s=0
for i in range(n-1):
  if q[i+1]-q[i]>0:
     k+=1
  else:
     s=max(s,k)
     k=1
s=max(s,k)
print(n-s)
Buggy python submission (verdict: Runtime Error):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
q=i1()
import math
y=[]
for i in range(q):
 y.append(i2())

for a,b in y:
 x=a*b
 c=int(math.sqrt(x))
 if c**2==x:
    c-=1
 z=2*c
 if  (x//c)==c:
   z-=1
 if x%c==0 and (x//c-1)==c:
   z-=1
 if a<=c:
   z-=1
 if b<=c:
   z-=1
 print(z)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
q=i1()
import math
y=[]
for i in range(q):
 y.append(i2())

for a,b in y:
 x=a*b
 c=int(math.sqrt(x))
 if c**2==x:
    c-=1
 z=2*c
 if c>0 and (x//c)==c:
   z-=1
 if c>0 and x%c==0 and (x//c-1)==c:
   z-=1
 if a<=c:
   z-=1
 if b<=c:
   z-=1
 print(z)

Buggy python submission (verdict: Runtime Error):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
q=i1()
import math
for i in range(q):
 [a,b]=i2()
 x=a*b
 c=int(math.sqrt(x))
 if c**2==x:
    c-=1
 z=2*c
 if  (x//c)==c:
   z-=1
 if x%c==0 and (x//c-1)==c:
   z-=1
 if a<=c:
   z-=1
 if b<=c:
   z-=1
 print(z)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
q=i1()
import math
y=[]
for i in range(q):
 y.append(i2())

for a,b in y:
 x=a*b
 c=int(math.sqrt(x))
 if c**2==x:
    c-=1
 z=2*c
 if c>0 and (x//c)==c:
   z-=1
 if c>0 and x%c==0 and (x//c-1)==c:
   z-=1
 if a<=c:
   z-=1
 if b<=c:
   z-=1
 print(z)

Buggy python submission (verdict: Runtime Error):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
q=i1()
import math
for i in range(q):
 [a,b]=i2()
 x=a*b
 c=int(math.sqrt(x))
 if c**2==x:
    c-=1
 z=2*c
 if  (x//c)==c:
   z-=1
 if x%c==0 and (x//c-1)==c:
   z-=1
 if a<=c:
   z-=1
 if b<=c:
   z-=1
 print(z)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
q=i1()
import math
y=[]
for i in range(q):
 y.append(i2())

for a,b in y:
 x=a*b
 c=int(math.sqrt(x))
 if c**2==x:
    c-=1
 z=2*c
 if c>0 and (x//c)==c:
   z-=1
 if c>0 and x%c==0 and (x//c-1)==c:
   z-=1
 if a<=c:
   z-=1
 if b<=c:
   z-=1
 print(z)

Buggy python submission (verdict: Runtime Error):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
q=i1()
import math
for i in range(q):
 [a,b]=i2()
 x=a*b
 c=int(math.sqrt(x))
 if c**2==x:
    c-=1
 z=2*c
 if  int(x//c)==c:
   z-=1
 if x%c==0 and (int(x//c)-1)==c:
   z-=1
 if a<=c :
   z-=1
 if b<=c:
   z-=1
 print(z)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
q=i1()
import math
y=[]
for i in range(q):
 y.append(i2())

for a,b in y:
 x=a*b
 c=int(math.sqrt(x))
 if c**2==x:
    c-=1
 z=2*c
 if c>0 and (x//c)==c:
   z-=1
 if c>0 and x%c==0 and (x//c-1)==c:
   z-=1
 if a<=c:
   z-=1
 if b<=c:
   z-=1
 print(z)
Buggy python submission (verdict: Runtime Error):
def i2():
 return [int(i) for i in input().split()]

[n,h]=i2()
a=[]
for i in range(n):
 b=i2()
 a+=[[b[0],0],[b[1],1]]
a.sort()
a=a[::-1]
i=0
c=0
while a[i][1]==1　and h>0:
 h-=a[i][0]
 c+=1
 i+=1
c+=h//a[i][0]
if h%a[i][0]:c+=1
print(c)

Fixed submission:
def i2():
 return [int(i) for i in input().split()]

[n,h]=i2()
a=[]
for i in range(n):
 b=i2()
 a+=[[b[0],0],[b[1],1]]
a.sort()
a=a[::-1]
i=0
c=0
while a[i][1]==1 and h>0:
 h-=a[i][0]
 c+=1
 i+=1

if h>0:
 c+=h//a[i][0]
 if h%a[i][0]:c+=1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
s=input()
ss=s.replace("x","")
if ss!=ss[::-1]:
 print(-1)
else:
 e=[]
 for i in range(len(ss)):
  e.append(ss[i])
 j=0
 k=0
 d1=[]
 jj=0
 kk=0
 d2=[]
 for i in range(len(s)):
  if k<len(e) and s[i]==e[k] :
    d1.append(s[j:i])
    j=i+1
    k+=1
  if kk<len(e) and s[::-1][i]==e[kk] :
    d2.append(s[::-1][jj:i])
    jj=i+1
    kk+=1
 d1.append(s[j:])
 d2.append(s[::-1][jj:]) 
 dd=0  
 for i in range(len(d1)):
   dd+=abs(len(d1[i])-len(d2[i]))
 print(dd//2)


Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
s=input()
ss=s.replace("x","")
if ss!=ss[::-1]:
 print(-1)
else:
 e=[]
 for i in range(len(ss)):
  e.append(ss[i])
 j=0
 k=0
 d1=[]
 jj=0
 kk=0
 d2=[]
 sr=s[::-1]
 for i in range(len(s)):
  if k<len(e) and s[i]==e[k] :
    d1.append(s[j:i])
    j=i+1
    k+=1
  if kk<len(e) and sr[i]==e[kk] :
    d2.append(sr[jj:i])
    jj=i+1
    kk+=1
 d1.append(s[j:])
 d2.append(sr[jj:]) 
 dd=0  
 for i in range(len(d1)//2):
   dd+=abs(len(d1[i])-len(d2[i]))
 print(dd)
Buggy python submission (verdict: Time Limit Exceeded):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,k]=i2()
x=[]
y=[]
z=[]
for i in range(n):
 z.append(i2())
 x.append(z[-1][0])
 y.append(z[-1][1])
x.sort()
y.sort()
a=float("inf")
for i in range(n):
 for j in range(i,n):
  for kk in range(n):
    for l in range(kk,n):
      if len(list(filter(lambda xx:x[i]<=xx[0]<=x[j] and y[kk]<=xx[1]<=y[l] , z)))==k:
       a=min(a,(x[j]-x[i])*(y[l]-y[kk]))  
print(a)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,k]=i2()
x=[]
y=[]
zz=[]
for i in range(n):
 z=i2()
 x.append([z[0],i])
 y.append([z[1],i])
 zz.append(z)
x.sort()
y.sort()
xx=[i[1] for i in x]
yy=[i[1] for i in y]
a=float("inf")
for i in range(n):
 for j in range(i,n):
  for kk in range(n):
   for l in range(kk,n):
     if len(set(xx[i:j+1])&set(yy[kk:l+1]))==k:
         a=min(a,(zz[xx[j]][0]-zz[xx[i]][0])*(zz[yy[l]][1]-zz[yy[kk]][1]))
print(a)
Buggy python submission (verdict: Runtime Error):
n=i1()
x=[]
for i in range(n):
    x.append(i2())
x.sort()
print(x[-1][0]+x[-1][1])

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

n=i1()
x=[]
for i in range(n):
    x.append(i2())
x.sort()
print(x[-1][0]+x[-1][1])
Buggy python submission (verdict: Runtime Error):
    def i1():
     return int(input())
    def i2():
     return [int(i) for i in input().split()]

    [a,b,c,d,e,f]=i2()
    g=[]
    for i in range(31):
        for j in range(31):
                    ttt=(a*i+b*j)*100
                    tk=min(ttt*e/100,f-ttt)
                    tt=(tk//d)*d+(tk%d//(d-c))*(d-c)
                    t=ttt+tt
                    if t>0 :
                        g.append([(100*tt)/t,t,tt])

    g.sort()
    print(int(g[-1][1]),int(g[-1][2]))

def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

[a,b,c,d,e,f]=i2()
g=[[0,100*a,0]]
for i in range(31):
    for j in range(31):
                ttt=(a*i+b*j)*100
                tk=min(ttt*e/100,f-ttt)
                tt=(tk//d)*d+(tk%d//(d-c))*(d-c)
                t=ttt+tt
                if t>0 :
                    g.append([(100*tt)/t,t,tt])

g.sort()
print(int(g[-1][1]),int(g[-1][2]))

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

[a,b,c,d,e,f]=i2()
w=[]
s=[]
for i in range(f+1):
    for j in range(f+1):
        t=(a*i+b*j)*100
        tt=c*i+d*j
        if t<=f:
           w.append(t)
        if tt<=f:
           s.append(tt)
a=0
g=[]
for i in w:
 for j in s:
     if 0<i+j<=f and j<=i*e/100:
        g.append([j*100/(i+j),i+j,j])
g.sort()
print(g[-1][1],g[-1][2])
Buggy python submission (verdict: Time Limit Exceeded):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[N,M,R]=i2()
r=i2()
f=2**20
d=[[f for j in range(N)]for i in range(N)]
for i in range(N):d[i][i]=0
for i in range(M):
    a=i2()
    d[a[0]-1][a[1]-1]=a[2]
    d[a[1]-1][a[0]-1]=a[2]
for i in range(N):
    for j in range(N):
        for k in range(N):
            d[j][k]=min(d[j][k],d[j][i]+d[i][k])
a=[]
c=2**20
dd=[[f for j in range(N)]for i in range(N)]
for i in r:
    for j in r:
        if i<j:
            dd[i-1][j-1]=d[i-1][j-1]
            dd[j-1][i-1]=d[i-1][j-1]
import itertools
for i in list(itertools.permutations(r)):
    ddd=0
    for j in range(len(i)-1):
       ddd+=dd[i[j]-1][i[j+1]-1]
    c=min(c,ddd)
print(c)

Fixed submission:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

[N,M,R]=i2()
r=i2()
f=float("inf")
d=[[f for j in range(N)]for i in range(N)]
for i in range(N):d[i][i]=0
for i in range(M):
    a=i2()
    d[a[0]-1][a[1]-1]=a[2]
    d[a[1]-1][a[0]-1]=a[2]
for i in range(N):
    for j in range(N):
        for k in range(N):
            d[j][k]=min(d[j][k],d[j][i]+d[i][k])
c=float("inf")

import itertools
for i in list(itertools.permutations(r)):
    ddd=0
    for j in range(len(i)-1):
       ddd+=d[i[j]-1][i[j+1]-1]
    c=min(c,ddd)

print(c)