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:
import itertools
s=input()
t=len(s)
seq=[0,1]
l=itertools.product(seq,repeat=t-1)
m=[]
for i in l:
  tmp=""
  for j in range(t-1):
    tmp+=s[j]+"+"*i[j]
  tmp+=s[-1]
  m.append(tmp)

ans=0  
for j in m:
  ans+=eval(j)
  
print(ans)

Submission status: Accepted

Solution code:
s=input()

def dfs(i,f):
    global ans
    if i==len(s)-1:
        ans+=eval(f)
    else:
        #+を入れるかどうか
        dfs(i+1,f+'+'+s[i+1])
        dfs(i+1,f+s[i+1])

    return ans

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

Submission status: Accepted

Solution code:
*s, = map(str, input())

a = [""]*(len(s))
ans = 0

def rec(i:int, a:list) -> None:
    if i == len(s)-1:
        global ans
        ans += eval("".join(_s+_a for _s, _a in zip(s, a)))
        return

    a[i] = ""
    rec(i+1, a)
    a[i] = "+"
    rec(i+1, a)

rec(0, a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    S = input().strip()

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

        ans += tmp

    print(ans)

    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def insert(pos, s, x):
    return x.join([s[:pos], s[pos:]])


s = input()
length = len(s)
ret = 0

for i in range(2 ** (length-1)):
    my_str = s
    cnt = 0
    for j in range(length):
        if ((i >> j) & 1):
            my_str = insert(j+cnt+1, my_str, "+")
            cnt = cnt + 1
    ret = ret + eval(my_str)

print(ret)

Submission status: Accepted

Solution code:

S=input()
n=len(S)

ans=0
for i in range(2**(n-1)):
    a = [1&(i>>j) for j in range(n)]
    ind = set([i for i, x in enumerate(a) if x==1])
    nums=[]
    tmp=0
    for j in range(n):
        tmp = tmp*10 + int(S[j])
        if j in ind:
            nums += [tmp]
            tmp=0
    nums += [tmp]
    #print(nums)
    ans += sum(nums)

print(ans)

Submission status: Accepted

Solution code:
import sys
#input = sys.stdin.buffer.readline

def main():
    N = str(input())
    M = len(N)-1
    ans = 0
    for i in range(2**M):
        u = [0]
        for j in range(M):
            if (i>>j)&1:
                u.append(j+1)
        u.append(M+1)
        l = len(u)
        for k in range(l-1):
            num = int(N[u[k]:u[k+1]])
            ans += num
            
    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)):
    s = S[0]
    for j in range(n-1):
        if (i >> j) & 1:
            s += '+'
        s += S[j+1]
    ans += eval(s)
print(ans)

Submission status: Accepted

Solution code:
S = input()

beautify = lambda s: s.rstrip('+').lstrip('+').replace('++', '+')

def dfs(depth, formula):
    if depth+1 >= len(formula):
        return eval(beautify(formula))

    res = 0
    res += dfs(depth+2, "{}{}{}".format(
        formula[:depth+1],
        '+',
        formula[depth+1:],
    ))
    res += dfs(depth+1, formula)

    return res

ans = dfs(0, S)
print(ans)

Submission status: Accepted

Solution code:
s = input()
 
def dfs( i,  f ):
    if i == len( s ) - 1:
        return sum( list( map( int, f.split( "+" ))))
    return dfs( i + 1, f + s[ i  + 1 ] ) + dfs( i + 1, f +  "+" + s[  i   + 1 ])
print( dfs( 0, s[ 0 ]) )

Submission status: Accepted

Solution code:
s = str(input())
n = len(s)-1
t = 2**n

result = 0
for i in range(t):
  p = str(bin(i))[2:]
  p = '0'*(n-len(p))+p
  exList = []
  for j,k in enumerate(s):
    exList.append(k)
    if j != n and  p[j] == '1':
      exList.append('+')
  result += eval(''.join(exList))

print(result)

Submission status: Accepted

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


def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split('+'))))

    return dfs(i + 1, f + s[i + 1]) + dfs(i+1, f + '+' + s[i+1])


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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s=list(input().strip())
n=len(s)
ans=0
for i in range(1<<(n-1)):
    sum=0
    for j in range(n):
        sum*=10
        sum+=int(s[j])
        if 1&i>>j:
            ans+=sum
            sum=0
    ans+=sum
print(ans)

Submission status: Accepted

Solution code:
s = input()

ans = 0
n = len(s) - 1
for bit in range(1 << n):
    siki = s[0]

    for i in range(n):
        if bit & (1 << i):
            siki += "+"
        siki += s[i + 1]

    for i in siki.split("+"):
        ans += int(i)

print(ans)

Submission status: Accepted

Solution code:
#045c
S = list(input())

#allは2**9=512なので全探索でOK
if len(S)==1:
  print(int(S[0]))
else:
  ans = 0

  for i in range(0,2**(len(S)-1)):
      bit = str(bin(i))[2:].zfill(len(S)-1)
      #print(bit,":",end="") 
      number = int(S[0])

      for j in range(len(bit)):

          if bit[j] == "0":
              number = number*10 + int(S[j+1])
          else:
              #print("+",number,end="")
              ans += number
              number = int(S[j+1])

      #print("+",number)
      ans += number

  print(ans)

Submission status: Accepted

Solution code:
s=input()

def dfs(i,f):
    global s_sum
    if i==len(s)-1:
        s_sum+=sum(map(int,f.split('+')))

    else:
        dfs(i+1,f+'+'+s[i+1])
        dfs(i+1,f+s[i+1])

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

Submission status: Accepted

Solution code:
s=input()
from collections import deque
ans=0
d=deque()
d.append(s[0])
for i in range(len(s)-1): 
    for j in range(len(d)):
        tmp=d.popleft()
        d.append(tmp+"+"+s[i+1])
        d.append(tmp+s[i+1])
for i in range(len(d)):
    tmp=d.popleft()
    ans+=sum(list(map(int, tmp.split("+"))))
    # print(tmp.split("+"))
print(ans)

Submission status: Accepted

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

S=list(map(int,input()))
ans=0
for i in range(2**(len(S)-1)):
    bin_str=format(i,"0{}b".format(len(S)-1))
    ans+=S[-1]
    k=1
    for j in range(len(S)-1):
        if bin_str[-j]=="1":
            k=0
        ans+=S[-(2+j)]*(10**k)
        k+=1

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
s = input()
ans = 0
for bit in range(2**(len(s)-1)):
    tmp = ""
    for j in range(len(s)):
        if (bit >> j) & 1 == 1:
            tmp += s[j]
            tmp += "+"
        else:
            tmp += s[j]
    ans += eval(tmp)
print(ans)

Submission status: Accepted

Solution code:
s=input()

#＋を入れられる数
n=len(s)-1
ans=0
for i in range(2**n):
    f=s[0]
    for j in range(n):

        if (i>>j)&1:
            f+='+'
        f+=s[j+1]

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

Submission status: Accepted

Solution code:
def dfs(i, f, s, l):
    if i == l-1:
        return sum(list(map(int, f.split("+"))))
    
    return dfs(i+1, f+s[i+1], s, l) + dfs(i+1, f+"+"+s[i+1], s, l)

def main():
    s = input()
    l = len(s)

    print(dfs(0, s[0], s, l))
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
N = len(S)-1
ans = 0
for x in range(2 ** N):
  pvj = 0
  for j in range(N):
    if (x >> j) & 1:
      ans += int(S[pvj:j+1])
      pvj = j+1
  ans += int(S[pvj:N+1])
print(ans)

Submission status: Accepted

Solution code:
s = input()

n = len(s) - 1
ans = 0

for i in range(2 ** n):
    k = 0
    nm = []
    for j in range(n):
        if ((i >> j) & 1):
            nm.append(int(s[k:j + 1]))
            k = j + 1
        
        if j == n - 1:
            nm.append(int(s[k:n + 1]))
    
    ans += sum(nm)

if n == 0:
    print(int(s))
else:
    print(ans)

Submission status: Accepted

Solution code:
S = input()
Sum = 0
N = 2 ** (len(S) - 1)
for i in range(N):
  A = []
  for j in range(len(S) - 1):
    A.append(i % 2)
    i //= 2
  T = S[0]
  T2 = 0
  for j in range(len(S) - 1):
    if A[j] == 0:
      T = T[:] + S[j+1]
    else:
      T2 += int(T)
      T = S[j+1]
  T2 += int(T)
  Sum += T2
print(Sum)

Submission status: Accepted

Solution code:
S = input()
l = len(S)
ans = 0
for i in range(l):
  for j in range(i+1, l+1):
    s = int(S[i:j])
    e = max(i-1, 0)+max(l-j-1, 0)
    ans += s*(2**e)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = 0
S = input()
n = len(S)

def dfs(i,f):
    if i == n-1: return sum(list(map(int, f.split("+"))))

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

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

Submission status: Accepted

Solution code:
S = list(input())
form = "0"+str(len(S)-1)+"b"
ans = 0
if len(S)==1:
    print(int(S[0]))
else:
    for i in range(2**(len(S)-1)):
        b = format(i, form)
        eq = [S[0]]
        for j in range(len(b)):
            if b[j] == "1":
                sign = "+"
            else: sign = ""
            eq.append(sign)
            eq.append(S[j+1])
        eqstr = str("".join(eq))
        ans += eval(eqstr)
    print(ans)

Submission status: Accepted

Solution code:
import itertools

S = input()
N = len(S)
#print(S)

ans = 0
for v in itertools.product([1,0],repeat=N-1):
    start = 0
    for i in range(N-1):
        if v[i] == 1:
            stop = i+1
            ans += int(S[start:stop])
            start = stop
    ans += int(S[start:N])

print(ans)

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

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

# 間に+を挟むかどうかでビット全探索
ans = 0
for bit in range(1<<N):
    s = ''
    for i, num in enumerate(S):
        if bit & 1<<i:
            s += num + '+'
        else:
            s += num
    ans += eval(s)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
a=input()
s=list(a)
a=s
cnt=[]
#print(a)
aa=0
for i in range(2**(len(s)-1)):
    su=a[0]
    cnt=[]
    for j in range(len(s)-1):
        if (i>>j)&1==1:
            aa+=int(su)
            su=a[j+1]
            #cnt.append('+')
        elif (i>>j)&1==0:
            su+=a[j+1]
    aa+=int(su)
    #print(aa,su)
            #cnt.append('-')
        #print(su,cnt)
    #if su==7:
     #   print(str(a[0])+cnt[0]+str(a[1])+cnt[1]+str(a[2])+cnt[2]+str(a[3])+'='+'7')
      #  exit()
print(aa)

Submission status: Accepted

Solution code:
n=input()
res=0
for i in range(2**len(n)):
    f=[0]
    for j in range(1,len(n)):
        if (i>>j)&1:
            f.append(j)
    f.append(len(n))
    #print(f)
    pre=0
    for j in range(len(f)-1):
        #print(n[f[j]:f[j+1]])
        pre+=int(n[f[j]:f[j+1]])
    ##print(pre)
    res+=pre
print(res//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

CNT_MAX = 1 << (len(s) - 1)

def get_sum(s, sp):
    ret = 0
    start = end = len(s)
    for i in range(len(bin(sp))-2):
        if bool((sp >> i) & 1):
            start = len(s) - i - 1
            ret += int(s[start:end])
            end = start
    ret += int(s[0:end])
    return ret
    
ans = 0
for i in range(CNT_MAX):
    ans += get_sum(s, i)
    #print(get_sum(s, i))
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1<<(n-1)):
	b = 1
	# print('')
	for j in range(n):
		# print(int(s[-1-j])*b)
		ans += int(s[-1-j])*b
		# print('i = '+str(i)+',j = '+str(j))
		if i&(1<<j):
			b *= 10
		else:
			b = 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
ans = 0
for sep in range(2**(N-1)):
    p = 0
    for i in range(N):
        if (sep>>i)&1 or i==N-1:
            ans += int(S[p:i+1])
            p = i+1

print(ans)

Submission status: Accepted

Solution code:
S=input()

N=len(S)
if N==1:
    print(eval(S))
    exit()
t=[S[0]]*(2*N-1)
for i in range(1,N):
    t[2*i-1]=''
    t[2*i]=S[i]
ans=0
for i in range(1<<(N-1)):
    p=t[:]
    j=1
    while i:
        if i&1:
            p[2*j-1]='+'
        i>>=1
        j+=1
    ans+=eval(''.join(p))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

for i in range(1<<N):
    eq = S[0]
    for j in range(N):
        if i & (1<<j):
            eq += '+'
        eq += S[j+1]
    ans += eval(eq)

print(ans)

Submission status: Accepted

Solution code:
S = input()
Ans = 0
box = []

for i in range(2 ** (len(S)-1)):  # 文字の間に挿入するので、len(S)-1
    for j in range((len(S)-1)):
        box.append(S[j])
        
        if (i >> j) & 1:
            Ans += int("".join(box))
            box.clear()
            
    box.append(S[-1])
    Ans += int("".join(box))
    box.clear()

print(Ans)

Submission status: Accepted

Solution code:
*s, = map(int, list(input()))
gap = len(s)
ans = 0
for i in range(2 ** (gap - 1)): # x通り出てくる
    fmr = ""
    for j in range(gap):
        fmr += str(s[j])
        if (i >> j) & 1:
            fmr += "+"
    ans += eval(fmr)
print(ans)

Submission status: Accepted

Solution code:
# import numpy as np
# import math
import sys
input = sys.stdin.readline

S = input()

M = len(S)
N = 2 ** (M-1)

res = 0

for i in range(N):
    T = S[:]
    for j in range(M-1,-1,-1):
        if ((i >> j) & 1):
            temp = T[j:]
            T = T[:j]
            # print(temp)
            if temp != '':
                res += int(temp)
    if T != '':
        # print(T)
        res += int(T)

print(res//2)

Submission status: Accepted

Solution code:
N_0 = input()
N = list(N_0)
m = len(N)
ans = 0


numbers = list(range(1,m))

n = len(numbers)
box = []

for i  in range(2 ** n):
    box_0 = []
    for j in range(n):
        if ((i >> j)&1):
            box_0.append(numbers[j])
            

    box.append(box_0)

box[0]=0

for j in range(len(box)):
    M = list(N_0)
    if j == 0:
        ans+=int(N_0)
    else:
        for k in range(len(box[j])):
            if k ==0:
                M.insert(box[j][k],"+")
            else:
                M.insert(box[j][k]+k,"+")
                
            
                
        ans += eval("".join(M))
            
print("{}".format(ans))

Submission status: Accepted

Solution code:
n = str(input())
N = n
ans = 0
for i in range(2 ** int(len(n)-1)):
    n = N
    tmplist = []
    for j in range(1,len(n)):
        if (i >> j-1) & 1:
            #print(j-tmp,n)
            tmplist.append(int(n[:j]))
            n = n[j:].zfill(len(n))
    if not n == "":
        tmplist.append(int(n))

    ans += sum(tmplist)
    #print(tmplist)
    #print(i,sum(tmplist),tmplist)
print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
plus_words = []
for i in range(2**(len(S)-1)):
  for j in range(len(S)-1):
    plus_words.append(S[j])
    if ((i>>j)&1):
      ans += int("".join(plus_words))
      plus_words.clear()
  plus_words.append(S[-1])
  ans += int("".join(plus_words))
  plus_words.clear()
  
print(ans)

Submission status: Accepted

Solution code:
def dfs(i, f):
    if i == n-1:
        return sum(list(map(int, f.split('+'))))

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

s = input()
n = len(s)

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

Submission status: Accepted

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

    formula = ""
    for p_n, p_o in zip(n, op + [""]):
        formula += (p_n + p_o)
    ans += eval(formula)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()


def dfs(i,f):
  if i == len(s)-1:
    return sum(list(map(int,f.split("+"))))
  
  return dfs(i+1,f+s[i+1]) + dfs(i+1,f+"+"+s[i+1])

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

Submission status: Accepted

Solution code:
a = input()
if len(a) == 1:
    print(int(a))
    exit()
ans = 0
for i in range(2**(len(a)-1)):
    b = format(i, 'b').zfill((len(a)-1))
    li = []
    num = [a[0]]
    for i in range(len(b)):
        if b[i] == '1':
            ans += int(''.join(num))
            num = [a[i+1]]
        else:
            num.append(a[i+1])
    ans += int(''.join(num))

print(ans)

Submission status: Accepted

Solution code:
s = input()
sum = 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]
   
    
  sum += eval(f)
  
print(sum)

Submission status: Accepted

Solution code:
s = list(input())

d = len(s)-1
ans = 0

for i in range(2**d):
    op = ['']*(d+1)
    for j in range(d):
        if (i >> j) & 1:
            op[j] = '+'

    formula = ''
    for a, b in zip(s, op):
        formula += a + b

    ans += eval(formula)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import copy



S = input()
op_list = ["+"]*(len(S)-1)

sum = 0
for i in range(2**len(op_list)):
    op_list = ["+"]*(len(S)-1)
    for j in range(len(op_list)):

        if (i >> j) & 1:
            op_list[j] = ""
    s = ""
    for k in range(len(op_list)):
        s = s + S[k] + op_list[k]
    s = s + S[len(S)-1]
    sum = sum + eval(s)


print(sum)

Submission status: Accepted

Solution code:
from collections import deque

S = input().rstrip("\n")
# +の最大の数
max_plus = len(S) -1

answer = 0
for i in range(2 ** max_plus):
    state = i
    index = deque()
    for j in range(max_plus):
        # S[j]とS[j+1]の間に+がある
        if (state >> j) & 1:
            index.append(j+1)
    start = 0
    while index:
        idx = index.popleft()
        answer += int(S[start:idx])
        start = idx
    answer += int(S[start:])

print(answer)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
ans = 0
pl = ["", "+"]

for n in range(2**(N-1)):
  b = "{:012b}".format(n)
  b = b[12-N+1:]
  eval_str=""
  for i in range(N-1):
    eval_str = eval_str + S[i] + pl[int(b[i])]
  eval_str = eval_str + S[N-1]
  ans = ans + eval(eval_str)
print(ans)

Submission status: Accepted

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

S = one_str()

num_list = list(S)

start_bit=2**(len(S)-1)
end_bit = 2**(len(S))

def get_sums(array, bit):
    sums = 0
    start = 0
    end = 0
    for i,s in enumerate(bit):
        if s=="1":
            end = i+1
            sums+=int("".join(array[start:end]))
            start=i+1
    if end==start==0:
        return int("".join(array))
    else:
        sums+=int("".join(array[start:]))
    return sums

sums = 0
for i in range(start_bit, end_bit):
    bits = str(bin(i))[3:]
    sums += get_sums(num_list, bits)

print(sums)

Submission status: Accepted

Solution code:
s = input()

# print(eval(s[:1]+'+'+s[1:]))

n = len(s)
ans = 0

for m_i in range(2**(n-1)):
  temp = ''
  for n_i in range(n):
    temp += s[n_i]
    if m_i & (1 << n_i):
      temp += '+'
  # print(temp)
  ans += eval(temp)
  
print(ans)

Submission status: Accepted

Solution code:
import itertools as it

S = input()
ans = 0
for config in it.product(["+", ""], repeat=len(S) - 1):
    num = []
    for i in range(len(S)):
        num.append(S[i])
        if i < len(S) - 1:
            num.append(config[i])
    ans += sum([int(i) for i in "".join(num).split("+")])
print(ans)

Submission status: Accepted

Solution code:
s = input()
N = 2**(len(s) - 1)
ans = 0
for n in range(N):
    li, ci = 0, 0
    while n > 0:
        if n & 1 == 1:
            ans += int(s[li:ci + 1])
            li = ci + 1
        n = n >> 1
        ci += 1
    ans += int(s[ci:])

print(ans)

Submission status: Accepted

Solution code:
s = input()

ans = 0
for i in range(2 ** (len(s) - 1)):
    js = []
    for j in range(len(s) - 1):
        if (i >> j) & 1:
            js.append(j)

    if js == []:
        ans += int(s)
    else:
        prev = 0
        for j in range(len(js)):
            ans += int(s[prev:js[j] + 1])
            prev = js[j] + 1
        ans += int(s[prev:])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
n = len(s)
lists = []
tmp = []
Sum = 0
s_lists = []
for i in range(2 ** (n-1)):
    lists = []
    tmp = []
    cnt = 0
    s_lists = []
    int_list = []
    for k in range(n):
        s_lists.append(s[k])
    for j in range(n-1):
        if ((i >> j) & 1):
            lists.append(1)
        else:
            lists.append(0)
    for m in range(len(lists)):
        if lists[m] == 1:
            s_lists.insert(m + cnt + 1, "+")
            cnt += 1
    ss = "".join(s_lists)
    ss_list = ss.split("+")
    for h in ss_list:
        tmp = int(h)
        int_list.append(tmp)
    Sum += sum(int_list)
print(Sum)

Submission status: Accepted

Solution code:
def main():
    S = input()
    lens = len(S)

    patterns = []
    ans = 0

    if lens == 1:
        ans = int(S)
    else:
        for i in range(2 ** (lens-1)):
            x = format(i, 'b').zfill(lens-1)
            stmt = S[0]
            for i, xi in enumerate(x):
                if xi == '1':
                    stmt += '+'
                stmt += S[i+1]
            ans += eval(stmt)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import combinations

def main():
    S = input()
    n = len(S)
    a = [i for i in range(1, n)]
    ans = []
    for i in range(n):
        if i == 0:
            ans.append(int(S))
        else:
            k = list(combinations(a, i))
            for ki in k:  # ki: (1, 3)
                r = 0
                t = 0  # 一時記憶
                for j, sj in enumerate(S):
                    if j in ki:
                        r += t
                        t = int(sj)
                    else:
                        t = t * 10 + int(sj)
                r += t
                ans.append(r)

    # print(ans)
    print(sum(ans))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
I_MAX = len(S)
values = []


def calc(val, add, i):
    if i == I_MAX:
        val += add
        values.append(val)
    else:
        calc(val+add, int(S[i]), i+1)
        calc(val, 10*add+int(S[i]), i+1)


def solve():
    calc(0, int(S[0]), 1)
    print(sum(values))


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

res = 0
for bit in range(2**n):
    tmp = []
    for i in range(n):
        if (bit >> i) & 1:
            tmp.append('+')
        else:
            tmp.append('')
    e = ''
    for j in range(n):
        e += s[j] + tmp[j]
    else:
        e += s[n]
    res += eval(e)

print(res)

Submission status: Accepted

Solution code:
x=input()
n=len(x)
ans=[]
for i in range(2**(n-1)):
    s=format(i,"b").zfill(n-1)
    sprt=[0]
    for i in range(n-1):
        if s[i]=="1":
            sprt.append(i+1)
    sprt.append(n)
    for i in range(len(sprt)-1):
        ans.append(int(x[sprt[i]:sprt[i+1]]))
print(sum(ans))

Submission status: Accepted

Solution code:
import sys
from itertools import combinations

s = list(sys.stdin.readline().rstrip())
l = len(s)

def main():
    res = 0
    cand = range(1, l)
    for inser_cnt in range(l):
        for idces in combinations(cand, inser_cnt):
            t = s.copy()
            idces = list(idces)
            for i in idces[::-1]:
                t.insert(i, '+')
            res += eval(''.join(t))
            
    return res
                     
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
import itertools

S = input()
T = list(itertools.product(['+',''], repeat=len(S)-1))

ans = 0
for i in range(2**(len(S)-1)):
    calc_form = S[0]
    for j in range(len(S)-1):
        calc_form += T[i][j]+S[j+1]
    ans += eval(calc_form)

print(ans)

Submission status: Accepted

Solution code:
S = list(input()) #2^(lenS-1)通り

def plus(s,num,bef):#残りの文字列、何文字目か、これまで
    bef = list(bef)
    s = list(s)
    if len(s) == num:
        bef.append(int("".join(s)))
        return sum(bef)
    else:
        #+いれないとき
        ret = plus(s,num+1,bef)
        #+入れるとき
        bef.append(int("".join(s[:num])))
        ret += plus(s[num:],1,bef)
        return ret

print(plus(S,1,[]))

Submission status: Accepted

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

sum = 0
for k in range(1 << N):
  formula = list(S)
  str = ['' for _ in range(N)]
  for i in range(N):
    if k >> i & 1:
      str[i] = '+'
  for j in range(N):
    if str[j] == '+':
      formula.insert(2*j+1, '+')
    else:
      formula.insert(2*j+1, '')
  sum += eval("".join(formula))

print(sum)

Submission status: Accepted

Solution code:
S = input()

result = 0

op_cnt = len(S) - 1  # すき間の個数
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt  # あらかじめ ["-", "-", "-"] というリストを作っておく
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "+"  # フラグが立っていた箇所を "+" で上書き

    #print(op)
    
    formula = ""
    for p_n, p_o in zip(S, op + [""]):  # 少々モヤッとする
        formula += (p_n + p_o)
    result += eval(formula.replace("-",""))
    
print(result)

Submission status: Accepted

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

joinednum = []
sumjoined = 0
sumlist = []
def check(i,j):
    return (i>>j)%2
for i in range(1<<(n-1)):
    prejoined = [s[0]]
    for j in range(n-1):
        
        if check(i,j):
            prejoined.append(s[j+1])
        else:
            if len(prejoined)>0:
      
                joinednum.append(int("".join(prejoined)))
                prejoined = []
                prejoined.append(s[j+1])
            else:
                joinednum.append(int(s[j+1]))
    joinednum.append(int("".join(prejoined)))
    prejoined = []
    sumjoined = sum(joinednum)
    joinednum = []
    sumlist.append(sumjoined)
    sumjoined = 0

 
ans = sum(sumlist)
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

s = input()

po = list(product(["", "+"], repeat=(len(s) - 1)))

# print(s, po)

ans = 0

for i in range(len(po)):
    e = ""
    for j in range(len(s) - 1):
        e = e + s[j] + po[i][j]
    e = e + s[-1]
    # print(e)
    ans += eval(e)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from itertools import product

s = input()

ans = 0
for i in product([1,0], repeat=len(s)-1):
    p = ""
    for j, x in enumerate(i):
        p += s[j]
        if x == 1:
            p += "+"

    p += s[-1]
    ans += eval(p)

print(ans)

Submission status: Accepted

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