from itertools import combinations MOD = 10**9 + 7 n = int(input()) a = list(map(int, input().split())) # Count the occurrences of each number cnt = {} for num in a: cnt[num] = cnt.get(num, 0) + 1 # Get sorted list of unique numbers unique = sorted(cnt.keys()) result = 0 # Generate all combinations of three distinct numbers for trio in combinations(unique, 3): x, y, z = trio result += cnt[x] * cnt[y] * cnt[z] result %= MOD print(result % MOD)