import java.util.*; public class Main { static final int MOD = 1000000007; public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); HashMap map = new HashMap<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt(); if (map.containsKey(x)) { map.put(x, map.get(x) + 1); } else { map.put(x, 1); } } int length = map.size(); int[] arr = new int[length + 1]; int[] sums = new int[length + 1]; int[] totals = new int[length + 1]; int idx = 1; for (int x : map.values()) { arr[idx] = x; sums[idx] = sums[idx - 1] + arr[idx]; sums[idx] %= MOD; totals[idx] = (int)((long)(arr[idx]) * sums[idx - 1] + totals[idx - 1] % MOD); idx++; } long ans = 0; for (int i = length; i >= 1; i--) { ans += (long)(arr[i]) * totals[i - 1]; ans %= MOD; } System.out.println(ans); } }