# -*- coding:utf-8 -*- import collections import math if __name__ == "__main__": n = input() A = map(int,raw_input().split()) num = len(set(A)) cnt = collections.Counter(A) temp = 10 **9 + 7 if num < 3: print 0 else: ans = num * (num-1) * (num-2) / 6.0 for element in cnt.most_common(): ans *= element[1] print int(ans) % temp