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(){
		
		Dictionary<Pair, List<Pair2>> E = new Dictionary<Pair, List<Pair2>>();
		int Ext = (int) 1e7;
		
	
		for(int i=0;i<M;i++){
			var p0 = new Pair(P[i],C[i]);
			var q0 = new Pair(Q[i],C[i]);
			var p1 = new Pair(P[i],Ext);
			var q1 = new Pair(Q[i],Ext);
			if(!E.ContainsKey(p0)) E.Add(p0, new List<Pair2>());
			if(!E.ContainsKey(q0)) E.Add(q0, new List<Pair2>());
			if(!E.ContainsKey(p1)) E.Add(p1, new List<Pair2>());
			if(!E.ContainsKey(q1)) E.Add(q1, new List<Pair2>());
			E[p0].Add(new Pair2(q0, 0));
			E[q0].Add(new Pair2(p0, 0));
			E[p0].Add(new Pair2(p1, 1));// 外に出るときだけコスト1
			E[q0].Add(new Pair2(q1, 1));
			E[p1].Add(new Pair2(p0, 0));
			E[q1].Add(new Pair2(q0, 0));
		}
		
		long Inf = (long) 1e9;
		Dictionary<Pair, long> Min = new Dictionary<Pair, long>();
		var SH = new SkewHeap<Pair2>();
		var pstart = new Pair(0,Ext);
		Min.Add(pstart, 0);
		SH.Push(new Pair2(pstart, 0));
		
		HashSet<Pair> done = new HashSet<Pair>();
		
		while(SH.Count > 0){
			var now = SH.Top; SH.Pop();
			var p = now.Pos;
			var c = now.Cost;
			if(done.Contains(p)) continue;
			done.Add(p);
			Min[p] = c;
			if(!E.ContainsKey(p)) continue;
			foreach(var nxt in E[p]){
				var np = nxt.Pos;
				var nc = nxt.Cost;
				if(!Min.ContainsKey(np)) Min.Add(np, Inf);
				if(Min[np] <= c + nc) continue;
				Min[np] = c + nc;
				SH.Push(new Pair2(np, c + nc));
			}
		}
		
		var pend = new Pair(N-1, Ext);
		Console.WriteLine(Min.ContainsKey(pend) ? Min[pend] : -1);
		
		
		
	}
	int N,M;
	int[] P,Q,C;
	
	struct Pair{
		int P;
		int C;
		public Pair(int p, int c){
			P = p; C = c;
		}
	}
	
	class Pair2 : IComparable<Pair2> {
		public Pair Pos;
		public long Cost;
		public Pair2(Pair p, long c) {
			Pos = p; Cost = c;
		}
		public int CompareTo(Pair2 t) {
			//return this.Cost > t.Cost ? -1 : this.Cost < t.Cost ? 1 : 0;
			return this.Cost > t.Cost ? 1 : this.Cost < t.Cost ? -1 : 0;
		}
	}
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1];
		P = new int[M];
		Q = new int[M];
		C = new int[M];
		for(int i=0;i<M;i++){
			d = ria();
			P[i] = d[0] - 1; Q[i] = d[1] - 1; C[i] = d[2];
		}
	}

	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));}
}




class SkewHeap<T> where T:IComparable<T>{
	public int Count{
		get{return cnt;}
		private set{cnt=value;}
	}
	
	public SkewHeap(){
		root=null;
		this.Count=0;
	}
	
	public void Push(T v){
		NodeSH<T> p=new NodeSH<T>(v);
		root=NodeSH<T>.Meld(root,p);
		this.Count++;
	}
	
	public void Pop(){
		if(root==null)return;
		root=NodeSH<T>.Meld(root.L,root.R);
		this.Count--;
	}
	
	public T Top{
		get{return root.Val;}
	}
	
	int cnt;
	NodeSH<T> root;
	
	class NodeSH<S> where S : IComparable<S> {
		public NodeSH<S> L, R;
		public S Val;

		public NodeSH(S v){
			Val = v;
			L = null; R = null;
		}
		public static NodeSH<S> Meld(NodeSH<S> a, NodeSH<S> b){
			if(a == null)return b;
			if (b == null) return a;
			if (a.Val.CompareTo(b.Val) > 0) swap(ref a, ref b);
			a.R = Meld(a.R, b);
			swap(ref a.L, ref a.R);
			return a;
		}

		static void swap<U>(ref U x, ref U y) {
			U t = x; x = y; y = t;
		}
	}
}