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:
my_list = list(input())
sum = 0
n = len(my_list) - 1
for i in range(2**n):
    tmp = [""]*n
    for j in range(n):
        if 1&(i>>j):
            tmp[n-1-j] = "+"
    formula = ""
    for p,q in zip(tmp+[""],my_list):
        formula += str(q) + p
    sum += eval(formula)

print(sum)

Submission status: Accepted

Solution code:
S = input()
str_list = list(S)
p = len(S) - 1

ans = 0
for i in range(2 ** p):
    num = str_list[0]
    for j in range(p):
        if (i >> j) & 1:
            ans += int(num)
            num = ''
        num += str_list[j+1]
    ans += int(num)

print(ans)

Submission status: Accepted

Solution code:
nums = list(input().strip())
N = len(nums)
head = nums.pop(0)
print(sum(eval(head + "".join([('' if (j >> i) % 2 else '+') + str(n) for i, n in enumerate(nums)])) for j in range(2 ** (N - 1))))

Submission status: Accepted

Solution code:
S = input()


def solve(n,S,idx):
    ans = 0
    if idx >= len(S):
        return eval(n)

    ans += solve(n+"+"+S[idx], S, idx+1)
    ans += solve(n+S[idx], S, idx+1)
    return ans

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

Submission status: Accepted

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

import pdb
import sys
F = sys.stdin

S = F.readline().rstrip()
N = int(len(S) - 1)
sum = 0
l = [0]

# pdb.set_trace()
for bit in range(1<<N):
    for i in range(N):
        if bit & (1<<i):
            l.append(i+1)

    l.append(int(N+1))
    l_length = len(l)
    for j in range(l_length):
        if j == 0:
            continue
        ss = S[(l[j-1]):(l[j])]

        sum += int(ss)

    l = [0]


print(sum)

Submission status: Accepted

Solution code:
S = input()
last = len(S)
ans = 0

def dfs(pos, pre_pos, val):
    global ans
    if pos == last:
        ans += (val + int(S[pre_pos:]))
    else:
        new_val = val + int(S[pre_pos:pos])
        dfs(pos + 1, pos, new_val)
        dfs(pos + 1, pre_pos, val)

dfs(1, 0, 0)

print(ans)

Submission status: Accepted

Solution code:
s = input()
print(sum([eval(''.join(sum(zip(s, ['+' if ((bit >> i) & 1) == 1 else '' for i in range(len(s))]), ()))) for bit in range(1 << len(s) - 1)]))

Submission status: Accepted

Solution code:
S = list(input())
ans = 0
for i in range(1 << len(S) - 1):
    output = S[0]
    for j in range(len(S) - 1):
        if ((i >> j) & 1) == 1:
            output += "+"
        output += S[j + 1]
    ans += eval(output)
print(ans)

Submission status: Accepted

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

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:
S = list(input())
n = len(S)-1
ans=0
for i in range(2**n):
  tmp=S[:]
  for j in range(n):
    if (i>>j) & 1:
      tmp[j]+="+"
  ans+= eval("".join(tmp))
print(ans)

Submission status: Accepted

Solution code:
import math

S = input()

ans = 0
for i in range(2**(len(S)-1)):
    j = 0
    k = 1
    for c in format(i, '0' + str(len(S)-1) + 'b'):
        if c == '1':
            ans += int(S[j:k])
            j = k
        k += 1
    ans += int(S[j:k])

print(ans)

Submission status: Accepted

Solution code:
s = input()

ans = 0

n = len(s)-1

for i in range(2 ** n):
    bag = []
    for j in range(n):
        if ((i >> j) & 1):
            bag.append(1)
        else:
            bag.append(0)
    c = 0

    temp = s
    for j in range(0, n):
        c += 1
        if (bag[j]):
            temp = temp[:c] + '+' + temp[c:]
            c += 1

    ans += eval(temp)


print(ans)

Submission status: Accepted

Solution code:
from itertools import product

S = input()
n = len(S)

ans = 0
for P in product(["+",""],repeat=n-1):
    res = ""
    for s,p in zip(S,P):
        res += s+p
    res += S[-1]
    # print(res)
    ans += eval(res)
print(ans)

Submission status: Accepted

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

for i in range(2**(N-1)):
    i = str(bin(i))[2:].zfill(N-1)
    op = ["+" if int(i[j]) else "" for j in range(N-1)]
    q = [S[j//2] if j%2==0 else op[(j-1)//2] for j in range(2*N-1)]
    v += eval("".join(q))


print(v)

Submission status: Accepted

Solution code:
##ARC61-C
#再帰関数
s = list(input())
#桁数を扱うのは文字列として扱ってlenを取るのがベター
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])

#イメージとしては1文字目を計算して、2文字目を追加する時、+を追加するかしないかを分けて考えるイメージ
print(dfs(0,s[0]))

Submission status: Accepted

Solution code:
# coding: utf-8
S = list(input())
n = len(S) - 1
ans = 0
for i in range(2**n):
    tmp = S[:]
    for j in range(n):
        if (i >> j) & 1 == 1:
            tmp[j] += "+"
    ans += eval("".join(tmp))
print(ans)

Submission status: Accepted

Solution code:
#coding: utf-8
S = list(input())
ans = 0
n = len(S) - 1
for i in range(2**n):
    tmp = S[:]
    for j in range(n):
        if (i >> j) & 1 == 1:
            tmp[j] += "+"
    ans += eval("".join(tmp))
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
S = str(input())
n = len(S) - 1
ops = []
for i in range(2**n):
    op = [""] * n
    for j in range(n):
        if ((i >> j) & 1) == 1:
            op[n-1-j] = "+"
    ops.append(op[:])
    
ans = 0
for op in ops:
    s = [t for t in S]
    tmp = ""
    for k in range(len(op)):
        tmp += s[k]
        tmp += op[k]
    tmp += s[-1]
    ans += eval(tmp)
print(ans)

Submission status: Accepted

Solution code:
def main():

    S = input()
    n = len(S)
    memo = dict()
    def recursive(S, i, j):
        if i == j: return 0
        if (i, j) not in memo:
            v = int(S[i:j])
            for k in range(i+1, j):
                v += int(S[i:k])*pow(2, j-k-1) + recursive(S, k, j)
            memo[(i, j)] = v
        return memo[(i, j)]

    return recursive(S, 0, n)

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

Submission status: Accepted

Solution code:
def main():

    S = input()
    memo = dict()
    n = len(S)

    def recursive(S, i, j):

        v = 0
        if j < i: return v
        if (i, j) in memo: return memo[(i, j)]
        # if n == 1: return int(S)
        for k in range(i, j+1):
            if j - k < 1:
                v += int(S[i:k+1])
            else:
                v += int(S[i:k+1])*pow(2, j-k-1) + recursive(S, k+1, j)
        memo[(i, j)] = v
        return memo[(i, j)]

    ans = recursive(S, 0, n-1)

    return ans


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

Submission status: Accepted

Solution code:
import sys
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

# 参照URL:https://qiita.com/gogotealove/items/11f9e83218926211083a

# n = [int(x) for x in input().rstrip()]
# op_cnt = len(n) - 1  # すき間の個数
# ans2 = []
# 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] = "+"  # フラグが立っていた箇所を "+" で上書き
#     ans2.append(op)
# for a in ans2:
# 	print(a)

S = input().rstrip() # 入力値 "1234\n" を "1234"に
n = len(S)-1 # オペレータが入りうる隙間はlen(S)-1

ops = []
for i in range(2**n): # 各隙間に対して、 +するしないの2通りがあるので、2^n 回ループ
	op = [""] * n # あらかじめリストを作成
	for j in range(n):
		if((i>>j) & 1) == 1:  # 順に右にシフトさせ最下位bitのチェックを行う
			op[n-1-j] = "+" # フラグが立っていたらopの値を書き換える
	ops.append(op)

# ここまでで ops の中にありうる組み合わせが列挙される（以下はlen(S)-1==3の例）
# ['', '', '']
# ['', '', '+']
# ['', '+', '']
# ['', '+', '+']
# ['+', '', '']
# ['+', '', '+']
# ['+', '+', '']
# ['+', '+', '+']

ans = 0
for o in ops:
	s = [s for s in S]
	for k in range(len(o)):
		s.insert(2*k+1, o[k])
	ans += eval(''.join(s)) # eval を利用することで文字列を式として評価することができる

print(ans)

Submission status: Accepted

Solution code:
S = str(input())
n = len(S)
total,i_sum, reg = 0, 0, 0
for i in range(2**(n-1)):
    reg = int(S[0])
    for j in range(n-1):
        if(i >> j) & 1:
            i_sum += reg
#            print(i_sum,reg,"1")
            reg = 0
        reg = reg*10 + int(S[j+1])
#        print(reg,"2")
    i_sum += reg
    total += i_sum
    i_sum = 0
#   print(i_sum, total ,"3")
print(total)

Submission status: Accepted

Solution code:
S = input()


def solve(current='', index=0):
    if index is len(S) - 1:
        return eval(current + S[index])
    return solve(current + S[index], index + 1) + solve(current + S[index] + '+', index + 1)


def solve2():
    total = 0
    for source in range(1 << (len(S) - 1)):
        # in binary '1' means '+'
        # 125 ->  1 (source bit:0 ) + 2 + '(+ if (source bit: 1) & 1)
        current = ''
        for i, s in enumerate(S):
            current = current + s
            if (source >> i) & 1:
                total += int(current)
                current = ''
        total += int(current)
    return total

print(solve2())

Submission status: Accepted

Solution code:
S = input()


def solve(current = '', index=0):
    if index is len(S) - 1:
        return eval(current + S[index])
    return solve(current + S[index], index + 1) + solve(current + S[index] + '+', index + 1)


print(solve())

Submission status: Accepted

Solution code:
import sys
import copy

sys.setrecursionlimit(10**6)

def solve():
    S = input()
    lst = [int(S)]
    print(sum(func(S, 1, lst)))
    
def func(s, insertInd, lst):
    if insertInd == len(s):
        return lst
    
    else:
        copied = s
        inserted = copied[:insertInd] + '+' + copied[insertInd:]
        lst.append(evalsum(inserted))
        a = func(inserted, insertInd + 2, lst) 

        inserted = copied[:insertInd] + ' ' + copied[insertInd:]
        if inserted in '+':
            lst.append(evalsum(inserted))
        func(inserted, insertInd + 2, lst)
        
        return a

def evalsum(s):
    s = s.replace(' ', '')
    return sum(list(map(int, s.split('+'))))

if __name__ == '__main__':
    solve()

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 = list(input())
l = len(S)
ans = 0
for i in range(1 << (l-1)):
    A = str(S[0])
    for j in range(l-1):
        if (i >> j) & 1 == 1:
            A += '+'
        A += S[j+1]
    ans += eval(A)
print(ans)

Submission status: Accepted

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

def dfs(tmp, s):
    if len(s) == 1:
        return int(tmp)+int(s)+int(tmp+s)
    
    return int(tmp)*2**(len(s)-1)+dfs(s[0], s[1:]) + dfs(tmp+s[0], s[1:])

if n > 1:
    print(dfs(s[0], s[1:]))
else:
    print(int(s))

Submission status: Accepted

Solution code:
import numpy as np
s = input()

n = len(s)
iters = 2 ** (n - 1)
count = 0
for i in range(iters):
    buf = s[0]
    for j in range(n - 1):
        if i & (2**j):
            count += int(buf)
            buf = s[j + 1]
        else:
            buf += s[j + 1]
    count += int(buf)
print(count)

Submission status: Accepted

Solution code:
import numpy as np
s = input()

item = np.arange(len(s) - 1) + 1
n = len(item)
count = 0
for i in range(2 ** n):
    sidx = 0
    for j in range(n):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            eidx = item[j]
            count += int(s[sidx:eidx])
            sidx = eidx
    count += int(s[sidx:])
print(count)

Submission status: Accepted

Solution code:
# ARC061C
S = input()
N= len(S)
ans = 0

# +を挿入するのは2 ** (N-1)．間に入れるか入れないか
for i in range(2 ** (N - 1)):
    # iは各桁に+を挿入するかどうかを決定する．2進数として考える
    now_sum = 0                 # i番目の和を考える
    reg = int(S[0])
    for j in range(N - 1):      # 0or1を調べるためのループ
        if i & (1 << j):        # j回シフトした1とiの論理積をとることで1かどうかを調べる
      # if (i >> j) & 1:        # でも可．iをj回右シフトして，1と論理積をとる(最下位が1かを調べる) 
            now_sum += reg      # 1ならi番目の和にregを足す
            reg = 0
        reg *= 10               # 1でないならreg * 10 する.reg = 12なら120にする
        reg += int(S[j + 1])    # そして120 + 3で123となる
    now_sum += reg
    ans += now_sum
 
print(ans)

Submission status: Accepted

Solution code:
from itertools import zip_longest

N = input()
len_N = len(str(N))
sum =0

for i in range(2**(len_N-1)):
  hugo = [""]*(len_N-1)
  for j in range(len_N-1):
    if (i>>j)& 1:
      hugo[j]="+"
  #print(hugo)
  formula=""
  for aaa,bbb in zip_longest(N,hugo+[""]):
    formula +=(aaa+bbb)
  sum += eval(formula)

print(sum)

Submission status: Accepted

Solution code:
S = input()
l = len(S)
toal = 0
for i in range(1 << (l-1)):
    a = int(S[0])
    sum_t = 0
    for j in range(l-1):
        if ((i >> j) & 1):
            sum_t += a
            a = 0
        a *= 10
        a += int(S[j+1])
    sum_t += a 
    toal += sum_t
    
print(toal)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
from itertools import product

s = input()

ans = 0
for pat in product(["+", ""], repeat=len(s)-1):
    eq = ""
    for i in range(len(s)-1):
        eq += s[i] + pat[i]
    eq += s[-1]
    ans += eval(eq)

print(ans)

Submission status: Accepted

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

def num2bin(x, y):
  return format(x, '0'+str(y)+'b')

def f(a):
  out=0
  a=a+'+'
  l=len(a)
  i=0
  while i<l-1:
    j=i+1
    while j<l and a[j]!='+':
      j+=1
      
    out+=int(a[i:j])
    i=j
    
  return out
      

out=0
temp=pow(2, nn)
for i in range(temp):
  p=num2bin(i, nn)
  a=''
  for j in range(nn):
    a=a+S[j]
    if p[j]=='1':
      a=a+'+'
      
  a=a+S[-1]
  
  out+=f(a)
  
print(out)

Submission status: Accepted

Solution code:
# ARC061C - たくさんの数式 / Many Formulas (ABC045C)
from itertools import product


def main():
    S = input()
    if "\n" in S:
	    return
    ans = 0
    for ops in tuple(product(("", "+"), repeat=len(S) - 1)):
        ops = ops + ("",)  # operators
        exp = "".join(i + j for i, j in zip(S, ops))  # expression
        ans += eval(exp)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys


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


s = input()
n = len(s)

total_sum = 0
# +を挿入する事象は
# sが2文字なら2通り，3文字なら4通り，n文字なら2^(n-1)通りある
for i in range(2 ** (n - 1)):
    # iは各桁に+を挿入するかどうかを決定する
    # 例えば s=12345, i=0b0111, ss=1+2+3+45
    now_sum = 0
    reg = int(s[0])
    for j in range(n - 1):
        if i & 1 << j:
            now_sum += reg
            reg = 0
        reg *= 10
        reg += int(s[j + 1])
    now_sum += reg

    total_sum += now_sum

print(total_sum)

Submission status: Accepted

Solution code:
s = input()
n = len(s)-1
comb = 2**n-1 #0b1111
S = 0
for i in range(comb+1):
    #print('{:04b}'.format(i))
    sep =[]
    j0 = 0
    for j in range(n):
        #print('j=', j,  i>>j & 1)
        if (i>>j & 1):
            sep.append(s[j0:j+1])
            j0 = j+1
    sep.append(s[j0:])
    #print(sep)
    x = list(map(int, sep))
    S += sum(x)

print(S)

Submission status: Accepted

Solution code:
import itertools
a=input()
n=len(a)
l=list(itertools.product(range(2),repeat=n-1))
wl=[]
for i in range(len(l)):
    w=a[0]
    for j in range(n-1):
        if l[i][j]==1:
            w+="+"
        w+=a[j+1]
    wl.append(w)
print(sum(map(eval,wl)))

Submission status: Accepted

Solution code:
s=list(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 sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def parse():

    return 

def main():
    S = input()
    ans = 0
    nn = len(S)-1
    for i in range(1<<nn): # bit flag to insert '+'
        #print(bin(i))
        end = len(S)
        for j in range(nn):
            if 1<<j & i:
                start = len(S)-1-j
                s = S[start:end]
                #print(start,end)
                #print(s)
                try:
                    ans += int(s)
                except:
                    pass
                end = start
        s = S[:end]
        #print(s)
        try:
            ans += int(s)
        except:
            pass
        #print()
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0


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

print(ans)

Submission status: Accepted

Solution code:
S = input()
num = []
ans = 0
length = 0


def calc(x, i, j):
    if i == length-1:
        x += j
        global ans
        ans += x
    else:
        calc(x+j, i+1, num[i+1])
        calc(x, i+1, 10*j+num[i+1])


def solve():
    for s in S:
        num.append(int(s))
    global length
    length = len(num)
    calc(0, 0, num[0])
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import itertools
s=input()
n=len(s)
l=list(itertools.product(range(2),repeat=n-1))
tl=[]
for i in range(len(l)):
    t=s[0]
    for j in range(n-1):
        if l[i][j]==1:
            t+='+'
        t+=s[j+1]
    tl.append(t)
print(sum(map(eval,tl)))

Submission status: Accepted

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

n = len(S)

def getMax(fml, i):
    if i == n:
        return eval(fml)
    else:
        return getMax(fml + S[i], i+1) + getMax(fml + "+" + S[i], i+1)

print(getMax(S[0], 1))

Submission status: Accepted

Solution code:
s = input()

n = len(s)

def formula(fml, i):
  if i == n:
    return eval(fml)
  else:
    return formula(fml + s[i], i+1) + formula(fml + '+' + s[i], i+1)
    
print(formula(s[0], 1))

Submission status: Accepted

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

ans = 0
for i in range(2 ** sp):
    plus = [""] * sp
    for j in range(sp):
        if ((i >> j) & 1):  # 下から数えてj番目が1かどうか
            plus[sp-1 - j] = "+"
    fml = ""
    for i in range(len(S)):
        if i == len(S) - 1:
            fml = fml + S[i]
        else:
            fml = fml + S[i] + plus[i]
    ans += eval(fml)
print(ans)

Submission status: Accepted

Solution code:
S = input()

def DFSCalculation(plus_list):
    """return: 合計値"""

    if len(plus_list) == len(S) - 1:
        cand_list = []
        pre_i = 0
        for i in range(len(plus_list)):
            if plus_list[i] == 0:
                pass
            else:
                cand_list.append(S[pre_i : i + 1])
                pre_i = i + 1
        cand_list.append(S[pre_i :])
    
        sum_value = 0
        for x in cand_list:
            sum_value += int(x)
        return sum_value

    else:
        in_plus = DFSCalculation(plus_list + [1])
        not_in_plus = DFSCalculation(plus_list + [0])
        return in_plus + not_in_plus

sum_value = DFSCalculation([])

print(sum_value)

Submission status: Accepted

Solution code:
s = input()
r = 0
for i in range(2**(len(s)-1)):
  fml = ""
  for j in range(len(s)-1):
    fml += s[j]
    if((i>>j)%2): fml += "+"
  fml += s[-1]
  r += eval(fml)
print(r)

Submission status: Accepted

Solution code:
n = list(input())
gaps = len(n) - 1
import copy
ans = 0
for i in range(2 ** gaps):
    formula = copy.deepcopy(n)
    ops = [""] * gaps
    for j in range(gaps):
        if (i >> j) & 1:
            ops[gaps-j-1] = "+"
    formula1 = ""
    for f,op in zip(formula,ops + [""]):
        formula1 += (str(f) + op)
    ans += eval(formula1)

print(ans)

Submission status: Accepted

Solution code:
S = input()

l = len(S)
S_list = list(map(int, S))

ans = 0

for i in range(l):
    num = int(S_list[-i-1])

    for j in range(i+1):
        ans += num * (10 ** (j)) * (2 ** (max(l-1-j-1, l-1-i)))

print(ans)

Submission status: Accepted

Solution code:
S = list(map(int, list(input())))

result = 0
L = []

#S[1,2,5]とすると,i = 1でS[i] = 2で1 + 2の時,,
#1 + 25とするか1 + 2 + 5とするか,未確定
#確定したcurrent = 1とbuf = 2の2通りの値を持っておかないといけない

def recur(i, buf, current, S):
  global result
  if i == len(S) - 1:
    total = [current + buf * 10 + S[i],current,buf * 10,S[i]]
    L.append(total)
    result += current + buf * 10 + S[i]
    return
  
  # +を入れる
  ## ex:1 + 2 (= 3) → 3 + 5 = 8
  ## currentへ足し合わせ,bufを0とする
  ### i = 1,buf = 1の時,0 + 10 + 2 = 12をcurrentとして確定し再帰実行(i = 2で12 + 5)
  ### i = 1,current = 1の時(buf = 0),1 + 0 + 2をcurrentとして確定し再帰実行(i = 2で1 + 2 +5)
  #### i = 0の時,current,bufともに0,S[0] = 1をcurrentとして再帰実行(i = 1で1 + 25か 1 +2 +5の分岐に) 
  recur(i + 1, 0, current + buf * 10 + S[i], S)

  # +を入れない
  ## ex:1 * 10 + 2 (= 12) → (12) * 10 + 5 = 125
  ## iが進む毎に,bufとされた数が10倍になり,次の桁の数が足される
  ### i = 1,buf = 10の時,10 + 2 = 12をbuff(i = 2で120に)で再帰実行(120+5)
  ### i = 1,current = 1(buf = 0)の時,buf = 2(i = 2で20に),current = 1で再帰実行(1+20+5)
  ### i = 0の時,current,bufともに0,1をbufとする(i = 1で10に),current = 0で再帰実行(i = 1で125か12 + 5の分岐に)
  recur(i + 1, buf * 10 + S[i], current, S)

recur(0, 0, 0, S)
print(result)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
ans = 0
for i in range(2**(l-1)):
  cur = bin(i)[2:]
  cur = '0' * (l-1-len(cur)) + cur
  d = s[0]
  for j in range(l-1):
    if cur[j] == '1':
      ans += int(d)
      d = s[j+1]
    else:
      d += s[j+1]
  ans += int(d)
print(ans)

Submission status: Accepted

Solution code:
s = list(input())

r = [""]*len(s)
ans = 0

def rec(i: int) -> None:
    if i == len(s)-1:
        global ans
        ans += eval("".join(i+j for i, j in zip(s, r)))
        return

    rec(i + 1)
    r[i] = "+"
    rec(i + 1)
    r[i] = ""

rec(0)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
n = len(S) - 1
bool_list = [False] * n

state_list = []

def dfs(i, n, bool_list):
    bool_list = bool_list.copy()
    if i == n:
        state_list.append(bool_list)
    else:
        dfs(i + 1, n, bool_list)
        bool_list[i] = True
        dfs(i + 1, n, bool_list)

dfs(0, n, bool_list)

ans = 0
for state in state_list:
    res_str = ''
    for i in range(n):
        res_str += S[i]
        if state[i]:
            res_str += '+'
    else:
        res_str += S[-1]
    ans += eval(res_str)

print(ans)

Submission status: Accepted

Solution code:
def sumd(S,n,k):
    res=0
    temp=int(S[0])
    for i in range(n-1):        
        if k&(1<<i):
            res+=temp
            temp=int(S[i+1])
        else:
            temp=temp*10+int(S[i+1])
    res+=temp
    return res

S=input()
n=len(S)
ans=0
for k in range(1<<(n-1)):
    ans+=sumd(S,n,k)
print(ans)

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
ans = 0
for i in range(2**(n-1)):
  t = s[:]
  bag = []
  for j in range(n-1):
    if (i >> j) & 1:
      bag += [j]
  for idx in bag[::-1]:
    t.insert(idx+1, "+")
  ans += eval(''.join(t))

print(ans)

Submission status: Accepted

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

for i in range(2**(n-1)):#+入るかどうか2**n-1通りある
    #文字列としてevalで処理する
    e = ""
    for j in range(n-1):
        if (i >> j)& 1 == 1:
            e += s[j] + '+'
        else:
            e += s[j]
    e += s[-1]
    ans += eval(e)
print(ans)

Submission status: Accepted

Solution code:

S=input()
l=len(S)-1
ans =0
for i in range(1 << l):
    s=S[0]
    for j in range(l):
        if (i >> j)&1:
            s+="+"
        s+=S[j+1]
    ans+=eval(s)
    
    
print(ans)

Submission status: Accepted

Solution code:
S = input()
s = S[0]
ans = 0
def dfs(n,S,s):
    global ans
    s_0 = s + "+" + S[n]
    s_1 = s + S[n]
    if n == len(S) - 1:
        ans += eval(s_0) + eval(s_1)
    else:
        dfs(n+1,S,s_0)
        dfs(n+1,S,s_1)
if len(S) == 1:
    print(int(S))
else:
    dfs(1,S,s)
    print(ans)

Submission status: Accepted

Solution code:
import copy
S = input()

'''
bit探索
2 進数表記した場合の下から数えて n 桁目（一番下の桁を 0 とします）が 1 であるかどうかをチェックするためのコードは、(i >> n) & 1 
'''
def bit_cal2(n):
    return_list = ['']* (2 ** n)
    for i in range(2 ** n):
        for j in range(n):
            if ((i >> j) & 1):
                return_list[i] = return_list[i] + '1'
            else:
                return_list[i] = return_list[i] + '0'
    return return_list

#自作のは遅かった
'''
def bit_cal(max_num,cal_list=[],current_cnt=0):
    new_list = []
    if len(cal_list) == 0:
        for i in range(2):
            new_list.append([i])
    else:
        for cal_val in cal_list:
            for i in range(2):
                tmp = copy.deepcopy(cal_val)
                tmp.append(i)
                new_list.append(tmp)
    current_cnt += 1
    if max_num == current_cnt:
        return new_list
    return bit_cal(max_num,new_list,current_cnt)

'''
all_plus_combination = bit_cal2(len(S)-1)
ans = 0
for plus_combination in all_plus_combination:
    start_idx = 0
    for i in range(len(S)-1):
        if plus_combination[i] == '1':
            ans += int(S[start_idx:i+1])
            start_idx = i+1
    ans +=int(S[start_idx:100])
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(2**N):
    s = S[0]
    for j in range(N):
        if ((i >> j) & 1):
            s += "+"
        s += S[j+1]
    ans += eval(s)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

    ans += eval(t)

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

sum = 0
for i in range(2 ** n):
    s = S[0]
    for j in range(n):
        if (i >> j) & 1:
           s += "+"
        s += S[j+1]
    sum += eval(s)
print(sum)

Submission status: Accepted

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

bitlist = []
def allbit(string, n):
    if n ==0:
        bitlist.append(string)
        return
    allbit(string + "0", n-1);
    allbit(string + "1", n-1);
    
allbit("", sl-1)

ans = 0
for bit in bitlist:
    before_idx = 0
    for idx, b in enumerate(bit):
        if b == "1":
            if s[before_idx:idx+1] != "":
                ans += int(s[before_idx:idx+1])
                before_idx = idx+1
    if int(s[before_idx:]) != "":
        ans += int(s[before_idx:])
print(ans)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
import copy
s = list(input())
formula_list = []

def insert_(formula, count):
    global formula_list
    if len(formula) == 1:
        formula_list.append(formula)
        return 0
    no = copy.deepcopy(formula)
    yes = copy.deepcopy(formula)
    yes.insert(count, "+")

    count += 1

    if count < len(yes)-1:
        insert_(yes, count+1)
        insert_(no, count)
    else:
        formula_list.append(no)
        formula_list.append(yes)

def sum_list(for_list):
    s = 0
    for i in for_list:
        num = "".join(i)
        num = map(int, num.split("+"))
        s += sum(num)
    return s


insert_(s, 1)
print(sum_list(formula_list))

Submission status: Accepted

Solution code:
def test():
    s = list(input())
    l = len(s)-1
    ans = 0

    for i in range(2**l):
        op = [""]*l
        for j in range(l):
            if (i>>j)&1:
                op[j] = "+"
        res = ""
        for n,k in zip(s,op+[""]):
            if len(k) == 1:
                res += n+k
            else:
                res += n + ""
        ans += eval(res)
    print(ans)


if __name__ == "__main__":
    test()

Submission status: Accepted

Solution code:
s=input()
n=len(s)
a=2**(n-1)
t = [bin(i)[2:] for i in range(a)]
for i in range(a):
    t[i]='0'*(n-1-len(t[i]))+t[i]
    t[i]=t[i][::-1]
ans=0
#print(s)
#print(t)
for i in range(a):
    k=0
    for j  in range(n-1):
        if t[i][j]=="1":
            ans+=int(s[k:j+1])
            #print(s[k:j+1])
            k=j+1
            #print(ans,i,j)
    #print("ah",s[k:n])
    ans+=int(s[k:n])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def saiki(n,temp,start,ans):
    if n==len(S):
        if start==n:
            ans+=temp
            return ans
        else:
            return ans
    
    ans=saiki(n+1,temp+int(S[start:n+1]),n+1,ans)
    ans=saiki(n+1,temp,start,ans)
    
    return ans


S=input()


print(saiki(0,0,0,0))