print<>*grep(@$_>2,grep{//,@$_=grep$' ne$_,@{$_=pop@$_}until$#$_}map{($a)=/\S+ \S+/g;push@$a,$&;push@ $&,$a;//g}<>)?NO:YES