<>;map{y/.\n/ /d,$c&1?$_ eq$p?++$e:$_ eq$p=~s/ #*/$&=~y,#, ,r/er||/ /<$p=~/ /&&$e?++$c:($_^=$p=~y/ #/AD/r,/^g*((ad*|d*a)g*)*$/)?($d+=s/a(d+)|(d+)a/$1a$2/g,y/adg/ #/,$p=$_):($c=9):s/^#* \K *(?= #*$)/$&=~y, ,#,r/e?($p=$_,++$c):($c+=/ /*9)}<>,$z;print$c==2&$d<2?YES:NO