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):
import sys
from collections import deque

def main():
    input = sys.stdin.readline
    S = [s for s in input().strip()]
    q = deque()

    s = S.pop(0)
    q.append(s)
    while len(S) > 0:
        s = S.pop(0)
        q_ = deque()
        while len(q) > 0:
            a = q.popleft()
            q_.append(a + s)
            q_.append(a + '+' + s)

        q = q_

    ans = 0
    for a in q:
        ans += sum([int(i) for i in a.split('+')])

    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):
S = input()
ans = 0

for bit in range(1 << (len(S) - 1)):
    left = 0
    sum_list = []
    for i in range(0, len(S) + 1):
        if (bit >> i) & 1:
            sum_list.append(int(S[left : i + 1]))
            left = i + 1
        elif i == len(S):
            sum_list.append(int(S[left:i]))
    ans += sum(sum_list)
print(ans)

Solution (Python):
S = int(input())
def ans(L):
    if len(list(str(L))) == 1:
        return(int(L))
    elif len(list(str(L))) == 2:
        LI = list(str(L))
        return(int(LI[0])+int(LI[1])+int(L))
    else:
        LI = list(str(L))
        SUM = 0
        for i in range(len(list(str(L)))):
            if i != len(list(str(L)))-1:
                LISTA = LI[0:i+1]
                LISTB = LI[i+1:len(list(str(L)))] 
                SUM += (2**(len(LISTB)-1))*int("".join(LISTA)) + ans(int("".join(LISTB)))
            else:
                SUM += L
        return(SUM)
    
print(ans(S))

Solution (Python):
s=input()
s2 = ''.join([c + ' ' for c in s])
res = 0
for i in range(2**(len(s)-1)):
  t = list(s2)
  for j in range(len(s)-1):
    if (i >> j) & 1:
      t[2*j+1] = '+'
  res += eval(''.join([c for c in t if c!=' ']))
print(res)

Solution (Python):
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

s = ns()
ans = 0
for i in range(2 ** (len(s) - 1)):
    lis = list(bin(i)[2:].zfill(len(s) - 1))
    b = 0
    for j in range(len(lis)):
        if lis[j] == '1':
            ans += int(s[b:j + 1])
            b = j + 1
    ans += int(s[b:])
print(ans)

Solution (Python):


def dfs(lst, char_n, i, tmp_sum):
    if i == len(lst):
        return tmp_sum + int(char_n)
    return dfs(lst, lst[i], i + 1, int(char_n) + tmp_sum) + dfs(lst, char_n + lst[i], i + 1, tmp_sum)


lst = [x for x in input()]
print(dfs(lst, lst[0], 1, 0))

Solution (Python):


def dfs(lst_args, n_each_digit, i_num, n_calc):
    if i_num == len(lst_args):
        return n_calc + int(n_each_digit)
    return dfs(lst_args, lst_args[i_num], i_num + 1, int(n_each_digit) + n_calc) + dfs(lst_args, n_each_digit + lst_args[i_num], i_num + 1, n_calc)

lst = [x for x in input()]
print(dfs(lst, lst[0], 1, 0))

Solution (Python):


def dfs(lst_args, n_each_digit, i_num, n_calc):
    if i_num == len(lst_args):
        return n_calc + int(n_each_digit)
    return dfs(lst_args, lst_args[i_num], i_num + 1, int(n_each_digit) + n_calc) + dfs(lst_args, n_each_digit + lst_args[i_num], i_num + 1, n_calc)

lst = [x for x in input()]
print(dfs(lst, lst[0], 1, 0))

Solution (Python):
import itertools
A = list(input())
n = len(A)

if(n == 1):
  ans = A[0]

elif(n == 2):
  ans = int(A[0])+int(A[1])+int(A[0]+A[1])
  
else:
 Comb =  []
 for i in range(n-1):
  Comb.append(['','+'])
 Comb = list(itertools.product(*Comb))
 
 ans = 0
 for i in range(len(Comb)):
  tmp = list(Comb[i])
  tmp_list,tmp_str = [],A[0]
  for j in range(n):
   if(j != n-1):
    if(tmp[j] == ''): 
      tmp_str += A[j+1]
    elif(tmp[j] == '+'): 
      tmp_list.append(tmp_str)
      tmp_str = A[j+1]
   elif((j == n-1)and(j >= 2)):
      tmp_list.append(tmp_str) 
  tmp_list = list(map(int,tmp_list))
  ans += sum(tmp_list)
  
print(ans)

Solution (Python):
def solve():
  s = input()
  n = len(s)-1
  ans = 0
  for i in range(2**n):
    nsum = 0
    for j in range(n):
      if 1&(i>>j) == 1:
        ans += int(s[nsum:j+1])
        nsum = j+1
    ans += int(s[nsum:])
  print(ans)
solve()

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

oper = ['+','']

num = 0

oper_set = list(itertools.product(oper,repeat=N-1))

for i in range(len(oper_set)):
  x = ''
  for j in range(N-1):
    x += S[j] + oper_set[i][j]
  x += S[N-1]
  num += eval(x)


print(num)

Solution (Python):
def dfs(nums: list) -> int:
    if len(nums) == 1:
        return nums[0]

    
    n1 = nums[0] * (1 << (len(nums) - 2)) + dfs(nums[1:])

    
    headless = nums[1:]
    headless[0] += nums[0] * 10
    n2 = dfs(headless)

    return n1 + n2


def many_formulas(s: str) -> int:
    nums = list(map(int, s))
    return dfs(nums)


if __name__ == "__main__":
    s = input()
    ans = many_formulas(s)
    print(ans)

Solution (Python):
S = [int(x) for x in input()][::-1]
n = len(S) - 1
ans = S[0] * 2 ** n
for i in range(2 ** n):
    t = 1
    for j in range(n):
        if i >> j & 1:
            t = 1
        else:
            t *= 10
        ans += S[j + 1] * t
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
s = ""
S = input()
l = len(S)
S = list(S.zfill(10))
sum = 0
for i in range(2**(l-1)):
	i = list(str(format(i, "08b").zfill(9)))
	s = S[0]
	for j in range(len(i)):
		
		
		if i[j] == '1' and s != "": 
			sum += int(s)
			s = S[j+1]
		else:
			s += S[j+1]
		
	sum += int(s)
	
print(sum)

Solution (Python):
S = input()

def dfs(s):
    if len(s) == len(S) - 1:
        index = 0
        sum_v = 0
        for i, bl in enumerate(s):
            if bl == "1":
                sum_v += int(S[index:i + 1])
                index = i + 1
        sum_v += int(S[index:])
        return sum_v
    else:
        return dfs(s + "0") + dfs(s + "1")

print(dfs(""))

Solution (Python):
n=input()
ans=0
def dfs(i,flag):
  global ans
  if i!=len(n)-1:
    dfs(i+1,flag)
    dfs(i+1,flag|2**i)
  else:
    num=[]
    start=0
    for i in range(len(n)):
      if flag&2**i>0:
        num.append(int(n[start:i+1]))
        start=i+1
    if start!=n:
      num.append(int(n[start:]))
    ans+=sum(num)
dfs(0,0)
print(ans)

Solution (Python):
from functools import reduce

def main():
    
    

    
    
    
    
    
    
    
    

    
    s = list(input().rstrip())
    
    
    sum = 0
    for i in range(1 << len(s)-1):
        e = s[0]
        for j in range(len(s)-1):
            
            if(i & (1 << j)):
                e = e + '+' + s[j+1]
            else:
                e = e + s[j+1]
        sum += eval(e)
        
    print(sum)
if __name__ == '__main__':
    main()

Solution (Python):

s = list(input())

cand = []


n = len(s) - 1
arr = [0] * n
for i in range(2 ** n):
    diff = 0
    for j in range(n):
        if((1&i>>j) == 1):
            arr[j] = 1
        else:
            arr[j] = 0
    
    s_copy = s[:]
    diff = 0
    for j in range(len(arr)):
        if arr[j] == 1:
            s_copy = s_copy[:(j+diff+1)] + ["+"] + s_copy[(j+diff+1):]
            diff += 1
    cand.append(s_copy)

cand_sum = []

for i in range(len(cand)):
    t = "".join(cand[i])
    tt = []
    tt = t.split("+")
    tt = list(map(int,tt))
    cand_sum.append(sum(tt))

print(sum(cand_sum))

Solution (Python):
s = str(input())
ans = 0
for i in range(1 << (len(s)-1)):
    si = s[0]
    for j in range(len(s)-1):
        if i & (1 << j):
            si += "+"+s[j+1]
        else:
            si += s[j+1]
    ans += eval(si)
print(ans)

Solution (Python):
import itertools
s=input()
C=['+','']
X=list(itertools.product(C,repeat=len(s)-1))
ans=0
for i in range(len(X)):
    res=''
    for j in range(len(s)-1):
        res+=s[j]+X[i][j]
    res+=s[len(s)-1]
    ans+=eval(res)

print(ans)

Solution (Python):
s=input();ans=0
def m(b):
  global s
  ans=""
  for i in range(len(s)-1):ans+=s[i]+("+"if b[i]=="1"else"")
  return eval(ans+s[-1])
for i in range(2**(len(s)-1)):ans+=m(bin(i)[2:].zfill(len(s)-1))
print(ans)

Solution (Python):
from itertools import product

S=input()
n=len(S) 

answer=0
for _l in product([0,1], repeat=n-1): 
  
  __l = [0] + list(filter(lambda x:_l[x-1], range(1,n))) + [n] 
  
  answer += sum([int(S[__l[i]:__l[i+1]]) for i in range(len(__l)-1)])
  
print(answer)

Solution (Python):
S = input()
n = len(S)
if n == 1:
    print(S)
    quit()
import itertools as it
def sum_insert(x,S): 
    z = zip(S,x)
    L = []
    for x in z:
        L.append(x[0])
        if x[1] == '1':
            L.append('+')
    L.append(S[-1])
    s = ''.join(L)
    return eval(s)
ans = 0
variation = []
for i in range (2**(n-1)):
    variation.append(format(i,'b').zfill(n-1))

for x in variation:
    ans += sum_insert(x,S)
print(ans)

Solution (Python):
s = input()

res = int(s)
for i in range(1,len(s)):
    l = len(s)-i
    for j in range(len(s)-l+1):
        x = i-1
        if j>0 and j<len(s)-l:
            x -=1
        res+=int(s[j:j+l])*(2**x)

print(res)

Solution (Python):
""" AtCoder """

S = input()

l = ['+', '']

n = 2** (len(S) - 1)
ans = 0

for i in range(n):
    tmp = ''
    for j in range(len(S) - 1):
        tmp += S[j] + l[(i >> j) & 1]
    tmp += S[-1]
    ans += eval(tmp)

print(ans)

Solution (Python):
S = input()
ans = 0
for i in range(2 ** (len(S)-1)):
    bit = format(i, "b").zfill(len(S))[::-1]
    k = ""
    for j, s in enumerate(S):
        k += s
        if bit[j] == "1":
            k += "+"
    ans += eval(k)
print(ans)

Solution (Python):
S = input()

all_sum = 0
for n in range(1<<len(S)-1):
	t = ""
	for i, s in enumerate(S):
		t += s
		if n&1<<i!=0:
			t += "+"
	all_sum += eval(t)
print(all_sum)

Solution (Python):
s = list(map(int,list(input())))

if len(s) == 1:
    print(s[0])
    exit()

from collections import deque

cands=deque([[0],[1]])

while len(cands[0]) != len(s)-1:
    newcands = []
    for cand in cands:
        newcands.append(cand+[0])
        newcands.append(cand+[1])
    cands = newcands

memo = []
while cands:
    pos = cands.pop()
    siki = ''
    for i, p in enumerate(pos):
        siki += str(s[i])
        if p == 1:
            siki += '+'
    siki += str(s[-1])
    memo.append(eval(siki))

print(sum(memo))

Solution (Python):
def f(s):
  if len(s) > 1:
    cnt = 1
    ans = int(s)
    for i in range(1,len(s)):
      a, c = f(s[i:])
      ans += int(s[:i]) * c + a
      cnt += c
    return ans, cnt
  else:
    return int(s), 1
  
print(f(input())[0])

Solution (Python):
import itertools


def main():
    S = input()
    ans = 0
    for p in itertools.product(("", "+"), repeat=len(S)-1):
        p = list(p) + ['']
        fig = "".join([a+b for a, b in zip(S, p)])
        ans += eval(fig)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
S = list(input())
N = len(S)
ans = 0
for pt in range((1 << (N-1))):
    
    tmpS = S.copy()
    
    inscnt = 1
    for i in range(N-1):
        if (1 << i) & pt:
            tmpS.insert(i+inscnt,'+')
            inscnt+=1
    
    tmpsum=eval("".join(tmpS))
    
    ans+=tmpsum
    
print(ans)

Solution (Python):
def main():
    S = input()
    n = len(S)-1

    val_sum = 0
    for i in range(2**n):
        idx = 0
        for j in range(n):
            if 1 & (i >> j) == 1:
                val_sum += int(S[idx:j+1])
                idx = j+1
        val_sum += int(S[idx:])

    print(val_sum)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    S = input()
    n = len(S)-1

    val_sum = 0
    for i in range(2**n):
        idx = 0
        for j in range(n):
            if 1 & (i >> j) == 1:
                val_sum += int(S[idx:j+1])
                idx = j+1
        val_sum += int(S[idx:])

    print(val_sum)


if __name__ == "__main__":
    main()

Solution (Python):
S=list(input())
S=[int(i) for i in S]
n=len(S)
ans=0
if n!=1:
    for k in range(1,n+1):
        for j in range(n-k):
            ans+=S[k-1]*(10**j)*(2**(n-2-j))
        ans+=S[k-1]*(10**(n-k))*(2**(k-1))
    print(int(ans))
else:print(S[0])

Solution (Python):


















import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product 
from bisect import bisect_left, bisect_right

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))

S = input()

def dfs(s):
    if len(s) == 1:
        return [s]
    def add(l, r):
        return [l+ri for ri in r]
    return add(s[0], dfs(s[1:])) + add(s[0] + "+", dfs(s[1:]))

print(sum(map(eval,dfs(S))))

Solution (Python):
n = list(map(int, input()))


ans = 0
ind = len(n) - 1

for i in range(len(n)):
    ans += (10**i * (n[-1] * 2**ind  + sum(n[:-1]) * 2**(ind - 1)))
    n = n[:-1]
    ind = len(n) - 1
print(int(ans))

Solution (Python):
s = list(map(int, list(input())))

if len(s) == 1:
    print(s[0])
    exit()

m = len(s) - 1

n = 2 ** m

ans = 0
for i in range(n):
    d = list(map(int, list(str(bin(i)))[2:]))
    if len(d) < m:
        d = [0] * (m - len(d)) + d

    temp = s[0]
    for j in range(m):
        if d[j] == 0:
            ans += temp
            temp = s[j+1]
        else:
            temp *= 10
            temp += s[j+1]
    ans += temp
    

print(ans)

Solution (Python):
s = input()
n = int(s)
r = 0

for bit in range(2**(len(s)-1)):
    
    e = s[0]
    
    for i in range(len(s)-1):
        if ((bit>>i)&1) == 1:
            
            
            e += '+'
        
        e += s[i+1]
    
    r += sum(map(int, e.split('+')))
print(r)

Solution (Python):
S = input()

def DP(x , i):
    
    ans = 0
    
    if i == len(S):
        
        
        if '+' in x:
            return eval(x)
        else:
            return int(x)
    else:
        
        ans += DP(x + S[i] , i+1)
        if i > 0:
            
            ans += DP(x + '+' + S[i], i+1)
        return ans

print(DP('',0))

Solution (Python):
n = input()
co = 0
for i in range(2**(len(n)-1)):
    a = ""
    for j in n:
        a += j
        if i % 2 == 1:
            a += "+"
        i //= 2
    co += eval(a)
print(co)

Solution (Python):
S = input()
op_cnt = len(S) - 1
ResSum = 0

for i in range(2**op_cnt):
    op = [""] * op_cnt
    for j in range(op_cnt):
        if((i >> j) & 1):
            op[op_cnt - 1 - j] = "+"

    formula = ""
    for p_S, p_o in zip(S, op + [""]):
        formula += (p_S + p_o)

    ResSum += eval(formula)

print(ResSum)

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

total = 0

for i in range(2**n):
    l = [""] * n
    for j in range(n):
        if (i >> j) & 1 :
            l[j] = "+"
    formula = ""
    for p, q in zip(s, l+[""]):
        formula += p + q
    total += eval(formula)

print(total)

Solution (Python):

S=input()
def DP(x,i):
    ans=0
    if i==len(S):
        if '+' in x:
            return eval(x)
        else:
            return int(x)
    else:
        ans+=DP(x+S[i],i+1)
        if i>0:
            ans+=DP(x+'+'+S[i],i+1)
        return ans
print(DP('',0))

Solution (Python):
def cal(d, i, k, total):
  if i == len(d):
    return total + int(k)
  return cal(d, i+1, d[i], total + int(k)) + cal(d, i+1, k + d[i], total)

d = [x for x in input()]
print(cal(d, 1, d[0], 0))

Solution (Python):
S = input()

ans = [S[0]]

for i in range(1,len(S)):
    candidate = []
    for j in ans:
        candidate.append(j+S[i])
        candidate.append(j+'+'+S[i])
        ans = candidate

num = 0
for a in ans:
    num += eval(a)

print(num)

Solution (Python):
S = input()

ans = [S[0]]

for i in range(1,len(S)):
    candidate = []
    for j in ans:
        candidate.append(j+S[i])
        candidate.append(j+'+'+S[i])
        ans = candidate

num = []
for a in ans:
    num.append(eval(a))

print(sum(num))

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

t = []
y = 0

t.append(int(s[n]) * (2 ** n ))

for i in range(n):
    y = 0
    for j in range(1,len(s)+1):
        if j == len(s) + 1 - i:
            continue
        elif j == len(s) - i:
            y = y + int(s[i]) * (10 ** (n - i)) * (2 ** i)
            t.append(y)
        else:
            y = y + int(s[i]) * (10 ** (j - 1)) * (2 ** (n - j))

print(sum(t))

Solution (Python):

S = str(input())
Slist=list(S)
Slen=len(S)
Smax=2**(Slen-1)
ans=0
for i in range(Smax):
    I=bin(i)
    I=I.lstrip("0b")
    Ilen=len(I)
    if Ilen<Slen-1:
        j=0
        for j in range(Slen-Ilen-1):
            I="0"+I
    
    k=0
    Ilist=list(I)
    klist=[]
    now=Slist[0]
    for k in range(Slen-1):
        if Ilist[k]=="0":
            klist.append(int(now))
            now=Slist[k+1]
        else:
            now+=Slist[k+1]
    klist.append(int(now))
    ans+=sum(klist)
print(ans)

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

Solution (Python):
s=input()
n=len(s)-1
if n==0:
  print(s)
else:
  l=[]
  a=len(bin(1<<n))-3
  for i in range(1<<n):
    l.append(str(bin(i))[2:].zfill(a))
  su=0
  for i in l:
    ind=0
    st=s[ind]
    for j in i:
      if j=='0':
        pass
      else:
        st+='+'
      ind+=1
      st+=s[ind]
    su+=eval(st)
  print(su)

Solution (Python):
import itertools
s = input()
ans = 0
ss = [s[i//2] if i%2==0 else "+" for i in range(2*len(s)-1)]

for li in itertools.product(range(2),repeat=len(s)-1):
  for j in range(len(s)-1):
    if li[j] ==1:
      ss[j*2+1] = "+"
    else:
      ss[j*2+1] = ""
  ans = ans+ eval("".join(ss))
print(ans)

Solution (Python):
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
l = [i for i in s]
A = l[1:]

ans = 0
for i in range(1 << len(A)):
	for j in range(len(A)):
		if ((i >> j) & 1) == 1:
			if f == 1:
				continue
			f = 1
		else:
			f = 0
	else:
		s = l[0]
		for j in range(len(A)):
			if ((i >> j) & 1) == 1:
				ans += int(s)
				s = A[j]
			else:
				s += A[j]
		else:
			ans += int(s)

print(ans)

Solution (Python):
def main():
    s = input()
    length = len(s)
    ans = 0

    
    for pt in range(2**(length-1)):
        plus_num = 0
        s_tmp = s
        num =[]

        for i in range(length-1):
            if (pt >> i)&1 :
                s_tmp = s_tmp[:i+1+plus_num] + '+' + s_tmp[i+1+plus_num:]
                
                plus_num += 1
        
        num = s_tmp.split('+')
        for i in num:
            ans += int(i)

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    s = list(map(int, input()))
    r = sum(a + b for a, b in iter_formulas(s))
    print(r)

def iter_formulas(s):
    if len(s) == 1:
        yield 0, s[0]
        return
    
    for a, b in iter_formulas(s[:-1]):
        yield a + b, s[-1]
        yield a, b * 10 + s[-1]

main()

Solution (Python):
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])

s = input()
n = len(s)

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

Solution (Python):
S = input()
T=[s for s in S]
N = len(S)-1
ans=0
for i in range(1<<N):
    T=[s for s in S]
    U=''
    b=[]
    for j in range(N,-1,-1):
        if (i>>j)&1:
            b.append(j)
    for B in b:
        T.insert(B+1,'+')
    for t in T:
        U+=t
    ans += eval(U)
print(ans)

Solution (Python):
import sys
import itertools

S = input()
if len(S) == 1:
    print(int(S))
    sys.exit()

ls = []
a = [0, 1]
for i in itertools.product(a, repeat=len(S)-1):
    ans = 0
    start = 0
    for j, x in enumerate(i):
        if x == 1:
            ans += int(S[start:j+1])
            start = j + 1
    ans += int(S[start:len(S)])
    ls.append(ans)
print(sum(ls))

Solution (Python):
import sys

S = input()
if len(S) == 1:
    print(int(S))
    sys.exit()

ls = []
for i in range(1<<(len(S)-1)):
    ans = 0
    num = format(i, 'b').zfill(len(S)-1)
    start = 0
    for j, x in enumerate(num):
        if x == '1':
            ans += int(S[start:j+1])
            start = j + 1
    ans += int(S[start:len(S)])
    ls.append(ans)
print(sum(ls))

Solution (Python):
import sys

S = input()
if len(S) == 1:
    print(int(S))
    sys.exit()

ls = []
for i in range(1<<(len(S)-1)):
    ans = 0
    num = format(i, 'b').zfill(len(S)-1)
    start = 0
    for (j, x) in enumerate(num):
        if x == '1':
            ans += int(S[start:j+1])
            start = j + 1
    ans += int(S[start:len(S)])
    ls.append(ans)
print(sum(ls))

Solution (Python):
from itertools import product

S = list(input())

states = list(product([i for i in range(2)], repeat=len(S)-1))

res = 0



for state in states:
    formula = S[0]
    for i in range(len(state)):
        if state[i] == 0:
            formula += S[i+1]
        else:
            formula += '+' + S[i+1]

    
    res += eval(formula)

print(res)

Solution (Python):
S = list(input())
"""
if(len(S) == 1):
  print(S[0])
  exit()
cnt = 0
for i in range(1 << len(S)-1):
  f = S[0]
  for j, b in enumerate(format(i, 'b').zfill(len(S)-1)):
    if(b == '1'):
      f += '+'
    f += S[j+1]
  cnt += sum(map(int,f.split('+')))
print(cnt)

"""

cnt = 0
for i in range(1 << len(S)-1):
  f = S[0]
  for j in range(len(S)-1):
    if(((i >> j) & 1)== 1):
      f += '+'
    f += S[j+1]
  cnt += sum(map(int, f.split('+')))
print(cnt)

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):
def dfs(i, s, plus):
    if i == n - 1:
        return sum(list(map(int, s.split("+"))))
    return dfs(i + 1, s, plus) +\
           dfs(i + 1, s[:i + plus + 1] + "+" + s[i + plus + 1:], plus + 1)

s = input()
n = len(s)

print(dfs(0, s, 0))

Solution (Python):
def dfs(i, s, plus):
    if i == n - 1:
        b = list(map(int, s.split("+")))
        return sum(b)
    return dfs(i + 1, s, plus) + dfs(i + 1, s[:i + plus + 1] + "+" + s[i + plus + 1:], plus + 1)

s = input()
n = len(s)

print(dfs(0, s, 0))

Solution (Python):
def bit_all(a,n):
    ans = 0
    for i in range(2**n):
        mini_ans = 0
        now = 0
        for j in range(n):
            if i>>j & 1:
                mini_ans += int(a[now:j+1])
                now = j+1
        mini_ans += int(a[now:])
        ans += mini_ans
    print(ans)
                
                
a = input()
bit_all(a,len(a)-1)

Solution (Python):
S = input()


def f(s, n):
    
    r = 0
    a = 0
    for i in range(len(s) - 1):
        if n & (1 << i) == 0:
            a += int(s[i])
            a *= 10
        else:
            a += int(s[i])
            r += a
            a = 0

    a += int(s[len(s) - 1])
    r += a

    return r


N = (1 << (len(S) - 1))
ans = 0
for n in range(N):
    a = f(S, n)
    
    ans += a

print(ans)

Solution (Python):
s = input()
ret = 0
for i in range(1 << (len(s)-1)):
    x = 0
    sum = 0
    for j in range(len(s)-1):
        if 1<<j & i :
            sum=sum+int(s[x:j+1])
            x = j+1
    sum=sum+int(s[x:])
    ret=ret+sum
print(ret)

Solution (Python):
n = input()
L = []
s = 0
for i in range(len(n)):
  L.append(int(n[i]))

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

Solution (Python):
N = input()
L = []
S = 0
for i in range(len(N)):
  L.append(int(N[i]))
for i in range(len(N)):
  S += (sum(L[0:i])*(2**(i-1))+L[i]*(2**i))*(10**(len(N)-i-1))
print(int(S))

Solution (Python):

S = input()
l = len(S)
S = [int(S[i]) for i in range(l)]

def f(i,sl):
    if i == l-1:
        left = 0
        sumEx = 0
        for j in range(l-1):
            
            left = left*10+S[j]
            if sl[j] == "1":
                sumEx = sumEx + left
                left = 0
        left = left * 10 + S[-1]
        return sumEx + left
                
    else:
        return f(i+1,sl+"1")+f(i+1,sl+"0")
print(f(0,""))

Solution (Python):
S = [int(n) for n in input()]
l = len(S)
ans = 0
for i in range(l):
    for j in range(l - i):
        if (i + j) == (l - 1):
            t = 1
        else:
            t = 2
        ans += S[i] * 10**j * 2**(l - j - t)
print(ans)

Solution (Python):
import itertools
import copy as c
s=list(input())
S=[s[i//2] if i%2==0 else " " for i in range(len(s)*2-1) ]
Ssub=S
ans=0
T=[i for i in range(len(s)*2-1) if i%2==1]
for sss in range(len(s)):
  for ttt in list(itertools.combinations(T,sss)):
    for rrr in ttt:
      S[rrr]="+"
    S="".join(S).replace(" ","")
    ans+=eval("".join(S))
    S=c.deepcopy(Ssub)

print(ans)

Solution (Python):
S = input()
max_pos = len(S) - 1

ans = 0
if max_pos > 0:
    for i in range(1 << max_pos):
        total = 0
        fragment = ""
        for j in range(len(S)):
            digit = S[j]
            fragment += digit
            if j == len(S) - 1 or ((i >> j) & 1) == 1:
                total += int(fragment)
                fragment = ""
        ans += total
else:
    ans = int(S)

print(ans)

Solution (Python):
s=input()
n=len(s)-1
a=0
for i in range(1<<n):
  l=[]
  for x,y in zip(s,[''for _ in[0]*10]):
    l.append(x)
    l.append(y)
  for j in range(n):
    if i>>j&1:
      l[j*2+1]='+'
  a+=eval(''.join(l))
print(a)

Solution (Python):
s=input()
n=len(s)-1
a=0
for i in range(1<<n):
  l=[]
  for x,y in zip(s,[''for _ in[0]*10]):
    l.append(x)
    l.append(y)
  for j in range(n):
    if i>>j&1:
      l[j*2+1]='+'
  a+=eval(''.join(l))
print(a)

Solution (Python):
s = input()
A = []
for i in range(2 ** (len(s) - 1)):
    t = ''
    for j in range(len(s)):
        t += s[j]
        if j != len(s) - 1:
            if i % 2 == 0:
                t += '+'
        else:
            break
        i //= 2
    A.append(eval(t))
print(sum(A))

Solution (Python):
S = input()
power = len(S)-1
loop = 2**power

revS = list(reversed(S))
ans = 0

for i in range(loop):
    ans += int(revS[0])
    multi_ten = 10
    for j in range(power):
        digit = bin(i>>j)[-1]
        if digit == "0":
            ans += int(revS[j+1])*multi_ten
            multi_ten *= 10
        else:
            ans += int(revS[j+1])
            multi_ten = 10
print(ans)

Solution (Python):
S=input()
ans=0
for i in range(len(S)):
    for j in range(i+1):
        ans+=int(S[-(i+1)])*(10**j)*(2**(len(S)-1))//(2**min(i,j+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&(1<<j):tmp+="+"
        tmp+=S[j+1]
    ans+=eval(tmp)
print(ans)

Solution (Python):
S = input()
ans = 0
for i in range(2 ** (len(S) - 1)):
    t = ''
    for s in S:
        t += s
        if i % 2 != 0:
            t += '+'
        i //= 2
    ans += eval(t)
print(ans)

Solution (Python):
def f(s: str):
    n = len(s)

    m = {
        "0": "",
        "1": "+"
    }
    ans = 0
    for bit in range(0, 1<<(n-1)):
        bits = "{:b}".format(bit).zfill(n-1)
        

        ss = s[0]
        for op, x in zip(bits, s[1:]):
            ss += m[op] + x
        ans += sum(map(int, ss.split("+")))
    return ans


print(f(input()))

Solution (Python):
from sys import setrecursionlimit; setrecursionlimit(10**9)
S = input()

def res(S, A, B):
    if not S:
        B.append(sum(list(map(int, A))))
        return None
    A += [S[0]]
    res(S[1:], A, B)
    A.pop()
    A[-1] += S[0]
    res(S[1:], A, B)
    return B

if len(S) == 1:
    print(int(S))
else:
    B = res(S[1:], [S[0]], [])
    print(sum(B))

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

if n==1:
    ans=int(s)
else:
    for b in range(0, 1<<n-1):
        bits=[((b>>i)&1)!=0 for i in range(n-1)]
        t=s[0]
        for i in range(n-1):
            if bits[i]:
                t+='+'
            t+=s[i+1]
        ans+=eval(t)
print(ans)

Solution (Python):
s = input()

cnt = 0
for i in range(2 ** (len(s) - 1)):
    t = ''
    for j in s:
        t += j
        if i % 2 == 1:
            t += '+'
        i //= 2
    cnt += eval(t)
    
print(cnt)

Solution (Python):
*a, = map(int, list(input())[::-1])
n = len(a)

b = [[0]*k for k in range(n+1)]
for k in range(n+1):
    for i in range(k):
        b[k][i] = sum([10**j * a[i+j] for j in range(k-i)])


dp = [0]*n
for k in range(n):
    dp[k] = sum([b[k+1][0]] + [b[k+1][i+1]*2**i + dp[i] for i in range(k)])

print(dp[n-1])

Solution (Python):
*a, = map(int, list(input())[::-1])
n = len(a)

b = [[0]*k for k in range(n+1)]
for k in range(n+1):
    for i in range(k):
        b[k][i] = sum([10**j * a[i+j] for j in range(k-i)])


dp = [0]*n
for k in range(n):
    dp[k] = sum([b[k+1][0]] + [b[k+1][i+1]*2**i + dp[i] for i in range(k)])

print(dp[n-1])

Solution (Python):
from itertools import product as p
s=list(input())
*t,=p(["+",""],repeat=len(s)-1)
v=0

for i in t:
  b=""
  for j in range(2*len(s)-1):
    if j%2:
      b+=i[j//2]
    else:
      b+=s[j//2]
  v+=eval(b)

print(v)

Solution (Python):
s=input()
count=0
for i in range(2**(len(s)-1)):
    t=""
    for j in s:
        t+=j
        if i%2==1:
            t+="+"
        i//=2
    
    count+=eval(t)
print(count)

Solution (Python):

s =input()
n = int(s)
r = 0
p=0
for bit in range(2**(len(s)-1)):
    e = s[0]
    for i in range(len(s)-1):
        if ((bit>>i)&1) == 1:
            e += '+'
        e += s[i+1]
        
    r+= sum(map(int, e.split('+')))
    p+= eval(e)
print(r)

Solution (Python):
def combi(n):
    if len(n) > 1:
        a = n.pop()
        for i in combi(n):
            yield i + [a]
            yield i + ['+', a]
    else:
        yield n

s = 0
for i in combi(list(input())):
    s += eval(''.join(i))

print(s)

Solution (Python):
s = input().strip()
ls = len(s)
total = 0

for i in range(1, ls+1):
  for j in range(0, ls-i+1):
    total += int(s[j:j+i]) * pow(2, max(0,j-1)+max(0, ls-i-j-1))
print(total)

Solution (Python):
s=str(input())
l=len(s)
ans=0
conb=[]
for i in range(2**(l-1)):
    no=i
    x=[]
    for j in range(l-1):
        tar=no%2
        if tar==1:
            x.append(j)
        no=no//2
    conb.append(x)
def tasu(s,p):
    kosuu=len(p)
    count=0
    now=0
    for k in range(kosuu):
        count+=int(s[now:p[k]+1])
        now=p[k]+1
    return count
for k in range(len(conb)):
    p=conb[k]
    p.append(l)
    ans+=tasu(s,p)
print(ans)