just an example
Code\n\nclass Solution {\n    \n    fun sumOfFlooredPairs(nums: IntArray): Int {\n        val maxN = nums.max()\n        val v = nums.fold(IntArray(N+1)) { a, n
# Code\n```\nclass Solution {\n    \n    fun sumOfFlooredPairs(nums: IntArray): Int {\n        val maxN = nums.max()\n        val v = nums.fold(IntArray(N+1)) { a, n -> a.also{ a[n]++ } }.apply {(1..N).forEach { i -> this[i] += this[i-1] }}\n        return nums.toSet().fold(0.toLong()){ sum, x ->\n            (sum + generateSequence(D(x, x*2-1, 1, 0)) { d ->\n                                    D(d.l + x, d.r + x, d.acc + 1, (d.sum + d.acc*(v[d.r]-v[d.l-1]))%MOD)\n                   }.find { it.l > maxN }!!.sum.let { (it*(v[x]-v[x-1]))%MOD } ) % MOD }.toInt()\n    }\n\n    private val N = 200002\n    private val MOD = 1_000_000_007\n    private data class D(val l: Int, val r: Int, val acc: Long, val sum: Long)\n}\n```
['Kotlin']