// Arup Guha
// 4/1/2016
// Solution to USACO Silver January Problem: Sequences Summing to Seves

import java.util.*;
import java.io.*;

public class div7 {

	public static void main(String[] args) throws Exception {

		// Read in data.
		BufferedReader stdin = new BufferedReader(new FileReader("div7.in"));
		int n = Integer.parseInt(stdin.readLine().trim());
		int[] arr = new int[n];
		for (int i=0; i<n; i++)
			arr[i] = Integer.parseInt(stdin.readLine().trim());

		// Keep track of smallest and largest index we've seen a mod.
		int[] min = new int[7];
		Arrays.fill(min, n);
		int[] max = new int[7];
		Arrays.fill(max, -1);

		// For empty list.
		min[0] = 0;
		max[0] = 0;

		// Cumulative frequency array by mod, and the mins and maxs of each mod.
		int[] mods = new int[n+1];
		for (int i=1; i<=n; i++) {
			mods[i] = (mods[i-1] + arr[i-1])%7;
			min[mods[i]] = Math.min(min[mods[i]], i);
			max[mods[i]] = Math.max(max[mods[i]], i);
		}

		// Just look for the biggest gap.
		int res = 0;
		for (int i=0; i<7; i++)
			res = Math.max(res, max[i]-min[i]);

		// Write result.
		PrintWriter out = new PrintWriter(new FileWriter("div7.out"));
		out.println(res);
		out.close();
		stdin.close();
	}
}
