#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <bitset>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define vi vector<int>
#define pii pair<int,int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=1e6+10;
const int dis[4][2]={{0,1},{-1,0},{0,-1},{1,0}};
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int n,m;
ll a[maxn],pre[7],last[7],now;
int main()
{
int i,j,k,t;
scanf("%d",&n);
rep(i,1,n){
scanf("%lld",&a[i]);
now=(now+a[i])%7;
if(pre[now])last[now]=i;
else pre[now]=i;
}
ll ma=0;
rep(i,0,6)
{
if(pre[i]&&last[i])ma=max(ma,last[i]-pre[i]);
}
printf("%lld\n",ma);
//system ("pause");
return 0;
}