#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } signed main(){ int n;cin>>n; vector v(n); cin>>v; vector cnt(3,0); for(auto &x:v){ x--; cnt[min(2,x)]++; } ll res=0; res+=cnt[0]*(cnt[0]-1); res+=cnt[0]*cnt[1]*3; res+=cnt[0]*cnt[2]*2; res+=cnt[1]*(cnt[1]-1)/2; res+=cnt[1]*cnt[2]; res+=cnt[2]*(cnt[2]-1)/2; cout<