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):
s = input()
cal = ["+",""]
ans = 0
if len(s) == 1:
  print(s)
elif len(s) == 2:
  for i in cal:
    ans += eval(s[0]+i+s[1])
  print(ans)
elif len(s) == 3:
  for i in cal:
    for j in cal:
      ans += eval(s[0]+i+s[1]+j+s[2])
  print(ans)
elif len(s) == 4:
  for i in cal:
    for j in cal:
      for k in cal:
        ans += eval(s[0]+i+s[1]+j+s[2]+k+s[3])
  print(ans)
elif len(s) == 5:
  for i in cal:
    for j in cal:
      for k in cal:
        for l in cal:
          ans += eval(s[0]+i+s[1]+j+s[2]+k+s[3]+l+s[4])
  print(ans)
elif len(s) == 6:
  for i in cal:
    for j in cal:
      for k in cal:
        for l in cal:
          for m in cal:
            ans += eval(s[0]+i+s[1]+j+s[2]+k+s[3]+l+s[4]+m+s[5])
  print(ans)
elif len(s) == 7:
  for i in cal:
    for j in cal:
      for k in cal:
        for l in cal:
          for m in cal:
            for n in cal:
              ans += eval(s[0]+i+s[1]+j+s[2]+k+s[3]+l+s[4]+m+s[5]+n+s[6])
  print(ans)
elif len(s) == 8:
  for i in cal:
    for j in cal:
      for k in cal:
        for l in cal:
          for m in cal:
            for n in cal:
              for o in cal:
                ans += eval(s[0]+i+s[1]+j+s[2]+k+s[3]+l+s[4]+m+s[5]+n+s[6]+o+s[7])
  print(ans)
elif len(s) == 9:
  for i in cal:
    for j in cal:
      for k in cal:
        for l in cal:
          for m in cal:
            for n in cal:
              for o in cal:
                for p in cal:
                  ans += eval(s[0]+i+s[1]+j+s[2]+k+s[3]+l+s[4]+m+s[5]+n+s[6]+o+s[7])
  print(ans)
elif len(s) == 10:
  for i in cal:
    for j in cal:
      for k in cal:
        for l in cal:
          for m in cal:
            for n in cal:
              for o in cal:
                for p in cal:
                  for q in cal:
                    ans += eval(s[0]+i+s[1]+j+s[2]+k+s[3]+l+s[4]+m+s[5]+n+s[6]+o+s[7]+p+s[8]+q+s[9])
  print(ans)

Solution (Python):
from itertools import combinations

def insert(s:str, ind:tuple):
    ind = list(ind)
    for i in range(0, len(ind)):
        ind[i] += i
        s = s[:ind[i]] + "+" + s[ind[i]:]
    else:
        return s
        
s = input()
ans = int(s)
for i in range(1, len(s)):
    for comb in combinations(range(1, len(s)), i):
        ans += eval(insert(s, comb))
else:
    print(ans)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    s = list(map(int, input()))
    n = len(s)
    ans = 0
    m = 1<<(n-1)
    for b in range(m):
        a = s[0]
        m = 0
        for i in range(n-1):
            if b&(1<<i):
                a *= 10
                a += s[i+1]
            else:
                m += a
                a = s[i+1]
        ans += a+m
    print(ans)
    return


def B():

    return


def C():

    return


def D():

    return


def E():

    return


def F():

    return


def G():

    return


def H():

    return


def I_():

    return


def J():

    return


if __name__ == "__main__":
    A()

Solution (Python):
from itertools import product
S=input()
s=[]
for i in range(len(S)):
    s.append(int(S[i]))
L=len(S)-1
l=list(product([1,0],repeat=L))
a=0
for i in range(len(l)):
    t=0
    a+=s[-1]
    for j in range(L-1,-1,-1):
        if l[i][j]:
            t+=1
        else:
            t=0
        a+=s[j]*10**t
print(a)

Solution (Python):
S = input()

total_sum = 0

def pros(last_str, cur, remain):
  global total_sum
  if len(remain) == 1:
    total_sum += cur + int(last_str + remain[0])
  else:
    pros(last_str + remain[0], cur, remain[1:])
    pros('', cur + int(last_str + remain[0]), remain[1:])
pros('', 0, S)
print(total_sum)

Solution (Python):
import itertools

S = input()
ans = 0
if len(S) == 1:
    print(int(S))
    exit()
for s in itertools.product(range(2), repeat=len(S)-1):
    t = 0
    for i in range(len(S)-1):
        if s[i] == 1:
            ans += int(''.join(S[t:i+1]))
            t = i+1
        if len(S)-2 == i:
            ans += int(''.join(S[t:]))
print(ans)

Solution (Python):
S = list(input())
n = len(S)
res = 0

for i in range(2 ** (n - 1)):
    sub = []
    for j in range(n - 1):
        if (i >> j) & 1 == 1:
            sub.append('+')
        else:
            sub.append('')            
    f = S[0]
    for k in range(n - 1):
        f += sub[k] + S[k + 1]
    res += eval(f)            

print(res)

Solution (Python):
S = list(input())

def dfs(i, s):
    res = 0
    if i == len(S) - 1:
        f = S[0]
        for j in range(len(s)):
            f += s[j] + S[j + 1]
        return eval(f)

    for o in [['+'], ['']]:
        res += dfs(i + 1, s + o)

    return res

print(dfs(0, []))

Solution (Python):
from itertools import accumulate
S=[int(i) for i in input()]

N=len(S)
sac=[0]+list(accumulate(S))
ans=0

for i in range(N):
  ans+=int(sac[i]*2**(i-1)+2**i*S[i]) * 10**(N-1-i)
print(ans)

Solution (Python):
s=list(input())
n=len(s)
ans=0
for i in range(2**(n-1)):
    f=s[0]
    for j in range(n-1):  
        if i&(1<<j):
            f=f+"+"
            
            
        f=f+s[j+1]
        
    
    ans=ans+sum(map(int,f.split("+")))
  
print(ans)

Solution (Python):
S = list(map(int, input()))
rs = []
for b in range(2**(len(S)-1)):
  r = 0
  c = 0
  for i in range(len(S)-1):
    c = 10*c+S[i]
    if b&(1<<i) != 0:
      r += c
      c = 0
  c = 10*c+S[-1]
  r += c
  rs.append(r)
r = sum(rs)
print(r)

Solution (Python):
S = list(input())

def dfs(i, S):
    if i == len(S):
        
        sum = 0
        num = 0
        for char in S:
            if num == 0 and char != '+':
                num += int(char)
            elif num != 0 and char != '+':
                num = num * 10 + int(char)
            else:
                
                sum += num
                num = 0
        
        sum += num
        return sum
    else:
        
        S.insert(i, '+')
        num1 = dfs(i + 2, S)
        S.pop(i)

        
        num2 = dfs(i + 1, S)

    return num1 + num2

print(dfs(1, S))

Solution (Python):
from itertools import combinations

S = input()
lenS = len(S)
idx_list = [i for i in range(1,lenS)]
ans = 0
for i in range(1, lenS):
  for combination in combinations(idx_list, i):
    prv_idx = 0
    for idx in combination:
      ans += int(S[prv_idx:idx])
      prv_idx = idx
    ans += int(S[idx:])
print(ans+int(S))

Solution (Python):

S=input()
n=len(S)

ans=0

for bit in range(1 << (n-1)):
    f=S[0]

    for i in range(0,n-1):
        if bit & (1 << i):
            f=f+"+"
        f=f+S[i+1]
    
    ans=ans+sum(map(int,f.split("+")))

print(ans)

Solution (Python):
s = list(input())
ans = 0

for i in range(2**(len(s)-1)):
    ss = s.copy()
    for j in range(len(s)-1,-1,-1):
        if (i>>j)&1:
            ss.insert(j+1, "+")
    k = "".join(ss)
    k = map(int, k.split("+"))
    ans += sum(k)
print(ans)

Solution (Python):
S=input()

ans=0
for i in range(2**(len(S)-1)):
    num=[]
    Binary=bin(i)[2:].zfill(len(S)-1)
    for j in range(len(S)):
        s=int(S[j])
        if j==0:
            num.append(s)
        else:
            if Binary[j-1]=="0":
                tmp=num.pop()*10
                num.append(tmp+s)
            else:
                num.append(s)
    ans+=sum(num)

print(ans)

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

def dp(s, i, used, limit):
  if i == N - 1:
    if used == limit:
      return eval(''.join(s))
    else:
      return 0
  if used > limit:
    return 0
  splus = s[:]
  splus[i] += '+'
  ret = dp(splus[:], i + 1, used + 1, limit) + dp(s[:], i + 1, used, limit)
  return ret

ret = 0
for p in range(N):
  ret += dp(S[:], 0, 0, p)

print(ret)

Solution (Python):
S = input()
ans = []


def fn(s, arr):
    ans.append(int(s) + sum(map(int, arr)))
    for i in range(1, len(s)):
        fn(s[i:], arr + [s[:i]])


fn(S, [])
print(sum(ans))

Solution (Python):
s=input()
n=len(s)
def dfs(i,f):
    if i==n-1:
        return sum(list(map(int,f.split("+"))))
    return dfs(i+1,f+s[i+1])+dfs(i+1,f+"+"+s[i+1])
print(dfs(0,s[0]))

Solution (Python):
s=input()
n=len(s)
if n==1:
  print(int(s))
  exit()
if n==2:
  m=int(s)
  print(m+m//10+m%10)
  exit()

t=[int(s[i]) for i in range(n)]
wa=0
for i in range(n-1):
  wa+=(10**i)*(2**(n-2-i))*(sum(t[0:n-i])+t[n-1-i])
wa+=10**(n-1)*t[0]
print(wa)

Solution (Python):
def main():
    S = input()
    memo = dict()

    def helper(S, i):
        
        if i == len(S): return [0, 1]
        if i == len(S)-1: return [int(S[i]), 1]

        if i not in memo:
            memo[i] = [0, 0]
            for j in range(i+1, len(S)+1):
                if j not in memo:
                    memo[j] = helper(S, j)
                memo[i][0] += int(S[i:j])*memo[j][1] + memo[j][0]
                memo[i][1] += memo[j][1]
            
        return memo[i]

    return helper(S, 0)[0]

if __name__ == '__main__':

    print(main())

Solution (Python):

import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    s = input()

    def build(sub):
        if len(sub) == 1:
            return [sub]
        top = sub[0]
        rest = build(sub[1:])

        ret = []
        for r in rest:
            ret.append(top + r)
            ret.append(top + '+' + r)
        return ret

    ans = sum(map(lambda inp: eval(inp), build(s)))
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
S = input()
ans = 0
for num in range(2**((len(S)-1))):
  before = 0
  nums = []
  for i in range(len(S)-1):
    if num>>i&1:
      nums.append(int(S[before:i+1]))
      before = i+1
  nums.append(int(S[before:]))
  ans += sum(nums)
print(ans)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)


S = input()

"""
10こ数字がならんでいるとして、各プラスいれるかいれないかで2**10通りある
つまり1024通りしかない
普通に計算するか、dfs
"""
def dfs(l):
    global ans
    if len(l) == len(S)-1:
        
        s = S[0]
        for idx, is_plus in enumerate(l):
            if is_plus:
                
                ans += int(s)
                s = S[idx+1]
            else:
                s = s + S[idx+1]
        else:
            
            ans += int(s)
    else:
        dfs(l + [True])
        dfs(l + [False])

ans = 0
dfs([])
print(ans)

Solution (Python):
def dfs(i, func):
    if i == len(S) - 1:
        return eval(func)

    ret = 0
    ret += dfs(i + 1, func + S[i + 1])
    ret += dfs(i + 1, func + '+' + S[i + 1])
    return ret


S = input().strip()

print(dfs(0, S[0]))

Solution (Python):
s = input()

n = len(s)

ans = 0
for bit in range(1<<(n-1)):
    sum = 0
    insert = [0]
    for i in range(n-1):
        if bit & (1<<i):
            insert.append(i+1)
    insert.append(n+1)
    for j in range(len(insert)-1):
        sum += int(s[insert[j]:insert[j+1]])
    
    ans += sum

print(ans)

Solution (Python):
import itertools


def main():
    s = input()
    n = len(s)
    a = list(itertools.product(['+', ''], repeat=n - 1))
    ans = 0
    for i in a:
        formula = s[0]
        for index, j in enumerate(i):
            formula += j
            formula += s[index + 1]
        ans += eval(formula)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
S = str(input())
l = list(map(str,(map(bin,range(2**(len(S)-1))))))

ans = 0
for i in range(len(l)):
    ev = l[i][2:].zfill(len(S)-1)
    res = 0
    num_str = S[0]
    for j in range(1,len(S)):
        if(ev[j-1] == '0'):
            num_str = num_str + S[j]
        else:
            res += int(num_str)
            num_str = S[j]
    res += int(num_str)
    ans += res

print(ans)

Solution (Python):
S = input()

ans = 0
if len(S) == 1:
    ans = int(S)
else:
    for i in range(2**(len(S)-1)):
        tmp = S[0]
        for j, b in enumerate(format(i, 'b').zfill(len(S)-1)):
            if b == '1':
                tmp += '+'
            tmp += S[j+1]
        ans += eval(tmp)
print(ans)

Solution (Python):
s = input()

if len(s) == 1:
  print(s)
  exit()

a = 0
di = len(s) - 1
m = 2 ** di
for i in range(m):
  b = format(i, 'b').zfill(di)
  fs = ''
  for c, d in zip(s, b):
    fs += c
    if d == '1':
      fs += '+'
  fs += s[-1]
  a += eval(fs)

print(a)

Solution (Python):
import sys
INPUT = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 9)


def main():
    S = INPUT()
    l = len(S)
    ans = 0

    for i in range(2**(l-1)):
        tmp = S[0]
        for j in range(l-1):
            if (i >> j) & 1: tmp += "+"
            tmp += S[j+1]

        ans += eval(tmp)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    S = SI()

    ans = int(S)
    for 文字数 in range(1, len(S)):
        for 開始位置 in range(len(S)-文字数+1):
            if 開始位置 == 0 or 開始位置+文字数 == len(S):
                ans += int(S[開始位置:開始位置+文字数]) * 2**(len(S) - 1 - 文字数)
            else:
                ans += int(S[開始位置:開始位置+文字数]) * 2**(len(S) - 1 - 文字数 -1)
    print(ans)

main()

Solution (Python):
s = input()
answer = 0

if len(s) == 1:
    print(s)
else:
    for i in range(2**(len(s)-1)):
        f = s[0]
        for j,b in enumerate(str(format(i,'b').zfill(len(s)-1))):
            if b == '1':
               f += ','
            f += s[j+1]
        answer += sum(int(i) for i in f.split(','))
    print(answer)

Solution (Python):
s=list(input())

out=0
for p in range(1,2**(len(s)-1)):
  plus_p=list(str(bin(p))[2:])
  plus_p.reverse()
  plus_p=[i for i,pp in enumerate(plus_p) if pp=='1']
  for j in range(len(plus_p)):
    if j==0:
      out+=int(''.join(s[0:plus_p[j]+1]))
    if j<len(plus_p)-1:
      out+=int(''.join(s[plus_p[j]+1:plus_p[j+1]+1]))
    else:
      out+=int(''.join(s[plus_p[j]+1:]))
print(out+int(''.join(s)))

Solution (Python):
s=input()
ans=0
for i in range(2**(len(s)-1)):
	r=0
	d="0"*10+bin(i)
	for j in range(len(s)-1):
		if d[-j-1]=="1":
			ans+=int(s[r:j+1])
			r=j+1
	ans+=int(s[r:])
print(ans)

Solution (Python):
from itertools import product

S = input()
n = len(S)

op = list(product(['', '+'], repeat=n - 1))

total = 0
for o in op:
    ans = S[0]
    for i in range(n - 1):
        ans += o[i] + S[i + 1]
    total += eval(ans)
print(total)

Solution (Python):
S = input().strip()

answer = 0

for n in range(2**(len(S)-1)):
    A = [0]
    for d in range(9):
        if n & (1 << d):
            A.append(d+1)
    T = []
    
    for l, r in zip(A, A[1:]):
        T.append(int("".join(S[l:r])))
    T.append(int("".join(S[A[-1]:])))
    answer += sum(T)

print(answer)

Solution (Python):
import itertools
a = input()
n = len(a)
s = int(a)
num =[x for x in range(n-1)]
for i in range(1,n):
    position = list(itertools.combinations(num,i))
    for next in position:
        t=''
        for j in range(n):
            t+=a[j]
            if j in next:
                s+=int(t)
                t=''
        s+=int(t)
print(s)

Solution (Python):
S=input()
ans=0
for i in range(2**(len(S)-1)):
    tmp=S[0]
    for j in range(len(S)-1):
        if (i>>j)&1:tmp+="+"
        tmp+=S[j+1]
    ans+=eval(tmp)
print(ans)

Solution (Python):
s = input()
len_s = len(s)
l = []
for i in range(len_s):
  l.append(s[i])
  l.append('')
del l[-1]
i = 0
ans = 0
while i< 2**(len_s-1):
  for j in range(len_s-1):
    l[2*j+1] = ''  if (i//2**j)%2==0 else '+'
  ans += eval(''.join(l))
  i+=1
print(ans)

Solution (Python):
S=input()
ans=0
for i in range(2**(len(S)-1)):
    tmp=S[0]
    for j in range(len(S)-1):
        if (i>>j)&1:tmp+="+"
        tmp+=S[j+1]
    ans+=eval(tmp)
print(ans)

Solution (Python):
s = input()
n = len(s)

ans = 0

for bit in range(1 << (n - 1)):
    
    f = s[0]

    for i in range(n - 1):
        if bit & (1 << i):
            
            f += "+"
        f += s[i + 1]

    ans += sum(map(int, f.split("+")))

print(ans)

Solution (Python):
s = input()
n = len(s)
count = 0
for l in range(0,n):
    for r in range(l,n):
        x = int(s[l:r+1])
        if l >= 2:
            ln = 2**(l-1)
        else:
            ln = 1
        if r <= n-3:
            rn = 2**(n-2-r)
        else:
            rn = 1
        count += rn*ln*x
print(count)

Solution (Python):
import itertools
s = input()
a = ["", "+"]
a = list(itertools.product(a, repeat=len(s) - 1))
total = 0
for i in a:
    ss = ""
    for j in range(len(s)):
        ss += s[j]
        if j < len(i) and i[j] == "+":
            total += int(ss)
            ss = ""
    total += int(ss)
print(total)

Solution (Python):
s = input()
n = len(s)
ans = 0
def suc(time):
  if time == []:
    return 'over'
  else:
    now = n-2
    while now >= 0:
      if time[now] == 0:
        time[now] = 1
        break
      else:
        time[now] = 0
        now -= 1
    if now >= 0:
      return time
    else:
      return 'over'
time = [0 for _ in range(n-1)]
while time != 'over':
  add = 0
  st = 0
  for i in range(n):
    try:
      if time[i] == 1:
        add += int(s[st:i+1])
        st = i+1
    except:
      
      add += int(s[st:])
  ans += add
  time = suc(time)
print(ans)

Solution (Python):

import collections
import itertools
import sys
import time

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

s = input()
n = len(s)
place_pos = n - 1


def eval_expr(expr):
    expr = expr.split("+")
    res = 0
    for s in expr:
        res += int(s)
    return res

res = 0
for h in range(1 << place_pos):
    expr = s[0]
    for i in range(place_pos):
        if h >> i & 1:
            expr = expr + "+"
        expr += s[i + 1]
    res += eval_expr(expr)

print(res)

Solution (Python):
S = input()
ans = 0
for i in range(2**(len(S)-1)):
    tmp = S[0]
    for j in range(len(S)-1):
        if i & (1 << j):
            tmp += "+"
        tmp += S[j+1]
    ans += eval(tmp)
print(ans)

Solution (Python):
s=input()
l=len(s)
def base(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out.rjust(l-1,'0')
ans=0
for i in range(2**(l-1)):
    b=base(i,2)
    p=1
    ans+=int(s[-1])
    for j in range(1,l):
        if b[-j]=="0":
            p*=10
            ans+=int(s[-j-1])*p
        else:
            p=1
            ans+=int(s[-j-1])

print(ans)

Solution (Python):
s = input()
length = len(s)

def insert(s,pos,k):
    return s[:pos+1+k] + '+' + s[pos+1+k:]

ans = 0
for i in range(2**(length-1)):
    ss = s
    bit = format(i,'b')
    bit = bit.rjust(length-1,'0')
    k = 0
    for j in range(len(bit)):
        if bit[j]=='1':
            ss = insert(ss,j,k)
            k += 1
    ans += eval(ss)

print(ans)

Solution (Python):

s = input()
n = len(s)

def dfs(string, depth):
    if depth == n-1:
        return eval(string)
    return dfs(string+s[depth+1], depth+1) + dfs(string+"+"+s[depth+1], depth+1)

print(dfs(s[0], 0))

Solution (Python):
def c_many_formulas(S):
    import itertools
    ans = 0
    for operators in itertools.product(('', '+'), repeat=len(S) - 1):
        operator = list(operators) + ['']  
        formula = ''.join([value + op for value, op in zip(S, operator)])
        ans += eval(formula)
    return ans

S = input()
print(c_many_formulas(S))

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b, h = IR(3)
    print((a+b)*h//2)
    return


def B():
    d = defaultdict(int)
    d["a"] = deque(S())
    d["b"] = deque(S())
    d["c"] = deque(S())
    tern = "a"
    while d[tern]:
        tern =  d[tern].popleft()
    print(str.capitalize(tern))
    return


def C():
    s = S()
    def dfs(tmp, s):
        res = "0"
        t = tmp if s == [] else 0
        for i in range(len(s)):
            res += s[i]
            t += dfs(int(res)+tmp, s[1 + i:])
        return t
    print(dfs(0, s))
    return


def D():
    h, w, n = LI()
    ans = [(h - 2) * (w - 2)] + [0] * 9
    d = defaultdict(int)
    for _ in range(n):
        a, b = LI()
        for mb in range(-1, 2):
            mb += b
            for ma in range(-1, 2):
                if mb == ma == 0:
                    continue
                ma += a
                if 2 <= ma < h and 2 <= mb < w:
                    d[(ma, mb)] += 1
    for _, value in d.items():
        ans[value] += 1
        ans[0] -= 1
    print("\n".join(map(str, ans)))
    return


if __name__ == '__main__':
    C()

Solution (Python):
S = input()

L = [S]

for i in range(len(S)-1):
    L_new = []
    for l in L:
        L_new.append(l[:1+2*i] + '+' + l[1+2*i:])
        L_new.append(l[:1+2*i] + ' ' + l[1+2*i:])
    L = L_new

print(sum([eval(str.replace(l, ' ', '')) for l in L]))

Solution (Python):

def main():
    data = list(map(int, list(input())))
    ans = 0
    for i in range(2 ** (len(data) - 1)):
        bin_data = bin(i)[2:]
        bin_data = bin_data.zfill(len(data) - 1)
        bin_data = list(map(int, list(bin_data)))

        

        kari = 0
        for j in range(len(data) - 1):
            if bin_data[j]:
                ans += kari * 10 + data[j]
                kari = 0
            else:
                kari = kari * 10 + data[j]
        ans += kari * 10 + data[len(data) - 1]

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

import sys
sys.setrecursionlimit(300000)


def solve(S: str):
    eqs = [S[0]]
    for i in range(1, len(S)):
        c = S[i]
        nex = []
        for eq in eqs:
            nex.append(eq + '+' + c)
            nex.append(eq + c)
        eqs = nex
    
    ret = 0
    for eq in eqs:
        nums = eq.split('+')
        for n in nums:
            ret += int(n)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  
    solve(S)

if __name__ == '__main__':
    main()

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

def num(k, s, ans):
    
    if k == N:
        for a in s:
            ans += int(a)
        return ans
    ss = s[:]
    sss = s[:]
    l = ss.pop()
    ss.append(l+S[k])
    sss.append(S[k])
    ans1 = num(k+1, ss, ans)
    ans2 = num(k+1, sss, ans1)
    return ans2

print(num(1, [S[0]], 0))

Solution (Python):


def solve():
    S = input()

    def dfs(depth, s):
        if depth == len(S):
            
            return sum(list(map(int, s.split("+"))))
        
        ret1 = dfs(depth+1, s+"+"+S[depth])
        ret2 = dfs(depth+1, s+S[depth])

        return ret1 + ret2

    ans = dfs(1, S[0])
    print(ans)

if __name__ == "__main__":
    solve()

Solution (Python):
def resolve():
    S = input()
    n = len(S)
    ans = 0
    for i in range(2**(n-1)):
        s = ''
        for j in range(n):
            s += S[j]
            if i & 2**j != 0:
                s += '+'
        ans += eval(s)
    print(ans)

if __name__ == "__main__":
    resolve()

Solution (Python):
s = input()
n = len(s) - 1

op_list = []

for i in range(2**n):
  op = [""] * n
  for j in range(n):
    if (i >> j) & 1:
      op[j] = "+"
  op_list.append(op)

f_list = []

for op in op_list:
  f = s[0]
  for i in range(n):
    f += op[i]
    f += s[i+1]
  f_list.append(f)

ans = 0

for f in f_list:
  ans += eval(f)

print(ans)

Solution (Python):
s=input()
dp=[0]*len(s)
dp[0]=int(s[0])
for i in range(1,len(s)):
    dp[i]=int(s[:i+1])+sum(dp[j-1]+int(s[j:i+1])*2**(j-1) for j in range(1,i+1))
print(dp[-1])

Solution (Python):
from copy import *
from sys import *
import math
import queue
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	s = input()
	ans = 0
	if(len(s)==1): print(int(s));exit()
	for i in range(0,2**(len(s)-1)):
		temp = []
		ix2 = base_10_to_n(i,2)
		for i in range(len(s)-len(ix2)-1):
			ix2 = '0' + ix2
		tmp = s[0]
		for j in range(len(ix2)):
			if(ix2[j]=='1'):
				temp.append(tmp)
				tmp = s[j+1]
			else:
				tmp = tmp + s[j+1]
		temp.append(tmp)
		for i in temp:
			ans+=int(i)
	print(ans)


def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Solution (Python):
ans = 0

s = input()
l = []
for i in s:
  l.append(i)
  l.append('x')
l.pop()

n = len(s)

def solve(k):
  global ans, n, l
  if k >= n+n-2:
    cur = ''
    for i in range(len(l)):
      if i % 2 == 1 and l[i] == '+':
        ans += int(cur)
        cur = ''
      elif i % 2 == 0:
        cur += l[i]
    ans += int(cur)
    return
  
  l[k] = '+'
  solve(k+2)
  l[k] = 'x'
  solve(k+2)

solve(1)

print(ans)

Solution (Python):
s = input()
count = 0
for i in range(len(s)):
    for j in range(i + 1, len(s) + 1):
        count += int(s[i:j]) * (2 ** (max(0, (i - 1)) + max(0, (len(s) - j - 1))))
print(count)

Solution (Python):
S = input()
sum = 0
for i in range(0, 2**(len(S)-1)):
	m = i
	lst = [S[0]]
	for j in range(1, len(S)):
		if m % 2 == 0:
			lst[-1] = lst[-1]+S[j]
		else:
			lst.append(S[j])
		m //= 2
	for j in range(0, len(lst)):
		sum += int(lst[j])
print(sum)

Solution (Python):
import itertools


S = list(input())





index = []
for i in range(len(S)):
    index.append(i)

result = 0
for i in range(1,len(S)):
    list_C =  list(itertools.combinations(index, i))
    
    for one in list_C:
        T = S
        
        sum_list = []
        devide = 0
        for key in range(0,i):
            sum_list.append(''.join(T[devide:one[key]]))
            devide = one[key]
        sum_list.append(''.join(T[devide:]))
        if '' not in sum_list:
            result += sum(list(map(int,sum_list)))
result += int(''.join(S))
print(result)

Solution (Python):
S = input()
max_plus = len(S)-1
s = S[::-1]

num = 2**(max_plus)
sum = 0


f = 0

while(s):
    f+=1
    max = 1
    n = num
    for i in s:
        t = int(i)

        sum += max*t*n
        max = max*10
        n = n//2
    s = s[1:]
    

    if(f==1):
        num = num//2


print(sum)

Solution (Python):
x = input()

sum = 0

for i in range(len(x)):
  
  
  sum += 2**i * int(x[i])*(10**(len(x) - i - 1))
  
  
  
  d = len(x) - i - 1
  for j in range(1,d+1):
    sum += 2**i * 2**(j-1) * int(x[i]) * 10 ** (d-j)
    
print(sum)

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

Solution (Python):
s = list(input())
num = len(s)
ans = 0
for i in range(2**(num-1)):
    ls = [0 for _ in range(num-1)]
    for j in range(num-1):
        if (i>>j)&1:
            ls[j]=1
    ls.insert(0,0)
    j = 1
    for i in range(num):
        if ls[num-1-i]==0:
            ans += int(s[num-i-1])*j
            j *=10
        else:
            ans += int(s[num-i-1])*j
            j =1
print(ans)