Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
totl=min(0,a[0]-b[0])
for i in range(n):
  totl+=min(0,a[i+1]-b[i]-b[i+1])
    
print(sum(b)+totl)
  


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(n):
  if b[i]-a[i]>0:
    cnt+=a[i]
    cnt+=min(b[i]-a[i],a[i+1])
    a[i+1]=max(a[i+1]-b[i]+a[i],0)
  else:
    cnt+=b[i]
print(cnt)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if a[0]-b[0]<0:
  totl=a[0]-b[0]
else:
  totl=0
for i in range(n):
  if b[i]+b[i+1]>a[i+1]:
    totl+=a[i+1]-b[i]-b[i+1]
    
print(sum(b)+totl)
  


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(n):
  if b[i]-a[i]>0:
    cnt+=a[i]
    cnt+=min(b[i]-a[i],a[i+1])
    a[i+1]=max(a[i+1]-b[i]+a[i],0)
  else:
    cnt+=b[i]
print(cnt)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if a[0]-b[0]<0:
  totl=a[0]-b[0]
for i in range(n):
  if b[i]+b[i+1]>a[i+1]:
    totl+=a[i+1]-b[i]-b[i+1]
    
print(sum(b)+totl)
  


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(n):
  if b[i]-a[i]>0:
    cnt+=a[i]
    cnt+=min(b[i]-a[i],a[i+1])
    a[i+1]=max(a[i+1]-b[i]+a[i],0)
  else:
    cnt+=b[i]
print(cnt)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
totl=0
for i in range(n):
  m=min(b[i],max(a[i],a[i+1]))
  totl+=m
  del a[a.index(m)]
print(totl)
  


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(n):
  if b[i]-a[i]>0:
    cnt+=a[i]
    cnt+=min(b[i]-a[i],a[i+1])
    a[i+1]=max(a[i+1]-b[i]+a[i],0)
  else:
    cnt+=b[i]
print(cnt)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=a.sort(reverse=True)
d=b.sort(reverse=True)
totl=0
for i in range(n):
  totl+=min(c[i],d[i])
print(totl)
  


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(n):
  if b[i]-a[i]>0:
    cnt+=a[i]
    cnt+=min(b[i]-a[i],a[i+1])
    a[i+1]=max(a[i+1]-b[i]+a[i],0)
  else:
    cnt+=b[i]
print(cnt)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a_=a.sort(reverse=True)
b_=b.sort(reverse=True)
totl=0
for i in range(n):
  totl+=min(a_[i],b_[i])
print(totl)
  


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(n):
  if b[i]-a[i]>0:
    cnt+=a[i]
    cnt+=min(b[i]-a[i],a[i+1])
    a[i+1]=max(a[i+1]-b[i]+a[i],0)
  else:
    cnt+=b[i]
print(cnt)
Buggy python submission (verdict: Runtime Error):
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(n-2):
  lst=[p[i],p[i+1],p[i+2]]
  m=min(lst)
  P=p[i+1]
  del lst.index(m)
  if min(lst)==P:
    cnt+=1
print(cnt)


Fixed submission:
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(n-2):
  lst=[p[i],p[i+1],p[i+2]]
  m=min(lst)
  P=p[i+1]
  del lst[lst.index(m)]
  if min(lst)==P:
    cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
n=int(input())
d=list(map(int,input().split()))
D=sorted(d)
num=D[n/2]-D[(n/2)-1]
print(num)

Fixed submission:
n=int(input())
d=list(map(int,input().split()))
D=sorted(d)
num=D[n//2]-D[(n//2)-1]
print(num)

Buggy python submission (verdict: Runtime Error):
n=int(input())
d=list(map(int,input().split()))
D=sorted(d)
num=D[(n/2)]-D[(n/2)-1]
print(num)


Fixed submission:
n=int(input())
d=list(map(int,input().split()))
D=sorted(d)
num=D[n//2]-D[(n//2)-1]
print(num)

Buggy python submission (verdict: Runtime Error):
n=int(input())
d=list(map(int,input().split()))
D=sorted(d)
print(D[(n/2)]-D[(n/2)-1])


Fixed submission:
n=int(input())
d=list(map(int,input().split()))
D=sorted(d)
num=D[n//2]-D[(n//2)-1]
print(num)

Buggy python submission (verdict: Runtime Error):
n=int(input())
d=list(map(int,input().split()))
D=sorted(d)
print(D[(n/2)+1]-D[(n/2)-1])


Fixed submission:
n=int(input())
d=list(map(int,input().split()))
D=sorted(d)
num=D[n//2]-D[(n//2)-1]
print(num)

Buggy python submission (verdict: Runtime Error):
n=int(input())
d=list(map(int,input().split()))
D=sorted(d)
print(D[(n//2)+1]-D[(n//2)-1])

Fixed submission:
n=int(input())
d=list(map(int,input().split()))
D=sorted(d)
num=D[n//2]-D[(n//2)-1]
print(num)
Buggy python submission (verdict: Runtime Error):
n,l=map(int,input().split())
d=114514
num=114514
for j in range(n):
  if abs(l+j)<d:
    d=abs(l+j)
    num=j
s=0
for in range(n):
  s+=1
print(s+(n-1)*l-num)


Fixed submission:
n,l=map(int,input().split())
d=114514
num=114514
for j in range(n):
  if abs(l+j)<d:
    d=abs(l+j)
    num=j
s=0
for i in range(n):
  s+=i
print(s+(n-1)*l-num)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]
for i in range(m):
  a.append(int(input()))
lst=[]
lst.append(a[0])
lst.append(0)
for j in range(m-1):
  lst.append(a[j+1]-a[j]-1)
  lst.append(0)
lst.append(n-a[m-1])
l=len(lst)
for k in range(l-1):
  if lst[k]==0 and lst[k+1]==0:
    print(0)
    break
  else:
    if lst[k]>1:
      lst[k]-=1
if lst[l-1]>1:
  lst[l-1]-=1
for p in range(l):
  if lst[p]==0:
    del lst[p]
totl=1
for q in range(len(lst)):
  totl*=lst[q]
  totl=totl%1000000007
print(totl)




 
  
  
   
    





Fixed submission:
import sys
n,m=map(int,input().split())
a=[]
for i in range(m):
  a.append(int(input()))
a.sort()
for i in range(m-1):
  if a[i+1]-a[i]==1:
    print(0)
    sys.exit()
p=10**9+7  
dp=[0]*(n+1)
dp[0]=1
if 1 not in a:
  dp[1]=1
lst=set(list(range(1,n+1)))
A=set(a)
Lst=lst-A
Lst=list(Lst)
if 1 in Lst:
  Lst.remove(1)
for i in Lst:
  dp[i]=dp[i-1]+dp[i-2]
  if p<=dp[i]:
    dp[i]=dp[i]%p
print(dp[n]%p)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
L=100000
R=100000
for i in range(m):
  l=int(input())
  r=int(input())
  L=max(L,l)
  R=min(R,r)
print(max(0,R-L+1))

  


Fixed submission:
n,m=map(int,input().split())
l=[]
r=[]
for i in range(m):
  a,b=map(int,input().split())
  l.append(a)
  r.append(b)
lm=max(l)
rm=min(r)
if rm-lm<0:
  print(0)
else:
  print(rm-lm+1)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
L=100000
R=100000
for i in range(m):
  l=int(input())
  r=int(input())
  L=max(L,l)
  R=min(R,r)
print(max(0,R-L+1))

  


Fixed submission:
n,m=map(int,input().split())
l=[]
r=[]
for i in range(m):
  a,b=map(int,input().split())
  l.append(a)
  r.append(b)
lm=max(l)
rm=min(r)
if rm-lm<0:
  print(0)
else:
  print(rm-lm+1)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
lst=[]
L=100000
R=100000
for i in range(m):
  l=int(input())
  r=int(input())
  L=max(L,l)
  R=min(R,r)
print(max(0,R-L+1))

  


Fixed submission:
n,m=map(int,input().split())
l=[]
r=[]
for i in range(m):
  a,b=map(int,input().split())
  l.append(a)
  r.append(b)
lm=max(l)
rm=min(r)
if rm-lm<0:
  print(0)
else:
  print(rm-lm+1)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
lst=[]
for i in range(m):
  l=int(input())
  r=int(input())
  for j in range(l,r+1):
    lst.append(j)
print(len(set(lst)))


Fixed submission:
n,m=map(int,input().split())
l=[]
r=[]
for i in range(m):
  a,b=map(int,input().split())
  l.append(a)
  r.append(b)
lm=max(l)
rm=min(r)
if rm-lm<0:
  print(0)
else:
  print(rm-lm+1)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
lst=[]
for i in range(n):
  l=int(input())
  r=int(input())
  for j in range(l,r+1):
    lst.append(j)
print(len(set(lst)))


Fixed submission:
n,m=map(int,input().split())
l=[]
r=[]
for i in range(m):
  a,b=map(int,input().split())
  l.append(a)
  r.append(b)
lm=max(l)
rm=min(r)
if rm-lm<0:
  print(0)
else:
  print(rm-lm+1)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
lst=[]
for i in range(m):
  a,b=map(int,input().split())
  for j in range(a,b+1):
    lst.append(j)
cnt=0
for k in range(1,n+1):
  if lst.count(k)==m:
    cnt+=1
print(cnt)
  

Fixed submission:
n,m=map(int,input().split())
l=[]
r=[]
for i in range(m):
  a,b=map(int,input().split())
  l.append(a)
  r.append(b)
lm=max(l)
rm=min(r)
if rm-lm<0:
  print(0)
else:
  print(rm-lm+1)
Buggy python submission (verdict: Runtime Error):
from math import log
n,k=map(int,input().split())
p=0
for i in range(1,n+1):
  p+=((1/2)**(math.ceil(math.log2(k/i))))/n
print(p)

Fixed submission:
n,k=map(int,input().split())
lst=[]
for m in range(1,n+1):
  a=1
  cnt=0
  for i in range(100000):
    if m*a>=k:
      lst.append(cnt)
      break
    else:
      a*=2
      cnt+=1
totl=0
for j in range(n):
  totl+=0.5**lst[j]
print(totl/n)
Buggy python submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().split()))
cnt=1
if n==1:
  print(1)
else:
  for i in range(1,n):
  if all(h[i]>=h[j] for j in range(i-1)):
    cnt+=1
  print(cnt)


Fixed submission:
n=int(input())
h=list(map(int,input().split()))
cnt=1
if n>=2:
  for i in range(1,n):
    if all(h[i]>=h[j] for j in range(i)):
      cnt+=1
  print(cnt)
else:
  print(1)
Buggy python submission (verdict: Runtime Error):
a=[]
for i in range(5):
  a.append(input())
b=[]
for j in range(5):
  if a[j]%10==0:
    b.append(10)
  else:
    b.append(a[j]%10)
idx=b.index(min(b))
cnt=a[idx]
del a[idx]
for k in range(4):
  if a[k]%10==0:
    cnt+=a[k]
  else:
    cnt+=a[k]+10-(a[k]%10)
print(cnt)
  




Fixed submission:
a=[]
for i in range(5):
  a.append(int(input()))
b=[]
for j in range(5):
  if a[j]%10==0:
    b.append(10)
  else:
    b.append(a[j]%10)
idx=b.index(min(b))
cnt=a[idx]
del a[idx]
for k in range(4):
  if a[k]%10==0:
    cnt+=a[k]
  else:
    cnt+=a[k]+10-(a[k]%10)
print(cnt)
Buggy python submission (verdict: Runtime Error):
n=int(input())
lst=[]
for i in range(5):
  lst.append(int(input()))
if n%lst(min)==0:
  print(n//lst(min)+4)
else:
  print(n//lst(min)+5)
  


Fixed submission:
n=int(input())
lst=[]
for i in range(5):
  lst.append(int(input()))
if n%min(lst)==0:
  print((n//min(lst))+4)
else:
  print((n//min(lst))+5)
Buggy python submission (verdict: Runtime Error):
b=input()
a=['A','C','G','T']
b=['A','T','C','G']
i=a.index(b)
print(b[i])

Fixed submission:
b=input()
a=['A','C','G','T']
c=['T','G','C','A']
i=a.index(b)
print(c[i])
Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=input()
t=[0]*n
for i in range(n):
  t[i+1]=t[i]+(1 if s[i:i+2]=='AC' else 0)
for j in range(q):
  l,r=map(int,input().split())
  print(t[r-1]-t[l-1])
  
    

    


Fixed submission:
n,q=map(int,input().split())
s=input()
t=[0]*(n+1)
for i in range(n):
  t[i+1]=t[i]+(1 if s[i:i+2]=='AC' else 0)
for j in range(q):
  l,r=map(int,input().split())
  print(t[r-1]-t[l-1])

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())
    t=s[l-1:r]
    print(t.count('AC'))
    


Fixed submission:
n,q=map(int,input().split())
s=input()
t=[0]*(n+1)
for i in range(n):
  t[i+1]=t[i]+(1 if s[i:i+2]=='AC' else 0)
for j in range(q):
  l,r=map(int,input().split())
  print(t[r-1]-t[l-1])
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
d={}
for i in range(n):
  a,b=map(int,input().split())
  d[b]=a
D=sorted(d.items(),key=lambda x:x[1])
val=0
cnt=0
j=0
while cnt<=m:
  cnt+=int(D[j][0])
  val+=int(D[j][1])
  j+=1
val-=int(D[j][1])*(cnt-m)
print(val)


Fixed submission:
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
a.sort()
totl=0
x=0
for j,k in a:
  if x+k<m:
    totl+=j*k
    x+=k
  else:
    totl+=j*(m-x)
    break
print(totl)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
d={}
for i in range(n):
  a,b=map(int,input().split())
  d[b]=a
D=sorted(d.items())
val=0
cnt=0
j=0
while cnt<=m:
  cnt+=int(D[j][0])
  val+=int(D[j][1])
  j+=1
val-=int(D[j][1])*(cnt-m)
print(val)


Fixed submission:
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
a.sort()
totl=0
x=0
for j,k in a:
  if x+k<m:
    totl+=j*k
    x+=k
  else:
    totl+=j*(m-x)
    break
print(totl)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
d={}
for i in range(n):
  a,b=map(int,input().split())
  d[b]=a
D=sorted(d.items())
val=0
cnt=0
j=0
while cnt<=m:
  cnt+=D[j][0]
  val+=D[j][1]
  j+=1
val-=D[j][1]*(cnt-m)
print(val)


Fixed submission:
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
a.sort()
totl=0
x=0
for j,k in a:
  if x+k<m:
    totl+=j*k
    x+=k
  else:
    totl+=j*(m-x)
    break
print(totl)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
a.sort()
totl=0
x=0
for j,k in range(a):
  if x+j<m:
    totl+=j*k
    x+=k
  else:
    totl+=j*(x-m)
    break
print(totl)
    
    
  
  

Fixed submission:
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
a.sort()
totl=0
x=0
for j,k in a:
  if x+k<m:
    totl+=j*k
    x+=k
  else:
    totl+=j*(m-x)
    break
print(totl)
Buggy python submission (verdict: Runtime Error):
A,B,C = map(int,input().split())

r = B%A
s = (B-r)/A

print(min(C,s)


Fixed submission:
A,B,C = map(int,input().split())

List=[B//A,C]
print(min(List))
Buggy python submission (verdict: Runtime Error):
A,B,K = map(int,input().split())

i=0
j=1
while i<K:
  if A%j=0 and B%j=0:
     i +=1
  else:
     i =i
  j+=1

print(j)
  


Fixed submission:
A,B,K = map(int,input().split())

i=0
j=100
while i<K:
    if A%j==0 and B%j==0:
        i +=1
    else:
        i =i
    j-=1

print(j+1)

Buggy python submission (verdict: Runtime Error):
A,B,K = map(int,input().split())

i=0
j=1
while i<K:
  if A%j=0^B%j=0:
     i +=1
  else:
     i =i
  j+=1

print(j)
  

Fixed submission:
A,B,K = map(int,input().split())

i=0
j=100
while i<K:
    if A%j==0 and B%j==0:
        i +=1
    else:
        i =i
    j-=1

print(j+1)
Buggy python submission (verdict: Runtime Error):
S=input()
s=S[6:8]
if '0' in s:
  if s == '10':
     s = s
  else:
     s = s.strip('0')
n = int(s)
if n<=4:
  print('Heisei')
else:
  print('TBD')
  
  


Fixed submission:
y,m,d = map(int,input().split("/"))
if m<=4:
  print('Heisei')
else:
  print('TBD')

Buggy python submission (verdict: Runtime Error):
S=input()
s=S[6:8]
if '0' in s:
  if s == '10':
     s = s
  else:
    s = s.replace('0','')
n = int(s)
if n<=4:
  print('Heisei')
else:
  print('TBD')
  
  

Fixed submission:
y,m,d = map(int,input().split("/"))
if m<=4:
  print('Heisei')
else:
  print('TBD')

Buggy python submission (verdict: Runtime Error):
S=input()
u=S[7:8]
U=int(u)
if U<=4:
    print('Heisei')
else:
    print('TBD')


Fixed submission:
y,m,d = map(int,input().split("/"))
if m<=4:
  print('Heisei')
else:
  print('TBD')

Buggy python submission (verdict: Runtime Error):
S=input()
u=S[6:8]
U=int(u)
if U<=4:
    print('Heisei')
else:
    print('TBD')


Fixed submission:
y,m,d = map(int,input().split("/"))
if m<=4:
  print('Heisei')
else:
  print('TBD')

Buggy python submission (verdict: Runtime Error):
S=input()
u=s[6:8]
U=int(u)
if U<=4:
    print('Heisei')
else:
    print('TBD')


Fixed submission:
y,m,d = map(int,input().split("/"))
if m<=4:
  print('Heisei')
else:
  print('TBD')
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
if B%A=0:
  print(A+B)
else:
  print(B-A)

Fixed submission:
A,B=map(int,input().split())
if B%A==0:
  print(A+B)
else:
  print(B-A)
Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
a=list(map(int,input().split()))
gcd=float('inf')
for i in range(n-1):
  gcd=min(gcd,math.gcd(a[i],a[i+1]))
print(gcd)
  
      


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
def gcd(x,y):
  while x%y>0:
    x,y=y,x%y
  return y
a.sort(reverse=True)
ans=a[0]
for j in range(n-1):
  ans=gcd(ans,a[j+1])
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
a=list(map(int,input().split()))
print(math.gcd(a))
      

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
def gcd(x,y):
  while x%y>0:
    x,y=y,x%y
  return y
a.sort(reverse=True)
ans=a[0]
for j in range(n-1):
  ans=gcd(ans,a[j+1])
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
dif=[]
if m<=n:
  print(0)
  sys.exit()
else:
  for i in range(n-1):
    dif.append(x[i+1]-x[i]-1)
  dif.sort(reverse=True)
  ans=x[n-1]-x[0]+1
  for j in range(n):
    ans-=dif[j]
  print(ans-n+1)
  

Fixed submission:
import sys
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
dif=[]
if m<=n:
  print(0)
  sys.exit()
else:
  for i in range(m-1):
    dif.append(x[i+1]-x[i])
  dif.sort(reverse=True)
  ans=x[m-1]-x[0]
  for j in range(n-1):
    ans-=dif[j]
  print(ans)
Buggy python submission (verdict: Runtime Error):
s = int(input())
def func(n):
  if n%2 == 1:
    return 3n+1
  else:
    return n//2
def prog(N):
  if N == 1:
    return s
  else:
    a=s
    for i in range(1,N):
      a = func(a)
    return a

b=[]
for i in range(1,1000001):
  tmp = prog(i)
  if tmp in b:
    print(i)
    break
  else:
    b.append(tmp)
  



Fixed submission:
s = int(input())
def func(n):
  if n%2 == 1:
    return 3*n+1
  else:
    return n//2
def prog(N):
  if N == 1:
    return s
  else:
    a=s
    for i in range(1,N):
      a = func(a)
    return a

b=[]
for i in range(1,1000000):
  tmp = prog(i)
  if tmp in b:
    print(i)
    break
  else:
    b.append(tmp)

Buggy python submission (verdict: Runtime Error):
s = int(input())
def func(n):
  if n%2 == 1:
    return 3n+1
  else:
    return n//2
def prog(N):
  if N == 1:
    return s
  else:
    a=s
    for i in range(1,N):
      a = func(a)
    return a

b=[]
for i in range(1,10000):
  tmp = prog(i)
  if tmp in b:
    print(i)
    break
  else:
    b.append(tmp)
  



Fixed submission:
s = int(input())
def func(n):
  if n%2 == 1:
    return 3*n+1
  else:
    return n//2
def prog(N):
  if N == 1:
    return s
  else:
    a=s
    for i in range(1,N):
      a = func(a)
    return a

b=[]
for i in range(1,1000000):
  tmp = prog(i)
  if tmp in b:
    print(i)
    break
  else:
    b.append(tmp)

Buggy python submission (verdict: Runtime Error):
s = int(input())
def func(n):
  if n%2 == 1:
    return 3n+1
  else:
    return n/2
def prog(N):
  if N == 1:
    return s
  else:
    a=s
    for i in range(1,N):
      a = func(a)
    return a


while prog(k)==prog(j):
  



Fixed submission:
s = int(input())
def func(n):
  if n%2 == 1:
    return 3*n+1
  else:
    return n//2
def prog(N):
  if N == 1:
    return s
  else:
    a=s
    for i in range(1,N):
      a = func(a)
    return a

b=[]
for i in range(1,1000000):
  tmp = prog(i)
  if tmp in b:
    print(i)
    break
  else:
    b.append(tmp)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
lst=[10001]*(n+1)
lst[0]=0
for i in range(1,n+1):
  for j in range(1,k+1):
    if lst[i]>lst[max(0,i-j)]+abs(h[i]-h[max(0,i-j)]):
      lst[i]=lst[max(0,i-j)]+abs(h[i]-h[max(0,i-j)])
print(lst[n])
    
  


Fixed submission:
import sys
n,k=map(int,input().split())
h=list(map(int,input().split()))
c=[float('inf')]*n
def sub(l):
  return(abs(l-h[0]))
if n-1<=k:
  lst=list(map(sub,h))
  del lst[0]
  print(min(lst))
  sys.exit()  
c[0]=0
m=n-k
for i in range(m):
  for j in range(1,k+1):
    c[i+j]=min(c[i+j],c[i]+abs(h[i+j]-h[i]))
    
for i in range(n-k,n-1):
  for j in range(1,n-i):
    c[i+j]=min(c[i+j],c[i]+abs(h[i+j]-h[i]))
print(c[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,W=map(int,input().split())
lst=[]
for i in range(n):
  w,v=map(int,input().split())
  lst.append([w,v])
nap=[]
for i in range(n+1):
  nap.append([0]*(W+1))
for i in range(1,n+1):
  for j in range(1,W+1):
    if lst[i-1][0]<=j:
      nap[i][j]=max(nap[i-1][j],nap[i-1][j-lst[i-1][0]]+lst[i-1][1])
    else:
      nap[i][j]=nap[i-1][j]
print(nap[n][W])
 
 
    
  


Fixed submission:
n,W=map(int,input().split())
lst=[]
for i in range(n):
  w,v=map(int,input().split())
  lst.append([w,v])
nap=[]
for i in range(n+1):
  nap.append([0]*(W+1))
for i in range(1,n+1):
  for j in range(1,W+1):
    if lst[i-1][0]<=j:
      nap[i][j]=max(nap[i-1][j],nap[i-1][j-lst[i-1][0]]+lst[i-1][1])
    else:
      nap[i][j]=nap[i-1][j]
print(nap[n][W])
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
d=[0]*(n-1)
for j in range(n-1):
  d[j+1]=d[j]+h[j+1]-h[j]
m=float('inf')
for l in range(1,n-k+1):
  m=min(m,d[l+k-1]-d[l])
print(m)
  
  
  
  


Fixed submission:
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
d=[0]*n
for j in range(n-1):
  d[j+1]=d[j]+h[j+1]-h[j]
m=float('inf')
for l in range(n-k+1):
  m=min(m,d[l+k-1]-d[l])
print(m)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
d=[0]*(n-1)
for j in range(n-1):
  d[j+1]=d[j]+h[j+1]-h[j]
m=1000000001
for l in range(1,n-k+1):
  m=min(m,d[l+k-1]-d[l])
print(m)
  
  
  
  


Fixed submission:
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
d=[0]*n
for j in range(n-1):
  d[j+1]=d[j]+h[j+1]-h[j]
m=float('inf')
for l in range(n-k+1):
  m=min(m,d[l+k-1]-d[l])
print(m)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
d=[0]*(n-1)
for j in range(n-1):
  d[j+1]=d[j]+h[j+1]-h[j]
m=1000000001
for l in range(n-k):
  m=min(m,d[l+k-1]-d[l])
print(m)
  
  
  
  

Fixed submission:
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
d=[0]*n
for j in range(n-1):
  d[j+1]=d[j]+h[j+1]-h[j]
m=float('inf')
for l in range(n-k+1):
  m=min(m,d[l+k-1]-d[l])
print(m)
Buggy python submission (verdict: Runtime Error):
n=int(input())
t,a=map(int,inout().split())
h=list(map(int,input().split()))
def abs(k,l):
  if k>l:
    return k-l
  else:
    return l-k  
b=20000313
cnt=0
for i in range(n):
  if b>abs(a,t-0.006*h[i]):
    b=t-0.006*h[i]
    cnt=i
  else:
    b=b
    cnt=cnt
print(cnt+1)

  
  
  

Fixed submission:
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
def abs(k,l):
  if k>l:
    return k-l
  else:
    return l-k  
b=20000313
cnt=0
for i in range(n):
  if b>abs(a,t-0.006*h[i]):
    b=abs(a,t-0.006*h[i])
    cnt=i
  else:
    b=b
    cnt=cnt
print(cnt+1)
Buggy python submission (verdict: Runtime Error):
n,t=map(int,input().split())
a=[]
b=[]
for i in range(n):
  a.append(int(input()))
  b.append(int(input()))
c=[]
for j in range(n):
  if b[j]>t:
    c.append(1001)
  else:
    c.append(a[j])
if c==[1001]*n:
  print('TLE')
else:
  print(min(c))

    

Fixed submission:
n,t=map(int,input().split())
a=[]
b=[]
for i in range(n):
  s,u=map(int,input().split())
  a.append(s)
  b.append(u)
c=[]
for j in range(n):
  if b[j]>t:
    c.append(1001)
  else:
    c.append(a[j])
if c==[1001]*n:
  print('TLE')
else:
  print(min(c))