#include #include int main() { int n; std::cin >> n; std::vector a(n); for (size_t i = 0; i < n; i++) { std::cin >> a[i]; } long long one, two, more; one = 0; two = 0; for (auto ai : a) { if (ai == 1) { one++; } else if (ai == 2) { two++; } } more = n - one - two; long long result = 0; result += (two + more) * (two + more - 1) / 2; result += 2 * ((one + more) * (one + more - 1) / 2 - more * (more - 1) / 2); result += 3 * one * two; std::cout << result << std::endl; }