https://coderun.yandex.ru/problem/cup-cowcake-throwing/description Легкая

Решение

import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter

private fun cupCowcakeThrowing(results: List<Int>): Int {
    val max = results.max()
    val maxIndex = results.indexOf(max)
    if (maxIndex == results.lastIndex) return 0

    val maxCandidate = results.subList(maxIndex + 1, results.lastIndex)
        .filterIndexed { index, result -> result % 10 == 5 && results[index + maxIndex + 2] < result }
        .maxOrNull() ?: return 0

    return results.sortedDescending().indexOf(maxCandidate) + 1
}

fun main() {
    val reader = BufferedReader(InputStreamReader(System.`in`))
    val writer = BufferedWriter(OutputStreamWriter(System.out))

    reader.readLine()
    val results = reader.readLine().split(" ").map { it.toInt() }

    writer.write(cupCowcakeThrowing(results).toString())
    writer.newLine()
    writer.flush()

    reader.close()
    writer.close()
}