program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i, ans
    integer(int32), allocatable:: a(:), numc(:)

    read*, n
    allocate(a(n))
    read*, a(:)
    allocate(numc(0:maxval(a)), source=0)
    do i=1,n
        numc(a(i)) = numc(a(i)) + 1
    end do
    ans=0

    do i=1,ubound(numc,1)-2
        ans=max(ans,sum(numc(i-1:i+1)))
    end do

    print*, ans
end program name