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:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


s = S()
n = len(s)

ans = 0

for bit in range(1 << (n - 1)):

    f = s[0]

    for i in range(n - 1):
        if (bit >> i) & 1:

            f += "+"
        f += s[i + 1]

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

print(ans)

Submission status: Accepted

Solution code:
import itertools

s = input()

lis = list(itertools.product(["","+"], repeat = len(s)-1))

ans = 0
for i in range(len(lis)):
    evalu = ""
    for j in range(len(s)-1):
        evalu += s[j] +lis[i][j]
    evalu += s[-1]
    ans += eval(evalu)
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
s=input()
n=len(s)
ans=0
for p in product([0,1], repeat=n-1):
  wk=s[0]
  index=0
  for i in p:
    index+=1
    if i==0:
      wk+=s[index]
    else:
      ans+=int(wk)
      wk=s[index]
  if wk!="":
    ans+=int(wk)
print(ans)

Submission status: Accepted

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

# In[3]:


from itertools import product


# In[16]:


S = input()


# In[17]:


length = len(S)
ans = 0
for lst in product(["+",""], repeat=length-1):
    mystr = ""
    for i in range(length-1):
        mystr += S[i]+lst[i]
    mystr += S[-1]
    mylist = [int(x) for x in mystr.split("+")]
    ans += sum(mylist)
print(ans)


# In[ ]:

Submission status: Accepted

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

Submission status: Accepted

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

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

    for i in range(n):
        if bit & (1 << i):
            f += "+"
        f += s[i+1]
    
    ans += sum(list(map(int, f.split("+"))))

print(ans)

Submission status: Accepted

Solution code:
def many_eq(i: int, f: str) -> int:
    if i == n-1:
        return sum(list(map(int, f.split("+"))))
    
    return many_eq(i+1, f+s[i+1]) + \
        many_eq(i+1, f+"+"+s[i+1])


s = input()
n = len(s)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
ans = 0

for i in range(2 ** (len(s)-1)):
  split = [0]
  for j in range(len(s)-1):
    if (i >> j) & 1:
      split.append(j+1)
  split.append(len(s))
  for i in range(len(split)-1):
    ans += int(s[split[i]:split[i+1]])
print(ans)

Submission status: Accepted

Solution code:
s = str(input())
ans = 0
for i in range(2**(len(s) - 1)):
    l = s[0]
    for j in range(len(s)-1):
        if (i >> j) & 1:
            l += "+"
        l += s[j+1]
    ans += eval(l)#eval関数は文字列を数式としてその解を返す
print(ans)

Submission status: Accepted

Solution code:
import itertools
S = input()
npm = len(S) - 1
sum = eval(S)
pcomb = []
for i in range(npm):
    pcomb.append(list(itertools.combinations(range(1, npm + 1), i + 1)))
for j in pcomb:
    k = 0
    for l in range(len(j)):
        pcomb2 = j[k]
        npmc = 0
        F = S
        for m in pcomb2:
            F = F[:m + npmc] + "+" + F[m + npmc:]
            npmc += 1
        sum += eval(F)
        k += 1
print(sum)

Submission status: Accepted

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

def solve(S: str):
    ans = 0
    for i in range(1<<(len(S)-1)):
        # i の bit が記号の挿入位置に当たる
        # print(i, format(i, 'b'), len(format(i,'b'))-1)
        tmp =int(S[0])
        for j in range(len(S)-1):
            # print(format(i, 'b'), j, bool(i & (1<<j))) # 挿入位置の判定
            if i & (1<<j): ans+=tmp;tmp=0;
            tmp*=10
            tmp+=int(S[j+1])
        ans+=tmp
    print(ans)
def main():
    def read(): return sys.stdin.readline().rstrip()
    solve(read())

if __name__ == '__main__':
    main()
# s = list(sys.stdin.rea

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
S = list(map(int, list(input())[: -1]))
N = len(S)
res = 0
for i in range(N):
  x = int(S[i])
  for j in range(1, N - i):
    res += x * pow(10, j - 1) * (1 << (N - j - 1))
  res += x * pow(10, N - i - 1) * (1 << i)
print(res)

Submission status: Accepted

Solution code:
import math, sys

S = input()
n = len(S)
if n == 1:
    print(int(S))
    sys.exit()
ans = 0
for i in range(2**(n-1)):

    ib = (bin(i)[2:]).zfill(n-1)
    #print(ib)

    l = 0
    for j in range(n):
        if j == n-1:
            ans += int( S[l:j+1] )
            #print( S[l:j+1] , ans)
            break
        if ib[j] =="1":
            ans += int( S[l:j+1] )
            #print( S[l:j+1] , ans)
            l = j+1
print(ans)

Submission status: Accepted

Solution code:
import math
import collections
from sys import exit
from itertools import product

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

s = list(input())
n = len(s)
ans = 0
for p in product((0,1), repeat=n):
    total = 0
    for i in range(n):
        if p[i] == 1:
            ans += total
            total = 0
        else:
            total = total*10 + int(s[i])
    ans += total
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
s=input()
import itertools
l=[*itertools.accumulate(s)]
o=[]
for b in range(1<<len(s)-1):
  q=[]
  p=0
  for i in range(len(s)-1):
    if b&(1<<i):
      q+=int(l[i][p::]),
      p=i+1
  c=l[-1][p::]
  c=c if c else 0
  q+=int(c),
  o+=sum(q),
print(sum(o))

Submission status: Accepted

Solution code:
from itertools import product
s = input()
n = len(s)
ans = 0
for lst in product(['x', ' '], repeat=n-1):
    ss = ''
    for i in range(n-1):
        ss += (s[i] + str(lst[i]))
    ss += s[-1]
    ss = ss.replace('x', '')
    temp = [int(x) for x in ss.split()]
    ans += sum(temp)
print(ans)

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

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

S=input()
ans=0

def rec(s,tmp):
    global ans
    if len(s)==0:
        ans+=tmp
    for i in range(1,len(s)+1):
        rec(s[i:],tmp+int(s[:i]))

rec(S,0)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class Combination:
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod
        self.fac = [1 for i in range(self.n + 1)]
        self.finv = [1 for i in range(self.n + 1)]
        for i in range(2, self.n+1):
            self.fac[i] = (self.fac[i - 1] * i) % self.mod
            self.finv[i] = (self.finv[i-1] * pow(i, -1, self.mod)) % self.mod

    def comb(self, n, m):
        return self.fac[n] * (self.finv[n-m] * self.finv[m] % self.mod) % self.mod
def iparse():
    return list(map(int, input().split()))

if __name__ == "__main__":
    s = input()
    ans = 0
    for i in range(1 << (len(s) - 1)):
        prev = 0
        for j in range(len(s) - 1):
            if (i >> j) & 1 == 1:
                tmp = s[prev:j + 1]
                ans += int(tmp)
                prev = j+1
        ans += int(s[prev:])
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def cal():
    s = input()
    num, ans = len(s)-1, 0
    for i in range(2**num):
        count0, count1 = 0, 0
        for j in range(num):
            count1 += 1
            if (i>>j)&1:
                ans += int(s[count0:count1])
                count0 = count1
        ans += int(s[count0:count1+1])
    print(ans)
cal()

Submission status: Accepted

Solution code:
def dfs(i,sum1):
    if i == len(s):
        return sum(list(map(int,sum1.split("+"))))
    return dfs(i+1,sum1 + "+" + s[i])+dfs(i+1,sum1 + s[i])
s = input()#一以上9以下
print(dfs(1,s[0]))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
ans = 0
for i in range(2**(N-1)):
    stack = []
    for j in range(N-1):
        if (i>>j) & 1:
            stack.append("+")
        else:
            stack.append("*")
    
    tmp = 0
    num = S[0]
    for i in range(N-1):
        st = stack.pop()
        if st == "+":
            tmp += int(num)
            num = ""
        num += S[i+1]

    tmp += int(num)
    ans += tmp


print(ans)

Submission status: Accepted

Solution code:
def dfs(i,sum1):
    global ss
    #print(i,sum1)
    if i == len(s):
        return sum(list(map(int,sum1.split("+"))))
    return dfs(i + 1, sum1 + s[i]) + dfs(i + 1, sum1 + "+" +s[i])


s = input()
ss = 0
print(dfs(1,s[0]))

Submission status: Accepted

Solution code:
S = input()
L = []
for i in range(len(S)):
    L.append(S[i])

n = len(S)
ans = []
for i in range(2 ** (n - 1)):
    obj = []
    for j in range(n - 1):
        if (i >> j) & 1:
            obj.append(j)
        else:
            obj.append(-1)
    # print(obj)
    s = ''
    s += L[0]
    for j in range(len(obj)):
        if obj[j] == -1:
            s += L[j + 1]
            continue
        else:
            s += '+'
            s += L[j + 1]
    # print(s)
    idx = 0
    now = 0

    while True:
        if now == len(s) - 1:
            ans.append(int(s[idx:]))
            break
        if s[now] == '+':
            ans.append(int(s[idx:now]))
            idx = now + 1
            now = idx
        else:
            now += 1
print(sum(ans))

Submission status: Accepted

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

import itertools as it
a=0
for i in range(l):
 for j in it.combinations(range(1,l), i):
  t='';p=0
  for k in j:
    t+=S[p:k]+'+'
    p=k
  t+=S[p:]
  a+=eval(''.join(t))
print(a)

Submission status: Accepted

Solution code:
S=input()
l=len(S)
ls=[i for i in range(1,l)]
    
import itertools as it
a=0
for i in range(l):
 for j in it.combinations(ls, i):
  t='';p=0
  for k in j:
    t+=S[p:k]+'+'
    p=k
  t+=S[p:]
  a+=eval(''.join(t))
print(a)

Submission status: Accepted

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

ls=[i for i in range(1,l)]
    
sa=[]
for i in range(len(S)):sa+=[S[i],'']
sa=sa[:-1]

import copy
import itertools as it
ans=0
for i in range(l):
 for j in it.combinations(ls, i):
    sx=copy.copy(sa)
    for k in j:sx[2*k-1]='+'
    ans+=eval(''.join(sx))
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
S=input()
l=len(S)
ls=''
for i in range(1,l):ls+=str(i)
sa=['']*(2*l-1)
for i in range(len(sa)):
    if i%2==0:
        sa[i]=S[i//2]

import copy
import itertools as it
ans=0
for i in range(l):
    for j in list(it.combinations(ls, i)):
        sx=copy.copy(sa)
        for k in j:
            k=int(k)
            sx[2*k-1]='+'
        ans+=eval(''.join(sx))
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = 0
for i in range(2**(n-1)):
    t = []
    x = i
    for j in range(n-1):
        t.append(s[j])
        if x % 2 != 0:
            t.append('+')
        x = x // 2
    t.append(s[-1])
    m = 0
    for i in t:
        if i != '+':
            m *= 10
            m += int(i)
        else:
            ans += m
            m = 0
    ans += m
print(ans)

Submission status: Accepted

Solution code:
S = input()
num = 0
bits = format(num , 'b').zfill(len(S) - 1)
ans = 0
for i in range(2 ** (len(S) - 1)):
  index = 0
  for j in range(len(S) - 1):
    if(bits[j] == "1"):
      ans += int(S[index:j + 1])
      index = j + 1
  ans += int(S[index:])
  num += 1
  bits = format(num , 'b').zfill(len(S) - 1)
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def main():
    S = input()
    l = len(S) - 1
    ans = 0
    for i in range(1 << l):
        val = 0
        num = S[0]
        for j in range(l):
            if (i & (1 << j)):
                val += int(num)
                num = S[j + 1]
            else:
                num += S[j + 1]
        val += int(num)
        ans += val
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = input()
opr = len(n) - 1
cal_sum = 0
for i in range(2**opr):
  op = [""] * opr
  for j in range(opr):
    if((i>>j)&1):
      op[opr-1-j] = "+"
  cal = ""
  for x,y in zip(n,op+[""]):
    cal += x+y
  cal_sum += eval(cal)
print(cal_sum)

Submission status: Accepted

Solution code:
s = input()
n = len(s)-1
ans = 0
for i in range(2**n):
    op = [0]*n
    for j in range(n):
        if ((i >> j) & 1):
            op[j] = 1
    t = s[0]
    for j in range(1,n+1):
        if op[j-1] == 1:
            t += '+' + s[j:j+1]
        else:
            t += s[j:j+1]
    ans += sum(list(map(int,t.split('+'))))
print(ans)

Submission status: Accepted

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

ans = 0
for bit in range(1 << n-1):
    tmp = s[0]
    for i in range(n-1):
        if bit & (1 << i):
            tmp += "+"
        tmp += s[i+1]
    
    ans += sum(map(int,tmp.split("+")))

print(ans)

Submission status: Accepted

Solution code:
S = input()
f = lambda x: 2**(x-1) if x > 0 else 1
lenS = len(S)
ans = 0
for i in range(1,lenS+1):
    for j in range(lenS-i+1):
        ans += int(S[j:j+i]) * f(j) * f(lenS-j-i) 
print(ans)

Submission status: Accepted

Solution code:
S = list(input())
l = len(S)
ans = 0
for i in range(1<<(l-1)):
    X = S[:]
    for j in range((l-1)):
        if i >> j & 1:
            X.insert(l-j-1,'+')
    X = ''.join(X)
    ans += sum(list(map(int,X.split('+'))))
print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0

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

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
ans = 0
n = len(s)
for i in range(n):
    c = int(s[i])
    for k in range(n):
        if n-i-1<k:
            break
        val = c * pow(2, i) * (1 if n-i-k-2 <=0 else pow(2,n-i-k-2)) * pow(10,k)
        ans += val
#         print(val)
print(ans)

Submission status: Accepted

Solution code:
import itertools
n = input()
l = len(n)
ans = 0
for ope in itertools.product("_+", repeat = l - 1):
    num = n[0]
    for i in range(l - 1):
        if ope[i] == "+":
            num += n[i + 1]
        else:
            ans += int(num)
            num = n[i + 1]
    ans += int(num)
print(ans)

Submission status: Accepted

Solution code:
a=list(input())
ans=0
for i in range(2**(len(a)-1)):
    s=a[0]
    for j in range(len(a)-1):
        if i%2:s+='+'
        s+=a[j+1]
        i//=2
    ans+=eval(s)
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

  return dfs(i+1, f+S[i+1]) + dfs(i+1, f+'+'+S[i+1])

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)
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
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def calc(s, bit):
    split_list = [0]
    ans = 0
    for i in range(len(s)-1):
        if 2**i & bit:
            split_list.append(i+1)
    if split_list == [0]:
        return int(s)
    for j, i in enumerate(split_list):
        if j == len(split_list)-1:
            ans += int(s[i:])
            break
        ans += int(s[i:split_list[j+1]])
    return ans

def main(s):
    wa = 0
    for i in range(2**(len(s)-1)):
        wa += calc(s, i)
    return wa

s = input()
print(main(s))

Submission status: Accepted

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

ans = 0
for bit in range(1 << (n-1)):
    tmp = S[0]
    for i in range(n-1):
        if bit & (1 << i):
            tmp += "+"
        tmp += S[i+1]
    
    ans += sum(map(int, tmp.split("+")))

print(ans)

Submission status: Accepted

Solution code:
from itertools import product
s=input()
a=0
for p in product((0,1),repeat=len(s)-1):
    t=s[0]
    for i,b in enumerate(p,start=1):
        if b==1:
            t+='+'+s[i]
        else:
            t+=s[i]
    a+=eval(t)
print(a)

Submission status: Accepted

Solution code:
from itertools import product

S = list(input())
N = len(S)

ans = 0
for adds in product([0, 1], repeat=N - 1):
    eqn = [""] * (2 * N - 1)
    eqn[::2] = S[:]
    for i, has_add in enumerate(adds):
        if has_add:
            eqn[2 * i + 1] = "+"
        else:
            eqn[2 * i + 1] = ""
    ans += eval("".join(eqn))
print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math

#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
s = input()
ans = 0
for bit in range(1 << len(s)-1):
    st = s[0]
    wa = 0
    for i in range(len(s)-1):
        if bit & (1 << i):
            wa += int(st)
            st = s[i+1]
        else:
            st += s[i+1]
    ans += wa + int(st)
print(ans)

Submission status: Accepted

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


def dfs(now, total, i):
    if i == n:
        return total + now
    else:
        res = 0
        res += dfs(now * 10 + int(s[i]), total, i + 1)
        res += dfs(int(s[i]), total + now, i + 1)
        return res


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

Submission status: Accepted

Solution code:
import copy
S = list(input())
ans = 0
for i in range(2**(len(S)-1)):
  T = copy.copy(S)
  shift = 0
  for j in range(len(S)-1):
    if i & (1 << j):
      shift += 1
      T.insert(j+shift,"+")
  T.append("+")
  NS = ""
  for x in T:
    if x != "+":
      NS = NS + x
    elif x == "+":
      ans += int(NS)
      NS = ""
  if "+" not in T:
    ans += int("".join(T))
print(ans)

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)-1
ans = 0
for i in range(1 << N):
    a = S[0]
    for j in range(N):
        if(i >> j) & 1 == 0:
            a += S[j+1]
        else:
            x = int(a)
            ans += x
            a = S[j+1]
    x = int(a)
    ans += x
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
S = input().strip()
N = len(S)
cnt = 0
for x in product((0,1),repeat=N-1):
    y = S[:]
    for i in range(N-2,-1,-1):
        if x[i]==1:
            y = y[:i+1]+"+"+y[i+1:]
    cnt += eval(y)
print(cnt)

Submission status: Accepted

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

n = len(s)-1
ans = 0
for i in range(2**n):
    temp = ['']*n
    for j in range(n):
        if (i >> j)&1:
            temp[j] = '+'
    t = []
    for k in range(n):
        t.append(s[k])
        t.append(temp[k])
    else:
        t.append(s[-1])
    t = ''.join(t)
    ans += eval(t)
print(ans)

Submission status: Accepted

Solution code:
import itertools
s = input()
n = len(s)-1
ans = 0
for v in itertools.product(["+", ""], repeat=n):
    x = s[0]
    for i in range(n):
        x += v[i] + s[i+1]
    ans += eval(x)
print(ans)

Submission status: Accepted

Solution code:
S = input()

ans = 0


def helper(cur, res):
    global ans
    if res == "":
        ans += cur
    for i in range(1, len(res) + 1):
        helper(cur + int(res[:i]), res[i:])


helper(0, S)

print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
ans = 0
for k in range(2**(N-1)):
    t = []
    p = 0
    for d in range(N+1):
        if (k>>d)&1:
            t.append(int(S[p:d+1]))
            p = d+1
    t.append(int(S[p:d]))
    ans += sum(t)
print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
for i in range(2**(len(S)-1)):
    ls = []
    index = 0
    for j in range(len(S)-1):
        if ((i >> j) & 1):
            ls.append(int(S[index:j+1]))
            index = j+1
    ls.append(int(S[index:]))
    ans += sum(ls)
print(ans)

Submission status: Accepted

Solution code:
s=[int(c) for c in input()]
n=len(s)
dp=[0]*n
dp2=[0]*n

dp[0]=s[0]
dp2[0]=s[0]
for i in range(1,n):
    dp2[i]=dp2[i-1]*10+s[i]*2**i
    dp[i]=dp2[i]+2*dp[i-1]-dp2[i-1]

print(dp[n-1])

Submission status: Accepted

Solution code:
S=input()
L=len(S)
from itertools import*
print(sum([eval(''.join([S[i//2] if i%2==0 else '+' if p[i//2] else '' for i in range(L*2-1)])) for p in product((0,1),repeat=L-1)]))

Submission status: Accepted

Solution code:
S=input()
n=len(S)
ans=0
 
for paint in range(2**(n-1)):
	temp_S=S[0]
 
	for i in range(n-1):
		if (paint>>i)&1==1:
			temp_S+="+"
		temp_S+=S[i+1]
 
	ans+=sum(map(int, temp_S.split("+")))
print(ans)

Submission status: Accepted

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

ans = 0

for bit in range(1 << (n - 1)):
    # 各場合で式 f を生成する
    f = s[0]

    for i in range(n - 1):
        if bit & (1 << i):
            # フラグが立っているならば "+" を式の末尾に追加する
            f += "+"
        f += s[i + 1]

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

print(ans)

Submission status: Accepted

Solution code:
n = list(input())
dp = [n[0]]

for i in range(0, len(n)-1):
    tmp = []
    for j in dp:
        tmp.append(j + str(n[i+1]))
        tmp.append(j + '+' + n[i+1])
    else:
        dp = tmp

result = 0
for i in dp:
    result += sum([int(i) for i in i.split('+')])

print(result)

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

S = input()
N = len(S)

def bit(S, j):
    # Sの右からj bit目(0-indexed)
    return (S>>j)&1

ans = 0
for i in range(1<<(N-1)):
    k = 0
    tmp = []
    for j in range(N-1):
        if bit(i, j) == 1:
            tmp.append(S[k:j+1])
            k = j + 1
    tmp.append(S[k:])

    for t in tmp:
        ans += int(t)

print(ans)

Submission status: Accepted

Solution code:
def dfs(i,sall):
    if i == lenS:
        return (sall)
        #return sum(map(int,(s[0]+sall).split("+")))
    return dfs(i + 1,sall+"+"+s[i])+"+"+dfs(i + 1,sall+s[i])

s = input()
lenS = len(s)
print(sum(map(int,dfs(1,s[0]).split("+"))))

Submission status: Accepted

Solution code:
def hojyu(a):
  if len(a)!=N:
    return "0"*(N-len(a))+a
  else:
    return a
S=input()
N=len(S)-1
R=list()
ans=0
for i in range(2**N):
  s=str(bin(i)[2:])
  s=hojyu(s)
  b=0
  mae=0
  for k in range(len(s)):
    if s[k]=="1":
      b+=int(S[mae:k+1])
      mae=k+1
  b+=int(S[mae:])
  ans+=b
print(ans)

Submission status: Accepted

Solution code:

n = str(input())

len_n = len(n)-1

ans = 0
total = 0

for i in range(2**len_n):
    temp = n[0]
    for j in range(len_n):
        if (i >> j) & 1:
            temp += '+'
        temp += n[j+1]
    total = list(map(int, temp.split('+')))
    ans += sum(total)

print(ans)

Submission status: Accepted

Solution code:
from itertools import product
S = input()
if len(S)==1:
    print(int(S))
else:
    Sum = 0
    for TR in product([0,1],repeat=(len(S)-1)):
        Op = ['+' if TO==1 else '' for TO in TR]+['']
        Sum += eval(''.join([TS+TO for TS,TO in zip(S,Op)]))
    print(Sum)

Submission status: Accepted

Solution code:
# 毎回挿れるか挿れないかの二択の探索をしてみる
# 2値なのでbit全探索をやってみる
# 逆ポーランド必要か？と思ったけど加算だけだしいらんかったわ助かる
s = input()
ans = 0
for bit in range(0, 1 << len(s) - 1):
    opr = []
    for i in range(len(s) - 1):
        opr.append("水着" if bit >> i & 1 == 1 else "ワンピース")
    exp = [s[0]]
    for i in range(len(opr)):
        if opr[i] == "ワンピース":
            exp[-1] += s[i + 1]
        elif opr[i] == "水着":
            exp.append(s[i + 1])
    ans += sum(list(map(int, exp)))
print(ans)

Submission status: Accepted

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

M = 2#bit探査をしたい時はM=2
def dfs(A):
    global ans
    # 終端条件 --- l 重ループまで回したら処理して打ち切り
    if len(A) == l:
        memo=0
        for i in range(l):
            if A[i]==1:
                ans+=int(S[memo:i+1])
                memo=i+1
        ans+=int(S[memo:])
        return
    for v in range(M):
        A.append(v)
        dfs(A)
        A.pop() # これが結構ポイント

dfs([])
print(ans)