import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Map; import java.util.Map.Entry; import java.util.Scanner; import java.util.Set; import java.util.TreeMap; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final long MOD = 1000000007; Map counts = new TreeMap(); for(int i = 0; i < N; i++){ final long L = sc.nextLong(); if(!counts.containsKey(L)){ counts.put(L, 0); } counts.put(L, counts.get(L) + 1); } System.out.println(counts); long[] count_array = new long[counts.size()]; long sum = 0; { int i = 0; for(final Entry entry : counts.entrySet()){ count_array[i] = entry.getValue(); sum += count_array[i]; i++; } } long answer = 0; long forward_sum = 0, backward_sum = sum; for(int i = 0; i < count_array.length; i++){ backward_sum -= count_array[i]; //System.out.println(sum + " : " + forward_sum + " " + count_array[i] + " " + backward_sum); answer += forward_sum * count_array[i] * backward_sum; answer %= MOD; forward_sum += count_array[i]; } System.out.println(answer); } }