#include<bits/stdc++.h>
using namespace std;
int n;
long long ans=0;
inline int read()
{
char c=getchar();
int x=0;
while(c<'0'||c>'9') c=getchar();
while(c>='0'&&c<='9')
{
x=x*10+c-'0';
c=getchar();
}
return x;
}
int main()
{
n=read();
int tmp,pos=0;
for(int i=1;i<=n;i++)
{
tmp=read();
if(tmp==5)
{
pos++;
ans+=(pos*(pos+1))/2;
ans%=1000000007;
ans+=pos*(i-pos);
ans%=1000000007;
}
else pos=0;
}
cout<<ans;
}
Subtask #2 WA