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.Linq;
using System.Collections.Generic;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            ARC061.C();
        }
        class ARC061
        {
            public static void C()
            {
                var S = Read.Str().Select(c => c - '0').ToArray();
                var N = S.Length;
                long sum = 0;
                for(int i = 0; i < (1 << (N - 1)); ++i)
                {
                    long current = S[0];
                    for(int j = 1; j < N; ++j)
                    {
                        if (((1 << (j - 1)) & i) > 0)
                        {
                            sum += current;
                            current = S[j];
                        }
                        else
                        {
                            current = 10 * current + S[j];
                        }
                    }
                    sum += current;
                }
                Console.WriteLine(sum);
            }
            public static void D()
            {
                var H = Read.Long();
                var W = Read.Long();
                var N = Read.Int();
                var AB = Read.TupleInt(N);
                Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
                foreach(var ab in AB)
                {
                    if (!dict.ContainsKey(ab.Item1 - 1)) { dict.Add(ab.Item1 - 1, new HashSet<int>()); }
                    dict[ab.Item1 - 1].Add(ab.Item2 - 1);
                }

                Func<int,int, int> count = (h, w) =>
                {
                    if (h < 0 || w < 0 || h + 3 > H || w + 3 > W) { return -1; }
                    int c = 0;
                    for (int i = 0; i < 3; ++i)
                    {
                        for (int j = 0; j < 3; ++j)
                        {
                            if (dict.ContainsKey(h + i) && dict[h + i].Contains(w + j))
                            {
                                c++;
                            }
                        }
                    }
                    return c;
                };

                var ans = new long[10];
                var check = new Dictionary<int, HashSet<int>>();
                foreach(var ab in AB)
                {
                    var a = ab.Item1 - 1;
                    var b = ab.Item2 - 1;
                    for(int i = 0; i < 3; ++i)
                    {
                        for(int j = 0; j < 3; ++j)
                        {
                            var h = a - 2 + i;
                            var w = b - 2 + j;
                            if(!check.ContainsKey(h) || !check[h].Contains(w))
                            {
                                var c = count(h, w);
                                if (c > 0) { ans[c]++; }
                                if (!check.ContainsKey(h)) { check.Add(h, new HashSet<int>()); }
                                check[h].Add(w);
                            }
                        }
                    }
                }
                ans[0] = (H - 2) * (W - 2) - ans.Sum();
                for(int i = 0; i < 10; ++i)
                {
                    Console.WriteLine(ans[i]);
                }
            }
        }
        class Util
        {

        }

        static class Read
        {
            static Queue<string> queue = new Queue<string>();
            static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } }
            public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); }
            public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); }
            public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); }
            public static int[] IntN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); }
            public static long[] LongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); }
            public static ulong[] ULongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToUInt64(s)).ToArray(); }
            public static string[] StrN() { return Console.ReadLine().Split(' '); }
            public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); }
            public static long[,] LongMatrix(int r, int c)
            {
                var mat = new long[r, c];
                for (int i = 0; i < r; ++i)
                {
                    var x = Read.LongN();
                    for (int j = 0; j < c; ++j)
                    {
                        mat[i, j] = x[j];
                    }
                }
                return mat;
            }
            public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false)
            {
                Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
                for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN(); dict[ab[0]].Add(ab[1]);
                    if (!isDirectional) { dict[ab[1]].Add(ab[0]); }
                }
                return dict;
            }
            public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M)
            {
                Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>();
                for (int i = 0; i <= N; ++i)
                {
                    dict.Add(i, new Dictionary<int, long>());
                }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN();
                    dict[ab[0]].Add(ab[1], ab[2]);
                    dict[ab[1]].Add(ab[0], ab[2]);
                }
                return dict;
            }
        }
    }
}