Kotlin evenly allocation
Code\n\nclass Solution {\n    \n        var upperList = mutableListOf<Int>()\n        var lowerList = mutableListOf<Int>()\n        var result: List<List<Int>> 
# Code\n```\nclass Solution {\n    \n        var upperList = mutableListOf<Int>()\n        var lowerList = mutableListOf<Int>()\n        var result: List<List<Int>>  = listOf(upperList, lowerList)\n        var upperCnt = 0\n        var lowerCnt = 0\n    fun reconstructMatrix(upper: Int, lower: Int, colsum: IntArray): List<List<Int>> {\n        upperCnt = upper\n        lowerCnt = lower\n        colsum.forEach {\n            when(it) {\n                2 -> {\n                    when {\n                        upperCnt > 0 && lowerCnt > 0 -> addOneBoth()\n                        else -> return emptyList()\n                    }\n                }\n                1 -> when {\n                    upperCnt > 0 && upperCnt >= lowerCnt -> {\n                        addOneUpper()\n                    }\n                    lowerCnt > 0 && lowerCnt >= upperCnt -> {\n                        addOneLower()\n                    }\n                    else -> return emptyList()\n                }\n                0 -> addZeorBoth()\n            }\n        }\n        if(upperCnt != 0 || lowerCnt != 0) {\n            return emptyList()\n        }\n        return result\n    }\n\n    fun addOneBoth(){\n        upperList.add(1)\n        upperCnt--\n        lowerList.add(1)\n        lowerCnt--\n        // println("uppercnt= $upperCnt | lowerCnt = $lowerCnt")\n        // println("addOneBoth: " + upperList.toString() + " | " + lowerList.toString())\n    }\n\n        fun addZeorBoth(){\n        upperList.add(0)\n        lowerList.add(0)\n        // println("uppercnt= $upperCnt | lowerCnt = $lowerCnt")\n        // println("addZeorBoth: " + upperList.toString()+ " | " + lowerList.toString())\n    }\n\n     fun addOneUpper(){\n        upperList.add(1)\n        upperCnt--\n        lowerList.add(0)\n        // println("uppercnt= $upperCnt | lowerCnt = $lowerCnt")\n        // println("addOneUpper: " + upperList.toString() + " | " + lowerList.toString())\n    }\n\n    fun addOneLower(){\n        upperList.add(0)\n        lowerList.add(1)\n        lowerCnt--\n        // println("uppercnt= $upperCnt | lowerCnt = $lowerCnt")\n        // println("addOneLower: " + upperList.toString() + " | " + lowerList.toString())\n    }\n}\n```
['Kotlin']