fun main() { val (n, m) = readLine()!!.trim().split(' ').map(String::toInt) val gems = Array(n){readLine()!!.trim().split(' ').map(String::toInt)} val gemSum = (0 until m).map{j -> gems.sumBy{it[j]}} gems.sortByDescending{it.zip(gemSum).map{(a, b) -> a.toLong() * b}.sum()} val myScore = LongArray(m){0L} val enjapma = LongArray(m){0L} for (i in 0 until n) { when (i and 1) { 0 -> for (j in 0 until m) { myScore[j] += gems[i][j].toLong() } else -> for (j in 0 until m) { enjapma[j] += gems[i][j].toLong() } } } println(myScore.map{it * it}.sum() - enjapma.map{it * it}.sum()) }