#include using namespace std; using ll = long long; using ld = long double; using pii = pair; using pll = pair; using vi = vector; #define pb push_back #define eb emplace_back #define fi first #define se second #define all(x) begin (x), end(x) #define sz(x) (int) (x).size() #define rep(i,a,b) for (int i = (a); i < (b); i++) mt19937 rng(random_device{}()); int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi a(n+1); rep(i,1,n+1) cin >> a[i]; sort(a.begin(), a.end()); int mexSum = 0; auto it_1 = upper_bound(a.begin()+1, a.end(), 1); it_1--; int qtd_1 = it_1 - a.begin(); auto it_2 = upper_bound(a.begin()+1, a.end(), 2); it_2--; int qtd_2 = it_2 - it_1; int remainder = n - qtd_1 - qtd_2; int comb = qtd_1 * qtd_2; mexSum = 3*comb; mexSum += 2 * qtd_1/2 * (qtd_1-1); mexSum += (qtd_2 * (qtd_2-1))/2; mexSum += remainder; cout << mexSum; }