#!/usr/bin/env python3 # -*- coding: utf-8 -*- import collections import itertools MODULUS = 10 ** 9 + 7 def main(): _ = input() counter = collections.Counter(map(int, input().split())) num_distinct_heights = len(counter) answer = 0 if num_distinct_heights >= 3: for key1, key2, key3 in itertools.combinations(counter.keys(), 3): answer += counter[key1] * counter[key2] * counter[key3] print(answer % MODULUS) if __name__ == '__main__': main()