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

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

unsigned long long int fac(int n) {
    unsigned long long int r = 1;
    for (int i = 1; i <= n; i++) {
        r *= 2;
    }
    return r;
}

void genbin(int n, char *bin, int l) {
    int i = 0;
    memset(bin, '\0', 11); //sizeof(bin));
    bin[0] = '0';
    while (n >= 1) {
        bin[i++] = (n % 2) + '0';
        n = n / 2;
    }
    // 6 -> 011

    // 0埋め（後ろへ０を詰めて、）
    int m = strlen(bin);
    for (;m < l; m++) {
        bin[m] = '0';
    }
    bin[m] = '\0';
    // 6 -> 011 -> 0110

    // swap（最初と最後を交換すると、ヒューマンリーダブルなバイナリ文字列ができる）
    m = strlen(bin);
    i = m - 1;
    for (int j = 0; j < m/2; j++) {
        char t = bin[i];
        bin[i] = bin[j];
        bin[j] = t;
        i -= 1;
    }
    // 6 -> 011 -> 0110 -> 0110
}

unsigned long long int ebal(char *s, char *op) {
    unsigned long long int r = 0;
    char t[10+10+1] = {0};

    //  s[i] = 123
    // op[k] =  01z
    //  t[j] = 12+3+
    for (int i = 0, j = 0, k = 0, l = 0; i < strlen(s); i++, k++) {
        t[j++] = s[i];
        if (op[k] == '1' || op[k] == 'z') {
            char u[10+1] = {0};
            strncpy(u, t+l, j-l);
            u[j-l+1] = '\0';
            //printf("i=%d j=%d k=%d l=%d s=%s op=%s u=%s\n", i, j, k, l, s, op, u);
            r += atol(u);
            t[j++] = '+';
            l = j;
        }
    }
    //printf("%s %s\n", op, t);
    //eval(t);

    return r;
}

int main() {
    char s[10+1];
    scanf("%s", s);

    int l = strlen(s);
    if (l == 1) {
        printf("%s\n", s);
        return 0;
    }

    char bin[9+1+1] = {0};
    unsigned long long int r = 0;
    for (unsigned long long int i = 0; i < fac(l-1); i++) {
        genbin(i, bin, l-1);
        bin[strlen(bin)] = 'z'; // 終端文字番兵
        bin[strlen(bin)+1] = '\0';
        r += ebal(s, bin);
    }

    printf("%lld\n", r);
    return 0;
}