import kotlin.system.exitProcess val br = System.`in`.bufferedReader() fun readLine(): String? = br.readLine() fun readString() = readLine()!! fun readInt() = readString().toInt() fun readStrings() = readLine()?.split(" ")?.filter { it.isNotEmpty() } ?: listOf() fun readInts() = readStrings().map { it.toInt() }.toIntArray() const val MAX_STACK_SIZE: Long = 128 * 1024 * 1024 fun main() { val thread = Thread(null, ::run, "solve", MAX_STACK_SIZE) thread.setUncaughtExceptionHandler { _, e -> e.printStackTrace(); exitProcess(1) } thread.start() } fun run() { val N = readInt() val a = readInts() output(solve(N, a)) } fun solve(N: Int, a: IntArray): Int { val sum = a.sum() fun canDivide(target: Int): Boolean { var sum = 0 for (ai in a) { sum += ai if (sum == target) sum = 0 else if (sum > target) return false } return sum == 0 } var res = 1 var i = 2 while (i * i <= sum) { if (sum % i == 0) { val target = sum / i if (canDivide(target)) res = i } i++ } return res } fun output(res: Int) = println(res)