import kotlin.system.exitProcess val br = System.`in`.bufferedReader() fun readLine(): String? = br.readLine() 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, M) = readInts() val a = Array(M) { readInts() } output(solve(N, M, a)) } fun solve(N: Int, M: Int, a: Array): Boolean { val preSum = a[0].scan(0, Int::plus).toIntArray() fun has777(): Boolean { for (i in 0 until N) { for (j in 1..N) { if (preSum[j] - preSum[i] == 777) return true } } return false } if (has777()) return true for (i in 1 until M) { var s = 0 for (j in 1..N) { s += a[i][j - 1] preSum[j] += s } if (has777()) return true } return false } fun output(res: Boolean) = println(if (res) "YES" else "NO") /* 10 700 0 0 3 10 710 710 710 713 0 0 70 7 -1 10 700 70 7 2 10 710 780 787 789 1 1 1 1 1 11 701 71 8 3 */