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=str(input())
S=[]
S[0:0]=s
for i in range(len(S)):
    S[i]=int(s[i])
t=0
for i in range(len(S)):
    p=len(S)-i-1
    for j in range(p):
        t+=S[i]*10**j*2**(len(S)-j-2)
    t+=S[i]*10**p*2**i
print(t)

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 = str(input())
L = len(S)

lst = []
for i in range(2**(L-1)):
    lst.append(bin(i))
    lst[i] = lst[i][2:]
    lst[i] = lst[i].zfill(L-1)

res = []

for j in lst:
    lst_s = list(S)
    for k in range(L-1):
        if j[k] == "0":
            lst_s[k+1] = lst_s[k] + lst_s[k+1]
            lst_s[k] = "0"
        else:
            pass
    for l in range(L):
        lst_s[l] = int(lst_s[l])
    res.append(sum(lst_s))

print(sum(res))

Submission status: Accepted

Solution code:
s = input()
ans = 0
for i in range(2 ** (len(s) - 1)):
    fom_lst = []
    for j in range(len(s) - 1):
        if (i >> j & 1):
            fom_lst.append('+')
        else:
            fom_lst.append('')
    S = ''
    for num, fom in zip(s, fom_lst):
        S += num + fom
    S += s[-1]
    if '+' in S:
        ans += sum(map(int, S.split('+')))
    else:
        ans += int(S)

print(ans)

Submission status: Accepted

Solution code:
n = [int(x) for x in input()]
op_cnt = len(n)-1
sum =0
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] ='+'
  formula =''

  for p_n, p_o in zip(n, op+[""]):
    formula += (str(p_n) + p_o)
  sum +=eval(formula)

print(sum)

Submission status: Accepted

Solution code:
lst = [x for x in input()]
n = len(lst)
ret_lst = []


def hoge(idx, currnet):

    if idx == n:
        ret_lst.append(currnet)
    else:
        hoge(idx + 1, currnet + lst[idx])
        hoge(idx + 1, currnet + "+" + lst[idx])


hoge(1, lst[0])
ret = 0
for s in ret_lst:
    ret += sum([int(x) for x in s.split("+")])
print(ret)

Submission status: Accepted

Solution code:
import itertools

s = input()
n = len(s)

ans = 0
for v in itertools.product([0, 1], repeat=n-1):
    lst = list(v)
    idx = 0
    for i in range(n-1):
        if lst[i] == 1:
            ans += int(s[idx:i+1])
            idx = i + 1
    ans += int(s[idx:])
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:
from itertools import product
s = input()
l = len(s)
ans = 0
pat = list(product(['+', ''], repeat=l-1))
for i in range(2**(l-1)):
    fom = s[0]
    for j, k in zip(pat[i], s[1:]):
        fom += (j + k)
    ans += eval(fom)
print(ans)

Submission status: Accepted

Solution code:
def dfs(i,f):
    if i == n-1:
        return(sum(map(int,f.split('+'))))

    return dfs(i+1,f+s[i+1]) +\
               dfs(i+1,f+'+'+s[i+1])
s = input()
n = len(s)
print(dfs(0,s[0]))

Submission status: Accepted

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

t_list = []

for i in range(1<<(n-1)):
    t = ['' for _ in range(n)]
    for j in range(n):
        if (i >> j) & 1:
            t[j] = '+'
    t_list.append(t)

ans = 0

for i in t_list:
    formula = [x+y for x,y in zip(s,i)]
    formula = ''.join(formula)
    ans += eval(formula)
    
print(ans)

Submission status: Accepted

Solution code:
import itertools

s = input()
sum = 0

patern = [i for i in range(len(s)-1)]
pair = []
for i in range(0, len(patern)+1):
	pair += list(itertools.combinations(patern, i))

for lst in pair:
	start = 0
	for i in lst:
		sum += int(s[start:i+1])
		start = i+1
	sum += int(s[start:len(s)]) 


print(sum)

Submission status: Accepted

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


ans = 0
t_list = []
for i in range(2**(n-1)):
    t = ['' for _ in range(n)]
    for j in range(n-1):
        if (i >> j) & 1:
            t[j] = '+'
    t_list.append(t)


for i in range(2**(n-1)):
    formula = [i+j for i,j in zip(s,t_list[i])]
    formula = ''.join(formula)
    ans += eval(formula)
    
print(ans)

Submission status: Accepted

Solution code:
S = input()
count = 0


def calculate(isPlus):
    #print(isPlus)
    ans = 0
    start = 0
    for i in range(len(isPlus)):
        if isPlus[i]:
            #print('i=', i, 'ans+=', S[start:i+1])
            ans += int(S[start:i+1])
            start = i+1
        if i == len(isPlus)-1:
            #print('i=', i, 'ans+=', S[start:])
            ans += int(S[start:])

    return ans


def recursion(depth, isPlus):
    global count
    if depth == len(S)-1:
        count += calculate(isPlus)
    else:
        recursion(depth=depth+1, isPlus=isPlus+[False])
        recursion(depth=depth+1, isPlus=isPlus+[True])


if len(S) == 1:
    print(S)
else:
    recursion(depth=0, isPlus=[])
    print(count)

Submission status: Accepted

Solution code:
s = input()

x = [list(map(int,bin(x)[2:].zfill(len(s)-1))) for x in range(2**(len(s)-1))]
ans = 0
sp1 = 0
sp2 = 0
for i in range(len(x)):
    for j in range(len(s)-1):
        if x[i][j]==1:
            sp1 = j+1
            ans += int(s[sp2:sp1])
            sp2 = sp1
    sp2=0
    ans += int(s[sp1:])
print(ans)

Submission status: Accepted

Solution code:
s = input()

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
def solve(input_s):
    length = len(input_s)
    ans = []
    
    def func(i, n):
        if i == length-1:
            ans.append(sum(map(int, n.split("+"))))
        else:
            func(i+1, n+"+"+input_s[i+1])
            func(i+1, n+input_s[i+1])

    func(0, input_s[0])
    return sum(ans)

if __name__ == "__main__":
    input_s = input()
    print(solve(input_s))

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
kotae=[]
#配列のi番目の後に+を入れるかどうか,考える前までにできている文字列をchar
def dfs(i,char):
  if i==n-1:
    kotae.append(sum(list(map(int,char.split("+")))))
  else:
    dfs(i+1,char+"+"+s[i+1])
    dfs(i+1,char+s[i+1])
dfs(0,s[0])
print(sum(kotae))

Submission status: Accepted

Solution code:
s=input()

l=len(s)-1

sums=[]

for i in range(2**l):

    inds=[0]

    for j in range(l):
      
        if (i>>j) & 1==1:
            inds.append(j+1)
            
    if len(inds)==1:
        sums.append(int(s))
    else:
        nums=[]
        
        for j in range(len(inds)-1):
            nums.append(int(s[inds[j]:inds[j+1]]))

        nums.append(int(s[inds[-1]:]))

        total=0
        for  n in nums:
            total+=n
        
        sums.append(total)
      
res=0
for n in sums:
    res+=n
  
print(res)

Submission status: Accepted

Solution code:
def resolve():
    S = input()
    total = int(S)
    for bits in range(1<<(len(S)-1)):
        _total = 0
        prev = 0
        for odr in range(len(S)-1):
            if (bits & (1<<odr)):
                _total += int(S[prev:odr+1])
                prev = odr+1
        if bin(bits).count("1") > 0 and len(S[prev:]) > 0:
            _total += int(S[prev:])
        total += _total
    print(total)


if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
import math
import fractions
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################



ss = input()
n = len(ss)
s=[]
for i in range(n):
    s.append(int(ss[i]))

ans = 0
for i in range(2**(n-1)):
    d=[[]]
    bit = ValueToBits(i,n-1)
    for j in range(n-1):
        d[-1].append(s[j])
        if(bit[j]==1):
            d.append([])
    d[-1].append(s[n-1])
    #print(d)
    
    for j in d:
        for k in range(len(j)):
            ans += 10**(len(j)-1-k) * j[k]

            



print(ans)

Submission status: Accepted

Solution code:
import itertools
S=input()
N=len(S)-1
sum1=0

for i in itertools.product(["+",""],repeat=N):
    ans=""
    for x in range(N):
        if i[x]=="+":
            ans+=S[x]+i[x]
        else:
            ans+=S[x]
    ans+=S[-1]
    sum1+=eval(ans)
print(sum1)

Submission status: Accepted

Solution code:
import itertools
s=input()
ans=0
rep=len(s)-1

for i in itertools.product(["+", ""], repeat=rep):
    temp=""
    #print(i)
    for j in range(rep):
        temp+=s[j]
        temp+=i[j]
    temp+=s[-1]
    ans+=eval(temp)
    #print(temp)

print(ans)

Submission status: Accepted

Solution code:
import itertools
s=list(input())
n=len(s)
sum1=0

for v in itertools.product(["+",""],repeat=n-1):
    a=""
    for i in range(n-1):
        if v[i]=='+':
            a+=s[i]+v[i]
        else:
            a+=s[i]
    
    a+=s[-1]
    sum1+=eval(a)
print(sum1)

Submission status: Accepted

Solution code:
#直積を使った方法
from itertools import product
s = input()
n = len(s)
su = 0
l = list(product(["+",""], repeat=n-1))
for i in range(2**(n-1)):
  a = "0+"
  for j,k in zip(s,l[i]):
    a += j+k
  a += s[-1]
#  print(a)
  su += eval(a)
print(su)

Submission status: Accepted

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

Submission status: Accepted

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

total = 0
for i in range(2**plusi):
    prej = 0
    ret = []
    for j in range(plusi):
        if (i >> j) & 1:
            total += int(S[prej:j+1])
            prej = j + 1
    total += int(S[prej:plusi+1])
print(total)

Submission status: Accepted

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

patterns = []
for i in range(2**(l-1)):
    pattern = [''] * (l-1)
    for j in range(l-1):
        if (i >> j & 1):
            pattern[j] = '+'
    patterns.append(pattern)

ans = 0
for pattern in patterns:
    a = s[0]
    for i in range(l-1):
        if (pattern[i] == ''):
            a += s[i+1]
        else:
            ans += int(a)
            a = s[i+1]
    else:
        ans += int(a)

print(ans)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
ans=0
k=pow(2,n-1)
i=0
while i<k:
    m=i
    sum=int(s[n-1])
    x=10
    p=n-2
    while p>-1:
        if m%2==0:
            sum+=int(s[p])*x
            x*=10
        else:
            sum+=int(s[p])
            x=10
        m=m//2
        p-=1
    ans+=sum
    i+=1
print(ans)

Submission status: Accepted

Solution code:
S=input()
N=len(S)-1
ans=0
if len(S)==1:
    print(S)
    exit()
for i in range(2**N):
    op=["-"]*N
    for j in range(N):
        if ((i>>j)&1):
            op[N-1-j]="+"
    #print(op)
    l=[]
    tmp=""
    for k in range(N):
        tmp=tmp+S[k]
        if k==(N-1):
            if op[k]=="+":
                l.append(tmp)
                l.append(S[-1])
            else:
                tmp=tmp+S[-1]
                l.append(tmp)
            break
        if op[k]=="+":
            l.append(tmp)
            tmp=""
        else:
            pass
    #print(l)
    for k in range(len(l)):
        val=int(l[k])
        ans+=val

print(ans)

Submission status: Accepted

Solution code:
s = list(input())
l = len(s)-1
li = ["+",0]
L = [0]*(l)

from itertools import product
sum1 = 0
for v in product(li,repeat = l):
    a = ""
    for i in range(l):
        if v[i] == "+":
            a += s[i] + (v[i])
        else:
            a +=s[i]
    a +=s[-1]
    sum1 += eval(a)
print(sum1)

Submission status: Accepted

Solution code:

s = input()

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

print(ans)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

def main():
    S = readline().rstrip()
    N = len(S)
    ans = 0
    for i in range(2**(N-1)):
        b = bin(i)[2:].zfill(N-1)
        f = [S[i]+'+' if b[i]=='1' else S[i] for i in range(N-1)]
        f += S[-1]
        ans += eval(''.join(f))
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 23 02:13:44 2020

@author: Kanaru Sato
"""

s = input()
n = len(s)

count = 0

for state in range(2**(n-1)):
    nums = s
    for i in range(n-1):
        if state & (1<<i):
            nums = nums[:n-1-i]+"+"+nums[n-1-i:]
    count += sum(map(int, nums.split("+")))

print(count)

Submission status: Accepted

Solution code:
S = list(map(int,list(input())))
N = len(S)
ans = 0
for i in range(2 ** (N - 1)):
    cnt = 0
    temp = S[0]
    for j in range(N - 1):
        flag = i & 1
        if flag:
            cnt += temp
            temp = S[j + 1]
        else:
            temp = temp * 10 + S[j + 1]
        i >>= 1
    ans += cnt + temp
print(ans)

Submission status: Accepted

Solution code:
S=input()
 
ls = len(S)
res = 0

for i in range(0,ls):
    x = S[ls-i-1]
    a = 0    
    b = 2**(ls-1)
    for j in range(0,i+1):
        if j == i:
            b = b
        
        else:
            b = b//2
        a = a+(10**j)*b
    res  =  res + int(x)*a

print(res)

Submission status: Accepted

Solution code:
S = input()

cnt = 0
for i in range(1 << (len(S) - 1)):
    t = i
    l = 0
    r = 1
    while t > 0:
        if t % 2 == 1:
            cnt += int(S[l:r])
            l = r
            r += 1
        else:
            r += 1
        t >>= 1
    cnt += int(S[l:])

print(cnt)

Submission status: Accepted

Solution code:
list_N = list(input())
n = len(list_N) - 1
ans = 0
for i in range(2 ** (n)):
    cnt = 0
    c = []
    for j in range(n):
        if ((i >> j) & 1):
            c.append(int("".join(list_N[cnt:j+1])))
            cnt = j+1
    c.append(int("".join(list_N[cnt:n+1])))
    ans += sum(c)

print(ans)

Submission status: Accepted

Solution code:
import itertools
s = input()
digits = list(s)
length = len(digits)
operators = list(itertools.product([0, 1], repeat=length - 1))
total = 0
for i in operators:
    t = []
    for j in range(length - 1):
        t.append(digits[j])
        if i[j] == 1:
            t.append('+')
    t.append(digits[-1])
    total += eval(''.join(t))
print(total)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 22 23:44:20 2020

@author: Kanaru Sato
"""

def dfs(numstr,count,chara):
    if len(chara) == 1:
        return count+int(numstr+chara)
    else:
        numstr = numstr+chara[0]
        return dfs("",count+int(numstr),chara[1:])+dfs(numstr,count,chara[1:])

s = input()

print(dfs("",0,s))

Submission status: Accepted

Solution code:
s = input()

keta = []
for i in range(len(s)):
    keta.append(int(s[-(i+1)]))

ans = 0
for j in range(len(s)):
    ans += (10**j)*(keta[0]*(2**(len(s)-j-1))+(sum(keta)-keta[0])*(2**(len(s)-j-2)))
    keta = keta[1:]

print(int(ans))

Submission status: Accepted

Solution code:
from itertools import product
s = input()
s_last = s[-1]
len_s = len(s)
ttl = 0
for i in product(['', '+'], repeat=len_s- 1):
    ttl += eval(''.join(s[j] + i[j] for j in range(len_s - 1)) + s_last)
print(ttl)

Submission status: Accepted

Solution code:
s=list(map(int,list(input())))
import itertools
ans=0
for i in itertools.product([0,1], repeat=len(s)-1):
    sums=0
    snum=s[0]
    for ii in range(len(i)):
        if i[ii]==0:
            snum=snum*10+s[ii+1] 
#            print(i,ii,snum,sums)           
        else:
            sums=sums+snum
#            print(i,ii,snum,sums)
            snum=s[ii+1]
    sums=sums+snum
#    print(i)
#    print(sums,"---------")
    ans=ans+sums
print(ans)

Submission status: Accepted

Solution code:
S = input()

plus = [i for i in range(1, len(S))]

import itertools

ans = int(S)
for c in range(1, len(S)):
    for l in itertools.combinations(plus, c):
        l_ = list(l)
        formula = ""
        for i, s in enumerate(S):
            if i in l_:
                formula += "+"
            formula += s
        ans += sum([int(num) for num in formula.split("+")])
print(ans)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
import itertools
#from scipy.misc import comb

S = input()
N = len(S)

ans = 0
for i in range(1<<(N-1)):
    func = S[0]
    for j in range(N-1):
        if (i>>j)&1:
            func += '+'
        func += S[j+1]
    ans += eval(func)

print(ans)

Submission status: Accepted

Solution code:
from collections import deque
S=input()
N=len(S)
cnt=0
for i in range(pow(2,N-1)):
    d=deque()
    flag=[0]*(N-1)
    num = []
    v=[]
    for j in range(N):
        d.append(S[j])
    for j in range(N-1):
        if (i>>j)&1:
            flag[j]=1
    #print(flag)
    for j in range(N):
        s=d.popleft()
        v.append(s)
        if (j<N-1):
            if(flag[j]==1):
                s="".join(v)
                num.append(int(s))
                v=[]
        else:
            s = "".join(v)
            num.append(int(s))
            v = []
    #print(num)
    cnt=cnt+sum(num)
print(cnt)

Submission status: Accepted

Solution code:
a,b,k=0,0,1
for d in input():a,b=2*a+b,10*b+int(d)*k;k*=2
print(a+b)

Submission status: Accepted

Solution code:
S,a,b=input(),0,0
for i in range(len(S)):a,b=2*a+b,10*b+int(S[i])*2**i
print(a+b)

Submission status: Accepted

Solution code:
S = input()
a, b = 0, int(S[0])
for i in range(1, len(S)):
    d = int(S[i])
    a = 2 * a + b
    b = 10 * b + (2 ** i) * d
print(a + b)

Submission status: Accepted

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


def main():
    S = input()
    N = len(S) - 1
    result = 0
    for i in range(2**N):
        f = S[0]
        for j in range(N):
            if i >> j & 1:
                f += "+"
            f += S[j + 1]
        result += eval(f)
    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s=input()
l_s=len(s)
b='0%db'%(l_s-1)
ans=0
for i in range(2**(l_s-1)):
  t=''
  for j in range(l_s-1):
    t+=s[j]+('+' if format(i,b)[j]=='1' else '')
  t+=s[l_s-1]
  ans+=eval(t)
print(ans)

Submission status: Accepted

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

for i in range(2**(n-1)):
  index =format(i,'b').zfill(n-1)
  index = [int(ind) for ind in index]
  
  
  t = s
  for k in range(n-1):
    if index[k]==1:
      t = t[:k+1+sum(index[:k])]+ '+' + s[k+1:]

  ans += eval(t)
print(ans)

Submission status: Accepted

Solution code:

def dfs(s):
    stack = []
    push, pop = stack.append, stack.pop
    push([s,[]])

    ans = 0

    while stack:
        ss, lst = pop()
        if ss == '':
            ans += sum(lst)
        for i in range(1,len(ss)+1):
            push([ss[i:] , lst + [int(ss[:i])]])
    return ans

s = input()
print(dfs(s))

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)

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)


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)

def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split("+"))))

    # 式 f の末尾に "+" を追加するかしないかして次の数字を追加
    # 関数の足し算はメソッドを記憶したまま、各関数に分岐していく
    # → (2:返る関数が2個) ^ (n-1:再帰回数が i=0,1...でn-1回) ＝ 最終的な関数は2^(n-1)個
    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:
from collections import defaultdict
import io
import math

data = input()
counter = 0
for o in range(1 << (len(data) - 1)):
    array = data[0]
    for i in range(len(data) - 1):
        if o & 1 << i:
            array += '+'
        array += data[i + 1]
    counter += eval(array)
print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():
        S=str(input())

        # bit全探索
        # https://qiita.com/gogotealove/items/11f9e83218926211083a#%E4%BE%8B%E9%A1%8C-1
        n = len(S)-1
        if n==0:
            return int(S)
        else:
            # 昇順での探索だよ
            ans=0
            for i in range(2 ** n):
                temp = n+1
                for j in range(n):  # このループが一番のポイント
                    if ((i >> j) & 1):
                        ans+=int(S[-j-1:temp])
                        temp=-j-1
                    if j==n-1:
                        ans+=int(S[:temp])# 順
            return ans# に右にシフトさせ最下位bitのチェックを行う
    print(main())


resolve()

Submission status: Accepted

Solution code:
import sys
import fractions

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
bit = len(S)-1
Sum = 0
for b in range(2 ** bit):
    bb = b
    i = 1
    offset = 0
    s = list(S)
    while bb:
        if bb & 1:
            s.insert(i+offset, ',')
            offset += 1
        bb >>= 1
        i += 1
    Sum += sum(map(int, ''.join(s).split(',')))
print(Sum)

Submission status: Accepted

Solution code:
S=input()
t=len(S)-1
sum = 0
for bit in range(2**t):
    f=S[0]

    for i in range(t):
        if bit &(1<<i):
            f+='+'
        f+=S[i+1]
    
    sum+=eval(f)

print(sum)

Submission status: Accepted

Solution code:
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])
s = input()
n = len(s)
print(dfs(0, s[0]))

Submission status: Accepted

Solution code:
S=input()
total=0
for bit in range(1<<len(S)-1):
    evals=S[0]
    for n in range(len(S)-1):
        if bit&(1<<n):
            evals+="+"
        evals+=S[n+1]
    total+=eval(evals)
print(total)

Submission status: Accepted

Solution code:
def main():
    S = input()

    ans = 0
    for bit in range(1<<(len(S)-1)):
        left = 0
        for i in range(len(S)-1):
            if (bit >> i) & 1:
                ans += int(S[left:i+1])
                left = i + 1
        ans += int(S[left:])
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    S = input()
    strs = str(S)
    width = len(strs)
    num = 0
    
    for i in range(width, 0, -1):
        if width > i + 1:
            num += adding_first(strs, i) * 2 ** (width - i -1)
            strs = strs[1:]
        else:
            num += adding_first(strs, i)
            strs = strs[1:]
    print(num)

def adding_first(x, y):
    addition = 0
    for i in range(1, y + 1):
        a = x[0:int(i)]
        b = x[int(i):y + 1]
        if len(b) != 0:
            addition += int(a) * 2 ** (len(b)-1)
        else:
            addition += int(a)


    return addition

main()

Submission status: Accepted

Solution code:
import itertools

s = input()

reslist = []

def diverge(current_list, pos):
    if pos == len(s):
        reslist.append(current_list)
        return
    stick_list = current_list.copy()
    current_list.append(int(s[pos]))
    diverge(current_list, pos + 1)
    stick_list[-1] = stick_list[-1]*10 + int(s[pos])
    diverge(stick_list, pos + 1)

diverge([int(s[0])], 1)

# print(reslist)

sol = 0

for res in reslist:
    sol += sum(res)

print(sol)

Submission status: Accepted

Solution code:
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])


s = input()
n = len(s)

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0

# 値を入れられる場所がlen(S)-1箇所
for i in range(pow(2, len(S)-1)):
    bit = bin(i)[2:].zfill(len(S)-1)
    ind = 0
    res = 0
    for j in range(len(bit)):
        if bit[j] == "1":
            res += int(S[ind:j+1])
            ind = j+1
    res += int(S[ind:])
    ans += res

print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    S = input().rstrip()
    n = len(S)
    res = 0

    for s in range(1<<(n-1)):
        l = 0
        for i in range(n-1):
            if (s>>i) & 1:
                res += int(S[l:i+1])
                l = i+1
        res += int(S[l:])
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

s = sys.stdin.readline().rstrip()
n = len(s)

def c(n):
    return pow(2, max(0, n - 1))
  
def main():
    res = 0
    for l in range(n):
        for r in range(l, n):
            res += int(s[l:r+1]) * c(l) * c(n - 1 - r)
    print(res)

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
n = len(s)-1
ans = 0
for bit in range(1<<n):
    tmp = s
    cnt = 0
    for i in range(n):
        if 1<<i & bit:
            tmp = tmp[:i+1+cnt] + '+' + tmp[i+1+cnt:]
            cnt += 1
    ans += eval(tmp)
print(ans)

Submission status: Accepted

Solution code:
S = list(str(input()))

op_cnt = len(S) - 1
cons = 0
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] = "+"
    Ans = []
    for k in range(len(S)-1):
        Ans.append(S[k])
        Ans.append(op[k])
    Ans.append(S[-1])
    formula = ''.join(Ans)
    cons += eval(formula)

print(cons)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
ans = 0
for i in range(2**(l-1)):
    b = str(format(i, '0{}b'.format(l-1)))
    ns = ''
    for j in range(l):
        ns += s[j]
        if j!=l-1:
            if b[j]=='1':
                ns += '+'
    ans += eval(ns)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))

def main():
  s = input()
  slen = len(s)
  ans = 0
  for i in range(2**(slen-1)):
    nya = [0]
    for j in range(slen-1):
      if i >> j & 1:
        nya.append(j+1)
    nya.append(slen)
    #print(nya)
    # [0, 3]
	# [0, 1, 3]
	# [0, 2, 3]
	# [0, 1, 2, 3]
    for j in range(len(nya) - 1):
      ans += int(s[nya[j]:nya[j+1]])
  print(ans)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import itertools
 
s=input()

s=list(s)

keta = len(s)

pluscheck = []

ans = 0

for i in range(1,keta):
    pluscheck.append(i)

for i in range(keta):
    for j in itertools.combinations(pluscheck,i):
        memo = []
        for k in range(keta):
            if k in j:
                ans += int(''.join(map(str,memo)))
                memo = []
                memo.append(s[k])
            else:
                memo.append(s[k])
        ans += int(''.join(map(str,memo)))
print(ans)