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()
ans=0
for i in range(2**(len(s)-1)):
	a=int(s[0])
	b=0
	for j in range(len(s)-1):
		if i&(1<<j)==0 :
			a=a*10+int(s[j+1])
		else:
			b+=a
			a=int(s[j+1])
	ans+=a+b
print(ans)

Submission status: Accepted

Solution code:
x = input()
l = len(x)
y_original = x[0]
s = 0

for i in range(1,l):
  y_original += 't'+x[i]
  
for i in range(2**(l-1)):
  y = y_original
  for j in range(l-1):  
    if ((i>>j) & 1) == 1:
      z = list(y)
      z[(2*l-3)-2*j] = '+'
      y = ''.join(z)
  y2 = y.replace('t','')
  s += eval(y2)
print(s)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
m = [int(s[0])]
if l >= 2:
  for j in range(1,l):
    y = 0
    for k in range(1,j+1):
      y += m[k-1] + int(s[k:j+1]) *(2** (k-1))
    x = y + int(s[:j+1])
    m.append(x)
print(m[-1])

Submission status: Accepted

Solution code:
def main():
    S = input()
    n = len(S) - 1
    ans = 0

    for i in range(2 ** n):
        c = S[0]
        for j in range(n):
            if (i >> j) & 1 == 1:
                c += "+"
            c += S[j + 1]
        t = list(map(int, c.split("+")))
        ans += sum(t)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    S = input()
    n = len(S) - 1
    ans = 0

    if n == 0:
        print(int(S))
        return

    for i in range(2 ** n):
        plus_lst = [0] * n
        for j in range(n):
            if (i >> j) & 1 == 1:
                plus_lst[n - 1 - j] = 1  # 0: "", 1: "+"

        res = 0
        num = S[0]
        for j in range(n):
            if plus_lst[j] == 0:
                num += S[j + 1]

            if plus_lst[j] == 1:
                res += int(num)
                num = S[j + 1]

            if j == n - 1:
                res += int(num)

        ans += res

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

M = 2#bit探査をしたい時はM=2
def dfs(A):
    global ans
    # 終端条件 --- l 重ループまで回したら処理して打ち切り
    if len(A) == l:
        memo=0
        for i in range(l):
            if A[i]==1:
                ans+=int(S[memo:i+1])
                memo=i+1
        ans+=int(S[memo:])
        return
    for v in range(M):
        A.append(v)
        dfs(A)
        A.pop() # これが結構ポイント

dfs([])
print(ans)

Submission status: Accepted

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

s = str(input())
n = len(s) - 1
answer = 0
for i in range(2 ** n):
    operation = [""] * n
    for j in range(n):
        if (i >> j) & 1:
            operation[n - 1 -j] = "+"
    
    formula = ""
    for p_n, p_o in zip(s, operation + [""]):
        formula += (p_n + p_o)
    
    answer += eval(formula)

print(answer)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
sum = 0
for b in range(1 << (n-1)):
    t = 0
    for i in range(n-1):
        if b & (1 << i):
            sum += int(s[t:i+1])
            t = i+1
    sum += int(s[t:])
print(sum)

Submission status: Accepted

Solution code:
S=input()
res=[]
for i in range(2**(len(S)-1),2**(len(S))):
    tmp=''
    for j in range(len(S)):
        if j==len(S)-1:
            tmp+=S[j]
        elif (str(bin(i))[3:])[j]=='1':
            tmp+=S[j]
        else:
            tmp+=S[j]+'+'
    if tmp[-1]=='+':
        tmp=tmp[:-1]
    res.append(eval(tmp))
print(sum(res))

Submission status: Accepted

Solution code:
#bit使うversion
S = input()
N = len(S)
res = 0
for i in range(2**(N-1)):
  formula = ""
  for j in range(N-1):
    if (i>>j) & 1: 
      formula += S[j]
      formula += "+"
    else:
      formula += S[j]
  formula += S[N-1]
  res += eval(formula)
print(res)

Submission status: Accepted

Solution code:
#itertoolsを使うversion
import itertools
S = input()
N = len(S)
res = 0
for ptr in itertools.product([0,1], repeat=(N-1)):
  formula = ""
  for i in range(N-1):
    if ptr[i] == 1:
      formula += S[i]
      formula += "+"
    else:
      formula += S[i]
  formula += S[N-1]    
  res += eval(formula)
print(res)

Submission status: Accepted

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

ans = 0
for i in range(2 ** (N - 1)):
    ptn = [' '] * (N - 1)
    for j in range(N - 1):
        if (i >> j) & 1:
            ptn[len(ptn) - j - 1] = '+'

    formula = ''.join([n + op for n, op in zip(list(S), ptn + [''])]).replace(' ', '')
    ans += eval(formula)

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
S = input()
n = len(S) - 1
pattern = []
ans = 0

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

for i in range(2 ** n):
    X = S[0]
    for j in range(n):
        if pattern[i][j] == "+":
            ans += int(X)
            X = S[j+1]
        else:
            X += S[j+1]
    ans += int(X)
print(ans)

Submission status: Accepted

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

sl=[]
for i in range(ls):
    sl.append(s[i])
nl=[int(j) for j in sl]

#"+"が入りうる箇所はls-1箇所ある
sumn=[]
#i=0~3
#i=0x00,0x01,0x10,0x11
for i in range(2**(ls-1)):
    #j=0~1
    mul=1
    for j in range(ls-1):
        number=mul*nl[ls-j-1]
        if ((i>>j)&1):
            mul=1
        else:
            mul*=10
        sumn.append(number)
    sumn.append(nl[0]*mul)
print(sum(sumn))

Submission status: Accepted

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

Submission status: Accepted

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

tot = 0

for i in range(2**(n-1)):
  f = S[0]
  for j in range(n-1):
       if ((i >> j) & 1):
        f += " "
       f += S[j+1]
  
  tot += sum(map(int, f.split(" ")))

print(tot)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    ans = 0
    S = SI()
    bit_len = len(S)-1
    for i in range(2**bit_len):
        ls = ["" for _ in range(bit_len)]
        for j in range(bit_len):
            if (i >> j) & 1:
                ls[j] = "+"
                
        calc = []
        for n in range(len(S)):
            calc.append(S[n])
            if n != len(S)-1:
                calc.append(ls[n])
        ans += eval("".join(calc))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

S = list(input())
N = len(S)
# print('S:',S)

#onとoff
a = ['nashi','+']
Ls = list(itertools.product(a, repeat=N-1))
# print('Ls:',Ls)

out=0
dammy=[]
for L in Ls:
    # print('L,out:',L,out)
    dammy=[]
    for i in range(N):
        # print('dammy:',dammy)
        if i==N-1:
            dammy.append(S[i])
            out+=int(''.join(dammy))
            dammy=[]
        elif L[i] == 'nashi':
            dammy.append(S[i])
        else:
            dammy.append(S[i])
            out+=int(''.join(dammy))
            dammy=[]

print(out)

Submission status: Accepted

Solution code:
a = [int(x) for x in input()]
n = len(a)

sum_val = 0
for i in range(1 << (n - 1)):
    tmp_val = a[0]
    for j in range(n - 1):
        if (i >> j) & 1:
            sum_val += tmp_val
            tmp_val = a[j + 1]
        else:
            tmp_val = tmp_val * 10 + a[j + 1]
    sum_val += tmp_val
print(sum_val)

Submission status: Accepted

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

cnt = 0
for i in range(1 << len(S)-1):
    y = None
    x = 0
    for j in range(len(S)):
        x -= 1
        if x == -len(S):
            cnt += int(S[x:y])
        elif i & (1 << j):
            cnt += int(S[x:y])
            y = x

print(cnt)

Submission status: Accepted

Solution code:
from itertools import product
s = input()
l = len(s)
ans = 0
for pattern in product(range(2), repeat=l-1):
  #print(pattern)
  tempsum = 0
  temp = [s[0]]
  for i in range(l-1):
    if pattern[i] == 0:
      temp.append(s[i+1])
    else:
      tempsum+=int("".join(temp))
      temp = [s[i+1]]
  tempsum+=int("".join(temp))
  #print(tempsum)
  ans+=tempsum
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
def rec(op_index, part_s):
    if op_index == n - 1:
        return sum(map(int, part_s.split('+')))
    part_s1 = '{}{}'.format(part_s, s[op_index+1])
    part_s2 = '{}+{}'.format(part_s, s[op_index+1])
    return rec(op_index+1, part_s1) + rec(op_index+1, part_s2)
 
print(rec(0, s[0]))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(int(1e8))


s = input()
n = len(s)

def rec(op_index, part_s):
    if op_index == n - 1:
        return sum(map(int, part_s.split('+')))
    part_s1 = '{}{}'.format(part_s, s[op_index+1])
    part_s2 = '{}+{}'.format(part_s, s[op_index+1])
    return rec(op_index+1, part_s1) + rec(op_index+1, part_s2)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    s = input()
    N = len(s)
    res = 0
    for bit in range(1 << N - 1):
        tmp = 0
        for i in range(N - 1):
            tmp *= 10
            tmp += int(s[i])
            if bit & (1 << i):
                res += tmp
                tmp = 0
        tmp *= 10
        tmp += int(s[-1])
        res += tmp
    
    print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S = input()
result = 0
space_cnt = len(S)-1
for i in range(2 ** space_cnt):
    space = [""] * space_cnt
    for j in range(space_cnt):
        if ((i >> j) & 1):
            space[space_cnt -1 -j] = "+"
    formula = ""
    for i in range(space_cnt):
        formula += S[i]+space[i]
    formula += S[-1]
    result += eval(formula)
print(result)

Submission status: Accepted

Solution code:
s = list(input())

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# 入力
s = input()
num = len(s)-1
ret = 0

for i in range(2**num):
    st = 0
    for j in range(num):
        if (i >> j) & 1:
            ret += int(s[st:j+1])
            st = j+1
    ret += int(s[st:])

print(ret)

Submission status: Accepted

Solution code:
s = input()
#word = []
#for i in range(len(s)):
#    word.append(int(s[i]))
interval = len(s) - 1
ans = 0
for i in range(2**interval):
    f = list(s)
    for j in range(interval):
        if (i & (1<<j)):
            f[j] = f[j] + '+'
    f = "".join(f)
    #print(f)
    if '+' in f:
        #print(f.split('+'))
        ans = ans + sum(list(map(int,f.split('+'))))
    else:
        ans = ans + int(f)
print(ans)

Submission status: Accepted

Solution code:
n = [int(x) for x in input()]
op_cnt = len(n) - 1  
out=0
for i in range(2 ** op_cnt):
    op = ["+"] * op_cnt  
    box=""
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "" 
        box=""  
    for a,b in zip(n,op+[""]):
        box+=(str(a)+b)
    box=box.split('+')
    ou=0
    for k in box:
        out+=int(k)
print(out)

Submission status: Accepted

Solution code:
n = input()

sumP = 0

for i in range(2 ** (len(n)- 1)):   #間の数、植木算の全探索
    plus=[]                         #＋位置のリスト
    for j in range(len(n) - 1):     #今調べるやつがどの位置に+をもつか
        if i >> j & 1 :             #iをj回シフトして、0か1を判定する。1なら、そこに+があるため格納したい
            plus.append(j)          

    middle_index = 0

    for pos in plus:
        sumP += int(n[middle_index:pos + 1])       #前半部分を和
        middle_index = pos + 1
    sumP += int(n[middle_index:])                  #後半部分を和

print(sumP)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    s = set()
    for i in range(2**len(S)):
        tmp = S[0]
        for j in range(1,len(S)):
            if (i >> j) & 1:
                tmp += '+' + S[j]
            else:
                tmp += S[j]
        s.add(tmp)
    ans = 0
    for a in s:
        ans += eval(a)
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(2**n):
    num = s[0]
    for j in range(n):
        if (i >> j) & 1:
            num += "+"
        num += s[j + 1]
    ans += sum(map(int, num.split("+")))
print(ans)

Submission status: Accepted

Solution code:
s=input()
# ss=int(s)
n=len(s)
ans=int(s)
for bit in range(1<<(n-1)):
    if bit==0 : continue
    now=[] #+の位置
    for i in range(n):
        if bit>>i &1 :
            now.append(i)

    for i in range(len(now)-1):
        ans+=int(s[now[i]+1:now[i+1]+1])
    ans+=int(s[:now[0]+1])
    ans+=int(s[now[-1]+1:])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s) - 1
a = 0
for i in range(2 ** n):
    f = s[0]
    for j in range(n):
        if ((i >> j) & 1):
            f += "+"
        f += s[j + 1]
    a += sum(map(int, f.split("+")))

print(a)

Submission status: Accepted

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

def value(m):
    num = s[0]
    ans = 0
    for i in range(1, n):
        t = (m>>(i-1)) & 1
        if t ==1:
            ans += int(num)
            num = s[i]
        else:
            num = num + s[i]
    ans += int(num)
    return ans

count = 0
for i in range(2**(n-1)):
    count +=value(i)

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from itertools import product
S = input()
n = len(S)
bit = list(product([0, 1], repeat = n - 1))
ans = 0
for state in bit:
    s = S[0]
    for i in range(len(state)):
        if state[i] == 1:
            s += '+' + S[i + 1]
        else:
            s += S[i + 1]
    ans_list = list(map(int,s.split('+')))
    for a in ans_list:
        ans += a
print(ans)

Submission status: Accepted

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

ans = 0
p = 1
c = pow(2, n - 1)

for i in range(n):
    for j in range(i, n):
        if j == i:
            ans += p * c * int(S[-j - 1])
            c //= 2
        else:
            ans += p * c * int(S[-j - 1])
    p *= 10

print(ans)

Submission status: Accepted

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

from itertools import product
LS = list(product([0,1], repeat=N-1))
out = 0
for L in LS:
    T = S[0]
    for i in range(N-1):
        if L[i]==1:
            T += "+"+S[i+1]
        else:
            T += S[i+1]
    A = list(map(int,T.split("+")))
    out += sum(A)
print(out)

Submission status: Accepted

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

def calc(T):
    N = len(T)
    t = 0
    ans = 0
    tmp = 0
    while T[t]!="=":
        if T[t]=="+":
            ans += tmp
            tmp = 0
            t+=1
            continue
        else:
            tmp = 10*tmp+int(T[t])
            t+=1
    ans += tmp
    return ans

from itertools import product
LS = list(product([0,1], repeat=N-1))
out = 0
for L in LS:
    T = S[0]
    for i in range(N-1):
        if L[i]==1:
            T += "+"+S[i+1]
        else:
            T += S[i+1]
    T += "="
    out += calc(T)
print(out)

Submission status: Accepted

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


ans = 0

for i in range(2 ** (n-1)):
    s_temp = s.copy()
    numbers = [s_temp.pop(0)]
    for j in range(n-1):
        if (i >> j) & 1:
            numbers.append(s_temp.pop(0))
        else:
            numbers[len(numbers)-1] = numbers[len(numbers)-1] + s_temp.pop(0)

    numbers = list(map(int, numbers))

    ans += sum(numbers)

print(ans)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nums = input()

op_cnt = len(nums) -1

sum = 0

for i in range(2 ** op_cnt):
    op = [""] * op_cnt
    for j in range(op_cnt):
        if(i >> j & 1):
            op[j] = "+"
    # print(op)

    formula = ""

    for p_n,p_o in zip(nums,op + [""]):
        formula += (p_n + p_o)

    sum += eval(formula)

print(sum)

Submission status: Accepted

Solution code:
S = input()
size = len(S)
patterns = []
ans = 0

def flagfun(flag):
    if len(flag) == size:
        patterns.append(flag+"1")
        return
    
    flagfun(flag+'0')
    flagfun(flag+'1')

flagfun('')

for pattern in patterns:
    lastKey = 0
    for k, v in enumerate(pattern):
        if v == "1":
            if len(S[lastKey:k]) != 0:
                ans += int(S[lastKey:k])
                lastKey = k

print(int(ans/2))

Submission status: Accepted

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

ans = 0
for i in range(2 ** (N - 1)):
    nums = []
    num = ''
    for j in range(N):
        num += S[j]
        if (i >> j) & 1:
            nums.append(int(num))
            num = ''
    else:
        nums.append(int(num))
    ans += sum(nums)

print(ans)

Submission status: Accepted

Solution code:
def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split("+"))))
 
    # 式 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 sum(list(map(int, f.split("+"))))

    # 式 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:
import sys
S = list(input())
T = [int(a) for a in S]
N = len(T)

if N == 1:
  print(T[0])
  sys.exit()
  
ans = 0
for i in range(2 ** (N-1)):
  i_ = i
  j = 1
  tmp = T[0]
  while j < N:
    #print(i,i_,j,N)
    if i_ % 2 == 0:
      tmp *= 10
      tmp += T[j]
    if i_ % 2 == 1:
      ans += tmp
      tmp = T[j]
    i_ = i_ >> 1
    j += 1
  ans += tmp
  #print(ans,i)
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = [1]
for i in range(20):
    cnt.append(sum(cnt))
ans = 0
for i in range(len(s)):
    for f in range(i + 1, len(s) + 1):
        num = int(s[i:f])
        ans += num * cnt[i] * cnt[len(s) - f]
print(ans)

Submission status: Accepted

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

for i in range(2 ** N):
  pw = 0
  for j in range(N):
    if ((i >> j) & 1):
      res += int(S[pw:j+1])
      pw = j+1
  res += int(S[pw:])
  
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

S = input().strip()
result = 0
num = list()
for i in range(len(S)):
    num.append(int(S[i]))

for b in range(2**(len(S)-1)):
    b_str = format(b, 'b').zfill(len(S)-1)
    sum = 0
    for i in range(len(num) - 1):
        if b_str[i] == '0':
            result += sum * 10 + num[i]
            sum = 0
        else:
            sum = sum * 10 + num[i]
    result += sum * 10 + num[-1]

print(result)

Submission status: Accepted

Solution code:
s = input()

res = 0
for i in range(2**(len(s)-1)):
    pos = 0
    for j in range(len(s)-1):
        if (i >> j) & 1:
            res += int(s[pos:j+1])
            pos = j + 1
    res += int(s[pos:])

print(res)

Submission status: Accepted

Solution code:
s = list(input())
n = len(s) - 1 
p = 0
for i in range(2**n):
    m = int(s[0])
    x = i
    for j in range(n):
        if x % 2 != 0:
            p += m
            m = int(s[j+1])
        else:
            m = m * 10 + int(s[j+1])
        x = x // 2
    p += m
print(p)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s) - 1
a = 0
for i in range(2 ** n):
    f = s[0]  
    for j in range(n):  
        if ((i >> j) & 1):
            f += "+"
        f += s[j + 1]
    a += sum(map(int, f.split("+")))

print(a)

Submission status: Accepted

Solution code:
n=input()
s=len(n)
ans=0
def f(i,cur=""):
    global ans
    #print(i,cur)
    if(i==s):
        ans+=eval(cur)
        return
    f(i+1,cur+n[i])
    if(i!=s-1):f(i+1,cur+n[i]+'+')
f(0)
print(ans)

Submission status: Accepted

Solution code:
S=input()
ans=0
for i in range(2**(len(S)-1)):
    a=bin(i)
    b=a[2:]
    while len(b)<len(S)-1:
        b="0"+b
    k=0
    temp=0
    for j in range(len(b)):
        if b[j]==str(1):
            temp+=int(S[k:j+1])
            k=j+1
    if S[k:len(S)]!="":    
        temp+=int(S[k:len(S)])
    ans+=temp
print(ans)

Submission status: Accepted

Solution code:
def solve(S):
    n = len(S) - 1
    result = 0
    for i in range(2**n):
        sum_i = 0
        now = 0
        for j in range(n+1):
            now = now * 10 + int(S[j])
            if j < n:
                if ((i >> j) & 1):
                    sum_i += now
                    now = 0
            else:
                sum_i += now
        result += sum_i
    return result
S = input()
print(solve(S))

Submission status: Accepted

Solution code:
S = list(input())
l = len(S)-1
su = 0
for i in range(2**l):
    q = S[0]
    for j in range(l):
        if (i>>j) & 1:
            q += '+' + S[j+1]
        else:q += S[j+1]
    su += eval(q)
print(su)

Submission status: Accepted

Solution code:
S = input()

N = len(S)

ans = 0
for i in range(2**(N-1)):
    tmp = S[0]
    for j in range(len(S)-1):
        flag = (i >> j) & 1

        if flag:
            tmp += "+" + S[j+1]
        else:
            tmp += S[j+1]

    num = list(map(int, tmp.split("+")))
    ans += sum(num)

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# n=int(input())
# lst=[int(input()) for _ in range(n)]
# ans1=sum(lst)
# max1=max(lst)
# print(ans1)
# print(0 if max1<=ans1-max1 else max1-(ans1-max1))
s=input()
n=len(s)
l=n-1
lst_1=[]
for i in range(1<<l):
    lst=[]
    for j in range(l):
        if ((i>>j)&1):
            lst.append("+")
        else:lst.append("_")
    lst_1.append(lst)

ans=0
for i in range(1<<l):
    temp=s[0]
    for j in range(l):

        if lst_1[i][j]=="+":
            temp+="+"
        temp += s[j+1]
    ans+=sum(map(int,temp.split("+")))
print(ans)

Submission status: Accepted

Solution code:
import copy
a = list(input())
N=len(a)
bit_list =[]
for i in range(2**(N-1)):
  b = format(i,"09b")
  b = b[::-1]
  bit_list.append(b)
count = 0
for i in range(2**(N-1)):
  a_list = []
  a_list=copy.copy(a)
  num = 0
  num_li =[a[0]]
  for k,j in enumerate(bit_list[i]):
    if j == '1':
      a_list.insert(k+1+num,"+")
      num+=1
  for j,i in enumerate(a_list):
    if j>0:
      num_li[0] +=i
  count+= eval(num_li[0])
print(count)

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)-1
ans = 0
l = []
for i in range(2**n):
    ss = s.copy()
    for j in range(n):
        bit = (i >> j) & 1
        if bit == 1:
            ss.insert(n - j, '+')

    ans += eval(''.join(ss))      

 
print(ans)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
def dfs(i,f):
    if i==n-1:#iがn-1になったら，全数字を区切って+を加えてint型に変換して合計する
        return sum(list(map(int,f.split("+"))))
    return dfs(i+1,f+s[i+1])+dfs(i+1,f+ "+"+s[i+1]) # 文字列で次の数字をそのまま連結するパターンと、+で区切るパターン
# 初期値でsの一文字目を入れておく
print(dfs(0,s[0]))

Submission status: Accepted

Solution code:
def RecSum(S, i):
    if i > len(S) - 1:
        return eval(''.join(S))
    SS = S.copy()
    SS.insert(i, "+")
    return RecSum(S, i+1) + RecSum(SS, i+2)


S = list(input())
print(RecSum(S, 1))

Submission status: Accepted

Solution code:
data = input()
length = len(data)

between = length - 1
num = 0
for i in range(2**between):
    list_data = list(data)
    for j in range(between):
        if ((i >> j) & 1):
            list_data[between - j] = '+'+list_data[between - j]
    hoge = ''.join(list_data).split('+')
    for k in hoge:
        num += int(k)

print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
num = len(S)-1 #符号を加えられる隙間の数
x=[]

for i in range(2**num):
    tmp=['-']*num #すべてマイナスを初期値として用意しておく
    for j in range(num):
        if ((i >> j) &1):
            tmp[num-1-j] ='+'
    x.append(tmp)
        
#print(x) #これで全符号パターンができた

ans =0

for i in range(len(x)):
    now =S[0]
    for j in range(len(x[i])):
        if x[i][j] == '-':
            now += S[j+1:j+2]
        else:
            now = now + x[i][j] + S[j+1:j+2] 
    #print(now) #プラスの記号を挿入した表記
    ans += eval(now)

print(ans)

Submission status: Accepted

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

def part_sum(S, clist):
    start = 0
    sum = 0
    for c in clist:
        sum += int(S[start:c])
        start = c
    sum += int(S[start:])
    return sum

def main():
    s = input()
    # output = int(input())
    length = len(s)
    numlist = list(range(1, length))
    ans = 0
    for i in range(length):
        combi = list(itertools.combinations((numlist), i))
        for clist in combi:
            clist = list(clist)
            ans += part_sum(s, clist)
    print(ans)
    # if ans == output:
    #     print('OK')
    # else:
    #     print('No')
                
            
        
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/arc061/tasks/arc061_a
# 復習課題
# シフト演算を用いてリファクタリングせよ。

S = list(input())
ans = 0

for i in range(2**(len(S)-1)):
    p = list(bin(i))
    flag = ['0' for _ in range(len(S) - len(p) + 1)] + p[2:]
    l = 0
    for j in range(len(S)-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 = list(input())
ans = 0

for i in range(2**(len(S)-1)):
    tmp = S
    p = list(bin(i))
    flag = ['0' for _ in range(len(S) - len(p) + 1)] + p[2:]
    nums = []
    l = 0
    for j in range(len(S)-1):
        if flag[j] == '1':
            nums.append("".join(tmp[l:j+1]))
            l = j+1
    nums.append("".join(tmp[l:]))
    for n in nums:
        ans += int(n)

print(ans)

Submission status: Accepted

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

#calc("",1234) = calc("1",234) + calc("1+"",234)
#calc("1",234) = calc("12",34) + calc("12+",34)
#calc("12+",34) = calc("12+3",4) + calc("12+3+",4)
#calc("12+3",4) = calc("12+34")
def calc(express,i):
    if i == len(nums):
        return sum(list(map(int,express.split("+"))))
    return calc(express + nums[i],i+1) + calc(express + "+"+ nums[i] ,i+1) 

nums = list(input())
print(calc(nums[0],1))

Submission status: Accepted

Solution code:
import itertools
s = input()
ans=0
for i in list(itertools.product([0,1], repeat=len(s)-1)):
  b = 0
  a = s[0]
  for j in range(len(s)-1):
    if i[j] == 0:
      a+=s[j+1]
    else:
      b+=int(a)
      a=s[j+1]
  b+=int(a)
  ans+=b
print(ans)

Submission status: Accepted

Solution code:
def gen(s):
    yield int(s)
    for i in range(len(s)-1):
        l = s[:i+1]
        r = s[i+1:]
        x = int(l)
        for y in gen(r):
            yield x + y
s = input()
print(sum(gen(s)))