$\=NO;<>;$s=$i=$j=!s/\S+/$s+=${--$j}+=$&;$s-=${--$i}while$s>777;$s-777or$\=YES/gerfor<>;print