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()

len_s = len(s)
ans = 0

for i in range(2**(len_s-1)):
    num = s[0]
    rnum = 0
    for j in range(len_s-1):
        flag = i >> j & 1
        if flag == 1:
            rnum += int(num)
            num = s[j+1]
        else:
            num += s[j+1]
    ans += rnum + int(num)

print(ans)

Solution (Python):
s = input()

d = len(s) - 1

def dfs(depth: int, cur:int, s: str, res: str) -> int:
    if depth == d:
        tmp = s + res[:1]
        return cur + int(tmp)
    
    else:
        tmp = s + res[:1]
        return dfs(depth+1, cur+int(tmp), "", res[1:]) \
                + dfs(depth+1, cur, tmp, res[1:])
                
ans = dfs(0, 0, "", s)

print(ans)

Solution (Python):
S = input()
ans = 0
for b in range(2**(len(S)-1)):
    opes = []
    for i in range(len(S)-1):
        if b&(1<<i):
            opes.append('+')
        else:
            opes.append('')
    formula = ''.join([c+o for c,o in zip(S, opes)])
    ans += eval(formula + S[-1])
print(ans)

Solution (Python):
S=str(input())
formula=[""]*(len(S)*2-1)
ans=0
for i in range(len(S)*2-1):
    if i%2==0:
        formula[i]=S[i//2]
place=pow(2,len(S)-1)-1
for i in range(place+1):
    for j in range(len(bin(i))-2):
        
        if int(str(bin(i))[-j-1])==1:
            formula[2*j+1]="+"
    ans+=eval(''.join(formula))
    for k in range((len(formula)-1)//2):
        formula[2*k+1]=""
print(ans)

Solution (Python):
from itertools import zip_longest, chain

s = input()

sign_amount = len(s)-1
table = str.maketrans("01", " +")

sum_num = 0
for i in range(2 ** sign_amount):
	bin_str = bin(i)[2:].zfill(sign_amount)
	signs = bin_str.translate(table)
	formula = "".join(chain(*zip_longest(s, signs, fillvalue=" "))).replace(" ", "")
	sum_num += eval(formula)

print(sum_num)

Solution (Python):


S = list(input())
N = len(S)-1

ans = 0

for i in range(1 << N):
    offset = 0
    for j in range(N):
        if (i>>j) & 1 == 1:
            
            S.insert(j+1+offset, '+')
            
            offset += 1
            
    ans += eval(''.join(S))
    
    S = [j for j in S if j != '+']

print(ans)

Solution (Python):

import itertools

def main():
    s = list(input())
    string = []
    for i in s:
        string.append(i)
        string.append('')
    position = [x for x in range(1, len(string)-1, 2)]
    ans = 0

    for i in range(len(s)):
        places = list(itertools.combinations(position, i))
        for place in places:
            string_cp = string[:]
            for p in place:
                string_cp[p] = '+'
            ans += eval(''.join(string_cp))

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
s = input()
n = len(s)
num = 0
for i in range(1 << n):
    if i % 2 == 0:
        continue
    pre = 0
    tmp = []
    for j in range(n):
        if i & 1 << j:
            if len(s[pre:j]) != 0:
                tmp.append(int(s[pre:j]))
            pre = j
    tmp.append(int(s[pre:]))
    num += sum(tmp)

print(num)

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

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

S = input()
L = len(S)-1
flags = []
for i in range(2**L):
	t = format(i,'010b')
	flags.append(list(t[10-L:]))


ans = 0

for flag in flags:
	tmp_li = [0]
	for i,fl in enumerate(flag):
		if fl == '1':
			tmp_li.append(i+1)
	tmp_li.append(L+1)

	for i in range(len(tmp_li)-1):
		l = tmp_li[i]
		r = tmp_li[i+1]
		ans += int(S[l:r])

print(ans)

Solution (Python):
from itertools import product, chain
S = input()
ans = 0
if len(S) == 1:
    print(S)
    exit()

for i in product(['+', ''], repeat=len(S) - 1):
    ans += eval(S[0] + ''.join(chain.from_iterable(zip(i, S[1:]))))
print(ans)

Solution (Python):
from itertools import product, chain
S = input()
ans = 0
for i in product(['+', ''], repeat=len(S) - 1):
    ans += eval(S[0] + ''.join(chain(*zip(i, S[1:]))))
print(ans)

Solution (Python):

"""
Created on Wed Aug  8 21:43:24 2018
ABC045C
@author: maezawa
"""

s = input()
n = len(s)-1
sums = 0

for i in range(2**n):
    signs =[]
    for j in range(n):
        if i & (1<<j):
            signs.append('+')
        else:
            signs.append('')
    
    eq = ''
    for k in range(n):
        eq += s[k] + signs[k] 
    eq += s[n]
    
    sums += eval(eq)
    
print(sums)

Solution (Python):



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

    ans = 0
    for bit in range(1 << d):
        sum_i = 0
        prev_pos = 0
        for i in range(d):
            if bit & (1 << i) != 0:
                sum_i += int(s[prev_pos:i + 1])
                prev_pos = i + 1

        ans += sum_i + int(s[prev_pos:d + 1])

    print(ans)

Solution (Python):
from itertools import combinations as c
s=input()
r=0
for j in range(1,len(s)):
  for i in c(range(1,len(s)),j):
    k=[0]+list(i)+[len(s)]
    v=sum(map(int,[s[k[i]:k[i+1]] for i in range(j+2-1)]))
    r+=v
print(r+int(s))

Solution (Python):
S = input()

ans = 0

def dfs(s, sum_, n):
    if n == len(S)-1:
        return int(s) + sum_

    return dfs(s+S[n+1], sum_, n+1) + dfs(S[n+1], sum_+int(s), n+1)

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

Solution (Python):
S = input()

allsum = 0

def calcStr(s) :
    return sum(list(map(int, s.split("+"))))

def dosum(s, idx) :
    global allsum
    if idx >= len(s) :
        allsum += calcStr(s)
        
    else :
        if len(s) > idx :
            dosum(s[0:idx] + "+" + s[idx:len(s)], idx + 2)
            dosum(s, idx + 1)
            
dosum(S, 1)
print(allsum)

Solution (Python):
from itertools import zip_longest

s = input()
s = list(s)
cnt_pos = len(s) - 1
formula_cnt = 2 ** (cnt_pos)

ans = 0
for i in range(formula_cnt):
    sgns = ['+' if (i & (2 ** x) != 0) else '' for x in range(cnt_pos)]
    formula = ''
    for c, sgn in zip_longest(s, sgns, fillvalue=''):
        formula += c + sgn
    
    ans += eval(formula)
print(ans)

Solution (Python):
from itertools import product

S = input()
n = len(S) - 1
ans = 0
for p in product([True, False], repeat=n):
    x = 0
    s = ''
    for i in range(n):
        s += S[i]
        if p[i]:
            x += int(s)
            s = ''
    s += S[-1]
    x += int(s)
    ans += x
print(ans)

Solution (Python):
import itertools

s = input()

tfs = []
tfset = (True, False)
for i in itertools.product(tfset, repeat=len(s)-1):
    tfs.append(i)

allsum = 0
for tf in tfs:
    sum = 0
    digit = 0
    for i, seed in enumerate(tf):
        if seed:
            sum += int(s[digit:i+1])
            digit = i+1
    sum += int(s[digit:])
    allsum += sum

print(allsum)

Solution (Python):
S = input()
tf_str = ""

ans = 0

def dfs(tf_str,S):
    global ans
    if len(tf_str) != len(S)-1:
        dfs(tf_str + "f",S)
        dfs(tf_str + "t",S)
    else:
        frm = 0
        for to in range(1,len(S)):
            if tf_str[to-1] == "t":
                ans += int(S[frm:to])
                frm = to
        
        ans += int(S[frm:])


dfs(tf_str,S)   
print(ans)

Solution (Python):
import sys

S = input()


combs = pow(2, len(S) - 1)
if len(S) == 1:
    print(S)
    sys.exit()

total = 0
for i in range(combs):
    
    comb_i = format(i, '0' + str(len(S)) + 'b')
    if len(comb_i) > 1:
        comb_i = comb_i[1:]

    tmp = S[0]
    for j in range(len(comb_i)):
        b = int(comb_i[j])
        if b == 1:
            tmp += "+"
        tmp += S[j + 1]
    total += eval(tmp)
print(total)

Solution (Python):
import copy
from itertools import combinations
S = input()

result = 0
for n_plus in range(len(S)):
    for plus_indices in combinations(range(1, len(S)), n_plus):
        S_new = copy.deepcopy(S)
        for i, plus_idx in enumerate(plus_indices):
            S_new = S_new[:plus_idx+i] + '+' + S_new[plus_idx+i:]
        result += eval(S_new)
print(result)

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

SUM = 0
for pattern in itertools.product('+ ', repeat=len(S)-1):
    form = ''
    for i in range(len(S)-1):
        form += S[i] + pattern[i]
    form += S[-1]
    SUM += eval(form.replace(' ', ''))
print(SUM)

Solution (Python):
import functools
S = input()
C = [S[0]]
for s in S[1:]:
  C = functools.reduce(lambda x, y: x + y, [[c + s, c + '+' + s] for c in C])
ans = 0
for c in C:
  ans += sum([int(x) for x in c.split('+')])
print(ans)

Solution (Python):
import copy
from itertools import combinations
S = input()

result = 0
for n_plus in range(len(S)):
    for plus_indices in combinations(range(1, len(S)), n_plus):
        S_new = copy.deepcopy(S)
        c = 0
        for i, plus_idx in enumerate(plus_indices):
            S_new = S_new[:plus_idx+i] + '+' + S_new[plus_idx+i:]
        result += eval(S_new)
print(result)

Solution (Python):
s = input()

m = {}
def f(t):
    ret = []
    for i in range(1, len(t) + 1):
        hd,tl = t[:i], t[i:]
        if tl == '':
            ret.append(int(hd))
            continue
        if tl in m:
            ret = ret + m[tl]
            continue
        ihd = int(hd)
        ret = ret + [ihd + x for x in f(tl)]
    return ret
print(sum(f(s)))

Solution (Python):
from copy import deepcopy
s = input()
length = len(s)

ans = 0
def solve(s_split, s, i):
    if i == length:
        
        global ans
        ans += sum(list(map(int, s_split)))
    else:
        tmp1 = deepcopy(s_split)
        tmp1[-1] += s[0]
        solve(tmp1, s[1:], i+1)

        tmp2 = deepcopy(s_split)
        tmp2.append(s[0])
        solve(tmp2, s[1:], i+1)
        
solve([s[0]], s[1:], 1)
print(ans)

Solution (Python):
from copy import deepcopy
s = input()
length = len(s)

ans = 0
def solve(s_split, s, i):
    if i == length:
        
        global ans
        ans += sum(list(map(int, s_split)))
    else:
        tmp1 = deepcopy(s_split)
        tmp1[-1] += s[0]
        solve(tmp1, s[1:], i+1)

        tmp2 = deepcopy(s_split)
        tmp2.append(s[0])
        solve(tmp2, s[1:], i+1)
        
solve(['0'], s, 0)
print(int(ans/2))

Solution (Python):
import sys

s = input()
plus_num = len(s) - 1
if plus_num == 0:
    print(s)
    sys.exit(0)

f = '0%sb' % plus_num
plus_list = [format(i, f) for i in range(2 ** plus_num)]
result = 0

for plus in plus_list:
    ans = 0
    tmp = int(s[0])
    for i, v in enumerate(s[1:]):
        if plus[i] == '0':
            tmp = tmp * 10 + int(v)
        else:
            ans += tmp
            tmp = int(v)
    ans += tmp
    result += ans

print(result)

Solution (Python):
s = input()
plus_num = len(s) - 1
if plus_num == 0:
    print(s)
    exit(0)

f = '0%sb' % plus_num
plus_list = [format(i, f) for i in range(2 ** plus_num)]
result = 0

for plus in plus_list:
    ans = 0
    tmp = int(s[0])
    for i, v in enumerate(s[1:]):
        if plus[i] == '0':
            tmp = tmp * 10 + int(v)
        else:
            ans += tmp
            tmp = int(v)
    ans += tmp
    result += ans

print(result)

Solution (Python):
import itertools as it

S = input()
ans = 0

for bits in it.product((True, False), repeat=len(S)-1):
    A = ''
    for s, bit in zip(S, bits + (0,)):
        A += s + '+'*bit
    ans += eval(A)

print(ans)

Solution (Python):
from itertools import product
s=input()

r=0
for i in product([0,1],repeat=len(s)-1):
    t=''
    for c,j in zip(s,list(i)+[0]):
        t+=c+'+'*j
    r+=eval(t)
    
print(r)

Solution (Python):
a=input()
x=0
for i in range(2**(len(a)-1)):
    s=''
    for j in range(len(a)-1):
        s+=a[j]+'+'*int(format(i,'010b')[-j-1])
    s+=a[-1]
    x+=eval(s)
print(x)

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

def slove(left,right):
    if len(right)==0:
        return eval(left+right)
    return slove(left+right[0],right[1:])+slove(left+'+'+right[0],right[1:])

ans=slove(s[0],s[1:])
print(ans)

Solution (Python):
from itertools import chain, product, zip_longest
 
s = input()
assert all(c in '123456789' for c in s)

betweens = product(('', '+'), repeat=len(s)-1)
def make_string(between):
  return ''.join(chain.from_iterable(zip_longest(s, between, fillvalue='')))
strings = (make_string(between) for between in betweens)
print(sum(map(eval, strings)))

Solution (Python):
from itertools import chain, product

s = input()
assert all(c in '123456789' for c in s)

betweens = product(('', '+'), repeat=len(s)-1)
strings = (s[0] + ''.join(chain.from_iterable(zip(between, s[1:]))) for between in betweens)
print(sum(map(eval, strings)))

Solution (Python):
from itertools import product

s = input()
assert all(c in '123456789' for c in s)

def make_string(mask):
    return s[0] + ''.join(('+' if m else '') + c for m, c in zip(mask, s[1:]))

masks = product((0,1), repeat=len(s)-1)
print(sum(eval(make_string(mask)) for mask in masks))

Solution (Python):
s = input()
assert all(c in '123456789' for c in s)

def dfs(i, s1):
    if i == len(s):
        yield eval(s1)
        return
    yield from dfs(i+1, s1+s[i])
    yield from dfs(i+1, s1+'+'+s[i])

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

Solution (Python):
S = str(input())
t = len(S)
ans =0
for i in range(1<<t-1):
    k=S[0]
    for x in range(t-1):
        if i & 1<<x:
            k=k+'+'+S[x+1]
        else:
            k+=S[x+1]
    ans +=eval(k)
print(ans)

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

Solution (Python):
s=input()
ans=0
for i in range(2**(len(s)-1)):
  t=""
  for j in range(len(s)-1):
    if format(i,"0"+str(len(s)-1)+"b")[j] == '1':
      t+=s[j]+"+"
    else:
      t+=s[j]
  t+=s[-1]
  ans+=eval(t)
print(ans)

Solution (Python):
S = input()
ans = 0
for b in range(2**(len(S)-1)):
    opes = []
    for k in range(len(S)-1):
        if b&(1<<k):
            opes.append('+')
        else:
            opes.append('')
    formula = ''.join([a+o for a,o in zip(S,opes)]) + S[-1]
    ans += eval(formula)

print(ans)

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

    AC(S)


def AC(S):
    n = len(S)
    a = [0] * (n-1)

    def rec(i, n):
        ans = 0
        if i == n:
            ss = list(S)
            for j, x in enumerate(a):
                if x == 1:
                    ss[j] = ss[j] + "+"
            
            for x in "".join(ss).split("+"):
                ans += int(x)
            return ans

        a[i] = 1
        ans += rec(i + 1, n)
        a[i] = 0
        ans += rec(i + 1, n)
        return ans
    ans = rec(0, n-1)
    print(ans)


def WA(S):
    ans = 0
    for n in range(len(S)):
        x = f(S, n)
        ans += x

    print(ans)


def f(S, n):
    ans = 0
    if n == 0:
        ans = int(S)
    elif len(S) - 1 == n:
        ans = sum(map(int, S))
    elif n == 1:
        for i in range(len(S)-1):
            x = int(S[:i+1]) + int(S[i+1:])
            ans += x
            print(S, n, i, x)
    else:
        for i in range(len(S)-1):
            x = S[:i+1]
            y = S[i+1:]
            if len(y) > n - 1:
                ans += int(x) + f(y, n-1)

    print(S, n, ans, sep="\t")
    return ans


if __name__ == '__main__':
    main()

Solution (Python):






def dfs(i: int):
    global count

    if i == n - 1:
        count += eval(''.join(numbers))
        return

    numbers[2 * i + 1] = ""
    dfs(i + 1)
    numbers[2 * i + 1] = "+"
    dfs(i + 1)


if __name__ == '__main__':
    s = input()
    n = len(s)
    numbers = [""] * (2 * n - 1)
    count = 0

    for i in range(n):
        numbers[2 * i] = s[i]

    dfs(0)
    print(count)

Solution (Python):
from itertools import product
s=input().strip()
ans=0
for i in product(["","+"] , repeat=len(s)-1):
  t=s[0]
  n=1
  for j in i:
    t+=j+s[n]
    n+=1
  ans+=eval(t)
  
print(ans)

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

Solution (Python):
def my_add(arg: list):
    if len(arg) == 1:
        return eval(arg[0])
    return my_add([arg[0]+arg[1]]+arg[2:]) + my_add([arg[0]+'+'+arg[1]]+arg[2:])

print(my_add(list(input())))

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

for b in range(2**(len(S)-1)):
    opes = []
    for k in range(len(S)-1):
        if b & (1 << k):
            opes.append('+')
        else:
            opes.append('')
    formula = ''.join([d + o for d,o in zip(S,opes)])
    ans += eval(formula + S[-1])
print(ans)

Solution (Python):
def cul(num, idx):
    if idx == len(num):
        return eval(num)

    return cul(num[:idx]+"+"+num[idx:], idx+2) + cul(num, idx+1)


def main():
    s = input()
    print(cul(s, 1))


if __name__ == '__main__':
    main()

Solution (Python):
s = int(input())
sl = list(str(s))
sl_n = len(sl) - 1
l = ['a','b']
def a_or_b(x):
    if len(list(str(x[0]))) == sl_n:
        return x
    else:
        ll = []
        for i in range(len(x)):
            ll.append(x[i] + 'a')
        for i in range(len(x)):
            ll.append(x[i] + 'b')
        x = ll
        return a_or_b(x)
    
lll = []
ans = 0

if len(sl) == 1:
    ans = s
else:
    lll = a_or_b(l)
    kkk = []
    for i in range(len(lll)):
        p = sl
        q = list(str(lll[i]))
        st = ''
        for j in range(len(p) - 1):
            if q[j] == 'a':
                st = st + p[j] +'+'
            else:
                st = st + p[j] + ''
        st = st + sl[-1]
        res = eval(st)
        ans += res
        
print(ans)

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

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

def ops(x):
    o = []
    for i in range(len(S)-1):
        o.append(x%2 == 1)
        x //= 2
    return o

ans = 0
for i in range(2**(len(S)-1)):
    op = ops(i)
    x = S[0]
    for i in range(len(S)-1):
        if op[i]:
            ans += x
            x = S[i+1]
        else:
            x = x*10 + S[i+1]
    ans += x
print(ans)

Solution (Python):
def exp2(n):
	ans = 1
	for i in range(0, n):
		ans = ans * 2
	return ans

S = list(raw_input())
opnumber = exp2(len(S)-1)
ans = 0

for i in range(0, opnumber):
	tmp = i
	numlst = []
	n = S[0]
	for j in range(1, len(S)):
		if tmp%2 == 1:
			numlst.append(int(n))
			n = ''
		n = n + S[j]
		tmp = tmp / 2
	numlst.append(int(n))
	for j in range(0, len(numlst)):
		ans = ans + numlst[j]

print ans

Solution (Python):
def c_many_formulas(S):
    import itertools
    
    string = itertools.product('01', repeat=len(S) - 1)
    ans = 0
    for s in string:
        operator = ['+' if x == '1' else '' for x in s] + ['']  
        tmp = ''  
        for value, op in zip(S, operator):
            tmp += (value + op)  
        ans += eval(tmp)
    return ans

S = input().strip()
print(c_many_formulas(S))

Solution (Python):
def li(s):
    lis = [[] for i in range(2**(len(s)-1))]
    bi = []
    if len(s) == 1:
        return [[int(s)]]
    for i in range(2**(len(s)-1)):
        bi.append(bin(i)[2:])
        while len(bi[i]) != len(s)-1:
            bi[i] = "0"+bi[i]

    for i in range(len(bi)):
        v = 0
        for j in range(len(bi[i])):
            if bi[i][j] == "1":
                lis[i].append(int(s[v:j+1]))
                v = j+1
            if j == len(bi[i])-1:
                lis[i].append(int(s[v:]))
    return lis

s = input()
ans = 0
lis = li(s)

for i in lis:
    for j in i:
        ans += j
print(ans)

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

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

Solution (Python):
s = input()

result = []

def spstr(made, left):
    for x in range(1, len(left)+1):
        new_made = made.copy()
        new_made.append(int(left[0:x]))
        new_left = left[x:]
        if new_left == "":
            result.append(new_made)
        else:
            spstr(new_made, new_left)
spstr([], s)

count = 0
for r in result:
    for n in r:
        count += n
print(count)

Solution (Python):
s = raw_input()
n = len(s)
res = 0
for i in range(n):
    for j in range(i, n):
        cnt =  n - (j - i + 3) + (i == 0) + (j == n - 1)
        res += int(s[i:j+1])*(1<<cnt)
print res

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

def sum_of_digit(d, l, s): 
    
    if s == 0:
        return d * (2 ** (l - s))
    else:
        digits = [(2 ** (s - 2 - i)) * (10 ** i) for i in range(s - 1)] + [10 ** (s - 1)]
        return d * (2 ** (l - s)) * sum(digits)

ans = 0
for i in range(len(S)):
    ans += sum_of_digit(S[i], len(S), len(S) - i)
    
print(ans)

Solution (Python):
def dfs(x,s,ans,n):
    if x == len(S):
        ans.append(eval(s))
        return
    dfs(x+1,s,ans,n)
    s = s[:x+n]+'+'+s[x+n:]
    dfs(x+1,s,ans,n+1)

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

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

Solution (Python):
from itertools import product
S = input()
i,L = 0,len(S)
ops = list(product(" +", repeat=L-1))

T = 0
for op in ops:
    W = ""
    for i in range(L-1):
        W += S[i]+op[i]
    W += S[L-1]
    T += eval(W.replace(" ",""))
print(T)

Solution (Python):
import itertools
s = input()
ans = 0

for op in itertools.product(["+", ""], repeat=len(s)-1):
  temp = ""
  for j in range(len(op)):
    temp += s[j]
    temp += op[j]
  temp += s[-1]
  ans += eval(temp)

print(ans)

Solution (Python):


s = input()
if len(s) == 1:
    total = int(s)
else:
    bitlist = []
    
    for i in range(2 ** (len(s) - 1)):
        bitlist.append([int(x) for x in list(bin(i)[2::].zfill(len(s) - 1))])
    
    total = 0
    for bit in bitlist:
        befnum = int(s[0])
        
        for i, plus in enumerate(bit):
            if plus == 0:
                
                befnum = befnum * 10 + int(s[i + 1])
                
            else:  
                
                total += befnum
                befnum = int(s[i + 1])
                
            if i == len(bit) - 1:
                total += befnum
            
print(total)

Solution (Python):
T=list(input())
S=[int(i) for i in T]
N=len(S)-1
K=0
for i in range(2**N):
    t=str(bin(i))[2:]
    t="0"*(N-len(t))+str(t)
    t=t.replace("1","+").replace("0", " ")
    u=str(S[0])
    for i in range(N):
        u+=str(t[i])+str(S[i+1])
    u=u.replace(" ","")
    v=u.split("+")
    M=0
    for i in v:
        M+=int(i)
    K+=M
print(K)

Solution (Python):
T=list(input())
S=[int(i) for i in T]
N=len(S)-1
K=0
for i in range(2**N):
    t=str(bin(i))[2:]
    t="0"*(N-len(t))+str(t)
    t=t.replace("1","+").replace("0", " ")
    u=str(S[0])
    for i in range(N):
        u+=str(t[i])+str(S[i+1])
    u=u.replace(" ","")
    v=u.split("+")
    M=0
    for i in v:
        M+=int(i)
    K+=M
print(K)

Solution (Python):
S=input()
def culc(s,a):
  a.sort()
  res=int(s[:a[0]])
  for i in range(1,len(a)):
    x=int(s[a[i-1]:a[i]])
    res+=x
  res+=int(s[a[-1]:])
  return res

bits=2**(len(S)-1)
ans=int(S)
for i in range(1,bits):
  cnt=[]
  for j in range(len(S)-1):
    if (i>>j)&1:
      cnt.append(j+1)
  ans+=culc(S,cnt)
print(ans)

Solution (Python):
import itertools
s = input()
x,answer = [" ","+"],0
for i in itertools.product(x,repeat=len(s)-1):
	s2 = ""
	for j in range(len(s)-1):
		s2 += s[j]+i[j]
	s2 += s[-1]
	s2 = s2.replace(" ","")
	answer += eval(s2)
print(answer)

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

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

Solution (Python):
from functools import reduce

def formulas(s):
    formula_list = []
    def aux(current, i):
        if i < len(s):
            aux(current + [s[i]], i + 1)
            aux(current + ['+', s[i]], i + 1)
        else:
            formula_list.append(''.join(current))                
    
    aux([s[0]], 1)
    return formula_list
        
    
if __name__ == '__main__':
    s = input()
    print(reduce(lambda x, y: x + eval(y), formulas(s), 0))

Solution (Python):
import itertools
s=input()
ans=0
for i in itertools.product(["","+"],repeat=len(s)-1):
    e=""
    j=0
    for k in s:
        e+=k
        if j<len(i):
            e+=i[j]
            j+=1
    ans+=eval(e)
print(ans)

Solution (Python):
import itertools
s=input()
ans=0
for i in itertools.product(["","+"],repeat=len(s)-1):
    e=""
    j=0
    for k in s:
        e+=k
        if j<len(i):
            e+=i[j]
            j+=1
    ans+=eval(e)
print(ans)

Solution (Python):
s = input()
l = len(s)
val = []
for i in range(2 ** (l-1)):
	div = [0]
	for j in range((l-1)):
		if (i >> j) & 1:
			div.append(j+1)
	v = 0
	for d in range(len(div)-1):
		v += int(s[div[d]:div[d+1]])
	v += int(s[div[-1]:])

	val.append(v)

print(sum(val))

Solution (Python):
import itertools

S = input()

ans = 0
for T in itertools.product(['', '+'], repeat=len(S) - 1):
    e = ''
    i = 0
    for s in S:
        e += s
        if i < len(T):
            e+=T[i]
            i+=1
    ans += eval(e)

print(ans)

Solution (Python):
import sys
s=input()
if(len(s)==1):
  print(s)
  sys.exit()
su=0
for i in range(2**(len(s)-1)):
  b=bin(i)[2:].zfill(len(s)-1)
  calcs=s[0]
  for j in range(len(b)):
    if(b[j]=="0"):calcs+=s[j+1]
    else:calcs+="+"+s[j+1]
  su+=eval(calcs)
print(su)

Solution (Python):
s = list(input())
ans = 0
for i in range(2**(len(s)-1)):
    
    a = list(format(i,'b').zfill(len(s)-1)+'0')
    b = []
    for j in range(len(s)):
        b.append(s[j])
        if a[j] == '1':
            b.append('+')
            
    ans += eval(''.join(b))

print(ans)

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

Solution (Python):
S = input()
N = len(S)
ans = 0
for i in range(2**(N-1)):
    ans += eval(''.join([S[j] + '+' * ((i>>j)&1) for j in range(N-1)]) + S[-1])
print(ans)

Solution (Python):
from itertools import product, zip_longest

S = input()
cmb = list(product(["", "+"], repeat=(len(S) - 1)))

formulas = []
for c in cmb:
    formulas.append("".join(x + y for x, y in zip_longest(S, c, fillvalue="")))

ans = 0
for f in formulas:
    ans += eval(f)
print(ans)

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

if __name__ == "__main__":
    main()

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

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    s = input()
    n = len(s)
    sum = 0
    for i in range((1<<(n-1))):
        prev = 0
        exp = ""
        for j in range(n-1):
            if (i>>j)&1:
                exp += s[prev:j+1]
                prev = j+1
                exp += "+"
        exp += s[prev:]
        sum += eval(exp)
    print(sum)
        

if __name__ == "__main__":
    main()

Solution (Python):
s=list(input())
total=0
mask=0
n=len(s)
while mask<(1<<(n-1)):
    i=0
    s_i=s[:]
    while i<n-1:
        if mask&(1<<i):
            s_i[i]=s_i[i]+"+"
        i+=1
    total+=eval("".join(s_i))
    mask+=1
print(total)

Solution (Python):
def main():
    S = list(str(input()))

    total = 0
    mask = 0
    n = len(S)
    while mask < (1<<(n-1)):
        i = 0
        s = S[:]
        while i < n-1:
            if mask & (1<<i):
                s[i] = s[i] + '+'
            i += 1
        total += eval(''.join(s))
        mask += 1

    print(total)

main()

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()
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):
from itertools import combinations
s = input()
ans = 0
for i in range(len(s)):
    for ind in combinations(range(1, len(s)), i):
        c = 0
        st = s
        for j in ind:
            st = st[:j+c] + '+' +st[j+c:]
            c += 1
        ans += eval(st)
print(ans)

Solution (Python):
s=input()
n=len(s)
a=[]
for i in range(1<<(n-1)):
 c=""
 for j in range(n-1):
   if i>>j & 1:
     b="+"
   else:
     b=""
   c+=s[j]+b
 c+=s[-1]
 a.append(c)
k=0
for i in a:
  for j in i.split("+"):
    k+=int(j)
print(k)

Solution (Python):

"""
https://beta.atcoder.jp/contests/abc045/tasks/arc061_a

"""
import sys
from sys import stdin
from itertools import combinations
input = stdin.readline


def prepare_eq(S, c):
    
    if len(c) == 0:
        return S

    eq = ''
    for i, s in enumerate(S):
        eq += s
        if i == c[0]:
            eq += '+'
            c = c[1:]
            if len(c) == 0:
                eq += S[i+1:]
                break
    return eq


def solve(S):
    total = 0
    for i in range(len(S)):
        for c in combinations(range(len(S)-1), i): 
            eq = prepare_eq(S, c)
            total += eval(eq)   
    return total


def main(args):
    S = input().strip()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
def c_ManyFormulas(S):
    import itertools
    d = len(S)  
    
    comb = itertools.product('01', repeat=d - 1)
    ans = 0
    for c in comb:
        c = ['+' if x == '1' else '' for x in c]
        tmp = ''  
        for i in range(d):
            if i == d - 1:
                
                tmp += S[d - 1]
            else:
                tmp += S[i] + c[i]
        ans += eval(tmp)
    return ans

S = input().strip()
print(c_ManyFormulas(S))