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: Runtime Error)

using System;
using System.Collections.Generic;
using System.Linq;

namespace SnukesColoring
{
    class Program
    {
        static void Main(string[] args)
        {
            long W, H, N;
            var read = Console.ReadLine();
            var ary = read.Split(' ');
            H = long.Parse(ary[0]);
            W = long.Parse(ary[1]);
            N = long.Parse(ary[2]);

            var blacks = new Tuple<long, long>[N];
            for (long i = 0; i < N; i++)
            {
                read = Console.ReadLine();
                ary = read.Split(' ');
                blacks[i] = new Tuple<long, long>(long.Parse(ary[0]) - 1, long.Parse(ary[1]) - 1);
            }

            var counts = new Dictionary<Tuple<long, long>, int>();
            foreach (var black in blacks)
            {
                for (var y = black.Item1 - 2; y <= black.Item1; y++)
                {
                    if (y < 0 || y + 2 >= H) continue;
                    for (var x = black.Item2 - 2; x <= black.Item2; x++)
                    {
                        if (x < 0 || x + 2 >= W) continue;

                        var pt = new Tuple<long, long>(x, y);
                        if (!counts.ContainsKey(pt))
                        {
                            counts.Add(pt, 0);
                        }
                        counts[pt]++;
                    }
                }
            }

            Console.WriteLine((W - 2) * (H - 2) - counts.Count);
            for (var j = 1; j <= 9; j++)
            {
                Console.WriteLine(counts.Count(a => a.Value == j));
            }

            //Console.ReadKey();
        }
    }
}