from collections import defaultdict from itertools import combinations N = int(input()) take = defaultdict(lambda: 0) devider = 1000000007 for i in [i for i in input().split()]: take[i] += 1 # len(take)が3未満でも0になる res = len(list(combinations(range(len(take)), 3))) res %= devider for i in [i for i in take.values() if 1 < i]: res *= i res %= devider print(res)