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 <bits/stdc++.h>

#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// type alias
using VI = std::vector<int>;
using VII = std::vector<VI>;
using VB = std::vector<bool>;
using VBB = std::vector<VB>;
using VS = std::vector<std::string>;
using PII = std::pair<int, int>;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  solve();
  return 0;
}

// [解法1] bit全探索
// void solve() {
//   std::string s;
//   std::cin >> s;
//   // check(SIZE(s));
//   int total = 0;
//   for (int i = 0; i < (1 << (SIZE(s) - 1)); i++) {
//     std::bitset<10> b(i);
//     // check(b);
//     b.set(SIZE(s) - 1);
//
//     int sum = 0;
//     int count = 1;
//     for (int j = 0; j < SIZE(s); j++) {
//       // check(j);
//       if (b.test(j)) {
//         // check(count);
//         // check(s.substr(j + 1 - count, count));
//         sum += std::stoll(s.substr(j + 1 - count, count));
//         count = 1;
//       } else {
//         count++;
//       }
//     }
//     // check(sum);
//     total += sum;
//     // cout("");
//   }
//   cout(total);
// }

// [解法2] 端から入れるかどうか決めていく再帰で深さ優先探索
void dfs(int i, std::string s, int next, int sofar, int &total);
void solve() {
  std::string s;
  std::cin >> s;
  int total = 0;
  dfs(0, s, 0, 0, total);
  cout(total);
}
void dfs(int i, std::string s, int next, int sofar, int &total) {
  if (i == SIZE(s) - 1) {
    total += sofar + next*10 + stoll(s.substr(i, 1));
    return;
  }
  // (i+1)文字目の後に+を入れない
  dfs(i+1, s, next*10 + stoll(s.substr(i, 1)), sofar, total);
  // (i+1)文字目の後に+を入れる
  dfs(i+1, s, 0, sofar + next*10 + stoll(s.substr(i, 1)), total);
}