#include <cstdio>
using namespace std;
#define NMAX 100000
#define P 1000000007
bool ty[NMAX];
int main(){
int n;
int tt;
long long sumb=0,sumw=0,ans=0;
long long numb;
int i,j;
freopen("asm_code.in","r",stdin);
freopen("asm_code.out","w",stdout);
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&tt);
if(tt==1){
ty[i]=true;
sumb++;
}else sumw++;
}
for(i=0;i<n;i++){
numb=0;
if(!ty[i])for(j=i+1;j<n;j++)
if(ty[j])numb++;
else ans=(ans+((sumb-numb)*numb)%P)%P;
}
printf("%lld",ans);
return 0;
}