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 (Python):
from itertools import combinations

s = raw_input()
l = len(s)

allstrs = [[s]]
for n in range(1, l):
    pluses = combinations(range(1, l), n)
    for plus in pluses:
        strs = [s[:plus[0]]] + [s[plus[i]:plus[i+1]] for i in range(0,
            len(plus)-1)] + [s[plus[-1]:]]
        allstrs.append(strs)

print(sum([sum([int(x) for x in strs]) for strs in allstrs]))

Solution (Python):
dp=["","+"]
s=input()
su=0
for i in range(2**(len(s)-1)):
    val=""
    b=bin(i)[2:].zfill(len(s)-1)
    for j in range(len(s)-1):
        val+=s[j]+dp[int(b[j])]
    val+=s[len(s)-1]
    su+=eval(val)
print(su)

Solution (Python):
import sys
numbers = sys.stdin.readline().rstrip()

l = len(numbers)

total = 0
all_pattern =  pow(2,l-1)

for (i,n) in enumerate(map(int,list(reversed(numbers)))):
   remain_pattern = all_pattern
   p = 0
   for j in xrange(i):
     remain_pattern /= 2
     total += n * (pow(10,p)) * remain_pattern
     
     p += 1
   total += n * pow(10,p) * remain_pattern
   
print total

Solution (Python):


n = input()
s = list(str(n))


d = {}
    
def solve(l):
    if len(l) == 1:
        return int(l[0])
    
        
    sum = int("".join(l))
    for i in xrange(1,len(l)):
        
        
        d[str(l)]= int("".join(l[:i]))*2**(len(l[i:])-1) + solve(l[i:])
        sum += d[str(l)]
    return sum
        
print solve(s)

Solution (Python):
def f(S):
    n = len(S)
    ret = int(S)
    for i in range(1, n):
        x = int(S[:i])
        ret += 2**(n-i-1)*x + f(S[i:])
    return ret

S = input()
print(f(S))

Solution (Python):
import itertools
nums = input()
index = range(1, len(nums))
def resolve(i):
    t = list(nums)
    for j in reversed(i): t.insert(j, "+")
    return eval("".join(t))

print(sum([resolve(i) for i in itertools.chain(*[itertools.combinations(index, x) for x in range(len(index) + 1)])]))

Solution (Python):
def solve(digits, pos, x, y):
    if pos == len(digits):
        return x + y
    a = solve(digits, pos + 1, x + y, digits[pos])
    b = solve(digits, pos + 1, x, 10 * y + digits[pos])
    return a + b

digits = list(map(int, list(raw_input())))
result = solve(digits, 1, 0, digits[0])
print(result)

Solution (Python):
def gen(s):
	if len(s)==1:
		yield s
	else:
		for ss in gen(s[:-1]):
			yield ss + s[-1]
			yield ss + '+' + s[-1]

s = input()
print(sum(map(eval, gen(s))))

Solution (Python):
from itertools import product

S = tuple(input())
N = len(S)
res = 0
for ops in product(["+", ""], repeat=N-1):
    exp = "".join([n + op for n, op in zip(S, ops+("",))]).strip("+")
    res += eval(exp)
print(res)

Solution (Python):


root_s = raw_input()

'''
for length n, there are n-1 places to put the plus sign
'''

total = 0

n = len(root_s)
for mask in xrange(2**(n-1)):
    new_s = ''
    for i, c in enumerate(root_s):
        new_s += c
        if mask & (1 << i):
            new_s += '+'
    
    total += eval(new_s)

print total

Solution (Python):
def get(s):
    length = len(s)
    sum = 0
    for i in range(length):
        sum += int(s[0:i+1])
        sum += get(s[i+1:])
        if len(s[i+1:]) != 0:
            sum += (2**(len(s[i+1:])-1)-1)*int(s[0:i+1])
    return int(sum)

def main():
    string = str(input())
    print(int(get(string)))

main()

Solution (Python):
result = 0
def BT(k, current, s):
    global result
    if k == len(a) :
        if current == 0 :
            result += s
    else :
        BT(k+1, int(a[k]), s+current)
        BT(k+1, current* 10 + int(a[k]), s)

a = input()+'0'
BT(1,int(a[0]),0)
print(result)

Solution (Python):
result = 0
def BT(k, current, s):
    global result
    if k >= len(a)-1 :
        if current == 0 :
            result += s
        
    else :
        BT(k+1, int(a[k+1]), s+current)
        BT(k+1, current* 10 + int(a[k+1]), s)

a = input()+'0'
BT(0,int(a[0]),0)
print(result)

Solution (Python):
S = str(input())
N = len(S)
B = [[0 for k in range(N)] for k in range(N)]

t = 1
for p in range(N):
    for q in range(N):
        if p == q:
            t *= 2
        if p >= q:
            B[q][p] = t//2

ans = 0
for k in range(N):
    for j in range(N):
        ans += int(S[k])*B[k][j]*10**(N-j-1)

print(ans)

Solution (Python):
s = list(input())
ans = 0
for i in range(1<<(len(s)-1)):
    expr = ''.join([s[j]+'+' if ((i>>j)&1) else s[j] for j in range(len(s))])
    ans += eval(expr)
print(ans)

Solution (Python):

def addPlus(s,n):
    total = 0
    ps = [s]
    org = s
    for i in range(1,len(org)):
        ps.append(org[:i] + '+' + org[i:])

    for i in range(1,n):
        curr = ps[:]
        for itm in curr:
            for j in range(1,len(itm)):
                pros = itm[:j] + '+' + itm[j:]
                if pros not in ps:
                    if '++' not in pros:
                        ps.append(pros)
    
    for itm in ps:
        total += eval(itm)

    print(total)

if __name__ == '__main__':
    s = input()
    addPlus(s,len(s) - 1)

Solution (Python):
dp = {}
def rec(s):
    if s in dp:
        return dp[s]
    ret = int(s)
    for i in range(1,len(s)):
        ret += int(s[:i] )* (2**(len(s) - i - 1)) + rec(s[i:])
    dp[s] = ret
    return ret
print(rec(input()))

Solution (Python):
from sys import stdin
a = stdin.readline().strip()
ans = 0
n = len(a)
plus = n-1
b = [a[0]]
for i in xrange(1,n):
    b.append('')
    b.append(a[i])
    
total = 1<<plus

for i in xrange(total):
    x = ''
    c = list(b)
    
    for j in xrange(n-1):
        if i & (1<<j):
            c[2*j+1] = '+'
    
    
    ans += eval(''.join(c))
print ans

Solution (Python):
S = str(input())
N = len(S) - 1

res = 0

for i in range(1<<N):
    t = ''
    for j in range(N):
        t += S[j]
        if((i>>j&1) > 0): t += '+'
    t += S[-1]
    res += eval(t)
print(res)

Solution (Python):
s = map(int, raw_input())

def dfs(c, nums):
    if c==len(s):
        return sum(nums)
    res = 0
    res += dfs(c+1, nums + [s[c]])
    if c:
        nums2 = nums[:]
        nums2[-1] = nums2[-1]*10 + s[c]
        res += dfs(c+1, nums2)
    return res

print dfs(0, [])

Solution (Python):
n = raw_input()


def weight(i, j):
    l = len(n)
    return 2 ** (max(i-1, 0) + max(l-j-2, 0))

s = 0
for i in range(len(n)):
    for j in range(i, len(n)):
        num = int(n[i:j+1])
        s += int(num) * weight(i, j)

print s

Solution (Python):
import sys
perm = sys.stdin.readline().strip()
total = 0


def addPlus(inp, n):
    total = 0
    possible = [inp]
    orig = inp

    for i in range(1, len(orig)):
        possible.append(orig[:i] + '+' + perm[i:])

    for i in range(1, n):
        curr = possible[:]
        for item in curr:
            for j in range(1, len(item)):
                processed = item[:j] + '+' + item[j:]
                if processed not in possible:
                    if '++' not in processed:
                        possible.append(processed)

    for item in possible:
        total += eval(item)

    return total


print(addPlus(perm, len(perm) - 1))

Solution (Python):
dp = {}

def rec(s):
    if s in dp:
        return dp[s]
    ret = int(s)
    for i in range(1, len(s)):
        ret += int(s[:i]) * (2**(len(s)-i-1)) + rec(s[i:])
    dp[s] = ret
    return ret

print(rec(input()))

Solution (Python):
S = str(raw_input())

n = len(S)
table = []

SS = []
for s in S:
    SS.append(int(s))

for i in range(n):
    x = [0] * n
    for j in range(i):
        x[j] = 2 ** (i-1)
    x[i] = 2 ** i
    table.append(x)

ret = 0
for i in range(n):
    p = n - 1 - i
    for j in range(i+1):
        if table[i][j] > 0:
            ret += SS[j] * (10**p) * table[i][j]

print ret

Solution (Python):
import itertools,math,bisect,pprint,sys
s = raw_input()
n = len(s)
ans = []
for i in range(n):
    for j in list(itertools.combinations(range(n-1),i)):
        S = s
        a = 0
        for k in reversed(j):
            a += int(S[k+1:])
            S = S[:k+1]
        else:
            a += int(S)
        ans.append(a)
print sum(ans)

Solution (Python):
import sys

s = sys.stdin.readline().strip()
def mypowerof2(exp):
        ret = 1
        for i in range(exp):
                ret *= 2
        return ret
def mypowerof10(exp):
        ret = 1
        for i in range(exp):
                ret *= 10
        return ret
res = 0
for i in reversed(xrange(len(s))):
        for j in xrange(len(s)-i):
                base = int(s[i]) * mypowerof10(j)
                rate = mypowerof2(i) * mypowerof2((len(s)-1) - i - j - 1)
                res += base * rate



print res

Solution (Python):
S = input()
keta = len(S)

exp_sum = 0
for i in range(1 << keta-1):
    newS = S
    offset = 1
    for j in range(keta):
        if i & (1 << j):
            newS = newS[:j+offset] + "+" + newS[j+offset:]
            offset += 1
    exp_sum += eval(newS)

print(exp_sum)

Solution (Python):
def calc(s, f):
    n = len(s)
    li = []
    t = ""
    for i in range(n):
        t += s[i]
        if f & 1:
            li.append(t)
            t = ""
        f >>= 1
    if t:
        li.append(t)
    return sum(map(int, li))


s = input()
ans = 0
for i in range(1 << (len(s) - 1)):
    ans += calc(s, i)
print(ans)

Solution (Python):
def dfs(arr, accm=0):
	if len(arr) == 1:
		return arr[0]

	s1 = arr[0] * (2 ** (len(arr) - 2)) + dfs(arr[1:])

	_arr = list(arr[1:])
	_arr[0] += arr[0] * 10
	s2 = dfs(_arr)

	return s1 + s2

s = input()
arr = [int(a) for a in s]

print(dfs(arr))

Solution (Python):
def ans(s):
	if len(s) == 1:
		return int(s)
	else:
		length = len(s)
		res = int(s)
		for i in range(1, length):
			x = 1 << (length - i - 1)
			res += int(s[0: i]) * x + ans(s[i:len(s)])
		return res

s = input()
print(ans(s))

Solution (Python):
s = raw_input()

def solve(add, s):
	if s ==  "":
		return 0
	else:
		res = add + int(s)
		for i in range(1, len(s)):
			res += solve(add + int(s[:i]), s[i:])
		return res

print solve(0, s)

Solution (Python):
s = input()
ans = 0
l = len(s)-1
for i in range(2**(len(s)-1)):
    bs = ("{0:0>"+str(l)+"b}").format(i)
    s1 = 0
    temp = s[:]
    j = 0
    for b in bs:
        j+=1
        if b == '1':
            s1 += int(temp[:j])
            temp = temp[j:]
            j = 0
    s1 += int(temp)
    ans += s1
print(ans)

Solution (Python):
import sys
def line():return sys.stdin.readline().strip()

S = line()
L = list(S)
ans = 0
for i in range(1 << (len(S) - 1)):
    A = ""    
    for j in range(len(S)):
        A+=L[j]
        if i & (1 << j):
            A+="+"
    ans+=eval(A)
print(ans)

Solution (Python):
S = input()
N = len(S)


def convert(s):
    lst = []
    for i in range(N):
        if (s >> i) & 1 == 1:
            lst.append(i)
    return lst


def calc(lst):
    if len(lst) == 0:
        return int(S)
    elif len(lst) == 1:
        return int(S[:lst[0] + 1]) + int(S[lst[0] + 1:])
    else:
        tmp = [S[:lst[0] + 1]]
        for i in range(len(lst) - 1):
            tmp.append(S[lst[i] + 1:lst[i+1] + 1])
        tmp.append(S[lst[-1] + 1:])
        ans = 0
        for t in tmp:
            ans += int(t)
        return ans

ans = 0
for i in range(1 << (N - 1)):
    lst = convert(i)
    ans += calc(lst)
print(ans)

Solution (Python):
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')


def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def ilist():
    return map(int,list(raw_input()))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())


def join(s):
    return ''.join(s)


def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)


def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m


def index(a, x):
    
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1


def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

@memoize
def nck(a,b,m):
    b = min([a-b,b])
    if (b>a or b<0 or a<0):
        return 0
    elif a == 0:
        return 1
    return (nck(a-1,b-1,m)+nck(a-1,b,m)) % m

nh=zip([1,0,-1,0],[0,1,0,-1])



sl=ilist()
n=len(sl)
sm=0
for j in range(n+1):
    for k in range(j+1,n+1):
        p=int(join(map(str,sl[j:k])))
        if j==0 and k==n:
            sm+=p
        elif j!=0 and k==n:
            sm+=p*(2**(j-1))
        elif j==0 and k!=n:
            sm+=p*(2**(n-k-1))
        else:
            sm+=p*(2**(j+n-k-2))

print sm

Solution (Python):
from itertools import permutations as perm
S = raw_input()
n = len(S)
dp = [[] for i in xrange(n)]
dp[0].append(int(S[0]))
for i in xrange(1,n):
	dp[i].append(int(S[:i+1]))
	for j in xrange(i):
		for k in dp[j]:
			dp[i].append(k+int(S[j+1:i+1]))
print sum(dp[n-1])

Solution (Python):
s=raw_input()
n=len(s)
ans=0
for i in xrange(1<<n-1):
    new=[]
    for j in xrange(n-1):
        if i>>j&1:
            new.append(j)
    news=""
    for j in xrange(n):
        if j in new:
            news+=s[j]+"+"
        else:
            news+=s[j]
    tmp=""
    for j in news:
        if j=="+":
            ans+=int(tmp)
            tmp=""
        else:
            tmp+=j
    if tmp!="":
        ans+=int(tmp)
print(ans)

Solution (Python):








s = input()
l = len(s)

if l == 1:
	print(int(s))
else:
	ans = 0

	m = int('1'*(l-1), 2)
	for i in range(m+1):
		now = format(i, 'b').zfill(l-1)
		tmp = s[0]
		for k in range(l-1):
			if now[k] == '0':
				tmp += s[k+1]
			else:
				ans += int(tmp)
				tmp = s[k+1]
		ans += int(tmp)
	print(ans)

Solution (Python):



import itertools

S = input()
signs = [['+',''] for _ in range(len(S)-1)]

ans = 0
for comb in itertools.product(*signs):
    expr = ''
    for i in range(len(S)-1):
        expr += (S[i] + comb[i])
    expr += S[-1]
    ans += eval(expr)
print(ans)

Solution (Python):

s = input()

n = len(s) - 1
ans = 0
for mask in range(0, 1 << n):
    num = int(s[0])
    cur = 0
    for i in range(0, n):
        if mask & (1 << i):
            cur += num
            num = 0
        num = num * 10 + int(s[i + 1])
    cur += num
    ans += cur

print(ans)

Solution (Python):
s = input()
n = len(s)-1
ans = 0
for i in range(1<<n):
    k = 0
    for j in range(n):
        if 1&(i>>j):
            ans += int(s[k:(j+1)])
            k = j+1
    ans += int(s[k:])
print(ans)

Solution (Python):
s = input()
len_s = len(s)
n = 2**(len_s-1)
total = 0
for i in range(n):
    buf = s[0]
    for j in range(len_s-1):
        if i & (2**j):
            total += int(buf)
            buf = s[j+1]
        else:
            buf += s[j+1]
    total += int(buf)
print(total)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**9


def f():
    s = input()
    l = len(s)
    sa = [c for c in s]
    m = 2**(l-1)
    r = 0
    for i in range(m):
        si = sa[0]
        for j in range(l-1):
            t = 2**j
            if i & t:
                si += '+'
            si += sa[j+1]
        r += eval(si)
    return r

print(f())

Solution (Python):



def rl(s): return xrange(len(s))


INF = 2147483647


import sys
stdin = sys.stdin

T =   stdin.readline().strip() 

N = len(T)
ts = ['' for _ in range(2*N)]
for i in range(N):
    ts[2*i] = T[i]

rr = 0
for i in range(1 << (N-1)):
    here = ts[:]
    for k in range(N):
        if i & (1 << k):
            here[2*k+1] = '+'

    rr += eval(''.join(here))

print rr

Solution (Python):
S = list(input())
ans = 0
for state in range(1 << (len(S)-1)):
    ans += eval(S[0] + ''.join(('+' if (state >> i & 1) else '')+x for i, x in enumerate(S[1:])))
print(ans)

Solution (Python):
import itertools
S = raw_input()
ans = 0
for p in itertools.product([True, False], repeat=len(S)-1):
  t = ''
  for i in xrange(len(S)):
    t += S[i]
    if i != len(S)-1 and p[i]:
      t += '+'
  ans += eval(t)

print ans

Solution (Python):
s = raw_input()
n = len(s)
ans = 0
for msk in range(0, (1 << (n - 1))):
    t = ''
    for i in range(n):
        t += s[i]
        if ((msk >> i) & 1) == 1:
            t += '+'
    ans += eval(t)
print ans