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



Sample input:
125


Sample output:
176

Submission status: Accepted

Solution code:
S = input()
S_len = len(S) - 1
p = []
for i in range(2 ** S_len):
    tmp = bin(i)[2::]
    while len(tmp) < S_len:
        tmp = "0" + tmp
    p.append(str(tmp))

sum = 0
for i in p:
    if len(p) == 1:
        sum = S
        break
    P = list(i)
    tmp = int(S[0])
    cnt = 1
    for j in P:
        if j == "0":
            tmp *= 10
            tmp += int(S[cnt])
        else:
            sum += tmp
            tmp = int(S[cnt])
        cnt += 1
    sum += tmp
print(sum)

Submission status: Accepted

Solution code:
#061C
s = input()
ans = 0

for i in range(2**(len(s)-1)):
    a = ""
    for j in range(len(s)):
        a += s[j]
        if i & (1 << j):
            a += "+"
    ans += eval(a)
    
print(ans)

Submission status: Accepted

Solution code:
S = str(input())
# print(S)
S_size = len(S)


def calc(s, plist):
    nlist = [0]*S_size
    nlistcount = 0
    start = 0
    end = 1
    plist = list(map(int, list(plist)))

    if plist == []:
        nlist[0] = int(s)

    for i in range(S_size-1):
        if plist[i] == 1:
            nlist[nlistcount] = int(S[start:end])
            start = end
            end += 1
            nlistcount += 1
        else:
            end += 1
        if end == S_size:
            nlist[nlistcount] = int(S[start:end])
            nlistcount += 1
    return sum(nlist)



# pi: +を入れるか判定した回数，
# plist: +を入れるかどうかの01str
def dfs(pi, plist):
    # print(pi, plist,type(plist))
    if pi == S_size - 1:
        # print(plist, calc(S, plist))
        return calc(S, plist)
    return dfs(pi + 1, plist+"0") + dfs(pi + 1, plist+"1")


print(dfs(0,""))

Submission status: Accepted

Solution code:
s = input()
length = len(s)
ans = 0
for i in range(1 << (length - 1)):
        front = 0
        for j in range(length):
                if 1 << j & i:
                        ans += int(s[front:j + 1])
                        front = j + 1
        ans += int(s[front:length])
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = 0
for i in range(2 ** (n - 1)):
    tmp = s[0]
    for j in range(n - 1):
        if ((i >> j) & 1):
            tmp += '+'
        tmp += s[j+1]
    ans += eval(tmp)
print(ans)

Submission status: Accepted

Solution code:
S = input()

def dfs(start, S, curSum, res):
	if start >= len(S):
		res[0] += curSum
		return

    # put a plus on each space until last
	for i in range(start+1, len(S) + 1):
		dfs(i, S, curSum+int(S[start:i]), res)

	
res = [0]

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

Submission status: Accepted

Solution code:
from functools import reduce
S = input()

def dfs(res, depth, path, S):
    if len(''.join(path)) == len(S):
        res.append(path)
    for i in range(depth + 1, len(S) + 1):
        dfs(res, i, path + [S[depth:i]], S)

res = []

dfs(res, 0, [], S)

print(sum(int(num) for nums in res for num in nums))

Submission status: Accepted

Solution code:
s = list(input())
def many_formulas(index,string):
    if index >=len(s):
        return eval(string)
    return many_formulas(index+1, string + "+" + s[index]) + many_formulas(index+1, string+s[index])
print(many_formulas(1,s[0]))

Submission status: Accepted

Solution code:
S = input()
length = len(S)
ans = 0
 
for i in range(length):
    ans += sum([int(S[i]) * (10**k) * 2**(max(0, length-i-k-2) + i) for k in range(length - i)])
 
print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
ans = 0

for i in range(1,2**(N-1)):
    A = S[0]
    for j in range(N-1):
        if 1 << j & i:
            A += '+'
        A += S[j+1]
    ans += eval(A)
    # print(A, 'ans: ', ans)

print(ans+int(S))

Submission status: Accepted

Solution code:
c=input()

import copy
pattern = []

def roop_cal(l,max_l,temp):
    if (l ==0):
        pattern.append(copy.copy(temp))
    else:
        for i in range(2):
            temp[max_l-l] = i
            roop_cal(l-1, max_l, temp)
            
l =len(c)-1
temp = [None for _ in range(l)]
roop_cal(l,l,temp)
sum_equation = 0
for i in range(len(pattern)):
    temp = []
    for j in range(len(c)):
        temp.append(c[j])
        if(j >=len(pattern[i])):
            sum_equation = sum_equation+int(''.join(map(str,temp)))
        else:
            if(pattern[i][j]==1):
                sum_equation = sum_equation+int(''.join(map(str,temp)))
                temp = []
                
print(sum_equation)

Submission status: Accepted

Solution code:
s = input()
ans = 0

def plus_in(num, i):
  if i < len(s):
    plus_in(num + s[i], i + 1)
    plus_in(num + "+" + s[i], i + 1)
  else:
    nums = map(int, num.split("+"))
    sum_nums = sum(nums)
    global ans
    ans += sum_nums


plus_in(s[0], 1)
print(ans)

Submission status: Accepted

Solution code:
M=input()
N=len(M)
S=[]
B=[]
for i in range(0,N):
    S.append(M[i])
    B.append(M[i])
T=2**(N-1)
A=0
if N!=1:
    for i in range(0,T):
        t=[]
        k=i
        for j in range(0,N-1):
            if k>=2**(N-2-j):
                t.append(1)
                k=k-2**(N-2-j)
            else:
                t.append(0)
        n=0
        for j in range(0,N):
            S[j]=B[j]
        for j in range(0,N-1):
            if j<N-2:
                if t[j]==1:
                    n=n+int(S[j])
                else:
                    S[j+1]=S[j]+S[j+1]
            else:
                if t[j]==1:
                    n=n+int(S[j])+int(S[j+1])
                else:
                    S[j+1]=S[j]+S[j+1]
                    n=n+int(S[j+1])
        A=A+n
else:
    A=int(M)
print(A)

Submission status: Accepted

Solution code:
S = input()
length = len(S)
ans = 0

for i in range(length):
    ans += sum([int(S[i]) * (10**k) * 2**(max(0, length-i-k-2) + i) for k in range(length - i)])

print(ans)

Submission status: Accepted

Solution code:
S = input()
length = len(S)
ans = 0

for i in range(length):
    ans += sum([int(S[i]) * (10**k) * 2**(max(0, length-i-k-2) + i) for k in range(length - i)])

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
n = len(s)

ans = 0
for b in range(1 << (n - 1)):
    tmp = 0
    for i, x in enumerate(s):
        tmp = 10 * tmp + int(x)
        if b >> i & 1:
            ans += tmp
            tmp = 0
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
S = input()

from itertools import combinations

s = int(S)
for l in range(1, len(S)):
    for c in combinations(range(1, len(S)), l):
        c = sorted(c)
        n = [int(S[lower:upper]) for lower, upper in zip([0] + c, c + [len(S)])]
        s += sum(n)

print(s)

Submission status: Accepted

Solution code:
S = input()

ans = 0

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

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

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

print(ans)

Submission status: Accepted

Solution code:
from inspect import currentframe


def debug_print(s):
    # print(s)
    return


def debug_key(*args):
    names = {id(v): k for k, v in currentframe().f_back.f_locals.items()}
    debug_print(', '.join(names.get(id(arg), '???')+' = '+repr(arg) for arg in args))


def solve(S):
    N = len(S)
    ans = 0

    for i in range(2 ** (N - 1)):
        culculate = S[0]
        for j in range(N - 1):
            if i & (1 << j):
                culculate += "+" + S[j + 1]
            else:
                culculate += S[j + 1]
        ans += eval(culculate)
        debug_key(culculate)
    print(ans)


if __name__ == '__main__':

    S_input = input()

    solve(S_input)

Submission status: Accepted

Solution code:
N = str(input())

score = 0
for i in range(2**(len(N)-1)):
    Ni = '0' * (len(N)-len(format(i, 'b'))-1) + format(i, 'b') + '0'
    l = list()
    buff = str()
    for n, ni in zip(N, Ni):
        buff += n
        if ni == '1':
            l.append(int(buff))
            buff = str()

    l.append(int(buff))
    score += sum(l)

print(score)

Submission status: Accepted

Solution code:
s = input()
l = len(s)

ans = 0

for mask in range(2 ** (l-1)):
    f = s
    last_plus = 0
    for bit in range(l-1):
        if (mask >> bit) & 1:
            ans += int(s[last_plus: bit+1])
            last_plus = bit + 1

    ans += int(s[last_plus:])

print(ans)

Submission status: Accepted

Solution code:
s = str(input())

ans = 0
for i in range(2 ** (len(s)-1)):
    plus_l = []
    cal_l = []
    for j in range(len(s)):
        bit = 2 ** j
        if i & bit > 0:
            plus_l.append(j)
    if len(plus_l) == 0:
        cal_l = [int(s)]
    else:
        pre = 0
        for k in plus_l:
            cal_l.append(int(s[pre:k+1]))
            pre = k+1
        cal_l.append(int(s[pre:]))
    ans += sum(cal_l)

print(ans)

Submission status: Accepted

Solution code:
S = input()
len_ = len(S) - 1

sum_ = 0
for i in range(2 ** len_):
    formula = ''
    for j, s in enumerate(S):
        formula += s
        if i & 2**j:
            formula += '+'
    sum_ += eval(formula)

print(sum_)

Submission status: Accepted

Solution code:
s = list(input())

def sum_list(S,stock):
    if len(S) == 2:
        return int(S[0]) + int(S[1]) + int(S[0]+S[1]) + stock * 2
    elif len(S) == 1:
        return int(S[0])
    else:
        return sum_list(S[1:],int(S[0])+stock) + sum_list([S[0]+S[1]]+S[2:],stock)
                                                 
print(sum_list(s,0))

Submission status: Accepted

Solution code:
L = list(raw_input())
total = 0
for bit in range(2**(len(L) - 1)):
    P = [""] * (len(L))
    for k in range(len(L) - 1):
        if bit & (1 << k):
            P[k] = ""
        else:
            P[k] = "+"
    calc = ""
    for i in range(len(L)):
        calc += L[i] + P[i]
    calc = eval(calc)
    total += calc
print(total)

Submission status: Accepted

Solution code:
string = input()
text = []
for s in string:
    text.append(s)
    text.append('')

count = 0

for i in range(2**(len(string)-1)):
    for j in range(len(string)-1):
        if (i >> j) & 1:
            text[2*j+1] = '+'
        else:
            text[2*j+1] = ''

    formula = ''.join(text)
    count += eval(formula)

print(count)

Submission status: Accepted

Solution code:
L = list(input())
ans = 0
for bit in range(1 << (len(L)-1)) :
    P = [""]*len(L)
    for k in range(len(L)-1) :
        if bit & (1 << k) :
            P[k] = "+"
    calc = ""
    for i in range(len(L)) :
        calc += L[i] + P[i]
    ans += eval(calc)
print(ans)

Submission status: Accepted

Solution code:
####### 再起関数
def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split("+"))))

    # 式 f の末尾に "+" を追加するかしないかして次の数字を追加
    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]))

Submission status: Accepted

Solution code:
from itertools import combinations
S = input()
zenbu = list(range(len(S)+1))
soto = (zenbu[0], zenbu[-1])
naka = zenbu[1:-1]
kumi = []
for i in range(len(naka)+1):
    comb = list(combinations(naka, i))
    for c in comb:
        kumi.append(sorted(c + soto))

total_list = []
for k in kumi:
    total_list.append(sum([int(S[k[i]:k[i+1]]) for i in range(len(k)-1)]))
print(sum(total_list))

Submission status: Accepted

Solution code:
s = input()

def dfs(p, n):
    if n == 0:
        return eval(p)
    else:
        return dfs(p[:n] + "+" + p[n:], n-1) + dfs(p, n-1)

print(dfs(s, len(s)-1))

Submission status: Accepted

Solution code:
S = input()
len_s = len(S)-1
count = 0
ss = []
for i in range(2**len_s):
  binary = format(i, 'b').zfill(len_s+2)[2:]
  tmp=[S[0]]
  for j in range(len(binary)):
    if binary[j] =='1':
      tmp.append(S[j+1])
    else:
      tmp[-1] = tmp[-1]+S[j+1]
  count += sum(int(i) for i in tmp)
print(count)

Submission status: Accepted

Solution code:
s = input()

def plus(p,n):
	if n==0:
		return eval(p)
	else:
		# nはsを上位の桁から数えて箇所に+を入れるか入れないか場合分けをしている
		return plus(p[:n] + '+' + p[n:], n-1) + plus(p,n-1)
  
print(plus(s,len(s)-1))

Submission status: Accepted

Solution code:
S = input()
length = len(S)


def dfs(summary, array, i):
    if i == length:
        return 0
    elif i == length -  1:
        return sum([int(x) for x in array.split("+")])
    array_plus = array[:-(length-i-1)] + "+" + array[-(length-i-1):]
    summary = 0
    summary += dfs(summary, array ,i+1)
    summary += dfs(summary, array_plus ,i+1)
    return summary



if length == 1:
    print(S)
else:
    print(dfs(0, S, 0))

Submission status: Accepted

Solution code:
S = input()
#llen(S)-1までの長さのバイナリを入れる、0をそのまま、１を＋とみなす。
#再帰関数にして、引数に前のls-1を入れればいい
def sumall(ls = 0):
    bls = bin(ls)
    if len(S) <= len(bls)-2:
        return 0
    else:
        count = 0
        pi = 0
        for ib,b in enumerate(bls[::-1]):
            if b == 'b':
                count += int(S[pi:])
                break
            elif b == '1':
                count += int(S[pi:ib+1])
                pi = ib+1
        #print(count)
        return count + sumall(ls+1)
if len(S) == 1:
    print(int(S))
else:
    print(sumall(0))

Submission status: Accepted

Solution code:
S = input()

ans = 0
for i in range(2 ** (len(S) - 1)):
    formula = ''
    flag = bin(i)[2:].zfill(len(S) - 1)
    for j, x in enumerate(flag):
        formula += S[j]
        if x == '1':
            formula += '+'
    if len(S) > 1:
        formula += S[-1]
    ans += eval(formula)

print(ans)

Submission status: Accepted

Solution code:
s = input()
len_s = len(s)
s = '+'.join(s)
#print(s)

ans = 0
for i in range(2**(len_s-1)):
    tmp_s = list(s)
    for j in range(len_s-1):
        if ((i>>j)&1):
            tmp_s[2*j+1] = ''
    tmp_s = ''.join(tmp_s)
    #print(tmp_s)
    ans += eval(tmp_s)
    #print(ans)

print(ans)

Submission status: Accepted

Solution code:
S = list(input())

import copy
cnt = 0
for i in range(2 ** (len(S)-1)):
    op = []
    for j in range((len(S)-1)):
        if ((i >> j) & 1):
            op.append(j)

    S_copy = copy.deepcopy(S)
    for idx, k in enumerate(op):
        S_copy.insert(k+1+idx, '+')
    cnt += eval(''.join(S_copy))

print(cnt)

Submission status: Accepted

Solution code:
s = input()
N = len(s)
ans = 0
temp = 0
for i in range(2**(N-1)):
	temp = [s[0]]
	for n in range(N-1):
		if (i >> n) & 1:
			ans += int("".join(temp))
			temp = [s[n+1]]
		else:
			temp.append(s[n+1])
	ans += int("".join(temp))
print(ans)

Submission status: Accepted

Solution code:
s = input()

def plus(p,n):
  if n==0:
    return eval(p)
  else:
    return plus(p[:n] + '+' + p[n:], n-1) + plus(p,n-1)
  
print(plus(s,len(s)-1))

Submission status: Accepted

Solution code:
s = input()


def insert_string(target_string, insert_point, ins_string):
    return target_string[:insert_point] + ins_string + target_string[insert_point:]


sum = 0

for i in range(2**(len(s)-1)):
    insert_count = 0
    temp_s = s
    for j in range(len(s)-1):
        if (i >> j) & 1: # 1 = +
            temp_s = insert_string(temp_s, j+1+insert_count, '+')
            insert_count += 1

    sum += eval(temp_s)

print(sum)

Submission status: Accepted

Solution code:
S = str(input())
l = S.__len__()
ans = 0
for i in range(1 << (l-1)):
    p = []
    for j in range(l-1):
        if (i >> j) & 1 == 1:
            p.append(j)
    t = 0
    num = S[0]
    while(t < l-1):
        if t in p:
            ans += int(''.join(num))
            num = S[t+1]
        else:
            num += S[t+1]
        t += 1
    else:
        ans += int(''.join(num))

print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
N = len(S)
for i in range(2**(N-1)):
  b = bin(i)[2:]
  T = S
  while len(b)<N-1:
    b = '0'+b
  b = b[::-1]
  ind = [0]
  count= 1
  for j in range(N-1):
    if b[j]=='1':
      ind +=[count]
      count = 1
    else:
      count +=1
  ind = ind[1:]
  for h in ind:
    ans += int(T[:h])
    T = T[h:]
  ans += int(T)
  
print(ans)

Submission status: Accepted

Solution code:
s = list(input())

ans = 0
for i in range(2 ** (len(s) - 1)):
    s_copy = s[:]
    for j in reversed(range(len(s))):
        if (i >> j) & 1:
            s_copy.insert(j + 1, '+')
    cut = ''.join(s_copy).split('+')

    for j in cut:
        ans += int(j)

print(ans)

Submission status: Accepted

Solution code:
s = input()
# + が入る場所の数
num = len(s) - 1
# 合計値
total = 0
# 2のn乗数通りとなる(+を入れる or 入れない)
for i in range(2 ** num):
    # +を入れた式を作成
    formula = s[0]
    for j in range(num):
        # +を入れる場合
        if (i >> j) & 1:
            formula += "+"
        formula += s[j + 1]
    # 式を評価
    total += eval(formula)
print(total)

Submission status: Accepted

Solution code:
def alllist(n,stre):
    if n == 0:
        return [[stre]]
    else:
        oldlist = alllist(n-1,stre)
        newlist = oldlist[:]
        for elements in oldlist:
            new1 = elements[:]
            temp1 = new1[0][:(len(stre) - n)]
            temp2 = new1[0][(len(stre) - n):]
            new1 = new1[1:]
            new1.insert(0,temp1)
            new1.insert(1,temp2)
            newlist.append(new1)
        return newlist

s=input()

lista=alllist(len(s)-1,s)
aaaaa=0

for elemens in lista:
    for i in elemens:
        listb=[]
        listb.append(int(i))
        aaaaa += sum(listb)

print(aaaaa)

Submission status: Accepted

Solution code:
S = input()
p = ["+", ""]

count = 0
for i in range(2 ** (len(S) - 1)):
    t = S[0]
    for j in range(len(S) - 1):
        t += p[i >> j & 1] + S[j + 1]
    #print(t)
    count += eval(t)
print(count)

Submission status: Accepted

Solution code:
S = input()
p = ["+", ""]

count = 0
for i in range(2**(len(S)-1)):
  t = S[0]
  for j in range(len(S)-1):
    t += p[i>>j&1] + S[j+1]
  count += eval(t)
print(count)

Submission status: Accepted

Solution code:
S = input()
n = len(S)-1
ans = 0

for i in range(1 << n):
    op = [""] * n
    for j in range(n):
        if i & (1 << j):
            op[j] = "+"
    f = "".join([S[i//2] if i % 2 == 0 else op[i//2] for i in range(2*(n+1)-1)])
    ans += eval(f)
print(ans)

Submission status: Accepted

Solution code:
S = input()
length = len(S) - 1
sum = 0
for i in range(2**length):
	plus = [0]
	for j in range(length):
		if ((2**j) & i) // (2**j) == 1:
			plus.append(j + 1)
	plus.append(length + 1)
	for j in range(len(plus) - 1):
		sum += int(S[plus[j]:plus[j+1]])
print(sum)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S=input()  
ans=0
num=0

def count(S,binnumber,i):
    if i==1:
        if binnumber[0]=="1":
            return int(S[0])+int(S[1:])
        return int(S)
    elif binnumber[i-1]=="1":
            return int(S[i:])+count(S[:i],binnumber,i-1)
    return count(S,binnumber,i-1)

for i in range(len(S)-1):
    num=num+2**i

for i in range(num+1): 
    binnumber=str(format(i,"b").zfill(len(S)-1))
    j=len(binnumber)
    ans=ans+count(S,binnumber,j)
    
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)

# Override `input` function because `stdin.readline()` is 10x faster than built-in `input()`
input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    S, = read_h(typ=str)
    n = len(S) - 1

    total = 0
    for i in range(2**n):
        prev = 0
        for j in range(n):
            #  print(i, j)
            if ((i >> j) & 1):
                #  print(i, j)
                m = int(S[prev:j + 1])
                #  print(m)
                total += m
                prev = j + 1

        m = int(S[prev:])
        #  print(m)
        total += m

    print(total)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def clc(a, b, c, p, t):
    if c == 0:
        b = a[0]
        return clc(a, b, c + 1, True, t) + clc(a, b, c + 1, False, t)
    elif c == len(a)-1:
        if p:
            return t + int(b) + int(a[c])
        else:
            return t + int(b + a[c])
    else:
        if p:
            t += int(b)
            b = a[c]
        else:
            b += a[c]
        return clc(a, b, c + 1, True, t) + clc(a, b, c + 1, False, t)


s = input()
print(clc(s, "", 0, True, 0) if len(s) != 1 else s)

Submission status: Accepted

Solution code:
s = input()
n = len(s)-1
ss = s
sum = 0
for x in range(2**n):
    s = list(s)
    j = 0
    for i in range(n):
        if (x>>i)&1:
            s.insert(i+j+1,"+")
            j += 1

    s = "".join(s)
    sum += eval(s)
    s = ss



print(sum)

Submission status: Accepted

Solution code:
S = input()
n = len(S)
sum = 0
for i in range(2**(n-1)):
    B = [""] * (n-1)
    f = ""
    for j in range(n-1):
        if((i>>j)&1):
            B[j] = "+"
            
    for a,b in zip(S, B+[""]):
        
        f += a
        f += b
        
    sum += eval(f)

print(sum)

Submission status: Accepted

Solution code:
S=input()

n=len(S)-1
total=0
for i in range(2**n):
    SS=S[0]
    x=format(i,'0'+str(n)+'b')
    #print('x',x)
    for j in range(n):
        if x[j]=='1':
            SS+="+"
        SS+=S[j+1]
        #print("SS",SS)
    total+=eval(SS)
print(total)

Submission status: Accepted

Solution code:
S = input()
len_s = len(S)
a = [int(S[i]) for i in range(len(S))]
sum_list = []

def f(pos, one_sum, block):
    if pos == len_s - 1:
        one_sum += block
        sum_list.append(one_sum)

    else:
        f(pos+1, one_sum + block, a[pos+1])
        f(pos+1, one_sum, 10*block+a[pos+1])

f(0,0,a[0])
print(sum(sum_list))

Submission status: Accepted

Solution code:
S = str(input())

ans = ""

for mask in range(1 << (len(S)-1)):
    for i in range(len(S)):
        if ((mask >> i) & 1):
            ans += str(S[i]) + "+"
        else:
            ans += str(S[i])
    ans += "+"

print(int(eval(ans[:-1])))

Submission status: Accepted

Solution code:
S = input()
def partial_sum(pseq):
    #import pdb
    #pdb.set_trace()
    if len(pseq) > 0:
        return int(pseq) + sum(int(pseq[:i])*(2**(len(pseq)-i-1)) +  partial_sum(pseq[i:]) for i in range(1, len(pseq)))
    else:
        return 0
print(partial_sum(S))

Submission status: Accepted

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

ans = 0
if n == 0:
    ans = int(s)
else:
    for i in range(2 ** n):
        calc = [0 for i in range(n)]
        for j in range(n):
            if ((i >> j) & 1):
                calc[- 1 - j] = 1
        str_num = s[0]
        for k in range(n):
            if calc[k] == 0:
                str_num += s[k+1]
            elif calc[k] == 1:
                ans += int(str_num)
                str_num = s[k+1]
            if k == n-1:
                ans += int(str_num)

print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/arc061/tasks/arc061_a
def solve(S):
    a = _iter(S, '')
    return a


def _iter(s, t):
    if s == '':
        if t.endswith('+'):
            return 0
        return eval(t)
    a = s[0]
    b = s[1:]
    return _iter(b, t+a) + _iter(b, t+a+'+')


if __name__ == '__main__':
    S = input()
    print(solve(S))

Submission status: Accepted

Solution code:
S = input()

def calc(n):
    P = [(n >> i) % 2 for i in range(len(S)-1)]
    tmp = ""
    for i, s in enumerate(S):
        tmp += s
        if i < len(S)-1 and P[i] == 1:
            tmp += "+"
    return eval(tmp)

ans = 0
for i in range(2 ** (len(S)-1)):
    ans += calc(i)
print(ans)

Submission status: Accepted

Solution code:
import itertools

s = input().split()[0]

start_index = 0

sum_list = []

# 0のとき
sum_list.append(int(s))

# 0以外のとき
for spliter_n in range(1, len(s)):
	# print('spliter_n: {}'.format(spliter_n))

	comb_list = list(itertools.combinations(list(range(0, len(s)-1)), spliter_n))
	# print('comb_list: {}'.format(comb_list))
	
	for comb_set in comb_list:
		s_copy = s
		number_list = []
		comb_set_list = list(comb_set)
		comb_set_list = [-1] + comb_set_list
		# print('comb_set_list: {}'.format(comb_set_list))

		for i, a in enumerate(comb_set_list):

			if a == comb_set_list[-1]:
				# 最後の要素だったら
				s_i = comb_set_list[i]+1
				number_list.append(s[s_i:])
				
			else:
				# 最後の要素じゃなかったら
				s_i, e_i = comb_set_list[i]+1, comb_set_list[i+1]+1
				number_list.append(s[s_i:e_i])

		debug_text = (' + ').join(number_list)
		# print('debug_text = {}'.format(debug_text))

		number_list = [int(x) for x in number_list]
		# print(number_list)
		sum_list.append(sum(number_list))
	# print('------------')

# print(sum_list)
answer = sum(sum_list)
print(answer)

Submission status: Accepted

Solution code:
S = list(input())
N = len(S) - 1
res = 0
for bits in range(0,2**N):
    pos = [0] * N
    for i in range(N):
        if bits & (1<<i):
            pos[i] = 1
    acc = 0
    for i in range(N):
        acc += pos[i]
        if pos[i] == 1:
            pos[i] = acc
    s = list(S)
    for i in range(N):
        if pos[i] > 0:
            p = pos[i] + i
            s.insert(p, '+')

    expr = "".join(s)
    res += eval(expr)

print(res)

Submission status: Accepted

Solution code:
s = input()

def calc_str(st):
  lst = st.split('+')
  lst = map(int, lst)
  return sum(lst)
  
prev = []
for c in s:
  if prev != []:
    new_prev = []
    for elem in prev:
      new_prev.append(elem + c)
      new_prev.append(elem + "+" + c)
    prev = new_prev
  else:
    prev.append(c)

sums = 0
for elem in prev:
  sums += calc_str(elem)
print(sums)

Submission status: Accepted

Solution code:
s = input()
len_s = len(s)
a = [int(s[i]) for i in range(len_s)]
sum_list = []


def f(pos,one_sum,block):
    if pos == len_s - 1:
        one_sum += block
        sum_list.append(one_sum)
    else:
        f(pos+1,one_sum+block,a[pos+1])
        f(pos+1,one_sum,10*block+a[pos+1])
    

f(0,0,a[0])
print(sum(sum_list))

Submission status: Accepted

Solution code:
s = input()
n = len(s) - 1
ans = 0
for i in range(2 ** n):
    index = []
    for j in range(n):
        if ((i>>j)&1):
            index.append(j)
    lis = []
    zero = 0
    for k in range(len(index)):
        lis.append(int(s[zero:index[k]+1]))
        zero = index[k] + 1
    lis.append(int(s[zero:]))
    ans += sum(lis)
print(ans)

Submission status: Accepted

Solution code:
s = input()
len = len(s)
ns = list(map(int,s))
total_sum = 0
for bit in range(1 << (len-1)):
  ##print(bit)
  sum_ = 0
  num = ns[0]
  for i in range(1, len):
    if (bit & 1) > 0:
     
      sum_ += num
      num = ns[i]
    else:
      num = (num * 10 + ns[i])
    bit = bit >> 1
  total_sum += sum_ + num
print(total_sum)

Submission status: Accepted

Solution code:
s = [int(x) for x in input()]
##print(s)
count = len(s)-1##+の入りうるポジション数
sum = 0
for bit in range(2**count):
    hugou = [""] * count
    ##print(bin(bit))
    for i in range(count):
        if (bit >> i) & 1:
            hugou[count-1-i] = "+"
            ##print(hugou)
    calc = ""
   
    for j in range(count):
        calc += str(s[j])
        ##print(s)
        calc += str(hugou[j])
        ##print(hugou)
        ##print(calc)
    calc += str(s[-1])
    ##print(calc)
    sum += eval(calc)
print(sum)

Submission status: Accepted

Solution code:
def f(a, b, le, tf):
    b[le] = tf
    if le == len(b)-1:
        t = ""
        s1 = 0
        for i in range(len(b)):
            t += a[i]
            if b[i] == 1:
                s1 += int(t)
                t = ""
        t += a[len(b)]
        s1 += int(t)
        return s1
    else:
        return f(a, b, le+1, 0) + f(a, b, le+1, 1)


aa = input()
bb = [0] * (len(aa)-1)
if len(aa) == 1:
    print(aa)
else:
    print(f(aa, bb, 0, 0) + f(aa, bb, 0, 1))

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)-1
total=0
for i in range(2**n):
  bitl = list(bin(i)[2:].zfill(len(s)-1))
  tmp=''
  for j in range(len(s)-1):
    bitl[j] = bitl[j].replace('1','+').replace('0','')
    tmp+=s[j]+bitl[j]
  tmp+=s[len(s)-1]
  total+=eval(tmp)
print(total)

Submission status: Accepted

Solution code:
import itertools
s = list(input())
bit=['','+']
total=0
for i in itertools.product(bit, repeat=len(s)-1):
  siki=s[0]
  k=0
  for j in s[1:]:
    siki+=i[k]+j
    k+=1
  total+=eval(siki)
print(total)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
import math
mod = 10**9 + 7
def I(): return int(input())
def II(): return map(int, input().split())
def L(): return list(map(int, input().split()))
def TWO(M):
  L=[0]*M
  R=[0]*M
  for i in range(M):
    L[i],R[i] = II()
  return L, R

from itertools import product
S = I()
mark = list(product(['','+'],repeat=len(str(S))-1))
ans = 0
for a in mark:
  form = ''
  for i in range(len(str(S))*2-1):
    if i%2==0:
      form += str(S)[i//2]
    else:
      form += a[i//2]
  ans += eval(form)
print(ans)

Submission status: Accepted

Solution code:
s = input()

op_n = len(s) - 1

ans = 0

for i in range(1 << op_n):
  sign = [""] * op_n
  for j in range(op_n):
    if ((i>>j)&1):
      sign[j] = "+"
  formula = ""
  for k in range(op_n):
    formula += s[k] + sign[k]
  formula += s[op_n] 
  ans += eval(formula)
print(ans)

Submission status: Accepted

Solution code:
s=input()
l=2**(len(s)-1)
count=0
for i in range(l):
    n=0
    buf=0
    while(i):
        if i & 1 ==1:
            count+=int(s[buf:n+1])
            buf=n+1
        n+=1
        i=i>>1
    count+=int(s[buf:])
print(count)

Submission status: Accepted

Solution code:
from itertools import product

S = input()
ans = 0
for symbol in product(['+', ''], repeat=len(S) - 1):
    string = ''
    for i in range(len(S) - 1):
        string += S[i] + symbol[i]
    ans += eval(string + S[-1])

print(ans)

Submission status: Accepted

Solution code:
S = input()
S_list = list(S)
n = len(S) 
a = []

list_0or1 = [0] * (n-1)
check = []

def f(i):
    if i == n-1 :
        check.append(list_0or1.copy())
    if i != n-1:
        list_0or1[i] = 0
        f(i+1)
    if i != n-1:
        list_0or1[i] = 1
        f(i+1)
f(0)

sum_list = []
for i in range(len(check)):
    S_list_copy = S_list.copy()
    for j in range(n-1) :
        if check[i][j] == 1 :
            S_list_copy[j+1] = '+' + S_list_copy[j+1]
    S_list_copy = ''.join(S_list_copy)
    S_list_copy = list(map(int,S_list_copy.split('+')))
    s = sum(S_list_copy)
    sum_list.append(s)
print(sum(sum_list))

Submission status: Accepted

Solution code:
input_num = str(input())

def calc_adding(left_str, skip_cnt, const):
  # 1桁まで来たら、+ を挟めない
  if len(left_str) <= 1 + skip_cnt:
    return int(left_str) + const

  # + の有無で分岐を増やす
  # + を入れない場合
  res_np = calc_adding(left_str, skip_cnt + 1, const)

  # + 入れる場合
  const += int(left_str[:1 + skip_cnt])
  res_p = calc_adding(left_str[1 + skip_cnt:], 0, const)

  return res_np + res_p

res = calc_adding(input_num, 0, 0)
print(res)