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.values(), 3)): pat = a[0]*a[1]*a[2] res += pat res %= devider print(res)