#include #include #include #include using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int32_t N, i; cin >> N; vector A(N); for (i = 0; i != N; ++i) cin >> A[i]; int32_t count_1 = 0, count_2 = 0; for (i = 0; i != N; ++i) switch (A[i]) { case 1: ++count_1; break; case 2: ++count_2; break; } cout << N * static_cast(N - 1) / 2 + count_1 * static_cast(count_1 - 1) / 2 + count_1 * static_cast(N - count_1) + count_1 * static_cast(count_2) << '\n'; return 0; }