from collections import defaultdict from itertools import combinations N = int(input()) take = defaultdict(lambda: 0) devider = 10**9 + 7 for i in [i for i in input().split()]: take[i] += 1 # len(take)が3未満でも0になる res = 0 for a in list(combinations(take.keys(), 3)): pat = take[a[0]] * take[a[1]] * take[a[2]] res += pat res %= devider print(res)