sub f{my$x=$_;$g[$_]or$g[$_]=1,map$$_[$x]&&&f,0..499}<>;map{$d[$_]^=$$_[$`+$&-$_]=$h[$_]=1for/\d+/g;f}<>;print@g~~@h&grep($_,@d)<3?YES:NO