import java.io.PrintWriter import java.util.* import kotlin.math.* fun lis(p: List): Int { val lst = mutableListOf() loop@for (v in p) { for (i in lst.indices) { if (lst[i] > v) { lst[i] = v continue@loop } } lst.add(v) } return lst.size } fun PrintWriter.solve() { val n = nextInt() val p = (1..n).toMutableList() var num = 0 do { if (lis(p) + lis(p.reversed()) == n) { num++ } } while (nextPermutation(p)) println(num) } fun nextPermutation(lst: MutableList): Boolean { val n = lst.size for (i in n - 2 downTo 0) { if (lst[i] < lst[i + 1]) { for (j in n - 1 downTo i + 1) { if (lst[j] > lst[i]) { lst[i] = lst[j].also { lst[j] = lst[i] } val tmpArray = lst.takeLast(n - (i + 1)).sorted() tmpArray.forEachIndexed { index, e -> lst[i + 1 + index] = e } return true } } } } return false } fun main() { Thread(null, { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() }, "solve", abs(1L.shl(26))) .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } } .apply { start() }.join() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() // endregion