from collections import Counter N = int(input()) A = list(map(int, input().split())) C = Counter(A) NC = len(C) dp = [1, 0, 0, 0] for v in C.values(): dp2 = [1, 0, 0, 0] for i in range(3): dp2[i + 1] = dp[i + 1] + v * dp[i] dp = dp2 print(dp[3])