Так вроде норм будет?
https://play.kotlinlang.org/#eyJ2ZXJzaW9uIjoiMS4zLjMwIiwiY29kZSI6ImltcG9ydCBrb3RsaW54LmNvcm91dGluZXMuKlxuaW1wb3J0IGtvdGxpbnguY29yb3V0aW5lcy5jaGFubmVscy4qXG5cblxuZnVuIG1haW4oKSA9IHJ1bkJsb2NraW5nKERpc3BhdGNoZXJzLklPKSB7XG4gICAgcHJpbnRsbihcInN0YXJ0XCIpXG4gICAgdmFsIGl0ZW1zID0gbGlzdE9mKFwib25lXCIsIFwidGhyZWVcIiwgXCJmb3VyXCIsIFwidHdvXCIsIFwiZWxldmVuXCIpXG4gICAgZm9yKGxvYWRlZCBpbiBkb3dubG9hZFBhcmFsZWxsKGl0ZW1zKSkge1xuICAgICAgICBwcmludGxuKGxvYWRlZClcbiAgICB9XG59XG5cbkBVc2VFeHBlcmltZW50YWwoRXhwZXJpbWVudGFsQ29yb3V0aW5lc0FwaTo6Y2xhc3MpXG5mdW4gQ29yb3V0aW5lU2NvcGUuZG93bmxvYWRQYXJhbGVsbChpdGVtczogTGlzdDxTdHJpbmc+KSA9IHByb2R1Y2Uge1xuICAgIGl0ZW1zLmZvckVhY2ggeyBpdGVtIC0+XG4gICAgICAgIGxhdW5jaCB7IHNlbmQoZG93bmxvYWQoaXRlbSkpIH1cbiAgICB9XG59XG5cbnN1c3BlbmQgZnVuIGRvd25sb2FkKGl0ZW06IFN0cmluZyk6IFBhaXI8U3RyaW5nLCBCb29sZWFuPiB7XG4gICAgZGVsYXkoaXRlbS5sZW5ndGggKiAxXzAwMEwpXG4gICAgcmV0dXJuIGl0ZW0gdG8gKGl0ZW0ubGVuZ3RoID4gMylcbn1cbiIsInBsYXRmb3JtIjoiamF2YSIsImFyZ3MiOiIifQ==