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: Wrong Answer

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

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

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: Wrong Answer

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

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

print(tot)

Submission status: Wrong Answer

Solution code:
S=input()
print(S)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

s = input()
sums = set()

for i, _ in enumerate(s, 1):
  sums.update(sum(int(v) for v in t) for t in combinations(s, i))

len(sums)

Submission status: Wrong Answer

Solution code:
from itertools import product


S = input()
L = len(S)
Y = set()

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

print(sum(Y))

Submission status: Wrong Answer

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: Wrong Answer

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 = int(s)
cnt += sum(map(int, s))
for i in range(1, N - 1):
    eqs = rec(s, 0, i)
    cnt += sum([eval(eq) for eq in eqs])
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()

l = len(s) - 1 # 各数の間の数
total_patterns = 2 << (l)

ans = 0
for i in range(total_patterns):
    num_between = format(i,'b').zfill(l) # 10進数を2進数に変換
    tmp = ''
    for j in range(l):
     if num_between[j] == '1':
         tmp += (s[j] + '+')
     else:
         tmp += s[j]
    tmp += s[-1]
    ans += sum([int(i) for i in tmp.split('+')])

print(ans)

Submission status: Wrong Answer

Solution code:
def get(s):
    length = len(s)
    sum = 0
    for i in range(length):
        sum += int(s[0:i+1])
        sum += get(s[i+1:])
        if len(s[i+1:]) != 0:
            sum += (2**(len(s[i+1:])-1)-1)*int(s[0:i+1])
    return int(sum)

def main():
    string = str(input())
    print(int(get(string)))

Submission status: Wrong Answer

Solution code:
def get(s):
    length = len(s)
    sum = 0
    for i in range(length):
        sum += int(s[0:i+1])
        sum += get(s[i+1:])
        if len(s[i+1:]) != 0:
            sum += (2**(len(s[i+1:])-1) -1)*int(s[0:i+1])
    return sum

def main():
    string = str(input())
    print(int(get(string)))

Submission status: Wrong Answer

Solution code:
def get(s):
    length = len(s)
    sum = 0
    for i in range(length):
        sum += int(s[0:i+1])
        sum += get(s[i+1:])
        if len(s[i+1:]) != 0:
            sum += 2**(len(s[i+1:])-1) -1
    return int(sum)

def main():
    string = str(input())
    print(int(get(string)))

main()

Submission status: Wrong Answer

Solution code:
result = 0
def BT(k, current, s):
    global result
    if k >= len(a)-1 :
        if current == 0 :
            result += s
        print(k,current,s,result)
    else :
        BT(k+1, int(a[k+1]), s+current)
        BT(k+1, current* 10 + int(a[k+1]), s)

a = input()+'0'
BT(0,int(a[0]),0)
print(result)

Submission status: Wrong Answer

Solution code:
s=raw_input()

def sum_by_step(l,step):
    res = 0
    count = 0
    while (count+step <= len(l)):
        res += int(l[count:count+step])
        count += step
    if count < len(l):
        for newstep in xrange(1,len(l)-count+1):
            res += sum_by_step(l[count:],newstep)
    return res

result = int(s)
x = [int(n) for n in s]
'''
for i in xrange(len(s)-1):
    result += int(s[:i+1]) + int(s[i+1:])

for j in xrange(len(s)):
    result += int(s[j])

print result
'''

#result += sum(x)

for i in xrange(len(s)):
    step = 1

    while i+step < len(s):
        result += int(s[:i+1]) + sum_by_step(s[i+1:],step)
        step += 1

print result

Submission status: Wrong Answer

Solution code:
s=raw_input()

def sum_by_step(l,step):
    res = 0
    count = 0
    while (count+step <= len(l)):
        res += int(l[count:count+step])
        count += step
    if count < len(l):
        res += int(l[count:])
    return res

result = int(s)
x = [int(n) for n in s]
'''
for i in xrange(len(s)-1):
    result += int(s[:i+1]) + int(s[i+1:])

for j in xrange(len(s)):
    result += int(s[j])

print result
'''

#result += sum(x)

for i in xrange(len(s)):
    step = 1

    while i+step < len(s):
        result += int(s[:i+1]) + sum_by_step(s[i+1:],step)
        step += 1

print result

Submission status: Time Limit Exceeded

Solution code:
import copy
S = input()

'''
def bit_cal(max_num,cal_list=[],current_cnt=0):
    new_list = []
    if len(cal_list) == 0:
        for i in range(2):
            new_list.append([i])
    else:
        for cal_val in cal_list:
            for i in range(2):
                tmp = copy.deepcopy(cal_val)
                tmp.append(i)
                new_list.append(tmp)
    current_cnt += 1
    if max_num == current_cnt:
        return new_list
    return bit_cal(max_num,new_list,current_cnt)
'''

def bit_cal(max_num,cal_list=[],current_cnt=0):
    new_list = []
    if len(cal_list) == 0:
        for i in range(2):
            new_list.append(str(i))
    else:
        for cal_val in cal_list:
            for i in range(2):
                new_list.append(cal_val + str(i))
    current_cnt += 1
    if max_num == current_cnt:
        return new_list
    return bit_cal(max_num,new_list,current_cnt)

all_plus_combination = bit_cal(len(S)-1)


ans = 0
for plus_combination in all_plus_combination:
    start_idx = 0
    for i in range(len(S)-1):
        if plus_combination[i] == '1':
            ans += int(S[start_idx:i+1])
            start_idx = i+1
    ans +=int(S[start_idx:100])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
S = input()

def bit_cal(max_num,cal_list=[],current_cnt=0):
    new_list = []
    if len(cal_list) == 0:
        for i in range(2):
            new_list.append([i])
    else:
        for cal_val in cal_list:
            for i in range(2):
                tmp = copy.deepcopy(cal_val)
                tmp.append(i)
                new_list.append(tmp)
    current_cnt += 1
    if max_num == current_cnt:
        return new_list
    return bit_cal(max_num,new_list,current_cnt)

all_plus_combination = bit_cal(len(S)-1)


ans = 0
for plus_combination in all_plus_combination:
    start_idx = 0
    for i in range(len(S)-1):
        if plus_combination[i] == 1:
            ans += int(S[start_idx:i+1])
            start_idx = i+1
    ans +=int(S[start_idx:100])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations
import sys, re
inp = sys.stdin.readline().strip()
perms = []
used = []
total = 0
#orig = inp

def checkOrder(check, inp):
    count = 0
    for i in range(len(check)):
        if check[i] == '+':
            continue
        elif check[i] == inp[count]:
            count += 1
        else:
            return False
    return True


for i in range(0, len(inp)):
    withPlus = inp + '+' * i
    perms = [''.join(p) for p in permutations(withPlus)]

    for perm in perms:
        if not re.match(r'.*\+\+.*', perm) and not perm[0] == '+' and not perm[-1] == '+':
            if checkOrder(perm, inp) and not perm in used:
                total += eval(perm)
                used.append(perm)

print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
l=len(s)
ans=int(s[l-1])*(2**(l-1))
ak=1
sk=0

for i in range(2**(l-1)):
    for j in range(l-2,-1,-1):
        if (i>>j)&1==1:
            ak=1
        else:
            ak*=10
        sk=int(s[j])*ak
        ans+=sk
    ak=1

print(ans)

Submission status: Accepted

Solution code:
S = list(map(int, list(input())))
L = len(S)
ans = 0
for bit in range(2**(L-1)):
    temp = 0

    for i in range(L-1):
        temp =temp*10 + S[i]
        if bit & (1<<i):
            ans += temp
            temp = 0
    temp  = temp*10 + S[-1]
    ans += temp


print(ans)

Submission status: Accepted

Solution code:
S = input()

ans = 0
def dfs(now, i):
    if i == len(S):
        global ans
        ans += eval(now)
        return
    dfs(now+"+"+S[i], i+1)
    dfs(now+S[i], i+1)
    
dfs(S[0],1)
print(ans)

Submission status: Accepted

Solution code:
s = list(input())
l = ["#"] * (len(s)-1)
ans = 0
for i in range(2**(len(s)-1)):
    for j in range(len(s)-1):
        if (i>>j)&1:
            l[j] = "+"
    x = []
    for j in range(len(s)*2-1):
        if j % 2 == 0:
            x.append(s[j//2])
        else:
            if l[(j-1)//2] == "+":
                x.append("+")
    ans += sum(list(map(int, "".join(x).split("+"))))
    l = ["#"] * (len(s)-1)
print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
ans = 0
stack = [(0,0,1)]
while stack:
  t,s,g = stack.pop()
  if g >= N:
    ans+=t+int(S[s:g])
  else:
    stack.append((t,s,g+1))
    stack.append((t+int(S[s:g]),g,g+1))
print(ans)

Submission status: Accepted

Solution code:
li=list(input())
lis=[]
for i in range(len(li)):
  lis.append(li[i])
  lis.append('')
lis.pop(-1)
sum=0
for i in range(2**(len(li)-1)):
    for j in range(len(li)-1):
      if (i >> j)&1:
          lis[2*j+1]='+'
    str=''.join(lis)
    calc=0
    a=[]
    #計算
    a=list(str.split('+'))
    for j in a:
      calc+=int(j)
    sum+=calc
    #戻す
    for j in range(len(li)-1):
      lis[2*j+1]=''
print(sum)

Submission status: Accepted

Solution code:
"""
DFS（深さ優先探索）
"""


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

    def dfs(i, s):
        if i == N - 1:
            return sum(map(int, s.split('+')))
        return dfs(i + 1, s + S[i + 1]) + dfs(i + 1, s + '+' + S[i + 1])

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()

def solve(i,psum,tmp):
  if i==len(s):
    return tmp+int(psum)  
  return solve(i+1,s[i],int(psum)+tmp) + solve(i+1,psum+s[i],tmp)

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

Submission status: Accepted

Solution code:
S = input()
N = len(S) 
ans = 0
for i in range(2**(N-1)):
    f = S[0]
    for j in range(N-1):
        if ( i >> j ) & 1 :
            f += '+'
        f += S[j+1]
    ans += sum(map(int,f.split('+')))
print(ans)

Submission status: Accepted

Solution code:
S = input()

def dfs(i, f):
    if i == N-1:
        return sum(map(int, f.split('+')))
    return dfs(i+1, f + S[i+1]) + dfs(i+1, f+'+'+S[i+1])

N = len(S)
print(dfs(0, S[0]))

Submission status: Accepted

Solution code:
S = input()

N = len(S)
ans = 0
for bit in range(2**(N-1)):
    f = S[0]
    for i in range(N-1):
        if bit>>i & 1:
            f += "+"
        f += S[i+1]
    ans += sum(map(int, f.split('+')))
print(ans)

Submission status: Accepted

Solution code:
s = input()

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

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

Submission status: Accepted

Solution code:
def main():
	S = list(str(input()))
	LenP = len(S)-1
	ans = 0
	for i in range(2**LenP):
		P = [""]*LenP
		for j in range(LenP):
			if i >> j & 1:
				P[j] = "+"
		Res = [None] * (len(S)+len(P))
		Res[1::2],Res[::2] = P,S
		ResEval = "".join(Res)
		ans += eval(ResEval)
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

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

for i in range(2**(n-1)):
    mode = ['-']*(n-1)
    for j in range(n-1):
        if (i >> j) & 1 == 1:
            mode[j] = '+'
    
    val = S[0]
   
    for k in range(len(mode)):
        if mode[k] == '+':
            val += '+'
            val += S[k + 1]
        else:
            val += S[k + 1]

    ans += eval(val)
print(ans)

Submission status: Accepted

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

if num == 0:
    print(int(s))
else:
    for i in range(2**num):
        mode = ['-']*num
        for j in range(num):
            if (i>>j)&1:
                mode[j] = '+'
        val = s[0]
        for k in range(num):
            if mode[k] == '+':
                if val != '':
                    ans += int(val)
                val = s[k+1]
            else:
                val += s[k+1]
            if val != '' and k == num-1:
                ans += int(val)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
sl=len(s)
ans=0
for i in range(2**(sl-1)):
    bit=bin(i)[2:].zfill(sl-1)
    now=0
    for j in range(len(s)-1):
        if int(bit[j]):
            ans+=int(s[now:j+1])
            now=j+1
    ans+=int(s[now:])
print(ans)

Submission status: Accepted

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

for i in range(2**n):
  l = X[0]
  for j in range(n):
    if (i>>j & 1) == 1:
      l += "+"
    l += X[j+1]
  #Xのjが入ってる番目の隙間でsplit
  num = map(int,l.split("+"))
  ans += sum(num)
print(ans)

Submission status: Accepted

Solution code:
S = input()
n = len(S)
res = 0
for i in range(1 << n-1):
    subres = 0
    subst = S[0]
    for j in range(n-1):
        if i >> j & 1:
            subres += int(subst)
            subst = S[j+1]
        else:
            subst += S[j+1]
        if j == n - 2:
            subres += int(subst)
    res += subres
if n == 1:
    print(int(S))
else:
    print(res)

Submission status: Accepted

Solution code:
import copy


def main():
    target = input()

    num_list = []

    def function(n):
        if n == 0:
            num_list.append([(target[0], )])
        else:
            ans = []
            for i in num_list[n-1]:
                m = list(copy.copy(i))
                m.pop()
                m.append(i[-1] + target[n])
                ans.append(m)
                m = list(copy.copy(i))
                m.append(target[n])
                ans.append(m)
            ans = tuple(ans)
            num_list.append(ans)
    for x in range(len(target)):
        function(x)
    # print(num_list[-1])
    answer = 0
    for x in num_list[-1]:
        for y in x:
            answer += int(y)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def dfs(i,s):
  if i == n-1:
    return eval(s)

  return dfs(i+1, s+S[i+1]) + \
         dfs(i+1, s+"+"+S[i+1])

S = str(input())
n = len(S)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = SS()
    len_S = len(S)

    ans = 0
    for i in range(2 ** (len(S) - 1)):
        tmp = S[0]
        for j in range(len_S - 1):
            if i >> j & 1:
                ans += int(tmp)
                tmp = S[j+1]
            else:
                tmp += S[j+1]
        ans += int(tmp)

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import copy
S = list(input())
L = len(S)-1 #長さ
tmp = 1
ans = 0
locate = copy.deepcopy(S)
for i in range (2**L):
    for j in range(L):
        if (i >> j) & 1:
            locate.insert(j+tmp,'+')
            tmp += 1 
    locateSTR = "".join(locate)
    ans += (eval(locateSTR))
    tmp = 1
    locate = copy.deepcopy(S)
    
print(ans)

Submission status: Accepted

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

lis_2 = []
for i in range(1 << (sn - 1)):
    lis = [0, sn]
    for j in range(sn - 1):
        if (i >> j) & 1:
            lis.append(j + 1)
    lis = sorted(lis)
    #print(lis)
    sum1 = 0
    for j in range(len(lis) - 1):
        sum1 += int(s[lis[j]:lis[j + 1]])
    lis_2.append(sum1)
#print(lis_2)
print(sum(lis_2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
#print(n)
ans=0
for bit in range(1 << (n - 1)):
    # 各場合で式 f を生成する
    #print("bit",bit,bin(bit))
    f = s[0]

    for i in range(n - 1):
        if bit & (1 << i):
            # フラグが立っているならば "+" を式の末尾に追加する
            f += "+"
        f += s[i + 1]
        #print("i",i,"1 << i",bin(1 << i),"f",f)
    ans += sum(map(int, f.split("+")))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

res_list = []

for i in range(2**(len(S)-1)):
    temp_s = ''
    for j in range(len(S)):
        temp_s += S[j]
        if ((i >> j) & 1):
            temp_s += '+'
    # print(temp_s)
    res_list.append(temp_s)

temp_S_list = [eval(item) for item in res_list]

print(sum(temp_S_list))

Submission status: Accepted

Solution code:
# C - たくさんの数式
s = list(input())
n = len(s)
a = 0
for i in range(2 ** (n-1)):
    l = []
    l.append(s[0])
    for j in range(n-1):
        if (i & 1 << j):
            l.append('+')
        l.append(s[j+1])
    a += eval(''.join(l))

print(a)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
from itertools import product
bit=list(product([0,1],repeat=n))
#print(bit)
ans=0
for b in bit:
  #print(b)
  cnt=0
  kouho=""
  for i in range(n):
    if i==n-1:
      kouho+=s[i]
      #print(kouho)
      cnt+=int(kouho)
      kouho=""
    else:
      if b[i]==0:
        kouho+=s[i]
      elif b[i]==1:
        kouho+=s[i]
        cnt+=int(kouho)
        #print(kouho)
        kouho=""
    
  ans+=cnt

print(ans//2)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!




def insert_str(target, i, char):
    return target[:i] + char + target[i:]

def calc(target, i):
    global ans
    if i >= len(target):
        ans += eval(target)
        return
    calc(target, i+1)
    calc(insert_str(target, i, "+"), i+2)
        
S = input()
N = len(S)
ans = 0
calc(S, 1)


print(ans)

Submission status: Accepted

Solution code:
from itertools import product
s=int(input())
sl=list(str(s))
n=len(sl)
ans=0
for i in product([0,1],repeat=n-1):
    
    temp=0
    for j in range(n):
        ans+=int(sl[n-j-1])*10**temp
        temp+=1
        if n-j-2>=0 and i[n-j-2]==1:
            temp=0
print(ans)

Submission status: Accepted

Solution code:
s=int(input())
sl=list(str(s))
n=len(sl)
temp=0
for i in range(n):
    for j in range(n-i):
        temp+=(int(sl[i])*(10**j))*(2**(i+max(0,(n-i-j-2))))
print(temp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
rt = 0
for l in range(1,len(S)+1):
  for i in range(len(S)-l+1):
    tmp = 1 if i == 0 or i+l==len(S) else 2
    tw = 2**(0 if len(S)-l-tmp<0 else len(S)-l-tmp)
    rt+=tw*int(S[i:i+l])

print(rt)

Submission status: Accepted

Solution code:
S = input().rstrip()
N = len(S) - 1
p = "+"

ans = 0
for bit in range(1 << N):
	mae = 0
	for j in range(N):
		if (bit >> j) & 1:
			ans += int(S[mae: j + 1])
			mae = j + 1
	ans += int(S[mae: len(S)])
print(ans)

Submission status: Accepted

Solution code:
S = input()
L = list(S)
N = len(L)
bitmask = 2 ** (N - 1)

totals = []
for mask in range(bitmask):
    total = 0
    digit = 0
    for i in range(N):
        num = int(L[N - i - 1])
        total += num * (10 ** digit)
        # bitにi番目のフラグが立っているかどうか
        if mask & (1 << i):
            digit = 0
        else:
            digit += 1
    totals.append(total)

print(sum(totals))

Submission status: Accepted

Solution code:
from collections import deque
s=input()
l=len(s)
ans=0
for i in range(1<<(l-1)):
  Q=deque()
  for j in range(l-1):
    if (i>>j)&1:
      Q.append(j)
  Q.append(l-1)
  start=0
  while Q:
    v=Q.popleft()
    goal=v+1
    ans+=int(s[start:goal])
    start=v+1
print(ans)

Submission status: Accepted

Solution code:

def main():

    s = str( input() )
    s_l = len(s)
    ans = 0
    for i in range( 2 ** (s_l - 1) ):
        x_i = [ 0 for i in range( s_l - 1 ) ]
        x_i_ = list( format( i , 'b' ) )
        x_i[ len( x_i ) - len( x_i_ ) : ] = x_i_

        start = 0
        goal = 0
        for j in range( len(x_i) ):
            if x_i[j] == '1':
                goal = j + 1
                ans += int( s[start:goal] )

                #print(start,goal,int( s[start:goal] )  )

                start = goal
        goal = s_l
        ans += int( s[ start:goal ] )

        #print(start , goal,int( s[start:goal] )  )
    
    print( ans )

main()

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    s = S()
    lenth = len(s)
    itr = itertools.product([0,1],repeat=lenth-1)
    ans = 0

    for i in itr:
        tmp = s[0]
        cnt = 0
        for plus,char in zip(i, s[1:]):
            if plus == 1:
                cnt += int(tmp)
                tmp = char
            else:
                tmp += char
        cnt += int(tmp)
        ans += cnt

    print(ans)                
        
main()

Submission status: Accepted

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

ans = 0

for i in range(2**(l-1)):
    a = s[0]
    for j in range(l-1):
        if i >> j & 1 == 1:
            a += '+'
        a += s[j+1]
    ans += eval(a)
print(ans)

Submission status: Accepted

Solution code:
def main():
    a = input()
    p = len(a)
    ans =0
    for i in range(2**(p-1)):
        t =a[0]
        for j in range(p-1):
            if (i & 1 <<j):
                t = t + '+'
            t = t + a[j+1]
        ans += eval(t)
    print(ans)
if __name__ =='__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

# TODO: 再帰関数でリストを作成 [s1, "+", s2, s3, "+", s4]とか
result = []
def dfs(i, list):
    if i == len(S):
        result.append(list)
        return
    else:
        if i == len(S) - 1:
            return dfs(i+1, list+[S[i]])
        else:
            return dfs(i+1, list+[S[i]]), dfs(i+1, list+[S[i], "+"])

# TODO: リストに従って和を計算
dfs(0, [])
ans = 0
for l in result:
    sum_of_l = 0
    sequence = 0
    for id in range(len(l)):
        if l[id] == "+":
            sum_of_l += sequence
            sequence = 0
        else:
            sequence *= 10
            sequence += int(l[id])
    sum_of_l += sequence
    ans += sum_of_l

print(ans)

Submission status: Accepted

Solution code:
s = str(input())

n = len(s)-1
ans = 0
for i in range(2**n):
    op = [""]*n
    for j in range(n):
        if (i>>j)&1:
            op [n - 1 - j] = "+"
    formula = ""
    for p1 ,p2 in zip(s, op + [""]):
        formula += (p1 + p2)
    ans += eval(formula)

print(ans)

Submission status: Accepted

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

res=0
if n==0:
    res=int(s)
    
for i in range(2**n):
    B=format(i,'b').zfill(n)+'1'
    left=0
    for j in range(n+1):
        if B[j]=='1':
            res+=int(s[left:j+1])
            left=j+1
        
print(res)

Submission status: Accepted

Solution code:
#
A = input()
a_len = len(A)

answer = 0
for i in range(2**(a_len-1)):
  a_tmp = A
  total = 0
  bin_index = format(i, 'b').zfill(a_len-1)
  for j in range(a_len-1):
    a_tmp = list(a_tmp)
    if bin_index[j] == '1':
      a_tmp.insert(2*j+1, '+')
    else:
      a_tmp.insert(2*j+1, '#')
    a_tmp = ''.join(a_tmp)
  a_tmp = a_tmp.replace('#', '')
  a_tmp = map(int, a_tmp.split('+'))
  answer += sum(a_tmp)
print(str(answer))

Submission status: Accepted

Solution code:
def main():
  s = input()
  p = len(s)
  i = 0
  ans = 0
  for i in range(2 ** (p-1)):
    t = s[0]
    for j in range(0,p-1):
      if (i & (1 << j)):
        t = t + "+"
      t = t + s[j+1]
      
    #print(bin(i),t,eval(t))
    ans += eval(t)
    
  print(ans)
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:

def equa(ans,i,s,p):
  for e in (0,1):
    p[i] = e
    if i < len(p)-2:
      ans = equa(ans,i+1,s,p)
    else:
      #print(i,s,p)
      prii = 0
      for ii in range(len(p)):
        if p[ii] == 1:
          ans += int(s[prii:ii+1])
          #print(prii,ii+1,int(s[prii:ii+1]))
          prii = ii+1
  return ans
def main():
  s = input()
  p = [0]*(len(s)-1)
  p.append(1)
  i = 0
  ans = 0
  ans = equa(ans,i,s,p)
  print(ans)
  
if __name__ == '__main__':
  main()

Submission status: Accepted

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

for i in range(2**(l-1)):
    T = S[0]
    for j in range(l-1):
        if i>>j & 1:
            T = T + ""
        else:
            T = T + "+"
        T = T+S[j+1]
    ans += eval(T)
print(ans)

Submission status: Accepted

Solution code:
S = input()

ans=0
for i in range(1<<(len(S)-1)):
    num = int(S[0])
    cur=0
    for j in range(len(S)-1):
        if i & (1<<j):
            cur+=num
            num=0
        num=num*10+int(S[j+1])
    cur += num
    ans+=cur
print(ans)

Submission status: Accepted

Solution code:
s = input()
ans = 0
for i in range(1<<(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:
s=str(input())
n=len(s)
ans=0
x=1
list=[int(s[n-1])]
for i in range(2**(n-1)):
    for j in range(n-1):
        if (i>>j)&1==True:
            x*=10
        else:
            x=1
        list.append((int(s[n-2-j])*x))
    ans+=sum(list)
    x=1
    list=[int(s[n-1])]
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = 0
for i in range(2**(n-1)):
  flag = [False] * (n-1)
  for j in range(n-1):
    if (i >> j) & 1:
      flag[j] = True
  tmp = int(s[0])
  for k in range(n-1):
    if flag[k]:
      ans += tmp
      tmp = int(s[k+1])
    else:
      tmp *= 10
      tmp += int(s[k+1])
  ans += tmp
print(ans)

Submission status: Accepted

Solution code:
S = input()

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

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

print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
ans = 0
for i in range(N):
    for j in range(i+1):
        ans += int(S[N-i-1]) * 10 ** j * 2 ** (N-min(i+1, j+2))
print(ans)

Submission status: Accepted

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

def self(i,w):
    if(i == n-1):
        return sum(list(map(int, w.split("+"))))
    return self(i+1,w+s[i+1]) + self(i+1,w+"+"+s[i+1])

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

Submission status: Accepted

Solution code:
s = input()
n = len (s)
def self(i,w):
    if i == n-1:
        return sum(list(map(int, w.split('+'))))
    return self(i+1,w+s[i+1])+self(i+1,w+'+'+s[i+1])
 
print(self(0,s[0]))

Submission status: Accepted

Solution code:
S=int(input())
leng=len(str(S))

bin(2**leng-1)
ans=0
if leng==1:
    print(S)
    exit()
for i in range(2**(leng-1)):
    bid=bin(2**(leng-1)+i)
    start=0
    for j in range(3,len(str(bid))):
        if bid[j]=='1':
            ans+=int(str(S)[start:j-2])
            start=j-2
        if j==len(str(bid))-1:
            ans+=int(str(S)[start:j-1])
print(ans)

Submission status: Accepted

Solution code:
S=input()
n=len(S)-1
ans=0
for i in range(2**n):
    tmp=S
    cnt=0
    for j in range(n):
        if (i>>j)&1:
            tmp=tmp[:j+1+cnt]+" "+tmp[j+1+cnt:]
            cnt+=1
    ans+=sum(list(map(int,tmp.split(" "))))
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = input()

ans = 0
l = len(s)
for i in range(2**(l-1)):
    ss = ''
    for j in range(l):
        ss += s[j]
        if (i >> j) & 1:
            ss += '+'
    ans += eval(ss)
print(ans)