Problem:
Score : 300 points

Problem Statement

You are given a string S consisting of digits between 1 and 9, inclusive.
You can insert the letter + into some of the positions (possibly none) between two letters in this string.
Here, + must not occur consecutively after insertion.

All strings that can be obtained in this way can be evaluated as formulas.

Evaluate all possible formulas, and print the sum of the results.

Constraints

1 \leq |S| \leq 10

All letters in S are digits between 1 and 9, inclusive.

Input

The input is given from Standard Input in the following format:

S

Output

Print the sum of the evaluated value over all possible formulas.

Sample Input 1

125

Sample Output 1

176

There are 4 formulas that can be obtained: 125, 1+25, 12+5 and 1+2+5. When each formula is evaluated,

125

1+25=26

12+5=17

1+2+5=8

Thus, the sum is 125+26+17+8=176.

Sample Input 2

9999999999

Sample Output 2

12656242944

Solution in Rust (1.15.1) (judge verdict: Accepted)

pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn itob(i: u32) -> Vec<bool> {
    let mut n = i;
    let mut ret: Vec<bool> = vec![];
    for _ in 0..9 {
        if n % 2 == 1 {
            ret.push(true);
        } else {
            ret.push(false);
        }
        n /= 2;
    }
    ret
}

fn pow(u: u32) -> u32 {
    let mut ret: u32 = 1;
    for _ in 0..u {
        ret *= 2;
    }
    ret
}

fn main() {
    let mut ans: u64 = 0;
    let s: String = read();
    let cv: Vec<char> = s.chars().collect();

    if cv.len() == 1 {
        println!("{}", cv[0]);
        return;
    }

    for i in 0..pow(s.len() as u32 - 1) {
        let bv = itob(i);
        let mut tmp: Vec<char> = vec![cv[0]];
        for j in 1..cv.len() {
            if bv[j - 1] {
                let stmp: String = tmp.clone().into_iter().collect();
                let utmp: u64 = stmp.parse().unwrap();
                ans += utmp;
                tmp = vec![cv[j]];
            } else {
                tmp.push(cv[j]);
            }
        }
        let stmp: String = tmp.clone().into_iter().collect();
        let utmp: u64 = stmp.parse().unwrap();
        ans += utmp;
    }

    println!("{}", ans);
}