N = int(input())
A = [int(n) for n in input().split(' ')]
s = 0
a,b=[0,0]
for i in range(N-1):
    for j in range(i, N):
        if A[i]==A[j]:
            a +=1
        else:
            b+=1
         
    
ans = (a*b) % (10**9+7)
print(ans)