#include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; 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; } using namespace std; typedef long long ll; ll tri(ll n){ return (n*(n-1))/2; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector a(n); for(int i = 0; i < n; i++) cin >> a[i]; map cnt; for(int x: a){ if(cnt.count(x) == 0) cnt[x] = 1; else cnt[x]++; } ll m = n; ll ans = 0; if(cnt.count(1)){ m -= cnt[1]; ans += tri(cnt[1])*2; ll k = m; if(cnt.count(2)){ ans += cnt[1]*cnt[2]*3; k -= cnt[2]; } ans += cnt[1]*k*2; } ans += tri(m); cout << ans << endl; }