<>;$_=reverse<>;s/. (?=(.))/$-*=$&!=$1;$%+=$1*++$-/ge;print$%