import sys from bisect import bisect_right sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') MOD = 10 ** 9 + 7 def solve(): n = int(input()) A = list(map(int, input().split())) A.sort() res = 0 for i in range(n): j = bisect_right(A, A[i]) res += (A[i] + 1) * (j - i - 1) k = bisect_right(A, A[i] + 1) res += (A[i] + 2) * (k - j) res += (A[i] + 1) * (n - k) print(res) if __name__ == '__main__': solve()