print((function (f, g, m) local a = f() if a==true then return "YES" end for _=2,m do if g(a) then return "YES" end end return "NO" end)(function () local a = {0} for e in io.stdin:read("*l"):gmatch("%d+") do if e=="777" then return true end e=tonumber(e) table.insert(a,e) a[1]=a[1]+e end return a end, function (a) local i = 2 for e in io.stdin:read("*l"):gmatch("%-?%d+") do e=tonumber(e) a[1],a[i],i=a[1]+e,a[i]+e,i+1 end if a[1]<777 then return false end for i=2,#a do local t=0 for j=i,#a do t=t+a[j] if t==777 then return true end if t>777 then break end end end return false end, tonumber(io.stdin:read("*l"):match("%d+%s(%d+)"))))