program sample
    implicit none
  
    integer(8) :: i,j,m,n,x(0:100000),b
    integer(8),allocatable :: a(:),y(:)
  
    read(*,*) n
    allocate(a(n))
    read(*,*)a
    x(:)=0
    do i=1,n
        b=a(i)
        x(b)=x(b)+1
    end do
    m=0
    do i=0,100000-2
        if (x(i)+x(i+1)+x(i+2)>m)then
            m=x(i)+x(i+1)+x(i+2)
        endif
    end do


    write(*,*) m
  
    stop
end program sample
  

