#!perl $p=pop;$i=pop;sub t{my$n=pop;$k.=$c=substr($p,$n,1);$d[$n]=1;map{$a=$_;map{$t=substr($p,$_,1);t($_)if$i=~/$c.*$t/&&!$a||$i=~/$t.*$c/&&$a and!$d[$_]}$n..length$p}0,1}t 0;print reverse($k)." "