import Control.Monad (replicateM) import Data.Maybe (fromJust) import qualified Data.ByteString.Char8 as B import Data.Array.Unboxed (UArray, (!), listArray) import Data.Array.Unboxed as UArray rInt :: B.ByteString -> Int rInt = fst . fromJust . B.readInt f777 :: Int -> UArray Int Int -> Bool f777 n xs = f 0 0 0 where f l r s | l == n = False | s == 777 = True | r == n = f (l + 1) r (s - (xs ! l)) | s < 777 = f l (r + 1) (s + (xs ! r)) | otherwise = f (l + 1) r (s - (xs ! l)) solve :: Int -> [[Int]] -> String solve n as = if any (f777 n) as' then "YES" else "NO" where ze = replicate n 0 as' = map (listArray (0, n - 1)) $ scanl (zipWith (+)) ze as {--} main = do [n, m] <- map rInt . B.words <$> B.getLine as <- map (map rInt . B.words) <$> replicateM m B.getLine putStrLn $ solve n as