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:
from copy import deepcopy
s = input()
n = len(s)
partitions = []

for i in range(1<<(n-1)):
    p = []
    k = 0
    for j in range(n):
        if i & 2**j:
            #print (bin(i), j, s[k:j+1])
            p.append(int(s[k:j+1]))
            k = j+1
    p.append(int(s[k:n]))
    partitions.append(p)
#print (partitions)
print (sum([sum(p) for p in partitions]))

Submission status: Accepted

Solution code:
import copy
s=list(input())
mylist=[""]*(len(s)+(len(s)-1))
for i in range(len(s)):
    mylist[2*i]=s[i]
ans=0
for i in range(2**(len(s)-1)):
    l=copy.deepcopy(mylist)
    for j in range(len(s)-1):
        if (i>>j&1):
            l[2*j+1]="+"
    ans+=eval("".join(l))
print(ans)

Submission status: Accepted

Solution code:
import copy
s=list(input())
mylist=[""]*(len(s)+(len(s)-1))
for i in range(0,len(s)):
    mylist[2*i]=s[i]
ans=0
for i in range(2**(len(s)-1)):
    l=copy.deepcopy(mylist)
    for j in range(len(s)-1):
        if (i>>j&1):
            l[2*j+1]="+"
    ans+=eval("".join(l))
print(ans)

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    S = list(map(int, S))
    N = len(S)

    ans = 0
    for bit in range(1 << (N - 1)):
        n = 0
        for i, s in enumerate(S):
            n = 10 * n + s
            if bit & (1 << i):
                ans += n
                n = 0
        ans += n

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    S = list(map(int, S))
    N = len(S)

    ans = 0
    for bit in range(1 << (N - 1)):
        n = 0
        for i, s in enumerate(S):
            n += s
            if bit & (1 << i):
                ans += n
                n = 0
            else:
                n *= 10
        ans += n // 10

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    N = len(S)

    ans = 0
    for bit in range(1 << (N - 1)):
        vec = []
        for i, s in enumerate(S):
            vec.append(s)
            if bit & (1 << i):
                vec.append('+')
        ans += sum(map(int, ''.join(vec).split('+')))

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    N = len(S)

    @lru_cache(maxsize=None)
    def rec(i):
        if i == N:
            return 0

        ans = 0
        for j in range(i + 1, N + 1):
            ans += int(S[i:j]) * pow(2, max(N - j - 1, 0)) + rec(j)

        return ans

    print(rec(0))
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
sm=0
for i in range(1<<len(s)-1):
  j=0
  st=0
  while j<len(s):
    if (i>>j)&1 ==1:
      sm+=int(s[st:j+1])
      st=j+1  
    j+=1
  sm+=int(s[st:])
  
print(sm)

Submission status: Accepted

Solution code:
S = input()
n = len(S)-1
ans = 0
for i in range(1 << n):
    p = 0
    for j in range(n):
        if i >> j & 1 == 0:
            continue
        else:
            ans += int(S[p:j+1])
            p = j+1
    ans += int(S[p:])

print(ans)

Submission status: Accepted

Solution code:
S = input()
L = len(S)-1
a = 0

for i in range(2**L):
  T = S[0]
  for j in range(L):
    T+=(i>>j&1)*"+"+S[1+j]
  a+=eval(T)

print(a)

Submission status: Accepted

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

ans=0
for ib in range(1<<(keta-1)):
    f = s
    cnt = 1
    for i in range(0, keta):
        if (ib >> i & 1):
            # +を入れる。
            f = f[0:i+cnt]+"+"+f[i+cnt:]
            cnt += 1
    
    #+で分割する。
    cnt = list(map(int, f.split("+")))
    ans += sum(cnt)
print(ans)

Submission status: Accepted

Solution code:
def main():
    S = list(map(int,input()))
    n = len(S)

    ans = 0
    for i in range(2**(n-1)):
        b = 0
        t = 0
        for j in range(n):
            if (j < (n-1) and i >> j &1) or j == n-1:
                for k,s in enumerate(S[b:j+1]):
                    t += s * 10**(j-b-k)

                b = j+1
        ans += t

    print(ans)
    
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
s_len = len(s)
ans = 0
for i in range(1<<s_len-1):
    dum = s[0]
    for j in range(1,s_len):
        if (i >> (j-1))%2 == 1:
            dum += "+"
        dum += s[j]
    ans += sum(map(int,dum.split("+")))
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
S = input()

num = len(S)

ans = 0

for bit in range(2**(num-1)):
  f = S[0]
  for i in range(num-1):
    if (bit >> i) & 1:
      f += '+'
    f += S[i+1]
  ans += sum(map(int,f.split('+')))

print(ans)

Submission status: Accepted

Solution code:
s = input()
s = s[::-1]
ans = 0

for mask in range(1 << (len(s) - 1)):
    rate = 1
    for i in range(len(s)):
        ans += int(s[i]) * rate
        if mask >> i & 1 == 1:
            rate = 1
        else:
            rate *= 10

print(ans)

Submission status: Accepted

Solution code:
S=input()
Len=len(S)-1
ans=0
for i in range(1<<Len):
  Tmp=S[0]
  cnt=0
  for j in range(Len):
    if 1&(i>>j):
      Tmp+='+'
      Tmp+=S[j+1]
    else:
      Tmp+=S[j+1]
  cnt=eval(str(Tmp))
  ans+=cnt
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def h(A,B):
    T=""
    for i in range(len(B)):
        T+=A[i]+B[i]
    return T+A[-1]

from itertools import product
S=input()

P=product(["","+"],repeat=len(S)-1)

K=0
for p in P:
    K+=eval(h(S,p))
print(K)

Submission status: Accepted

Solution code:
def bfs(s: str, n: int, i: int, j: int, k: int):
    return k+int(s[j:]) if i==n-1 else bfs(s,n,i+1,i+1,k+int(s[j:i+1]))+bfs(s,n,i+1,j,k)

s=input()
n=len(s)
print(bfs(s,n,0,0,0))

Submission status: Accepted

Solution code:
def dfs(s: str, n: int, i: int, x: str):
    return sum(list(map(int,x.split('+')))) if i==n-1 else dfs(s,n,i+1,x+s[i+1])+dfs(s,n,i+1,f'{x}+{s[i+1]}')

s=input()
n=len(s)
print(dfs(s,n,0,s[0]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

S = input()
N = len(S) - 1

ans = 0
for i in range(1 << N):
    exp = ""
    for j in range(len(S)):
        exp += S[j]
        if i & 1 << j > 0:
            exp += "+"
    ans += sum(map(int, exp.split("+")))
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

S = input()
ans = 0
for i in product([0,1],repeat=len(S)-1):
    check = S[0]
    for s,flag in zip(S[1:],i):
        if flag:
            check += '+' + s
        else:
            check += s
    ans += eval(check)
print(ans)

Submission status: Accepted

Solution code:
import sys

def main(s):
    intl=[int(w) for w in s]
    intl.reverse()
    ps=0
    for i in range(2**(len(s)-1)):
        l=[x for x in intl]
        j=i
        e=0
        for k in range(1,len(s)):
            e=(e+1)*(j&1)
            l[k]=l[k]*(10**e)
            j>>=1
        ps=ps+sum(l)
    return ps

s=sys.stdin.readline().strip()

print(main(s))

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 + a[i + 1]) + dfs(i + 1, f + "+" + a[i + 1])


a = input()
n = len(a)

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

Submission status: Accepted

Solution code:
import sys
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    S = in_s()
    N = len(S)

    comb = itertools.product([0, 1], repeat=N - 1)
    ans = 0

    for com in comb:
        now = S[0]
        ts = 0
        for i, f in enumerate(com):
            i = i + 1
            if f == 0:
                now += S[i]
            else:
                ts += int(now)
                now = S[i]
        else:
            ts += int(now)

        # print(ts)
        ans += ts

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
answer = 0
for bit in range(2 ** (len(S) - 1)):
    formula = S[0]
    for i in range(len(S) - 1):
        if bit & (1 << i):
            formula += '+'
        formula += S[i + 1]
    answer += sum(map(int, formula.split('+')))
print(answer)

Submission status: Accepted

Solution code:
S = input()

res = 0
for bit in range(1<<len(S)-1):
  last = 0  # 最後に+を入れた位置を記録する
  for i in range(len(S)-1):
    if bit & (1<<i):
      res += int(S[last:i+1])
      # print(f'S[last:i+1]={S[last:i+1]}')
      last = i + 1
  res += int(S[last:])
  # print(f'S[last:] = {S[last:]}')
  
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
ans = 0

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

Submission status: Accepted

Solution code:
from itertools import product

s = input()

ans = 0
for l in product([0, 1], repeat=len(s) - 1):
    num = s[0]
    for i, bit in enumerate(l):
        if bit == 0:
            num = ''.join([num, s[i + 1]])
        elif bit == 1:
            ans += int(num)
            num = s[i + 1]
    ans += int(num)
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
all_sum = 0
#0から(2^n-1)-1までループ
for bit in range(1<<(n-1)):
    func = s[0]
    for i in range(n-1):
        if bit & (1<<i):
            func += "+"
        func += s[i+1]
    
    all_sum += sum(map(int, func.split('+')))
print(all_sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import product

s = input()
n = len(s)
ans = 0
for pluses in product((True, False), repeat=n - 1):
    current_continuous_num = s[0]
    current_sum = 0
    for idx, is_plus in enumerate(pluses):
        if is_plus:
            current_sum += int(current_continuous_num)
            current_continuous_num = s[idx + 1]
        else:
            current_continuous_num += s[idx + 1]
    ans += current_sum + int(current_continuous_num)
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

s = input()

ans = 0

for i in product(["","+"], repeat=len(s)-1):
    str = ""
    for j in range(len(s)-1):
        str += s[j]
        str += i[j]
    str += s[-1]

    ans += eval(str)

print(ans)

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+a[i+1]) + dfs(i+1, f+'+'+a[i+1])

a = input()
n = len(a)

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

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) - 1
sum = 0;

for i in range(2**N):
    # iの下位からn番目のビットが1かどうかの判定
    # (i >> n) & 1 
    """
    例えば、3は011であり、この下から2ビット目は、0
    3を2ビット右シフトすると 0|11 となり0、1とのORをとりfalse
    """
    operator = [''] * N
    for n in range(N):
        if ((i>>n) & 1):
            operator[N-1-n] = '+'

    # print(operator)
    # Sとoperatorを交互につなげる

    operator.append('')
    formula = ""

    for s, o  in zip(S, operator):
        formula += s + o
    # print(formula)
    sum += eval(formula)
print(sum)

Submission status: Accepted

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

n = input()
s = len(n)
print(dfs(0,n[0]))

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
s=input()
n=len(s)
ans=0
ans+=int(s)
if n==1:
  print(ans)
  exit()
for i in s:
    ans+=int(i)
l=[i for i in range(n-1)]
for i in range(1,n-1):
    c=itertools.combinations(l,i)
    for p in c:
        pulus=set(list(p))
        z=0
        for j in range(n):
            ans+=int(s[n-1-j])*10**z
            if j != n-1 and n-2-j not in pulus:
                z+=1
            else:
                z=0
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = (len(s) - 1)
ans = 0
for i in range(2 ** n):
    s2 = s
    for j in range(n):
        if (i >> j) & 1:
            s2 = s2[:(n - j)] + " " + s2[n - j:]
    ans += sum([int(x) for x in s2.split()])

print(ans)

Submission status: Accepted

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

from itertools import product
bits=list(product([0,1], repeat=l-1))

ans=0
for bit in bits:
    tmp_s=s
    cnt=0
    for i in range(l-1):
        if bit[i]==1:
            tmp_s=tmp_s[:i+1+cnt]+'+'+tmp_s[i+1+cnt:]
            cnt+=1
    ans+=eval(tmp_s)

print(ans)

Submission status: Accepted

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

def dfs(i,f):
    if i==l-1:
        return eval(f)
    else:
        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()
l=len(s)

from itertools import product
bits=list(product([0,1], repeat=l-1))

ans=0
for bit in bits:
    tmp_s=s
    cnt=0
    for i in range(l-1):
        if bit[i]==1:
            tmp_s=tmp_s[:i+1+cnt]+'+'+tmp_s[i+1+cnt:]
            cnt+=1
    ans+=eval(tmp_s)

print(ans)

Submission status: Accepted

Solution code:
s = input()

from itertools import combinations
from collections import Counter

def split(s, pivot):
    split_ary = []
    st = 0
    for p in pivot:
        split_ary.append(s[st:p])
        st = p
    split_ary.append(s[st:])
    return split_ary

sub_ary = []
N = len(s)
for i in range(N):
    for sep_idx in combinations(range(1,N), i):
        sub_ary.extend(split(s, sep_idx))

c = Counter(sub_ary)
ans = 0
for k,cnt in c.items():
    ans += int(k) * cnt

print(ans)

Submission status: Accepted

Solution code:
import itertools
S = list(input())
set01 = list(itertools.product('01', repeat=(len(S)-1)))
S_01 = ['','+']
counter = 0
for i in range(len(set01)):
    SS = ""
    for j in range(len(S)-1):
        SS += S[j   ] + S_01[int(set01[i][j])]
    SS += S[-1]
    SS = "".join(SS)
    counter += eval(SS)
print(counter)

Submission status: Accepted

Solution code:
s = input()
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:
# https://atcoder.jp/contests/abc045/tasks/arc061_a

s = input()

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

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])

def main():
    ans = dfs(0,S[0])
    print(ans)


if __name__ == '__main__':
    S = input()
    n = len(S)
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import product

    s = input()
    l = len(s) - 1
    ans = 0

    for bit in product(range(2), repeat=l):
        score = 0
        cur = ""
        for i, b in enumerate(bit):
            cur += s[i]
            if b:
                score += int(cur)
                cur = ""
        cur += s[-1]
        score += int(cur)
        ans += score

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = list(input())
s = []
q = 0
ans = 0
for i in S:
    s.append(int(i))
for i in range(2 ** len(s)):
    for i2 in range(len(s)):
        if i >> i2 & 1:
            ans += q
            q = s[i2]
        else:
            q *= 10
    ans += q
    q = 0
print(ans)

Submission status: Accepted

Solution code:
def calc(s):
    n = len(s)
    ans = 0
    for bit in range(1 << (n - 1)):
        ss = s[0]
        for i in range(n - 1):
            if bit & (1 << i):
                ss += '+'
            ss += s[i + 1]
        ans += eval(ss)
    return ans

s = str(input())
print(calc(s))

Submission status: Accepted

Solution code:
S=input()
if len(S)==1:
  print(S)
else:
  def bfs(i,j,k):
    if i==len(S)-1:
      return k+int(S[j:])
    return bfs(i+1,i+1,k+int(S[j:i+1]))+bfs(i+1,j,k)
  bns=bfs(0,0,0)
  print(bns)

Submission status: Accepted

Solution code:
import sys
from itertools import product

input = sys.stdin.readline
P = 10 ** 9 + 7


def main():
    S = input().rstrip()

    N = len(S)
    ans = 0
    for comb in product(["+", ""], repeat=N - 1):
        eq = S[0]
        for s, c in zip(S[1:], comb):
            eq = "".join([eq, c])
            eq = "".join([eq, s])
        ans += eval(eq)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


class Solver:
    def __init__(self):
        self.ans = 0

    def calc(self, cur: int, rest: str, pos: int):
        if not rest or len(rest) == pos:
            self.ans += cur + int(rest)
            return

        self.calc(cur + int(rest[:pos]), rest[pos:], 1)
        self.calc(cur, rest, pos + 1)


def main():
    S = input().strip()
    solve = Solver()
    solve.calc(0, S, 1)
    print(solve.ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import product

S = input()
N = len(S)
ans = 0
for opes in product(("", "+"), repeat=N - 1):
    eqn = "".join(s + o for s, o in zip(S[:-1], opes)) + S[-1]
    ans += sum(map(int, eqn.split("+")))
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

S = input()
N = len(S)
ans = 0
for opes in product(("", "+"), repeat=N - 1):
    eqn = []
    for s, o in zip(S[:-1], opes):
        eqn += s + o
    eqn = "".join(eqn) + S[-1]
    ans += sum(map(int, eqn.split("+")))
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

S = input()
N = len(S)
ans = 0
for opes in product(("", "+"), repeat=N - 1):
    eqn = []
    for s, o in zip(S[:-1], opes):
        eqn += s + o
    ans += eval("".join(eqn) + S[-1])
print(ans)

Submission status: Accepted

Solution code:
from copy import deepcopy
S = input()
n = len(S) - 1
C = 0
for bit in range(2 ** n):
    T = list(S)
    U = []
    for i in range(n + 1):
        U.append(T[i])
        if (bit & (1 << i)):
            U.append('+')
    V = ''
    for u in U:
        V += u
    C += eval(V)
print(C)

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:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)

S = s()
N = len(S)-1
ans = 0
for bit in range(1<<N):
    B = [(bit>>i)&1 for i in range(N)]
    start = 0
    for i in range(N):
        if B[i] == 1:
            ans += int(S[start:i+1])
            start = i+1
    ans += int(S[start:N+1])
print(ans)

Submission status: Accepted

Solution code:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def debug(predicate, value):
    if predicate:
        print(value)
    return value


def solve():
    """
    OPT[i][j] : (count, all sum between i and j)
    OPT[i][j] = OPT[i][k]+S[k+1:j+1]
    """
    S = input().strip()
    N = len(S)
    OPT = [
        [0 for _ in range(N)] for _ in range(N)
    ]
    for length in range(N+1):
        for i in range(N-length):
            j = i+length
            OPT[i][j] = [1, int(S[i:j+1])]
            for l in range(i, j):
                OPT[i][j][0] += OPT[i][l][0]
                OPT[i][j][1] += OPT[i][l][1]+OPT[i][l][0]*int(S[l+1:j+1])
    return OPT[0][N-1][1]


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

Submission status: Accepted

Solution code:
S = input()
a=[""]*(len(S))
ans = 0
for n in range(len(S)):
  a[n] = S[n]
for n in range(2**(len(S)-1)):
  b=[""]*(len(S))
  c=""
  for m in range(len(S)-1):
    if n>>m & 1:
      b[m] = "+" #[]でくくらない
  for p in range(len(S)):
    c += a[p]+b[p]
  ans += eval(c)
print(ans)

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
a = 0

for i in range(2**(n-1)):
  op = []
  tmp = ""
  for j in range(n-1):
    if (i >> j) & 1:
      op.append("+")
    else:
      op.append("")
  op.append("")
  
  for num, sbl in zip(s, op):
    tmp += num + sbl
  a += eval(tmp)

print(a)

Submission status: Accepted

Solution code:
from collections import deque

s = input()

if len(s) == 1:
  print(s)
  exit()

lst = deque([[" "], ["+"]])
rlt = 0

while lst:
  sm = lst.pop()
  if len(sm) == len(s) - 1:
    now = int(s[0])
    for i in range(len(s) - 1):
      if sm[i] == '+':
        rlt += now
        now = int(s[i+1])
      else:
        now = now*10 + int(s[i+1])
    rlt += now
  else:
    als = sm+[" "]
    lst.append(als)
    als = sm+["+"]
    lst.append(als)
    
print(rlt)

Submission status: Accepted

Solution code:
def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    S = input()
    K = len(S)-1
    s = 0
    for pattern in range(2**K):
        tmp = S[0]
        for i in range(K):
            if (pattern>>i)&1:
                tmp += ' '
            tmp += S[i+1]
        s += sum(map(int, tmp.split()))
    print(s)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = 0
for bit in range(1 << (n - 1)):
    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:
import sys
readline = sys.stdin.readline

S = readline().rstrip()

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

Submission status: Accepted

Solution code:
import itertools


def m():
    S = input()
    ans = 0
    for i in range(len(S)):
        for item in itertools.combinations(range(len(S) - 1), i):
            if len(item) == 0:
                ans += int(S)
                continue
            ind = 0
            for j in item:
                ans += int(S[ind:j+1])
                ind = j+1
            ans += int(S[ind:])
    return ans


print(m())

Submission status: Accepted

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

    # 式 f の末尾に "+" を追加するかしないかして次の数字を追加
    return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + "+" + s[i + 1])#sは文字列


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)):
  i=list(bin(i))[::-1]
  t=list(s)
  for j in range(len(i)-1,-1,-1):
    if i[j]=='1':
      t.insert(j+1,'+')
  t=''.join(t)
  ans+=eval(t)
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	s = S()
	total = int(s)
	s_list = [s[:i+1] + '+' + s[i+1:] for i in range(len(s)-1)]
	while s_list:
		new_s_list = []
		for s_tmp in s_list:
			total += eval(s_tmp)
			plus = s_tmp.rfind('+')
			if plus < len(s_tmp)-2:
				new_s_list += [s_tmp[:plus+i+2] + '+' + s_tmp[plus+i+2:] for i in range(len(s_tmp)-plus-2)]
		s_list = new_s_list.copy()
	print(total)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
for bit in range(1<<(N-1)):
    formula = ""
    for i in range(N-1):
        if (bit >> i) & 1:
            k = "+"
        else:
            k = ""
        formula += S[i] + k
    formula += S[N-1]
    ans += eval(formula)
print(ans)

Submission status: Accepted

Solution code:
def rec(i, x):
    if i >= length:
        return sum(list(map(int, x.split("+"))))
    return rec(i + 1, x + s[i + 1]) + rec(i + 1, x + "+" + s[i + 1])


s = input()
length = len(s) - 1
print(rec(0, s[0]))

Submission status: Accepted

Solution code:
def solve(bit):
    nums = []
    i, j = 1, 0
    num = s[0]
    while i < len(s):
        if bit[j] == 1:
            nums.append(int(num))
            num = s[i]
        else:
            num += s[i]
        i += 1
        j += 1
    else:
        nums.append(int(num))
    return sum(nums)

s = str(input())
l = len(s)
ans = 0
for i in range(2**(l-1)):
    bit = [0] * (l - 1)
    for j in range(l-1):
        if ((i >> j) & 1):
            bit[j] = 1
    ans += solve(bit)
print(ans)

Submission status: Accepted

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

# is insert + on the right side.
patterns = product([True, False], repeat=len(S)-1)

ans = 0
for ptn in patterns:
  ptn_idxs = [i for i, bl in enumerate(ptn) if bl]
  ptn_s = ''
  for i in range(len(S) - 1):
    ptn_s += S[i]
    if i in ptn_idxs:
      ptn_s += '+'
  ans += eval(ptn_s + S[-1])

print(ans)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
res = 0
for pat in range(2 ** (l-1)):
    #print(pat)
    shiki = s[0]
    for i in range(l-1):
        if (pat >> i & 1) == 1:
            shiki += "+" + s[i+1]
        else:
            shiki +=  s[i+1]
    res += eval(shiki)
    #print(shiki)
print(res)

Submission status: Accepted

Solution code:

s = input()
slen = len(s) - 1
sum = 0
for i in range(2 ** (slen)):
    oplist = [""]*(len(s)-1)
    for j in range(slen):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            oplist[len(s) - 2 - j] = "+"

    siki = ""
    for i in range(len(oplist)):
        siki += s[i] + oplist[i]
    siki += s[-1]
    sum += eval(siki)

print(sum)