// Arup Guha
// 5/11/2016
// Solution to 2016 USACO Bronze January Problem: Angry Cows

import java.util.*;
import java.io.*;

public class angry {

	public static void main(String[] args) throws Exception {

		// Read in data.
		Scanner stdin = new Scanner(new File("angry.in"));
		int n = stdin.nextInt();
		int[] vals = new int[n];
		for (int i=0; i<n; i++)
            vals[i] = stdin.nextInt();

        // Sort it.
        Arrays.sort(vals);

        int res = 0;

        // Try each start point.
        for (int i=0; i<n; i++) {

            boolean[] used = new boolean[n];
            used[i] = true;
            explode(used, vals, i, 1, true);
            explode(used, vals, i, 1, false);
            int tmp = 0;
            for (int j=0; j<n; j++) if (used[j]) tmp++;
            res = Math.max(res, tmp);

        }

		// Write result.
		PrintWriter out = new PrintWriter(new FileWriter("angry.out"));
		out.println(res);
		out.close();
		stdin.close();
	}

    // This is ugly, but it works for the small bounds...
	public static void explode(boolean[] used, int[] vals, int loc, int radius, boolean dir) {

        // Go forward direction.
	    if (dir) {

            // Mark everything within r.
            int i = loc+1;
            while (i < vals.length && vals[i] - vals[loc] <= radius) {
                used[i] = true;
                i++;
            }
            i--;

            // If at least one exploded, just recursively explode the last can that did in this direction.
            if (i > loc) explode(used, vals, i, radius+1, dir);

	    }

        // Repeat, but to the left...
	    else {

            // Mark everything within r.
            int i = loc-1;
            while (i >= 0 && vals[loc] - vals[i] <= radius) {
                used[i] = true;
                i--;
            }
            i++;

            // Recurse, if necessary.
            if (i < loc) explode(used, vals, i, radius+1, dir);
	    }
	}
}
