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:
import itertools
import copy as c
s=list(input())
S=[s[i//2] if i%2==0 else " " for i in range(len(s)*2-1) ]
Ssub=S
ans=0
T=[i for i in range(len(s)*2-1) if i%2==1]
for sss in range(len(s)):
  for ttt in list(itertools.combinations(T,sss)):
    for rrr in ttt:
      S[rrr]="+"
    S="".join(S).replace(" ","")
    ans+=eval("".join(S))
    S=c.deepcopy(Ssub)
#print(S,T)
print(ans)

Submission status: Accepted

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

ans = 0
if max_pos > 0:
    for i in range(1 << max_pos):
        total = 0
        fragment = ""
        for j in range(len(S)):
            digit = S[j]
            fragment += digit
            if j == len(S) - 1 or ((i >> j) & 1) == 1:
                total += int(fragment)
                fragment = ""
        ans += total
else:
    ans = int(S)

print(ans)

Submission status: Accepted

Solution code:
s=input()
n=len(s)-1
a=0
for i in range(1<<n):
  l=[]
  for x,y in zip(s,[''for _ in[0]*10]):
    l.append(x)
    l.append(y)
  for j in range(n):
    if i>>j&1:
      l[j*2+1]='+'
  a+=eval(''.join(l))
print(a)

Submission status: Accepted

Solution code:
s = input()
A = []
for i in range(2 ** (len(s) - 1)):
    t = ''
    for j in range(len(s)):
        t += s[j]
        if j != len(s) - 1:
            if i % 2 == 0:
                t += '+'
        else:
            break
        i //= 2
    A.append(eval(t))
print(sum(A))

Submission status: Accepted

Solution code:
S = input()
power = len(S)-1
loop = 2**power

revS = list(reversed(S))
ans = 0

for i in range(loop):
    ans += int(revS[0])
    multi_ten = 10
    for j in range(power):
        digit = bin(i>>j)[-1]
        if digit == "0":
            ans += int(revS[j+1])*multi_ten
            multi_ten *= 10
        else:
            ans += int(revS[j+1])
            multi_ten = 10
print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
for i in range(2 ** (len(S) - 1)):
    t = ''
    for s in S:
        t += s
        if i % 2 != 0:
            t += '+'
        i //= 2
    ans += eval(t)
print(ans)

Submission status: Accepted

Solution code:
def f(s: str):
    n = len(s)

    m = {
        "0": "",
        "1": "+"
    }
    ans = 0
    for bit in range(0, 1<<(n-1)):
        bits = "{:b}".format(bit).zfill(n-1)
        # print(bits)

        ss = s[0]
        for op, x in zip(bits, s[1:]):
            ss += m[op] + x
        ans += sum(map(int, ss.split("+")))
    return ans


print(f(input()))

Submission status: Accepted

Solution code:
from sys import setrecursionlimit; setrecursionlimit(10**9)
S = input()

def res(S, A, B):
    if not S:
        B.append(sum(list(map(int, A))))
        return None
    A += [S[0]]
    res(S[1:], A, B)
    A.pop()
    A[-1] += S[0]
    res(S[1:], A, B)
    return B

if len(S) == 1:
    print(int(S))
else:
    B = res(S[1:], [S[0]], [])
    print(sum(B))

Submission status: Accepted

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

if n==1:
    ans=int(s)
else:
    for b in range(0, 1<<n-1):
        bits=[((b>>i)&1)!=0 for i in range(n-1)]
        t=s[0]
        for i in range(n-1):
            if bits[i]:
                t+='+'
            t+=s[i+1]
        ans+=eval(t)
print(ans)

Submission status: Accepted

Solution code:
s = input()

cnt = 0
for i in range(2 ** (len(s) - 1)):
    t = ''
    for j in s:
        t += j
        if i % 2 == 1:
            t += '+'
        i //= 2
    cnt += eval(t)
    
print(cnt)

Submission status: Accepted

Solution code:
*a, = map(int, list(input())[::-1])
n = len(a)

b = [[0]*k for k in range(n+1)]
for k in range(n+1):
    for i in range(k):
        b[k][i] = sum([10**j * a[i+j] for j in range(k-i)])
# b[k][i]は整数"a[k-1]a[k-2] ... a[i]"

dp = [0]*n
for k in range(n):
    dp[k] = sum([b[k+1][0]] + [b[k+1][i+1]*2**i + dp[i] for i in range(k)])

print(dp[n-1])

Submission status: Accepted

Solution code:
from itertools import product as p
s=list(input())
*t,=p(["+",""],repeat=len(s)-1)
v=0

for i in t:
  b=""
  for j in range(2*len(s)-1):
    if j%2:
      b+=i[j//2]
    else:
      b+=s[j//2]
  v+=eval(b)

print(v)

Submission status: Accepted

Solution code:
s=input()
count=0
for i in range(2**(len(s)-1)):
    t=""
    for j in s:
        t+=j
        if i%2==1:
            t+="+"
        i//=2
    #print(t)
    count+=eval(t)
print(count)

Submission status: Accepted

Solution code:

s =input()
n = int(s)
r = 0
p=0
for bit in range(2**(len(s)-1)):
    e = s[0]
    for i in range(len(s)-1):
        if ((bit>>i)&1) == 1:
            e += '+'
        e += s[i+1]
        #print(e)
    r+= sum(map(int, e.split('+')))
    p+= eval(e)
print(r)

Submission status: Accepted

Solution code:
def combi(n):
    if len(n) > 1:
        a = n.pop()
        for i in combi(n):
            yield i + [a]
            yield i + ['+', a]
    else:
        yield n

s = 0
for i in combi(list(input())):
    s += eval(''.join(i))

print(s)

Submission status: Accepted

Solution code:
s = input().strip()
ls = len(s)
total = 0

for i in range(1, ls+1):
  for j in range(0, ls-i+1):
    total += int(s[j:j+i]) * pow(2, max(0,j-1)+max(0, ls-i-j-1))
print(total)

Submission status: Accepted

Solution code:
s=str(input())
l=len(s)
ans=0
conb=[]
for i in range(2**(l-1)):
    no=i
    x=[]
    for j in range(l-1):
        tar=no%2
        if tar==1:
            x.append(j)
        no=no//2
    conb.append(x)
def tasu(s,p):
    kosuu=len(p)
    count=0
    now=0
    for k in range(kosuu):
        count+=int(s[now:p[k]+1])
        now=p[k]+1
    return count
for k in range(len(conb)):
    p=conb[k]
    p.append(l)
    ans+=tasu(s,p)
print(ans)

Submission status: Accepted

Solution code:
ans = 0
 
def dfs(i, cur, sum_v):
    global ans, S
    if i == len(S)-1:
        ans += sum_v
        return 
    dfs(i+1, int(S[i+1]), sum_v+int(S[i+1]))
    dfs(i+1, cur*10+int(S[i+1]), sum_v+cur*9+int(S[i+1]))
 
S = input()
dfs(0, int(S[0]), int(S[0]))
print(ans)

Submission status: Accepted

Solution code:
ans = 0
 
def dfs(S, i, cur, sum_v):
    global ans
    if i == len(S)-1:
        ans += sum_v
        return 
    dfs(S, i+1, int(S[i+1]), sum_v+int(S[i+1]))
    dfs(S, i+1, cur*10+int(S[i+1]), sum_v+cur*9+int(S[i+1]))
 
S = input()
dfs(S, 0, int(S[0]), int(S[0]))
print(ans)

Submission status: Accepted

Solution code:
S = input()

L = len(S) - 1
cand = []

for bit in range(1 << L):
    wh = []
    for i in range(L):
        if (bit & (1 << i)):
            wh.append(i)
    tmp = []
    prev = 0
    for i in wh:
        tmp.append(int(S[prev:i+1]))
        prev = i+1
    tmp.append(int(S[prev:]))
    cand.append(sum(tmp))
print(sum(cand))

Submission status: Accepted

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

# 125 => 125, 1+25, 12+5, 1+2+5
# i文字目までの数字を使った時の和が sum_v

ans = 0

def dfs(S, i, cur, sum_v):
    global ans
    # print(cur,)
    if i == len(S)-1:
        ans += sum_v
        return 
    dfs(S, i+1, int(S[i+1]), sum_v+int(S[i+1]),)
    dfs(S, i+1, cur*10+int(S[i+1]), sum_v+cur*9+int(S[i+1]))

S = input()
dfs(S, -1, 0, 0)
print(ans//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)
sum = 0
# 数字の間を全探索
for i in range(2**(n-1)):
    f = ""
    for j in range(n):
        f += s[j]
        # iを右にj個削り、1桁目のビットが1かどうか
        if i>>j & 1 == 1:
            f += "+"
    sum += eval(f)
print(sum)

Submission status: Accepted

Solution code:
from itertools import product
s = input()
firstnum = s[0]
s = s[1:]
ans = 0
for c in product(range(2),repeat=(len(s))):
    formula = firstnum
    for i in range(len(s)):
        if c[i] == 1:
            formula += '+'
        formula += s[i]
    ans += eval(formula)

print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = 0
#数字の間を全探索
for i in range(2**(n-1)):
    f = ""
    for j in range(n):
        f += s[j]
        #iを右にj個削り、１桁目のビットが１かどうか
        if i>>j & 1 == 1:
            f += "+"
    #print(f)
    ans += eval(f)
print(ans)

Submission status: Accepted

Solution code:
a = input()
ar = []
for i in range(len(a)):
    ar.append(a[i])
n = len(ar)
ret = 0
for i in range(2**(n-1)):
    s = "+"
    tmp = ""
    for j in range(n):
        if (1 & (i >> j)) == 1:
            tmp += ar[j]
            tmp += s
        else:
            tmp += ar[j]
    stmp = tmp.split("+")
    ret += sum(int(k) for k in stmp)
print(int(ret))

Submission status: Accepted

Solution code:
#C 解3
S = input()
n = len(S) - 1 # 間の数
Sum = 0
for i in range(2**n):
    #print('%05d' % i)#
    pl = ''
    for j in range(n):
        pl += S[j]
        #print(j)#
        if format(i,'0'+str(n)+'b')[j]=='1': pl += '+' 
    pl += S[n]
    #print(pl,end=',')#
    Sum += sum([int(x) for x in pl.split('+')])
print(Sum)

Submission status: Accepted

Solution code:
#C
import math

S = int(input())
#print(S)#
sum = 0
def gen(n, post, sum):
    #print('n, post, sum -- ', n, post, sum)#
    if n<10: 
        #print(post)#
        if post==0: return n+sum
        else: return n * 10**int(math.log10(post)+1) + post + sum
    else:
        nxn = n//10
        d = n%10
        if post==0: nxpost = d
        else: nxpost = d * 10**int(math.log10(post)+1) + post
        # dの左に+をいれるか否か
        #print('next n, post, sum -- ', nxn, nxpost, sum)
        pluson = gen(nxn, 0, nxpost+sum)  # +入り 
        plusoff = gen(nxn, nxpost, sum) # +なし
        #print(pluson, plusoff)#
        return pluson + plusoff
print(gen(S, 0, 0))

Submission status: Accepted

Solution code:
n=input()
size=len(n)
#print(n,size)

ans=0
for i in range(2**(size-1)):
    z=format(i,'b').zfill(size-1)
#    print(z)
    string=n[0]
    for j in range(size-1):
        if z[j]=='1':
            string+='0'+n[j+1]
        elif z[j]=='0':
            string+=n[j+1]
    string=string.replace('0','+')
    ans+=eval(string)

print(ans)

#12656242944

Submission status: Accepted

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

ans = 0
ops = list(product("+ ", repeat=len(S)-1))
for op in ops:
    ans += eval((S[0]+"".join(x+y for (x,y) in zip(op,S[1::]))).replace(" ",""))

print(ans)

Submission status: Accepted

Solution code:
import copy
s = input()
n=len(s)
ints=int(s)

# くっつけるか、数値としてたすパターンを再帰関数で回せばいい

all_sum=[0]
num = []
# 各桁のそれぞれの数字を出力するアルゴリズム
while ints != 0:
  # print(num)
  num.append(str(ints % 10))
  ints //= 10
num.reverse()



def DFS(num,count,sum):
    if count==n:
        # print(num)
        # print(sum)
        all_sum[0]+=sum
        return
    
    num_coppy = copy.deepcopy(num)
    # そのまま足しちゃう
    
    sum+=int(num_coppy[count])
    # print(int(num_coppy[count]))
    count+=1
    DFS(num_coppy,count,sum)

    count-=1

    #　一個後とくっつける
    if count<=n-2:
        
        num_coppy[count+1]=num_coppy[count]+num_coppy[count+1]
        sum -= int(num_coppy[count])
        count+=1
        DFS(num_coppy,count,sum)


    
    return

    
    
    
DFS(num,0,0)
    

print(all_sum[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(2**(n-1)):
    eq = ''
    for j,c in enumerate(s):
        eq += c
        if i & (1<<j):
            eq += '+'
    ans += eval(eq)

print(ans)

Submission status: Accepted

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

kotae = 0
for i in range(2**(slen-1)):
    si = s
    for j in range(slen-1):
        if i & 1<<j:
            si = si[:slen-j-1]+"+"+si[slen-j-1:]
        else:
            pass
    kotae += eval(si)

print(kotae)

Submission status: Accepted

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

def keisan(s):
    smod = s
    wa = 0
    while smod.count("+") != 0:
        wa += int(smod[:smod.index("+")])
        smod = smod[smod.index("+")+1:]
    wa += int(smod)
    return wa

kotae = 0
for i in range(2**(slen-1)):
    ibin = bin(i)[2:]
    si = s
    for j in range(1, len(ibin)+1):
        if ibin[-j] == "1":
            si = si[:slen-j]+"+"+si[slen-j:]
        else:
            pass
    kotae += keisan(si)

print(kotae)

Submission status: Accepted

Solution code:
N = list(input())
l = []

for i in range(2**len(N)):
    eq = ''
    for j in range(len(N)):
        if j == len(N)-1:
            eq += N[j]
            break
        if (i >> j) % 2 == 1:
            eq += N[j] + '+'
        else:
            eq += N[j]
    l.append(eq)

ans = 0
for l_ in l:
    ans += eval(l_)
print(ans//2)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
total = 0
for i in range(2**(N - 1)):
    eq = ''
    for j, c in enumerate(S):
        eq += c
        if i & (1 << j):
            eq += '+'
    total += eval(eq)
print(total)

Submission status: Accepted

Solution code:
s = input()
l = [s[0]]
d = len(s) - 1
if d == 0:
  print(s)
  exit()
def operate_1(string):
  return string
def operate_2(string):
  string += "+"
  return string
# l,d は未定義注意
def bfs(list_hoge = l,depth = 0,deepest = d):
    queue = []
    for e in list_hoge:
        for b in [0,1]:
            if b == 0:
                operated = operate_1(e)
                operated += s[depth + 1]
                queue.append(operated)
            elif b == 1:
                operated = operate_2(e)
                operated += s[depth + 1]
                queue.append(operated)
    list_hoge = queue[:]
    depth += 1
    if depth == deepest:
        return list_hoge
    else:
        return bfs(list_hoge,depth)
ans = 0
for e in bfs():
  ans += eval(e)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
s = input()
s2 = s

t = []
t2 = []
u = []
ans = int(s)
p = 0
digit = 0
for i in range(len(s)):
    u.append([])
for i in range(len(s)):
    t.append(i)
    if i != len(s) - 1:
        t2.append(i)
    u[i].append(i)
    u[i].append(s[i])
addli = []
for k in range(1, len(s)):
    for balls in itertools.combinations(t2, k):
        for call in balls:
            if p != 0:
                call = call - digit
            r2 = s2
            s3 = r2[:call + 1]
            s2 = r2[call + 1:]
            ss3 = s3
            addli.append(int(ss3))
            p += 1
            digit += len(s3)
            if len(balls) == p:
                addli.append(int(s2))
        ans += sum(addli)

        addli = []
        p = 0
        s2 = s
        digit = 0
print(ans)

Submission status: Accepted

Solution code:
# N,M = [int(n) for n in input().split()]
# S = str(input())
# T = str(input())
S = [s for s in str(input())] # ['1', '2', '5']

sum =0
for bit in range(1 << len(S) -1):
    l = []
    tmpS = [s for s in S]
    for i in range(len(S) -1):
        if(bit & (1 << i)):
            l.append(i)
    for i in l:
        tmpS[i] += "+"
    sum+=eval("".join(tmpS))

print(sum)

Submission status: Accepted

Solution code:
s = input()
s_split = [s[i] for i in range(len(s))]
result = 0

for i in range(2**(len(s)-1)):
    b = bin(i)[2:]
    b = b.zfill(len(s)-1)
    tmp = s_split.copy()

    for j in range(len(b)-1, -1, -1):
        if b[j] == "1":
            tmp.insert(-j-1, "+")


    result += eval("".join(tmp))
print(result)

Submission status: Accepted

Solution code:
s = input()
s_split = [s[i] for i in range(len(s))]
result = 0

for i in range(2**(len(s)-1)):
    b = bin(i)[2:]
    b = b.zfill(len(s)-1)
    tmp = s_split.copy()

    for j in range(len(b)-1, -1, -1):
        if b[j] == "1":
            tmp.insert(-j-1, "+")

    before = ""
    num = 0
    for x in range(len(tmp)):
        if tmp[x] == "+":
            num += int(before)
            before = ""
        else:
            before += tmp[x]
    if len(before) != 0:
        num += int(before)
    result += num
print(result)

Submission status: Accepted

Solution code:
import itertools


def main():
    s = input()
    res = int(s)
    all_indices = list(range(1, len(s)))
    for r in range(1, len(all_indices) + 1):
        for indices in itertools.combinations(all_indices, r):
            ss = s[:]
            for i in sorted(indices, reverse=True):
                ss = ss[:i] + '+' + ss[i:]
            res += eval(ss)
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(2**(N-1)):
    s = S[:]
    for j in range(N):
        if i & 2**j:
            s[j] = s[j]+ '+'
    ans += eval(''.join(s))

print(ans)

Submission status: Accepted

Solution code:
import itertools

S=input()
L=len(S)
ITER=list(itertools.product([0,1],repeat=(L-1)))
ANS=0

for iter in ITER:
    PLUS=S[0]
    for j in range(L):
        if  j==L-1:
            ANS+=int(PLUS)
        elif iter[j]==0:
            ANS+=int(PLUS)
            PLUS=S[j+1]
        else:
            PLUS+=S[j+1]

print(ANS)

Submission status: Accepted

Solution code:
# encoding: utf-8
S = list(map(int, list(input())))
N = len(S)

def ans(bits):
    term = 0
    ret = 0
    for i, Si in enumerate(S):
        term = term * 10 + Si
        bit = (bits >> i) % 2
        if bit == 1:
            ret += term
            term = 0
    ret += term
    # print("##", bits, ret)
    return ret

def acm(pos, bits):
    # end
    # print("#", pos, "{:010b}".format(bits))
    if pos == N - 1: return ans(bits)
    # branch
    return acm(pos + 1, bits) + acm(pos + 1, bits + (1 << pos))

print(acm(0, 0))

Submission status: Accepted

Solution code:
S = [int(_) for _ in input()]
ans = 0
for i in range(len(S)):
    for j in range(i, len(S)):
        count = 2 ** i
        if j < len(S) - 1:
            count *= 2 ** (len(S) - 2 - j)
        ans += count * S[i] * 10 ** (j - i)
print(ans)

Submission status: Accepted

Solution code:
s = input()

N = [i for i in range(len(s)-1)]  # N = bit探索する桁数
# Nの要素の全組み合わせが出力
sum = 0
for i in range(1 << len(N)):
    output = []
    tmp = s[0]
    for j in range(len(N)):
        if ((i >> j) & 1) == 1:
            tmp += "+" + s[j + 1]
            output.append(j)  # このjが今回探索するindexの1つ
        else:
            tmp += s[j+1]
    # print(output)
    # print(tmp)
    sum += eval(tmp)
print(sum)

Submission status: Accepted

Solution code:
# input
l = [int(x) for x in list(input())]

N = len(l)
ans = 0

for i in range(N):
    for k in range(N - i - 1):
        ans += (2 ** i) * (2 ** (N - i - k - 2)) * (10 ** k) * l[i]
    ans += (2 ** i) * (10 ** (N - i - 1)) * l[i]

print(ans)

Submission status: Accepted

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

for i in range(2**(N-1)):
    Scop = S[:] 
    for j in range(N-1):
        if i & 2**j:
            Scop[j] = Scop[j]+'+'
    ans += eval(''.join(Scop))
    #print(Scop)

print(ans)

Submission status: Accepted

Solution code:
def dfs(nums):
    if len(nums) == 1:
        return int(nums[0])
    if len(nums) == 0:
        return 0
    curr_sum = 0
    curr_sum += int(''.join(nums))
    for i in range(len(nums)-1):
        a = nums[:i+1]
        b = nums[i+1:]
        a_sum = int(''.join(a))
        curr_sum += dfs(b) + a_sum * pow(2, len(b)-1)
    return curr_sum


S = input()
s = list(S)
print(dfs(s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
if len(s)!=1:
  l=[]
  for k in range(2**(len(s)-1)):
    l.append(format(k,'0'+str(len(s)-1)+'b'))
  c=0
  for i in range(2**(len(s)-1)):
    m=list(l[i])
    m.append('1')
    x=0;y=0
    for j in range(len(s)):
      if m[j]=='0':y+=1
      else:
        c+=int(s[x:x+y+1])
        x=j+1
        y=0
  print(c)
else:print(int(s))

Submission status: Accepted

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

ans = 0
for b in reversed(range(2**(n-1))):
    sb = s
    for i in reversed(range(n-1)):
        if (b>>i)&1 == 1:
            sb = sb[:i+1] + "+" + sb[i+1:]
#     print(sb)
    ans += eval(sb)
    
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    S = input()
    ans = 0

    for n in range(2**(len(S)-1)):
        B = to_bin(n)

        B = "0" * (len(S) - len(B) - 1) + B

        expr = S[0]
        for b,s in zip(B, S[1:]):
            if b == "1":
                expr += "+"
            expr += s


        ans += eval(expr)

    print(ans)


main()

Submission status: Accepted

Solution code:
S = input()

def func(S, i):
    if len(S) <= i:
        return eval(S)
    S1 = S[:i] + '+' + S[i:]
    return func(S, i + 1) + func(S1, i + 2)

print(func(S, 1))

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
S = raw_input()
N = len(S)
r = 0
for i in range(1<<(N-1)):
  t = S[N-1]
  si = 0
  for j in range(N-1):
    x = S[N-2-j]
    if (1<<j & i)>0:
      si += int(t)
      t = x
    else:
      t = x+t
  si += int(t)
  r += si
print r

Submission status: Accepted

Solution code:
S = input()
cnt = 0
for p in range(2 ** (len(S) - 1)):
  F = S[0]
  for i in range(len(S) - 1):
    F += '+' if p % 2 else ''
    F += S[i + 1]
    p //= 2
  cnt += sum([int(f) for f in F.split('+')])
print(cnt)

Submission status: Accepted

Solution code:
s = list(input())

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

Submission status: Accepted

Solution code:
s=list(input())
b=0
a=[[0 for i in range(len(s))] for j in range(len(s))]
if len(s)>=3:
    a[0][0],a[0][1]=1,1
    for i in range(2,len(s)):
        a[0][i]=a[0][i-1]*2
    for i in range(1,len(s)):
        for j in range(i,len(s)):
            a[i][j]=a[i-1][j-1]*2
    for i in range(len(s)):
        for j in range(len(s)):
            b+=int(s[i])*a[i][j]*10**(len(s)-j)
    print(b//10)
elif len(s)==2:
    print(11*int(s[0])+2*int(s[1]))
else:
    print(int(s[0]))

Submission status: Accepted

Solution code:
def culc(s):
    if len(s) == 0:
        return 0
    elif len(s) == 1:
        return int(s)
    count = 0
    for i in range(len(s)):
        count += culc(s[0:i])
        count += int(s[i:len(s)]) * (2 ** max(0, len(s[0:i])-1))
    return count

print(culc(input()))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S = list(map(int,list(input())))

p_num = 2**(len(S) - 1)
p = []
for i in range(p_num):
    temp_list = []
    temp = i
    for j in range(len(S) - 1):
        temp_list.append(temp % 2)
        temp //= 2

    p.append(temp_list)

g_sum = 0
for p_list in p:
    s_sum = S[0]
    add = 0
    for i in range(1,len(S)):
        if p_list[i-1] == 1:
            add += s_sum
            s_sum = S[i]
        else:
            s_sum = s_sum*10 + S[i]
    add += s_sum
    g_sum += add

print(g_sum)

Submission status: Accepted

Solution code:
S = list(map(int,list(input())))
# -*- coding: utf-8 -*-

p_num = 2**(len(S) - 1)
p = []
for i in range(p_num):
    temp_list = []
    temp = i
    for j in range(len(S) - 1):
        temp_list.append(temp % 2)
        temp //= 2

    p.append(temp_list)

g_sum = 0
for p_list in p:
    s_sum = S[0]
    add = 0
    for i in range(1,len(S)):
        if p_list[i-1] == 1:
            add += s_sum
            s_sum = S[i]
        else:
            s_sum = s_sum*10 + S[i]
    add += s_sum
    g_sum += add
    # print(p_list)
    # print(add)

print(g_sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
ans = 0

for i in range(2**(len(S)-1)):
    temp = S[0]
    for j in range(len(S)-1):
        #print(i, 1<<j, i&(1<<j))
        if i & (1<<j) != 0:
            temp += "+"
        temp += S[j+1]
    #print(temp)
    ans += eval(temp)
print(ans)

Submission status: Accepted

Solution code:
S = input()
n = len(S)-1
ans = 0
for i in range(2**n):
    i = bin(i)[2:]
    i = '0'*(n-len(i))+i
    s = ''
    for j in range(n):
        if i[j]=='1':
            s = s+S[j]+'+'
        else:
            s = s+S[j]
    s = s+S[-1]
    s = s.split('+')
    for x in s:
        ans += int(x)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def slow_solve(S):
    l = 2 ** (len(S) - 1)
    sum = 0
    for i in range(l):
        bi = ("{:0%db}" % (len(S) - 1)).format(i)
        ope = []
        for b in bi:
            if b == "0":
                ope.append("")
            else:
                ope.append("+")
        ope.append("")
        p = ""
        for s, o in zip(S, ope):
            p += s
            p += o
        sum += eval(p)
    return sum

if __name__ == "__main__":
    print(slow_solve(input()))

Submission status: Accepted

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

s=input()

ans=tmp=0
t=len(s)

for i in range(1<<(t-1)):
#    print(i)
    tmp=int(s[0])
    for j in range(t-1):
        if (i & (1<<j)):
            tmp*=10
            tmp+=int(s[j+1])
        else:
            ans+=tmp
            tmp=int(s[j+1])
    ans+=tmp
print(ans)

Submission status: Accepted

Solution code:
import itertools


def main():
    s = input()
    ans = 0
    # '+'の数
    for i in range(len(s)):
        # '+'を挟み込み可能性のある場所の全通り
        for ind in itertools.combinations(range(1, len(s)), i):
            # '+'を挟み込んだ時の文字列のズレ幅
            c = 0
            st = s
            for j in ind:
                st = st[:j + c] + '+' + st[j + c:]
                c += 1
            ans += eval(st)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
n = len(s)
a = 0
for i in range(n):
  d = int(s[i])
  for k in range(n-i):
    a += (2**i)*int(2**(k-1)+0.5)*(10**(n-i-k-1))*d
print(a)

Submission status: Accepted

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

s = stdin.readline().rstrip()
ans_list = []
ans = 0

for i in range(2**(len(s)-1)):
    s_plus = ""
    b = "{:0{}b}".format(i,len(s)-1)
    for j in range(len(s)-1):
        s_plus += s[j]
        if b[j] == "1":
            s_plus += ","
        else:
            s_plus += ""
    s_plus += s[-1]
    ans_list = s_plus.split(",")
    ans_list_int = [int(i) for i in ans_list]
    ans += sum(ans_list_int)
print(ans)

Submission status: Accepted

Solution code:
S = input()

ans = 0
N = 2**(len(S) - 1)

if len(S) == 1:
    print(S)
    exit()
for i in range(N):
    bit = bin(i)[2:]
    if len(bit) != len(S):
        bit = '0'*(len(S)-len(bit) - 1) + bit

    tmp = S[0]
#    print(bit)
    for i,b in enumerate(bit):
        if b == '0':
            tmp += S[i+1]
        else:
            ans += int(tmp)
            tmp  = S[i+1]
#            tmp += '+' + S[i+1]
    if len(tmp) > 0:
        ans += int(tmp)
print(ans)