#include using namespace::std; const int N = 200000 + 5; int n; int a[N]; int main(){ scanf("%d", &n); long long extra = 0, ones = 0, twos = 0; for(int i = 0; i < n; i++){ scanf("%d", a + i); if(a[i] == 1) ones += 1; else if(a[i] == 2) twos += 1; else extra += 1; } long long ans = 2 * extra * ones + 1 * extra * twos + 3 * ones * twos + 2 * ones * (ones - 1) / 2 + 1 * extra * (extra - 1) / 2 + 1 * twos * (twos - 1) / 2; printf("%lld\n", ans); return 0; }