Problem:


Score : 300 points

Problem Statement

You are given a string S consisting of digits between 1 and 9, inclusive.
You can insert the letter + into some of the positions (possibly none) between two letters in this string.
Here, + must not occur consecutively after insertion.

All strings that can be obtained in this way can be evaluated as formulas.

Evaluate all possible formulas, and print the sum of the results.

Constraints

1 \leq |S| \leq 10

All letters in S are digits between 1 and 9, inclusive.

Input

The input is given from Standard Input in the following format:

S

Output

Print the sum of the evaluated value over all possible formulas.

Sample Input 1

125

Sample Output 1

176

There are 4 formulas that can be obtained: 125, 1+25, 12+5 and 1+2+5. When each formula is evaluated,

125

1+25=26

12+5=17

1+2+5=8

Thus, the sum is 125+26+17+8=176.

Sample Input 2

9999999999

Sample Output 2

12656242944



Sample input:
125


Sample output:
176

Submission status: Accepted

Solution code:
s=input()
n=len(s)
c=0
for i in range(2**(n-1)):
    a=[[int(s[0])]]
    for j in range(n-1):
        if (i>>j)&1:
            a.append([int(s[j+1])])
        else:
            a[-1].append(int(s[j+1]))
    for i, val in enumerate(a):
        for x in range(len(val)):
            c+=(10**x)*val[-(x+1)]
print(c)

Submission status: Accepted

Solution code:
S = input()
ans = 0
for i in range(2**(len(S)-1)):
    plus = []
    bit = i
    for j in range(len(S)-1):
        if bit & 1 == 1:
            plus.append(True)
        else:
            plus.append(False)
        bit = bit >> 1
    elm = []
    tmp = S[0]
    for j in range(1,len(S)):
        if plus[j-1] == True:
            elm.append(int(tmp))
            tmp = S[j]
        else:
            tmp += S[j]
    if tmp != '':
        elm.append(int(tmp))

    ans += sum(elm)
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
S=list(input())
op_cnt = len(S)-1  # すき間の個数
sum_=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] = "+"  # フラグが立っていた箇所を "+" で上書き
    op=deque(op)
    T=deque()
    #print(op,S)
    for i in range(op_cnt):
        T.append(S[i])
        T.append(op.popleft())
    T.append(S[-1])
    sum_ += eval("".join(T))
print(sum_)

Submission status: Accepted

Solution code:
import copy

s = input()
l = len(s) - 1
count = 0

for i in range(2**l):
  code = list(copy.deepcopy(s))
  bin_str = bin(i).replace('0b', '').zfill(l)
  
  plus_count = 0
  for j in range(len(bin_str)):
    if bin_str[j] == '1':
      code.insert(j+1+plus_count,'+')
      plus_count += 1
      
  code = ''.join(code)
  if '++' in code:
    continue
    
  count += eval(''.join(code))
  
print(count)

Submission status: Accepted

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


s = list(input())

ans = 0

for i in range(1<<len(s)-1):
    ttl = []
    memo = s[0]
    for j in range(0,len(s)-1):
        if (i>>j)&1:
            memo += s[j+1]
        else:
            ttl.append(int(memo))
            memo = s[j+1]
    ttl.append(int(memo))
    ans += sum(ttl)
    ttl = []

print(ans)

Submission status: Accepted

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


s = list(input())

ans = 0

for i in range(1<<len(s)):
    ttl = []
    memo = s[0]
    for j in range(1,len(s)):
        if (i>>j)&1:
            memo += s[j]
        else:
            ttl.append(int(memo))
            memo = s[j]
    ttl.append(int(memo))
    
    ans += sum(ttl)
    ttl = []

print(ans//2)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


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


def LF(): return list(map(float, input().split()))


def LI_(): return list(map(lambda x: int(x)-1, input().split()))


def II(): return int(input())


def IF(): return float(input())


def LS(): return list(map(list, input().split()))


def S(): return list(input().rstrip())


def IR(n): return [II() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def FR(n): return [IF() for _ in range(n)]


def LFR(n): return [LI() for _ in range(n)]


def LIR_(n): return [LI_() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]


def sosu(x):
    for i in range(2, int(sqrt(x)+1)):
        if x % i == 0:
            return False
    return True


mod = 1000000007
inf = float('INF')


def A():
    v1, v2, v3 = LI()
    v = v1+v2+v3
    if(v >= 22):
        print('bust')
    else:
        print('win')
    return

# B


def B():
    S = input()
    S = S[:-1]
    count = 0
    for i in range(len(S)//2):
        if (S[i] != S[-1-i]):
            count += 1

    print(count)
    return

# C


def true():
    S = input()
    S = S[:-1]
    
    tmp=0
    for x in range(1 << (len(S)-1)):
        func = S[-1]
        for i in range(len(S)-1):
            if(x & (1 << i)):
                tmp+=int(func)
                func = S[-2-i]
            else:
                func = S[-2-i]+func
        tmp+=int(func)
    print(tmp)

    return


def C():
    N = II()
    L = []
    for i in range(1, N+1):
        A = II()

        for j in range(A):
            x, y = LI()
            L.append([i, x, y])


# D


def D():

    a, b, x = LI()
    BIG = a*a*b/2
    if x > BIG:
        y = 2*b-(2*x/a/a)
        print(math.degrees(math.atan(y/a)))
    else:
        y = 2*x/a/b
        print(math.degrees(math.atan(b/y)))
    return

# E


def E():
    N, K = LI()
    A = LI()
    F = LI()
    A.sort(reverse=True)
    F.sort()
    cost = []
    for i in range(len(N)):
        cost.append(A[i]*F[i])

    a = F[cost.index(max(cost))]

    return

# F


def F():
    N, M = LI()

    value = [0] * M
    power = [0] * M
    for i in range(M):
        a, b = LI()
        value[i] = a
        c = LI()
        L = ['0'] * N
        for k in c:
            L[k - 1] = '1'
        bint = ''.join(L)
        power[i] = int(bint, 2)
    bint = ''.join(list(['1'] * N))
    dp = [inf] * (int(bint, 2)+1)
    t = 0
    cost = 0

    dp[0] = 0
    for s in range(int(bint, 2) + 1):
        for i in range(M):
            t = s | power[i]
            cost = dp[s] + value[i]
            dp[t] = min(dp[t], cost)
    print(-1) if(dp[-1] == inf) else print(dp[-1])

    return

    # you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")


def solution(S):
    # write your code in Python 3.6
    N = len(S)

    pass


# Solve
if __name__ == '__main__':

    true()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
c = 0
if len(s) == 1:
  print(s)
else:
  for i in range(2**(len(s)-1)):
    now = 0
    b = bin(i)[2:]
    b = "0"*(len(s)-len(b)-1) + b + "1"
    for j in range(len(s)):
      if b[j] == "1":
        c += int(s[now:j+1])
        now = j+1
  print(c)

Submission status: Accepted

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

def DFS(i, f):
    n = []
    if i == l - 1:
        n.append(sum(list(map(int, f.split("+")))))
        return n

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

print(sum(DFS(0, s[0])))

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:
S = input()
p = [1] * (len(S) - 1)
sumlst = [0] * len(S)
ans = 0
def dfs(i):
    global ans
    if i == (len(S) - 1):
        tmp = ''
        if p[0] == 1:
            tmp += S[0] + '+' + S[1]
        else:
            tmp += S[0] + S[1]
        for i in range(1, len(p)):
            if p[i] == 1:
                tmp += '+' + S[i + 1]
            else:
                tmp += S[i + 1]
        ans += eval(tmp)
        return

    p[i] = 1
    dfs(i + 1)
    p[i] = 0
    dfs(i + 1)
    return
if len(S) == 1:
    print(int(S))
    exit()
dfs(0)

print(ans)

Submission status: Accepted

Solution code:
S=input()
ans=0
for i in range(2**(len(S)-1)):#どこに+を入れるのか、隙間はlen(s)-1であるからこうなっている
    tmp=S[0]#tmpという配列に+を含めて、evalで計算する方針
    for j in range(len(S)-1):
        if (i>>j)&1:tmp+="+"#iビット目が1であれば+を追加
        tmp+=S[j+1]#更に次の文字を追加、j+1なのはもともと0を加えていたため
    ans+=eval(tmp)
print(ans)

Submission status: Accepted

Solution code:
S=input()

stack=[]
stack.append([S[0],1])
ans=0
while stack:
  v=stack.pop()
  formula=v[0]
  index=v[1]
  if index==len(S):
    ans+=eval(formula)
  else:
    stack.append([formula+S[index],index+1])
    stack.append([formula+"+"+S[index],index+1])

print(ans)

Submission status: Accepted

Solution code:
# C - たくさんの数式 / Many Formulas
s = input()
n = len(s)-1
o = []

if n==0:
    print(int(s))
    exit()

for i in range(2**n):
    op = [0]*n
    for j in range(n):
        if ((i>>j)&1):
            op[n-1-j]=1
    o.append(op)

ans = 0

for i,oo in enumerate(o):
    t = ''
    for j,ss in enumerate(s):
        if j==0:
            t += ss
            continue
        if o[i][j-1]:
            ans += int(t)
            t = ''
            t += ss
        else:
            t += ss
        if j==n:
            ans += int(t)

print(ans)

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
ans=0
for i in range(2**(n-1)):
	ni=list(map(int,list(str(format(i,"b")))))
	while len(ni)<n-1:
		ni.insert(0,0)
	siki=s[0]
	for j in range(n-1):
		if ni[j]==1:
			siki+="+"
		siki+=s[j+1]
	ans+=eval(siki)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
n=len(s)
f=0
for i in range(1<<n-1):
    a=s[0]
    for j in range(n-1):

        if i&(1<<j):
            
            a+='+'+s[j+1]
        else:
            a+=s[j+1]
    f+=eval(a)
print(f)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy

s = str(input())
S = []
for x in s:
    S.append(x)

#+を入れるか入れないかで全探索する
#bit 0ならば+を入れない、1ならば入れる

tot = 0
#bitの生成
for i in range(1<<(len(S)-1)):
    #数字間に+を入れるか入れないか判定
    #入れない-> '', 入れる-> '+'
    Cal = []
    T = copy.deepcopy(S)
    for j in range(len(S)-1):
        if (i>>j)&1 == 1:
            Cal.append('+')
        else:
            Cal.append('')
    #上記までで、Cal=['', '+']などのリストが生成
    #''の場合は結合する
    eq = ''
    for k in range(len(S)-1):
        eq = eq + T[k]+Cal[k]
    eq = eq + T[-1]
    res = eval(eq)
    tot += res
print(tot)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = tmp = 0

s=input()
n=len(s)
for i in range(0,n):
    # print(list(itertools.combinations(range(1, n), i)))
    for c in itertools.combinations(range(1,n),i):
        tmp=0
        for ci in c:
            ans+=int(s[tmp:ci])
            # print(int(s[tmp:ci]),0,tmp)
            tmp=ci
        ans+=int(s[tmp:n])
        # print(int(s[tmp:n]),1)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    ans = 0
    N = len(S)
    for i in range(N):
        for j in range(i+1, N+1):
            l = 2 ** (max(0, i-1))
            r = 2 ** (max(0, N-j-1))
            ans += int(S[i:j]) * l * r
    return ans


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import combinations

S = input()

ans = int(S)
for n in range(1, len(S)):
    for c in combinations(range(len(S) - 1), n):
        op = [''] * len(S)
        for ci in c:
            op[ci] = '+'
        shiki = ''
        for i in range(len(S)):
            shiki += S[i] + op[i]
        ans += eval(shiki)
print(ans)

Submission status: Accepted

Solution code:
s=input()
x=bin(0)
count=0
for i in range((2**(len(s)-1))):
    cur=s[0]
    cur_num=x[2:].zfill(len(s)-1)
    for i in range(len(s)-1):
        if(cur_num[i]=='1'):
            cur+='+'
        cur+=s[i+1]
    count+=eval(cur)
    x = bin(int(x,2)+ 1)
print(count)

Submission status: Accepted

Solution code:
import sys
import itertools

s = sys.stdin.readline().rstrip()
n = len(s)


ans = 0
for i in range(n):
    combs = list(map(list, itertools.combinations(range(1, n), i)))
    res2 = 0
    for c in combs:
        c.insert(0, 0); c.append(n)
        res1 = 0
        for j in range(i+1):
            res1 += int(s[c[j]:c[j+1]])
        res2 += res1
    ans += res2

print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools

s = sys.stdin.readline().rstrip()
n = len(s)


ans = 0
for i in range(n):
    combs = list(map(list, itertools.combinations(range(1, n), i)))
    res2 = 0
    for c in combs:
        c.insert(0, 0); c.append(n)
        res1 = 0
        for j in range(1, i+2):
            res1 += int(s[c[j-1]:c[j]])
        res2 += res1
    ans += res2

print(ans)

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)-1
def dfs(x,y):
  ans = 0
  if x == n:
    return sum(list(map(int,"".join(y).split("+"))))
  else:
    return dfs(x+1,y+"+"+s[x+1])+dfs(x+1,y+s[x+1])
print(dfs(0,s[0]))

Submission status: Accepted

Solution code:
def dfs(i, formula):
    if i + 1 == num_digits:
        return sum(list(map(int, formula.split("+"))))

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


s = input()
num_digits = len(s)

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

Submission status: Accepted

Solution code:
s = list(map(int,list(input())))
n = len(s)
w = 0
for i in range(n):
    for j in range(i, n):
        if j == i:
            w += s[i]*(10**(n-1-j))*(2**j)
        else:
            w += s[i]*(10**(n-1-j))*(2**(j-1))
print(w)

Submission status: Accepted

Solution code:
import itertools


def add_operators(numbers, operators):
    return ''.join([operators[i] + numbers[i] for i in range(len(numbers))])


def main(s):
    numbers = list(s)
    operators = [['']]
    operators.extend([['', '+']] * (len(numbers) - 1))
    products = itertools.product(*operators)
    sum_numbers = 0
    for p in products:
        sum_numbers += sum(map(int, add_operators(numbers, p).split('+')))
    return sum_numbers


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

Submission status: Accepted

Solution code:
import itertools


def strjoin(numbers, options):
    return numbers[0] + ''.join([options[i] + numbers[i + 1] for i in range(len(options))])


def main(s):
    if len(s) == 1:
        return int(s)
    numbers = list(s)
    options = [['', '+']] * (len(numbers) - 1)
    products = itertools.product(*options)
    n_sum = 0
    for p in products:
        n_sum += sum(map(int, strjoin(numbers, p).split('+')))
    return n_sum


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

Submission status: Accepted

Solution code:
s = input()
ans = 0
k = len(s)
def search(formulas, n,count):
    global k
    if count >= k:
        cal(formulas)
    else:
        search(formulas,n+1,count + 1)
        search(formulas[:n] + "+" + formulas[n:],n+2,count + 1)
def cal(formulas):
    global ans
    ans += sum(map(int, list(formulas.split("+"))))
search(s,1,1)
print(ans)

Submission status: Accepted

Solution code:
s=input()
L=[[s,0]]
for i in range(1,len(s)):
    M=[]
    for l in L:
        M.append([(l[0][:i+l[1]])+"+"+(l[0][i+l[1]:]),l[1]+1])
    L+=M
print(sum(map(lambda x:eval(x[0]),L)))

Submission status: Accepted

Solution code:
s=input()
l=len(s)
x=[0]*l
for i in range(l):
  for j in range(i,l):
    if j-i>0:
      x[j]+=int(s[i])*(2**i)*(2**(j-i-1))
    else:
      x[j]+=int(s[i])*(2**i)
a=0
for i in range(l):
  a+=x[i]*(10**(l-i-1))
print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
from itertools import product
S = input().rstrip()

ans = 0
ops = list(product("+ ", repeat=len(S)-1))

for op in ops:
    s = S[0] + "".join(x+y for (x,y) in zip(op,S[1::])).replace(" ","")
    ans += eval(s)

print(ans)

Submission status: Accepted

Solution code:
def examC():
    St = S()
    N = len(St)
    cur = int(0)
    ansC = [0]*(2**(N-1))
    for i in range(2**(N-1)):
        k = int(0)
        cur = int(0)
        for j in range(N-1):
            if (i>>j)%2==1:
#                print(St[k:j+1],i,j)
                cur += int(St[k:j+1])
                k = j+1
        cur += int(St[k:])
        ansC[i] = cur

    print(sum(ansC))

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Accepted

Solution code:
# bit全探索

S = input().strip()

ans = 0
for i in range(2**(len(S)-1)):
    e = ['' if c == '0' else '+' for c in format(i, 'b').zfill(len(S))]
    ans += eval(''.join(a+b for a, b in zip(e, S)))
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
ans = []
for i in range(2**(n-1)):
    a = 0
    b = 0
    for j in range(n):
        s[j] = int(s[j])
        b *=10
        if ((i>>j)&1):
            a = a+b+s[j]
            b = 0
        else:
            b+=s[j]
    a+=b
    ans.append(a)
print(sum(ans))

Submission status: Accepted

Solution code:
import itertools

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

PRD3=[]
for i in range(len(PRD1)):
    PRD3.append(['']*(2*N+1))

for i in range(len(PRD1)):
    PRD3[i][::2]=S
    PRD3[i][1::2]=PRD1[i]

ans=0
for i in range(len(PRD3)):
    PRD3[i]=['' if j=='_' else j for j in PRD3[i]]
    ans+=eval(''.join(PRD3[i]))

print(ans)

Submission status: Accepted

Solution code:
ans = 0
 
def dfs(i, cur, sum_v):
    global ans, S
    if i == len(S)-1:
        ans += sum_v
        return 
    dfs(i+1, int(S[i+1]), sum_v+int(S[i+1]))
    dfs(i+1, cur*10+int(S[i+1]), sum_v+cur*9+int(S[i+1]))
 
S = input()
dfs(0, int(S[0]), int(S[0]))
print(ans)

Submission status: Accepted

Solution code:
def solve():
    def recur(i, s):
        if not i < length:
            return sum(map(int, s.split("+")))

        ans1 = 0
        if not i == length - 1:
            ans1 = recur(i + 1, s + S[i] + '+')
        ans2 = recur(i + 1, s + S[i])
        return ans1 + ans2

    S = input()
    length = len(S)

    # print('S, len', S, length)

    return recur(0, '')


if __name__ == '__main__':
    res = solve()
    print(res)

Submission status: Accepted

Solution code:
def main():
    S = input()
    lst = list()
    ans = 0
    for i in range(1 << len(S) - 1):
        lst.clear()
        pre = 0
        for j in range(len(S) - 1):
            if i >> j & 1:
                lst.append(int(S[pre:j + 1]))
                pre = j + 1
        lst.append(int(S[pre:]))
        ans += sum(lst)
    print(ans)
    return


main()

Submission status: Accepted

Solution code:
S = input()
x = len(S)-1
ans = 0
for i in range(1 << x):
    insert = []
    for j in range(x):
        if i >> j & 1:
            insert.append(j)
    st = []
    for k, s in enumerate(S):
        st.append(s)
        if k in insert:
            st.append('+')
    ans += eval(''.join(st))
print(ans)

Submission status: Accepted

Solution code:
s = list(input())
l = len(s) - 1
ans = 0
for i in range(2**l):
    op = [""] * l
    res = ""
    for j in range(l):
        if (i>>j) & 1:
            op[j] = "+"
    
    for n, k in zip(s, op+[""]):
        if len(k) != 0:
            res += n + k
        else:
            res += n
    ans += eval(res)

print(ans)

Submission status: Accepted

Solution code:
import itertools
S = input().strip()
k = len(S)
tot = 0
for x in itertools.product((0,1),repeat=k-1):
    y = S[0]
    for i in range(k-1):
        if x[i]==0:
            y += S[i+1]
        else:
            y += "+"+S[i+1]
    tot += eval(y)
print(tot)

Submission status: Accepted

Solution code:
from collections import deque
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = []

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

for i in range(2**(N)):
    cou = int(0)
    lower = 0
    que = deque()
    for l in range(N+1):
        que.append(int(S[l]))
    for j in range(N):
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
#            print(i,j)
            for k in range(lower,j+1):
                cou += que.popleft()*(10**(j-k))
            lower = j+1
#            print(cou)
    k = int(0)
    while que:
        cou += que.pop()*(10**k)
        k +=1
    ans.append(cou)

print(sum(ans))

Submission status: Accepted

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

S = input()
n = len(S)

def dfs(i, f):
    # 文末？の最後まで行ったらreturn
    if i == n - 1:
        return f
    # +を入れるか入れないか
    return dfs(i + 1, f + S[i + 1]) + "+" + dfs(i + 1, f + "+" + S[i + 1])

def main():
    print(eval(dfs(0,S[0])))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans=0
for i in range(2**(N-1)):
  l=0
  for j in range(N-1):
    if (i>>j)&1:
      ans+=int("".join(S[l:j+1]))
      l=j+1
  ans+=int("".join(S[l:]))
  
print(ans)

Submission status: Accepted

Solution code:
s=input()
n=len(s)-1 
sub=[] 
t=(1<<n)
sm=0 
for i in range(t):
    curr=[]
    for j in range(n):
        if i&(1<<j):
            curr.append(j)
    now=''
    part=[]
    for it in range(len(s)): 
        now+=s[it]
        if it in curr:
            part.append(now)
            now=''
    part.append(now)
    for p in part: 
        #print(p)
        sm+=int(p)
print(sm)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for bit in range(1 << (n - 1)):
    # 各場合で式 f を生成する
    f = s[0]

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

    ans += eval(f)

print(ans)

Submission status: Accepted

Solution code:
def dfs(i, f):
    if i == n - 1:
        return eval(f)
    
    return dfs(i + 1, f + s[i + 1]) + \
           dfs(i + 1, f + "+" + s[i + 1])

s = input()
n = len(s)

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

Submission status: Accepted

Solution code:
def dfs(i,f):
    if i==n-1:
        return f
    return dfs(i+1,f+s[i+1])+'+'+dfs(i+1,f+'+'+s[i+1])
s=input()
n=len(s)
print(eval(dfs(0,s[0])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = str(input())
n_list = list(n)
r = ''
for i in n_list:
  r += '1'

def make_math(numbers, b_str):
  b_str_list = list(b_str)
  r = ''
  for index, n in enumerate(b_str_list):
    r += numbers[index]
    if n == '1' and index < len(b_str_list) - 1:
      r += '+'
  return r

math_list = []
f = '0' + str(len(r)) + 'b'
bi = int(r, 2)
for i in range(bi):
  bb = format(i+1, f)
  math_list.append(make_math(n, bb))

total = 0
m = list(set(math_list))
for mm in m:
  mm_split = map(int, mm.split('+'))
  total += sum(mm_split)

print(total)

Submission status: Accepted

Solution code:
def slove():
    import sys
    import itertools
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    mt = 0
    for v in itertools.product(["+", ""], repeat=len(s)-1):
        l = []
        t = 0
        for i, vv in enumerate(v):
            l.append(s[i])
            if vv == "+":
                t += int("".join(l))
                l = []
        l.append(s[-1])
        t += int("".join(l))
        mt += t
    print(mt)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import itertools

def solve(S: str):
    LEN = len(S)
    bit_list = list(itertools.product([0, 1], repeat=LEN-1))
    s = S[::-1]
    answer=0
    for b in bit_list:
        a = 0
        keta =0 
        for i in range(LEN):
            a += int(s[i])*10**keta
            if i == LEN-1:
                break
            keta+=1
            if b[i] == 1:
                keta = 0
        answer += a
            
            
    print(answer)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def f(s, t):
    if t == '':
        return sum(map(int, s.split('+')))
    else:
        return f(s + t[0], t[1:]) + f(s + '+' + t[0], t[1:])


S = input()
print(f(S[0], S[1:]))

Submission status: Accepted

Solution code:
import itertools

S = [ (n) for n in input()]
ans = []
n= len(S)-1

l = ["+", ""]
pattern = list(itertools.product(l, repeat=n))
for p in pattern:
    t = ""
    for i in range(n):
        t += S[i]+p[i]
    t=t+S[n]
    ans.append(eval(t))

print(sum(ans))

Submission status: Accepted

Solution code:
# C - たくさんの数式 / Many Formulas

import itertools

S = input()

ans_list = []

for plus_pattern in list(itertools.product(["","+"], repeat = len(S)-1)):

    formula = ""
    for idx in range(len(S)-1):
        formula += S[idx]
        formula += plus_pattern[idx]

    formula += S[-1]
    ans_list.append(eval(formula))

print(sum(ans_list))

Submission status: Accepted

Solution code:
Sl = list(input())

def func(n, s):
    n += 1
    if n==len(Sl)-1:
        a = sum([int(i) for i in (s+Sl[n]).split("+")])
        b = sum([int(i) for i in (s+"+"+Sl[n]).split("+")])
        return a + b
    else:
        return func(n, s+Sl[n]) + func(n, s+"+"+Sl[n])

if len(Sl)==1:
    print(Sl[0])
else:
    print(func(0, Sl[0]))

Submission status: Accepted

Solution code:
S = input().strip()

ans = 0
for i in range(2**(len(S)-1)):
  e = ['' if c == '0' else '+' for c in format(i,'b').zfill(len(S))]
  ans += eval(''.join(a+b for a,b in zip(e,S)))

print(ans)

Submission status: Accepted

Solution code:
l=list(input())
n=len(l)
if n==1:
    print(l[0])
    exit()
op=['0','1']
for i in range(n-2):
    tmp=[]
    for j in op:
        tmp.append(j+'0')
        tmp.append(j+'1')
    op=tmp
ans=0
for i in op:
    k=list(i)
    k.append('2')
    s=l[0]
    t=0
    for j in range(n):
        if k[j]=='1':
            s+=l[j+1]
        elif k[j]=='0':
            t+=int(s)
            s=l[j+1]
        else:
            t+=int(s)
    ans+=t
print(ans)

Submission status: Accepted

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

def SplitSum(i, t):
    if i == n-1:
        return sum(list(map(int, t.split('+'))))
    
    return SplitSum(i+1, t+S[i+1]) + SplitSum(i+1, t+'+'+S[i+1])

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

Submission status: Accepted

Solution code:
st = input()
total = int(st)
signs = len(st) - 1
for i in range(1, 2 ** signs):
    start = 0
    for j in range(1, signs + 1):
        if (i & (1 << (j - 1))) >> (j - 1) == 1:
            total += int(st[start:j])
            start = j
    total += int(st[start: ])
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def splitter(str):
    for i in range(1, len(str)):
        start = str[0:i]
        end = str[i:]
        yield (start, end)
        for split in splitter(end):
            result = [start]
            result.extend(split)
            yield result


if __name__ == "__main__":
    s = str(input())
    possibilities = list(splitter(s))
    sum = int(s)
    for i in possibilities:
        for j in i:
            sum += int(j)
    print(sum)

Submission status: Accepted

Solution code:
S = input()
S_prime = ''
for c in S:
    S_prime += c + '+'
S_prime = S_prime[:-1]
def rem(s, N, target = '+'):
    cnt = -1
    ind = 0
    for i, c in enumerate(s):
        if c == target:
            cnt += 1
        if cnt == N:
            ind = i
            break
    return s[:i] + s[i+1:]
def f(s, N):
    # print(s)
    # if s.isdecimal():
    #     return int(s)
    tot = sum(map(int, s.split("+")))  # "+"なくても大丈夫
    for i in range(N, s.count("+")):
        tot += f(rem(s, i), i)
    return tot
print(f(S_prime, 0))

# 1+2+3+4 -> 12+3+4 -> 12+34
# 1+2+3+4 -> 1+2+34 -> 12+34
# 上二つが重複するのをなくした。サンプルケースはOK