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# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            List<char> cA = Console.ReadLine().Trim().ToCharArray().ToList();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<List<char>> lstCal = new List<List<char>>();                                                       // 考えられる数式一覧
            for (int i = 0; i < Math.Pow(2, cA.Count - 1); i++)
            {
                List<char> oneUsr = new List<char>();
                oneUsr.AddRange(cA);
                lstCal.Add(oneUsr);                                                                                 // Defaultは入力値
            }
            // 数式生成
            for (int i = 0; i < lstCal.Count ; i++)                                                                 // 数値の間に+挿入
            {                                                                                                       // 考えられる場合全て考慮
                List<char> cBin = Convert.ToString(i, 2).ToCharArray().ToList();                                    // 現在の値を2進法で
                cBin.Reverse();                                                                                     // 下の桁からにする為、リバース
                List<int> iIns = new List<int>();                                                                   // + 挿入箇所
                for (int j = 0; j < cBin.Count; j++) { if (cBin[j] == '1') { iIns.Add(j+1); } }                     // 2進法で1の立っている箇所に+挿入
                iIns.Reverse();                                                                                     // 大きいほうからの為、リバース
                for (int j = 0; j < iIns.Count; j++) { lstCal[i].Insert(iIns[j], '+'); }                            // 大きい方から挿入しないとIndexNoがずれる
            }
            // 数式計算
            long lOut = 0L;
            for (int i = 0; i < lstCal.Count; i++)
            {
                string sOne = new String(lstCal[i].ToArray());                                                      // charからStringへ変換
                string[] sAry = sOne.Split('+');
                for (int j = 0; j < sAry.Length; j++)
                {
                    lOut += long.Parse(sAry[j]);
                }
            }

            // 出力
            Console.WriteLine("{0}", lOut.ToString());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine();
            for (int i = 0; i < lstCal.Count; i++)
            {
                string sOut = new String(lstCal[i].ToArray());                                                      // charからStringへ変換
                Console.WriteLine("{0}", sOut.ToString());
            }
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}