@S=<>=~/./g; for$p(0..2**(@S-1)-1){ ($l,$r)=(0,$#S); $a=''; $a.=$S[$p>>$_&1?$l++:$r--]for 0..@S-2; $h{$a.$S[$l]}=1 } print~~keys%h