#include using namespace std; typedef long long ll; int main() { int n; cin >> n; ll b[4]{0}; for(int i = 0; i < n; i++){ int a; cin >> a; b[min(a, 3)]++; } ll ans = b[1] * (b[1] - 1) + b[1] * b[2] * 3 + b[2] * (b[2] - 1) / 2 + b[3] * (b[3] - 1) / 2 + b[3] * (b[1] + b[2]); cout << ans << endl; }