#include using namespace std; #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; using P=pair; const int INF=1001001001; const int mod=1e9+7; int main(){ int n; cin>>n; ll cnt1=0,cnt2=0; rep(i,n){ int a; cin>>a; if(a==1){cnt1++;} if(a==2){cnt2++;} } ll ans=0; ll p=n-cnt1,p2=n-cnt1-cnt2; ans+=p*(p-1)/2; ans+=2*cnt1*(cnt1-1)/2+cnt1*p2; ans+=3*cnt1*cnt2; cout<