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)

def part_sum(cur, i, res):
    if i < n-1:
        part_sum(cur+s[i], i+1, res)
        part_sum(cur+s[i]+"+", i+1, res)
    else:
        cur += s[i]
        res.append(sum(list(map(int, cur.split("+")))) )
    return res
  
res = part_sum("", 0, [])
print(sum(res))

Submission status: Accepted

Solution code:
S = input()

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

for i in range(2**(n-1)):
    form = S
    bit = []
    for _ in range(n-1):
        bit.append(i%2)
        i =  i // 2
    eq = ""
    for i, b in enumerate(bit):
        eq += (form[i])
        if b == 1:
            eq += ('+')
    eq += form[-1]

    ans += eval(eq)

print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
cand = []

def func(ac,yet,sum):
  next = int(yet[0])
  
  
  if len(yet) ==1:
    cand.append(sum+ ac+ next)
    cand.append(sum+ ac*10+ next)
  else:
    func(next, yet[1:],ac+sum)
    func(ac*10+next, yet[1:],sum)

func(0,s,0)
print(sum(cand)//2)

Submission status: Accepted

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

for i in range(2**(n-1)):
  form = s
  bit = []
  for _ in range(n-1):
    bit.append(i%2)
    i =  i//2

  for j in range(n-1):
    if bit[j]:
      form = form[:n-j-1] + '+' + form[n-j-1:]

    
  ans += eval(form)
print(ans)

Submission status: Accepted

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

plus = []
for i in range(2**(n-1)):
    tmp = [""] * n
    for j in range(n-1):
        if i >> j & 1:
            tmp[j] = "+"
    plus.append(tmp)

ans = 0
for p in plus:
    s = ""
    for i in range(n):
        s = s + S[i] + p[i]
    ans += eval(s)
print(ans)

Submission status: Accepted

Solution code:
def dfs(arr: list, index: int, length: int, S: str) -> int :

    if index == length-1:
        return cal(arr, S)

    index += 1
    return dfs(arr+[index], index, length, S) + dfs(arr, index, length, S)


def cal(arr: list, S: str) -> int :
    s = 0
    tmp = arr[0]

    for a in arr[1:]:
        s += int(S[tmp:a])
        tmp = a
    s += int(S[arr[-1]:])
    
    #print(s)

    return s

S = input()

arr = [0]
ans = dfs(arr, 0, len(S), S)

print(ans)

Submission status: Accepted

Solution code:
def manyformula(S):
    T=int(S)
    if len(S)==1:
        return int(S)
    else:
        m=0
        for i in range(1,len(S)):
            a=T%(10**i)
            b=T//(10**i)
            m=m+b*(2**(len(str(a))-1))+manyformula(str(a))
        return T+m

S=input()
print(manyformula(S))

Submission status: Accepted

Solution code:
s = input()
n = 0
for i in range(2**(len(s)-1)):
    b = list("{0:010b}".format(i))
    b.reverse()
    
    index = 0
    for j in range(len(s)):
        if b[j] == "1":
            n += int(s[index:j+1])
            index = j+1
    if index != j+1:
        n += int(s[index:j+1])
    
print(n)

Submission status: Accepted

Solution code:
S = input()
s = list(S)
exp = ""
total = 0

for i in range(2**(len(S)-1)):
    a = list(bin(i)[2:])

    a = ["0"] * (len(s) - len(a)-1) + a
    for j in range(len(s)-1):
        if (a[j] == "1"):
            exp += s[j] + "+"
        else:
            exp += s[j]

    exp += s[-1]
    total += sum(map(int, exp.split("+")))
    exp = ""

print(total)

Submission status: Accepted

Solution code:
class Formula():
    def __init__(self, S):
        self.input = S
        self.sum = 0
        self.input_len = len(S)

        self.input_split_pos = self.input_len - 1
        self.mask = 2**self.input_split_pos - 1

    def calc_sum(self, S: str, split_pos: int) -> int:
        stack = []
        split_pos = [i for i, x in enumerate(
            [int(x) for x in bin(split_pos)[2:].zfill(self.input_split_pos)]) if x == 1]

        start = 0
        if split_pos == []:
            stack.append(int(self.input))
        else:
            for i in split_pos:
                stack.append(int(self.input[start:i + 1]))
                start = i + 1
            stack.append(int(self.input[start:self.input_len]))
        self.sum += sum(stack)
        return self.sum


def main():
    S = input()
    formula = Formula(S)

    bits = 0b0

    while bits <= formula.mask:
        formula.calc_sum(S, bits & formula.mask)
        bits += 1
    print(formula.sum)


main()

Submission status: Accepted

Solution code:
s = str(input())
s_list = []
for i in range(len(s)):
  s_list.append(s[i])

#print(s_list)
L = len(s_list)

sum_a = 0
if L == 1:
  print(int(s))
else:
  for k in range(2**(L-1)):
    plus_list = [0]*(L-1)
    p = list(bin(k)[2:])
    for l in range(len(p)):
      plus_list[L-len(p)+l-1] = int(p[l])

    #print("p_list:",plus_list)
    #print("p:",p)
    num_list = []
    start = 0
    for i in range(len(plus_list)):
      if plus_list[i]:
        num_list.append(s_list[start:i+1])
        start = i+1
    num_list.append(s_list[start:])
    ans = 0
    for i in num_list:
      s = ''
      for j in i:
        s = s+j
      ans += int(s)
    sum_a += ans
    #print("num_list:",num_list)
    #print("ans:",ans)
  print(sum_a)

Submission status: Accepted

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

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

def dfs(i,s,m): 
    #
    #
    # m: これまでに何回
    ans = 0
    if i==n:
        return sum_s(s)

    ans += dfs(i+1,s,m) # i番目に+を入れない場合
    ans += dfs(i+1,s[:i+1+m]+"+"+s[i+1+m:],m+1) # i番目に+を入れる場合

    return ans


print(dfs(0,S,0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
s = input()

# 1, 2, 3, 4, 5, 6, 7, 8, 9, 9
#   0  1  0  0  0  1  0  0  0
# len(s) - 1
ans = 0
for p in itertools.product([0, 1], repeat=len(s) - 1):
    div = int(s[0])
    for idx, flg in enumerate(p, 1):
        if flg == 0:
            div *= 10
            div += int(s[idx])
        else:
            ans += div
            div = 0
            div += int(s[idx])
    ans += div
print(ans)

Submission status: Accepted

Solution code:
S = input()

n = len(S)-1

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

def dfs(i, S, k):
    ans = 0
    if i==n:
        return calc(S)

    ans += dfs(i+1, S, k)
    ans += dfs(i+1, S[:i+1+k] + "+" + S[i+1+k:], k+1)

    return ans

if n==0:
    print(S)
else:
    print(dfs(0, S, 0))

Submission status: Accepted

Solution code:
S = input()

def F(S):
  yield int(S)
  for i in range(len(S) - 1):
    left = S[: i + 1]
    right = S[i + 1 :]
    x = int(left)
    for y in F(right):
      yield x + y
print(sum(F(S)))

Submission status: Accepted

Solution code:
S = input()
op_cnt = len(S) - 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(S, op + [""]):
        if p_o == "+":
            formula += (p_n + p_o)
        else:
            formula += p_n
    ans += eval(formula)

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s = input().strip()
ans = 0
n = len(s)-1

for i in range(2 ** n):
  t = ''
  for j in range(n):
    t += s[j]
    if (i >> j) & 1:
      t += '+'
  else:
    t += s[n]
  ans += eval(t)

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s = input().strip()
n = len(s)
ans = 0
for i in range(1<<(n-1)):
    t = ''
    for j in range(n-1):
        t += s[j]
        if (i >> j) & 1:
            t += '+'
    else:
        t += s[n-1]
    ans += eval(t)
print(ans)

Submission status: Accepted

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

for bit in range(1 << n):
    eval_str = ''
    eval_str += s[0]
    for i in range(n):
        if bit & (1 << i):
            eval_str += '+'
        eval_str += s[i + 1]
    sum += eval(eval_str)

print(sum)

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 = [int(s) for s in list(input())]
n = len(S)
ans = 0
for bit in range(1 << (n-1)):
    total = 0
    tmp = S[0]
    for i in range(n-1):
        if (bit >> i) & 1:
            total += tmp
            tmp = S[i+1]
        else:
            tmp = tmp*10 + S[i+1]
    total += tmp
    ans += total
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


count = 0
for i in range(pow(2,n-1)):
    k = 0
    buf = 0
    for j in range(n):
        if((i & (1<<j))):
            buf +=pow(10,k)*int(s[n-1-j])
            #print(buf)
            count += buf
            buf = 0
            k = 0
        else:
            buf +=pow(10,k)*int(s[n-1-j])
            k += 1
    count += buf
print(count)

Submission status: Accepted

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

s = int(input())
x = [ int(i) for i in list(str(s)) ]
length = len(x)

ans = 0
for bit in range(1<<(length-1)):
    cur = int(x[0])
    for i in range(length-1):
        # i番目の間に + が挿入されていたとき
        if (bit>>i)&1:
            ans += cur
            cur = int(x[i+1])
        # i番目の間に + が挿入されていないとき
        else:
            cur *= 10
            cur += int(x[i+1])
    ans += cur

print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = 0
for bit in range( 1 << (n-1)):
  f = s[0]
  for i in range(n-1):
    if bit & (1 << i):
      f += "+"
    f += s[i+1]
  ans += sum(map(int, f.split("+")))
print(ans)

Submission status: Accepted

Solution code:
from itertools import product 
S = input()
N = len(S)

cand = ["","+"]

ans = 0
for i in product(cand,repeat=(N-1)):
    i = list(i)
    i.append("")
    e = "".join([a+b for a,b in zip(S,i)])
    ans += eval(e)
print(ans)

Submission status: Accepted

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

total_result = 0
for bit in range(1<<plus_number):
  buffer = s[0]
  for i in range(plus_number):
    if bit & (1 << i):
      # +を挿入する
      buffer += "+"
    buffer += s[i+1]
  total_result += sum(map(int, buffer.split('+')))
print(total_result)

Submission status: Accepted

Solution code:
s = str(input())
ans = 0

for i in range(2**(len(s)-1)):
    x = s[0]

    for j in range(len(s)-1):
        if (i>>j) & 1:
            x += '+'
        x += s[j+1]
        
    ans += sum(map(int,x.split('+')))
print(ans)

Submission status: Accepted

Solution code:
# C
import itertools

S = input()

ans = 0

ans += int(S)

for i in range(1, len(S)):
    for j in itertools.combinations(range(1,len(S)),i):
        aa = 0
        for k in j:
            ans += int(S[aa:k])
            aa = k
        ans += int(S[aa:len(S)])
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7

def main():
    S = cin.string()
    ans = 0
    N = len(S) - 1
    for i in range(1 << N):
        t = ["."] * N
        for j in range(N):
            if i >> j & 1:
                t[j] = "+"
        tmp = int(S[0])
        for j in range(N):
            if t[j] == "+":
                ans += tmp
                tmp = int(S[j + 1])
            else:
                tmp *= 10
                tmp += int(S[j + 1])
        ans += tmp
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

if l == 1:
    print(S)
else:
    patterns = []
    for i in range(2 ** (l-1)):
        b = format(i, 'b').zfill(l-1)
        patterns.append(b)

    ans = 0
    for pi in patterns:
        s = S[0]
        for i, bi in enumerate(pi):
            if bi == '1':
                s += '+'
            s += S[i+1]
        v = eval(s)
        ans += v
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for i in range(2 ** (n-1)):

    formula = ''
    formula += a[0]

    for j in range(n-1):

        if (i >> j) & 1:
            formula += '+'

        formula += a[j+1]
    
    ans += sum(map(int, formula.split('+')))

print(ans)

Submission status: Accepted

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

s=0
for i in range(2**l):
    t=format(i,"b")
    t=t.zfill(l)
    k=S[0]
    for j in range(l):
        if(t[j]=="0"):
            k=k+S[j+1]
        else:
            s+=int(k)
            k=S[j+1]
    s+=int(k)
 
print(s)

Submission status: Accepted

Solution code:
s = input()
len_s = len(s)
total_sum = 0
for i in range(2 ** (len_s - 1)):
    sum_array = []
    prev_place = 0
    for j in range(len_s - 1):
        if (i >> j) & 1:
            sum_array.append(int(s[prev_place:j+1]))
            prev_place = j+1
    if prev_place != len_s:
        sum_array.append(int(s[prev_place:len_s]))
    total_sum += sum(sum_array)
print(total_sum)

Submission status: Accepted

Solution code:
def generate_permutations(trunk, size, current=[]):
    if len(current) == size:
        trunk.append(current)
        return

    generate_permutations(trunk, size, current + [True])
    generate_permutations(trunk, size, current + [False])


S = input()
perms = []
generate_permutations(perms, len(S) - 1)
ANS = 0
for perm in perms:
    A = [int(c) for c in S]
    ans = 0
    tmp = A.pop(0)
    for i in range(len(A)):
        if perm[i]:
            ans += tmp
            tmp = A[i]
        else:
            tmp *= 10
            tmp += A[i]
    else:
        ans += tmp
    ANS += ans
print(ANS)

Submission status: Accepted

Solution code:
s = input()
n = len(s) - 1
answers = []
sl = [s[i] for i in range(len(s))]
for i in range(2 ** n):
    tmp = []
    for j in range(n):
        if ((i >> j) & 1):
            tmp.append(j)
    ll = ['*']*len(s)
    for k in tmp:
        ll[k] = '+'
    ans = []
    for k, _ in zip(sl, ll):
        ans.append(k)
        ans.append(_)
    ans = [_ for _ in ans if _ != '*']
    ans = ''.join(ans)
    ans = ans.split('+')
    ans = [int(_) for _ in ans if _ != '+']
    ans = sum(ans)
    answers.append(ans)
print(sum(answers))

Submission status: Accepted

Solution code:
class Number:
    value = ''
    plus = False
    
    def __init__(self, value, plus = False):
      self.value = value
      self.plus = plus

    def __str__(self) -> str:
        return '+' + str(self.value) if self.plus else str(self.value)


count = 0


def solve(numbers, k):
    global count
    if k >= len(numbers):
        x = ''.join([str(n) for n in numbers])
        count += sum(int(x) for x in x.split('+'))
        return

    b = []

    for i, n in enumerate(numbers):
        if i == k:
            b.append(Number(n.value, True))
        else:
            b.append(n)

    solve(numbers, k + 1)
    solve(b, k + 1)


s = input()

numbers = [Number(x) for x in s]

solve(numbers, 1)

print(count)

Submission status: Accepted

Solution code:
def solution(x,N,ans):
  return ans + int(N) if x == len(N)-1 else solution(x+1,N,ans) + solution(0,N[x+1:],ans+int(N[:x+1]))
 
print(solution(0,input(),0))

Submission status: Accepted

Solution code:
def solution(x,N,ans):
  if x == len(N)-1:
    return ans + int(N)
  res=solution(x+1,N,ans) + solution(0,N[x+1:],ans+int(N[:x+1]))
  return res

print(solution(0,input(),0))

Submission status: Accepted

Solution code:
s=input()
n=len(s)-1
l=[]
for i in range(n):
    l.append("+")
sum = 0

if len(s) < 2:
    sum = s

else:
    for i in range(2 ** n):
        plus = []
        tmp = ""
        ans = 0
        for j in range(n):
            if ((i>>j) & 1):
                plus.append(l[j])
            else:
                plus.append("")
        for i in range(n):
            tmp += s[i]+plus[i]
            if i == n-1:
                tmp+=s[i+1]
        tmp2 = tmp.split("+")
        for i in range(len(tmp2)):
            ans += int(tmp2[i])
        sum+=ans

print(sum)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = readline().rstrip().decode('utf_8')

def F(S):
	yield int(S)
	for i in range(len(S)-1):
		left = S[:i+1]
		right = S[i+1:]
		x = int(left)
		for y in F(right):
			yield x+y

print(sum(F(S)))

Submission status: Accepted

Solution code:
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

S = input()
N = len(S)-1
ans = 0
for n in range(2**N):
	b = Base_10_to_n(n,2).rjust(N,'0')
	tmp = []
	ind = 0
	for i in range(N):
		if b[i] == '1':
			tmp.append(int(S[ind:i+1]))
			ind = i+1
	tmp.append(int(S[ind:]))
	ans += sum(tmp)

print(ans)

Submission status: Accepted

Solution code:
s = input()
N = 1<<(len(s)-1)
c = 0
for one in range(N):
    tmp = ''
    for i in range(len(s)-1):
        tmp+=s[i]
        if one>>i & 1==1:
            tmp+='+'
    tmp+=s[len(s)-1]
    c+=sum([int(o) for o in tmp.split('+')])
print(c)

Submission status: Accepted

Solution code:
from itertools import product
s=input()
n=len(s)
ans=0
for p in product(['+',''],repeat=n-1):
    r=''
    for u,t in zip(s,p):
        r+=u+t
    r+=s[-1]
    ans+=eval(r)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

S = input()[:-1]  # 改行をなくす
n = len(S) - 1  # +を入れる事ができる場所の数

# bit全探索
P = []
for bit in range(0, 1<<n):  # 00 ~ 11
    plus = [""] * n
    for j in range(n):
        if bit>>j & 1:
            plus[j] = "+"
    P.append(plus)



ans = 0
if n == 0:
    print(int(S))
else:
    for plus in P:
        nums = []
        tmp = S
        pre = 0
        for i in range(n):
            if plus[i] == "+":
                nums.append(int(tmp[pre:i+1]))
                pre = i+1
            if i == n-1:
                nums.append(int(tmp[pre:]))
        ans += sum(nums)
    print(ans)

Submission status: Accepted

Solution code:
# arc 061 Many Formulas
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

S = read().rstrip().decode('utf-8')

def F(S):
    for i in range(2 ** (len(S) - 1)):
        operator_list = format(i, 'b').zfill(len(S)) # 最大桁は必ず0
        sum_ = 0
        num = 0
        for j, operator in zip(S, operator_list):
            if operator == "0":
                num = num * 10 + int(j)
            else:
                sum_ += num
                num = int(j)
        sum_ += num

        yield sum_

ans = sum(F(S))
print(ans)

Submission status: Accepted

Solution code:
# arc 061 Many Formulas
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

S = read().rstrip().decode('utf-8')

def F(S):
    total = 0
    for i in range(2 ** (len(S) - 1)):
        operator_list = format(i, 'b').zfill(len(S)) # 最大桁は必ず0
        sum_ = 0
        num = 0
        for j, operator in zip(S, operator_list):
            if operator == "0":
                num = num * 10 + int(j)
            else:
                sum_ += num
                num = int(j)
        sum_ += num

        total += sum_
    return total

ans = F(S)
print(ans)

Submission status: Accepted

Solution code:
S = input()

n=len(S)
sm=0

for i in range(2**(n-1)):
    tmp = [False]*(n-1)

    for j in range(n-1):
        if i >> j &1:
            tmp[j]=True

    result_list = []
    for s_n in range(len(S)):
        result_list.append(S[s_n])
        if s_n < len(tmp) and tmp[s_n]:
            result_list.append("+")

    res=""
    for x in result_list:
        res+=x
    sm+=eval(res)

print(sm)

Submission status: Accepted

Solution code:
import itertools
S = input()
L = [i for i in range(2*len(S)-1)]
i = 0
res = []
for j in range(len(L)):
    if j%2 == 0:
        L[j] = S[j//2]
    else:
        L[j] = ''
res.append(L)
def procedure(L,i,res):
    #L = List
    #i = number of '+' to put.(<=len(S)+1)
    #res = List witch we will accumulate [1,'',2,'+',3],[1,'+',2,'',3]
    Search_base = list(itertools.combinations([i for i in range(len(L)-1) if i%2 !=0], i))
    #[(1, 3), (1, 5), (3, 5)] for ([1,'',2,'',3,'',4],2)
    temp = []
    for element in L:
        temp.append(element)
    for j in range(len(Search_base)):
        for number in Search_base[j]:
            #print(number)
            temp[number] = '+'
        res.append(temp)
        #print('reboot')
        temp = [element for element in L]
        #print(temp)
    return res
Formulas = [procedure(L,i,[]) for i in range(len(S))]
#[[['1', '', '2', '', '3']], [['1', '+', '2', '', '3'], ['1', '', '2', '+', '3']], [['1', '+', '2', '+', '3']]]
#Formulas[1] = [['1', '', '2', '', '3']]
#Formulas[2] = [['1', '+', '2', '', '3'], ['1', '', '2', '+', '3']]
#Formulas[3] = [['1', '+', '2', '+', '3']]
#よって読み込みは：For liste in Formulas, for sous-liste in liste...

for liste in Formulas: #'+'i個ずつで見ていく。
    #スペースを除去して [1,2,'+',3] 除去する必要ないかも？🙄
    for sous_liste in liste:
        while '' in sous_liste:
            sous_liste.remove('')
#[[['1', '2', '3']], [['1', '+', '2', '3'], ['1', '2', '+', '3']], [['1', '+', '2', '+', '3']]]
res = 0
composant = ''
Found = []
for liste in Formulas:
    for sous_liste in liste:
        for i in range(len(sous_liste)):
            if sous_liste[i] != '+':
                composant += sous_liste[i] #'+'にぶち当たるまで、strの形でつなげて行く。
            elif sous_liste[i] == '+':
                res += int(composant)
                composant = '' #'+'にぶち当たったら、resに足して、リセットしてやり直す。
        if composant != '':
            Found.append(res+int(composant)) #Case 1への対応。
        else:
            Found.append(res)
        composant = ''
        res = 0
for element in Found:
    res += element
print(res)

Submission status: Accepted

Solution code:
def dfs(splitted: "the list of integer", a: int, b: int, depth: int) -> int:
  if len(splitted) == depth:
    return a + b
  else:
    # 左のdfs() 呼び出し -> +を挿入しなかったとき
    # 右のdfs() 呼び出し -> +を挿入したとき
    return dfs(splitted, a, b * 10, depth + 1) + dfs(splitted, a + b, splitted[depth], depth + 1)

s = [int(x) for x in input()]
print(dfs(s, 0, 0, 0))

Submission status: Accepted

Solution code:
def calc(s):
    yield int(s)
    for i in range(1, len(s)):
        a = int(s[:i])
        for b in calc(s[i:]):
            yield a + b
S = input()
result = sum(calc(S))
print(result)

Submission status: Accepted

Solution code:
s = input()
result_sum = 0 # 総和 
plus_count = len(s) - 1 # 集合の要素数

for bit in range(1 << plus_count): # bit全探索
  splitted_string = s[0] # 最初の数字を取る
  for iter_plus in range(plus_count):
    if bit & (1 << iter_plus): # ビットを立てる -> +を挿入する
      splitted_string += '+'
    splitted_string += s[iter_plus+1] # 適宜+が入った状態で数字列が構築
    
  # +で区切って,それぞれintに変換し合計
  splitted_integer = [int(x) for x in splitted_string.split('+')]
  result_sum += sum(splitted_integer)
print(result_sum)

Submission status: Accepted

Solution code:
s = input()
result_sum = 0
plus_count = len(s) - 1

for bit in range(1 << plus_count):
  splitted_string = s[0]
  for iter_plus in range(plus_count):
    if bit & (1 << iter_plus):
      splitted_string += '+'
    splitted_string += s[iter_plus+1]
  result_sum += eval(splitted_string)

print(result_sum)

Submission status: Accepted

Solution code:
s = input()
max_plus = len(s)-1
plus = [reversed(bin(i)[2:]) for i in range(2**max_plus)]
value_sum = 0
for i in plus:
    value = 0
    prov_s = s
    end_plus = 0
    for index, j in enumerate(i):
        if j == "1":
            cut_index = (1+index)*(-1)+end_plus
            value += int(prov_s[cut_index:])
            prov_s = prov_s[0:cut_index]
            end_plus += -1 * cut_index
    value_sum += value + int(prov_s)
print(value_sum)

Submission status: Accepted

Solution code:
s = input()
max_plus = len(s)-1
plus = [reversed(bin(i)[2:]) for i in range(2**max_plus)]
value_sum = 0
for i in plus:
    value = 0
    prov_s = s
    end_plus = 0
    for index, j in enumerate(i):
        if j == "1":
            cut_index = (1+index)*(-1)+end_plus
            value += int(prov_s[cut_index:])
            prov_s = prov_s[0:cut_index]
            end_plus += -1 * cut_index
    value_sum += value + int(prov_s)#(int(prov_s) if prov_s else 0)
print(value_sum)

Submission status: Accepted

Solution code:
s = input()
max_plus = len(s)-1
plus = [reversed(bin(i)[2:]) for i in range(2**max_plus)]
value_sum = 0

for i in plus:
    value = 0
    prov_s = s
    end_plus = 0
    for index, j in enumerate(i):
        if j == "1":
            cut_index = (1+index)*(-1)+end_plus
            value += int(prov_s[cut_index:])
            prov_s = prov_s[0:cut_index]
            end_plus += -1 * cut_index
    value_sum += value + (int(prov_s) if prov_s else 0)
print(value_sum)

Submission status: Accepted

Solution code:
s = 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[j] = "+"
    formula = ""
    for p_n, p_o in zip(s, op + [""]):  # 少々モヤッとする
        formula += (p_n + p_o)
    ans += eval(formula)
print(ans)

Submission status: Accepted

Solution code:
# import sys

# n = input()
# last = 0
# result = []

# if len(n) == 1:
#     print(int(n))
#     sys.exit()

# for i in range(len(n)-1):
#     print('i',i)
#     s1 = n[:i+1]
#     s2 = n[i+1:]
#     for j in range(len(s2)-1):
#         s21 = s2[:j+1]
#         s22 = s2[j+1:]
#         result.append(int(s1)+int(s21)+int(s22))
#     print('s1 s2',s1,s2)
#     print('sum ',int(s1)+int(s2))
#     result.append(int(s1)+int(s2))

# for i in range(len(n)):
#     print('i n[i]',i,n[i])
#     last += int(n[i])

# result.append(last)
# result.append(int(n))
# print(result)
# print(sum(result))

S = str(input())
N = len(S) - 1
 
res = 0
 
for i in range(1<<N):
    t = ''
    for j in range(N):
        t += S[j]
        if((i>>j&1) > 0): t += '+'
    t += S[-1]
    res += eval(t)
print(res)

Submission status: Accepted

Solution code:
s = input()
n=len(s)
ans=0
for i in range(2**(n-1)):
    bit=i
    a = []
    for k in range(n-1):
        a.append(bit % 2)
        bit //= 2
    t = ""
    for j in range(n-1):
        t += s[j]
        if (a[j]):
            t += "+"
    t+=s[-1]
    #print(t)
    ans += eval(t)
print(ans)

Submission status: Accepted

Solution code:
N = input()
n=len(N)-1
S = [0 for _ in range(n)]
combi = []

def makeCombination():
    rec(0)
    
def rec(i):
    if i == n:
        combi.append(S[:])
        return
    rec(i + 1)
    S[i] = 1
    rec(i + 1)
    S[i] = 0
    
makeCombination()

sum_N = 0
for l in combi:
    pre = 0
    for i in range(n):
        if l[i] == 1:
            sum_N += int(N[pre:i+1])
            pre = i+1
    
    sum_N += int(N[pre:])

print(sum_N)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

  for i in range(n - 1):
    if bit & (1 << i):
      f += '+'
    f += s[i + 1]

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

print(ans)

Submission status: Accepted

Solution code:
from itertools import product
s = input()
ans = 0
#opで+の候補生成
for op in product(["", "+"], repeat=len(s)-1):
    
    op = list(op)
    op.append("")
    #op=('', '+')の場合，1+""+2+"+"+5になる
    ans += eval(''.join( a + b for a, b in zip(s, op)))
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from itertools import combinations

s = input()
n = len(s)

def gen():
    l = []
    for i in range(n):
        l.append(s[i])
        l.append("")
    return l

res = 0
for r in range(n):
    for p in combinations(range(n-1),r):
        e = gen()
        for i in p:
            e[2*i+1] = "+"
        res += eval("".join(e))

print(res)

Submission status: Accepted

Solution code:
S = list(input())
def dfs(S, i, bind, ans): 
  if i == len(S):
    return ans + int(bind)
  return dfs(S, i + 1, S[i], int(bind) + ans) + dfs(S, i + 1, bind + S[i], ans)
print(dfs(S, 1, S[0], 0))

Submission status: Accepted

Solution code:
from itertools import product
 
S = input()
n = len(S)
 
ans = 0
for P in product(["+",""],repeat=n-1):
    res = ""
    for s,p in zip(S,P):
        res += s+p
    res += S[-1]
    ans += eval(res)
print(ans)