#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 50;
int n, a[maxn], one, three;
int ans;
int main()
{
while(cin >> n)
{
ans = 0, one = 0, three = 0;
for(int i = 1;i <= n;i++)
{
cin >> a[i];
if(a[i] == 3) three++;
}
for(int i = 1;i <= n;i++)
{
if(a[i] == 1)
one++;
if(a[i] == 3)
three--;
if(a[i] == 2)
ans += one * three;
}
cout << ans << endl;
}
return 0;
}
using namespace std;
const int maxn = 1e5 + 50;
int n, a[maxn], one, three;
int ans;
int main()
{
while(cin >> n)
{
ans = 0, one = 0, three = 0;
for(int i = 1;i <= n;i++)
{
cin >> a[i];
if(a[i] == 3) three++;
}
for(int i = 1;i <= n;i++)
{
if(a[i] == 1)
one++;
if(a[i] == 3)
three--;
if(a[i] == 2)
ans += one * three;
}
cout << ans << endl;
}
return 0;
}