#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <cstring>
#include <string>
#define MOD 1000000007
using namespace std;
int n,f[100010],a[100010],sum1[100010],sum2[100010],t=0;
long long ans=0;
int main()
{
freopen("asm_code.in","r",stdin);
freopen("asm_code.out","w",stdout);
ios::sync_with_stdio(false);
cin>>n;
for (int i=1;i<=n;i++)
{
cin>>a[i];
if (a[i]!=a[i-1]) t=i-1;
sum1[i]=sum1[i-1];
sum2[i]=sum2[i-1];
if (a[i]==1) sum1[i]++;
if (a[i]==2) sum2[i]++;
for (int j=t;j>=1;j--)
{
if (a[i]==1&&a[j]==1) ans=(ans+(sum2[i]-sum2[j])*sum2[j]%MOD)%MOD;
if (a[i]==2&&a[j]==2) ans=(ans+(sum1[i]-sum1[j])*sum1[j]%MOD)%MOD;
}
}
cout<<ans<<endl;
}