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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <iostream>
#include <string>
#include <vector>

#include <sstream>
#include <bitset>

#include <cmath>

using namespace std;

int debug=0;

int main(){
    string S;
    cin >> S;
    int len1= S.length();
    vector<bitset<9>> Bit;
    vector<bitset<9>> Mask;
    
    // create bitmap
    // abc
    // len1=3
    // 00
    // 01
    // 10
    // 11
    int allnum = pow(2,len1-1);
    for(int i =0; i< allnum; ++i) {
        Bit.push_back(bitset<9>(i));
        //cout << Bit[i] << endl;
        //cout << static_cast<bitset<9>>(i) << endl;
    }

    // create bitmask
    // 01
    // 10
    for(int i=9; i>0;--i){
        int tmp;    
        tmp = pow(2,i-1);
        Mask.push_back(bitset<9>(tmp));
        // cout << static_cast<bitset<9>>(tmp) << endl;
    }

    // cout << "mask[0]=" << Mask[0] << endl;

    string st_num="";
    long long num1=0;
    long long sum=0;
    for(int i=0; i<allnum; ++i){
        // S="abc"
        // len1=3
        //
        // Bit[i] 
        // 0...00 -> abc
        // 1...01 -> ab+c
        // 2...10 -> a+bc
        // 3...11 -> a+b+c
        //
        // st_num ="c"
        // num=0
        bitset<9> bit1;
        string st1="x";
        bit1 = Bit[i];
        st1[0] = S[len1-1];
        // cout << "char..." << st1 <<endl;
        st_num = st1;
        //
        if(debug) cout << "Try Bit[i]" << bit1 <<endl;
        //
        for(int j=0;j<len1-1;++j){
            // 0...00 -> abc
            // 1...01 -> ab+c
            // 2...10 -> a+bc
            // 3...11 -> a+b+c
            // try bitmask
            // j=0 01
            // j=1 10
            // S="abc"
            // len1=3
            if(debug) cout << "st_num=" << st_num << ",sum=" << sum ;
            if(debug) cout << ",mask=" << Mask[9-1-j] << endl;
            // 
            bitset<9> bit2;
            bit2 = bit1 & Mask[9-1-j];
            if (bit2.any()){
                // found +
                num1 = stoll(st_num);
                //
                if(debug) cout <<"found +, st_num= " << st_num << endl;
                sum += num1;

                string st2="x";
                st2[0] = S[len1-1-j-1];
                st_num= st2;

            }else {
                string st3="x";
                st3[0] =S[len1-1-j-1];
                st_num = st3 + st_num;
            }
        } 
        //
        if(debug)cout << "st_num=" << st_num << ",sum=" << sum <<endl;
        // 
        if (st_num != ""){
            num1 = stoll(st_num);
            sum += num1;
            st_num="";
        }
    }

    cout << sum << endl;


}