#include using namespace std; int n; vector cnt(4, 0); long long solve(); int main() { cin >> n; for (int i = 0; i < n; ++i) { int a; cin >> a; if (a <= 2) ++cnt[a]; else ++cnt[3]; } cout << solve() << endl; return 0; } long long solve() { long long res = 0; auto mex = [](int l, int r) { if (l > r) swap(l, r); if (l != 1) return 1; if (r == 2) return 3; return 2; }; for (int i = 1; i <= 3; ++i) for (int j = i; j <= 3; ++j) { long long now = cnt[i] * cnt[j]; if (i == j) now = cnt[i] * (cnt[i] - 1) / 2; res += now * mex(i, j); } return res; }