Under construction

Still being built. Things may change

Eve, Psyche and the Wife of the Blue MEX

Interview

Time limit1sMemory limit1024 MB

Summary
Given N integers, compute the sum of mex({A_i, A_j}) over all pairs i<j of the array.
Level

Easy3 of 10

Topics
Combinatorics, Math
Solved
No attempts yet

Problem

mex(S)\textrm{mex}(S) is the smallest non-negative integer not contained in the set SS.

Given NN non-negative integers A1,A2,…,ANA_1, A_2, \dots, A_N, write a program that computes the following value.

∑i=1N−1∑j=i+1Nmex({Ai,Aj})\sum_{i=1}^{N-1} \sum_{j=i+1}^{N} \textrm{mex}(\{A_i, A_j\})

Input

The first line contains an integer NN. (2≤N≤200 0002 \le N \le 200\,000)

The second line contains NN integers A1,A2,…,ANA_1, A_2, \dots, A_N separated by spaces. (0≤Ai≤100 0000 \le A_i \le 100\,000)

Output

Print the value the problem asks for.

Examples1

  1. Example 1

    Input
    8
    0 2 0 1 3 2 1 0
    
    Expected output
    24