AAAAAAAAAAAAAAAAAA
Code


# Code
```kotlin []
class Solution {
    fun findXSum(nums: IntArray, k: Int, x: Int): IntArray {
        val n = nums.size
        val result = IntArray(n - k + 1) { 0 }
        for (i in 0..n - k) {
            val map = HashMap<Int, Int>()
            nums.drop(i).take(k).forEach {
                map[it] = map.getOrDefault(it, 0) + 1
            }
            result[i] = map
                .toList()
                .sortedWith(compareBy({ it.second }, { it.first }))
                .takeLast(x)
                .sumOf { it.second * it.first }
        }
        return result
    }
}
```
['Kotlin']