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:
#!/usr/bin/env python3
import sys


def solve(S: int):
    s_array = list(str(S))
    N = len(s_array) - 1

    sum = 0
    for bit in range(2 ** N):
        num_string = s_array[0]
        for i in range(N):
            if bit & 1 << i:
                sum += int(num_string)
                num_string = s_array[i + 1]
            else:
                num_string += s_array[i + 1]
        sum += int(num_string)
    print(sum)
    
    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 = int(next(tokens))  # type: int
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Accepted

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


def solve(S: int):
    s_array = list(str(S))
    N = len(s_array) - 1

    sum = 0
    for bit in range(2 ** N):
        num_string = s_array[0]
        for i in range(N):
            if not (bit & 1 << i):
                sum += int(num_string)
                num_string = ""
            num_string += s_array[i + 1]
        sum += int(num_string)
    print(sum)
    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 = int(next(tokens))  # type: int
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys

def main():
    S  = input()
    n  = len(S) - 1
    sum = 0
    for i in range(2 ** n):
        ichi = 0
        for j in range(n): 
            if ((i >> j) & 1):
                sum += int(S[ichi:j+1])
                ichi = j+1
        sum += int(S[ichi:n+1])
    print(sum)



if __name__ == '__main__':
    main()

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[n-1-j] = ""
  
  a = ""
  for N,P in zip(s, op+[""]):
    a += N + P
  ans += eval(a)
print(ans)

Submission status: Accepted

Solution code:
S = [int(n) for n in list(input())]
n = len(S)
sbox = []

def f(i, box, k):
  if i==n-1:
    box += k
    sbox.append(box)
  else:
    f(i + 1, box+k, S[i+1])
    f(i + 1, box, 10*k + S[i+1])
    
f(0, 0, S[0])
print(sum(sbox))

Submission status: Accepted

Solution code:
s = input()
ln = len(s) - 1
pat = []

for i in range(2**ln):
    tmp = ['']
    for j in range(ln):
        if i >> j & 1:
            tmp.append('+')
        else:
            tmp.append('')
    pat.append(tmp)

ans = 0
for p in pat:
    tmp = ''
    for i, j in zip(p, s):
        tmp += i+j
    ans += eval(tmp)

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
S = list(input())

l = len(S)
anss = []

for i in range(1<<l-1):
	i = list("{:b}".format(i).zfill(l-1))
	ans = []
	S_ = S.copy()
	ans.append(S_.pop(0))
	while S_ != []:
		if i.pop(0) == "1":
			ans.append("+")

		ans.append(S_.pop(0))

	anss.append(eval("".join(ans)))

print(sum(anss))

Submission status: Accepted

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


def sr(): return sys.stdin.readline().rstrip()


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


S = sr()
SIZE = len(S)
ans = 0


def dfs(depth, p_list):
    global ans

    if depth == SIZE - 1:
        sum_list = []
        T = S
        for j, p in enumerate(p_list):
            if p:
                sum_list.append(int(S[SIZE - len(T): j + 1]))
                T = S[j + 1:]
        if T:
            sum_list.append(int(T))
        # print(p_list, sum_list, T)
        ans += sum(sum_list)

        return

    for i in range(2):
        p_list[depth] = i
        dfs(depth + 1, p_list)


def main():

    p_list = [0] * (SIZE - 1)
    dfs(0, p_list)

    print(ans)


main()

Submission status: Accepted

Solution code:
S = input()

def dfs(a,s,n): #a:今まで計算した分、s:数字(文字)、n:左から何番目の位置に+を入れるか入れないか
    if(len(s) == 1):
        return int(s)
    elif(len(s) == n+1):
        return int(s[len(s)-1]) + int(s[:len(s)-1]) + int(s) + 2*a
    else:
        return dfs(a,s,n+1) + dfs(a+int(s[:n]),s[n:],1)

print(dfs(0,S,1))

Submission status: Accepted

Solution code:
s = str(input())
li = list(s)
sum_ = 0
# 2こうえんざんのアルゴリズム。
for i in range(1 << len(s) -1):
    r =''
    for j in range(len(s) ):
        r += li[j]
        if i & (1 << j):
            r += '+'

    sum_ += eval(r)
print(sum_)

Submission status: Accepted

Solution code:
import numpy as np
S = np.array(list(input()), dtype=str)
l = len(S) - 1
print(sum(eval("".join(np.vstack((np.char.replace(np.char.replace(np.array(list(format(n, "0%db" % (l + 1))), dtype=str), "0", ""), "1", "+"), S)).T.ravel())) for n in range(1 << l)))

Submission status: Accepted

Solution code:
from functools import lru_cache


@lru_cache(maxsize=4096)
def solve(idx, S, num):
    if len(S) == 1 or len(S) == idx:
        return int(S) + num
    # +を入れるパターン
    ret = solve(1, S[idx:], num+int(S[:idx]))
    # +を入れないパターン
    ret += solve(idx+1, S, num)
    return ret


S = input()
print(solve(1, S, 0))

Submission status: Accepted

Solution code:
S = input()
op = len(S) - 1
res = 0
for i in range(2 ** op):
    string = ""
    bag = []
    for j in range(op):
        if (i >> j) & 1 == 1:
            bag.append("+")
        else:
            bag.append("")
    for s, b in zip(S, bag + [""]):
        string = string + s + b
    res += eval(string)
print(res)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
S = list(input())

l = len(S)
ans = []

for i in range(1<<l-1):
	anss = []
	i = list("{:b}".format(i).zfill(l-1))
	SS = S.copy()
	anss.append(SS.pop(0))
	while SS != []:
		if i.pop(0) == "1":
			anss.append("+")
		anss.append(SS.pop(0))

	ans.append(eval("".join(anss)))


print(sum(ans))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
S = list(input())

l = len(S)

anss = []
for i in range(1<<l-1):
	ans = []
	i = list("{:b}".format(i).zfill(l-1))
	#print(i)
	S_ = S.copy()
	ans.append(S_.pop(0))
	while S_ != []:
		if i.pop(0) == "1":
			ans.append("+")
		ans.append(S_.pop(0))
		#print(ans)
	anss.append(eval("".join(ans)))
#print(anss)
print(sum(anss))

Submission status: Accepted

Solution code:
N = input()
b = N[0]
c = 0
for i in range(2**(len(N)-1)):
    a = "0"*20+str(bin(i))[2:]
    for j in range(1,len(N)):
        if a[-j] == "0":
            b += N[j]
        elif a[-j] == "1":
            c += int(b)
            b = N[j]
    c += int(b)
    b = N[0]
print(c)

Submission status: Accepted

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

s = input()
n = len(s)

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

Submission status: Accepted

Solution code:
s=input()

length=len(s)

keta=len(s)

gross=0

for i in s:
    i=int(i)
    
    gross+=2**(len(s)-keta)*i*(2**(keta-4)*(5**(keta-1)-1)+10**(keta-1))
    
    keta-=1
    
print(int(gross))

Submission status: Accepted

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

ans = 0

for i in range(2**(n-1)):
    s_temp = s[0]
    for j in range(n-1):
        if i>>j & 1:
            s_temp += "+" + s[j+1]
        else:
            s_temp += s[j+1]
    ans += eval(s_temp)

print(ans)

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(k) for k in input().split()]
def base10to(n, b):
    if (int(n/b)):
        return base10to(int(n/b), b) + str(n%b)
    return str(n%b)
#template
S = input()
ans = 0
n = len(S)
for i in range(2**(n-1)):
    k = base10to(i,2)
    tmp = S[0]
    if len(k)<n-1:
        for j in range(n-1-len(k)):
            k = '0'+k
    for l in range(1,n):
        if k[l-1] == '0':
            tmp+= S[l]
        else:
            ans += int(tmp)
            tmp = S[l]
    ans += int(tmp)
print(ans)

Submission status: Accepted

Solution code:
s = str(input())

#import
import itertools

#resultcounter
count = 0

# シグマ
for i in range(len(s)):
    # 全挟み込みかたを記述
    bet = len(s) -1
    #betのindex
    betindex = [i for i in range(bet)]
    

    # betの組み合わせ
    for v in itertools.combinations(betindex, i):
            # str分割のリストの入れものの準備
        li = []
        #liの要素
#         li[0] = s[:v[0]+ 1]
#         li[1] = s[v[0]+ 1:v[1]+ 1]
#         .......

#イテレーションを回すためにlist化
        v = list(v)
        v = [i+1 for i in v]
        v.insert(0, 0)
        v += [len(s)]
        for j in range(len(v) - 1):
            li += [s[v[j]:v[j+1]]]
            
#             print(li)
        li = [int(i) for i in li]
        count += sum(li)
            
            
print(count)

Submission status: Accepted

Solution code:
"""
def bs(num_array, max_element, min_element):
    from collections import deque
    if(num_array == max_element - min_element + 1):
        que = deque(deque([i for i in range(min_element, max_element+1, 1)]))
        return que
    else:        
        # If min_element is not used
        que = deque([deque([])])
        que.extend(bs(num_array, max_element, min_element + 1))
        # IF min_element is used
        subset_yes = bs(num_array-1, max_element, min_element + 1)
        for e in subset_yes:
            e.appendleft(min_element)
        
        que.extendleft(subset_yes)
        return que
"""
def solve(S):
    from itertools import combinations
    from collections import deque
    n = len(S)
    answer = 0
    for i in range(n):
        for item in combinations(list(range(1, n, 1)), i):
            char_list = [c for c in S]
            que = deque(item)
            while que:
                index = que.pop()
                char_list.insert(index, " ")
            split_s = ""
            for c in char_list:
                split_s += c
            #print(split_s)
            answer += sum(map(int, split_s.split()))
    return answer

def main():
    S = input()

    print(solve(S))
#print(solve("125"))
#print(solve("9999999999"))
main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

for i in range(2**(n-1)):
    subset = [0]*(n-1)
    s_temp = s[0]
    for j in range(n-1):
        if i>>j & 1:
            s_temp += "+"+s[j+1]
        else:
            s_temp += s[j+1]
    ans += eval(s_temp)


print(ans)

Submission status: Accepted

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

ans = 0

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

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

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

print(ans)

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

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

n = len(S)
ans = 0
for P in product([0, 1], repeat= n - 1):
    b = 0
    tmp = 0
    for i in range(len(P)):
        if P[i] == 1:
            tmp += int(S[b:i + 1])
            b = i + 1
        else:
            pass
    tmp += int(S[b:n])
    ans += tmp
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
def dfs(s, rest):
    if len(rest) != 0:
        r = rest.pop(0)
        return dfs(s[:] + ['+'] + [r], rest[:]) + dfs(s[:] + [r], rest[:])
    else:
        return eval(s)
def eval(s):
    sum = 0
    c = ""
    for i in s:
        if i == "+":
            sum += int(c)
            c = ""
        else:
            c += i
    return sum + int(c)
r = s.pop(0)
print(dfs([r],s))

Submission status: Accepted

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

mask = 0b0
end = 2**(n-1)
ans = 0
for i in range(2**10):
    if(mask >= end):
        break
    word = s[0]
    for j in range(n-1):
        if(mask & 1<<j):
            word += '+'
        word += s[j+1]
    ans += eval(word)
    mask += 1
print(ans)

Submission status: Accepted

Solution code:
Sin=input()
S=[int(Sin[i]) for i in range(len(Sin))]
#print(S)
def sums(a):
  n=len(a)
  if n==1:
    return a[0]
  else:
    s=0
    for i in range(n):
      s+=10**(n-i-1)*a[i]
    
    for i in range(n-1):
      t=0
      b=a[i+1:]
      c=a[:i+1]
      for j in range(i+1):
        t+=(10**(i-j))*c[j]
      n2=len(b)-1
      s+=t*(2**n2)+sums(b)
      
    return s
  
print(sums(S))

Submission status: Accepted

Solution code:
S=input()
S_f=S
enzan=[]
op_cnt = len(S) - 1  #+を入れられるのは2**(n-1)個
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt  # あらかじめ ["-", "-"] というリストを作っておく
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "+"  # フラグが立っていた箇所を "+" で上書き
    enzan.append(op)

ans=0
for i in enzan:
  S_f=S
  now=0
  for j in range(len(S)-1):
    if i[j]=='+':
      now+=int(S_f[:j+1])
      S_f="0"*len(S_f[:j+1])+S_f[j+1:]

  now+=int(S_f)
  ans+=now
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main() -> None:
    S = input()
    print(sum(bit(S)))


def bit(S) -> list:
    list = []
    list.append(int(S))
    for i in range(len(S)-1):
        left = S[:i+1]
        right = S[i+1:]
        x = int(left)
        for y in bit(right):
            list.append(x + y)
    return list


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def Recursion(S):
    list = []
    list.append(int(S))
    for i in range(len(S)-1):
        left = S[:i+1]
        right = S[i+1:]
        x = int(left)
        for y in Recursion(right):
            list.append(x + y)
    return list

S = input()
print(sum(Recursion(S)))

Submission status: Accepted

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

ans = 0
for bit in range(2**(n-1)):
    cand = []
    j = 0
    for i in range(n):
        if (bit >> i) & 1:
            cand.append(S[j:i+1])
            j = i + 1
    cand.append(S[j:])
    ans += sum(map(int, cand))
    #print(cand)

print(ans)

Submission status: Accepted

Solution code:
s = input()[:: -1]

ans = 0
for i in range(2**(len(s) - 1)):
    num, d = int(s[0]), 10
    for j in range(len(s) - 1):
        if (i >> j) & 1:
            num += int(s[j + 1]) * d
            d *= 10
        else:
            ans += num
            num = int(s[j + 1])
            d = 10
    
    ans += num
    
print(ans)

Submission status: Accepted

Solution code:
class cal():
    def __init__(self):
        self.sum = 0
    def N(self,T):
        for x in range(1,len(T)+1):
            nan = 2**(len(T[x:])-1)
            if nan < 1:
                nan = 1
            self.sum += int(T[:x]) * nan
            self.N(T[x:])
        return self.sum

T = cal()
print(T.N(input()))

Submission status: Accepted

Solution code:
s=str(input())
ans=0
for i in range(1<<(len(s)-1)):
  st=s[0]
  for j in range(len(s)-1):
    if ((i >> j) & 1) == 1:
      st+="+"+s[j+1]
    else:
      st+=s[j+1]
  ans+=eval(st)
print(ans)

Submission status: Accepted

Solution code:
S = input()
l = len(S)
n = pow(2, l-1) #n通りの数式
ans = 0

for i in range(n): #2のn乗通りの全探索
  f = S[0] 
  for j in range(l-1):
    if i >> j & 1: #iのjビット右シフト,bitAND
      f += '+' #s[k]の直後に+を挿入
    f += S[j+1] #s[j]または+の直後にs[j+1]を入れる
  ans += sum(map(int, f.split('+'))) #int型に, '+'で区切る -> 数式としてを和をとる それの和をとる
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=str(input())
ans=0
for i in range(1<<(len(s)-1)):
  st=s[0]
  for j in range(len(s)-1):
    if i & (1<<j):
      st+="+"+s[j+1]
    else:
      st+=s[j+1]
  ans+=eval(st)
print(ans)

Submission status: Accepted

Solution code:
s = list(map(int, input()))
s = s[::-1]
n = len(s)
ans = 0

for bit in range(1<<n-1):
    digit = 0
    for i in range(n):
        ans = ans + s[i] * (10 ** digit)
        if (bit & (1<<i)):
            digit = 0
        else:
            digit = digit + 1

print(ans)

Submission status: Accepted

Solution code:
#ひとのを真似しただけ。再挑戦
S = input()
ans = 0

import itertools
ans = 0
for ptn in itertools.product([0, 1], repeat=len(S)-1):
    bgn = 0
    for i in range(len(S) - 1):
        if ptn[i] == 1:
            ans += int(S[bgn:i+1])
            bgn = i + 1
    ans += int(S[bgn: len(S)])

print(ans)

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

answer = sum(F(S))
print(answer)

Submission status: Accepted

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

S = read().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

answer = sum(F(S))
print(answer)

Submission status: Accepted

Solution code:

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

def main():
    mod=10**9+7
    S=input()
    N=len(S)
    ans=0
    
    import itertools
    
    for ite in itertools.product([0,1], repeat=(N-1)):
        L=list(ite)+[1]
        L2=[0]
        for i in range(N):
            if L[i]==1:
                L2.append(i+1)
        
        temp=0
        
        for i in range(1,len(L2)):
            temp+=int(S[L2[i-1]:L2[i]])
            
        ans+=temp
        
    print(ans)
        

main()

Submission status: Accepted

Solution code:
s = input()
ans = 0
n = len(s) - 1
m = 2 ** n
for i in range(m):
    bit = bin(i)[2:len(bin(i))]
    a = n - len(bit)
    if a != 0:
        bit = '0'*a + bit
    tmp = int(s[0])
    for j in range(n):
        if bit[j] == '0':
            tmp = 10*tmp + int(s[j+1])
        elif bit[j] == '1':
            ans += tmp
            tmp = int(s[j+1])
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
def dfs(i, Ope, sum):
    if i == N-1:
        start = 0
        for j in range(N-1):
            if Ope[j] == "+":
                #print(S[start:j+1])
                sum += int(S[start:j+1])
                start = j+1
        #print(S[start:N])
        sum += int(S[start:N])
        return sum
    else:
        Ope_plus = Ope + ["+"]
        Ope_null = Ope + [""]
        sum = dfs(i+1, Ope_plus, sum)
        sum = dfs(i+1, Ope_null, sum)
        return sum

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

Submission status: Accepted

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

s = input()

def dfs(i, t):
    if i == len(s) - 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:
def calc_ssum(s):
    if len(s) == 1:
        res = [[s]]
        return res
    else:
        resprev = calc_ssum(s[:len(s)-1])
        res = []
        for string in resprev:
            tmp = string + [s[-1]]
            res.append(tmp)
            tmp2 = string
            tmp2[-1] = tmp2[-1] + s[-1]
            res.append(tmp2)
        return res

s = input()
all_s = calc_ssum(s)

result = 0
for l in all_s:
    l_int = list(map(int, l))
    result += sum(l_int)

print(result)

Submission status: Accepted

Solution code:
"""
yieldを使った全探索
"""
import sys
input = sys.stdin.buffer.readline


S = input()[:-1]

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

answer = sum(F(S))
print(answer)

Submission status: Accepted

Solution code:
if __name__=='__main__':
    s = input()
    locate = len(s)-1

    # +を入れる箇所をbit探索で探す
    sum_all = 0
    for bit in range(1 << locate):
        binary = str(format(bit, 'b'))
        binary = binary.zfill(len(s)-1)
        head = 0
        for i in range(len(binary)):
            if binary[i] == '1':
                sum_all += int(s[head:i+1])
                head = i+1
        sum_all += int(s[head:])

    print(sum_all)

Submission status: Accepted

Solution code:
#こっちはbit全探索を用いた解法

#Sは最大でも10桁、+が入る場所は9箇所なので計算量は2^9=512程度。
#全探索で余裕か

#plusの位置をlist化する。

s = str(input())
slen = len(s)

masterlist = []

for i in range (2 ** (slen-1)):
    pluslist = []
    for j in range(slen - 1):
        if i >> j & 1:
            pluslist.append(True)
        else:
            pluslist.append(False)
    masterlist.append(pluslist)

result = 0

#pl as pluslist

for pl in masterlist:
    plus_count = 0
    after_s = s
    for k in range(len(pl)):
        if pl[k] == True:
            after_s = "{0}{1}{2}".format(after_s[:k+plus_count+1],"+",after_s[k+plus_count+1:])
            plus_count += 1
    try:
        list_sum = eval(after_s)
    except NameError:
        list_sum = int(s) #もしプラスが1回も出ない場合はafter_sが定義されない。
    result += list_sum

print(result)





"""
#こっちは愚直に深さ優先探索した解法
def tansaku(number,plus_point,sum_temp):
    #print(number,plus_point,sum_temp)
    str_number = str(number)
    if len(str_number) -1 <= plus_point :
        return number + sum_temp
    else:
        next_number = int(str(number)[plus_point+1:])
        a1 = int(tansaku(next_number,0,sum_temp + int(str(number)[:plus_point+1])))
        #print(a1)

        a2 = tansaku(number,plus_point+1,sum_temp)
        #print(a2)


        return a1 + a2
 


if __name__ == "__main__":
    s = int(input())
    print(tansaku(s,0,0))
"""

Submission status: Accepted

Solution code:
import sys

S = list(map(int, sys.stdin.readline().strip()))
len_S = len(S)
ans = 0
for i in range(2 ** (len_S - 1)):
  sum_ = S[len_S - 1]
  cursor = len_S - 1
  power = 0
  while cursor > 0:
    cursor -= 1 
    if i % 2 == 1:
      power += 1
    else:
      power = 0
    sum_ += S[cursor] * (10 ** power)
    i >>= 1
  ans += sum_
print(ans)

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は最大でも10桁、+が入る場所は9箇所なので計算量は2^9=512程度。
#全探索で余裕か



def tansaku(number,plus_point,sum_temp):
    #print(number,plus_point,sum_temp)
    str_number = str(number)
    if len(str_number) -1 <= plus_point :
        return number + sum_temp
    else:
        next_number = int(str(number)[plus_point+1:])
        a1 = int(tansaku(next_number,0,sum_temp + int(str(number)[:plus_point+1])))
        #print(a1)

        a2 = tansaku(number,plus_point+1,sum_temp)
        #print(a2)


        return a1 + a2
 


if __name__ == "__main__":
    s = int(input())
    print(tansaku(s,0,0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = str(input())
#kumiにブロックが入ってるこれを足してく
#それぞれの区切りで+を入れるかどうか見ればいい　それでも可能
#+を入れる個数を固定した後どこに入れるかを考える
"""解説：実際に+を入れたのを作ってく 文字列作って＋区切り文字にして足してけば良い
幅優先探索？"""
#文字列のままのやつのストック
from collections import deque
bcal = []
que = deque()
que.append(S[0])
s = ''.join([S[0],'+'])
que.append(s)
while len(que)>0:
    a = que.popleft()
    pn = a.count('+')
    if len(a)-pn == len(S):
        if a[-1]=='+':
            b = a.strip(a[-1])
            bcal.append(b)
        else:
            bcal.append(a)
    else:
        ai = len(a)-pn
        an1 =''.join([a,S[ai]])
        an2 =''.join([a,S[ai],'+'])
        que.append(an1)
        que.append(an2)
        
ans = 0
bcal= set(bcal)
for item in bcal:
    ee = item.split('+')
    for item2 in ee:
        ans += int(item2)

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
S = input()
Sum = 0
for i in range(2**(len(S)-1)):
  binary = str(format(i,'b'))
  binary_zero = binary.zfill(len(S)-1)
  t = 0
  for j in range(len(S)-1):
    if binary_zero[j]=='1':
      Sum += int(S[t:j+1])
      t = j+1
  Sum += int(S[t:])
print(Sum)

Submission status: Accepted

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

def dfs(i, sentence):
    # 再起が最後まで終了した時
    if i == l - 1:
        return sum(list(map(int, sentence.split("+"))))
    return dfs(i+1, sentence + "+" + s[i+1]) + dfs(i+1, sentence+s[i+1])

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

Submission status: Accepted

Solution code:
import sys
S = sys.stdin.readline().rstrip()
n = len(S) - 1
ans = 0
for i in range(2 ** n):
    op = [""] * n
    tmp = S[0]
    for j in range(n):
        if (i >> j) & 1:
            tmp += "+"
        tmp += S[j + 1]
    ans += eval(tmp)
print(ans)

Submission status: Accepted

Solution code:
inf = 10**15
mod = 10**9+7
s = input()
n = len(s)-1
ans = 0
for i in range(2**n):
    acc = int(s[0])
    for j in range(n):
        if ((i >> j) & 1):  # 1だったら(オンだったら)
            ans+=acc
            acc=int(s[j+1])
        else:
            acc *= 10
            acc += int(s[j+1])
    ans+=acc
print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
plus_flag = [0] * (N - 1)


def calc(flags):
    val = 0
    num_begin_index = 0
    num_end_index = None
    for flag_index in range(len(flags)):
        if flags[flag_index] == 0:
            continue
        num_end_index = flag_index + 1
        val += int(S[num_begin_index:num_end_index])
        num_begin_index = num_end_index
    num_end_index = len(flags) + 1
    val += int(S[num_begin_index:num_end_index])
    return val


def calc_sum(index, flag):
    plus_flag[index] = flag
    if index == len(plus_flag) - 1:
        return calc(plus_flag)
    return calc_sum(index + 1, 0) + calc_sum(index + 1, 1)


if N == 1:
    print(S)
else:
    print(calc_sum(0, 0) + calc_sum(0, 1))

Submission status: Accepted

Solution code:
s1, *sn = input()
L = len(sn)
SUM = 0
for bits in range(1 << L):
    formula = s1
    for op, s in enumerate(sn):
        if bits >> op & 1:
            formula += '+'
        formula += s
    value = sum(map(int, formula.split('+')))
    # print(formula, value, sep=' => ')
    # print(SUM, SUM + value, sep=' => ')
    SUM += value
print(SUM)

Submission status: Accepted

Solution code:
s = str(input())

def calc(s):
    if len(s) == 0: return [0]
    if len(s) == 1: return [int(s)]
    tmp = []
    for i in range(len(s)):
        left = s[:i+1]
        right = s[i+1:]
        x = int(left)
        for j in calc(right):
            tmp.append(x + j)
    return tmp

print(sum(calc(s)))