from collections import Counter m = 1000000007; n = int(input()) a = dict(Counter(list(map(int, input().split())))) dp = [0,0,0] for d in a: newdp = [a[d],0,0] for i in range(3): newdp[i] = (newdp[i]+dp[i])%m for i in range(1, 3): newdp[i] = (newdp[i]+dp[i-1]*a[d])%m dp = newdp print(dp[2])