from collections import Counter N = int(input()) A = Counter(map(int, input().split())) lA = len(A) MOD = 10 ** 9 + 7 comb = (lA * (lA - 1) * (lA - 2) // 6) % MOD s = 1 for v in A.values(): s = (s * v) % MOD print(comb * s % MOD)