package net.ipipip0129.kotlin.yukicoder fun main(args: Array) { val len = readLine()!!.toInt() // ループ防止用 val isPass = Array(len, { false }) var np = 1 var cnt = 1 isPass[0] = true while (np != len) { val vp = Integer.toBinaryString(np).filter { s -> s == '1' }.length if (len < np + vp) { np -= vp } else { if (isPass[np + vp - 1]) { if (np - vp <= 0) { println("-1") return } else { np -= vp } } else { np += vp } } if (isPass[np - 1]) { println("-1") return } isPass[np - 1] = true cnt += 1 } println(cnt) }