#include using namespace std; typedef long long ll; typedef long double ld; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m; i >= n; --i) #define ALL(v) (v).begin(),(v).end() templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> n; ll c1=0,c2=0; vector a(n); REP(i,n){ cin >> a[i]; if(a[i]==1) c1++; if(a[i]==2) c2++; } ll r=n-c1-c2; cout << (c2+r)*(c2+r-1)/2+(c1*(c1-1)/2+c1*r)*2+c1*c2*3 << endl; }