import java.io.PrintWriter import java.util.* import kotlin.math.* fun nextPermutation(array: MutableList): Boolean { var tmp: Int for (i in array.size - 2 downTo 0) { if (array[i] < array[i + 1]) { for (j in array.size - 1 downTo i + 1) { if (array[j] > array[i]) { tmp = array[i] array[i] = array[j] array[j] = tmp val tmpArray = array.takeLast(array.size - (i + 1)).sorted() tmpArray.forEachIndexed { index, e -> array[i + 1 + index] = e } return true } } } } return false } fun PrintWriter.solve() { val n = nextInt() val a = Array(n) { nextInt() } val b = Array(n) { nextInt() } val p = (0 until n).toMutableList() val map = mutableMapOf() do { var point = 0 for (i in 0 until n) { point += maxOf(0, a[p[i]] - b[i]) } map[point] = (map[point] ?: 0) + 1 } while (nextPermutation(p)) val max = map.keys.maxOrNull()!! println(map[max]!!) } fun main() { Thread(null, { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() }, "solve", 1.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