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 = list(input())
n = len(s) - 1
sum = 0

for i in range(2 ** n):
    tmp = s[:]
    for j in range(n):
        if (i >> j) & 1:
            tmp[j] += '+'
    sum += eval(''.join(tmp))

print(sum)

Submission status: Accepted

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

for i in range(2 ** n):
    op = [''] * n
    for j in range(n):
        if (i >> j) & 1:
            op[j] = '+'
    t = ""
    for st, nOp in zip(s, op + ['']):
        t += (st + nOp)
    sum += eval(t)

print(sum)

Submission status: Accepted

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

# bit全探索
for bit in range(2 ** N):
    k = 0
    for j in range(N):
        if (bit >> j) & 1:
            ans += int(S[k:j + 1])
            k = j + 1
    ans += int(S[k:])
print(ans)

Submission status: Accepted

Solution code:
import itertools
s = input()
n = len(s) -1
result = 0
comb = list(itertools.product(["+", ""], repeat = n))
for b in comb:
    temp = ""
    for i in range(n):
        temp += s[i] + b[i]
    temp += s[-1]
    result += eval(temp)

print(result)

Submission status: Accepted

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

ans = 0
for i in range(2**(n-1)):
    
    add_place = [""] * n
    for j in range(n-1):
        #print(i,j)
        if ((i>>j)&1):
            add_place[j] = "+"
        #print(add_place)
    fomula = ""
    for num, add in zip(s,add_place):
        fomula += num + add
    #print(fomula)
    ans += eval(fomula)
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
s=input()
n=len(s)-1
ans=0
for b in list(product(['+',''],repeat=n)):
    a=s[0]
    for i in range(n):
        a=a+b[i]+s[i+1]
    ans+=eval(a)
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 = input()
N = len(S)

dp = [None] * (N + 1)
dp[0] = (0, 1)
for i in range(1, N + 1):
    summation = 0
    cnt = 0
    for j in range(i):
        summation += int(S[j:i]) * dp[j][1] + dp[j][0]
        cnt += dp[j][1]
    dp[i] = (summation, cnt)

print(dp[N][0])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

    ans = 0

    for i in range(2 ** n):
        ops = [""] * (n + 1)
        for j in range(n):
            if (i >> j) & 1:
                ops[j] = "+"

        fomula = ""
        for num, op in zip(S, ops):
            fomula += num + op

        ans += eval(fomula)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

    ans = 0

    for i in range(2 ** n):
        ops = [""] * (n + 1)
        for j in range(n):
            if (i >> j) & 1:
                ops[j] = "+"

        fomula = ""
        for k in range(n + 1):
            fomula += S[k] + ops[k]

        ans += eval(fomula)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

def dfs(i, f):
    # iがindex番号, fが文字列. 再帰関数なのでiがループの代わり
    # fに探索結果を格納していく
    if i == n-1: # Sの最後まで行ったら合計をとる
        l = list(map(int, f.split('+')))
        return sum(l)

    return dfs(i + 1, f + S[i + 1]) + dfs(i + 1, f + '+' + S[i + 1]) # なのもしないパターンと'+'を追加するパターン

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

Submission status: Accepted

Solution code:
S = list(input())
F = [0] * (len(S)-1)

ans = 0
def rec(i):
    global ans
    if i == len(F):
        string = S[0]
        tmp = []
        for i in range(len(F)):
            if F[i] == 0:
                string += S[i+1]
            else:
                tmp.append(string)
                string = S[i+1]
        
            if i == len(F) - 1:
                tmp.append(string)
        
        tmp = list(map(int, tmp))
        ans = ans + sum(tmp)
        return
        
    rec(i+1)
    F[i] = 1
    rec(i+1)
    F[i] = 0

if len(S) == 1:
    print(S[0])
else:
    rec(0)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
S=list(input())

l=list(itertools.product(['+',''], repeat=len(S)-1))
str=[]
for i in l:
    str.append(''.join([z for sublist in [[x, y] for x, y in zip(S,i)] for z in sublist]))

for i in range(len(str)):
    str[i]+=S[-1]
summary=0
for i in str:
    summary+=eval(i)

print(summary)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def relu(num):
    if num < 0: num = 0
    return num

S = str(input())
S_len = len(S)
ans = 0
for i in range(S_len):
    for j in range(i, S_len):
        part_num = int(S[i:j+1])
        ans += part_num * 2 ** relu(i-1) * 2 ** relu(S_len - j - 2)
print(ans)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce


def comb(n, r):
    r = min(r, n-r)
    if r == 0:
        return 1
    return reduce(mul, range(n, n-r, -1))//reduce(mul, range(1, r+1))


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

Submission status: Accepted

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

if len(s) == 1:
    ans = s
else:
    for i in range(n):
        t = ""
        a = str(bin(i))[2:].zfill(len(s)-1)
        for j in range(len(a)):
            if a[j] == "1":
                t += s[j] + "+"
            else:
                t += s[j]
        t += s[-1]
        ans += eval(t)
print(ans)

Submission status: Accepted

Solution code:
s = input()
import sys

n = len(s) - 1
if n == 0:
    print(int(s))
    sys.exit()

sums = 0
for i in range(2**n):
    bit = bin(i)[2:]
    if len(bit) <= n:
        bit = '0'*(n-len(bit)) + bit

    if bit.count('1') == 0:
        sums += int(s)
    elif bit.count('1') == 1:
        pos = bit.index('1')
        sums += int(s[:pos+1]) + int(s[pos+1:])
    else:
        num = bit.count('1')
        count = 0
        string = ''
        pos = 0
        for j,k in enumerate(bit):

            if k == '1' and count == 0:
               string += s[:j+1] + '+'
               count += 1
               pos = j
            elif k == '1':
                string += s[pos+1:j+1] + '+'
                pos = j
                count += 1
            if k == '1' and count == num:
                string += s[j + 1:]

        sums += sum([int(x) for x in string.split('+')])

print(sums)

Submission status: Accepted

Solution code:
s = input()
n = len(s) - 1
cnt = 0
for bit in range(1 << n):
    j = 0
    tmp = s[0]
    for i, v in enumerate(s[1:]):
        if bit & (1 << i):
            cnt += int(tmp)
            tmp = v
        else:
            tmp += v
    cnt += int(tmp)
print(cnt)

Submission status: Accepted

Solution code:
s = input()
n = len(s) - 1
cnt = 0
for bit in range(1 << n):
    j = 0
    for i, v in enumerate(bin(bit)[2:][::-1]):
        if v == "1":
            cnt += int(s[j:i + 1])
            j = i + 1
    cnt += int(s[j:])
print(cnt)

Submission status: Accepted

Solution code:
import itertools
s = input()
n = len(s)
ans = 0
for b in itertools.product([0, 1], repeat=n-1):
    array = [s[0]]
    for i, c in enumerate(s[1:]):
        array.append(b[i] * "+")
        array.append(c)
    ans += sum(map(int, "".join(array).split("+")))
print(ans)

Submission status: Accepted

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

result=0

for i in range(2**(n-1)):
    ##print("####",bin(i))
    ll=0
    for j in range(n-1):
        if ((i>>j) & 1):
            #print(bin(i),j)
            result+=int(s[ll:j+1])
            ll=j+1
    result+=int(s[ll:])
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

a = input()


def bubun(inp):
    result = []

    def saiki(bb, index, buf):
        if len(bb) == index:
            if len(bb) == 0:
                result.append(buf)
        else:
            saiki(bb, index + 1, buf)
            buf += int(bb[:index+1])
            bb = bb[index+1:]
            saiki(bb, 0, buf)
    saiki(inp, 0, 0)
    return sum(result)


print(bubun(a))

Submission status: Accepted

Solution code:
from functools import reduce
from operator import add

S = input()
N = len(S)


def dfs(i, a):
    if i == N:
        return reduce(add, map(int, a.split("+")))

    if i == 0:
        return dfs(i + 1, S[i])

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


print(dfs(0, ""))

Submission status: Accepted

Solution code:
S = list(input())
sum = 0

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

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

    s = ""

    for k in range(len(S)-1):
        s = s + S[k]+op_list[k]

    s = s + S[len(S)-1]

    sum = sum + eval(s)

print(sum)

Submission status: Accepted

Solution code:
S = input()
num = len(S) - 1 # 隙間の個数

all_value = 0
for i in range(2 ** num):
    op = [''] * num
    for j in range(num):
        if((i >> j) & 1):
            op[num - 1 - j] = "+"


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

    all_value += eval(formula)

print(all_value)

Submission status: Accepted

Solution code:
from itertools import product
s = list(input())
n = len(s)
pattern = []
answer = 0

pattern = list(product(['+', ''], repeat=n-1))

for i in range(2 ** (n-1)):
    formula = s[0]
    for j, k in zip(pattern[i], s[1:]):
        formula += (j + k)
    answer += eval(formula)

print(answer)

Submission status: Accepted

Solution code:
S = list(input())
N = len(S) -1 
all_formula = []
result = 0


for i in range(2**N):
    temp = S
    for j in range(N):
        all_formula.append(S[j])
        if i & 2**j:
            all_formula.append("+")
    all_formula.append(S[-1])
    all_formula.append("+")

all_formula.pop(-1)
all_formula = ''.join(all_formula)
result = eval(all_formula)

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = [i for i in list(input())]
N = len(S)-1

res = 0
for bit in range(2**N):
    f = []
    for i in range(N):
        f.append(S[i])
        if bit & (2**i): f.append('+')
        else: f.append('')
    f.append(S[-1])
    f = ''.join(f)
    res += eval(f)

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

ans = 0
for b in range(1<<(len(s)-1)):
    a = s[0]
    for i in range(len(s)-1):
        if b & (1<<i):
            a += "+" + s[i+1]
        else:
            a += s[i+1]
    ans += eval(a)
print(ans)

Submission status: Accepted

Solution code:
def plus(s):
   s=s.replace("#","")
   if "+" in s:
      numbers=list(map(int,s.split("+")))
      return sum(numbers) 

   else:
      return int(s)

S=input()
N=len(S)-1  #+が入りうる箇所

#数字の間に#を挿入
S_re=[]
for i in range(len(S)):
   if i!=len(S)-1:
      S_re.append(S[i])
      S_re.append("#")
   else:
      S_re+=S[i]
T="".join(S_re)

#bit全探索
count=0
for i in range(1<<N):
   output=[]
   for j in range(N):
      if((i>>j) & 1)==1:
         output.append(j)

   S_re=[c for c in T]
   for k in output:
      L=2*k+1
      S_re[L]="+"
   mojiretsu="".join(S_re)
   count+=plus(mojiretsu)

print(count)

Submission status: Accepted

Solution code:
s = input()
nbits = 1 << (len(s) - 1)
ans = 0
for bit in range(nbits):
    tmp = []
    for i in range(len(s) - 1):
        if bit & (1 << i):
            tmp.append(i)

    curr = 0
    for x in tmp:
        ans += int(s[curr : x + 1])
        curr = x + 1
    ans += int(s[curr:])

print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':

	S = input()

	s_len = len(S) - 1
	sum = 0
	for i in range(2**s_len):
		A = S[0]
		for j in range(s_len):
			if ((i >> j) & 1):
				A += "+" + S[j+1]
			else:
				A += S[j+1]
		sum += eval(A)

	print(sum)

Submission status: Accepted

Solution code:
S = input()

sum = 0

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

    s = ""

    for j in range(len(S)-1):
        s = s + S[j]+op_list[j]

    s = s + S[len(S)-1]

    sum = sum + eval(s)


print(sum)

Submission status: Accepted

Solution code:
S = str(input())
t = len(S)-1
a = []
for i in range(2**t):
    tasu = []
    for j in range(t):
        if ( (i >> j) & 1 ):
            tasu.append("+")
        else:
            tasu.append("")
    tasu.append("")
    a.append(tasu)

result = 0
for k in range(2**t):
    p = ""
    for (i,j) in zip(S,a[k]):
        p += i + j
    result += eval(p)
print(result)

Submission status: Accepted

Solution code:





liststr = list(input())
n = len(liststr)
listnum = []
for i in range(n):
    listnum.append(int(liststr.pop()))



a = [1]
for i in range(1, n):
    tmp = a[-1] * 10 + 2 ** (i-1)
    a.append(tmp)



sum1 = 0
for i in range(n):
    tmp = listnum[i]
    sum1 += int(tmp * a[i] * (2**(n-i-1)))
    
print(sum1)

Submission status: Accepted

Solution code:
S = list(input())



sum = 0

for i in range(2**(len(S)-1)):


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

    s = s + S[len(S)-1]

    sum = sum + eval(s)


print(sum)

Submission status: Accepted

Solution code:
s = input()
nbits = 2**(len(s)-1)
ans = 0
for bit in range(nbits):
  tmp = []
  for i in range(len(s)-1):
    if bit & (1 << i):
      tmp.append(i)
  curr = 0
  for x in tmp:
    ans += int(s[curr:x+1])
    curr = x + 1
  ans += int(s[curr:])
 
print(ans)

Submission status: Accepted

Solution code:
s = input()
nbits = 2**(len(s)-1)
ans = 0
for bit in range(nbits):
  tmp = []
  for i in range(len(s)-1):
    if bit & (1 << i):
      tmp.append(i)
  curr = 0
  for x in tmp:
    ans += int(s[curr:x+1])
    curr = x + 1
  ans += int(s[curr:])

print(ans)

Submission status: Accepted

Solution code:
s = input()
nbits = 2**(len(s)-1)
ans = 0
for bit in range(nbits):
  tmp = []
  for i in range(nbits):
    if bit & (1 << i):
      tmp.append(i)
  curr = 0
  for x in tmp:
    ans += int(s[curr:x+1])
    curr = x + 1
  ans += int(s[curr:])

print(ans)

Submission status: Accepted

Solution code:
import sys

S = list(input())

sum = 0
for i in range(2**(len(S)-1)):

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

    for j in range(len(S)-1):
        if (i>>j) & 1:
            op_list[j] = ''


    s = ""
    for st_index in range(len(op_list)):
        s = s + S[st_index] + op_list[st_index]
    s = s + S[len(S)-1]
    result = eval(s)
    
    sum = sum + result

print(sum)

Submission status: Accepted

Solution code:
S = input()
s2 = ['+' for i in range(2*len(S)-1)]
for i in range(2*len(S)-1):
    if i%2 == 0:
        s2[i] = S[i//2]
ans = []
for i in range(2**(len(S)-1)):
    s3 = s2.copy()
    for j in range(len(S)-1):
        if (i >> j) & 1 == 1:
            s3[2*j+1] = '+'
        else:
            s3[2*j+1] = ''
    s3 = ''.join(s3)
    ans.append(s3)
suma = 0
for i in ans:
    suma += eval(i)
print(suma)

Submission status: Accepted

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

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

n = len(S) - 1

ans = 0

for i in range(2**n):
    loc = [] # 右から何番目に＋を入れるかを格納
    for j in range(n):
        if (i>>j) & 1:
            loc.append(j+1)
    
    S2 = S

    for k in reversed(loc):
        S2 = S2[:k] + '+' + S2[k:]
    ans += eval(S2)

print(ans)

Submission status: Accepted

Solution code:
import sys
import copy
from collections import deque

sys.setrecursionlimit(1000000000)

def dfs(xs,q):
    if len(xs) == 0:
        return sum(int(i) for i in q)

    x = xs.popleft()

    if len(q) == 0:
        q.append(x)
        return dfs(xs,q)


    a1 = copy.copy(xs)
    a2 = copy.copy(xs)

    q1 = copy.copy(q)
    q2 = copy.copy(q)

    q1.append(x)

    y  = q2.pop()
    yx = y + x
    q2.append(yx)

    return dfs(a1,q1) + dfs(a2,q2)


s  = str(input())
xs = deque(list(s))

print(dfs(xs,deque([])))

Submission status: Accepted

Solution code:
from itertools import combinations
s = list(input())
len_s = len(s)
sum_ = 0

for i in range(len(s)):
    for t in combinations(range(1, len_s), i):
        copy_s = s[:]
        for cnt, idx in enumerate(t):
            copy_s.insert(cnt + idx, '+')
        sum_ += eval("".join(copy_s))

print(sum_)

Submission status: Accepted

Solution code:
S = input()

n = len(S)-1
ans = 0

for i in range(2**(n)):
    locs = []
    for j in range(n):
        if (i>>j) & 1:
            # 右からj番目にフラグが立っている
            locs.append(j+1)
    S2 = S
    for j in reversed(locs):
        S2 = S2[:j] + "+" + S2[j:]
    ans += eval(S2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(map(str,input()))
n = len(S) - 1

def calc(S, i, Tar, ans):
    if i == n:
        return ans + int(Tar)
    return calc(S, i+1, S[i+1], ans + int(Tar)) \
            + calc(S, i+1, Tar + S[i+1], ans)

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

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] = "+"

    fomula = ""
    for value, operator in zip(s, op + [""]):
        fomula += (value + operator)

    ans += eval(fomula)

print(ans)

Submission status: Accepted

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

for i in range(2**x):
    v=[0]*x
    for j in range(x):
        if (i>>j)&1==1:
            v[j]='+'

    w=n[0]
    for k in range(x):
        if v[k]=='+':
            w+=('+'+str(n[k+1]))
        else:
            w+=str(n[k+1])

    ans+=eval(w)


print(ans)

Submission status: Accepted

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

    return dfs(formula + "+" + S[index + 1], index + 1) + dfs(formula + S[index + 1], index + 1)


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

Submission status: Accepted

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

    else:
        return dfs(formula + '+' + S[index + 1], index + 1) + dfs(formula + S[index + 1], index + 1)


S = input()
max_index = len(S)

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

Submission status: Accepted

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

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


s = input()
num_digits = len(s)

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

Submission status: Accepted

Solution code:

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


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


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


show_flg = False
# show_flg = True


def main():
    S = input()
    N = len(S) - 1

    total = 0
    for i in range(2 ** N):
        splits = []
        # print("pattern {}: ".format(i), end="")
        for j in range(N):
            if ((i >> j) & 1):
                splits.append(j)
        splits.append(len(S))

        for j in range(len(splits)):
            n = splits[j]
            if j == 0:
                total += int(S[:n+1])
                # print(S[:n+1])
            else:
                prev = splits[j-1]
                # print(prev, n, S[prev+1:n+1])
                total += int(S[prev+1:n+1])

    print(total)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
for i in range(1<<N-1):
    p = 0
    for j in range(N-1):
        if i >> j & 1:
            ans += int(S[p:j+1])
            p = j + 1
    ans += int(S[p:])
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:
import math

N=int(input())

def dig(x,d):
  return int((x%(10**(d+1)))/(10**d))

D=int(math.log10(N))

ans=0

for bits in range(int(2**D)):
  ans+=dig(N,0)
  j=1
  for i in range(1,D+1):
    if (bits>>(i-1))&1:
      j=0
    ans+=int(dig(N,i)*(10**j))
    j+=1
print(int(ans))

Submission status: Accepted

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    S, = args
    n_sep = len(S)-1
    b_max = 2**n_sep

    ret = 0
    for b in range(b_max):
        p = 0
        for i in range(n_sep):
            if b >> i & 1:
                ret += int(S[p:i+1])
                p = i+1
        ret += int(S[p:])

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

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-1):
        tmp += S[j]
        if i & (1 << j):
            tmp += '+'
    tmp += S[-1]
    ans += eval(tmp)


print(ans)

Submission status: Accepted

Solution code:
S = list(input())
n = len(S)
a = []

sbox = []


for i in S:
    a.append(int(i))

def dfs(i,box,k):
    if i == n-1:
        box += k
        sbox.append(box)
    else:
        dfs(i+1,box+k,a[i+1])
        dfs(i+1,box,10*k+a[i+1])

dfs(0, 0, a[0])
print(sum(sbox))

Submission status: Accepted

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

totals = []

def total(n):
  tmp = int(s[-1 * n:])
  
  for i in range(n-1):
    tmp += int(s[-1 * n:-1 * (i+1)]) * 2**i + totals[i]
    
  totals.append(tmp)


for i in range(size):
  total(i+1)

print(totals[size - 1])

Submission status: Accepted

Solution code:
S=input()
s=[int(S[i]) for i in range(len(S))]
N=len(s)
B=[]
for i in range(2**(N-1)):
    ans=[[s[0]]]
    for j in range(N-1):
        if ((i>>j)&1):# 順に右にシフトさせ最下位bitのチェックを行う
            ans[-1].append(s[j+1])    
        else:
            ans.append([s[j+1]])
    for k in ans:
        for l, val in enumerate(reversed(k)):
            B.append((10**l)*val)
print(sum(B))

Submission status: Accepted

Solution code:
s = [int(x) for x in list(input())]
n = len(s)
ans = 0

for i in range(2**(n-1)):
    nnn = [[s[0]]]
    for j in range(0, n - 1):
        if ((i>>j)&1):
            nnn[-1].append(s[j + 1])
        else:
            nnn.append([s[j + 1]])

    for nn in nnn:
        for i, val in enumerate(reversed(nn)):
            ans += val * 10 ** i

print(ans)

Submission status: Accepted

Solution code:
def add_or_do_nothing(s, i, pos):
    if i == len(s):
        pre_i = 0
        ans = 0
        for i, pos_i in enumerate(pos, 1):
            if pos_i == '1':
                ans += int(s[pre_i:i])
                pre_i = i

        ans += int(s[pre_i:len(s)])
        return ans

    f_ans = add_or_do_nothing(s, i+1, pos+'0')
    s_ans = add_or_do_nothing(s, i+1, pos+'1')
    return f_ans + s_ans

s = input()

pos = ''
ans = add_or_do_nothing(s, 1, pos)

print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = 0
for i in range(2**n):
	l = []
	op = [""]*n
	for j in range(n):
		if ((i >> j) & 1) == 1:
			op[j] = '+'
	res = ""
	for a,b in zip(op+[""],s):
		res += a+b
	ans += eval(res)
print(ans//2)

Submission status: Accepted

Solution code:
s = input()

n = len(s)

ans = 0
for i in range(2**n):
	l = []
	op = [""]*n
	for j in range(n):
		if i & (1 << j):
			op[j] = '+'
	#print(op)
	res = ""
	for a,b in zip(op+[""],s):
		res += a+b

	ans += eval(res)

print(ans//2)

Submission status: Accepted

Solution code:
s = input()

n = len(s)

ans = 0
for i in range(2**n):
	l = []
	for j in range(n):
		if i & (1 << j):
			l.append(j)
	#print(l)
	string = s
	if len(l) == 0:
		continue
	for k in range(len(l)):
		if l[k] == 0:
			string = '+' + string
		else:
			string = string[:l[k]+k] + '+' + string[l[k]+k:]

	ans += eval(string)

print((ans + int(s))//2)

Submission status: Accepted

Solution code:
S = input()
n = len(S) - 1
ans = 0
for i in range(2**n):
    bits = [(i>>j)&1 for j in range(n)]
    bits.append("")
    expr = ""
    for s, b in zip(S, bits):
        expr += s
        if b == 1:
            expr += "+"
    ans += sum([int(s) for s in expr.split("+")])
print(ans)

Submission status: Accepted

Solution code:
S = input()
n = len(S) - 1
ans = 0
for i in range(2**n):
    bits = [(i>>j)&1 for j in range(n)]
    bits.append("")
    expr = ""
    for s, b in zip(S, bits):
        expr += s
        if b == 1:
            expr += "+"
    ans += eval(expr)
print(ans)

Submission status: Accepted

Solution code:
ans=0
s=input()
n=len(s)
# print((n-1)**2)
for i in range(2**(n-1)):
    # print(i)
    tmp=[]
    for k in range(n-1):
        # print("".join(tmp))
        tmp.append(s[k])
        if i>>k & 1:
            # print(114514)
            tmp.append("+")
    tmp.append(s[-1])
    # print("".join(tmp))
    ans+=eval("".join(tmp))
print(ans)

Submission status: Accepted

Solution code:
S = input()
def dfs(i, formula, ans_formula):
    # ベースケース
    if i == len(formula):
        ans_formula.append(formula)
        return formula

    # +を入れる場合
    dfs(i+2, formula[:i] + '+' + formula[i:], ans_formula)
    
    # +を入れない場合
    dfs(i+1, formula, ans_formula)

ans_formula = []
dfs(1, S, ans_formula)

ans = 0
for i in range(len(ans_formula)):
    ans += sum(list(map(int, ans_formula[i].split('+'))))

print(ans)

Submission status: Accepted

Solution code:
INF = float("inf") #const

def main():
    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] = "+"
        res = ""
        for a,b in zip(s,op+[""]):
            if len(b) != 0:
                res += a + b
            else:
                res += a
        ans += eval(res)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import copy

def main():
    sum=0
    S = list(map(str, input()))
    hoge = tmp = []

    op_cnt = len(S) - 1

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

        S_tmp = copy.deepcopy(S)
        for k in range(len(op)):
            S_tmp.insert(1+k*2,op[k])
        sum+=(eval("".join(S_tmp)))
    print(sum)

main()

Submission status: Accepted

Solution code:
S = input()

res_list = []

def my_recursion(res):
    if len(res) >= len(S):
        return ''

    my_recursion(res + '0')
    my_recursion(res + '+')
    if len(res) == len(S)-1:
        res_list.append(res)

    return res_list
# print(my_recursion(''))
# print(len(my_recursion('')))
res_list = my_recursion('')

temp_S_list = []

for item in res_list:
    temp_S = ''
    for i, j in enumerate(item):
        temp_S += S[i]+j
    temp_S += S[-1]
    S_done_eval = eval(temp_S.replace('0', ''))
    temp_S_list.append(S_done_eval)

print(sum(temp_S_list))

Submission status: Accepted

Solution code:
S = list(input())
A = [i for i in range(len(S)-1)]
ans = 0
for i in range(1 << len(A)):
    tmp = S.copy()
    idx = []
    k = 0
    for j in range(len(A)):
        if ((i >> j) & 1) == 1:
            idx.append(A[j])
    for j in range(len(idx)):
        tmp.insert(idx[j]+1+k, '+')
        k += 1
    
    str = ''.join(tmp)
    n = str.split('+')
    n = [int(i) for i in n]
    ans += sum(n)
print(ans)

Submission status: Accepted

Solution code:
S = input()
n = len(S)
ans = [0]*(n+1)

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