Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <cstdio>#include <algorithm>using namespace std;const int N = 100010;typedef long long LL;int n;int a[N];int one[N], three[N];int main(void) {scanf("%d", &n);for (int i = 1; i <= n; ++i) {scanf("%d", a + i);one[i] = one[i - 1];three[i] = three[i - 1];if (a[i] == 1) one[i] += 1;if (a[i] == 3) three[i] += 1;}LL ret = 0;for (int i = 1; i <= n; ++i) {if (a[i] == 2) {ret += (one[i] * (three[n] - three[i]));}}printf("%lld\n", ret);return 0;}