#include using namespace std; int main() { int N; cin >> N; vectorA(N); long long x = 0,y = 0; for(int i = 0; i < N; i++) { cin >> A[i]; if(A[i] == 1) { x++; } if(A[i] == 2) { y++; } } long long tmp = (N-1)*N/2; long long ans = 0; ans += x*y*3; tmp -= x*y; ans += x*(N-y-1)*2; ans -= x*(x-1); tmp -= x*(N-y-1); tmp += x*(x-1)/2; ans += tmp; cout << ans << endl; }