#pragma GCC target("sse4") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include unsigned char a[200000]; int n; using ll = long long; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int temp; scanf("%d", &temp); a[i] = 0b111 ^ (1 << std::min(temp - 1, 2)); } ll ans = 0; for (int j = 0; j < n; j++) { unsigned char t = a[j]; int ans2 = 0; for (int i = 0; i < j;i++) { ans2 += __builtin_ffs(t & a[i]); } ans += ans2; } printf("%lld\n", ans); }