Решение
import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
fun main() {
val reader = BufferedReader(InputStreamReader(System.`in`))
val writer = BufferedWriter(OutputStreamWriter(System.out))
val input = reader.readLine().split(" ").map { it.toInt() }
val a = input[0]
val b = input[1]
val c = input[2]
val d = input[3]
val options = mutableListOf<Triple<Int, Int, Long>>()
val laptop1 = listOf(Pair(a, b), Pair(b, a))
val laptop2 = listOf(Pair(c, d), Pair(d, c))
for (l1 in laptop1) {
for (l2 in laptop2) {
val w1 = l1.first
val h1 = l1.second
val w2 = l2.first
val h2 = l2.second
val widthH = w1 + w2
val heightH = maxOf(h1, h2)
options.add(Triple(widthH, heightH, widthH.toLong() * heightH))
val widthV = maxOf(w1, w2)
val heightV = h1 + h2
options.add(Triple(widthV, heightV, widthV.toLong() * heightV))
}
}
val bestOption = options.minByOrNull { it.third }!!
writer.write("${bestOption.first} ${bestOption.second}")
reader.close()
writer.close()
}