program main
	implicit none
	integer N, ans, i, amin, amax
	integer, allocatable :: a(:), b(:)
	read(*, *) N
	allocate(a(1:N))
	read(*, *) a(1:N)
	amax = maxval(a)
	amin = minval(a)
	allocate(b(amin-1:amax+1))
	b(amin-1:amax+1) = 0
	do i = 1, N
		b(a(i)) = b(a(i)) + 1
	end do
	ans = 0
	do i = amin, amax
		ans = max(ans,b(i-1)+b(i)+b(i+1))
	end do
	write(*, *) ans
end program main