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