N = gets.to_i A = gets.split.map(&:to_i) C = A.inject(Hash.new(0)) {|hash, a| hash[a] += 1; hash} ans = (C.values.combination(3).map {|x, y, z| x * y * z}.inject(:+)) % (10**9 + 7) puts ans