program ABC072C
    implicit none
    integer(8)::N,result,a_min,a_max,i
    integer(8),allocatable,dimension(:)::A,A_count
    read(5,*)N
    allocate(A(N))
    read(5,*)(A(i),i=1,N)
    allocate(A_count(maxval(A)+1))
    a_max=maxval(A)
    A_count=0
    result=0

    do i=1,N
        A_count(A(i)+1)=A_count(A(i)+1)+1
    end do

    do i=1,a_max-1
        if(A_count(i)+A_count(i+1)+A_count(i+2)>result)then
            result=A_count(i)+A_count(i+1)+A_count(i+2)
        end if
    end do

    print'(i0)',result
end program ABC072C