import kotlin.math.min fun main() { val output = System.out.bufferedWriter() fun write(s: CharSequence) { output.appendLine(s) output.flush() } val (a, b, c) = readln().split(" ").map { it.toInt() } var spentTickets = 0 var plane = false var index = 0 fun airline() { write("airline") spentTickets += a } fun self() { write("self") } fun buy() { write("buy") plane = true } var state = readln() while (state != "end") { index++ when { // airline is always cheaper than private flight c >= a -> airline() // we own the plane, use it plane -> self() // if the cost of buying the plane and trip fits in our current budget, buy it b + c <= 2 * min(a * index, b + c * index) - spentTickets -> buy() // buy a ticket else -> airline() } state = readln() } }