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