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