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 (_, M) = readInts() val a = Array(M) { readInts() } output(solve(M, a)) } fun solve(M: Int, a: Array): Boolean { val row = a[0].clone() fun has777(): Boolean { var i = 0 var sum = 0 for (j in row.indices) { sum += row[j] while (i < j && sum > 777) sum -= row[i++] if (sum == 777) return true } return false } if (has777()) return true for (i in 1 until M) { for (j in row.indices) row[j] += a[i][j] if (has777()) return true } return false } fun output(res: Boolean) = println(if (res) "YES" else "NO")