fun main(args:Array) { val n = readLine()!!.toInt() val input = readLine()!!.split(" ").map { it.toLong() } val num_freq = mutableMapOf() // 最頻値(high freqサーチ) input.map { if( num_freq.get(it) == null ) num_freq[it] = 0 num_freq[it] = num_freq[it]!! + 1 } val high = num_freq.toList().sortedBy { it.second }.last() // highfreqの個数をカウント val size = num_freq.toList().filter { it.second == high.second }.size // 誤差計算 if( size == 1 ) { input.map { Math.abs( it - high.first) }.sum().let { println(it) } } else { val mean = num_freq.toList().filter { it.second == high.second }.map { it.first }.sum() / size input.map { Math.abs( it - mean ) }.sum().let { println(it) } } }