N = int(input()) A = sorted(map(int, input().split(" "))) mod = int(10e9 + 7) A_s = set(A) A_count = len(A_s) A_dict = {i:0 for i in A_s} for i in A: A_dict[i] += 1 if A_count < 3: print(0) else: total = (A_count * (A_count - 1) * (A_count - 2)) // 2 // 3 total %= mod for v in A_dict.values(): total *= (v % mod) total %= mod print(total)