#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n; cin >> n; long long cnt[2] = {0, 0}; for (int i = 0; i < n; i++) { int a; cin >> a; if (a <= 2) { cnt[a - 1]++; } } long long ans = (long long)n * (n - 1); ans -= (n - cnt[0]) * (n - cnt[0] - 1) / 2; ans += cnt[0] * cnt[1]; cout << ans << endl; }