You are a coach at your local university. There are $n$ students under your supervision, the programming skill of the $i$-th student is $a_i$.

You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than $5$.

Your task is to report the maximum possible number of students in a balanced team.


-----Input-----

The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of students.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is a programming skill of the $i$-th student.


-----Output-----

Print one integer — the maximum possible number of students in a balanced team.


-----Examples-----
Input
6
1 10 17 12 15 2

Output
3

Input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337

Output
10

Input
6
1 1000 10000 10 100 1000000000

Output
1



-----Note-----

In the first example you can create a team with skills $[12, 17, 15]$.

In the second example you can take all students in a team because their programming skills are equal.

In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students).

Difficulty: EASY
Tags: Sorting

Amortized analysis
Skill types: Sorting

Amortized analysis

Starter code:

Solutions:
n = int(input())
s = list(map(int, input().split()))
s.sort()
s.append(1000000006)
maxcnt = 1
first = 0
last = 1
for i in range(1, n + 1):
	if s[i] - s[first] > 5:
		first += 1
	elif i - first + 1 > maxcnt:
		maxcnt = i - first + 1
print(maxcnt)


N = int(input())
arr = input()
arr = [int(x) for x in arr.split(' ')]
left = 0
right = 0
arr.sort()
res = 0
while left < N and right < N:
	if arr[right] > arr[left] + 5:
		res = max(res, right - left)
		left += 1
	else:
		right += 1
res = max(res, right - left)
print(res)


n = int(input())
a = list(map(int, input().split()))
contador = dict()
for skill in a:
	if skill not in contador:
		contador[skill] = 0
	contador[skill] += 1
max_qtd = 0
for s in contador:
	total = 0
	for i in range(6):
		if s + i in contador:
			total += contador[s + i]
	max_qtd = max(max_qtd, total)
print(max_qtd)


def funcao(lista):
	tam = len(lista)
	maior = 1
	i = 0
	j = i + 1
	while i < tam and j < tam:
		if int(lista[j]) - int(lista[i]) > 5:
			i += 1
		else:
			j += 1
			maior = max(maior, j - i)
	return maior
input()
lista = input().split()
lista = list(map(int, lista))
lista.sort()
print(funcao(lista))


n = int(input())
a = [int(i) for i in input().split(' ')]
a.sort()
dict = dict()
for i in range(n):
	if a[i] in dict:
		dict[a[i]] += 1
	else:
		dict[a[i]] = 1
res = 0
for d in dict:
	sum = 0
	for j in range(d, d + 6):
		if j in dict:
			sum += dict[j]
	res = max(res, sum)
print(res)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
maxCount = 0
j = 0
for i in range(n):
	while j < n and a[j] - a[i] <= 5:
		j += 1
		maxCount = max(maxCount, j - i)
print(maxCount)


n = int(input())
a = list(map(int, input().split()))
a.sort()
cur = 0
if n == 1:
	ans = 1
else:
	ans = 0
i = 0
j = 1
while j < n:
	if a[j] - a[i] <= 5:
		cur = j - i + 1
		ans = max(ans, cur)
		j += 1
	else:
		i += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
i = 0
j = 0
c = 0
f = 0
while j < len(a):
	if a[j] - a[i] <= 5:
		j += 1
		c += 1
	else:
		f = max(f, c)
		c = c - 1
		i = i + 1
f = max(f, c)
print(f)


def solve(students):
	students.sort()
	options = {}
	max_students = 0
	for student in students:
		new_options = {}
		if len(options) >= 0:
			to_delete = []
			for limit in options.keys():
				if student <= limit:
					new_options[limit] = options[limit] + 1
				else:
					max_students = max(max_students, options[limit])
		if student + 5 not in new_options:
			new_options[student + 5] = 1
		options = new_options
	for quantity in options.values():
		max_students = max(max_students, quantity)
	return max_students
n = int(input())
students = [int(x) for x in input().split()]
result = solve(students)
print(result)


import bisect
N = int(input().strip())
nums = [int(i) for i in input().strip().split()]
nums.sort()
start = 0
count = 1
ans = 1
for i in range(1, N):
	if nums[i] - nums[start] > 5:
		count = 1
		start = bisect.bisect_right(nums, nums[i] - 6, start, i + 1)
	else:
		count += 1
		if ans < i - start + 1:
			ans = i - start + 1
print(ans)


def main():
	n = int(input())
	a = sorted(list(map(int, input().split())))
	max_team = 0
	j = 0
	for i in range(n):
		while j < n and abs(a[i] - a[j]) <= 5:
			max_team = max(max_team, j - i + 1)
			j += 1
		if max_team == n - i + 1:
			break
	print(max_team)
main()


def binsearch(left, right):
	x = 5 + nums[left]
	while right - left > 1:
		middle = (left + right) // 2
		if nums[middle] > x:
			right = middle
		else:
			left = middle
	return left
n = int(input())
nums = list(map(int, input().split()))
nums.sort()
result = 0
second = 0
for first in range(n):
	second = binsearch(first, n)
	if second - first + 1 > result:
		result = second - first + 1
print(result)


import bisect
n = int(input())
a = list(map(int, input().rstrip().split()))
a.sort()
maxi = 0
for i in range(n):
	h = a[i] + 5
	index = bisect.bisect_right(a, h)
	maxi = max(maxi, index - i)
print(maxi)


import os
import sys
from math import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def array():
	return [int(i) for i in input().split()]
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = sorted(array())
l = 0
h = 1
ans = 1
while h < n:
	if a[h] - a[l] > 5:
		l += 1
	else:
		h += 1
	ans = max(h - l, ans)
print(ans)


from bisect import bisect_left
from bisect import bisect_right
n = int(input())
a = sorted([int(item) for item in input().split()])
ans = 0
for i in a:
	ans = max(ans, bisect_right(a, i + 5) - bisect_left(a, i))
print(ans)


from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest
from math import ceil, floor, log, log2, sqrt, gcd, factorial, pow, pi

def binNumber(n, size=4):
	return bin(n)[2:].zfill(size)

def iar():
	return list(map(int, input().split()))

def ini():
	return int(input())

def isp():
	return map(int, input().split())

def sti():
	return str(input())

def par(a):
	print(' '.join(list(map(str, a))))

def tdl(outerListSize, innerListSize, defaultValue=0):
	return [[defaultValue] * innerListSize for i in range(outerListSize)]

def sts(s):
	s = list(s)
	s.sort()
	return ''.join(s)

class pair:

	def __init__(self, f, s):
		self.fi = f
		self.se = s

	def __lt__(self, other):
		return (self.fi, self.se) < (other.fi, other.se)
n = ini()
a = iar()
a.sort()
ma = -1
cnt = 1
start = 0
i = 1
while i < n:
	if a[i] - a[start] <= 5:
		cnt += 1
	else:
		ma = max(ma, cnt)
		start += 1
		cnt = i - start
		i -= 1
	i += 1
ma = max(ma, cnt)
print(ma)


from bisect import bisect_right as br
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(n):
	k = br(a, a[i] + 5)
	ans = max(ans, k - i)
print(ans)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	k = 5
	M = 0
	z1 = z2 = 0
	while True:
		if a[z2] - a[z1] <= k:
			M = max(M, z2 - z1 + 1)
			z2 += 1
			if z2 == n:
				break
		else:
			z1 += 1
	print(M)
main()


n = int(input())
a = list(map(int, input().split()))
a.sort()
l = 0
i = 0
ans = -1
while i < n:
	if a[i] - a[l] > 5:
		ans = max(ans, i - l)
		while a[i] - a[l] > 5:
			l += 1
	i += 1
ans = max(ans, i - l)
print(ans)


n = int(input())
inputs = list(map(int, input().split()))
inputs.sort()
j = 0
result = 0
temp = 0
for i in range(n):
	if abs(inputs[i] - inputs[j]) <= 5:
		temp += 1
		result = max(temp, result)
	else:
		j += 1
print(result)


N = int(input())
L = sorted(list(map(int, input().split())))
i = j = 0
s = 1
while i < N and j < N:
	while i < N and j < N and (L[j] - L[i] <= 5):
		j += 1
		if i < N and j < N and (L[j] - L[i] <= 5):
			if j - i + 1 > s:
				s = j - i + 1
	i += 1
print(s)


n = int(input())
a = list(map(int, input().split()))
a.sort()
mx = i = 0
for j in range(n):
	while a[j] - a[i] > 5:
		i += 1
	mx = max(mx, j - i + 1)
print(mx)


n = int(input())
a = sorted(list(map(int, input().split())))
ans = []
ans.append(a[0])
cnt = len(ans)
for i in range(1, n):
	if len(ans) == 0:
		ans.append(a[i])
	elif a[i] - ans[0] <= 5:
		ans.append(a[i])
	else:
		j = 0
		while j < len(ans) and a[i] - ans[j] > 5:
			j += 1
		del ans[:j]
		ans.append(a[i])
	cnt = max(cnt, len(ans))
cnt = max(cnt, len(ans))
print(cnt)


from collections import *
from math import *
n = int(input())
a = list(map(int, input().split()))
a.sort()
j = n - 1
ans = 0
for i in range(n - 1, -1, -1):
	while j >= 0 and a[i] - a[j] <= 5:
		j -= 1
	ans = max(ans, i - j)
print(ans)


n = [int(x) for x in input().split()]
skills = [int(x) for x in input().split()]
skills.sort()

def get_team_amount(skills):
	res = 0
	index_first = 0
	for index in range(1, len(skills)):
		if skills[index] - skills[index_first] <= 5:
			if index - index_first >= res:
				res = index - index_first
		else:
			while index_first != index and skills[index] - skills[index_first] > 5:
				index_first += 1
	if len(skills) > 1 and index - index_first >= res:
		res = index - index_first
	print(res + 1)
get_team_amount(skills)


n = int(input())
a = sorted(list(map(int, input().split())))
left = 0
ans = 0
for right in range(n):
	if a[right] - a[left] <= 5:
		ans = max(ans, right - left + 1)
	else:
		while left < right:
			left += 1
			if a[right] - a[left] <= 5:
				ans = max(ans, right - left + 1)
				break
print(ans)


n = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
l = 0
r = 0
cnt = 0
while l < n:
	while r < n and a[r] - a[l] <= 5:
		cnt += 1
		r += 1
	ans = max(ans, cnt)
	l += 1
	if r < l:
		r += 1
	cnt = max(0, cnt - 1)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
ans = 0
j = 0
for i in range(n):
	while j < n and a[j] - a[i] <= 5:
		j += 1
		ans = max(ans, j - i)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
(m, i, j) = (0, 0, 0)
while j < n:
	while a[j] - a[i] <= 5:
		j += 1
		if j == n:
			break
	m = max(m, j - i)
	i += 1
print(m)


n = input()
v = list(map(int, input().split()))
v.sort()
i = 1
j = 0
t1 = 1
tm = 1
while i < len(v):
	if v[i] - v[j] <= 5:
		t1 += 1
		i += 1
		if t1 > tm:
			tm = t1
	else:
		j += 1
		t1 -= 1
print(tm)


n = int(input())
lst = sorted(map(int, input().split()))
res = i = j = 0
while j < n:
	while j < n and lst[j] - lst[i] < 6:
		j += 1
	res = max(res, j - i)
	i += 1
print(res)


N = int(input())
num = sorted(map(int, input().split()))
i = j = s = ans = 0
while j < N:
	if num[j] - num[i] > 5:
		s -= 1
		i += 1
	else:
		s += 1
		j += 1
		ans = max(s, ans)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
best = 0
l = 0
r = 0
while l < n and r < n:
	if a[r] - a[l] <= 5:
		best = max(best, r - l + 1)
		r += 1
	elif a[r] - a[l] > 5:
		l += 1
print(best)


I = lambda : map(int, input().rstrip().split())
n = int(input())
a = list(sorted(I()))
maxm = 1
i = 0
j = 1
while j < n:
	if a[j] - a[i] <= 5:
		maxm = max(j - i + 1, maxm)
		j += 1
	else:
		i += 1
print(maxm)


from sys import stdin
input = stdin.readline
T = 1
for t in range(1, T + 1):
	n = int(input())
	_input = list(map(int, input().split()))
	_input.sort()
	idx = 0
	count = 0
	for i in range(len(_input)):
		while idx < n and _input[idx] - _input[i] <= 5:
			idx += 1
			count = max(count, idx - i)
	print(count)


import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
ans = 0
l = 0
r = 0
d = 5
while l < N and r < N:
	if L[r] - L[l] <= d:
		ans = max(ans, r - l + 1)
		r += 1
	elif l == r:
		r += 1
	else:
		l += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
l = 0
s = 0
res = 0
for r in range(n):
	while a[r] - a[l] > 5:
		l += 1
	res = max(res, r - l + 1)
print(res)


import sys
n = int(input())
skl_lst = [int(e) for e in input().split()]
skl_lst.sort()
p1 = 0
p2 = 1
cntr = 0
while p2 < len(skl_lst):
	while skl_lst[p2] - skl_lst[p1] > 5:
		if p1 > p2:
			break
		p1 += 1
	sys.stderr.write(str(p1) + ' ' + str(p2) + '\n')
	cntr = max(p2 - p1, cntr)
	p2 += 1
print(cntr + 1)


def comand(lst):
	(result, j) = (0, 0)
	for i in range(len(lst)):
		while j < len(lst) and lst[j] - lst[i] <= 5:
			j += 1
			result = max(result, j - i)
	return result
n = int(input())
a = [int(x) for x in input().split()]
print(comand(sorted(a)))


n = int(input())
l = sorted(list(map(int, input().split())))
first = 0
first_val = l[0]
last = 1
maxi = 1
while True:
	while last < n and abs(l[first] - l[last]) <= 5:
		last += 1
	maxi = max(maxi, last - first)
	if last == n:
		break
	first += 1
	while l[first] == first_val:
		first += 1
print(maxi)


n = int(input())
a = input().split()
a = [int(i) for i in a]
a.sort()
m = 1
i = 0
for j in range(1, len(a)):
	while a[j] - a[i] > 5:
		i += 1
	if j - i + 1 > m:
		m = j - i + 1
print(m)


n = int(input())
skills = [int(i) for i in input().split(' ')]
skills.sort()
minus = [skills[i] - skills[i - 1] for i in range(1, len(skills))]
s = 0
i = 0
j = 0
res = 0
while j < n:
	if skills[j] - skills[i] > 5:
		s -= 1
		i += 1
	else:
		s += 1
		j += 1
		res = max(s, res)
print(res)


from sys import stdin, stdout

def read_input():
	global t
	t = int(input())

def solve():
	(n, k) = map(lambda x: int(x), input().split())
	arr = [0] + [int(x) for x in input().split()]
	arr.sort()
	dp = [[0 for x in range(k + 1)] for y in range(n + 1)]
	for j in range(1, k + 1):
		curr_team_size = 0
		worst_in_team = 1
		for i in range(1, n + 1):
			if arr[i] - arr[worst_in_team] <= 5:
				curr_team_size += 1
			else:
				curr_team_size += 1
				while arr[i] - arr[worst_in_team] > 5:
					curr_team_size -= 1
					worst_in_team += 1
			dp[i][j] = max(dp[i - curr_team_size][j - 1] + curr_team_size, dp[i - 1][j])
	print(dp[n][k])

def main():
	solve()
main()


iin = lambda : int(input())
lin = lambda : list(map(int, input().split()))
n = iin()
a = lin()
a.sort()
sol = 0
aa = []
i = 0
while i < n:
	ch = 1
	j = i + 1
	while j < n and a[j] == a[j - 1]:
		j += 1
		ch += 1
	aa.append([a[i], ch])
	i = j
sol = 0
i = 0
l = len(aa)
for i in range(l):
	j = i + 1
	ch = aa[i][1]
	while j < l and aa[j][0] - aa[i][0] <= 5:
		ch += aa[j][1]
		j += 1
	sol = max(ch, sol)
print(sol)


n = int(input())
est = list(map(int, input().split()))
est.sort()
ip = 0
maxi = 1
atual = 1
for i in range(1, n):
	if est[i] - est[ip] < 6:
		atual += 1
	else:
		if atual > maxi:
			maxi = atual
		while est[i] - est[ip] > 5:
			atual -= 1
			ip += 1
		atual += 1
print(max(maxi, atual))


num_student = int(input())
skills_student = sorted(input().split(), key=int)

def count(array, i, j):
	return int(array[j]) - int(array[i])

def team(array):
	i = 0
	j = 0
	max_ = 1
	count_ = 1
	while j + 1 < len(array):
		if count(array, i, j + 1) <= 5:
			j += 1
			count_ += 1
		else:
			max_ = max(max_, count_)
			if count_ > 1:
				count_ -= 1
			i += 1
			if i > j:
				j = i
	max_ = max(max_, j - i + 1)
	return max_
print(team(skills_student))


import sys
import bisect
input = sys.stdin.readline
n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
dp = [1 for i in range(len(arr))]
for i in range(len(arr) - 1, -1, -1):
	dp[i] += i - bisect.bisect_left(arr, arr[i] - 5, 0, len(arr))
print(max(dp))


def ans(a):
	a.sort()
	Mnum = 1
	i = 0
	j = 1
	if a == []:
		return 0
	if len(a) == 1:
		return 1
	num = 1
	while i != len(a) and j != len(a):
		if a[j] - a[i] <= 5:
			if j - i == 1:
				num = num + 1
				j = j + 1
				if num >= Mnum:
					Mnum = num
			else:
				num = num + 1
				j = j + 1
				if num >= Mnum:
					Mnum = num
		elif j - i == 1:
			j = j + 1
			i = i + 1
			num = 1
		else:
			num = num - 1
			i = i + 1
	return Mnum
n = input('')
arr = list(map(int, input().split(' ')))
print(ans(arr))


n = int(input())
arr = [int(x) for x in input().split()]
maxnum = 1
arr.sort(reverse=True)
for i in range(0, n):
	for j in range(0, n - i):
		if i + maxnum >= len(arr):
			break
		if arr[i] - arr[i + maxnum] < 6:
			maxnum += 1
			continue
		else:
			break
print(maxnum)


n = int(input())
arr = sorted(list(map(int, input().split())))
(i, j) = (0, 0)
t = 0
while i < n:
	while j < n and arr[j] - arr[i] <= 5:
		j += 1
		t = max(t, j - i)
	i += 1
print(t)


n = int(input())
pA = 0
pB = 0
l = list(map(int, input().split()))
l.sort()
maxi = 0
while pB < n:
	while pB < n and l[pB] - l[pA] <= 5:
		pB += 1
	maxi = max(maxi, pB - pA)
	pA += 1
print(maxi)


n = int(input())
a = [int(i) for i in input().split()]
(i, j) = (0, 0)
a.sort()
ans = 1
while j < len(a):
	while a[j] - a[i] > 5:
		i += 1
	ans = max(j - i + 1, ans)
	j += 1
print(ans)


n = int(input())
k = 5
a = [int(s) for s in input().split()]
a.sort()
(i, lenStab) = (0, 0)
while i + lenStab < n:
	if a[i] + k >= a[i + lenStab]:
		lenStab += 1
	else:
		i += 1
print(lenStab)


n = int(input())
l = list(map(int, input().split()))
l.sort()
j = 0
count = 0
for i in range(n):
	while abs(l[j] - l[i]) > 5:
		j += 1
	count = max(count, i - j)
print(count + 1)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		a.sort()
		r = 1
		j = 0
		for i in range(n):
			t = a[i]
			while a[j] < a[i] - 5:
				j += 1
			k = i - j + 1
			if r < k:
				r = k
		rr.append(r)
	return JA(rr, '\n')
print(main())


from bisect import bisect_left
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
mx = 0
for i in range(len(A)):
	l = bisect_left(A, A[i] - 5)
	mx = max(i - l + 1, mx)
print(mx)


def main():
	n = int(input())
	aa = [int(i) for i in input().split()]
	aa = sorted(aa)
	ans = 0
	j = 0
	for i in range(n):
		while j < n and aa[j] - aa[i] <= 5:
			j += 1
			ans = max(ans, j - i)
	print(ans)
main()


n = int(input())
a = input().split()
for i in range(0, len(a)):
	a[i] = eval(a[i])
a.sort()
max = 1
i = 0
while i + max < n:
	while i + max < n and a[i + max] - a[i] <= 5:
		max += 1
	i += 1
print(max)


n = int(input())
a = sorted(list(map(int, input().split())))
r = 1
res = 1
for i in range(0, n):
	while r < n and a[r] - 5 <= a[i]:
		r += 1
	res = max(res, r - i)
print(res)


import sys
n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split()))
a.sort()
i = 0
j = 0
d = 1
while j < n - 1:
	if a[j + 1] <= a[i] + 5:
		j = j + 1
		d = max([d, j - i + 1])
	else:
		i = i + 1
print(d)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
l = 0
r = 0
res = 1
while True:
	while r < n and a[r] - a[l] <= 5:
		r += 1
	res = max(res, r - l)
	if r == n:
		break
	while l < n and a[r] - a[l] > 5:
		l += 1
print(res)


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
	if a[i] not in d:
		d[a[i]] = 1
	else:
		d[a[i]] += 1
num = 0
for k in d.keys():
	tmp = 0
	for j in range(k, k + 6):
		if j in d:
			tmp += d[j]
	num = max(num, tmp)
print(num)


int_inp = lambda : int(input())
strng = lambda : input().strip()
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
import math
from collections import Counter, defaultdict
n = int(input())
a = list(map(int, input().split()))
a.sort()
j = 0
c = 0
for i in range(n):
	while j < n and a[j] - a[i] <= 5:
		j += 1
		c = max(c, j - i)
print(c)


n = int(input().strip())
numbers = list(map(int, input().strip().split(' ')))
numbers.sort()
start = 0
current = 0
l = []
tot = 0
while current < len(numbers) and start < len(numbers):
	if numbers[current] - numbers[start] > 5:
		start = start + 1
		l.append(tot)
		tot -= 1
	else:
		tot += 1
		current += 1
if len(l) > 0:
	print(max(tot, max(l)))
else:
	print(tot)


import sys
h = sys.stdin.readline
n = int(input())
l = sorted(map(int, h().split()))
ans = i = j = 0
while i < n:
	while j < n and l[j] - l[i] <= 5:
		j += 1
	ans = max(ans, j - i)
	i += 1
print(ans)


def get(a, index, low, high):
	while low < high:
		m = low + (high - low + 1) // 2
		if abs(a[m] - a[index]) <= 5:
			low = m
		else:
			high = m - 1
	return low - index + 1
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 1
c = 1
for i in range(0, n):
	an = get(a, i, i, n - 1)
	ans = max(ans, an)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
m = 1
i = 0
j = 0
while 1:
	if i >= n or j >= n:
		break
	if a[j] - a[i] < 6:
		l = j - i + 1
		if l > m:
			m = l
		j += 1
	else:
		i += 1
print(m)


import sys
import math
import bisect

def main():
	n = int(input())
	A = list(map(int, input().split()))
	A.sort()
	max_val = 0
	for i in range(n):
		first = i
		last = bisect.bisect_right(A, A[i] + 5, lo=i)
		val = last - first
		max_val = max(max_val, val)
	print(max_val)
main()


input()
d = dict()
a = list(map(int, input().split()))
for el in a:
	if el not in d.keys():
		d.setdefault(el, 1)
	else:
		d[el] += 1
maxkol = 0
for el in d.keys():
	kol = 0
	for i in range(-5, 1):
		kol += d.get(el + i, 0)
	sum = 0
	for i in range(1, 6):
		a = d.get(el + i, 0)
		a1 = d.get(el + i - 6, 0)
		if a > a1 + sum:
			kol += a - a1
		sum += a1
	maxkol = max(maxkol, kol)
print(maxkol)


n = int(input())
lis = sorted(map(int, input().split()))
i = j = ans = 0
while i < n and j < n:
	if lis[j] - lis[i] <= 5:
		ans = max(ans, j - i + 1)
		j += 1
	else:
		i += 1
while i < n:
	if lis[-1] - lis[i] > 5:
		i += 1
	else:
		ans = max(ans, n - i)
		break
print(ans)


__author__ = 'NIORLYS'
n = int(input())
a = list(map(int, input().split()))
a.sort()
d = {a[i]: i for i in range(n)}

def max_number_diff_in_at_most_five(dic, key, index):
	for j in range(5, -1, -1):
		if key + j in dic:
			return dic[key + j] - index + 1
max_students = 0
for i in range(n):
	if n - i + 1 <= max_students:
		break
	temp_max_students = max_number_diff_in_at_most_five(d, a[i], i)
	if temp_max_students > max_students:
		max_students = temp_max_students
print(max_students)


n = int(input())
arr = sorted([int(i) for i in input().split()])
j = 0
resutl = 0
for i in range(0, n - 1):
	while j < n:
		if arr[j] - arr[i] > 5:
			break
		j += 1
		resutl = max(resutl, j - i)
if n == 1:
	resutl = 1
print(resutl)


n = int(input())
l = [int(y) for y in input().split()]
i = 0
ans = 0
l.sort()
j = 0
for i in range(n):
	while j < n and l[j] - l[i] <= 5:
		j += 1
		ans = max(ans, j - i)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
j = 0
r = -1
for i in range(len(arr)):
	while j < len(arr) and arr[j] - arr[i] <= 5:
		j += 1
	r = max(j - i, r)
print(r)


n = int(input())
a = sorted(map(int, input().split()))
(left, right) = (0, 0)
ans = 1
while right < n - 1:
	if a[right + 1] - a[left] <= 5:
		right += 1
		ans = max(ans, right - left + 1)
	elif left < right:
		left += 1
	else:
		left += 1
		right += 1
print(ans)


n = int(input())
skills = sorted(list(map(int, input().split())))
lo = 0
hi = 0
ans = 0
while lo < n and hi < n:
	while hi < n and skills[hi] - skills[lo] <= 5:
		hi += 1
	ans = max(ans, hi - lo)
	lo += 1
print(ans)


import math
import os
import random
import re
import sys
from collections import defaultdict as dd
n = int(input())
l = [int(i) for i in input().split(' ')]
d = dd(int)
for i in l:
	d[i] += 1
l = list(set(l))
l.sort()
n = len(l)
ans = 0
cur = 0
i = 0
while i < n:
	cur = l[i]
	j = i
	tmp = 0
	while j < n and l[j] - cur <= 5:
		tmp += d[l[j]]
		j += 1
	ans = max(ans, tmp)
	i += 1
print(ans)


n = int(input(''))
num = list(map(int, input().split()))
num.sort()
sol = 0
j = 0
for i in range(n):
	while j < n:
		if num[j] - num[i] > 5:
			break
		j += 1
	sol = max(j - i, sol)
	if j == n - 1:
		break
print(sol)


from collections import Counter
n = int(input())
x = list(map(int, input().split()))
x.sort()
counts = Counter(x)
keys = list(counts.keys())
if len(keys) == 1:
	print(counts[keys[0]])
else:
	keys.sort()
	start = 0
	end = 1
	curr_seq = counts[keys[start]]
	largest_seq = counts[keys[start]]
	while start <= end and end < len(keys):
		if keys[end] - keys[start] <= 5:
			curr_seq += counts[keys[end]]
			end += 1
		else:
			if curr_seq > largest_seq:
				largest_seq = curr_seq
			curr_seq -= counts[keys[start]]
			start += 1
	print(max(curr_seq, largest_seq))


n = int(input())
l = sorted(map(int, input().split()))
res = 0
i = 0
while i < n:
	j = i + 1
	while j < n and l[j] - l[i] <= 5:
		j += 1
	res = max(res, j - i)
	if j == n:
		break
	while i <= j and l[j] - l[i] > 5:
		i += 1
print(res)


input()
a = list(map(int, input().split()))
a.sort()
numbers = []
i = 0
j = 0
while i < len(a):
	if a[i] - a[j] <= 5:
		numbers.append(i - j + 1)
		i += 1
	else:
		j += 1
print(max(numbers))


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
left = 0
right = 0
for i in range(n):
	left = i
	while right < n and a[right] - a[left] <= 5:
		ans = max(ans, right - left + 1)
		right += 1
	if left == right:
		right += 1
print(ans)


n = int(input())
scores = [int(x) for x in input().split()]
values = {}
for s in scores:
	for i in range(6):
		values[s + i] = values.get(s + i, 0) + 1
print(max(values.values()))


import bisect
n = int(input())
stu = list(map(int, input().split(' ')))
stu.sort()
set_stu = list(set(stu))
set_stu.sort()
len_k = bisect.bisect_right(stu, stu[0] + 5)
for i in range(1, len(set_stu)):
	Start = bisect.bisect_right(stu, set_stu[i - 1]) + 1
	End = bisect.bisect_right(stu, set_stu[i] + 5)
	lenlen = End - Start + 1
	if lenlen > len_k:
		len_k = lenlen
print(len_k)


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
n = ini()
a = sorted(inl())
i = 0
j = 0
ans = 1
while j < n:
	if i == j:
		j += 1
		continue
	if a[j] - a[i] <= 5:
		ans = max(ans, j - i + 1)
		j += 1
	else:
		i += 1
print(ans)


n = int(input())
l = [int(x) for x in input().split()]
l = sorted(l)
max = 0
p2 = 0
for p1 in range(n):
	while p2 < n and l[p2] <= l[p1] + 5:
		p2 += 1
	if max < p2 - p1:
		max = p2 - p1
print(max)


n = int(input())
a = list(map(int, input().split()))
a.sort()
l = []
j = 0
for i in range(n):
	while j < n and a[j] - a[i] <= 5:
		j += 1
	l.append(j - i)
if a[n - 1] - a[0] > 5:
	print(max(l))
else:
	print(n)


n = int(input())
students = [int(x) for x in input().strip().split(' ')]
students.sort()
start = 0
end = 1
maxTeam = 1
for i in range(1, n):
	if students[i] - students[start] <= 5:
		end += 1
	else:
		while students[i] - students[start] > 5:
			start += 1
		end += 1
	maxTeam = max(maxTeam, end - start)
print(maxTeam)


def bin_search(lst, target):
	scan_pos = None
	srt = 0
	end = len(lst) - 1
	while srt <= end:
		mid = srt + (end - srt) // 2
		if lst[mid][0] == target:
			scan_pos = mid
			break
		elif lst[mid][0] > target:
			end = mid - 1
		else:
			srt = mid + 1
	return scan_pos

def search(lst, startpoint, width=5):
	scan_pos = startpoint
	s = lst[startpoint][1]
	for i in range(width):
		if startpoint + i + 1 >= len(lst):
			break
		elif lst[startpoint + i + 1][0] <= lst[startpoint][0] + width:
			scan_pos = startpoint + i + 1
			s += lst[scan_pos][1]
		else:
			break
	return s
n = int(input())
l2 = input().split()
num = [int(x) for x in l2]
srt_num = sorted(num)
pair = [[0, 0]]
for i in range(len(srt_num)):
	if srt_num[i] > pair[-1][0]:
		pair.append([srt_num[i], 1])
	elif srt_num[i] == pair[-1][0]:
		pair[-1][1] += 1
all_pos = []
for i in range(1, len(pair)):
	all_pos.append(search(pair, i))
print(max(all_pos))


n = int(input())
a = sorted(list(map(int, input().split())))
ml = 0
y1 = 0
a1 = [0] * n
for y2 in range(1, n):
	if a[y2] - a[y1] > 5:
		while a[y2] - a[y1] > 5:
			y1 += 1
	a1[y2] = y1
for y in range(n):
	ml = max(ml, y - a1[y])
print(ml + 1)


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def main():
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	maxFromI = [0] * n
	end = -1
	for i in range(n):
		while end + 1 < n and a[end + 1] <= a[i] + 5:
			end += 1
		maxFromI[i] = end - i + 1
	dp = [[0] * (k + 1) for _ in range(n + 1)]
	for i in range(n):
		for j in range(k + 1):
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
			if j + 1 <= k:
				dp[i + maxFromI[i]][j + 1] = max(dp[i + maxFromI[i]][j + 1], dp[i][j] + maxFromI[i])
	print(dp[n][k])
main()


def go():
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	a.sort()
	m = start = end = 0
	while end < n:
		while end < n and a[end] - a[start] <= 5:
			end += 1
		m = max(m, end - start)
		while start < n - 1 and a[start] == a[start + 1]:
			start += 1
		start += 1
	return max(m, end - start)
print(go())


n = int(input())
a = list(map(int, input().split()))
a.sort()
max1 = int(0)
for i in range(n):
	lo = i
	hi = n - 1
	ans = -1
	while lo <= hi:
		mid = int((lo + hi) / 2)
		if a[mid] - a[i] > 5:
			hi = mid - 1
		else:
			ans = mid
			lo = mid + 1
	max1 = max(max1, ans - i + 1)
print(max1)


n = input()
arr = [int(x) for x in input().split()]
start = 0
end = 0
globalCount = 0
currCount = 0
arr.sort()
while end < len(arr):
	if arr[start] + 5 >= arr[end]:
		currCount += 1
		end += 1
		globalCount = max(currCount, globalCount)
	else:
		start += 1
		currCount -= 1
print(globalCount)


import bisect
n = int(input())
a = sorted(map(int, input().split()))
high = 0
best = 1
while high < n - 1:
	high += 1
	low = bisect.bisect_left(a, a[high] - 5)
	best = max(best, high - low + 1)
print(best)


n = int(input())
a = sorted(list(map(int, input().split())))
count = 0
i = j = 0
while i < n and j < n:
	if a[j] - a[i] <= 5:
		if j - i + 1 > count:
			count = j - i + 1
		j += 1
	else:
		i += 1
print(count)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = float('-inf')
j = 0
for i in range(n):
	while a[j] + 5 < a[i]:
		j += 1
	ans = max(ans, i - j + 1)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
i = 0
j = 0
maxi = 1
while j < n:
	while i < j and a[j] - a[i] > 5:
		i += 1
	maxi = max(maxi, j - i + 1)
	j += 1
print(maxi)


TN = 1

def solution():
	n = int(input())
	a = list(map(int, input().split()))
	dct = {}
	ans = []
	keys = []
	for i in range(n):
		try:
			x = dct[a[i]]
		except:
			dct[a[i]] = 1
			keys.append(a[i])
		else:
			dct[a[i]] += 1
	for i in keys:
		x = dct[i]
		for j in range(1, 6):
			try:
				y = dct[i - j]
			except:
				y = 0
			else:
				x += dct[i - j]
		ans.append(x)
	print(max(ans))
while TN != 0:
	solution()
	TN -= 1


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
ans = 0
l.sort()
from bisect import bisect_left as bl, bisect as br
for i in l:
	ans = max(ans, br(l, i + 5) - bl(l, i))
print(ans)


def bin_search(a, x):
	(left, right) = (0, n)
	while right - left > 1:
		middle = (left + right) // 2
		if a[middle] <= x:
			left = middle
		else:
			right = middle
	return left
n = int(input())
a = sorted(list(map(int, input().split())))
answer = 0
for i in range(n):
	j = bin_search(a, a[i] + 5)
	answer = max(answer, j - i + 1)
print(answer)


n = int(input())
a = sorted(map(int, input().split()))
ans = 0
ref = 0
for i in range(n):
	while abs(a[i] - a[ref]) > 5:
		ref += 1
	ans = max(ans, abs(i - ref) + 1)
print(ans)


from sys import stdin
from collections import defaultdict, Counter
from bisect import bisect_left
from math import sqrt
from heapq import *

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
t = 1
while t:
	t -= 1
	n = iinput()
	a = linput()
	a.sort()
	(i, j) = (0, 1)
	mx = 1
	diff = 0
	while i < n and j < n:
		diff = a[j] - a[i]
		if diff <= 5:
			mx = max(mx, j - i + 1)
			j += 1
		else:
			i += 1
	print(mx)


n = int(input())
valores = [int(x) for x in input().split(' ')]
valores.sort()
pont2 = 0
ans = 0
for pont1 in range(len(valores)):
	while pont2 < n and valores[pont2] - valores[pont1] <= 5:
		pont2 += 1
	ans = max(ans, pont2 - pont1)
print(ans)


n = int(input(''))
s = list(map(int, input('').split()))
t = {}
for i in s:
	t[i + 0.5] = 0
	t[i + 1.5] = 0
	t[i + 2.5] = 0
	t[i - 0.5] = 0
	t[i - 1.5] = 0
	t[i - 2.5] = 0
for i in s:
	t[i + 0.5] += 1
	t[i + 1.5] += 1
	t[i + 2.5] += 1
	t[i - 0.5] += 1
	t[i - 1.5] += 1
	t[i - 2.5] += 1
print(max(t.values()))


t = input()
m = list(map(int, input().split()))
m.sort()
(i, j) = (0, 1)
current_max = 0
while i < len(m) - 1 and j < len(m):
	if abs(m[i] - m[j]) <= 5:
		j += 1
	else:
		if j - i > current_max:
			current_max = j - i
		i += 1
		j -= 1
		if j <= i:
			j = i + 1
	if j - i >= len(m) - i:
		break
if j - i > current_max:
	current_max = j - i
print(current_max)


input()
lis = list(map(int, input().split()))
lis.sort()
ma = 0
dic = {}
for i in range(len(lis)):
	num = lis[i]
	temp = 0
	if num in dic:
		dic[num] += 1
	else:
		dic[num] = 1
	for j in range(6):
		if num - j in dic:
			temp += dic[num - j]
	ma = max(ma, temp)
print(ma)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
m = 0
from bisect import bisect
for i in range(n):
	m = max(m, bisect(a, a[i] + 5) - i)
print(m)


import sys
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
arr.sort()
a = []
maxx = 1
count = 1
i = 0
j = 1
flag = 0
while i < n and j < n:
	if arr[j] - arr[i] <= 5:
		maxx = max(maxx, j - i + 1)
	else:
		i += 1
	j += 1
print(maxx)


n = int(input())
A = list(map(int, input().split()))
A.sort()
j = 0
k = 0
for i in range(n):
	if A[i] - A[j] > 5:
		j += 1
	if i - j + 1 > k:
		k = i - j + 1
print(k)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
n = ii()
a = li()
d = collections.Counter(a)
dk = sorted(d.keys())
if min(dk) >= max(dk) - 5:
	print(n)
else:
	ans = 1
	lendk = len(dk)
	for i in range(lendk):
		temp = 0
		t = dk[i]
		k = 0
		while t <= dk[i] + 5:
			temp += d[t]
			k += 1
			if t == dk[-1]:
				break
			else:
				t = dk[i + k]
		ans = max(ans, temp)
	print(ans)


from collections import Counter
n = int(input())
lvls = Counter((int(i) for i in input().split()))
max_size = 0
for i in sorted(lvls.keys()):
	size = lvls[i] + lvls[i + 1] + lvls[i + 2] + lvls[i + 3] + lvls[i + 4] + lvls[i + 5]
	max_size = max(max_size, size)
print(max_size)


n = int(input())
l = list(map(int, input().strip().split()))

def mergelists(l, r):
	if isinstance(l, int):
		mx = max(l, r)
		mn = min(l, r)
		return [mn, mx]
	li = 0
	ri = 0
	ans = []
	while li < len(l) and ri < len(r):
		if l[li] < r[ri]:
			ans.append(l[li])
			li += 1
		else:
			ans.append(r[ri])
			ri += 1
	if li == len(l):
		ans.extend(r[ri:])
	else:
		ans.extend(l[li:])
	return ans

def mergesort(l):
	length = len(l)
	if length == 0:
		return []
	i = 0
	ans = []
	while i < length - 1:
		ans.append(mergelists(l[i], l[i + 1]))
		i += 2
	if length % 2 and isinstance(l[length - 1], int):
		ans.append([l[length - 1]])
	elif length % 2:
		ans.append(l[length - 1])
	if len(ans) == 1:
		return ans[0]
	else:
		return mergesort(ans)
l = mergesort(l)
count = []
cur = l[0]
c = 0
for i in l:
	if i == cur:
		c += 1
	else:
		count.append([cur, c])
		c = 1
		cur = i
count.append([cur, c])
mx = 0
for i in range(len(count)):
	j = i
	t = 0
	while 1:
		if count[j][0] - count[i][0] > 5:
			break
		else:
			t += count[j][1]
		j += 1
		if j == len(count):
			break
	mx = max(mx, t)
print(mx)


def bal_t(n, arr):
	m = 1
	arr.sort()
	j = 1
	for i in range(n):
		while j < n and arr[j] - arr[i] <= 5:
			j += 1
		if j - i > m:
			m = j - i
	return m
a = int(input())
b = list(map(int, input().strip().split()))
print(bal_t(a, b))


from sys import stdin
from bisect import bisect_right as br
n = int(stdin.readline().strip())
s = list(map(int, stdin.readline().strip().split()))
s.sort()
ans = 0
for i in s:
	x = br(s, i - 1)
	y = br(s, i + 5)
	ans = max(ans, y - x)
print(ans)


n = int(input())
nums = list(map(int, input().split()))
nums.sort()
p1 = 1
m = 0
for i in range(len(nums)):
	while p1 < len(nums) and nums[p1] - nums[i] <= 5:
		p1 += 1
	if p1 - i > m:
		m = p1 - i
	p1 = max(p1 - 1, i + 1)
print(m)


import bisect
n = int(input())
(a, b, c, i, l, s, st, lt) = (0, 0, 0, 0, [], [], [], [])
lst = sorted(list(map(int, input().split())))
while i <= n - 1:
	a = bisect.bisect_right(lst, lst[i] + 5)
	l.append(a - i)
	i += 1
print(max(l))


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
n = ii1()
arr = sorted(iia())
(p, res) = (0, 1)
for i in range(1, n):
	if arr[i] - arr[p] > 5:
		res = max(res, i - p)
		for j in range(p + 1, i):
			if arr[i] - arr[j] <= 5:
				p = j
				break
		else:
			p = i
if n > 1:
	res = max(res, i - p + 1)
print(res)


n = int(input())
a = sorted([int(x) for x in input().split()])
r = 0
ans = 1
for i in range(0, n):
	while r < n and a[r] - a[i] <= 5:
		r += 1
	ans = max(ans, r - i)
print(max(ans, r - i))


n = int(input())
team = list(map(int, input().split()))
team.sort()
left = 0
right = 0
max_size = 0
curr_size = 0
for left in range(n):
	while right < n and team[right] - team[left] <= 5:
		curr_size += 1
		right += 1
	max_size = max(max_size, curr_size)
	curr_size -= 1
print(max_size)


n = int(input())
a = list(map(int, input().split()))
l = 0
r = 1
br = 0
brm = 1
a.sort()
while r < n:
	if a[r] - a[l] <= 5:
		r = r + 1
		br = r - l
	else:
		l = l + 1
		if l == r:
			r = r + 1
	brm = max(brm, br)
print(brm)


n = int(input())
lis = sorted(map(int, input().split()))
f = 0
l = f + 1
ans = []
while l < n:
	if lis[l] - lis[f] <= 5:
		l += 1
	else:
		ans.append(l - f)
		f += 1
ans.append(l - f)
print(max(ans))


n = int(input())
a = list(map(int, input().split(' ')))
a = sorted(a)
b = list(set(a))
b = sorted(b)
count = [0] * len(b)
indx = 0
count[0] = 1
for i in range(1, n):
	if a[i] != a[i - 1]:
		indx += 1
	count[indx] += 1
ln = 0
for i in range(len(b)):
	j = i
	tl = 0
	while j < len(b) and b[j] <= b[i] + 5:
		tl += count[j]
		j += 1
	ln = max(ln, tl)
print(ln)


from bisect import bisect_right
import sys

def input():
	return sys.stdin.readline().rstrip()

def slv():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	dp = [[0] * (k + 1) for i in range(n + 1)]
	ans = 0
	for ni in range(1, n + 1):
		v = a[ni - 1]
		cnt = bisect_right(a, v - 6)
		for gi in range(1, k + 1):
			dp[ni][gi] = dp[cnt][gi - 1] + (ni - cnt)
			dp[ni][gi] = max(dp[ni][gi], dp[ni][gi - 1], dp[ni - 1][gi])
	ans = max((dp[ni][k] for ni in range(1, n + 1)))
	print(ans)
	return

def main():
	t = 1
	for i in range(t):
		slv()
	return
main()


n = int(input())
a = list(map(int, input().split()))
a.sort()
m = 0
j = 0
for i in range(0, n):
	if a[i] - a[j] > 5:
		j += 1
		if i - j + 1 > m:
			m = i - j + 1
if i - j + 1 > m:
	m = i - j + 1
print(m)


n = int(input())
a = sorted(map(int, input().split()))
m_l = 0
l = 0
r = 0
while l < n:
	while r < n and a[r] - a[l] <= 5:
		r += 1
	if r == n:
		m_l = max(m_l, r - l)
		break
	m_l = max(m_l, r - l)
	while l < n and l <= r and (a[r] - a[l] > 5):
		l += 1
print(m_l)


GI = lambda : int(input())
GIS = lambda : map(int, input().split())
LGIS = lambda : list(GIS())

def main():
	n = GI()
	l = LGIS()
	l.sort()
	i = j = 0
	m = 0
	while j < n:
		while l[j] - l[i] > 5:
			i += 1
		j += 1
		m = max(j - i, m)
	print(m)
main()


students = int(input())
skills = [int(x) for x in input().split()]
skills.sort()
counter = 0
(l, r) = (0, 0)
arr = []
while r != len(skills):
	if skills[r] - skills[l] <= 5:
		counter = r - l + 1
		r += 1
		arr.append(counter)
	else:
		l += 1
print(max(arr))


n = int(input())
l = list(map(int, input().split()))
l.sort()
i = k = ans = 0
while i < n - 1 and k < n:
	if l[i + 1] - l[k] <= 5:
		i = i + 1
		ans = max(ans, i - k)
	else:
		k = k + 1
print(ans + 1)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
(l, r, ans) = (0, 0, 0)
while l != n and r != n:
	if a[r] - a[l] <= 5:
		ans = max(ans, r - l + 1)
		r += 1
	else:
		l += 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
maxs = 1
min_el = l[0]
min_ind = 0
s = 1
for i in range(1, len(l)):
	if l[i] - min_el <= 5:
		s += 1
	else:
		min_el = l[min_ind + 1]
		min_ind = min_ind + 1
	maxs = max(maxs, s)
maxs = max(maxs, s)
print(maxs)


def bin_search(k):
	upper = n
	lower = i
	while upper != lower:
		mid = (upper + lower) // 2
		if list_1[mid] > k:
			upper = mid
		else:
			lower = mid + 1
	return lower
n = int(input())
list_1 = [int(i) for i in input().split()]
list_1.sort()
ans = 0
for i in range(n):
	ans = max(ans, bin_search(list_1[i] + 5) - i)
print(ans)


def main():
	from bisect import bisect_right
	n = int(input())
	a = sorted([int(i) for i in input().split()])
	ans = 1
	for l in range(n):
		r = bisect_right(a, a[l] + 5)
		ans = max(r - l, ans)
	print(ans)
main()


def main():
	n = int(input())
	skills = list(map(int, input().split()))
	skills.sort()
	skill_dict = {}
	for i in skills:
		if i not in skill_dict.keys():
			skill_dict[i] = 1
		else:
			skill_dict[i] += 1
	max_count = 0
	for i in skill_dict.keys():
		count = skill_dict[i]
		if i + 1 in skill_dict.keys():
			count += skill_dict[i + 1]
		if i + 2 in skill_dict.keys():
			count += skill_dict[i + 2]
		if i + 3 in skill_dict.keys():
			count += skill_dict[i + 3]
		if i + 4 in skill_dict.keys():
			count += skill_dict[i + 4]
		if i + 5 in skill_dict.keys():
			count += skill_dict[i + 5]
		if count > max_count:
			max_count = count
	print(max_count)
main()


from collections import defaultdict
n = int(input())
s = list(map(int, input().split(' ')))
diff = 5
d = defaultdict(int)
t_max = 0
for elem in s:
	d[elem] += 1
for key in list(d):
	key = int(key)
	curr = 0
	for i in range(0, 6):
		curr += d[key + i]
	t_max = max(t_max, curr)
print(t_max)


n = input()
n = int(n)
a = input()
a = [int(i) for i in a.split()]
a.sort()
_min = 0
_max = 0
_dict = {}
for i in a:
	if _min < i - 5:
		_max = max(_max, sum(_dict.values()))
		_dict = {key: value for (key, value) in _dict.items() if key >= i - 5}
	_dict[i] = _dict[i] + 1 if i in _dict else 1
_max = max(_max, sum(_dict.values()))
print(_max)


(num, sortedArr, right, result) = (int(input()), sorted(list(map(int, input().split()))), 0, 0)
for left in range(len(sortedArr)):
	while right < num and sortedArr[right] - sortedArr[left] <= 5:
		(right, result) = (right + 1, max(result, right - left + 1))
print(result)


siz = int(input())
ans = 1
s = sorted(map(int, input().split()))
(head, tail, ans) = (0, 0, 0)
while tail < siz:
	while tail < siz and s[tail] - s[head] <= 5:
		tail += 1
	ans = max(ans, tail - head)
	head += 1
print(ans)


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class BinaryTrie:

	class Node:

		def __init__(self, bit: bool=False):
			self.bit = bit
			self.children = []
			self.count = 0
			self.counter = 1

	def __init__(self, size):
		self.root = BinaryTrie.Node()
		self.size = size

	def convert(self, key):
		bits = []
		if isinstance(key, int):
			key = bin(key)[2:]
		if isinstance(key, str):
			for i in range(self.size - len(key)):
				bits += [False]
			for i in key:
				if i == '0':
					bits += [False]
				else:
					bits += [True]
		else:
			return list(key)
		return bits

	def add(self, key):
		node = self.root
		bits = self.convert(key)
		for bit in bits:
			found_in_child = False
			for child in node.children:
				if child.bit == bit:
					child.counter += 1
					node = child
					found_in_child = True
					break
			if not found_in_child:
				new_node = BinaryTrie.Node(bit)
				node.children.append(new_node)
				node = new_node
		node.count += 1

	def remove(self, key):
		node = self.root
		bits = self.convert(key)
		nodelist = [node]
		for bit in bits:
			for child in node.children:
				if child.bit == bit:
					node = child
					node.counter -= 1
					nodelist.append(node)
					break
		node.count -= 1
		if not node.children and (not node.count):
			for i in range(len(nodelist) - 2, -1, -1):
				nodelist[i].children.remove(nodelist[i + 1])
				if nodelist[i].children or nodelist[i].count:
					break

	def query(self, prefix, root=None):
		if not root:
			root = self.root
		node = root
		if not root.children:
			return 0
		for bit in prefix:
			bit_not_found = True
			for child in node.children:
				if child.bit == bit:
					bit_not_found = False
					node = child
					break
			if bit_not_found:
				return 0
		return node

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.data = 0
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key, val):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
			pCrawl.data += val
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		c = 0
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None

	def present(self, key):
		ans = 0
		pCrawl = self.root
		length = len(key)
		c = 0
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
			ans += pCrawl.data
		if pCrawl != None:
			return ans
		return -1
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
dp = [[0 for i in range(k + 1)] for j in range(n + 1)]
prev = [0 for i in range(n)]
for i in range(n):
	for j in range(i, -1, -1):
		if l[i] - l[j] <= 5:
			prev[i] = j
for i in range(k + 1):
	dp[0][i] = 0
for i in range(1, n + 1):
	for j in range(1, k + 1):
		dp[i][j] = max(dp[i - 1][j - 1] + 1, dp[i - 1][j], dp[prev[i - 1]][j - 1] + i - prev[i - 1])
print(dp[n][k])


n = int(input())
b = list(map(int, input().split()))
dic = {}
a = []
for i in b:
	try:
		if dic[i]:
			dic[i] += 1
	except KeyError:
		dic[i] = 1
		a.append(i)
a.sort()
n = len(a)
res = 0
for i in range(n):
	left = max(0, i - 3)
	right = min(i + 2, n - 1) + 1
	count = 0
	for j in range(left, right):
		if abs(a[left] - a[j]) <= 5:
			count += dic[a[j]]
		else:
			break
	res = max(res, count)
print(res)


n = int(input())
skill = [int(i) for i in input().split()]
skill.sort()
first = 0
maxi = 1
for i in range(1, n):
	if skill[i] - skill[first] > 5:
		if maxi < i - first:
			maxi = i - first
		while skill[i] - skill[first] > 5:
			first += 1
	elif i == n - 1:
		if maxi < i + 1 - first:
			maxi = i + 1 - first
print(maxi)


students = int(input())
skills = [int(x) for x in input().split()]
skills.sort()
max_team = 0
(l, r) = (0, 0)
while r != students:
	if skills[r] - skills[l] > 5:
		l += 1
	else:
		max_team = max(max_team, r - l + 1)
		r += 1
print(max_team)


import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
(l, r) = (0, 1)
cur = 0
while r < n:
	if arr[r] - arr[l] <= 5:
		if cur < r - l:
			cur = r - l
		r += 1
	else:
		l += 1
print(cur + 1)


def valid(m, l, n):
	for i in range(0, n - m + 1):
		if l[i + m - 1] - l[i] <= 5:
			return True
	return False
n = int(input())
l = list(map(int, input().strip().split()))
l.sort()
low = 1
high = n
while low < high:
	m = low + (high - low + 1) // 2
	if valid(m, l, n):
		low = m
	else:
		high = m - 1
print(low)


from collections import Counter
from operator import itemgetter

def prepare_data():
	_ = input()
	team = [int(i) for i in input().split()]
	return sorted([(el, count) for (el, count) in Counter(team).items()], key=itemgetter(0))

def find_max_team_count(countered_and_sorted_team):
	left_pointer = countered_and_sorted_team[0][0]
	left_pointer_idx = 0
	left_pointer_count = countered_and_sorted_team[0][1]
	current_sum = countered_and_sorted_team[0][1]
	max_sum = countered_and_sorted_team[0][1]
	for i in countered_and_sorted_team[1:]:
		while i[0] - left_pointer > 5:
			left_pointer_idx += 1
			current_sum -= left_pointer_count
			left_pointer = countered_and_sorted_team[left_pointer_idx][0]
			left_pointer_count = countered_and_sorted_team[left_pointer_idx][1]
		current_sum += i[1]
		if current_sum > max_sum:
			max_sum = current_sum
	return max_sum
countered_and_sorted_team = prepare_data()
max_sum = find_max_team_count(countered_and_sorted_team)
print(max_sum)


from bisect import bisect_right
n = int(input())
A = sorted(list(map(int, input().split())))
mx = 0
for i in range(n):
	th = A[i] + 5
	idx = bisect_right(A, th)
	mx = max(mx, idx - i)
print(mx)


import bisect
n = int(input())
a = list(sorted(map(int, input().split())))
ans = 0
for i in range(n):
	x = bisect.bisect_right(a, a[i] + 5, 0, len(a)) - i
	ans = max(ans, x)
print(ans)


N = int(input())
A = list(map(int, input().split()))
A.sort()
lo = 0
a_table = dict()
for a in A:
	if a not in a_table:
		a_table[a] = 1
	else:
		a_table[a] += 1
optimal = 0
for (key, val) in a_table.items():
	result = 0
	for i in range(key, key + 6):
		if i in a_table:
			result += a_table[i]
	optimal = max(optimal, result)
print(optimal)


import bisect
n = int(input())
array = list(map(int, input().strip().split()))
max_len = 0
array = sorted(array)
for i in range(len(array)):
	j = bisect.bisect(array, array[i] + 5)
	if j - i > max_len:
		max_len = j - i
print(max_len)


def sol(a):
	a.sort()
	max = 1
	k = len(a)
	j = k - 1
	i = k - 2
	num = 1
	if a == []:
		return 0
	while i >= 0 and j >= 0:
		if j - i == 1:
			if a[j] - a[i] <= 5:
				num = num + 1
				i = i - 1
				if num >= max:
					max = num
			else:
				j = j - 1
				num = 1
				i = i - 1
		elif a[j] - a[i] <= 5:
			num = num + 1
			i = i - 1
			if num >= max:
				max = num
		else:
			num = num - 1
			j = j - 1
	return max
n = input('')
k = list(map(int, input().split(' ')))
print(sol(k))


from collections import Counter
n = int(input())
ls = list(map(int, input().split()))
count = dict(Counter(ls))
ls = sorted(list(set(ls)))
Sum = []
for i in ls:
	res = 0
	for j in range(6):
		try:
			res += count[i + j]
		except:
			pass
	Sum.append(res)
print(max(Sum))


from collections import Counter
n = int(input())
l = list(map(int, input().split()))
dic = Counter(l)
k = set(l)
final = sorted(k)
maxi = 0
for i in range(len(final)):
	count = dic[final[i]]
	check = final[i]
	for j in range(i + 1, i + 6):
		if j < len(final):
			if final[j] - check <= 5:
				count += dic[final[j]]
			else:
				break
	if maxi < count:
		maxi = count
print(maxi)


n = int(input())
a = [int(x) for x in input().split()]
d = {}
for i in a:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
ans = -float('inf')
for i in d:
	aux = 0
	for j in range(6):
		if i + j in d:
			aux += d[i + j]
	ans = max(ans, aux)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
l = 0
lb = 0
rb = 0
nb = 0
for r in range(n):
	while a[r] - a[l] > 5:
		l += 1
	if r - l > nb:
		rb = r
		lb = l
		nb = r - l
print(nb + 1)


n = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
cur_min_idx = 0
cur_students = 1
idx = 1
while idx < n:
	if A[idx] - A[cur_min_idx] <= 5:
		cur_students += 1
		idx += 1
	else:
		cur_min_idx += 1
		cur_students -= 1
	ans = max(ans, cur_students)
ans = max(ans, cur_students)
print(ans)


n = int(input())
x = sorted(list(map(int, input().split())))
a = [x[0]]
max_len = 1
init = 0
for i in range(1, n):
	a.append(x[i])
	if x[i] - a[0 + init] > 5:
		init += 1
	elif len(a) > max_len:
		max_len = i + 1 - init
print(max_len)


def sol(n, skills):
	assert n == len(skills)
	skills.sort()
	max_team = 1
	j = 1
	for i in range(n):
		while j < n and abs(skills[i] - skills[j]) <= 5:
			j += 1
		max_team = max(max_team, j - i)
	print(max_team)

def test1():
	n = 6
	skills = [1, 10, 17, 12, 15, 2]
	sol(n, skills)

def test2():
	n = 10
	skills = list(map(int, '1337 1337 1337 1337 1337 1337 1337 1337 1337 1337'.split()))
	sol(n, skills)
n = int(input())
skills = list(map(int, input().split()))
sol(n, skills)


def solve(n, ll):
	ll.sort()
	mx = 0
	i = 0
	j = 0
	while i < n:
		while j < n and ll[j] - ll[i] <= 5:
			j += 1
			mx = max(mx, j - i)
		i += 1
	print(mx)
	return
n = int(input())
ll = list(map(int, input().split()))
solve(n, ll)


(n, a, d, mx) = (int(input()), list(map(int, input().split())), {}, 0)
s = set(a)
for i in a:
	if i not in d:
		d[i] = 0
	d[i] += 1
for i in s:
	res = 0
	t = i + 5
	for j in range(i, t + 1):
		if j in d:
			res += d[j]
	mx = max(mx, res)
print(mx)


from sys import stdin, stdout

def main():
	n = int(stdin.readline().strip())
	a = sorted([int(num) for num in stdin.readline().strip().split()])
	(l, r) = (0, 0)
	maxm = 1
	while l <= r and r < n - 1:
		r += 1
		if a[r] - a[l] > 5:
			while l < r and a[r] - a[l] > 5:
				l += 1
		maxm = max(maxm, r - l + 1)
	stdout.write(f'{maxm}')
main()


quantidade = int(input())
habilidades = list(map(int, input().split()))
habilidades.sort()
p2 = 0
time = 0
for i in range(len(habilidades)):
	while p2 < quantidade and habilidades[p2] - habilidades[i] <= 5:
		p2 += 1
	time = time if time > p2 - i else p2 - i
print(time)


cnt = lambda s, x: s.count(x)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
dgl = lambda : list(map(int, input()))
import bisect
n = ii()
l = sorted(il())
mx = 0
for i in range(n):
	x = bisect.bisect(l, l[i] + 5) - i
	mx = max(mx, x)
print(mx)


n = int(input())
l = list(map(int, input().split()))
l.sort()
li = []
cou = 0
j = 0
mx = -1
cu = 0
for i in l:
	li.append(i)
	cou += 1
	if i - li[j] <= 5:
		cu += 1
	else:
		if mx < cu:
			mx = cu
		cu = 0
		for k in range(j, cou):
			if i - li[k] <= 5:
				j = k
				cu = len(li) - k
				break
if mx < cu:
	mx = cu
print(mx)


from collections import deque
n = int(input())
array_a = list(map(int, input().split()))
array_a.sort()
answer = deque()
max_len = 0
for a in array_a:
	answer.append(a)
	if answer[-1] - answer[0] > 5:
		answer.popleft()
	max_len = max(max_len, len(answer))
print(max_len)


import sys
import math
from functools import reduce
import bisect

def getN():
	return int(input())

def getNM():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def input():
	return sys.stdin.readline().rstrip()

def index(a, x, pos):
	i = bisect.bisect(a, x) - 1
	if i == len(a) or i == 0:
		return -1
	return i - pos + 1
n = getN()
arr = sorted(getList())
ans = 1
for i in range(n):
	ans = max(ans, index(arr, arr[i] + 5, i))
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
j = 0
ans = 0
for i in range(n):
	while j < n and a[j] - a[i] <= 5:
		j = j + 1
	ans = max(ans, j - i)
	if ans > n - i - 1:
		break
print(ans)


n = int(input())
if n == 0:
	print(0)
	exit()
arr = input().split(' ')
arr = [int(a) for a in arr]
arr.sort()
max_diff = 5
(count, max_count) = (1, 1)
(current_elem, current_index) = (arr[0], 0)
for i in range(len(arr)):
	if i == 0:
		continue
	if arr[i] - current_elem > max_diff:
		max_count = max(max_count, count)
		current_index += 1
		if current_index < n:
			current_elem = arr[current_index]
	else:
		count += 1
max_count = max(max_count, count)
print(max_count)


n = int(input())
a = sorted([int(x) for x in input().split()])
i = 0
j = 0
maxi = -1
while i < n and j < n:
	if a[j] - a[i] <= 5:
		j += 1
	else:
		if maxi < j - i:
			maxi = j - i
		i += 1
if maxi < j - i:
	maxi = j - i
print(maxi)


n = int(input())
l = list(map(int, input().split()))
l.sort()
l.append(2 * 10 ** 9)
r = 0
ans = 0
for i in range(n):
	while l[r] - l[i] <= 5:
		r += 1
	ans = max(r - i, ans)
print(ans)


import sys
from collections import Counter

def i_ints():
	return map(int, sys.stdin.readline().split())
(n, k) = i_ints()
c = Counter(i_ints())
c2 = dict()
a = sorted(c)
for i in sorted(a):
	c2[i] = sum((c[j] for j in range(i, i + 6)))
len_a = len(a)
next_group = [-1] * len(a)
for i in range(len_a):
	for j in range(i + 1, len_a):
		if a[j] > a[i] + 5:
			next_group[i] = j
			break
maxes = [0] * n
for ii in range(k):
	old_maxes = maxes
	old_maxes.append(0)
	maxes = []
	for (i, aa) in enumerate(a):
		maxes.append(c2[a[i]] + old_maxes[next_group[i]])
	m = 0
	for i in range(len(a) - 1, -1, -1):
		if maxes[i] > m:
			m = maxes[i]
		else:
			maxes[i] = m
print(max(maxes))


import bisect
n = int(input())
cl = sorted(list(map(int, input().split())))
mx = 1
for i in range(n):
	pos = bisect.bisect_right(cl, cl[i] + 5)
	if pos - i + 1 > mx:
		mx = pos - i
print(mx)


n = int(input())
skils = input().split()
skils = [int(x) for x in skils]
skils.sort()
resposta = 0
j = 0
for i in range(len(skils)):
	while j < n and skils[j] - skils[i] <= 5:
		j += 1
	resposta = max(resposta, j - i)
print(resposta)


_ = input()
s_sort = sorted(list(map(int, input().split())))
max_count = 1
j = 0
for idx in range(0, len(s_sort)):
	while j < len(s_sort) and abs(s_sort[j] - s_sort[idx]) <= 5:
		j += 1
		max_count = max(max_count, abs(j - idx))
print(max_count)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l = r = 0
b = [0] * n
for _ in range(n):
	while l < r and a[r] - a[l] > 5:
		l += 1
	b[r] = l
	r += 1
dp = [[0 for _ in range(k + 1)] for _ in range(n)]
for i in range(1, k + 1):
	dp[0][i] = 1
for i in range(1, n):
	for j in range(1, k + 1):
		dp[i][j] = max(dp[i - 1][j], (dp[b[i] - 1][j - 1] if b[i] >= 1 else 0) + (i - b[i] + 1))
print(dp[-1][-1])


n = int(input())
u = list(map(int, input().split()))
u.sort()
d = [0] * n
ind = 0
k = 0
for i in range(n):
	if i != 0:
		k = d[i - 1] - 1
	while ind < n and u[ind] - 5 <= u[i]:
		k += 1
		ind += 1
	d[i] = k
print(max(d))


n = int(input())
a = list(map(int, input().strip().split()))
a = sorted(a)
max_size = 1
start = 0
end = 0
while start <= n - 1:
	while end <= n - 1 and a[end] <= a[start] + 5:
		end += 1
	end -= 1
	curr_size = end - start + 1
	if curr_size > max_size:
		max_size = curr_size
	start += 1
	if end < start:
		end = start
print(max_size)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
(p1, p2) = (0, 0)
r = 1
while p2 < n - 1:
	p2 += 1
	while a[p2] - a[p1] > 5:
		p1 += 1
	r = max(r, p2 - p1 + 1)
print(r)


n = int(input())
a = [int(x) for x in input().split(' ')]
a.sort()
i = 0
j = i
m = 0
while i < n:
	while j < n and a[j] - a[i] <= 5:
		j += 1
		m = max(m, j - i)
	i += 1
print(m)


n = int(input())
a = sorted(map(int, input().split()))
s = 0
e = -1
mx = 0
while s < n:
	e += 1
	while e < n - 1 and a[e + 1] - a[s] <= 5:
		e += 1
	mx = max(mx, e - s + 1)
	s += 1
print(mx)


n = int(input())
arr = sorted(list(map(int, input().split(' '))))
maximum = 1
pointer1 = 0
pointer2 = 1
while pointer1 < n and pointer2 < n:
	while pointer2 < n and arr[pointer2] - arr[pointer1] <= 5:
		pointer2 += 1
	length = pointer2 - pointer1
	if maximum < length:
		maximum = length
	pointer1 += 1
print(maximum)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
(l, r) = (0, 0)
cur = arr[l]
ans = 0
cnt = 0
for l in range(n):
	while r < n and arr[r] - arr[l] <= 5:
		r += 1
		ans = max(ans, r - l)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
index1 = 0
index2 = 1
ans = 1
size = 1
while index1 < n and index2 < n:
	if index2 == index1:
		size = 1
		index2 += 1
	elif arr[index2] - arr[index1] <= 5:
		index2 += 1
		size += 1
	else:
		ans = max(ans, size)
		index1 += 1
		size -= 1
ans = max(ans, size)
print(ans)


n = int(input())
l = sorted(map(int, input().split()))
g = 1
for i in range(n):
	for j in range(i + g, n):
		if l[j] - l[i] > 5:
			break
		if j - i + 1 > g:
			g = j - i + 1
print(g)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
i = 0
j = 0
ans = []
while i < n:
	while i < n and a[i] - a[j] < 6:
		i += 1
	ans.append(i - j)
	j += 1
print(max(ans))


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
(l, r) = (0, n - 1)
res = 0
for r in range(n):
	while a[r] - a[l] > 5:
		l += 1
	res = max(res, r - l + 1)
print(res)


n = int(input())
a = sorted(list(map(int, input().split())))
da = []
for i in range(n - 1):
	da.append(a[i + 1] - a[i])
sum = 0
maxcount = 0
tempcount = 0
for i in range(n - 1):
	if sum + da[i] <= 5:
		sum = sum + da[i]
		tempcount += 1
	else:
		sum = sum - da[i - tempcount] + da[i]
	maxcount = max(maxcount, tempcount)
print(maxcount + 1)


n = int(input())
arr = sorted(list(map(int, input().split())))
(pt1, pt2) = (0, 0)
ans = 0
while pt2 < n:
	while pt2 < n and arr[pt2] - arr[pt1] <= 5:
		pt2 += 1
	ans = max(ans, pt2 - pt1)
	while pt2 < n and arr[pt2] - arr[pt1] > 5:
		pt1 += 1
print(ans)


n = int(input())
arr = []
line = input().split()
for i in range(n):
	arr.append(int(line[i]))
if n == 1:
	print('1')
else:
	arr.sort()
	count = []
	c = 1
	start = 0
	for i in range(1, n):
		if arr[start] + 5 >= arr[i]:
			c += 1
		else:
			count.append(c)
			start = start + 1
			i = start + 1
	count.append(c)
	print(max(count))


def is_possible(d):
	for i in range(0, len(a) - d + 1):
		if a[i + d - 1] - a[i] <= 5:
			return True
	return False
n = int(input())
a = sorted(list(map(int, input().split())))
l = 0
r = n + 1
while r - l > 1:
	mid = (l + r) // 2
	if is_possible(mid):
		l = mid
	else:
		r = mid
print(l)


import math

def solve():
	n = int(input())
	arr = list(map(int, input().strip().split()))
	arr.sort()
	ans = 0
	l = 0
	for r in range(n):
		while arr[r] - arr[l] > 5:
			l += 1
		if r - l + 1 > ans:
			ans = r - l + 1
	return ans
print(solve())


n = int(input())
a = list(map(int, input().split()))
a.sort()
a.append(a[-1] + 10)
i = 0
ci = 1
ml = 0
while ci < n + 1:
	if a[ci] - a[i] <= 5:
		ci += 1
	else:
		ml = max(ml, ci - i)
		i += 1
print(ml)


n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)
mx = 0
for i in range(len(a)):
	(l, r) = (i, n)
	tof = a[i] + 5
	while r - l > 1:
		c = round((l + r) / 2)
		if a[c] <= tof:
			l = c
		else:
			r = c
	if r != n and a[r] < tof:
		l = r
	if l - i + 1 > mx:
		mx = l - i + 1
print(mx)


n = int(input())
lst = list(map(int, input().split()))
lst.sort()
i = 0
j = 0
m = 0
while j < n:
	if lst[j] - lst[i] <= 5:
		m = max(m, j - i + 1)
		j = j + 1
	else:
		i = i + 1
print(m)


I = lambda : map(int, input().split())
n = int(input())
a = list(I())
d = {}
for i in a:
	d[i] = d.get(i, 0) + 1
x = sorted(list(d.keys()))
maxx = 0
i = 0
j = 0
s = 0
while i != len(x):
	if abs(x[i] - x[j]) > 5:
		i = j + 1
		j += 1
		s = 0
	else:
		s += d[x[i]]
		i += 1
		maxx = max(maxx, s)
print(maxx)


n = int(input())
arr = list(map(int, input().split()))
i = 0
arr.sort()
j = 0
m = 0
for j in range(n):
	while arr[j] - arr[i] > 5:
		i += 1
	m = max(m, j - i + 1)
	j += 1
print(m)


from collections import Counter

def main():
	n = int(input())
	a = list(map(int, input().split()))
	counter = Counter()
	for x in a:
		counter[x] += 1
	ret = 0
	for x in a:
		tmp = 0
		for i in range(6):
			tmp += counter[x + i]
		ret = max(ret, tmp)
	print(ret)
main()


from bisect import bisect_right as br
n = int(input())
a = list(map(int, input().split()))
a.sort()
cnt = -10 ** 9
for i in range(n):
	cnt = max(cnt, br(a, a[i] + 5) - i)
print(cnt)


from sys import stdin
from sys import stdout
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
a.sort()
a.append(10000000000)
f = 0
m = 0
for i in range(n):
	if a[i] - a[f] > 5:
		f += 1
	elif i - f + 1 > m:
		m = i - f + 1
print(m)


import io
import os
import sys

def main():
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	maxFromI = [0] * n
	end = -1
	for i in range(n):
		while end + 1 < n and a[end + 1] <= a[i] + 5:
			end += 1
		maxFromI[i] = end - i + 1
	dp = [[0] * (k + 1) for _ in range(n + 1)]
	for i in range(n):
		for j in range(k + 1):
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
			if j + 1 <= k:
				dp[i + maxFromI[i]][j + 1] = max(dp[i + maxFromI[i]][j + 1], dp[i][j] + maxFromI[i])
	print(dp[n][k])
main()


input()
a = [int(s) for s in input().split()]
a.sort()
tekcount = 0
i = 0
while a[0] + 5 >= a[i]:
	tekcount += 1
	i += 1
	if i >= len(a):
		break
maxcount = tekcount
for i in range(1, len(a)):
	if a[i] != a[i - 1]:
		j = i
		tekcount = 0
		while a[i] + 5 >= a[j]:
			tekcount += 1
			j += 1
			if j == len(a):
				break
		if tekcount > maxcount:
			maxcount = tekcount
print(maxcount)


n = int(input())
a = sorted(map(int, input().split(' ')))
i = j = m = 0
while j < n:
	while j < n and a[j] - a[i] < 6:
		j += 1
	m = max(m, j - i)
	i += 1
print(m)


from collections import Counter
from bisect import bisect
n = int(input())
skills = Counter(map(int, input().split()))
answer = 0
soreted_skills = sorted(skills)
max_difference = 5
for i in range(len(soreted_skills)):
	max_skill = soreted_skills[i] + max_difference
	j = bisect(soreted_skills, max_skill)
	answer = max(answer, sum((skills[skill] for skill in soreted_skills[i:j])))
print(answer)


n = int(input())
a = [int(x) for x in input().split()]
d = {}
for i in a:
	d[i] = d.get(i, 0) + 1
mx = 0
for i in list(d.keys()):
	tec = 0
	for j in range(0, 6):
		tec += d.get(i + j, 0)
	if tec > mx:
		mx = tec
print(mx)


(n, k) = map(int, input().split())
a = sorted(list(map(int, input().split())))
i = 0
j = 0
ans = 0
start = [0] * n
for _ in range(n):
	while j < i and a[i] - a[j] > 5:
		j += 1
	start[i] = j
	i += 1
dp = [[0] * (k + 1) for _ in range(n)]
for i in range(1, k + 1):
	dp[0][i] = 1
for i in range(1, n):
	for j in range(1, k + 1):
		lastgroup = 0
		if start[i] >= 1:
			lastgroup = dp[start[i] - 1][j - 1]
		dp[i][j] = max(dp[i - 1][j], lastgroup + (i - start[i]) + 1)
print(dp[-1][-1])


n = int(input())
a = list(map(int, input().split()))
d = {}
for c in a:
	d[c] = d.get(c, 0) + 1
b = []
mx = 0
for c in d:
	ans = 0
	for i in range(0, 6):
		ans += d.get(c + i, 0)
	if ans > mx:
		mx = ans
print(mx)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
if n == 1:
	print(1)
else:
	maxi = 1
	i = 0
	j = 1
	while i < n:
		while j < n and arr[j] - arr[i] <= 5:
			j += 1
		maxi = max(maxi, j - i)
		i += 1
	print(maxi)


n = int(input())
L = [int(x) for x in input().split()]
D = {}
for i in L:
	if i in D:
		D[i] += 1
	else:
		D[i] = 1
best = 0
for i in D:
	temp = 0
	for j in range(6):
		temp += D.get(i + j, 0)
	best = max(best, temp)
print(best)


def sol(n, a):
	a.sort()
	best = 1
	(i, j) = (0, 0)
	while i < n:
		while j < n and a[j] - a[i] <= 5:
			j += 1
		best = max(best, j - i)
		i += 1
	return best
n = int(input())
a = list(map(int, input().strip().split()))
print(sol(n, a))


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
a.sort()
t = 0
head = a[t]
count = 1
b = [1]
j = 1
while j <= n - 1:
	if a[j] - head <= 5:
		count += 1
		if j == n - 1:
			b.append(count)
	else:
		b.append(count)
		head = a[t + 1]
		t += 1
		j -= 1
		count -= 1
	j += 1
print(max(b))


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
index = {}
for i in range(n):
	index[a[i]] = i
dp = [[1] * (k + 1) for i in range(n + 1)]
for i in range(n + 1):
	dp[i][0] = 0
for i in range(k + 1):
	dp[0][i] = 0
for i in range(1, n + 1):
	for item in range(5, -1, -1):
		if a[i - 1] + item in index:
			counter = index[a[i - 1] + item] - i + 1
			break
	for j in range(k + 1):
		if i > 0:
			dp[i][j] = max(dp[i - 1][j], dp[i][j])
		if j < k:
			dp[i + counter][j + 1] = max(dp[i + counter][j + 1], dp[i - 1][j] + counter + 1)
print(dp[n][k])


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = 1
for i in range(n - 1):
	key = arr[i] + 5
	s = i
	e = n - 1
	l = -1
	while s <= e:
		mid = (s + e) // 2
		if arr[mid] <= key:
			if mid == n - 1 or arr[mid + 1] > key:
				l = mid
				break
			s = mid + 1
		else:
			e = mid - 1
	if l != -1:
		if l - i + 1 > ans:
			ans = l - i + 1
print(ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
(i, j) = (0, 0)
res = 1
while j < n:
	if arr[j] - arr[i] > 5:
		i += 1
		continue
	res = max(res, j - i + 1)
	j += 1
print(res)


def main():
	input()
	nums = sorted(map(int, input().split()))
	ft = 0
	ans = 0
	for ed in range(len(nums)):
		num = nums[ed]
		while num > nums[ft] + 5:
			ft += 1
		ans = max(ans, ed - ft + 1)
	print(ans)

def __starting_point():
	main()
__starting_point()


n = int(input())
a = list(map(int, input().split()))
m = 1
a.sort()
cur = 1
d = 0
l = 1
for i in range(1, n):
	d += a[i] - a[i - 1]
	if d <= 5:
		cur += 1
		m = max(m, cur)
	else:
		while d > 5:
			d -= a[l] - a[l - 1]
			l += 1
			cur -= 1
		if d <= 5:
			cur += 1
			m = max(m, cur)
print(m)


n = int(input())
s = list(map(int, input().rstrip().split()))
a = sorted(s)
ma = 0
i = 0
for j in range(n):
	while a[j] - a[i] > 5:
		i += 1
	ma = max(ma, j - i + 1)
print(ma)


n = int(input())
l = list(map(int, input().split()))
l.sort()
i = 0
j = 1
a = 1
while i < n and j < n:
	if l[j] - l[i] <= 5:
		j += 1
		a = max(a, j - i)
	else:
		i += 1
print(a)


from sys import stdin
from math import gcd
input = stdin.readline
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = 0
start = 0
end = 0
while start < n and end < n:
	if arr[end] - arr[start] < 6:
		ans = max(ans, end - start + 1)
		end += 1
	else:
		start += 1
print(ans)


for _ in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	i = 0
	j = 0
	max1 = 0
	while i < n and j < n:
		if l[j] - l[i] <= 5:
			j = j + 1
		else:
			max1 = max(j - i, max1)
			i = i + 1
	print(max(max1, j - i))


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 1
l = 0
r = 0
while l < n - 1:
	if l > r:
		r = l
	while r < n - 1:
		if a[l] < a[r + 1] - 5:
			break
		r += 1
	if r - l + 1 > ans:
		ans = r - l + 1
	l += 1
print(ans)


(n, a, ans) = (int(input()), sorted(map(int, input().split())), 1)
(p1, tem) = (0, 1)
for i in range(1, n):
	if a[i] - a[p1] <= 5:
		tem += 1
	else:
		for j in range(p1, i + 1):
			if a[i] - a[j] <= 5:
				tem = i - j + 1
				p1 = j
				break
	ans = max(tem, ans)
print(ans)


n = int(input())
a = sorted(map(int, input().split()))
(ans, L, R) = (0, 0, 0)
while L < n:
	while R < n and a[R] - a[L] <= 5:
		R += 1
		ans = max(ans, R - L)
	L += 1
print(ans)


n = int(input())
team = list(map(int, input().split()))
team = list(sorted(team))
left = 0
right = 1
res = 1
while right < n:
	if left == right:
		right += 1
		continue
	if team[right] - team[left] > 5:
		left += 1
	else:
		res = max(res, right - left + 1)
		right += 1
res = max(res, right - left)
print(res)


from sys import stdin
n = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
d = {}

def maxCount(a):
	freq = {}
	for i in range(n):
		if a[i] in freq:
			freq[a[i]] += 1
		else:
			freq[a[i]] = 1
	ans = 0
	for (key, value) in freq.items():
		m = freq[key]
		for i in range(1, 6):
			if key + i in freq:
				m += freq[key + i]
		ans = max(ans, m)
	return ans
print(maxCount(arr))


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict, deque, Counter, OrderedDict
import threading

def main():
	n = int(input())
	a = sorted([*map(int, input().split())])
	(x, y) = (0, 0)
	ans = 1
	while y < n:
		if a[x] <= a[y] <= a[x] + 5:
			y += 1
			ans = max(ans, y - x)
		else:
			x += 1
			if y < x:
				y = x
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
A = list(map(int, input().split()))
A.sort()
i = 0
j = 0
ANS = 0
while j < n:
	while j < n - 1 and A[j + 1] - A[i] <= 5:
		j += 1
	ANS = max(ANS, j - i + 1)
	i += 1
	j = max(j, i)
print(ANS)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = []
for i in range(1, n):
	ans += [a[i] - a[i - 1]]
i = 0
j = 0
sm = 0
mx = -1
while j < n - 1:
	sm += ans[j]
	while i <= j and sm > 5:
		sm -= ans[i]
		i += 1
	mx = max(mx, j - i + 1)
	j += 1
print(max(1, mx + 1))


n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
ans = 0
for i in range(n):
	(left, right) = (i, n)
	maxed = arr[i] + 5
	while right - left > 1:
		mid = round((right + left) / 2)
		if arr[mid] <= maxed:
			left = mid
		else:
			right = mid
	if right != n and arr[right] == maxed:
		left = right
	if left - i + 1 > ans:
		ans = left - i + 1
print(ans)


n = int(input())
l1 = list(map(int, input().split()))
l1.sort()
x1 = 0
x2 = 0
s = 0
temps = 0
while x2 < n:
	if l1[x2] - 5 <= l1[x1]:
		temps += 1
		x2 += 1
	else:
		if temps > s:
			s = temps
		while x1 < x2:
			if l1[x2] - 5 > l1[x1]:
				x1 += 1
				temps -= 1
			else:
				break
if temps > s:
	s = temps
print(s)


n = int(input())
a = [int(i) for i in input().split(' ')]
a.sort()
res = 1
testnow = []
testnow.append(a[0])
for i in a[1:]:
	if i > testnow[0] + 5:
		if len(testnow) > res:
			res = len(testnow)
		testnow.append(i)
		testnow = list(filter(lambda x: x >= i - 5, testnow))
	else:
		testnow.append(i)
if len(testnow) > res:
	res = len(testnow)
print(res)


n = int(input())
l = list(map(int, input().split()))
l.sort()
m = 1
tem = 1
k = 1
flag = 0
for i in range(n):
	while 1 and n > 1:
		if l[k] - l[i] <= 5:
			tem = tem + 1
			if tem > m:
				m = tem
			k = k + 1
		else:
			tem = k - i - 1
			break
		if k > n - 1:
			flag = 1
			break
	if flag == 1:
		break
print(m)


def stdin():
	entrada = list(map(int, input().split()))
	return entrada
n = stdin()[0]
skills = stdin()
skills.sort()
ans = 1
i = 0
for j in range(n):
	while i < j and skills[j] - skills[i] > 5:
		i += 1
	ans = max(ans, j - i + 1)
print(ans)


n = int(input())
ass = list(map(int, input().split(' ')))
numsd = {}
for a in ass:
	if a in numsd:
		numsd[a] += 1
	else:
		numsd[a] = 1
keys = sorted(numsd.keys())
nums = 0
l = len(keys)
for (indx, a) in enumerate(keys):
	temp = numsd[a]
	i = indx + 1
	while i < l and keys[i] <= a + 5:
		temp += numsd[keys[i]]
		i += 1
	if temp > nums:
		nums = temp
print(nums)


from collections import defaultdict
n = int(input())
skills = [int(x) for x in input().split(' ')]
d = defaultdict(int)
skills_set = set()
for skill in skills:
	d[skill] += 1
	skills_set.add(skill)
m = 0
keys = d.keys()
for key in skills_set:
	tmp = 0
	for i in range(key, key + 6):
		tmp += d[i]
	if tmp > m:
		m = tmp
print(m)


n = int(input())
t = list(map(int, input().split()))
t.sort()
l = 0
r = 0
u = 0
g = 0
if len(set(t)) == 1:
	print(n)
elif max(t) - min(t) <= 5:
	print(n)
else:
	while r < n:
		if t[r] - t[l] <= 5:
			r += 1
		else:
			if r - l > g:
				g = r - l
			l += 1
	if r - l > g:
		g = r - l
	print(g)


def main():
	(n, k) = map(int, input().split())
	a = sorted((int(i) for i in input().split()))
	upper_bound = [0] * n
	(i, j) = (0, 0)
	while j < n:
		if a[i] + 5 >= a[j]:
			j += 1
		else:
			i += 1
		upper_bound[i] = j
	dp = [[0] * (k + 1) for _ in range(n + 1)]
	for i in range(n - 1, -1, -1):
		for j in range(1, k + 1):
			x = upper_bound[i]
			dp[i][j] = max(1 + dp[i + 1][j - 1], dp[i + 1][j], x - i + dp[x][j - 1])
	print(dp[0][k])
main()


from sys import stdin, stdout
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
a.sort()
b = 0
j = 0
for i in range(n):
	while j < n and a[j] - a[i] <= 5:
		j = j + 1
		b = max(b, j - i)
stdout.write(str(b) + '\n')


import sys
n = int(sys.stdin.readline())
inp = str(sys.stdin.readline()).split()
prog = [int(x) for x in inp]
prog.sort()
ans = 1
mn = prog[0]
mx = mn + 5
i = 1
for j in range(1, len(prog)):
	i = j
	tmpMax = 1
	mx = prog[j - 1] + 5
	try:
		if prog[i + ans - 1] <= mx:
			i = i + ans - 1
			tmpMax = ans
			while i < len(prog):
				if prog[i] <= mx:
					tmpMax += 1
				else:
					if tmpMax > ans:
						ans = tmpMax
					break
				i += 1
			if tmpMax > ans:
				ans = tmpMax
	except:
		False
print(ans)


n = int(input())
b = [int(s) for s in input().split()]
b.sort()
i = 0
min = 0
j = 0
d = b[0]
cnt = 0
while i < n and j < n:
	if abs(b[j] - d) <= 5:
		cnt += 1
		j += 1
	else:
		i += 1
		cnt -= 1
		d = b[i]
	if cnt > min:
		min = cnt
print(min)


n = int(input(''))
s = [int(x) for x in input('').split(' ')]
s1 = sorted(s)
long = 1
ran = [1]
i = 0
long = 1
for i in range(n):
	while i + long <= n - 1:
		if s1[i + long] - s1[i] <= 5:
			long += 1
		else:
			break
print(long)


n = int(input())
arr = [int(x) for x in input().split()]
arr = sorted(arr)
j = 0
a = 0
for i in range(0, n):
	while j < n and arr[j] - arr[i] < 6:
		j = j + 1
		a = max(a, j - i)
print(a)


n = int(input())
s = list(map(int, input().split()))
d = {}
ans = 1
for i in s:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
for i in d.keys():
	su = 0
	for j in range(i, i + 6):
		if j in d:
			su += d[j]
	if su > ans:
		ans = su
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
result = 0
begin = 0
end = 0
while end != n:
	while a[end] - a[begin] > 5:
		begin += 1
	result = max(result, end - begin + 1)
	if a[end] - a[begin] <= 5:
		end += 1
print(result)


n = int(input())
array = list(map(int, input().rstrip().split()))
array.sort()
if array[-1] - array[0] <= 5:
	print(n)
else:
	maxm = 1
	i = 0
	j = 1
	while i < n:
		while j < n:
			if array[j] - array[i] <= 5:
				maxm = max(j - i + 1, maxm)
				j += 1
			else:
				i += 1
		else:
			print(maxm)
			break


total = int(input())
skill = list(map(int, input().split(' ')))
skill.sort()
ponteiro_um = 0
ponteiro_dois = 0
dis_global = 0
while ponteiro_dois < len(skill):
	distancia_local = ponteiro_dois - ponteiro_um
	if distancia_local > dis_global:
		dis_global = distancia_local
	if ponteiro_um == ponteiro_dois:
		ponteiro_dois += 1
	elif skill[ponteiro_dois] - skill[ponteiro_um] <= 5:
		ponteiro_dois += 1
	else:
		ponteiro_um += 1
distancia_fora = ponteiro_dois - ponteiro_um
if distancia_fora > dis_global:
	dis_global = distancia_fora
if ponteiro_dois == len(skill) and ponteiro_um == 0:
	print(len(skill))
else:
	print(dis_global)


def problem_1133c():
	nmax = 0
	n = int(input())
	a = input().split(' ')
	for (i, _) in enumerate(a):
		a[i] = int(a[i])
	a.sort()
	(i, j) = (0, 1)
	while i < n - 1 and j < n:
		if a[j] - a[j - 1] > 5:
			if j - 1 - i > nmax:
				nmax = j - 1 - i
			i = j
			j += 1
		elif a[j] - a[i] > 5:
			if j - 1 - i > nmax:
				nmax = j - 1 - i
			i += 1
			if i == j:
				j += 1
		else:
			j += 1
	if j - 1 - i > nmax:
		nmax = j - 1 - i
	print(nmax + 1)
	return
problem_1133c()


import sys
input = sys.stdin.buffer.readline
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = 0
j = 0
for i in range(n):
	while j < n and arr[j] - arr[i] <= 5:
		j += 1
		ans = max(ans, j - i)
print(ans)


n = int(input())
l = list([int(x) for x in input().split()])
l.sort()
mx = 0
c = 0
lb = 0
ub = 0
while ub < n:
	if l[ub] - l[lb] <= 5:
		c += 1
		ub += 1
	else:
		mx = max(c, mx)
		while l[ub] - l[lb] > 5:
			lb += 1
			c -= 1
mx = max(c, mx)
print(mx)


n = int(input())
A = list(map(int, input().split()))
z = {}
ans = 0
for i in range(n):
	if A[i] not in z:
		z[A[i]] = 0
	z[A[i]] += 1
for x in z:
	cnt = 0
	cnt += z[x]
	if x + 1 in z:
		cnt += z[x + 1]
	if x + 2 in z:
		cnt += z[x + 2]
	if x + 3 in z:
		cnt += z[x + 3]
	if x + 4 in z:
		cnt += z[x + 4]
	if x + 5 in z:
		cnt += z[x + 5]
	ans = max(ans, cnt)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
m = 1
l = 0
r = 0
k = 1
while r != n:
	if a[r] - a[l] > 5:
		m = max(m, k - 1)
		while a[r] - a[l] > 5:
			k -= 1
			l += 1
	r += 1
	k += 1
m = max(m, k - 1)
print(m)


a = int(input())
c = list(map(int, input().split()))
m = -6
c.sort()
ind = -1
nma = 1
for (i, v) in enumerate(c):
	if v - m > 5:
		while v - m > 5:
			ind += 1
			m = c[ind]
	if nma < i - ind + 1:
		nma = i - ind + 1
print(nma)


n = int(input())
l = list(map(int, input().rstrip().split(' ')))
l.sort()
dic = {}
c = 1
la = l[0]
for i in range(1, n):
	if l[i] == la:
		c = c + 1
	else:
		dic[la] = c
		c = 1
	la = l[i]
dic[la] = c
b = 0
for (j, k) in dic.items():
	t = 0
	for i in range(6):
		t += dic.get(j + i, 0)
	if b < t:
		b = t
print(b)


n = int(input())
a = [int(x) for x in input().strip().split()]
a.sort()
l = r = 0
biggest = 1
while r < n - 1:
	r += 1
	if a[r] - a[l] > 5:
		l += 1
	biggest = max(biggest, r - l + 1)
print(biggest)


def main():
	n = int(input())
	studs = sorted(list(map(int, input().split())))
	rez = 0
	beg = end = 0
	while end < len(studs):
		while studs[end] - studs[beg] > 5:
			beg += 1
		rez = max(rez, end - beg + 1)
		end += 1
	print(rez)
main()


from collections import Counter

def input_array(arr, struc):
	return list(map(struc, arr.split()))

def dictsort(counter, i):
	return sorted(counter.items(), key=lambda item: item[i])
n = int(input())
arr = input_array(input(), int)
counter = Counter(arr)
counter = dictsort(counter, 0)
a = [i for (i, j) in counter]
b = [j for (i, j) in counter]
pointer = 0
csum = final = b[0]
for i in range(1, len(a)):
	for j in range(pointer, i):
		if a[i] - 5 > a[pointer]:
			pointer += 1
		else:
			break
	csum = sum(b[pointer:i + 1])
	if csum > final:
		final = csum
print(final)


n = int(input())
stu = sorted([int(x) for x in input().split()])
index = {}
counter = 0
for i in range(n):
	index[stu[i]] = i
for item in range(n):
	i = 5
	while i >= 0:
		if stu[item] + i in index:
			counter = max(counter, index[stu[item] + i] - item + 1)
			break
		i -= 1
print(counter)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	(l, r) = (0, 0)
	mx = 0
	while l < len(a):
		while r < len(a) and a[r] <= a[l] + 5:
			r = r + 1
		mx = max(mx, r - l)
		l = l + 1
	print(mx)
main()


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
import heapq
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
n = ri(1)
a = ri()
k = dd(int)
for i in a:
	k[i] += 1
ans = -99999999
for i in range(n):
	now = a[i]
	temp = 0
	for i in range(0, 6, 1):
		temp += k[now + i]
	ans = max(temp, ans)
print(ans)


(n, k) = map(int, input().split())
dp = [[0 for j in range(k + 1)] for i in range(n + 1)]
a = sorted([int(i) for i in input().split()])
cnt = [0 for i in range(n)]
for i in range(n):
	while i + cnt[i] < n and a[i + cnt[i]] - a[i] <= 5:
		cnt[i] += 1
for i in range(n):
	for j in range(k + 1):
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
		if j + 1 <= k:
			dp[i + cnt[i]][j + 1] = max(dp[i + cnt[i]][j + 1], dp[i][j] + cnt[i])
print(dp[n][k])


import sys
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def read():
	tc = 0
	if tc:
		input = sys.stdin.readline
	else:
		sys.stdin = open('input1.txt', 'r')
		sys.stdout = open('output1.txt', 'w')

def solve():
	n = ii()
	a = li()
	a.sort()
	c = 1
	j = 0
	ans = 0
	for i in range(1, n):
		if a[i] - a[j] > 5:
			ans = max(ans, c)
			while a[i] - a[j] > 5:
				j += 1
			c = i - j + 1
		else:
			c += 1
	ans = max(ans, c)
	print(ans)
solve()


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = {}
for i in range(n):
	b[a[i]] = 0
for i in range(n):
	b[a[i]] += 1
c = []
s = 0
for i in b:
	s = 0
	for j in range(i, i + 6):
		if j in b.keys():
			s = s + b[j]
	c.append(s)
print(max(c))


import sys
import os
import collections
n = int(input())
a = input()
a = list(map(int, a.split()))
i = 0
max_ = -1
dick = {x: 0 for x in a}
while i < n:
	dick[a[i]] += 1
	i += 1
i = 0
while i < n:
	sum_ = 0
	for j in range(0, 6):
		sum_ += dick.get(a[i] + j, 0)
	max_ = max(max_, sum_)
	i += 1
print(max_)


n = int(input())
l = sorted(list(map(int, input().split(' '))))
max_len = 0
(f, s) = (0, 1)
if len(l) == 1:
	print(1)
else:
	while True:
		length = s - f
		try:
			while l[s] - l[f] <= 5:
				length += 1
				s += 1
		except IndexError:
			if length > max_len:
				max_len = length
			break
		else:
			if length > max_len:
				max_len = length
			f += 1
			if f >= n:
				break
	print(max_len)


n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
i = 0
j = 0
while j < n:
	while j < n and l[j] - l[i] < 6:
		j += 1
	ans = max(ans, j - i)
	i += 1
print(ans)


from sys import stdin, stdout

def inp():
	return int(stdin.readline())

def minp():
	return map(int, stdin.readline().rstrip().split())

def linp():
	return list(minp())

def main():
	n = inp()
	l = linp()
	l.sort(reverse=True)
	(m, ini) = (0, 0)
	mm = 0
	pos = 0
	f = 0
	while True:
		for i in range(ini, n):
			if abs(l[pos] - l[i]) <= 5:
				m += 1
				if i == n - 1:
					f = 1
			else:
				ini = i
				break
		if m > mm:
			mm = m
		if mm == n:
			break
		m = m - 1
		pos += 1
		if f == 1:
			break
	print(mm)
main()


n = int(input())
a = list(sorted(map(int, input().split())))
maxsize = 0
j = 0
for i in range(len(a)):
	while a[i] - a[j] > 5:
		j += 1
	maxsize = max(maxsize, i - j + 1)
print(maxsize)


n = int(input())
tab = list(map(int, input().split()))
tab.sort()
(p1, p2) = (0, 0)
najdluzszy = 0
while p1 < n:
	while p2 < n and tab[p2] - tab[p1] <= 5:
		p2 += 1
	najdluzszy = max(najdluzszy, p2 - p1)
	p1 += 1
print(najdluzszy)


n = int(input())
A = list(map(int, input().split()))
A.sort()
j = 0
ans = 0
for i in range(n):
	while j < n:
		if A[j] - A[i] <= 5:
			j += 1
		else:
			break
	ans = max(ans, j - i)
	if i == j:
		j += 1
print(ans)


def func(params):
	(n, lst) = params
	lst = sorted(lst)
	max_cnt = 0
	start = 0
	end = 0
	cnt = 0
	while True:
		if end > n - 1:
			if cnt > max_cnt:
				max_cnt = cnt
			break
		if lst[end] - lst[start] <= 5:
			cnt += 1
			end += 1
		else:
			if cnt > max_cnt:
				max_cnt = cnt
			start += 1
			cnt -= 1
	print(max_cnt)
params = [int(input()), list(map(int, input().split()))]
func(params)


import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(n):
	ans = max(ans, bisect.bisect_right(a, a[i] + 5) - i)
print(ans)


n = int(input())
a = sorted(map(int, input().split()))
r = 0
ans = 0
for l in range(n):
	while r < n:
		if a[r] - a[l] > 5:
			break
		r += 1
	ans = max(ans, r - l)
print(ans)


n = int(input())
l = sorted([int(i) for i in input().split()])
(i, j) = (0, 0)
m = 0
c = 0
while j < n:
	if l[j] - l[i] <= 5:
		c = j - i + 1
		j += 1
	else:
		m = max(m, c)
		c = 0
		i += 1
m = max(m, c)
print(m)


def strongTeam(students):
	bestTeam = 0
	count = 0
	pos1 = pos2 = 0
	while pos2 < len(students):
		if abs(students[pos2] - students[pos1]) <= 5:
			count += 1
			pos2 += 1
			bestTeam = max(bestTeam, count)
		else:
			pos1 += 1
			count -= 1
	return bestTeam

def main():
	n = int(input())
	students = list(map(int, input().split()))
	students = sorted(students)
	print(strongTeam(students))
main()


n = int(input())
l = sorted(list(map(int, input().split())))
r = 0
b = 0
for i in range(n):
	while r < n and l[r] - l[i] < 6:
		r = r + 1
	b = max(b, r - i)
print(b)


n = int(input())
m = list(map(int, input().split()))
mas = [0]
k = [0]
m.sort()
cou = 2
for i in range(n):
	if m[i] != mas[-1]:
		mas.append(m[i])
		k.append(1)
		cou += 1
	else:
		k[-1] += 1
ans = 0
an = 0
mas.append(mas[-1])
k.append(0)
for i in range(1, cou):
	an = k[i]
	for j in range(1, min(6, cou - i)):
		if mas[j + i] - mas[i] < 6:
			an += k[j + i]
		else:
			break
	ans = max(an, ans)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
left = 0
right = 0
ans = -1
arr.sort()
while right < n:
	if arr[right] - arr[left] <= 5:
		ans = max(ans, right - left + 1)
		right += 1
	else:
		left += 1
print(ans)


R = lambda : map(int, input().split())
n = int(input())
L = sorted(R())
(i, j) = (0, 0)
ma = 0
while j < n:
	while j < n and L[j] - L[i] <= 5:
		j += 1
	ma = max(ma, j - i)
	i += 1
print(ma)


n = input()
students = list(map(int, input().split()))
students = sorted(students)
i = j = 0
max_len = 0
while i < len(students):
	while j < len(students) and students[j] - students[i] <= 5:
		j += 1
	max_len = max(max_len, j - i)
	i += 1
print(max_len)


n = int(input())
arr = list(map(int, input().split()))
ptr = 0
mptr = 0
max = 0
arr.sort()
arr.append(100000)
for j in range(n):
	if abs(arr[mptr] - arr[j + 1]) <= 5:
		mptr = ptr
	else:
		sum = j - mptr + 1
		if sum > max:
			max = sum
		ptr += 1
		mptr = ptr
print(max)


n = int(input())
l = list(map(int, input().split()))
l.sort()
c = 1
i = 0
j = 1
while i < n and j < n:
	z = l[j] - l[i]
	if z <= 5:
		k = j - i + 1
		c = max(c, k)
		j = j + 1
	else:
		i = i + 1
	if i == j:
		j = j + 1
print(c)


n = int(input())
a = list(map(int, input().split()))
a.sort()
i = 0
j = 1
c = 0
mx = 0
while j < n:
	if i == j:
		j += 1
	elif abs(a[i] - a[j]) <= 5:
		c += 1
		j += 1
		mx = max(mx, c)
	else:
		i += 1
		if c > 0:
			c -= 1
print(mx + 1)


dp = []
for i in range(5005):
	dp.append([0] * 5005)
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
p = [0] * (n + 1)
for i in range(n):
	z = a[i] - 5
	for j in range(i + 1):
		if a[j] >= z:
			p[i] = j
			break
ans = -1
for i in range(1, n + 1):
	for j in range(k + 1):
		dp[i][j] = max(dp[i - 1][j], dp[p[i - 1]][j - 1] + (i - p[i - 1]))
		if j != k:
			ans = max(ans, dp[i][j])
print(ans)


from sys import stdin, stdout
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = 0
j = 0
for i in range(n):
	while j < n and a[j] - a[i] <= 5:
		j = j + 1
		b = max(b, j - i)
print(b)


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
nb_students = RI()
strengths = sorted(RMI())
maxs = 0
(last, curr) = (0, 0)
while curr < nb_students:
	while curr < nb_students and strengths[curr] - strengths[last] < 6:
		curr += 1
	maxs = max(maxs, curr - last)
	last += 1
print(maxs)


n = int(input())
alunos = input().split()
habilidades = [int(hab) for hab in alunos]
habilidades.sort()
s = 0
i = 0
j = 0
cont = 0
while i < n and j < n:
	while int(habilidades[j]) - int(habilidades[i]) <= 5:
		cont += 1
		j += 1
		if j == n:
			break
	if cont > s:
		s = cont
	i += 1
	cont -= 1
print(s)


N = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
j = 0
for i in range(N):
	while j < N and a[j] - a[i] <= 5:
		j += 1
		ans = max(ans, j - i)
print(ans)


from sys import stdin, stdout
n = int(stdin.readline())
a = sorted([int(x) for x in stdin.readline().split()])
m = 0
a = a + [1000000000000]
j = 0
for i in range(n):
	while a[j] <= 5 + a[i]:
		j += 1
	m = max(j - i, m)
stdout.write(str(m))


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = []
d = 0
c = a[0]
j = 0
for i in range(n):
	if abs(a[i] - c) <= 5:
		d += 1
	else:
		b.append(d)
		j += 1
		c = a[j]
b.append(d)
print(max(b))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
dp = [[0 for j in range(k + 1)] for i in range(n + 1)]
l = [0 for i in range(n + 1)]
(i, li) = (n - 1, n - 1)
while i >= 0:
	while li >= 0 and a[i] - 5 <= a[li]:
		li -= 1
	l[i + 1] = li + 1
	i -= 1
dp[1][1] = 1
for i in range(2, n + 1):
	for j in range(1, k + 1):
		dp[i][j] = max(dp[i - 1][j], dp[l[i]][j - 1] + i - l[i])
print(max((dp[n][j] for j in range(1, k + 1))))


n = int(input())
a = list(map(int, input().split()))
a.sort()
x = 0
sol = 0
for i in range(0, n):
	while a[i] - a[x] > 5:
		x = x + 1
	sol = max(sol, i - x + 1)
print(sol)


n = int(input())
p = [*map(int, input().split())]
p.sort()
mcon = 0
j = 0
for i in range(n):
	while j < n and p[j] - p[i] <= 5:
		j += 1
	mcon = max(mcon, j - i)
print(mcon)


n = int(input())
arr = sorted(map(int, input().split()))
freq = {}
for x in arr:
	freq[x] = freq.get(x, 0) + 1
arr = sorted(freq.keys())
j = 0
curr = 0
while j < len(arr) and abs(arr[j] - arr[0] <= 5):
	curr += freq[arr[j]]
	j += 1
i = 1
ans = curr
while i < len(arr):
	curr -= freq[arr[i - 1]]
	while j < len(arr) and abs(arr[j] - arr[i] <= 5):
		curr += freq[arr[j]]
		j += 1
	ans = max(ans, curr)
	i += 1
print(ans)


from collections import defaultdict as dfd
n = int(input())
arr = list(map(int, input().split()))
d = dfd(int)
dd = dfd(bool)
for i in arr:
	d[i] += 1
	dd[i] = True
arr = list(d.items())
arr.sort()
if len(arr) == 1:
	print(arr[0][1])
else:
	mx = max(d.values())
	crr = dfd(int)
	brr = dfd(int)
	brr = [arr[0][1]]
	crr[arr[0][0]] = arr[0][1]
	for i in range(1, len(arr)):
		brr.append(brr[-1] + arr[i][1])
		crr[arr[i][0]] = brr[-1]
	for i in range(len(arr)):
		if dd[arr[i][0] + 5]:
			mx = max(mx, crr[arr[i][0] + 5] - crr[arr[i][0]] + d[arr[i][0]])
		elif dd[arr[i][0] + 4]:
			mx = max(mx, crr[arr[i][0] + 4] - crr[arr[i][0]] + d[arr[i][0]])
		elif dd[arr[i][0] + 3]:
			mx = max(mx, crr[arr[i][0] + 3] - crr[arr[i][0]] + d[arr[i][0]])
		elif dd[arr[i][0] + 2]:
			mx = max(mx, crr[arr[i][0] + 2] - crr[arr[i][0]] + d[arr[i][0]])
		elif dd[arr[i][0] + 1]:
			mx = max(mx, crr[arr[i][0] + 1] - crr[arr[i][0]] + d[arr[i][0]])
	print(mx)


from collections import defaultdict

def solve(n, k, nums):
	nums.sort()
	new_nums = [0]
	for i in range(1, n):
		x = min(nums[i] - nums[i - 1], 6)
		new_nums.append(new_nums[-1] + x)
	cand_count = new_nums[-1] + 1
	candidates = [0] * cand_count
	for n in new_nums:
		for i in range(n - 5, n + 1):
			if 0 <= i < cand_count:
				candidates[i] += 1
	prev = [None] * cand_count
	max_val = 0
	for i in range(cand_count):
		max_val = max(max_val, candidates[i])
		prev[i] = max_val
	for ki in range(1, k):
		new = [None] * cand_count
		new[0:6] = prev[0:6]
		for i in range(6, cand_count):
			new[i] = max(new[i - 1], prev[i - 6] + candidates[i])
		prev = new
	print(prev[-1])

def solve_from_stdin():
	(n, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	solve(n, k, nums)

def test():
	(n, k) = (1000, 500)
	nums = list(range(n))
	solve(n, k, nums)
solve_from_stdin()


kk = lambda : map(int, input().split())
ll = lambda : list(kk())
(n, k) = kk()
ls = sorted(ll())
(vs, ne) = ([0] * n, [-1] * n)
b = 0
for a in range(n):
	while b < n and ls[b] - ls[a] < 6:
		b += 1
	(vs[a], ne[a]) = (b - a, b)
curr = [0] * (n + 1)
for _ in range(k):
	prev = curr
	curr = [0] * (n + 1)
	for i in range(n):
		curr[i] = vs[i] + prev[ne[i]]
	m = 0
	for i in range(n - 1, -1, -1):
		if m > curr[i]:
			curr[i] = m
		else:
			m = curr[i]
print(m)


import itertools
x = input()
x = input()
stds = []
for i in x.split():
	stds.append(int(i))
stds.sort()
ind1 = 0
ind2 = 0
ans = 0
while ind2 < len(stds):
	if stds[ind2] - stds[ind1] <= 5:
		ans = max(ans, ind2 - ind1 + 1)
	if stds[ind2] - stds[ind1] <= 5 or ind1 == ind2:
		ind2 += 1
	else:
		ind1 += 1
print(ans)


n = int(input())
A = list(map(int, input().strip().split()))
count = {}
A = sorted(A)
for a in A:
	try:
		count[a] += 1
	except:
		count[a] = 1
B = [A[0]]
A.pop(0)
for a in A:
	if a != B[-1]:
		B.append(a)
for i in range(len(B)):
	for j in range(i + 1, i + 6):
		try:
			if B[j] - B[i] <= 5 and B[j] != B[i]:
				count[B[i]] += count[B[j]]
		except:
			abc = 123
print(max(count.values()))


n = int(input())
a = list(map(int, input().split()))
a.sort()
cm = 0
ans = 1
i = 1
while i < n:
	if a[i] - a[cm] <= 5:
		i += 1
		ans = max(i - cm, ans)
	else:
		while cm <= i and a[i] - a[cm] > 5:
			cm += 1
print(ans)


n = int(input())
li = list(map(int, input().split()))
arr = sorted(li)
m = 1
j = 1
for i in range(n):
	while j < n:
		if arr[j] - arr[i] > 5:
			break
		j += 1
	m = max(j - i, m)
	if j == n - 1:
		break
print(m)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = 1
i = 0
c_len = 1
j = i + 1
while i < n - 1:
	j = max(i + 1, j)
	while j < n and arr[j] - arr[i] <= 5:
		j += 1
		c_len += 1
	ans = max(c_len, ans)
	i += 1
	c_len = max(1, c_len - 1)
print(ans)


n = int(input())
nums = sorted(map(int, input().split()))
pref = []
if n == 1:
	print('1')
else:
	for (i, j) in zip(nums[:-1], nums[1:]):
		pref.append(j - i)
	n -= 1
	l = 0
	r = 0
	prefix_sum = 0
	maximum = -1
	while r < n:
		while prefix_sum <= 5 and r < n:
			maximum = max(maximum, r + 1 - l)
			prefix_sum += pref[r]
			r += 1
		if r == n and prefix_sum <= 5:
			maximum = max(maximum, r + 1 - l)
		while prefix_sum > 5 and l <= r:
			prefix_sum -= pref[l]
			l += 1
	print(maximum)


n = int(input())
powers = list(map(int, list(input().split(' '))))
powers.sort()
(left, right) = (0, 0)
result = 0
while True:
	if left == right:
		right += 1
	if right == n:
		break
	if powers[right] - powers[left] <= 5:
		result = max(result, right - left + 1)
		right += 1
	else:
		left += 1
print(max(result, 1))


n = int(input())
a = sorted(list(map(int, input().split())))
arr = []
for i in range(n - 1):
	arr.append(a[i + 1] - a[i])
_sum = 0
cnt = 0
maxcnt = 0
for i in range(n - 1):
	if _sum + arr[i] <= 5:
		_sum += arr[i]
		cnt += 1
	elif sum != 0:
		_sum = _sum - arr[i - cnt] + arr[i]
	maxcnt = max(cnt, maxcnt)
print(maxcnt + 1)


import sys, bisect
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
arr.sort()
start = dict().fromkeys(set(arr), 9846543210)
ans = 0
for i in range(n):
	start[arr[i]] = min(start[arr[i]], i)
for (idx, i) in enumerate(arr):
	if start[i] == idx:
		temp = bisect.bisect_right(arr, i + 5)
		ans = max(temp - idx, ans)
print(ans)


import bisect
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
DP = [[0] * (k + 1) for i in range(n)]
for i in range(n):
	x = bisect.bisect_right(A, A[i] + 5) - 1
	for j in range(k - 1, -1, -1):
		DP[i][j] = max(DP[i][j], DP[i - 1][j])
		DP[x][j + 1] = max(DP[i - 1][j] + x - i + 1, DP[x][j + 1])
print(max([DP[i][-1] for i in range(n)]))


import sys
inf = float('inf')
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def main():
	n = int(input())
	arr = get_array()
	d = {}
	for i in arr:
		if i not in d:
			d[i] = 0
		d[i] += 1
	mx = 0
	curr = 0
	for i in d:
		curr = d[i]
		mx = max(mx, curr)
		for j in range(i + 1, i + 6):
			if j in d:
				curr += d[j]
				mx = max(mx, curr)
	print(mx)
main()


import sys
import math

def getAndParseInt(num=1):
	string = sys.stdin.readline().strip()
	if num == 1:
		return int(string)
	else:
		return [int(part) for part in string.split()]

def getAndParseString(num=1, delim=' '):
	string = sys.stdin.readline().strip()
	if num == 1:
		return string
	else:
		return [part for part in string.split(delim)]
n = getAndParseInt()
skills = getAndParseInt(2)
counts = {}
for skill in skills:
	counts[skill] = counts.get(skill, 0) + 1
maximum = 0
for (skill, count) in counts.items():
	current_total = 0
	lowest_skill = max(skill - 5, 1)
	for poss_skill in range(lowest_skill, skill + 1):
		current_total += counts.get(poss_skill, 0)
	maximum = max(current_total, maximum)
print(maximum)


n = int(input())
skills = list(map(int, input().split(' ')))
skills.sort()
count = 0
max_count = 0
first = 0
for i in range(len(skills)):
	if skills[i] - skills[first] > 5:
		if count > max_count:
			max_count = count
		count = count - 1
		first = first + 1
	count = count + 1
if count > max_count:
	max_count = count
print(max_count)


n = int(input())
arr = list(map(int, input().split(' ')))
gresult = 0
from collections import Counter
count_arr = Counter(arr)
for i in arr:
	result = count_arr.get(i)
	for j in range(1, 6):
		result += count_arr.get(i + j, 0)
	if result > gresult:
		gresult = result
print(gresult)


from typing import List

def solv(arr: List[int]) -> int:
	arr.sort(reverse=True)
	(l, r, best_team) = (0, 0, 1)
	while r < len(arr):
		if l >= r:
			r += 1
			continue
		if arr[l] - arr[r] <= 5:
			best_team = max(best_team, r - l + 1)
			r += 1
		else:
			l += 1
	return best_team
input()
arr_txt = input()
arr = [int(v) for v in arr_txt.split()]
print(solv(arr))


n = int(input())
a = list(map(int, input().split()))
a.sort()
im = 0
mcount = 1
count = 1
for i in range(1, n):
	if a[i] - a[im] <= 5:
		count += 1
	else:
		mcount = max(mcount, count)
		while a[i] - a[im] > 5:
			im += 1
			count -= 1
		count += 1
print(max(mcount, count))


from bisect import *
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
	ind = bisect_right(l, l[i] + 5)
	if ind == n:
		ans = max(ans, n - i)
		break
	else:
		ans = max(ans, ind - i)
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
dp = [[0 for i in range(k + 1)] for j in range(n + 1)]
prev = [0 for i in range(n)]
for i in range(n):
	for j in range(i, -1, -1):
		if l[i] - l[j] <= 5:
			prev[i] = j
for i in range(k + 1):
	dp[0][i] = 0
for i in range(1, n + 1):
	for j in range(1, k + 1):
		dp[i][j] = max(dp[i - 1][j - 1] + 1, dp[i - 1][j], dp[prev[i - 1]][j - 1] + i - prev[i - 1])
print(dp[n][k])


n = int(input())
jogadores = [*map(int, input().split())]
jogadores.sort()
maxv = 0
cont = 0
p1 = p2 = 0
while p2 < n:
	if jogadores[p2] - jogadores[p1] <= 5:
		cont += 1
		p2 += 1
	else:
		cont -= 1
		p1 += 1
	maxv = max(maxv, cont)
print(maxv)


def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	cnt = [0] * n
	for i in range(n):
		while i + cnt[i] < n and a[i + cnt[i]] - a[i] <= 5:
			cnt[i] += 1
	dp = [[0] * (k + 1) for _ in range(n + 1)]
	for i in range(n):
		for j in range(k + 1):
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
			if j + 1 <= k:
				dp[i + cnt[i]][j + 1] = max(dp[i + cnt[i]][j + 1], dp[i][j] + cnt[i])
	print(dp[n][k])
main()


a = int(input())
b = sorted(map(int, input().split()))
i = j = m = 0
while j < a:
	if b[j] - b[i] <= 5:
		j += 1
	else:
		m = max(m, j - i)
		i += 1
print(max(m, j - i))


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
amount = 1
j = 0
i = 0
while i < n - 1:
	if j < i:
		j = i
	while j < n and a[j] - a[i] <= 5:
		j += 1
	amount = max(j - i, amount)
	i += 1
print(amount)


n = int(input())
arr = [int(i) for i in input().split()]
arr = sorted(arr)
count = 0
maxcount = 1
diff = 0
i = 0
j = 0
while j <= len(arr) - 1:
	diff = arr[j] - arr[i]
	count = count + 1
	if diff > 5:
		while diff > 5:
			i = i + 1
			diff = arr[j] - arr[i]
			count = count - 1
	j = j + 1
	maxcount = max(maxcount, count)
print(maxcount)


from sys import stdout, stdin

def select(students):
	students.sort(reverse=True)
	j = 0
	result = 0
	for i in range(len(students)):
		while j < len(students) and students[i] - students[j] <= 5:
			j += 1
		result = max(result, j - i)
	return result
n = int(stdin.readline().replace('\n', ''))
students = [int(x) for x in stdin.readline().replace('\n', '').split(' ')]
print(select(students))


n = int(input())
l = list(map(int, input().split()))
l.sort()
p1 = 0
p2 = 0
max_len = 0
while True:
	if p2 >= len(l):
		break
	if l[p2] - l[p1] <= 5:
		max_len = max(max_len, p2 - p1 + 1)
		p2 += 1
	else:
		p1 += 1
print(max_len)


from sys import stdin, stdout
import bisect as bs
for _ in range(1):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	a.sort()
	ans = 0
	for i in range(n):
		pos = bs.bisect(a, a[i] + 5) - 1
		ans = max(ans, pos - i + 1)
	print(ans)


n = int(input())
levels = list(map(int, input().split(' ')))
cont = 0
balance = 0
levels = sorted(levels)
for e in range(len(levels)):
	while cont < len(levels):
		if levels[cont] - levels[e] <= 5:
			cont += 1
		else:
			break
	if balance < cont - e:
		balance = cont - e
print(balance)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
dp = [0] * n
start = a[0]
(k, i) = (0, 0)
while i < n:
	if a[i] - start > 5:
		dp[k] = i - k
		k += 1
		start = a[k]
	else:
		i += 1
dp[k] = n - k
for i in range(k + 1, n):
	dp[i] = dp[i - 1] - 1
if dp[0] == n:
	print(n)
	exit()
dp2 = [[0 for i in range(m + 1)] for j in range(n + 1)]
for i in range(n - 1, -1, -1):
	for j in range(1, m + 1):
		dp2[i][j] = max(dp2[i + 1][j], dp2[i + 1][j - 1] + 1, dp2[dp[i] + i][j - 1] + dp[i])
print(dp2[0][m])


def atMostSum(arr, n, k):
	_sum = 0
	cnt = 0
	maxcnt = 0
	for i in range(n):
		if _sum + arr[i] <= k:
			_sum += arr[i]
			cnt += 1
		elif sum != 0:
			_sum = _sum - arr[i - cnt] + arr[i]
		maxcnt = max(cnt, maxcnt)
	return maxcnt
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
ss = []
for i in range(1, len(arr)):
	ss.append(arr[i] - arr[i - 1])
print(atMostSum(ss, len(ss), 5) + 1)


n = int(input())
moce = list(map(int, input().split()))
moc = sorted(moce)
wynik = 0
gorny = 0
for dolny in range(n):
	gor = gorny
	for i in range(gorny, n):
		if moc[i] > moc[dolny] + 5:
			gor = i
			break
		else:
			gor += 1
	gorny = gor - 1
	wynik = max(wynik, gorny - dolny + 1)
print(wynik)


n = int(input())
skill = list(map(int, input().split()))
skill.sort()
(i, j) = (0, 0)
best = 1
while j < n - 1:
	if skill[j + 1] - skill[i] <= 5:
		j += 1
	else:
		i += 1
	best = max(best, j - i + 1)
print(best)


N = int(input())
A = list(map(int, input().split()))
A.sort()
l = r = 0
numb = 1
t = 0
i = 0
while i < len(A) - 1:
	while r < len(A) and A[i] + 5 >= A[r]:
		r += 1
		t += 1
	if t > numb:
		numb = t
	if t > 0:
		t -= 1
	i += 1
print(numb)


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, size, link):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
n = int(input())
a = sorted(int_array())
ans = 0
i = j = 0
while j < n:
	if a[j] - a[i] <= 5:
		ans = max(ans, j - i + 1)
		j += 1
	else:
		i += 1
		ans = max(ans, j - i + 1)
print(ans)


import random
m = int(input())
n = [int(i) for i in input().split()]
n = sorted(n)
min_ = n[0]
i = 0
j = 1
MAX = [1]
kolvo = 0
if len(set(n)) != 1:
	while i < m:
		x = 0
		kolvo = 0
		j = i
		while abs(min_ - n[j]) <= 5:
			j += 1
			kolvo += 1
			if j == m:
				if abs(min_ - n[j - 1]) <= 5:
					MAX.append(kolvo)
				break
		if j == m:
			break
		while abs(n[j] - n[j - x]) <= 5:
			x += 1
			if j - x < 0 or abs(n[j] - n[j - x]) > 5:
				x -= 1
				break
		if i == m:
			break
		i = j - x
		min_ = n[j - x]
		MAX.append(kolvo)
	print(max(MAX))
else:
	print(m)


n = int(input())
h = {}

def add(score):
	global h
	if score in h:
		h[score] += 1
	else:
		h[score] = 1
for i in input().split():
	t = int(i)
	add(t)
res = 0
val = sorted(h.keys())
for i in val:
	temp = 0
	for j in range(i, i + 6):
		if j in h:
			temp += h[j]
	res = max(res, temp)
print(res)


n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = True
top = 1
i = 0
while top + i < n:
	if a[top + i] - a[i] <= 5:
		top += 1
	else:
		i += 1
print(top)


n = int(input())
a = list(map(int, input().split()))
a.sort()
dis = 1
b = []
for i in range(n - 1):
	b.append(a[i + 1] - a[i])
s = 0
c = 0
d = 1
for i in range(n - 1):
	c += b[i]
	d += 1
	if c <= 5:
		dis = max(dis, d)
	else:
		while c > 5:
			c -= b[s]
			s += 1
			d -= 1
print(dis)


n = int(input())
a = sorted(list(map(int, input().split())))
t = [[a[0], 1]]
ta = 1
lt = 1
for s in a[1:]:
	for team in t[lt - ta:]:
		if s - team[0] <= 5:
			team[1] += 1
		else:
			ta -= 1
	if s != t[-1][0]:
		t.append([s, 1])
		ta += 1
		lt += 1
print(max(t, key=lambda x: x[1])[1])


n = int(input())
d = [int(x) for x in input().split()]
d.sort()
m = 0
k = 1
for i in range(n - 1):
	for j in range(k, n):
		if d[j] - d[i] > 5:
			break
		if j - i > m:
			m = j - i
	else:
		break
	k = j
print(m + 1)


n = int(input())
skills = [int(a) for a in input().split(' ')]
skills.sort()
i = 0
maior_sq = 1
sq_atual = []
menos = 0
while i < n:
	skill = skills[i]
	leng = len(sq_atual)
	if leng == 0 or abs(skill - sq_atual[-1]) <= 5:
		if leng > 0 and abs(skill - sq_atual[0]) > 5:
			j = leng - 2
			while j >= 0:
				if abs(skill - sq_atual[j]) > 5:
					menos += j
					sq_atual = sq_atual[j + 1:leng]
					break
				j -= 1
		sq_atual.append(skill)
		if leng > maior_sq:
			maior_sq = leng
	else:
		if leng > maior_sq:
			maior_sq = leng
		menos += leng
		sq_atual = []
	i += 1
leng = len(sq_atual)
if leng > maior_sq:
	maior_sq = leng
print(maior_sq)


n = int(input())
A = list(map(int, input().split()))
A.sort()
i = 0
j = 0
ans = 0
while j < len(A):
	ans = max(ans, j - i)
	if i == j or A[j] - A[i] <= 5:
		j += 1
	else:
		i += 1
print(max(ans, j - i))


n = int(input())
a = list(map(int, input().split()))
a.sort()
l = r = 0
ans = 0
for i in range(n):
	while l < r and a[r] - a[l] > 5:
		l += 1
	ans = max(ans, r - l + 1)
	r += 1
print(ans)


def solve():
	N = int(input())
	A = [int(k) for k in input().split()]
	A.sort()
	Max = 1
	cur = 1
	first = 0
	for i in range(1, N):
		if A[i] - A[first] < 6:
			cur += 1
		else:
			if cur > Max:
				Max = cur
			while A[i] - A[first] > 5:
				first += 1
				cur -= 1
			cur += 1
	print(max(cur, Max))
solve()


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(1)
else:
	a.sort()
	p1 = 0
	p2 = p1
	tamanho = []
	for i in range(0, n - 1):
		if a[p2 + 1] - a[p1] <= 5:
			p2 += 1
		else:
			p1 += 1
			p2 += 1
		tamanho.append(p2 - p1 + 1)
	print(max(tamanho))


_ = input()
lst = list(map(int, input().split()))
lst.sort()
mx = 0
i = 0
j = 0
while i < len(lst) and j < len(lst):
	if lst[j] - lst[i] <= 5:
		j += 1
		mx = max(mx, j - i)
	else:
		i += 1
print(mx)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
s = 1
ms = 1
i = 0
j = 1
while i < n and j < n:
	if a[j] - a[i] <= 5:
		s += 1
		j += 1
	else:
		ms = max(ms, s)
		s -= 1
		i += 1
ms = max(ms, s)
print(ms)


n = int(input())
scores = [int(x) for x in input().split()]
scores.sort()
best = 1
first = 0
for i in range(1, n):
	if scores[i] - scores[first] > 5:
		first += 1
	best = max(best, i - first + 1)
print(best)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
dp = [[0 for i in range(k + 1)] for i in range(n + 1)]
(i, j) = (1, 2)
prev_max = [0 for i in range(k + 1)]
ans = 0
while i < n + 1:
	while j < n + 1 and a[j - 1] - a[i - 1] <= 5:
		j += 1
	for c in range(k):
		dp[j - 1][c + 1] = max(dp[j - 1][c + 1], prev_max[c] + (j - i))
		ans = max(ans, dp[j - 1][c + 1])
	for c in range(k):
		prev_max[c] = max(prev_max[c], dp[i][c])
	i = i + 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
max_students = 1
cont = 1
i = 0
j = 1
while j < n:
	if a[j] - a[i] <= 5:
		j += 1
		cont += 1
		if cont > max_students:
			max_students = cont
	else:
		i += 1
		cont -= 1
print(max_students)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	n = inp()
	lst = inlt()
	lst.sort()
	max_len = 0
	cur_len = 0
	start = 0
	for st in lst:
		while lst[start] + 5 < st:
			start += 1
			cur_len -= 1
		cur_len += 1
		max_len = max(max_len, cur_len)
	print(max(max_len, cur_len))
BUFSIZE = 8192

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
n = int(input())
arr = list(map(int, input().split(' ')))
arr.sort()
left = 0
right = 0
nlen = len(arr)
ans = 1
while right < nlen:
	if arr[right] - arr[left] <= 5:
		right += 1
		ans = max(ans, right - left)
	else:
		left += 1
print(ans)


n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
res = 0
ptr1 = 0
ptr2 = 1
while ptr2 < n:
	if arr[ptr2] - arr[ptr1] > 5:
		res = max(res, ptr2 - ptr1)
		ptr1 += 1
	else:
		ptr2 += 1
res = max(res, ptr2 - ptr1)
print(res)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
from bisect import bisect_left, bisect_right
dp = [[0] * (k + 1) for i in range(n + 1)]
for (pos, good) in enumerate(a):
	for g_cnt in range(1, k + 1):
		group_size = pos + 1 - bisect_right(a, good - 6)
		dp[pos + 1][g_cnt] = max(dp[pos + 1 - group_size][g_cnt - 1] + group_size, dp[pos][g_cnt])
ans = max((dp[n][g_cnt] for g_cnt in range(k + 1)))
print(ans)


(n, K) = map(int, input().split())
arr = sorted(map(int, input().split()))
freq = {}
for x in arr:
	freq[x] = freq.get(x, 0) + 1
arr = sorted(freq.keys())
freq = [freq[x] for x in arr]
n = len(arr)
dp = [[0 for _ in range(n + 1)] for _ in range(2)]
for k in range(1, K + 1):
	for i in range(n - 1, -1, -1):
		j = i
		curr = 0
		curr_ans = dp[k & 1][i + 1]
		while j < n and abs(arr[i] - arr[j]) <= 5:
			curr += freq[j]
			curr_ans = max(curr_ans, curr + dp[1 - (k & 1)][j + 1])
			j += 1
		dp[k & 1][i] = curr_ans
print(dp[K & 1][0])


from bisect import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(len(a)):
	j = bisect(a, a[i] + 5, i)
	ans = max(ans, j - i)
print(ans)


import heapq
n = int(input())
a = [int(t) for t in input().split(' ')]
a.sort()
skills = []
skillcount = {}
crewsize = 0
maxcrew = 0
for ai in a:
	if ai not in skillcount:
		skillcount[ai] = 1
		crewsize += 1
		heapq.heappush(skills, ai)
		while ai - skills[0] > 5:
			lowskill = heapq.heappop(skills)
			crewsize -= skillcount[lowskill]
			del skillcount[lowskill]
	else:
		skillcount[ai] += 1
		crewsize += 1
	maxcrew = max(maxcrew, crewsize)
print(maxcrew)


num_de_estudantes = int(input())
estudantes = list(map(int, input().split()))
estudantes.sort()
estudantes_balanceados = 0
j = 0
for i in range(num_de_estudantes):
	while j < num_de_estudantes and estudantes[j] - estudantes[i] <= 5:
		j += 1
		if estudantes_balanceados >= j - i:
			continue
		else:
			estudantes_balanceados = j - i
print(estudantes_balanceados)


n = int(input())
s = sorted(map(int, input().split()))
res = 1
i = 0
j = 0
m = 1
while i < n - 1:
	while j < n and abs(s[j] - s[i]) <= 5:
		if m > res:
			res = m
		j += 1
	if res >= n - i:
		break
	m = max(m, j - i)
	i += 1
print(m)


def main():
	_n = int(input())
	a = [int(x) for x in input().split(' ')]
	b = sorted(a)
	max_result = 0
	for (i, bi) in enumerate(b):
		(min_val_idx, max_val_idx) = (i, binary_search(b, bi + 5))
		result = max_val_idx - min_val_idx + 1
		if result > max_result:
			max_result = result
	print(max_result)

def binary_search(arr, target):

	def helper(arr, target, lo, hi):
		if lo >= hi:
			return lo if arr[lo] <= target else -1
		mi = (lo + hi) // 2
		if arr[mi] > target:
			return helper(arr, target, lo, mi)
		else:
			result = helper(arr, target, mi + 1, hi)
			return mi if result == -1 else result
	return helper(arr, target, 0, len(arr) - 1)
main()


def getMaxNumMembers(n, team):
	team = sorted(team)
	a = 0
	b = 0
	ans = 1
	cont = 1
	while b < n:
		if b + 1 < n and abs(team[b + 1] - team[a]) <= 5:
			cont += 1
			b += 1
			if ans < cont:
				ans = cont
		else:
			cont = max(1, cont - 1)
			a += 1
			if a > b:
				b = a
	return ans
n = int(input())
team = map(int, input().split())
print(getMaxNumMembers(n, team))


n = int(input())
k = [int(i) for i in input().split()]
k.sort()
l = []
for i in range(1, n):
	l.append(k[i] - k[i - 1])
(i, j, s) = (0, 0, 0)
for j in range(n - 1):
	s += l[j]
	if s > 5:
		s -= l[i]
		i += 1
print(n - i)


size = int(input())
students = list(sorted(map(int, input().split())))
(left, right, ans) = (0, 0, 0)
while left < size and right < size:
	if students[right] - students[left] <= 5:
		ans = max(ans, right - left + 1)
		right += 1
	elif left == right:
		right += 1
	else:
		left += 1
print(ans)


n = int(input())
a = sorted(list(map(int, input().split())))
max_a = 0
(i, j) = (0, 0)
while i < n and j < n:
	if a[j] - a[i] < 6:
		j += 1
	else:
		i += 1
	if j - i > max_a:
		max_a = j - i
print(max_a)


n_integrantes = input()
integrantes = list(map(int, input().split(' ')))
integrantes.sort()
primeiro = 0
ultimo = 0
integrates = 0
while ultimo < len(integrantes) - 1:
	if not integrantes[ultimo + 1] - integrantes[primeiro] <= 5:
		primeiro += 1
	ultimo += 1
print(ultimo - primeiro + 1)


a = int(input())
pa = list(map(int, input().split()))
kam = {}
y = 0
pa.sort()
sa = 0
la = []
ba = 0
x = 0
saa = 0
for x in range(a):
	if pa[x] - pa[y] <= 5:
		sa += 1
	else:
		la.append(sa)
		sa -= 1
		y += 1
		while ba == 0:
			if pa[x] - pa[y] <= 5:
				sa += 1
				break
			else:
				la.append(sa)
				sa -= 1
				y += 1
			if y == x:
				sa = 1
				break
la.append(sa)
print(max(la))


students = int(input())
skills = list(map(int, input().split()))
if len(list(set(skills))) == 1:
	print(len(skills))
else:
	skills.sort()
	ini = 0
	fim = students - 1
	i = ini
	j = fim
	maxp1 = 0
	maximum1 = 0
	maxp2 = 0
	maximum2 = 0
	while i <= students - 1 and j >= 0:
		if skills[ini] + 5 >= skills[i]:
			maxp1 += 1
			i += 1
			maximum1 = max(maximum1, maxp1)
		else:
			maxp1 -= 1
			ini += 1
		if skills[fim] - 5 <= skills[j]:
			maxp2 += 1
			j -= 1
			maximum2 = max(maximum2, maxp2)
		else:
			maxp2 -= 1
			fim -= 1
	print(max(maximum1, maximum2))


def countPairs(a, n):
	res = 0
	j = 0
	for i in range(n):
		while j < n and a[j] - a[i] <= 5:
			res = max(res, j - i)
			j += 1
	return res
n = int(input())
l = list(map(int, input().split()))
l.sort()
print(countPairs(l, n) + 1)


for t in range(1):
	n = int(input())
	arr = list(map(int, input().split()))
	unique = set(arr)
	counter = dict()
	for i in range(n):
		ele = arr[i]
		if ele in counter:
			counter[ele] += 1
		else:
			counter[ele] = 1
	maxim = 0
	for i in unique:
		ele = i
		count = 0
		for j in range(ele, ele + 6):
			if j in counter:
				count += counter[j]
		maxim = max(maxim, count)
	print(maxim)


from bisect import bisect_right
n = int(input())
arr = sorted(list(map(int, input().split())))
ans = -10 ** 9
for i in range(n):
	curr = arr[i]
	z = bisect_right(arr, curr + 5, lo=i)
	ans = max(ans, z - i)
print(ans)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(1)
else:
	a = sorted(a)
	z = 0
	for i in range(n - 1):
		if i + z >= n:
			break
		if a[i + z] - a[i] > 5:
			continue
		j = i + z
		while j < n:
			if a[j] - a[i] > 5:
				break
			j += 1
		z = j - i
		if j == n:
			break
	print(z)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()

def solve(a, n):
	li = {}
	for i in range(n):
		cnt = 1
		t = [a[i]]
		for j in range(i + 1, n):
			if a[j] - a[i] > 5:
				li[tuple(t)] = cnt
				break
			else:
				t += [a[j]]
				cnt += 1
				if j == n - 1:
					li[tuple(t)] = cnt
	return li
n = intIn()
a = listIn()
di = {}
a.sort()
for i in range(n):
	if a[i] not in di:
		di[a[i]] = 1
	else:
		di[a[i]] += 1
a = sorted(set(a))
if len(a) != 1:
	ans = solve(a, len(a))
	maxx = max(ans.values())
	if maxx != 1:
		f = []
		for ele in ans:
			if ans[ele] == maxx:
				f.append(ele)
		m = float('-inf')
		for ele in f:
			cnt = 0
			for e in ele:
				cnt += di[e]
			m = max(m, cnt)
		ans = m
	else:
		ans = max(di.values())
else:
	ans = n
print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from bisect import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
	a = bisect(l, l[i] + 5)
	ans = max(ans, a - i)
print(ans)


from collections import defaultdict
n = int(input())
l = list(map(int, input().split()))
l.sort()
u = set(l)
count1 = 0
count2 = 0
hash = defaultdict(list)
for i in range(len(l)):
	hash[l[i]].append(i)
ans = []
max = -10
for i in range(len(l)):
	z = l[i]
	k = [z, z + 1, z + 2, z + 3, z + 4, z + 5]
	for j in k:
		if j in u:
			ans.append([i, hash[j][-1]])
			ho = hash[j][-1] - i + 1
			if ho > max:
				max = ho
print(max)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
res = 1
j = 0
for i in range(n):
	chk = a[i]
	while j < n:
		if a[j] - chk <= 5:
			res = max(res, j - i + 1)
		else:
			break
		j += 1
print(res)


import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = pow(10, 9) + 7

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def solve():
	n = int(inp())
	a = sorted(lis())
	ans = 0
	temp = 1
	f = False
	for i in range(0, n):
		if f:
			break
		for j in range(temp, n):
			if a[j] - a[i] < 6:
				if j == n - 1:
					f = True
					ans = max(j - i + 1, ans)
				continue
			else:
				ans = max(j - i, ans)
				temp = j
				break
	if ans == 0:
		print(1)
	else:
		print(ans)
testcase(1)


from sys import stdin

def main():
	n = int(stdin.readline().strip())
	std = [int(s) for s in stdin.readline().strip().split(' ')]
	r = {}
	for i in std:
		if not i in r:
			r[i] = 0
		r[i] += 1
	maxg = 1
	for i in std:
		total = 0
		for j in range(6):
			total += r[i - j] if i - j in r else 0
		maxg = max(maxg, total)
	print(maxg)
main()


n = int(input())
a = [int(j) for j in input().split()]
a.sort()
ans = []
ma = 1
y = 0
if n == 1:
	print(1)
else:
	for x in range(1, len(a)):
		while a[x] - a[y] > 5:
			y += 1
		ans += [x - y + 1]
	print(max(ans))


(n, k) = map(int, input().split())
a = sorted((int(i) for i in input().split()))
u = [0] * n
(i, j) = (0, 0)
while j < n:
	if a[i] + 5 >= a[j]:
		j += 1
	else:
		i += 1
	u[i] = j
dp = [[0] * (k + 1) for i in range(n + 1)]
for i in range(n - 1, -1, -1):
	for j in range(1, k + 1):
		x = u[i]
		dp[i][j] = max(1 + dp[i + 1][j - 1], dp[i + 1][j], x - i + dp[x][j - 1])
print(dp[0][k])


a = int(input())
arr = sorted(list(map(int, input().split())))
(l, r) = (0, 1)
ans = 1
while r < a:
	if arr[l] >= arr[r] - 5:
		r += 1
		ans = max(ans, r - l)
	else:
		l += 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
c = 0
(x, y) = (0, 0)
while x < n and y < n:
	if l[y] - l[x] <= 5:
		c = max(y - x + 1, c)
		y += 1
	elif l[y] - l[x] > 5:
		x += 1
print(c)


(n, a, j, m) = (int(input()), sorted([*map(int, input().split())]), 0, 0)
if a[-1] - a[0] <= 5:
	print(n)
else:
	for i in range(n):
		while j < n and a[j] - a[i] <= 5:
			j += 1
		m = max(m, j - i)
		if j == n - 1:
			break
	print(m)


from collections import defaultdict

def f(i, s):
	if s - i < 6:
		return True
	return False
n = int(input())
a = defaultdict(int)
for i in input().split():
	i = int(i)
	a[i] += 1
ind = sorted(a.keys())
r = 0
x = len(ind)
for i in range(x):
	s = a[ind[i]]
	for j in range(1, 6):
		if i + j < x and ind[i + j] - ind[i] < 6:
			s += a[ind[i + j]]
	r = max(s, r)
print(r)


n = int(input())
raw = sorted(list(map(int, input().split())))
queue = [raw[0]] + [0] * n
tail = 0
top = 0
before = [1]
queue[top] = raw[0]
top = 1
for i in range(1, n):
	queue[i] = raw[i]
	while raw[i] - queue[tail] > 5:
		tail += 1
		if i == tail:
			break
	before.append(i - tail + 1)
print(max(before))


n = int(input())
skills = list(map(int, input().split()))
skills.sort()
max_students = 0
left = right = 0
total = 0
while right < n:
	if skills[right] - skills[left] <= 5:
		total += 1
		right += 1
	else:
		left += 1
		total -= 1
	max_students = max(max_students, total)
print(max_students)


n = int(input())
a = sorted(list(map(int, input().split())))
l = r = 0
m = 0
while r < n:
	while l <= r and a[r] - a[l] > 5:
		l += 1
	m = max(m, r - l + 1)
	r += 1
print(m)


n = int(input())
a = list(map(int, input().split()))
m = 1
ans = 1
j = 0
i = 1
a.sort()
while i < n:
	if a[i] - a[j] < 6:
		ans += 1
		i += 1
	else:
		ans -= 1
		j += 1
	m = max(m, ans)
print(m)


n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
(i, j) = (0, 0)
while i < n or j < n:
	if j == n:
		i += 1
	elif l[j] - l[i] <= 5:
		j += 1
	else:
		i += 1
	ans = max(ans, j - i)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
m = 0
i = 0
while i < len(arr):
	ind = 0
	count = 1
	r = 0
	for j in range(i, len(arr) - 1):
		if arr[i] == arr[j + 1]:
			count += 1
			ind += 1
		elif r + arr[j + 1] - arr[j] <= 5:
			r += arr[j + 1] - arr[j]
			count += 1
		else:
			break
	i += ind
	m = max(count, m)
	i += 1
print(m)


n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
(i, j) = (0, 0)
m = 0
while j < n:
	while j < n and a[j] - a[i] < 6:
		j += 1
	m = max(m, j - i)
	i += 1
print(m)


n = int(input())
ans = []
l = list(map(int, input().split()))
l.sort()

def binpow(ch, n):
	uk1 = -1
	uk2 = n
	while uk2 - uk1 > 1:
		if l[(uk2 + uk1) // 2] > ch + 5:
			uk2 = (uk2 + uk1) // 2
		else:
			uk1 = (uk2 + uk1) // 2
	return uk1
for i in range(n):
	t = binpow(l[i], n)
	ans.append(t - i + 1)
print(max(ans))


n = int(input())
students = sorted(map(int, input().split(' ')))
top = 0
active = {}
for student in students:
	if student not in active:
		active[student] = 0
	for a in list(active.keys()):
		if student - a <= 5:
			active[a] += 1
			top = max(top, active[a])
		else:
			del active[a]
print(top)


n = int(input())
a = sorted([int(i) for i in input().split()])
s = 0
l = 0
for r in range(0, n):
	while a[r] - a[l] > 5:
		l += 1
	s = max(s, r - l + 1)
print(s)


n = int(input())
skill = [int(x) for x in input().split()]
skill.sort()
resp = 0
cont = 0
l = 0
r = 0
for l in range(n):
	while r < n:
		if skill[r] <= skill[l] + 5:
			cont += 1
			r += 1
		else:
			resp = max(resp, cont)
			cont -= 1
			break
	resp = max(resp, cont)
print(resp)


import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
d = [0]
for i in range(1, n):
	d.append(a[i] - a[i - 1])
s = [0]
for i in range(1, n):
	s.append(s[-1] + d[i])
ans = 0
for i in range(n):
	j = bisect.bisect_right(s, 5 + s[i])
	ans = max(ans, j - i)
print(ans)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(moves, n):
	val = (moves + 1) // 2
	rem = moves - val
	sol = (val + 1) * (rem + 1)
	return sol < n

def sortSecond(val):
	return val[1]
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect
import functools as fnt
from decimal import Decimal

def solve():
	n = scanner()
	a = get_list()
	a.sort()
	l = 1
	m = 1
	for i in range(n - 1):
		while i + l < n and a[i + l] - a[i] <= 5:
			l += 1
			if i + l == n:
				break
		m = max(l, m)
	print(m)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = 1
for i in range(t):
	solve()


n = int(input())
a = sorted(list(map(int, input().split())))
(left, r) = (0, 1)
ans = 0
while r < n:
	while r < n and a[r] - a[left] <= 5:
		r += 1
	ans = max(ans, r - left)
	left += 1
print(max(ans, 1))


def arr_scan():
	return list(map(int, input().split(' ')))
n = int(input())
arr = sorted(arr_scan())
diff = []
for i in range(1, n):
	diff.append(arr[i] - arr[i - 1])
if len(diff) == 0:
	print(1)
	exit(0)
start = end = -1
d = 0
ans = 1
start = end = 0
d = diff[start]
while 1:
	if d <= 5:
		tmp = end - start + 2
		if tmp > ans:
			ans = tmp
		end += 1
		if end >= n - 1:
			break
		d += diff[end]
	else:
		d -= diff[start]
		start += 1
		if start >= n - 1:
			break
		if start > end:
			d = diff[start]
			end = start
print(ans)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
A.sort()
l = r = ans = 0
while l < N:
	while r < N and A[r] - A[l] <= 5:
		r += 1
	ans = max(ans, r - l)
	if l == r:
		r += 1
	l += 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
tol = 1
ma = 0
flag = False
Index1 = 0
i = 1
while i < n:
	if l[i] - l[Index1] <= 5:
		tol = i - Index1 + 1
		i += 1
	else:
		flag = True
		if tol > ma:
			ma = tol
		Index1 += 1
if flag == False:
	print(tol)
elif tol > ma:
	print(tol)
else:
	print(ma)


def input_as_list():
	return list(map(int, input().split()))
from collections import defaultdict

def solve():
	n = int(input())
	a = input_as_list()
	d = defaultdict(int)
	for x in a:
		d[x] += 1
	out = 0
	it = list(d.keys())
	for x in it:
		s = 0
		for i in range(x, x + 6):
			s += d[i]
		out = max(out, s)
	print(out)
solve()


n = int(input())
a = [i for i in input().split()]
d = {}
for i in range(n):
	d[a[i]] = d.get(a[i], 0) + 1
skills = []
for (k, v) in d.items():
	skills.append([int(k), v])
skills.sort()
i = 0
max_cnt = 0
while i < len(skills):
	cnt = skills[i][1]
	min_skill = skills[i][0]
	j = i + 1
	while j < len(skills) and abs(skills[j][0] - min_skill) <= 5:
		cnt += skills[j][1]
		j += 1
	if cnt > max_cnt:
		max_cnt = cnt
	cnt = skills[i][1]
	i += 1
print(max_cnt)


import bisect

def solve(skill, size):
	skill.sort()
	i = 0
	j = 1
	maxsize = 1
	while j < size:
		if skill[j] - skill[i] <= 5:
			maxsize = max(maxsize, j - i + 1)
		else:
			i = bisect.bisect_left(skill, skill[j] - 5, i, j)
		j += 1
	return maxsize
size = int(input().strip())
array = input().strip().split()
array = [int(array[i]) for i in range(size)]
print(solve(array, size))


from sys import stdin, stdout
for _ in range(1):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	a.sort()
	ans = 0
	for i in range(n):
		(l, r) = (i, n - 1)
		while l <= r:
			mid = l + r >> 1
			if a[mid] - a[i] <= 5:
				l = mid + 1
			else:
				r = mid - 1
		ans = max(ans, r - i + 1)
	print(ans)


n = int(input())
a = [int(s) for s in input().split()]
a = sorted(a)
i = 0
j = 0
res = 0
cur = 0
while j < len(a):
	while j < len(a) and a[j] - 5 <= a[i]:
		cur += 1
		j += 1
	if cur > res:
		res = cur
	i += 1
	cur -= 1
print(res)


n = int(input())
students = sorted(list(map(int, input().split())))
count = 0
j = 0
for i in range(n):
	while j < n and students[j] - students[i] <= 5:
		j += 1
		if count < j - i:
			count = j - i
		else:
			continue
print(count)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for i in a:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	mx = 0
	for i in range(n):
		(c1, c2) = (0, 0)
		for j in range(-5, 1):
			x = a[i] + j
			if x in d:
				c1 += d[x]
		for j in range(0, 6):
			x = a[i] + j
			if x in d:
				c2 += d[x]
		mx = max(c1, mx, c2)
	print(mx)
main()


import sys
sys.setrecursionlimit(1000000)
n = int(input())
s = list(map(int, input().split()))
s.sort()
l = r = 0
ans = 0
mn = s[0]
while r < n:
	mx = s[r]
	if mx - mn <= 5:
		r += 1
		ans = max(ans, r - l)
	else:
		l += 1
		mn = s[l]
print(ans)


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
d = 5
st = 0
i = 0
maxi = 1
while i < n:
	while st <= i and l[i] - l[st] > d:
		st += 1
	maxi = max(maxi, i - st + 1)
	i += 1
print(maxi)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
(start, end) = (0, 0)
while end < n:
	if a[end] <= a[start] + 5:
		end += 1
	else:
		start += 1
	ans = max(ans, end - start)
print(ans)


arraylen = int(input())
array = list(map(int, input().split()))
array = sorted(array, key=int)
saida = 0
contador = 0
for i in range(arraylen):
	while contador < arraylen and array[contador] - array[i] <= 5:
		contador = contador + 1
		saida = max(saida, contador - i)
print(saida)


n = int(input())
a = list(map(int, input().split()))
a.sort()
max_students = 0
last = 0
for (i, s) in enumerate(a):
	while s - a[last] > 5:
		last += 1
	if i - last + 1 > max_students:
		max_students = i - last + 1
print(max_students)


def main():
	n = int(input())
	arr = sorted(list(map(int, input().split())))
	ans = 0
	a = 0
	b = 0
	while b < n:
		if arr[b] - arr[a] <= 5:
			ans = max(ans, b - a + 1)
			b += 1
		else:
			a += 1
	print(ans)
main()


n = int(input())
a = input().split()
a = [eval(a[i]) for i in range(len(a))]
a.sort()
k = 0
j = 0
for i in range(k + j, len(a)):
	if a[i] - a[j] <= 5:
		k += 1
	else:
		j = j + 1
print(k)


from sys import exit, setrecursionlimit
setrecursionlimit(10 ** 6)
inn = lambda : input().strip()
mapp_m1 = lambda : map(lambda x: int(x) - 1, inn().split(' '))
mapp = lambda : map(int, inn().split(' '))
N = int(inn())
M = list(mapp())
M.sort()
from heapq import heappop, heappush
lowest = -1
team = [M[0]]
answer = 1
for a in range(1, N):
	next = M[a]
	while len(team) > 0 and next - team[0] > 5:
		heappop(team)
	heappush(team, next)
	answer = max(answer, len(team))
print(answer)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
dp = [0] * n
start = a[0]
(k, i) = (0, 0)
while i < n:
	if a[i] - start > 5:
		dp[k] = i - k
		k += 1
		start = a[k]
	else:
		i += 1
dp[k] = n - k
for i in range(k + 1, n):
	dp[i] = dp[i - 1] - 1
if dp[0] == n:
	print(n)
	exit()
dp2 = [[0 for i in range(m + 1)] for j in range(n + 1)]
for i in range(n - 1, -1, -1):
	for j in range(1, m + 1):
		dp2[i][j] = max(dp2[i + 1][j], dp2[i + 1][j - 1] + 1, dp2[dp[i] + i][j - 1] + dp[i])
print(dp2[0][m])


c = dict()

def cou(x):
	ans = 0
	for i in range(x, x + 6):
		if i in c:
			ans += c[i]
	return ans
n = int(input())
a = [int(i) for i in input().split()]
b = set(a)
for i in a:
	if i in c:
		c[i] += 1
	else:
		c[i] = 1
m = 0
for i in b:
	y = cou(i)
	if y > m:
		m = y
print(m)


n = int(input())
ai = list(map(int, input().split()))
ai.sort()
ans = 0
for i in range(n - 1, -1, -1):
	if ai[-1] - ai[i] > 5:
		break
	ans += 1
num = 0
num2 = 0
while num2 < n:
	if ai[num2] - ai[num] < 6:
		ans = max(ans, num2 - num + 1)
		num2 += 1
	else:
		num += 1
print(ans)


(n, ls) = (int(input()), sorted(map(int, input().split())))
p1 = 0
maxv = 0
for p0 in range(n):
	val = ls[p0] + 5
	while p1 < n and ls[p1] <= val:
		p1 += 1
	if p1 - p0 > maxv:
		maxv = p1 - p0
print(maxv)


import os, sys
from io import BytesIO, IOBase

def main():
	inf = -10 ** 6
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()))
	dp = [[inf] * (k + 1) for _ in range(n + 1)]
	for _ in range(n + 1):
		dp[_][0] = 0
	ind = 1
	for i in range(1, n + 1):
		while ind - 1 != n and a[ind - 1] - a[i - 1] <= 5:
			for te in range(1, k + 1):
				dp[ind][te] = max(dp[ind][te], ind - i + 1 + dp[i - 1][te - 1], dp[ind - 1][te])
			ind += 1
	print(max(map(max, dp)))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys

def rint():
	return map(int, sys.stdin.readline().split())
n = int(input())
a = list(rint())
a.sort()
aa = [[a[0], 1]]
for i in range(1, n):
	if aa[-1][0] == a[i]:
		aa[-1][1] += 1
	else:
		aa.append([a[i], 1])
ans = 0
for i in range(len(aa)):
	cnt = aa[i][1]
	vs = aa[i][0]
	for j in range(i + 1, i + 6):
		if j >= len(aa):
			break
		v = aa[j][0]
		if v - vs <= 5:
			cnt += aa[j][1]
		else:
			break
	ans = max(ans, cnt)
print(ans)


def read_tokens():
	return input().strip().split(' ')

def read_ints():
	return [int(s) for s in read_tokens()]
(n,) = read_ints()
arr = read_ints()

def fast(a) -> int:
	a.sort()
	n = len(a)
	l = 0
	max_size = 0
	for r in range(n):
		while a[r] - a[l] > 5:
			l += 1
		max_size = max(max_size, r - l + 1)
	return max_size
print(fast(arr))


a = int(input())
A = []
B = input().split()
for i in B:
	A.append(int(i))
A.append(1000000010)
A.sort()
i = 0
j = 0
ans = 0
while j < a:
	while A[j] - A[i] < 6:
		j += 1
	ans = max(ans, j - i)
	i += 1
print(ans)


def ten():
	n = int(input())
	a = sorted([i for i in map(int, input().split())])
	u = d = ans = 0
	while d != n:
		if a[d] - a[u] <= 5:
			ans = max(ans, d - u + 1)
			d += 1
			continue
		u += 1
	print(ans)
ten()


a = int(input())
z = list(map(int, input().split()))
z.sort()
l = 0
r = 0
count = 0
maxa = 0
while l <= r and r < len(z):
	if z[l] + 5 >= z[r]:
		count += 1
		r += 1
	else:
		maxa = max(count, maxa)
		count -= 1
		l += 1
maxa = max(maxa, count)
print(maxa)


import heapq
arr = input()
(N, K) = [int(x) for x in arr.split(' ')]
arr = input()
arr = [int(x) for x in arr.split(' ')]
arr.sort()
data = [[0] * N for _ in range(K)]
left = 0
right = 0
res = 0
while left < N and right < N:
	if arr[right] > arr[left] + 5:
		left += 1
	else:
		data[0][right] = max(data[0][right - 1], right - left + 1)
		right += 1
for i in range(K):
	data[i][0] = 1
for j in range(1, K):
	left = 0
	right = 0
	res = 0
	while left < N and right < N:
		if arr[right] > arr[left] + 5:
			left += 1
		else:
			if left >= 1 and right >= 1:
				data[j][right] = max(data[j][right - 1], data[j][right], data[j - 1][left - 1] + right - left + 1)
			elif left == 0 and right >= 1:
				data[j][right] = max(data[j][right - 1], data[j][right], right - left + 1)
			right += 1
print(data[K - 1][N - 1])


stu_num = int(input())
stu_pro = input().split(' ')
stu_pro = [int(x) for x in stu_pro]
stu_pro.sort()
pro_list = []
num_list = []
pro_temp = stu_pro[0]
num_temp = 0
for i in range(stu_num):
	if stu_pro[i] == pro_temp:
		num_temp += 1
	else:
		pro_list.append(pro_temp)
		num_list.append(num_temp)
		pro_temp = stu_pro[i]
		num_temp = 1
pro_list.append(pro_temp)
num_list.append(num_temp)
record_num = 0
max_num = 0
for i in range(len(pro_list)):
	for j in range(i, len(pro_list)):
		if pro_list[j] - pro_list[i] <= 5:
			record_num += num_list[j]
		else:
			if record_num > max_num:
				max_num = record_num
			record_num = 0
			break
	if record_num > max_num:
		max_num = record_num
	record_num = 0
print(max_num)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	right = 0
	res = 0
	for left in range(len(a)):
		while right + 1 < len(a) and a[right + 1] - a[left] <= 5:
			right += 1
		res = max(res, right - left + 1)
	return res
print(solve())


n = int(input())
l = input().split()
for i in range(0, n):
	l[i] = int(l[i])
l.sort()
result = 0
i = 0
j = 0
num = 1
try:
	while i < n and j < n:
		if l[j] - l[i] > 5:
			i += 1
			num -= 1
		else:
			result = max(result, num)
			j += 1
			num += 1
except IndexError:
	pass
print(result)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
sys.setrecursionlimit(int(pow(10, 6)))
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(1):
	n = l()[0]
	A = l()
	A.sort()
	mx = 0
	for i in range(n):
		x = br(A, A[i] + 5)
		mx = max(mx, x - i)
	print(mx)


from sys import stdin, stdout
from collections import Counter
(n, k) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
freq = Counter(a)
ks = sorted(freq.keys())
nn = len(ks)
dp = [[0 for _ in range(k + 1)] for _ in range(1 + nn)]
for i in range(1, nn + 1):
	for j in range(k, 0, -1):
		p = i
		len = 0
		while p > 0 and ks[i - 1] - ks[p - 1] <= 5:
			len += freq[ks[p - 1]]
			p -= 1
		dp[i][j] = max(dp[i - 1][j], len + dp[p][j - 1])
print(max(dp[-1]))


n = int(input())
arr = list(map(int, input().split()))
elem = set(arr)
count = dict()
for item in elem:
	count[item] = 0
for item in arr:
	count[item] += 1
key = list(count.keys())
key.sort()
high = 0
num = len(key)
for i in range(num):
	skill = key[i]
	cur = count[key[i]]
	j = i + 1
	for k in range(5):
		if j < num:
			if key[j] > skill + 5:
				break
			else:
				cur += count[key[j]]
				j += 1
	if high < cur:
		high = cur
print(high)


n = int(input())
ar = list(map(int, input().split()))[:n]
ar.sort()
i = 0
j = 0
m = 0
while i < n:
	while j < n and ar[j] - ar[i] <= 5:
		j = j + 1
	m = max(m, j - i)
	i = i + 1
print(m)


def solve(A, n):
	A = sorted(A)
	(i, j, res) = (0, 0, 1)
	while i < n:
		while j < n and A[j] - A[i] <= 5:
			j += 1
			res = max(res, j - i)
		i += 1
	return res
n = int(input())
arr = input().split(' ')
A = [int(n) for n in arr]
print(solve(A, n))


def main():
	n = int(input())
	a = list(map(int, input().split()))
	c = 1
	ans = 0
	a.sort()
	p1 = 0
	p2 = 1
	l = 1
	while p1 <= p2 and p2 < len(a):
		if a[p2] - a[p1] <= 5:
			l = max(p2 - p1 + 1, l)
			p2 += 1
		else:
			p1 += 1
	print(l)
main()


n = int(input())
students = [int(x) for x in input().split()]
students.sort()
seq_max = 1
i = 0
j = 1
temp = 1
while j < n:
	if students[j] - students[i] <= 5:
		temp += 1
		j += 1
		if temp > seq_max:
			seq_max = temp
	else:
		i += 1
		temp -= 1
print(seq_max)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import bisect
n = int(input())
vals = list(map(int, input().split()))
vals.sort()
maxsofar = 0
for j in range(n):
	lbound = max(vals[0], vals[j] - 5)
	leftval = bisect.bisect_left(vals, lbound)
	ubound = min(vals[-1], vals[j] + 5)
	rightval = bisect.bisect_right(vals, ubound)
	cur = max(j - leftval, rightval - j)
	if cur > maxsofar:
		maxsofar = cur
print(maxsofar)


import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
	return sys.stdin.readline()[:-1]
sys.setrecursionlimit(1000000)

def main():
	N = int(input())
	A = sorted(list(map(int, input().split())))
	max_member_count = 1
	for i in range(N):
		j = bisect.bisect_right(A, A[i] + 5)
		max_member_count = max(max_member_count, j - i)
	print(max_member_count)
main()