fun main(arr:Array) { val itemCount = readLine()!!.toInt() val items = readLine()!!.split(" ").map { it.toInt() }.let { a-> a.toSet().sorted().map { b-> b to a.count { it == b } } }.toMap() val keys = items.keys.toList() val count = items.keys.map { 0 }.toTypedArray() val mod = 1000000000 + 7 for(i in keys.indices) { if(i == 0) { count[0] = items[keys[0]]!! } else { count[i] = count[i-1] + items[keys[i]]!! } } var ans = 0L for(i in (0..keys.lastIndex - 2)) { for(j in (i+1..keys.lastIndex - 1)) { val remain = (count.last() - count[j]).toLong() var ptn = items[keys[i]]!!.toLong() * items[keys[j]]!!.toLong() ptn = ptn % mod ptn *= remain ptn = ptn % mod ans += ptn ans = ans % mod } } println(ans) }