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 = input()

op_count = len(s) - 1
op_list = []
for i in range(2**op_count):
    op = [''] * op_count
    for j in range(op_count):
        if (i >> j) & 1:
            op[op_count - 1 - j] = '+'
    op_list.append(op)

ans = 0
for i in range(2**op_count):
    cur = 1
    t = s
    for j in range(op_count):
        if op_list[i][j] == '+':
            t = t[:j + cur] + "+" + t[j + cur:]
            cur += 1
    ans += eval(t)
print(ans)

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
S = input()

patterns = []
def make_patterns(S, pairs, i = 1):
  global patterns
  #print(i, pairs, len(S))
  if i == len(S):
    patterns.append(list(map(int, pairs.split("+"))))
  else:
  	make_patterns(S, pairs + "+" + S[i], i + 1)
  	make_patterns(S, pairs + S[i], i + 1)
  
make_patterns(S, pairs = S[0], i = 1)
print(sum([sum(pattern) for pattern in patterns]))

Submission status: Accepted

Solution code:
S = input()

if len(S) == 1:
  print(int(S))
else:
  ans = 0
  for i in range(1<<(len(S)-1)):
    SP = []
    for j in range(len(S)-1):
      if (i>>j)&1 == 1:
        SP.append(j)
    SP += [len(S)-1]
    #print(SP)
    idx = 0
    for sp in SP:
      ans += int(S[idx:sp+1])
      idx = sp+1
  print(ans)

Submission status: Accepted

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

def f(i,t):
    if i == n-1:
        return sum(list(map(int, t.split('+'))))
    
    return f(i+1,t+s[i+1]) + f(i+1,t+'+'+s[i+1]) #sumの値を足してる

print(f(0,s[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:
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

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

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

import random


def main():
    s=input().strip()
    n=len(s)-1
    NUM_CASE= 2**n
    sum=0
    for case in range(0,NUM_CASE):
        left=0
        for index in range(n):
            if (case>>index) & 1 == 1:
                sum+=int(s[left:index+1])
                left=index+1
            else:               # if (case>>index) & 1 ==0:
                continue
        index=n
        sum+=int(s[left:index+1])
    print(sum)  
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

N = len(S)
cnt = 0

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

print(cnt)

Submission status: Accepted

Solution code:
import itertools
s=input()
li=["+",""]
lli=list(itertools.product(li,repeat=len(s)-1))
ans=0
for k in lli:
  val=""
  for i,j in zip(s,k):
    val+=i+j
  val+=s[-1]
  ans+=eval(val)
print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
for i in range(2**(len(S)-1)):
    tmp = []
    prev = 0
    for j in range(1, len(S)):
        if (i >> (j-1)) % 2 == 1:
            if len(S[prev:j]) != 0:
                tmp.append(int(S[prev:j]))
                prev = j
    if len(S[prev:]) != 0:
        tmp.append(int(S[prev:]))
    else:
        print(prev)
    ans += sum(tmp)
print(ans)

Submission status: Accepted

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


s_tmp = s[:]
s_str = ""
ans = 0

if len(s)==1:
    print(int(s[0]))
else:
    for i in range(pow(2,len(s_tmp)-1)):
        s_str = s.pop(0)
        j = 0
        while len(s) > 0:
            i_bin = list(format(i,"010b"))
            #print(*i_bin)
            if i_bin[len(i_bin)-j-1] == "1":
                s_str += "+"
            s_str += s.pop(0)
            j += 1
        #print(i,s_str)
        ans += eval(s_str)
        s = s_tmp[:]
        s_str = ""
    print(ans)

Submission status: Accepted

Solution code:
s = input()

sum = 0
for bit in range(1 << (len(s) - 1)):
    expr = s[0]
    for i in range(len(s) - 1):
        if bit & 1 << i:
            expr += '+'
        expr += s[i + 1]
    sum += eval(expr)

print(sum)

Submission status: Accepted

Solution code:


def calcA(S):
    Num=0
    for i in range (1,len(S)):
        A = int("".join(S[:i]))
        lenB=len(S[i:])
        Num += A*(2**(lenB-1))+calcA(S[i:])
    
    Num += int("".join(S))
    return Num


N = list(input())
print(calcA(N))

Submission status: Accepted

Solution code:
s = input().rstrip()
n = len(s)
res = 0
for i in range(2**(n - 1)):
    bs = bin(i)[2:].rjust(n - 1, '0')
    ss = s[0]
    for b, c in zip(bs, s[1:]):
        if b == '1':
            ss += '+'
        ss += c
    res += eval(ss)
print(res)

Submission status: Accepted

Solution code:
ans = 0

def go(s,index,cnt):
  if cnt == 0:
    temp = ''.join(s).replace(" ","")
    global ans
    ans+=eval(temp)
  else:
    for i in range(index,len(s),2):
      s[i] = '+'
      go(s,i+2,cnt-1)
      s[i] = ' '

s1 = input()
ans = int(s1)

s2 , k = "" , 0

for i in range(0,2*len(s1)-1):
  if i%2 == 0 : 
    s2+=s1[k]
    k+=1
  else:
    s2+=' '

s2 = list(s2)

for i in range(1,len(s1)):
  go(s2,1,i)

print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
pattern = [format(i, 'b').zfill(len(S) - 1) for i in range(2 ** (len(S) - 1))]

for i in pattern:
    temp = ''
    pm = i.translate(str.maketrans({'0': '-', '1': '+'}))
    for j in range(2 * len(S) - 1):
        if j % 2 == 0:
            temp += S[j // 2]
        else:
            temp += pm[j // 2]
    temp = temp.replace('-', '')
    ans += eval(temp)

print(ans)

Submission status: Accepted

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

li=[S[0]]

for i in range(1,N):
    f=[]
    for j in li:
        f.append(j+S[i])
        f.append(j+"+"+S[i])
        li=f
ans=0
for s in li:
    sum1=0
    temp=0
    for i in range(len(s)):
        if s[i]=="+":
            sum1+=temp
            temp=0
        else:
            temp=temp*10+int(s[i])
    sum1+=temp
    ans+=sum1

print(ans)

Submission status: Accepted

Solution code:
import itertools

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

lis=list(range(1,N))
combi=[]
for i in range(N):
    a=list(itertools.combinations(lis,i))
    combi.extend(a)

ans=0  
for s in combi:
    sum=0
    temp=[]
    for i in range(N):
        if i in s:
            sum+=int("".join(temp))
            temp=[S[i]]
        else:
            temp.append(S[i])
    sum+=int("".join(temp))
    ans+=sum
print(ans)

Submission status: Accepted

Solution code:
# 深さ優先探索
import functools


def eval_sum(s_index, i):
    # print(s_index, i)
    if i == len(s_index) - 1:
        return eval(functools.reduce(lambda x, y: x + y[0] + y[1], s_index, ''))
    else:
        return eval_sum(s_index[:], i + 1) + eval_sum(s_index[:i] + [[s_index[i][0], '+']] + s_index[i + 1:], i + 1)


s = input()
s_index = list(map(lambda x: [x, ''], s))

print(eval_sum(s_index, 0))

Submission status: Accepted

Solution code:
import itertools
s = input()
li = ["+", ""]
lli = list(itertools.product(li, repeat=len(s)-1))
ans = 0
for k in lli:
  val = ""
  for i, j in zip(s, k):
    val += i + j
  val += s[-1]
  ans += eval(val)
print(ans)

Submission status: Accepted

Solution code:
s = input()

n = len(s)-1
ans = 0

for i in range(2**n):
    formula = s[0]
    for j in range(n):
        if (i >> j) & 1:
            formula += "+"
        formula += s[j+1]
    f = list(map(int, formula.split("+")))
    ans += sum(f)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input();l=len(S);print(sum(eval("".join(sum(zip(["+"*(i&2**j)for j in range(l)],S),())))for i in range(2**l))//2)

Submission status: Accepted

Solution code:
S=input();s=0;l=len(S)-1
for i in range(2**l):
    T=S
    for j in range(l):
        if i&(2**j):T=T[:l-j]+"+"+T[l-j:]
    s+=eval(T)
print(s)

Submission status: Accepted

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

def main():
    s = input().strip()
    n = len(s)-1
    ans = 0
    for i in range(1<<n):
        t = s[0]
        for j in range(n):
            if ((i >> j) & 1) == 1:
                t += "+"
            t += s[j+1]
        ans += eval(t)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

# 整数 n を m 進数 k 桁で表現した文字列
# ex. bins(3,2,2) => 11
def bins(n, m, k):
    # n がマイナスだったり、k桁で収まらない場合やばそう
    s = ""
    while n > 0:
        s = str(n%m) + s
        n //= m
    s = "0"*(k-len(s)) + s
    return s

def main():
    s = input().strip()
    n = len(s)-1 # s の各文字（"+" を入れるスキマ）の数
    ans = 0
    # s の各文字の間に "+" を挿入する・しない場合の
    # 全ての文字列 (2**n 通り) を作って計算する
    for i in range(2**n):
        b = bins(i,2,n)
        t = s[0]
        for j in range(n):
            if b[j] == "1":
                t += "+"
            t += s[j+1]
        ans += eval(t)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin
import itertools
S = (stdin.readline().rstrip())
ans = 0
s = ""
for k in list(itertools.product(["","+"],repeat=len(S)-1)):
    #print(k)
    for i,j in itertools.zip_longest(S,k,fillvalue=""):
        s = s+i+j
        #print(s)
    ans += eval(s)
    s = ""
print(ans)

Submission status: Accepted

Solution code:
import itertools
s = input()
num_place = len(s) - 1

if num_place == 0:
  result = int(s)
else:
  list_place_plus = list(itertools.product(range(2), repeat=num_place))
  result = 0
  for one_place in list_place_plus:
    start = 0
    for place, check in enumerate(one_place):
      if check == 1:
        result += int(s[start:place+1])
        start = place + 1
      if place + 1 == num_place:
        result += int(s[start:])
print(result)

Submission status: Accepted

Solution code:
import itertools as it

S = input()
ans = 0
for config in it.product(range(2), repeat=len(S) - 1):
    eq = ""
    for i in range(len(S) - 1):
        eq += S[i] + "+" if config[i] == 1 else S[i]
    eq += S[-1]
    ans += sum([int(i) for i in eq.split("+")])
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

s = input()

ans = 0
for p in product("10", repeat=len(s)-1):
    formula = ""
    for i, l in enumerate(p):
        formula += s[i] + "+" * int(l)
    formula += s[-1]
    sol = eval(formula)
    ans += sol

print(ans)

Submission status: Accepted

Solution code:
S=input()
n=len(S)-1
comb=[[[] for i in range(n+1)] for j in range(n+1)]
for i in range(1,n+1):
    for j in range(1,n+1):
        if i>=1 and j==1:
            comb[i][j]=[[k] for k in range(1,i+1)]
        elif i==j:
            comb[i][j]=[[k for k in range(1,i+1)]]
        elif i>j:
            for m in range(len(comb[i-1][j-1])):
                comb[i][j]+=[comb[i-1][j-1][m]+[i]]
            comb[i][j]+=comb[i-1][j]
s=0
for i in range(1,n+1):
    cut_l=comb[n][i]
    for j in range(len(cut_l)):
        cut=[0]+cut_l[j]+[n+1]
        lis=[]
        for k in range(len(cut)-1):
            lis.append(int(S[cut[k]:cut[k+1]]))
        s+=sum(lis)
print(s+int(S))

Submission status: Accepted

Solution code:
def dfs(i,S):
    if i == n-1:
        return eval(S)
    return dfs(i+1,S+s[i+1]) + dfs(i+1,S+"+"+s[i+1])

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
ans = 0
for flag in itertools.product([0,1], repeat=n-1):
    cnt = int(s[-1])
    c = 0
    for i,ff in enumerate(flag):
        if ff:
            cnt += int(s[n-i-2])
            c = 0
        else:
            cnt += int(s[n-i-2]) * 10 ** (c+1)
            c += 1
    # print(cnt)
    ans += cnt
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(2**N):
  tmp = S[0]
  for j in range(N):
    if (i>>j) & 1:
      ans += int(tmp)
      tmp = S[j+1]
    else:
      tmp += S[j+1]
  ans += int(tmp)
print(ans)

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

S = input().rstrip()
l = list(S)
N = len(l)

if S == '1':
    print(1)
    exit()

def getbit(i, length):
    return format(i, '0' + str(length) + 'b')

bits = []
for i in range(2**(N-1)):
    bits.append(getbit(i, N-1))


ans = 0

for i in range(len(bits)):
    s = str(l[0])

    bitlist = list(bits[i])
    for j in range(len(bitlist)):
        if bitlist[j] == '0':
            pass
        else:
            s += '+'

        s += str(l[j+1])

    ans += eval(s)

print(ans)

Submission status: Accepted

Solution code:
s = list(input())

# 2^(文字数 - 1) 通りの数式が作れるので、それぞれの計算結果を足し合わせる
result = 0
for i in range(2 ** (len(s) - 1)):
    # 数字と数字の間を左から順に0, 1, ...番目とし、
    # iをビット列と見なして、(j+1)ビット目(j=0,1,...)が1の場合は j番目の位置に '+' を挿入する
    # e.g.) S = '125' とすると、 1{0}2{1}5, i=0b00~0b11 なので、それぞれ以下の数式に対応する
    # 0b00 → '125'
    # 0b01 → '1' + '25'
    # 0b10 → '12' + '5'
    # 0b11 → '1' + '2' + '5'
    num_str = s[0]
    for j in range(0, len(s) - 1):
        if ((i & (2 ** j)) >> j) == 1:
            # 文字間を '+' で繋ぐ
            num_str += '+'
        num_str += s[j + 1]
    result += eval(num_str)

print(result)

Submission status: Accepted

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

def f(i, a):
    if i == N-1:
        return sum(list(map(int, a.split('+')))) 
    
    return f(i+1, a + S[i+1]) + f(i+1, a + '+' + S[i+1])

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

Submission status: Accepted

Solution code:
s=input()
n=len(s)
ans=int(s)
for bit in range(1<<(n-1)):
    pattarn = []
    for j in range(n):
        if (bit & (1<<j)):
            pattarn.append(j)
    if len(pattarn)==0:
        continue
    left=0
    res=0
    for i in range(len(pattarn)):
        res+=int(s[left:pattarn[i]+1])
        left=pattarn[i]+1
    ans+=res+int(s[pattarn[-1]+1:])
print(ans)

Submission status: Accepted

Solution code:
Som=list(str(input()))
S=[]
for i in Som:
    S.append(int(i))
if len(S)>=3:
    nums=0
    for x in range(len(S)):
        if x==0:
            nums+=S[0]*(10**(len(S)-1))
        else:
            nums+=S[x]*(10**(len(S)-1-x))*(2**(x-1))
    for y in range(len(S)-1):
        nums+=(sum(S[:len(S)-y]))*(10**y)*(2**(len(S)-2-y))
    print(nums)
if len(S)==2:
    print(11*S[0]+2*S[1])

if len(S)==1:
    print(S[0])

Submission status: Accepted

Solution code:
S = input()

ans = 0
for i in range(1, len(S) + 1):
    for j in range(len(S) + 1 - i):
        left = j - 1
        right = len(S) - j - i - 1
        edge = (2 ** max(0, left)) * (2 ** max(0, right))
        #print(int(S[j: j + i]) * (2 ** edge))
        ans += int(S[j:j + i]) * edge
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    s = input()
    ls = len(s)
    ans = 0
    for bit in range(1 << (ls - 1)):
        f = ""
        for j in range(ls - 1):
            f += s[j]
            if 1 << j & bit:
                f += "+"
        f += s[-1]
        ans += eval(f)
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

def f(i, a):
    if i == N-1:
        return sum(list(map(int, a.split('+'))))
    
    return f(i+1, a + S[i+1]) + f(i+1, a + '+' + S[i+1])

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

Submission status: Accepted

Solution code:
s = input()
ans = 0

plus_minus = [[]]
for i in range(len(s) - 1):
  new = []
  for element in plus_minus:
    new.append(element + [0]) 
    new.append(element + [1])
    plus_minus = new
    
for element in plus_minus:
  formula = s
  plus_num = 0
  for i in range(0, len(s) - 1):
    if element[i] == 1:
      formula = (formula[:i + 1 + plus_num] + "+" + formula[i + 1 + plus_num:])
      plus_num += 1
  ans += eval(formula)
print(ans)

Submission status: Accepted

Solution code:
s=input();l=len(s)-1;print(sum(eval(s[0]+"".join("+"*(i>>j&1)+s[j+1]for j in range(l)))for i in range(2**l)))

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[j+1]
	a+=eval(t)
print(a)

Submission status: Accepted

Solution code:
import itertools
import copy

S = list(input())

answer = 0
length = len(S)
for pattern in itertools.product((True, False), repeat=length-1):
    S2 = S[:]
    for i in range(length-1):
        if pattern[i]:
            S2.insert(length-i-1, '+')
    answer += eval(''.join(S2))

print(answer)

Submission status: Accepted

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

A = [""] * (n*2-1)
j = 0
for i in range(0, n*2-1, 2):
    A[i] = s[j]
    j += 1

ans = 0

for i in range(2**(n-1)):
    i_b = format(i, '0'+str(n-1)+'b')
    # print(i_b)
    B = A[:]
    j = 1
    for i in range(n-1):
        if i_b[i] == "1":
            B[j] = "+"
        j += 2
    # print("".join(B))
    ans += eval("".join(B))

print(ans)

Submission status: Accepted

Solution code:
S = input()
t = [0] * (2 ** (len(S) - 1))
t[0] = int(S)
for i in range(2 ** (len(S) - 1)):
  r = 0
  s = ""
  l = list(bin(i)[2:])
  l = [0] * (len(S) - len(l) - 1) + l
  #print(l)
  for j in range(len(S)):
    if j == len(S) - 1:
      s += S[j]
      break
    if l[j] == "1":
      r += int(s + S[j])
      s = ""
    else:
      s += S[j]
  if s != "": r += int(s)
  #print(r)
  t[i] = r
print(sum(t))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
def resolve():
    s=input()
    n=len(s)
    ans=0
    from itertools import product
    for A in product(range(2),repeat=n-1):
        k=s[0]
        for i in range(n-1):
            k+='+' if A[i] else ''
            k+=s[i+1]
        ans+=eval(k)
    print(ans)
resolve()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# input=sys.stdin.readline
def resolve():
    s=input()
    n=len(s)
    ans=0
    from itertools import product
    for A in product(range(2),repeat=n-1):
        k=s[0]
        for i in range(n-1):
            k+='+' if A[i] else ''
            k+=s[i+1]
        ans+=eval(k)
    print(ans)
resolve()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
S=input()
N=len(S)

l=[]*9
count=0
for i in range(2**(N-1)):
    prev=0
    for j in range(N-1):
        if i>>j&1==1:
            count+=int(S[prev:j+1])
            prev=j+1
    count+=int(S[prev:N])
print(count)

Submission status: Accepted

Solution code:
s = input()
s_len = len(s)
ans = 0
for i in range(2 ** (s_len - 1)):
    shiki = ""
    # print("pattern {}: ".format(i), end="")
    for j in range(s_len):
        shiki += s[j]
        if i>>j & 1:
            shiki += '+'
    ans += eval(shiki)
    # print(shiki)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():                                                                     
    s = raw_input()                                                             
    to_eval = [s[0]]                                                            
    buf = []                                                                    
                                                                                
    for elem in s[1:]:                                                          
        for x in to_eval:                                                       
            buf.append(x+elem)                                                  
            buf.append(x+'+'+elem)                                              
        to_eval = buf[:]                                                        
        buf = []                                                                
                                                                                
    _sum = 0                                                                    
    for x in to_eval:                                                           
        _sum += eval(x)                                                         
    print(_sum)                                                                 
                                                                                
main()

Submission status: Accepted

Solution code:
S=input()
N=len(S)-1
total=0
for i in range(2**N):
    list=['+']*N
    for j in range(N):
        if ((i>>j)&1):
            list[N-j-1]=''
    formula=''
    for num,operator in zip(S,list+['']):
        formula+=(num+operator)
    total+=eval(formula)
print(total)

Submission status: Accepted

Solution code:
S=input()
total=0
if len(S)==1:
    print(S)
    exit(0)
for i in range(2**(len(S)-1)):
    a = int(S[0])
    t=format(i,'b').zfill(len(S)-1)
    for j in range(len(t)):
        if t[j]=='0':
            a=a*10+int(S[j+1])
        else:
            total+=a
            a=int(S[j+1])
    total+=a

print(total)

Submission status: Accepted

Solution code:
S=input()
result = 0

for i in range(1 << len(S)-1):
    #先頭文字
    hoge=S[0]
    for j in range( len(S)-1 ):
        if i>>j&1 :
            hoge+="+"
        hoge+=S[j+1]
    result += eval(hoge)
print(result)

Submission status: Accepted

Solution code:
s = input()

def dfs(s):
    ans = int(s)
    for i in range(1, len(s)):
        ans += int(s[:i]) * (1 << (len(s[i:])-1)) + dfs(s[i:])
    return ans

ans = dfs(s)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() 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)]
mod = 1000000007

n = str(I())
ans = 0
space_num = len(n) - 1
for i in range(2 ** space_num):
    ret = n[0]
    for j in range(space_num):
        if i & 1 << j:
            ret += '+'
        ret += n[j + 1]
    ans += eval(ret)


print(ans)

Submission status: Accepted

Solution code:
s = input()

ans = 0

#print(s[0],s[1],s[2])

for i in range(2**(len(s)-1)):
    tmp = i
    #print(tmp,tmp,tmp)
    temp = 0
    for j in range(len(s)-1):
        #print(ans)
        temp += int(s[j])
        #print(temp)
        if tmp % 2 == 0:
            temp = temp * 10
            #print(0)
            #if j == len(s)-2:
                #ans += temp + int(s[j+1])
        else:
            #ans += s[i]
            #print(1)
            ans += temp
            temp = 0
        if j == len(s)-2:
            ans += temp + int(s[j+1])
            #print(1)
        tmp = tmp // 2


if len(s) == 1:
    print(s[0])
    exit()
    
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import product
s=list(input())
cnt=0
pl=list(product(['','+'],repeat=len(s)-1))
for j in pl:
	for _ in range(len(s)):
		l=[s[0]]
		for i in range(len(s)-1):
			l.append(j[i])
			l.append(s[i+1])
	a="".join(l)
	cnt+=eval(a)
print(cnt)

Submission status: Accepted

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

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


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

Submission status: Accepted

Solution code:
import itertools
num = str(input())

olist = [int(i+1) for i in range(len(num)-1)]
comblist = []
for i, _ in enumerate(olist, 1):     
    for j in itertools.combinations(olist, r=i):
        comblist.append(j)

L = []
for i in range(len(comblist)):
  t = num
  for j in range(len(comblist[i])):
    t = t[0:comblist[i][j]+j] + "," + t[comblist[i][j]+j:]
  L.append(t)

out = 0
for i in range(len(L)):
  t = L[i].split(",")
  for j in range(len(t)):
    out += int(t[j])
print(out+int(num))

Submission status: Accepted

Solution code:
S = input()

# bit全探索で解く
def solve():
    ans = 0

    for i in range(2**(len(S)-1)):
        value = list(S)
        bit = list(str(bin(i))[2:].zfill(len(S)-1))
        for i, p in enumerate(bit):
            if int(p):
                value[i] = value[i] + '+'
        values = ''.join(value).split('+')
        values = list(map(int, values))
        ans += sum(values)
    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
S = input()
dp = len(S)*[0]
dp[0] = int(S[0])

for i in range(1,len(S)):
    dp[i]=int(S[:i+1])+sum(dp[j-1]+int(S[j:i+1])*2**(j-1) for j in range(1,i+1))
    
print(dp[-1])

Submission status: Accepted

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

a=[None]*n
a[0]=int(s[0])


for i in range(n-1):
  a[i+1]=a[i]*10+sum(int(j) for j in s[:i+2])*(2**i)+int(s[i+1])*(2**i)

print(a[n-1])

Submission status: Accepted

Solution code:
s = input()
cal = ["+",""]
ans = 0
if len(s) == 1:
  print(s)
elif len(s) == 2:
  for i in cal:
    ans += eval(s[0]+i+s[1])
  print(ans)
elif len(s) == 3:
  for i in cal:
    for j in cal:
      ans += eval(s[0]+i+s[1]+j+s[2])
  print(ans)
elif len(s) == 4:
  for i in cal:
    for j in cal:
      for k in cal:
        ans += eval(s[0]+i+s[1]+j+s[2]+k+s[3])
  print(ans)
elif len(s) == 5:
  for i in cal:
    for j in cal:
      for k in cal:
        for l in cal:
          ans += eval(s[0]+i+s[1]+j+s[2]+k+s[3]+l+s[4])
  print(ans)
elif len(s) == 6:
  for i in cal:
    for j in cal:
      for k in cal:
        for l in cal:
          for m in cal:
            ans += eval(s[0]+i+s[1]+j+s[2]+k+s[3]+l+s[4]+m+s[5])
  print(ans)
elif len(s) == 7:
  for i in cal:
    for j in cal:
      for k in cal:
        for l in cal:
          for m in cal:
            for n in cal:
              ans += eval(s[0]+i+s[1]+j+s[2]+k+s[3]+l+s[4]+m+s[5]+n+s[6])
  print(ans)
elif len(s) == 8:
  for i in cal:
    for j in cal:
      for k in cal:
        for l in cal:
          for m in cal:
            for n in cal:
              for o in cal:
                ans += eval(s[0]+i+s[1]+j+s[2]+k+s[3]+l+s[4]+m+s[5]+n+s[6]+o+s[7])
  print(ans)
elif len(s) == 9:
  for i in cal:
    for j in cal:
      for k in cal:
        for l in cal:
          for m in cal:
            for n in cal:
              for o in cal:
                for p in cal:
                  ans += eval(s[0]+i+s[1]+j+s[2]+k+s[3]+l+s[4]+m+s[5]+n+s[6]+o+s[7])
  print(ans)
elif len(s) == 10:
  for i in cal:
    for j in cal:
      for k in cal:
        for l in cal:
          for m in cal:
            for n in cal:
              for o in cal:
                for p in cal:
                  for q in cal:
                    ans += eval(s[0]+i+s[1]+j+s[2]+k+s[3]+l+s[4]+m+s[5]+n+s[6]+o+s[7]+p+s[8]+q+s[9])
  print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

def insert(s:str, ind:tuple):
    ind = list(ind)
    for i in range(0, len(ind)):
        ind[i] += i
        s = s[:ind[i]] + "+" + s[ind[i]:]
    else:
        return s
        
s = input()
ans = int(s)
for i in range(1, len(s)):
    for comb in combinations(range(1, len(s)), i):
        ans += eval(insert(s, comb))
else:
    print(ans)