program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32)::n,cnt(0:100000)=0
    integer(int32):: i,ans
    integer(int32), allocatable:: a(:)

    read*, n
    allocate(a(n))
    read*, a(:)

    do i=1,n
        cnt(a(i))=cnt(a(i))+1
    end do
    ans=0
    do i=1,99999
        ans=max(ans, sum(cnt(i-1:i+1)))
    end do
    print'(i0)', ans
end program main