#include using namespace std; long long x, y, z; int main() { int n; cin >> n; vector a(n, 0); for(auto& v : a) cin >> v; x = count(a.begin(), a.end(), 1); y = count(a.begin(), a.end(), 2); z = n - x - y; cout << x * y * 3 + x * (x - 1) / 2 * 2 + z * (n - x) / 2 << endl; return 0; }