#!/bin/python3 import sys n = int(input().strip()) a = [int(a_temp) for a_temp in input().strip().split(' ')] counts = {} for i in a: if i not in counts: counts[i] = 1 else: counts[i] += 1 curmax = None for k in counts: curcount = counts[k] leftcount = 0 rightcount = 0 if k-1 in counts: leftcount = counts[k-1] if k+1 in counts: rightcount = counts[k+1] thismax = curcount + max(leftcount, rightcount) if curmax == None or thismax > curmax: curmax = thismax print(curmax)