import kotlin.math.PI fun main(arr:Array) { rgb = readLine()!!.split(" ").map { it.toInt() }.sorted() val ans = getAns(rgb[0], rgb[2]) println(ans) } var rgb = listOf() fun getAns(min:Int, max:Int):Int { if(max-min <= 1) { if(canCreate(max)) { return max } return min } val mid = (max+min)/2 return if(canCreate(mid)) { getAns(mid, max) } else { getAns(min, mid) } } fun canCreate(count:Int):Boolean { if(count*3 > rgb.sum()) { return false } if(count <= rgb[0]) { return true } val diff = rgb.map { it - count }.toMutableList() if(diff[0] < 0) { val move = Math.min(diff[0] * -1, diff[2] / 2) diff[0] += move diff[2] -= move*2 if(diff[0] < 0 && diff[1] > 0) { val move2 = Math.min(diff[0] * -1, diff[1] / 2) diff[0] += move2 diff[1] -= move2 * 2 } } if(diff[1] < 0) { val move = Math.min(diff[1] * -1, diff[2] / 2) diff[1] += move diff[2] -= move * 2 } return diff.all { it >= 0 } }