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 (Clang 3.8.0) (judge verdict: Accepted)

//#include <algorithm>
#include <array>
//#include <cassert>
//#include <cfloat>
//#include <cmath>
//#include <cstdio>
//#include <cstdlib>
//#include <deque>
#include <iostream>
//#include <limits>
//#include <map>
//#include <queue>
//#include <set>
//#include <stack>
//#include <string>
//#include <tuple>
//#include <unordered_map>
//#include <unordered_set>
//#include <vector>
using namespace std;

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

string S;
long sum;

void dfs(int cur, array<char, 10> plus) {
  if (cur >= S.size()) {
    long num{};
    for (int i{}; i < S.size(); ++i) {
      if (plus[i] == '+') {
//        cerr << num << endl;
        sum += num;
        num = 0;
      }
      num *= 10;
      num += S[i] & 0xF;
    }
//    cerr << num << endl;
    sum += num;
    return;
  }
  dfs(cur + 1, plus);
  plus[cur] = '+';
  dfs(cur + 1, plus);
}

int main() {
  cin >> S;
  array<char, 10> plus;
  dfs(1, plus);
  cout << sum << endl;

  return 0;
}