Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n==3:
  print(2,5,63)
elif n==4:
  print(2,5,20,63)
elif n==5:
  print(2,5,20,30,63)
else:
  l=[2,3]
  cnt=2
  last=0
  for i in range(4,30001):
    if i%6 in [0,2,3,4]:
      l.append(i)
      cnt+=1
      if cnt==n:
        last=i
        break
  m=sum(l)
  if m%6==1:
    l.remove(9)
    for i in range(6):
      if (last+i)%6==2:
        l.append(last+i)
        break
  elif m%6==2:
    l.remove(8)
    for i in range(6):
      if (last+i)%6==0:
        l.append(last+i)
        break
  elif m%6==3:
    l.remove(9)
    for i in range(6):
      if (last+i)%6==0:
        l.append(last+i)
        break
  elif m%6==4:
    l.remove(8)
    for i in range(6):
      if (last+i)%6==4:
        l.append(last+i)
        break
  elif m%6==5:
    l.remove(9)
    for i in range(6):
      if (last+i)%6==4:
        l.append(last+i)
        break
  print(*l)
  if len(s)!=n:
    while True:
      z=0

Fixed submission:
n=int(input())
if n==3:
  print(2,5,63)
elif n==4:
  print(2,5,20,63)
elif n==5:
  print(2,5,20,30,63)
else:
  l=set()
  cnt=0
  e=0
  for i in range(2,30001):
    if i%2==0 or i%3==0:
      l.add(i)
      cnt+=1
      if cnt==n:
        m=sum(l)
        if m%6==2:
          l.discard(8)
          l.add((i//6+1)*6)
        elif m%6==3:
          l.discard(9)
          l.add((i//6+1)*6)
        elif m%6==5:
          l.discard(8)
          l.add((i+3)//6*6+3)
        break
  print(' '.join(map(str,l)))

Buggy python submission (verdict: Runtime Error):
n=int(input())
if n==3:
  print(2,5,63)
elif n==4:
  print(2,5,20,63)
elif n==5:
  print(2,5,20,30,63)
else:
  l=[2,3]
  cnt=2
  last=0
  for i in range(6,30001):
    if i%6 in [0,2,3,4]:
      l.append(i)
      cnt+=1
      if cnt==n:
        last=i
        break
  m=sum(l)
  if m%6==2:
    l.remove(8)
    for i in range(6):
      if (last+i)%6==0:
        l.append(last+i)
        break
  elif m%6==3:
    l.remove(9)
    for i in range(6):
      if (last+i)%6==0:
        l.append(last+i)
        break
  elif m%6==5:
    l.remove(9)
    for i in range(6):
      if (last+i)%6==4:
        l.append(last+i)
        break
print(*l)

Fixed submission:
n=int(input())
if n==3:
  print(2,5,63)
elif n==4:
  print(2,5,20,63)
elif n==5:
  print(2,5,20,30,63)
else:
  l=set()
  cnt=0
  e=0
  for i in range(2,30001):
    if i%2==0 or i%3==0:
      l.add(i)
      cnt+=1
      if cnt==n:
        m=sum(l)
        if m%6==2:
          l.discard(8)
          l.add((i//6+1)*6)
        elif m%6==3:
          l.discard(9)
          l.add((i//6+1)*6)
        elif m%6==5:
          l.discard(8)
          l.add((i+3)//6*6+3)
        break
  print(' '.join(map(str,l)))
Buggy python submission (verdict: Runtime Error):

a,b=map(int,input().split())
cntA,cntB=0,0
print(100,100)
flag=False
arr=[['#']*100 for i in range(100)]
l=[]
cntB=1
for i in range(2,99,4):
  if flag:break
  for j in range(2,99,4):
    l.append((i,j))
    for y in range(i-1,i+2):
      for x in range(j-1,j+2):
        arr[y][x]='.'
    cntA+=1
    if cntA==a:
      flag=True
      break
while cntB<b:
  cntB+=1
  s,t=l.pop()
  arr[s][t]='#'
for i in range(100):
  print(''.join(arr[i]))

Fixed submission:
a,b=map(int,input().split())
cntA,cntB=0,0
print(100,100)
flag=False
if a>=b:
  arr=[['#']*100 for i in range(100)]
  l=[]
  cntB=1
  for i in range(2,99,4):
    if flag:break
    for j in range(2,99,4):
      l.append((i,j))
      for y in range(i-1,i+2):
        for x in range(j-1,j+2):
          arr[y][x]='.'
      cntA+=1
      if cntA==a:
        flag=True
        break
  while cntB<b:
    cntB+=1
    s,t=l.pop()
    arr[s][t]='#'
  for i in range(100):
    print(''.join(arr[i]))
else:
  arr=[['.']*100 for i in range(100)]
  l=[]
  cntA=1
  for i in range(2,99,4):
    if flag:break
    for j in range(2,99,4):
      l.append((i,j))
      for y in range(i-1,i+2):
        for x in range(j-1,j+2):
          arr[y][x]='#'
      cntB+=1
      if cntB==b:
        flag=True
        break
  while cntA<a:
    cntA+=1
    s,t=l.pop()
    arr[s][t]='.'
  for i in range(100):
    print(''.join(arr[i]))

Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
cntA,cntB=0,0
print(100,100)
flag=False
arr=[['#']*100 for i in range(100)]
l=[]
cntB=1
for i in range(2,100,4):
  if flag:break
  for j in range(2,100,4):
    l.append((i,j))
    for y in range(i-1,i+2):
      for x in range(j-1,j+2):
        arr[y][x]='.'
    cntA+=1
    if cntA==a:
      flag=True
      break
while cntB<b:
  cntB+=1
  s,t=l.pop()
  arr[s][t]='#'
for i in range(100):
  print(''.join(arr[i]))

Fixed submission:
a,b=map(int,input().split())
cntA,cntB=0,0
print(100,100)
flag=False
if a>=b:
  arr=[['#']*100 for i in range(100)]
  l=[]
  cntB=1
  for i in range(2,99,4):
    if flag:break
    for j in range(2,99,4):
      l.append((i,j))
      for y in range(i-1,i+2):
        for x in range(j-1,j+2):
          arr[y][x]='.'
      cntA+=1
      if cntA==a:
        flag=True
        break
  while cntB<b:
    cntB+=1
    s,t=l.pop()
    arr[s][t]='#'
  for i in range(100):
    print(''.join(arr[i]))
else:
  arr=[['.']*100 for i in range(100)]
  l=[]
  cntA=1
  for i in range(2,99,4):
    if flag:break
    for j in range(2,99,4):
      l.append((i,j))
      for y in range(i-1,i+2):
        for x in range(j-1,j+2):
          arr[y][x]='#'
      cntB+=1
      if cntB==b:
        flag=True
        break
  while cntA<a:
    cntA+=1
    s,t=l.pop()
    arr[s][t]='.'
  for i in range(100):
    print(''.join(arr[i]))
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=[input() for i in range(n)]
cnt=[0]*5
for t in s:
  if t[0]=='M':
    cnt[0]+=1
  elif t[0]=='A':
    cnt[1]+=1
  elif t[0]=='R':
    cnt[2]+=1
  elif t[0]=='C':
    cnt[3]+=1
  elif t[0]=='H':
    cnt[4]+=1
ans=0
for v in itertools.combinations([0,1,2,3,4],3):
  ans+=cnt[v[0]]*cnt[v[1]]*cnt[v[2]]
print(ans)

Fixed submission:
import itertools
n=int(input())
s=[input() for i in range(n)]
cnt=[0]*5
for t in s:
  if t[0]=='M':
    cnt[0]+=1
  elif t[0]=='A':
    cnt[1]+=1
  elif t[0]=='R':
    cnt[2]+=1
  elif t[0]=='C':
    cnt[3]+=1
  elif t[0]=='H':
    cnt[4]+=1
ans=0
for v in itertools.combinations([0,1,2,3,4],3):
  ans+=cnt[v[0]]*cnt[v[1]]*cnt[v[2]]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
print(0,flush=True)
la=input()
if la=='Vacant':
  exit()
print(n-1,flush=True)
ra=input()
if ra=='Vacant':
  exit()
l=0
r=n-1
while r>=l+1:
  m=(l+r)//2
  print(m,flush=True)
  s=input()
  if s=='Vacant':
    exit()
  elif (s!=la and (m-l)%2==0) or (s==ra and (m-l)%2==1):
    r=m-1
    ra=s
  else:
    l=m+1
    la=s

Fixed submission:
n=int(input())
def out(t):
  print(t,flush=True)
  s=input()
  if s=='Male':return 0
  elif s=='Female':return 1
  else:exit()
l=0
r=n
f=out(0)
while l+1!=r:
  m=(l+r)//2
  if (m+f)%2==out(m):l=m
  else:r=m

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
print(0)
la=input()
if la=='Vacant':
  exit()
print(n-1)
ra=input()
if ra=='Vacant':
  exit()
l=0
r=n-1
while true:
  m=(l+r)//2
  print(m)
  s=input()
  if s=='Vacant':
    exit()
  elif (s!=la and (m-l)%2==0) or (s==ra and (m-l)%2==1):
    r=m-1
    ra=s
  else:
    l=m+1
    la=s


Fixed submission:
n=int(input())
def out(t):
  print(t,flush=True)
  s=input()
  if s=='Male':return 0
  elif s=='Female':return 1
  else:exit()
l=0
r=n
f=out(0)
while l+1!=r:
  m=(l+r)//2
  if (m+f)%2==out(m):l=m
  else:r=m

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
print(0)
la=input()
if la=='Vacant':
  exit()
print(n-1)
ra=input()
if ra=='Vacant':
  exit()
l=0
r=n-1
while true:
  m=(l+r)//2
  print(m)
  s=input()
  if s=='Vacant':
    exit()
  elif (s!=la and (m-l)%2==0) or (s==ra and (m-l)%2==1):
    r=m
    ra=s
  else:
    l=m
    la=s

Fixed submission:
n=int(input())
def out(t):
  print(t,flush=True)
  s=input()
  if s=='Male':return 0
  elif s=='Female':return 1
  else:exit()
l=0
r=n
f=out(0)
while l+1!=r:
  m=(l+r)//2
  if (m+f)%2==out(m):l=m
  else:r=m
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[list(map(int,input().split())) for i in range(2)]
ans=0
for i in range(n):
  cnt=0
  for j in range(i+1):
    cnt+=a[j][0]
  for j in range(i,n):
    cnt+=a[j][1]
  ans=max(ans,cnt)
print(ans)

Fixed submission:
n=int(input())
a=[list(map(int,input().split())) for i in range(2)]
ans=0
for i in range(n):
  cnt=0
  for j in range(i+1):
    cnt+=a[0][j]
  for j in range(i,n):
    cnt+=a[1][j]
  ans=max(ans,cnt)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,y=map(int,input().split())
for i in range(2*(10**3)+1):
  for j in range(4*(10**3)+1):
    res=y-i*10000-j*5000
    if res>=0 and res%1000==0 and res//1000+i+j==n :
      print(i,j,res//1000)
      exit()
print(-1,-1,-1)


Fixed submission:
n,y=map(int,input().split())
for i in range(2*(10**3)+1):
  for j in range(4*(10**3)+1):
    res=y-i*10000-j*5000
    if res>=0 and res%1000==0 and res//1000+i+j==n :
      print(i,j,res//1000)
      exit()
print(-1,-1,-1)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
c,s,f=[0]*(n-1),[0]*(n-1),[0]*(n-1)
for i in range(n-1):
  c[i],s[i],f[i]=map(int,input().split())
arr=[0]*n
for i in range(n-1):
  for j in range(i,n-1):
    l=s[j]
    if arr[i]>l:
      while arr[i]>l:
        l+=f[j]
    arr[i]=l
    arr[i]+=c[j]
  print(arr[i])
print(0)

Fixed submission:
n=int(input())
c,s,f=[0]*(n-1),[0]*(n-1),[0]*(n-1)
for i in range(n-1):
  c[i],s[i],f[i]=map(int,input().split())
arr=[0]*n
for i in range(n-1):
  for j in range(i,n-1):
    l=s[j]
    if arr[i]>l:
      while arr[i]>l:
        l+=f[j]
    arr[i]=l
    arr[i]+=c[j]
  print(arr[i])
print(0)
Buggy python submission (verdict: Runtime Error):
import math
x,y=map(int,input().split())
print(math.ceil(math.log2((y-x)/x))+1)

Fixed submission:
x,y=map(int,input().split())
print(len(bin(y//x))-2)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
cnt=0
c=Counter(a)
for u in c.keys():
  if int(u)>c[u]:
    cnt+=v
  else:
    cnt+=c[u]-int(u)
print(cnt)

Fixed submission:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
cnt=0
c=Counter(a)
for u in c.keys():
  if int(u)>c[u]:
    cnt+=c[u]
  else:
    cnt+=c[u]-int(u)
print(cnt)

Buggy python submission (verdict: Runtime Error):
import Counter
n=int(input())
a=list(map(int,input().split()))
cnt=0
c=Counter(a)
for u,v in c:
  if int(u)>v:
    cnt+=v
  else:
    cnt+=v-int(u)
print(cnt)

Fixed submission:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
cnt=0
c=Counter(a)
for u in c.keys():
  if int(u)>c[u]:
    cnt+=c[u]
  else:
    cnt+=c[u]-int(u)
print(cnt)
Buggy python submission (verdict: Runtime Error):
N,C=map(int,input().split())
ch=[[] for i in range(31)]
for i in range(N):
  s,t,c=map(int,input().split())
  ch[c].append([s,t])
arr=[[] for i in range(31)]
start=[]
end=[]
for i in range(31):
  score=[0]*(10**5+1)
  for j in range(len(ch[i])):
    score[ch[i][j][0]]+=1
    score[ch[i][j][1]]-=1
  for j in range(10**5+1):
    if score[j]==1:
      start.append(j)
    if score[j]==-1:
      end.append(j)
ans=[0]*(10**5+1)
for i in start:
  ans[i]+=1
for j in end:
  ans[j+1]-=1
for i in range(10**5):
  ans[i+1]+=ans[i]
print(max(ans))

Fixed submission:
N,C=map(int,input().split())
ch=[[] for i in range(31)]
for i in range(N):
  s,t,c=map(int,input().split())
  ch[c].append([s,t])
arr=[[] for i in range(31)]
start=[]
end=[]
for i in range(31):
  score=[0]*(10**5+1)
  for j in range(len(ch[i])):
    score[ch[i][j][0]]+=1
    score[ch[i][j][1]]-=1
  for j in range(10**5+1):
    if score[j]==1:
      start.append(j)
    if score[j]==-1:
      end.append(j)
ans=[0]*(10**5+3)
for i in start:
  ans[i]+=1
for j in end:
  ans[j+1]-=1
for i in range(10**5):
  ans[i+1]+=ans[i]
print(max(ans))
Buggy python submission (verdict: Runtime Error):
import Counter
n=int(input())
a=[int(input()) for i in range(n)]
c=Counter(a).most_common()
ans=0
for v in c:
  if v[1]%2==1:
    ans+=1
print(ans)

Fixed submission:
from collections import Counter
n=int(input())
a=[int(input()) for i in range(n)]
c=Counter(a).most_common()
ans=0
for v in c:
  if v[1]%2==1:
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(c).most_common()
s=[0,0]
for v in c:
  if v[1]>=2:
    s.append(int(v[0]))
s.sort()
print(s[-1]*s[-2])

Fixed submission:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(a).most_common()
s=[0,0]
for v in c:
  if v[1]>=2:
    for _ in range(v[1]//2):
      s.append(int(v[0]))
s.sort()
print(s[-1]*s[-2])
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
cnt1=0
cnt4=0
for i in a:
  if i%2==1:
    cnt1+=1
  elif cnt%4==0:
    cnt4+=1
if cnt4>=cnt1+1:
  print('Yes')
else:
  print('No')

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
cnt1=0
cnt2=0
cnt4=0
for i in a:
  if i%2==1:
    cnt1+=1
  elif i%4!=0:
    cnt2+=1
  elif i%4==0:
    cnt4+=1
if cnt2==0:
  if cnt1<=cnt4+1:
    print('Yes')
  else:
    print('No')
else:
  if cnt1<=cnt4:
    print('Yes')
  else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
def comb(n,k,p):
  from math import factorial
  if n<0 or k<0 or n<k:return 0
  if n==0 or k==0:return 1
  a=factorial(n)%p
  b=factorial(k)%p
  c=factorial(n-k)%p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return (d*d)%p
  if b%2==1:
    return (a*power_func(a,b-1,p))%p
import copy
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
b=copy.deepcopy(a)
b.sort()
tmp=-1
for i in range(n):
  if b[i]==b[i+1]:
    tmp=b[i]
r=[]
for i in range(n+1):
  if a[i]==tmp:
    r.append(i)
y=abs(r[1]-r[0]-1)
for k in range(1,n+2):
  ans=(comb(n-1,k,mod)+comb(n-1,k-2,mod)+comb(n-1,k-1,mod)*2-comb(n-1-y,k-1,mod))%mod
  print(ans)

Fixed submission:
def comb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
n=int(input())
mod=10**9+7
for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
import copy
a=list(map(int,input().split()))
b=copy.deepcopy(a)
b.sort()
tmp=-1
for i in range(n):
  if b[i]==b[i+1]:
    tmp=b[i]
r=[]
for i in range(n+1):
  if a[i]==tmp:
    r.append(i)
y=abs(r[1]-r[0]-1)
for k in range(1,n+2):
  ans=(comb(n-1,k,mod)+comb(n-1,k-2,mod)+comb(n-1,k-1,mod)*2-comb(n-1-y,k-1,mod))%mod
  print(ans)
Buggy python submission (verdict: Runtime Error):
from math import factorial
n,m=map(int,input().split())
mod=10**9+7
if abs(n-m)>=2:
  print(0)
elif abs(n-m)==1:
  print((factorial(n,mod)*factorial(m,mod))%mod)
else:
  print((2*factortial(n,mod)*factorial(m,mod))%mod)

Fixed submission:
from math import factorial
n,m=map(int,input().split())
mod=10**9+7
if abs(n-m)>=2:
  print(0)
elif abs(n-m)==1:
  print((factorial(n)%mod*factorial(m)%mod)%mod)
else:
  print((2*factorial(n)%mod*factorial(m)%mod)%mod)
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import *

class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.parents[x]>self.parents[y]:
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]
    def roots(self):
        return [i for i,x in enumerate(self.parents) if x<0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

n=int(input())
X=[[0,0] for i in range(n)]
Y=[[0,0] for i in range(n)]
edge=[[0,0] for i in range(n)]
for i in range(n):
  x,y=map(int,input().split())
  X[i]=[x,i]
  Y[i]=[y,i]
  edge[i]=[x,y]
X.sort()
Y.sort()
hq=[]
heapify(hq)
for i in range(n-1):
  x1,j1=X[i]
  x2,j2=X[i+1]
  y1,k1=Y[i]
  y2,k2=Y[i+1]
  heappush(hq,(x2-x1,j1,j2))
  heappush(hq,(y2-y1,k1,k2))
ans=0
uf=UnionFind(n)
while hq:
  w,s,t=heappop(hq)
  if uf.find(s)!=uf.find(t):
    uf.unite(s,t)
    ans+=w
print(ans)

Fixed submission:
from heapq import *

class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.parents[x]>self.parents[y]:
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]
    def roots(self):
        return [i for i,x in enumerate(self.parents) if x<0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

n=int(input())
X=[[0,0] for i in range(n)]
Y=[[0,0] for i in range(n)]
edge=[[0,0] for i in range(n)]
for i in range(n):
  x,y=map(int,input().split())
  X[i]=[x,i]
  Y[i]=[y,i]
  edge[i]=[x,y]
X.sort()
Y.sort()
hq=[]
heapify(hq)
for i in range(n-1):
  x1,j1=X[i]
  x2,j2=X[i+1]
  y1,k1=Y[i]
  y2,k2=Y[i+1]
  heappush(hq,(x2-x1,j1,j2))
  heappush(hq,(y2-y1,k1,k2))
ans=0
uf=UnionFind(n)
while hq:
  w,s,t=heappop(hq)
  if uf.find(s)!=uf.find(t):
    uf.unite(s,t)
    ans+=w
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import ceil
n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
def enough(x):
  cnt=0
  for i in range(n):
    if h[i]-x*b<=0:
      continue:
    cnt+=ceil((h[i]-x*b)/(a-b))
  if cnt<=x:
    return True
  else:
    return False
l=0
r=10**9
while r-l>0:
  mid=(r+l)//2
  if enough(mid):
    r=mid
  else:
    l=mid+1
print(r)

Fixed submission:
from math import ceil
n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
def enough(x):
  cnt=0
  for i in range(n):
    if h[i]-x*b<=0:
      continue
    cnt+=ceil((h[i]-x*b)/(a-b))
  if cnt<=x:
    return True
  else:
    return False
l=0
r=10**9
while r-l>0:
  mid=(r+l)//2
  if enough(mid):
    r=mid
  else:
    l=mid+1
print(r)
Buggy python submission (verdict: Runtime Error):
N,T=map(int,input().split())
t=list(map(int,input().split()))+[10**18]
x=0
for i in range(n):
  x+=min(t[i+1]-t[i],T)
print(x)

Fixed submission:
N,T=map(int,input().split())
t=list(map(int,input().split()))+[10**18]
x=0
for i in range(N):
  x+=min(t[i+1]-t[i],T)
print(x)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
def f(x):
  if a[x]>=k:
    return True
  dp=[False]*k
  dp[0]=True
  y=0
  for i in range(n):
    if i==x:
      continue
    for j in range(y,-1,-1):
      if j+a[i]>=k:
        continue
      dp[j+a[i]]|=dp[j]
    y=min(k-1,y+a[i])
  return sum(dp[k-a[x]:k])
if not f(n-1):
  print(n)
  exit()
if f(0):
  print(0)
  exit()
l,r=0,n-1
while r-l>1:
  mid=(r+l)//2
  if f(mid):
    r=mid
  else:
    l=mid
print(r)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
def f(x):
  if a[x]>=k:
    return True
  dp=[False]*k
  dp[0]=True
  y=0
  for i in range(n):
    if i==x:
      continue
    for j in range(y,-1,-1):
      if j+a[i]>=k:
        continue
      dp[j+a[i]]|=dp[j]
    y=min(k-1,y+a[i])
  return sum(dp[k-a[x]:k])
if not f(n-1):
  print(n)
  exit()
if f(0):
  print(0)
  exit()
l,r=0,n-1
while r-l>1:
  mid=(r+l)//2
  if f(mid):
    r=mid
  else:
    l=mid
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
n,ma,mb=map(int,input().split())
abc=[list(map(int,input().split())) for i in range(n)]
dp=[[[10**9]*401 for i in range(401)] for j in range(n+1)]
dp[0][0][0]=0
for i in range(1,n+1):
  for j in range(401):
    for k in range(401):
      if j-abc[i-1][0]>=0 and k-abc[i-1][1]>=0:
        dp[i][j][k]=min(dp[i-1][j][k],dp[i-1][j-abc[i-1][0]][k-abc[i-1][1]]+abc[i-1][2])
      else:
        dp[i][j][k]=dp[i-1][j][k]
ans=10**18
for j in range(1,401):
  for k in range(1,401):
    if dp[n][j][k]<10**9 and k*ma==j*mb:
      ans=min(ans,dp[n][j][k])
if ans==10**18:
  print(-1)
else: 
  print(ans)

Fixed submission:
n,ma,mb=map(int,input().split())
INF=10**17
dp=[[[INF]*(10*n+1) for i in range(10*n+1)] for j in range(n+1)]
dp[0][0][0]=0
ans=10**17
for i in range(n):
  a,b,c=map(int,input().split())
  for j in range(10*n+1):
    for k in range(10*n+1):
      if dp[i][j][k]!=INF:
        dp[i+1][j+a][k+b]=min(dp[i+1][j+a][k+b],dp[i][j][k]+c)
      dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k])
for i in range(1,10*n+1):
  for j in range(1,10*n+1):
    if i*mb==j*ma:
      ans=min(ans,dp[n][i][j])
if ans==INF:
  print(-1)
else:
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)
n=int(input())
t=[[] for i in range(n)]
for i in range(1,n):
  a=int(input())
  t[a-1].append(i)
def dfs(v):
  if not t[v]:
    return 0
  l=[dfs(i)+1 for i in t[v]]
  l.sort()
  for i in range(len(t[v])-1):
    l[i+1]=max(l[i+1],l[i]+1)
  return l[-1]
print(dfs(0))

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)
n=int(input())
t=[[] for i in range(n)]
for i in range(1,n):
  a=int(input())
  t[a-1].append(i)
def dfs(v):
  if not t[v]:
    return 0
  l=[dfs(i)+1 for i in t[v]]
  l.sort()
  for i in range(len(t[v])-1):
    l[i+1]=max(l[i+1],l[i]+1)
  return l[-1]
print(dfs(0))

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n=int(input())
t=[[] for i in range(n)]
for i in range(1,n):
  a=int(input())
  t[a-1].append(i)
def dfs(v):
  if not t[v]:
    return 0
  l=[dfs(i)+1 for i in t[v]]
  l.sort()
  for i in range(len(t[v])-1):
    l[i+1]=max(l[i+1],l[i]+1)
  return l[-1]
print(dfs(0))

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)
n=int(input())
t=[[] for i in range(n)]
for i in range(1,n):
  a=int(input())
  t[a-1].append(i)
def dfs(v):
  if not t[v]:
    return 0
  l=[dfs(i)+1 for i in t[v]]
  l.sort()
  for i in range(len(t[v])-1):
    l[i+1]=max(l[i+1],l[i]+1)
  return l[-1]
print(dfs(0))