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