import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static int maxElementsWithAbsDiffLessThanEqualTo1(int[] a) { if(a == null || a.length == 0) { return 0; } int maxCount = 0; SortedSet sortedSet = null; Set visitedElements = new HashSet<>(); for(int i = 0; i < a.length; i++) { if(visitedElements.contains(a[i])) { continue; } visitedElements.add(a[i]); sortedSet = new TreeSet<>(); sortedSet.add(a[i]); int count = 1; for(int j = 0; j < a.length; j++) { if(j == i) { continue; } if(sortedSet.size() == 1 && Math.abs(a[j] - sortedSet.first()) <= 1) { sortedSet.add(a[j]); count++; } else if((Math.abs(a[j] - sortedSet.first()) <= 1) && (Math.abs(a[j] - sortedSet.last()) <= 1)) { sortedSet.add(a[j]); count++; } } if(count > maxCount) { maxCount = count; } } return maxCount; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] a = new int[n]; for(int a_i=0; a_i < n; a_i++){ a[a_i] = in.nextInt(); } int count = maxElementsWithAbsDiffLessThanEqualTo1(a); System.out.println(count); } }