main=getLine>>=print.(\x->f x (2^((length x)-1)) x (length x) 0 0 "")
 where f x m s n i a e|i==m = a
                      |n==0 = f x m x (length x) (i+1) (a+((sum.(map read).words) e)) ""
                      |(quot(mod i(2^n))(2^(n-1)))==1 = f x m (init s) (n-1) i a ((last s):' ':e)
                      |otherwise = f x m (init s) (n-1) i a ((last s):e)