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: Runtime Error)

use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

macro_rules! trace {
    ($var:expr) => ({
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    })
}
macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }

fn eval(s: &Vec<u64>, a: &Vec<usize>) -> u64 {
    let mut r: u64 = 0;
    let mut ac: u64 = s[0];
    let n = s.len();
    for i in 1..n {
        if a[i-1] == 0 {
            ac = ac * 10 + s[i];
        } else {
            r += ac;
            ac = s[i];
        }
    }
    r += ac;
    // trace!((s, a, r));
    return r
}

fn main() {
    let mut sc = Scanner::new();
    let s: String = sc.cin();
    let cs: Vec<u64> = s.chars().map(|c| (c as u64) - ('0' as u64)).collect();
    let n = s.len();
    let mut ans: u64 = 0;
    for a in PowerPermutation::new(2, n - 1) {
        ans += eval(&cs, &a);
    }
    println!("{}", ans);

}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}
struct PowerPermutation { n: usize, m: usize, ar: Vec<usize> }
impl PowerPermutation {
    fn new(n: usize, m: usize) -> PowerPermutation {
        let ar = vec![0; m];
        PowerPermutation { n: n, m: m, ar: ar }
    }
}
impl Iterator for PowerPermutation {
    type Item = Vec<usize>;
    fn next(&mut self) -> Option<Vec<usize>> {
        if self.ar[self.m-1] >= self.n { return None }
        let r = self.ar.clone();
        self.ar[0] += 1;
        for i in 0..self.m-1 {
            if self.ar[i] == self.n {
                self.ar[i] = 0;
                self.ar[i + 1] += 1;
            } else {
                break;
            }
        }
        return Some(r);
    }
}