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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		
		int[] sum = new int[10];
		HashSet<long> Hs = new HashSet<long>();
		
		for(int i=0;i<N;i++){
			
			for(int rc=-2;rc<=0;rc++){
				if(!InRange(rc+A[i],1,H))continue;
				if(!InRange(rc+A[i]+2,1,H))continue;
				for(int cc=-2;cc<=0;cc++){
					if(!InRange(cc+B[i],1,W))continue;
					if(!InRange(cc+B[i]+2,1,W))continue;
					
					int br = A[i] + rc;
					int bc = B[i] + cc;
					int cnt = 1;
					for(int ii=0;ii<3;ii++){
						for(int jj=0;jj<3;jj++){
							if(Hs.Contains(enc(br+ii,bc+jj)))cnt++;
						}
					}
					sum[cnt]++;
					sum[cnt-1]--;
				}
			}
			Hs.Add(enc(A[i],B[i]));
		}
		
		long[] ans = new long[10];
		for(int i=0;i<10;i++)ans[i] = sum[i];
		ans[0] += ((long)H-2)*((long)W-2);
		
		for(int i=0;i<10;i++){
			Console.WriteLine(ans[i]);
		}
		
	}
	int H;
	int W;
	int N;
	int[] A,B;
	
	bool InRange(int n,int l,int u){
		return l <= n && n <= u ;
	}
	
	long enc(int r,int c){ return ((long)r<<32)+(long)c ;}
	int decR(long s){ return (int)(s>>32);}
	int decC(long s){ return (int)(s&0xFFFFFFFF);}
	
	public Sol(){
		var d = ria();
		H = d[0]; W = d[1]; N = d[2];
		A = new int[N];
		B = new int[N];
		for(int i=0;i<N;i++){
			var dd = ria();
			A[i] = dd[0];
			B[i] = dd[1];
		}
	}
	
	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}