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 = list(input())
l = len(s) - 1

def calcBit(num):
    res = []
    for _ in range(l):
        res.append(num%2)
        num >>= 1
    return res[::-1]

res = 0
for i in range(2**l):
    b = calcBit(i)
    f = ''
    for j in range(l):
        f += s[j] + b[j]*'+'
    f += s[-1]
    res += eval(f)

print(res)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = 0
for b in range(1 << (n - 1)):
  sm = 0
  a = int(s[0])
  for i in range(n - 1):
    if b & (1 << i) != 0:
      sm += a
      a = 0
    a = a * 10 + int(s[i + 1])
  ans += (sm + a)
print(ans)

Submission status: Accepted

Solution code:
S=input()
ans=0
listS=[]
for i in range(len(S)):
    listS.append(int(S[i]))
#print(listS)

for j in range(2**(len(listS)-1)):
    l=j
    list1=[]
    for k in range(len(listS)-1):
        if int(l/(2**(len(listS)-2-k)))==0:
            list1.append("")
        else:
            list1.append("+")
        l=l%(2**(len(listS)-2-k))
    #print(list1)
    SUB=str(listS[0])
    for m in range(len(list1)):
        SUB=SUB+list1[m]+str(listS[m+1])
    #print(eval(SUB))
    ans+=eval(SUB)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import product
S = [int(x) for x in list(input())]
N = len(S)
ans = 0
c = S[0]
for x in product(range(2), repeat = N-1):
    for i in range(1,N):
        if x[i-1] == 0:
            c = c*10 + S[i]
        else:
            ans += c
            c = S[i]
    ans += c
    c = S[0]
print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
for i in range (1<<(len(S)-1)):
	st = S[0]
	for j in range(len(S)-1):
		if i & (1<<j):
			st = st + '+' + S[j+1]
		else:
			st = st + S[j+1]
	ans = ans + eval(st)
	
print(ans)

Submission status: Accepted

Solution code:
s = input()


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

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


print(solve(s[:-1], s[-1]))

Submission status: Accepted

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

b = []
for i in range(2**(a-1)):
    c = []
    for j in range(a-1):
        if i|(2**j) == i:
            c.append(1)
        else:
            c.append(0)
    b.append(c)
ans = 0
for i in b:
    count = 0
    ss = s[:]
    for j in range(a-1):
        if i[j] == 1:
            ss = ss[:j+1+count]+'+'+ss[j+1+count:]
            count += 1
    ans += eval(ss)
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Task: https://arc061.contest.atcoder.jp/tasks/arc061_a#

def calc(num):
    backup = num
    ans = 0
    bit = 0b0
    
    while not(0b1 & (bit >> len(num)-1)):
        bit += 0b1
        # print(bin(bit))
        count = 0
        for i in range(len(num)-1):
            if 0b1 & (bit >> i):
                num = num[:len(num)-i-count-1] + "," + num[len(num)-i-count-1:]
                count += 1
        # print(num)
        li = num.split(',')
        for n in li:
            ans += int(n)
        num = backup
    return ans

num_input = input()

if len(num_input) == 1:
    print(num_input)
else:
    ans = calc(num_input)
    print(ans)

Submission status: Accepted

Solution code:
N=int(input())
m=list(map(int,str(N)))[::-1]
p=0
n=len(str(N))
if n==1:
    print(N)
    exit()
for i in range(2**(n-1)):
    s=(["0"]*8+list(bin(i)[2:]))[::-1]
    s=s[:n-1]
    p+=m[0]
    q=0
    for i in range(n-1):
        if s[i]=="0":
            q+=1
            p+=(10**q)*(m[i+1])
        else:
            q=0
            p+=m[i+1]
print(p)

Submission status: Accepted

Solution code:
s = input()

length = len(s) - 1
max = 2 ** length

ans = 0
for i in range(max):
    b = bin(i)[2:].zfill(length) + '1'
    index_s = 0
    l = []
    for j, flag in enumerate(b):
        if flag == '1':
            l.append(int(s[index_s:j+1]))
            index_s = j + 1
    
    ans += sum(l)

print(ans)

Submission status: Accepted

Solution code:
import math
s = list(map(int, input()))

sumofsum = 0

N = len(s)
def combin(n, k):
    com = math.factrial(n) * math.factrial(n - k) / math.factrial(k)
    return con

for i in range(N):
    for j in range(N - i):
        if j == 0:
            if i == 0:
                sumofsum += (10 ** (N - i - j - 1)) * s[i]
            else:
                sumofsum += (10 ** (N - i - j - 1) )* (2 ** (i))* s[i]
        else:
            if i == 0:
                sumofsum += (10 ** (N - i - j - 1)) * (2 ** (j - 1)) * s[i]
            else:
                sumofsum +=( 10 ** (N - i - j - 1)) * (2 ** (i))* (2 ** (j - 1)) * s[i]


print(sumofsum)

Submission status: Accepted

Solution code:
def calculate_num(index, number, _length, _ways):
    way_list = []
    __ways = _ways

    for i in range(_length - index):
        __ways = __ways/2
        way_list.append(int(__ways))
    way_list[-1] *= 2
    if way_list[-1] == 0:
        way_list[-1] = 1

    result = 0

    for i, way in enumerate(way_list):
        result += number * pow(10, i) * way

    return result


if __name__ == '__main__':
    num = input()
    num_list = [int(i) for i in str(num)]
    length = len(num_list)
    ways = pow(2, length - 1)
    sum_result = 0

    for num, value in enumerate(num_list):
        sum_result += calculate_num(num, value, length, ways)

    print(sum_result)
'''
    "1:1"
    "1:1:2"
    "1:1:2:4 2:2:4 4:4 8"
    "1:1:2:4:8"
    "12345"
'''

Submission status: Accepted

Solution code:
def main():
	s = input()
	ans = solve(s[0], s[1:])
	print(ans)

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

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
s=input()
ans=0
def slove(left,right):
    if len(right)==0:
        return eval(left)
    return slove(left+right[0],right[1:])+slove(left+'+'+right[0],right[1:])
ans=slove(s[0],s[1:])
print(ans)

Submission status: Accepted

Solution code:
S = input()
formula_list = []
total_sum = 0

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

def stackformula(s, i) :
    
    if len(s) == 1 :
        formula_list.append(s)
        return 
    
    if i >= len(s) :
        return 
    
    formula_y = s[:i] + "+" + s[i:]
    formula_n = s
    
    formula_list.append(formula_y)
    stackformula(formula_y, i + 2)
        
    formula_list.append(formula_n)
    stackformula(formula_n, i + 1)


stackformula(S, 1)
# calculate sum for each formula
for f in set(formula_list) :
    total_sum += calcformula(f)

print(total_sum)

Submission status: Accepted

Solution code:
# coding: utf-8
s='+'.join(list(input()))
ans=0
memo=set()
def check(w,n):
    global ans
    if w in memo:
        return
    memo.add(w)
    ans+=eval(w)
    for i in range(1,n+1):
        count=0
        for j in range(len(w)):
            if w[j]=='+':
                count+=1
                if count==i:
                    check(w[:j]+w[j+1:],n-1)

check(s,(len(s)-1)//2)
print(ans)

Submission status: Accepted

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

from itertools import product

def calc(s, p):
    assert len(s) == len(p) + 1
    s2 = ""
    for i, c in enumerate(s):
        if i > 0 and p[i - 1]:
            s2 += "+"
        s2 += c
    return eval(s2)

def main():
    s = input()
    n = len(s)
    tf = [True, False]
    ip = list(product(*[tf for i in range(n - 1)]))
    res = 0
    for p in ip:
        res += calc(s, p)
    print(res)

main()

Submission status: Accepted

Solution code:
s = raw_input()
z = 0
for i in range(len(s)):
	t = 0
	for j in range(len(s) - i):
		t = t * 10 + [1, 2 ** (j - 1)][j > 0]
	z += int(s[i]) * 2 ** i * t
print z

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import product

s = input()
s2 = '{}'.join(s)

betweenss = product(('', '+'), repeat=len(s)-1)
print(sum(eval(s2.format(*betweens)) for betweens in betweenss))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
res = 0
for i in range(2**(n-1)):
    k = 0
    b = bin(i)[2:]
    for j in range(len(b)):
        if b[-(j+1)] == '1':
            res += int(s[k:j+1])
            k = j+1
    res += int(s[k:])

            
print(res)

Submission status: Accepted

Solution code:
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	"""
	ビットマスクを用いた解法
	"""
	s = input()
	ans = 0
	for b in range(1 << len(s) - 1):
		x = ""
		for index, num in enumerate(s):
			x += num
			if index != len(s) - 1 and b >> index & 1: x += "+"
		ans += eval(x)
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	"""
	ビットマスクを用いた解法
	"""
	src = list(input())
	sum = 0
	for i in range(2 ** (len(src) - 1)):
		p = bin(i)[2:] # 2進数の数値部分だけを取り出す
		#print(p)
		p = "0" * (len(src) - 1 - len(p)) + p # (srcの長さ - 1)の桁数だけ右から0埋め
		#print(p)
		x = ""
		for index, num in enumerate(src):
			x += num
			if index != (len(src) - 1) and p[index] == "1":
				x += "+"
		sum += eval(x)
	print(sum)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
from itertools import compress, product

s = input()
n = len(s)

indices = range(1, n)
index_maskss = product((0,1), repeat=n-1)
indicess = ([0]+list(compress(indices, masks))+[n] for masks in index_maskss)
ijss = (zip(indices, indices[1:]) for indices in indicess)
sums = (sum(int(s[i:j]) for i, j in ijs) for ijs in ijss)
 
print(sum(sums))

Submission status: Accepted

Solution code:
from itertools import compress, product
 
s = input()
n = len(s)

index_maskss = product((0,1), repeat=n-1)
indicess = ([0]+list(compress(range(1, n), masks))+[n] for masks in index_maskss)
ijss = (zip(indices, indices[1:]) for indices in indicess)
sums = (sum(int(s[i:j]) for i, j in ijs) for ijs in ijss)

print(sum(sums))

Submission status: Accepted

Solution code:
from itertools import compress, product

s = input()
n = len(s)

indicess = ([0]+list(compress(range(1, n), masks))+[n] for masks in product((0,1), repeat=n-1))
ijss = (zip(indices, indices[1:]) for indices in indicess)
sums = (sum(int(s[i:j]) for i, j in ijs) for ijs in ijss)
print(sum(sums))

Submission status: Accepted

Solution code:
from itertools import compress, product

s = input()
n = len(s)

total = 0
for index_masks in product((0,1), repeat=n-1):
  indices = [0] + list(compress(range(1, n), index_masks)) + [n]
  ijs = zip(indices, indices[1:])
  numbers = (int(s[i:j]) for i, j in ijs)
  total += sum(numbers)
print(total)

Submission status: Accepted

Solution code:
from itertools import count, product
s = input()
n = len(s)
split_indices = ([i*m for i, m in zip(count(1), ms) if m] for ms in product((0,1), repeat=n-1))
split_indices = ([0]+indices+[n] for indices in split_indices)
split_indices = (zip(indices, indices[1:]) for indices in split_indices)
split_indices = (map(lambda ix: int(s[ix[0]:ix[1]]), indices) for indices in split_indices)
print(sum(map(sum, split_indices)))

Submission status: Accepted

Solution code:
def F(S):
    if len(S) ==1:
        return S[0]
    else:
        S1 = [(10*S[0]+S[1])]+S[2:]
        S2 = S[1:]
        return F(S1)+F(S2)+S[0]*(2**(len(S)-2))

s = input()
x = [int(s[i]) for i in range(len(s))]
print(F(x))

Submission status: Accepted

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

bit=0

ans=0

for i in range(2**(N-1)):
    bit=bin(i)
    
    Z=[]
    sf=0
    for k in range(len(bit)-2):
        
        if bit[len(bit)-1-k] =="1":
            
            Z.append(S[sf:k+1])
            sf=k+1
    Z.append(S[sf:])
    
    for k in range(len(Z)):
        ans+=int(Z[k])
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = 0
 
for i in range(2**(n-1)):
    l = list(s)
    for j in reversed(range(1, n)): 
        if (1<<(j-1)) & i > 0:
            l = l[:j] + ['+'] + l[j:] # strにインサートはない
    ans += eval(''.join(l))
 
print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
for i in range(1 << (len(S)-1)):
    eq = S
    k = 0
    for j in range(len(S)-1):
        if i & (1 << j):
            eq = eq[:j+1+k] + "," + eq[j+1+k:]
            k +=1
        else:
            pass
    eq = eq.split(",")
    eq = list(map(int,eq))
    ans += sum(eq)
print(ans)

Submission status: Accepted

Solution code:
s = input()

n = len(s) - 1

c_list = [list(map(int,format(i,"b").zfill(n))) for i in range(2**n)]

ans = 0

for i in c_list:
    start = 0
    goal = 0
    for j, v in enumerate(i):
        if v == 1:
            goal = j + 1
            ans += int(s[start:goal])
            start = j +1
    else:
        ans += int(s[start:])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

def solve(s, i, bind, ans):
    if i == len(s) - 1:
        return ans + int(bind)
    return solve(s, i+1, s[i+1], int(bind) + ans) + solve(s, i+1, bind + s[i+1], ans)

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

Submission status: Accepted

Solution code:
def solve(s,i,bind,ans): 
	if i==len(s):
		return ans+int(bind)
	return solve(s,i+1,s[i],int(bind)+ans)+solve(s,i+1,bind+s[i],ans)

s = list(input())
print(solve(s,1,s[0],0))

Submission status: Accepted

Solution code:
S = input()
n_length = len(S)
result = 0
for i in range(2**(n_length-1)):
    a = bin(i)[2:].zfill(10)
    tmp = 0
    now = ''
    for n in range(len(S)):
        now = S[-n-1] + now
        if a[-n-1] == '1':
            tmp += int(now)
            now = ''
    tmp += int(now) 
    result += tmp
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = raw_input()
l = len(s)
ans = 0
for p in range(l):
    for q in range(p+1,l+1):
        ans += int(s[p:q]) * (2**max(p-1,0)) * (2**max(l-q-1,0))
print ans

Submission status: Accepted

Solution code:
S = input()

A = 0
for b in range(pow(2,len(S)-1)):
    ans = 0
    sub = int(S[0])
    for s in S[1:]:
        if b%2==1:
            ans += sub
            sub = int(s)
        else:
            sub *= 10
            sub += int(s)
        b //= 2
    ans += sub
    A += ans
    
print(A)

Submission status: Accepted

Solution code:
S = input()
R = 0
S = list(S)
temp = []
for i in range(2**(len(S)-1)):
    for m in range(len(S)-1):
        if i+1 & 2**(m) > 0:
            temp.append(S[m] + "+")
        else:
            temp.append(S[m])
    temp.append(S[len(S)-1])
    temp = "".join(temp)
    R += eval(temp)
    temp = []    
print(R)

Submission status: Accepted

Solution code:
S = list(input())

L = len(S)

plus = [False] * (L-1)

sum = 0

for n in range(1 << (L-1)):
    for i in range(L-1):
        if (n >> i) % 2:
            plus[i] = True
        else:
            plus[i] = False

    stack = []
    for i in range(L):
        stack.append(S[i])
        if i == L - 1:
            sum += int("".join(stack))
            stack = []
        elif plus[i]:
            sum += int("".join(stack))
            stack = []

print(sum)

Submission status: Accepted

Solution code:
S=input()
#Sに０は含まれない。
N=len(S)
#後続の処理でSを加算することはなく、事前に加算する。
ans=0

plus_place=[]
#S(i)の直後に”＋”を挿入する場合plus_place[i]はTrue

#桁数の関係でS=1のみ例外として処理
if int(S) == 1:
    print(1)
    exit()

for i in range(2**(N-1)):
    tmp_bin=bin(i)[2:]
    while(len(tmp_bin) < N-1):
        tmp_bin = '0' + tmp_bin
    plus_place.append(tmp_bin)
#plusが入りうる全てのパターンを網羅

for s in plus_place:
    tmp = 0
    next_index=0
    for i,b in enumerate(s) :
        #各sごとの計算用のリスト
        if b == "1":
            tmp += int(S[next_index:i+1])
            next_index=i+1
        if i == N-2:
            tmp += int(S[next_index:i+2])
#    print('add',tmp)
#  print('i is',i)
#  print('index is',next_index)
    ans += tmp
                      
    
print(ans)

Submission status: Accepted

Solution code:
s = str(input())#2bit全検索
ans = 0
n = len(s)-1
for i in range(1<<n):#0-2**(len(s)-1)まで
    tmp = int(s[0])
    for j in range(n):
        if i & (1<<j):
            ans += tmp
            tmp = int(s[j+1])
        else:
            tmp = 10*(tmp)+int(s[j+1])
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
s = input()
sum = 0
n = [i for i in s]
#print(n)
l = len(n)

for i in range(2 ** (l-1)):
    #注意!!実際の組み合わせの数をbitに直したら１つ数が落ちる。
    #組み合わせのループ
    s1 = []
    for j in range(l):
        #bitshift用のループ
        if 1  & i >> j:
            s1.append(n[j])
            s1.append('+')
        else:
            s1.append(n[j])
    s2 = ''
    for i in s1:
        s2 += i
    s2 = s2.split('+')
    sum1 = 0
    for c in s2:
        sum1 += int(c)
    #print(sum1, s1)
    sum += sum1

print(sum)

Submission status: Accepted

Solution code:
from itertools import product

S = input()

summation = 0
for indices in product((0, 1), repeat=len(S) - 1):
    current_S = S[:]

    num_list = []
    counter = 0
    for i in indices:
        if i == 0:
            counter += 1
            continue
        else:
            appended_num, current_S = int(current_S[:counter + 1]), current_S[counter + 1:]
            num_list.append(appended_num)
            counter = 0
    else:
        num_list.append(int(current_S))

    summation += sum(num_list)
print(summation)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

S = raw_input()
length = len(S)

def dfs(depth, S):

    if depth == length - 1:
        return eval(S)

    # 「+」を入れない場合
    sum1 = dfs(depth + 1, S)

    # 「+」を入れる場合
    sum2 = dfs(depth + 1, insert_plus(S, depth))

    return sum1 + sum2

def insert_plus(S, depth):
    d = depth + S.count("+") + 1
    return "{0}{1}{2}".format(S[:d],"+",S[d:])

print dfs(0,S)

Submission status: Accepted

Solution code:
s=input()
ret=0
# ループを各文字の間bit分回す
for i in range(1<<(len(s)-1)):
    t=list(s)
    # 実はiとjの向きについてあまり深く考える必要は無いです。どうせ全探索するので。
    for j in reversed(range(1, len(s))):
        if i&(1<<(j-1)):
            t=t[:j]+["+"]+t[j:]
    ret+=eval("".join(t))
print(ret)

Submission status: Accepted

Solution code:
s=input()
def solve(decided, left, idx):
    if idx==len(s):
        return decided+left
    # 手前に+を入れる
    ret1 = solve(decided+left,int(s[idx]),idx+1)
    # 入れない
    ret2 = solve(decided, left*10+int(s[idx]), idx+1)
    return ret1+ret2
# 最初の文字の左側には+は入れる必要が無いので1から
print(solve(0,int(s[0]),1))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!python
# -*- coding: utf-8 -*-

from itertools import product


def main():
    S = input()
    ANS = 0
    for c in product(('+', ''), repeat=len(S) - 1):
        shiki = S[0]
        for i in range(1, len(S)):
            shiki += c[i - 1] + S[i]
        ANS += eval(shiki)
    print(ANS)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def return_binary(n, s):
    t = bin(n)[2:]
    while s > len(t):
        t = '0' + t
    t = t + '1'
    return t


def add_up(n, b):
    temp = ''
    total = 0
    for x in range(len(n)):
        temp = temp + n[x]
        if b[x] == '1':
            total = total + int(temp)
            temp = ''
    return total


raw_input = input()
length = len(raw_input)
tot = 0

if length == 1:
    print(raw_input)
else:
    for i in range(2**(length-1)):
        binary = return_binary(i, length-1)
        tot = tot + add_up(raw_input, binary)
    print(tot)

Submission status: Accepted

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

total=0
for i in range(2**(L-1)):
    formula=S
    for b in range(L-1):
        if i&2**b!=0:
            formula=formula[:L-b-1]+'+'+formula[L-b-1:]
    ans=eval(formula)
    total+=ans
print(total)

Submission status: Accepted

Solution code:
import itertools

s=input()
l=len(s)

cand=("+"," ")

ans=0

for i in itertools.product(cand,repeat=l-1):
	siki=s[0]
	for j in range(len(i)):
		if i[j]=="+":
			siki=siki+i[j]+s[j+1]
		else:
			siki=siki+s[j+1]
	ans+=eval(siki)
  
print(ans)

Submission status: Accepted

Solution code:
def pt(s: list):
    if len(s) == 1:
        return eval(s[0])
    return pt([s[0]+s[1]]+s[2:]) + pt([s[0]+'+'+s[1]]+s[2:])
print(pt(list((input()))))

Submission status: Accepted

Solution code:
def plus_or_through(s):
    if len(s) <= 1:
        return eval(s[0])
    return plus_or_through([s[0]+s[1]]+s[2:]) + plus_or_through([s[0]+'+'+s[1]]+s[2:])
print(plus_or_through(list(input())))

Submission status: Accepted

Solution code:
def search(s):
    if len(s) <= 1:
        return eval(s[0])
    return search([s[0]+s[1]]+s[2:]) + search([s[0]+'+'+s[1]]+s[2:])
print(search(list(input())))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import product


S = input()
L = len(S)
Y = []

for X in product(['', '+'], repeat=len(S)-1):
    f = S[0]
    for x, s in zip(X, S[1:]):
        f += x + s
    Y.append(eval(f))

print(sum(Y))

Submission status: Accepted

Solution code:
s = str(input())
n = len(s) - 1
sum = ''
for i in range(1 << n):
    for j in range(len(s)):
        if i & 1 << j:
            sum += str(s[j])
        else:
            sum += str(s[j]) + '+'
sum = sum.rstrip('+')
print(eval(sum))

Submission status: Accepted

Solution code:
S = list(input())
ans = 0
for i in range(1<<(len(S)-1)):
    f = S[0]
    for j in range(len(S)-1):
        if i&(1<<j):
            f += '+'
        f += S[j+1]
    ans += eval(f)
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
from collections import deque

S = list(input())
P = ['', '+']

sumN = 0
for pp in product(P, repeat=len(S) -1):
    eq = ''
    SQ = deque(S)
    PQ = deque(list(pp))
    while SQ:
        eq += SQ.popleft()
        if PQ:
            eq += PQ.popleft()
    sumN += eval(eq)

print(sumN)

Submission status: Accepted

Solution code:
ans = 0
S = list(input())
po = 1

for i in range(2**(len(S)-1)):
    buf = ""
    oper = bin(po)[2:].zfill(len(S))
    for j in range(len(S)-1):
        buf += S[j]
        if oper[j] == "0":
            continue
        elif oper[j] == "1":
            buf += "+"
    buf += S[-1]
    ans += eval(buf)
    if oper[-1] == "0" and i :
        po += 2
    else:
        po += 1
    
print(ans)

Submission status: Accepted

Solution code:
s = input()
len = len(s)
bit_len = 1 << (len - 1)
ans = 0

for b in range(bit_len):
    num= ord(s[0]) - ord('0')
    for i in range(len - 1):
        if (1 << i) & b != 0:
            ans += num
            num = 0
        num = num* 10 + ord(s[i+1]) - ord('0')
    ans += num

print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    S = input()

    bit_num = 2 ** (len(S) - 1)

    ans = 0
    for i in range(bit_num):
        formula = S[0]
        for j in range(len(S) - 1):
            if i & 2 ** j:
                formula += "+"
            formula += S[j + 1]

        ans += eval(formula)

    print(ans)

Submission status: Accepted

Solution code:
S = input()
tmp = ['']*len(S)
sum = 0
for i in range(len(S)):
    tmp[i] = S[i]
if len(S) < 2:
    print(int(S))
else:
    for j in range(pow(2,len(S)-1)):
        work = format(j,'b').zfill(len(S)-1)
        storeNUM = tmp[0]
        for k in range(len(work)):
            if work[k] == '1':
                sum += int(storeNUM)
                storeNUM = str(tmp[k+1])
            else:
                storeNUM = storeNUM + str(tmp[k+1])
        sum += int(storeNUM)
    print(sum)

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
ans=0
for i in range(1<<(n-1)):

    """
    ここで既に、n-1個の文字間のうち、どこに+を入れるかが決まる。入れるところにはbit
    が立ち(その桁が1となる)、入れないところにはbitが立たない(その桁が0となる)
    """

    S=s[0]
    for j in range(n-1):
        if i & (1<<j): #bitが立っている時
            S+="+"+s[j+1]
        else: #bitが立っていない時
            S+=s[j+1]
    ans+=eval(S)
print(ans)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
ans=0
for i in range(1<<n-1):#+を入れるかどうか
    num=s[0]
    for j in range(n-1):#+を入れるかどうか
        if i&(1<<j):#bitで考える,iと1<<jが同じ数字であれば実行
            num+="+"+s[j+1]
        else:
            num+=s[j+1]
    ans+=eval(num)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
a = []
sbox = []

for i in s:
    a.append(int(i))

n = len(a)

def f(i, box, k):
    if i == n-1:
        box += k
        sbox.append(box)
    else:
        f(i + 1, box + k, a[i + 1])
        f(i + 1, box, 10 * k + a[i + 1])

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

Submission status: Accepted

Solution code:
import functools
numbers = list(input())

expressions = set()

def subSum(currentIdx, expr):
    global expressions
    
    if currentIdx == 0:
        expressions.add(convertToString(expr))
        return

    next_expr1 = expr[:]
    next_expr2 = expr[:]
    next_expr2.insert(currentIdx, '+')

    subSum(currentIdx-1, next_expr1)
    subSum(currentIdx-1, next_expr2)

def convertToString(expr):
    ex = str(functools.reduce(lambda t, x: t + x, expr))
    return ex

def culc(expr):
    return sum(list(map(int, expr.split('+'))))

subSum(len(numbers) - 1, numbers)



print(sum(list(map(culc, list(map(str, expressions))))))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from itertools import product
def inpl(): return list(map(int, input().split()))

res = 0
S = input()
for P in product(range(2), repeat=len(S)-1):
    r = 0
    t = S[0]
    for p, s in zip(P, S[1:]):
        if p:
            t += s
        else:
            r += int(t)
            t = s
    r += int(t)
    res += r
print(res)

Submission status: Accepted

Solution code:
s = raw_input()

ans = 0

def dfs(s, nw):
    global ans
    if s == '':
        ans += eval(nw)
        return
    if nw == '':
        dfs(s[1:], nw + s[0])
    else:
        dfs(s[1:], nw + s[0])
        dfs(s[1:], nw + '+' + s[0])

dfs(s, '')
print ans

Submission status: Accepted

Solution code:
import numpy as np

def many_fomulas(digits):
    mat = np.zeros((len(digits), len(digits)), 'i')

    for i, _ in enumerate(digits):
        if i >= 0:
            mat[i, :i] = 2 ** (i - 1)
        mat[i, i] = 2 ** i

    total = 0
    for i, _ in enumerate(digits):
        for j, v in enumerate(digits):
            total += 10 ** (len(digits) - i - 1) * int(mat[i, j]) * v

    print(total)

#many_fomulas([1, 2, 5])
#many_fomulas([9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
many_fomulas([int(d) for d in input()])

Submission status: Accepted

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

for i in range(1 << n-1):
    ins = S[0]
    for j in range(n-1):
        if i & (1 << j):
            ins += "+" + S[j+1]
        else:
            ins += S[j+1]

    ans += eval(ins)

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-



def main():
    S = input()
    L = len(S)

    ans = 0

    for i in range(2**(L-1)):
        nums = S[0]
        for j in range(1, L):
            if i & (1<<(j-1)):
                nums += " "
            nums += S[j]
        #print(nums)
        subtotal = sum(map(int, nums.split()))
        ans += subtotal

    print(ans)

if __name__ == "__main__": main()

Submission status: Accepted

Solution code:

def rec(s, start, d):
    if d == 0:
        return [s[start:]]

    cand = []
    for i in range(start + 1, len(s)):
        c = rec(s, i, d - 1)
        for cc in c:
            cand.append(s[start:i] + '+' + cc)
    return cand


s = input()
# s = '125'
# s = '9999999999'

N = len(s)
cnt = 0
for i in range(N):
    eqs = rec(s, 0, i)
    for eq in eqs:
        if len(eq.replace('+', "")) == N:
            cnt += eval(eq)
    # cnt += sum([eval(eq) for eq in eqs])
print(cnt)

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
ans = 0

for i in range(1 << (n-1)):#+を入れるかどうか
    fomula = s[0]
    for j in range(n-1):#+を入れるかどうか
        if i & (1 << j):#bitで考えるとわかりやすい
            fomula += "+"
        fomula += s[j+1]

    ans += eval(fomula)

print(ans)

Submission status: Accepted

Solution code:
def __main__():
    s = input()
    result = cal(s)
    print(result[0])

# return (下階層の和の合計, 下階層の和のパターン数)
def cal(s):
    if len(s) == 0:
        return(0, 1)
    elif len(s) == 1:
        return (int(s), 1)
    else:
        sum, times = 0, 0
        for i in range(len(s)):
            num = int(s[0:(i + 1)])
            result = cal(s[(i + 1):len(s)])
            sum += num * result[1] + result[0]
            times += result[1]
        return (sum, times)
            
__main__()

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
ans = 0

for i in range(1 << (n - 1)):
    formula = s[0]
    for j in range(n - 1):
        if i & (1 << j):
            formula += "+"
        formula += s[j + 1]
    ans += eval(formula)

print(ans)

Submission status: Accepted

Solution code:
def main():
    num = [int(x) for x in list(input())]
    num.reverse()
    tot = 0
    N = len(num)

    for m in range(N):
        tot += ((2**(N-4)) * (5**(m) - 1) + (2**(N-m-1)) * (10**(m))) * num[m]

    print(int(tot))

if __name__ == '__main__':
  main()