N = int(input()) l = list(map(int, input().split())) s = set(l) l_count = [] l.sort() old_l_i = 0 count = 0 ans = 0 for l_i in l: if old_l_i == l_i: count += 1 else: l_count.append(count) count = 1 old_l_i = l_i l_count.append(count) l_count = l_count[1:] for i in range(len(l_count) - 2): for j in range(i + 1, len(l_count) -1): for k in range(j + 1, len(l_count)): ans += l_count[i] * l_count[j] * l_count[k] print(ans % 1000000007)