object Main extends App { val a: String = scala.io.StdIn.readLine() val b: String = scala.io.StdIn.readLine() val aIntOpt = if (a.matches("^(?!00)[0-9]{1,5}")) { Some(a.toInt) } else { None } val bIntOpt = if (b.matches("^(?!00)[0-9]{1,5}")) { Some(b.toInt) } else { None } val ans = for { a <- aIntOpt b <- bIntOpt if (a + b) <= 12345 } yield { a + b } println(if (ans.nonEmpty) "OK" else "NG") }