#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector a(n); int cnt1 = 0, cnt2 = 0; for (int i = 0; i < n; i++) { cin >> a[i]; cnt1 += (a[i] == 1); cnt2 += (a[i] == 2); } int cnt3 = n - cnt1 - cnt2; long long ans = 0; ans += cnt1 * cnt2 * 3; ans += cnt1 * cnt3 * 2 + cnt1 * (cnt1 - 1) / 2 * 2; ans += cnt2 * (cnt2 - 1) / 2 + cnt2 * cnt3 + cnt3 * (cnt3 - 1) / 2; cout << ans << endl; }