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:
#!usr/bin/env python3
from collections import defaultdict
import math
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def LIR(n): return [LI() for i in range(n)]
mod = 1000000007

#A

#B

#C

#D
s = list(S())
lis = []
sign = ["","+"]
k = 2**(len(s)-1)
d = 10-len(s)
for i in range(d):
    s.insert(0,"0")
i = 0
for a0 in range(2):
    for a1 in range(2):
        for a2 in range(2):
            for a3 in range(2):
                for a4 in range(2):
                    for a5 in range(2):
                        for a6 in range(2):
                            for a7 in range(2):
                                for a8 in range(2):
                                    if i >= k:break
                                    lis.append(s[0]+sign[a0]+s[1]+sign[a1]+s[2]+sign[a2]+s[3]+sign[a3]+s[4]+sign[a4]+s[5]+sign[a5]+s[6]+sign[a6]+s[7]+sign[a7]+s[8]+sign[a8]+s[9])
                                    i += 1
ans = 0
for i in lis:
    ans += eval(i[d:])
print(ans)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

Solution code:
#A
"""
n,k =map(int, input().split())

print(k * (k - 1)**(n - 1)) 
"""

#B
"""
import math
r, n, m = map(int, input().split())
kankaku = 2 * r / n
tyusin = n / 2
sum = 0
for i in range(1, n + m):
    if i - m < 0:
        yoko1 = 2 * math.sqrt(r ** 2 - ((tyusin - i) * kankaku)** 2)
        sum += yoko1
    elif i > n:
        yoko2 = 2*math.sqrt(r ** 2 - ((tyusin - i + m) * kankaku)** 2)
        sum += yoko2
    else:
        yoko1 = 2 * math.sqrt(r ** 2 - ((tyusin - i) * kankaku)** 2)
        yoko2 = 2 * math.sqrt(r ** 2 - ((tyusin - i + m) * kankaku)** 2)
        sum += max(yoko1, yoko2)
print(sum)
"""

#C
"""
n = int(input())
an = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans += an[i] - 1
print(ans)
"""
#D

import itertools
s = input()
sum = int(s)
sb = list(s)
for i in range(1, len(s)):
    a = list(itertools.combinations(list(range(1,len(s))), i))
    for k in a:
        sb = list(s)
        f = 0
        for n in k:
            sb.insert(n + f, "+")
            f += 1
        b = ""
        for n in sb:
            if n == "+":
                sum += int(b)
                b = ""
            else:
                b += n
        sum += int(b)

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
n = len(s)
res = 0
for i in range(2**(n-1)):
    bit = bin(i)[2:].zfill(n-1)
    index = []
    for j in range(n-1):
        if bit[j]=='1':
            index.append(j+1)
    if len(index)>0:
        div = []
        for k in range(len(index)):
            if k==0:
                div.append(int(s[:index[k]]))
            else:
                div.append(int(s[index[k-1]:index[k]]))
        div.append(int(s[index[-1]:]))
        res += sum(div)
    else:
        res += int(s)
print(res)

Submission status: Accepted

Solution code:
S = list(input())
ans = 0
for bit in range(1 << len(S)-1) :
    BIT = []
    calc = ""
    for k in range(len(S)-1) :
        if bit & (1 << k) :
            BIT.append(1+k)
    for k in range(len(S)) :
        if k in BIT :
            calc += "+"
        calc += S[k]
    ans += eval(calc)
print(ans)

Submission status: Accepted

Solution code:
#スライス操作とbit全探索 
S = input()
N = len(S)
insert = []

#部分集合列挙 を応用し + の挿入位置を求める
for i in range(1<<(N-1)):
    #insert = []
    tmp = []
    for j in range(N-1):
        if ((i>>j) & 1) == 1:
            #何故か位置でなく値を格納した
            #tmp.append(int(S[j]))
            tmp.append(j+1)
    insert.append(tmp)
#print(insert)

#挿入位置をもとに文字列スライス。ここで苦労
split = []

for i in insert:
    s = []
    copy = S[:]
    prev = 0
    for j in i:
        #前の挿入位置を記録し次で利用すれば良い
        if not (S[prev:j] == ""):
            s.append(int(S[prev:j]))
            copy = S[j:]
            prev = j
    s.append(int(copy))
    split.append(s)    
#print(split)

res = 0
for a in split:
    res += sum(a)
print(res)

Submission status: Accepted

Solution code:
import numpy as np
import itertools

def calc_sum(nums):
    if len(nums) == 1: return nums[0]
    idxs = np.arange(1, len(nums))
    masks = list(itertools.product([False, True], repeat=len(idxs)))

    ret = 0 
    for mask in masks:
        selected_idxs = [0] +list( idxs[ np.array(mask)]) + [len(nums)]
        for i in range(len(selected_idxs) - 1):
            ret += (int(''.join(nums[selected_idxs[i]: selected_idxs[i+1]])))
    return ret


S = input()
nums = [s for s in S]

print(calc_sum(nums))

Submission status: Accepted

Solution code:
s = list(input())
l = len(s)
t = [0] * l 
k = 2**(l-1)
for i in range(l):
    if i == 0:
        t[l-1] = k 
    else:
        t[l-1-i] = t[l-i] * 5 + k // 2
ret = 0 
for i in range(l):
    top = int(s[i])
    ret += top * t[i]
print(ret)

Submission status: Accepted

Solution code:
S = input()
sum_list = []

for i in range(1 << (len(S)-1)):
    temp = int(S[0])
    ans = 0
    for j in range(len(S)-1):
        if ((i >> j) & 1) == 1:
            ans += temp
            temp = int(S[j+1])
        else:
            temp = temp*10 + int(S[j+1])
    ans += temp
    sum_list.append(ans)
print(sum(sum_list))

Submission status: Accepted

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

N = 1 << (slen-1)

ans = 0
for i in range(N):
    eq = ''
    for j in range(slen):

        if i & 1<<j:
            eq += S[j:j+1] + '+'
        else:
            eq += S[j:j+1]

    ans += eval(eq)

print(ans)

Submission status: Accepted

Solution code:
S = list(input())

n = len(S)

ans = 0

def calc(i=0, s=0, buf=''):
    global ans
    if i == len(S):
        if buf:
            s += int(buf)
        ans += s

    else:
        if buf:
            calc(i+1, s + int(buf), S[i])

        calc(i+1, s, buf + S[i])


calc()

print(ans)

Submission status: Accepted

Solution code:
S = input()
s = len(S)
n = 0
for i in range(s):
    n+= int(S[i])*(10**(s-1-i))*2**i
lis = []
for i in range(s-1):
    lis.append(2**i)
for i in range(s-1):
    for j in range(s-1-i):
        n += int(S[i])*(10**(s-2-i-j))*(lis[i+j])
print(n)

Submission status: Accepted

Solution code:
from itertools import combinations as ic
S = list(input())
pos = [i for i in range(1, len(S))]
total = 0
for p in range(len(S)):
  combs = ic(pos, p)
  for comb in combs:
    ans = ''
    for j, n in enumerate(S):
      if j in comb:
        ans += '+' + n
      else:
        ans += n
    total += eval(ans)
print(total)

Submission status: Accepted

Solution code:
N = int(input())

A = []

while N>0:
    tmp = N%10
    A.append(tmp)
    N = (N-tmp)//10

dp = [[0 for i in range(len(A))] for j in range(len(A))]

dp[0][0] = 2**(len(A)-1)

for i in range(1, len(A)):
    for j in range(i-1):
        dp[i][j] = dp[i-1][j]
    dp[i][i-1] = dp[i-1][i-1]//2
    dp[i][i] =  dp[i-1][i-1]//2
    
ans = 0
    
for i in range(len(A)):
    for j in range(i+1):
        ans = ans + dp[i][j]*A[i]*(10**j)
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
ret = 0


def calc(i=0, s=0, buf=''):
    global ret
    if i == len(S):
        if buf:
            s += int(buf)
        ret += s
    else:
        if buf:
            calc(i + 1, s + int(buf), S[i])
        calc(i + 1, s, buf + S[i])


calc()
print(ret)

Submission status: Accepted

Solution code:
import itertools

s = input()
n = [i for i in s]
#print(n)
ans = 0
# +の個数
for i in range(len(n)):
    # +を挿入するパターンの全探索
    for j in itertools.combinations(range(len(n)-1), i):
        #print(i,j)
        temp = [i for i in s]
        # +を挿入
        for k in j[::-1]:
            temp.insert(k+1, "+")
            #print(i,j,k)
        # listから文字列に
        temp = "".join(temp)
        # +で区切ってリストに
        temp = temp.split("+")
        # リストの要素をint型にキャストして総和を算出
        temp = map(int, temp)
        ans += sum(temp)

print(ans)

Submission status: Accepted

Solution code:
S = input()

ans = 0

def dfs(i, s):
    global ans
    if i == 1:
        ans += eval(s)
        return
    dfs(i-1, s)
    dfs(i-1, s[:i-1]+'+'+s[i-1:])
    return

dfs(len(S),S)
print(ans)

Submission status: Accepted

Solution code:
def digit_gen(num_str, index):
    global S, sum_list
    if index == len(S):
        sum_list.append(num_str)
        return
    digit_gen(num_str + S[index], index + 1)
    digit_gen(num_str + S[index] + "+", index + 1)


if __name__ == "__main__":
    S = [c for c in input()]  
    index = 0
    sum_list = []
    num_str = ""
    digit_gen(num_str, index)
    sum_list = sum_list[::2]
    ans = 0
    a = "ans += "
    for num_str in sum_list:
        exec(a+num_str)
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np


s = input()
size = len(s)

num = 0
for i in range(2**(size-1)):
    sp = np.array([(i >> j) & 1 for j in range(size)])
    st = ''.join([k + (' ' if sp[j] == 1 else '') for j, k in enumerate(s)])
    x = map(int, st.split())
    num += sum(x)
print(num)

Submission status: Accepted

Solution code:
def solve(x):
	if x == []:
		return 0
	if len(x) == 1:
		ans = x[0]
		return ans
	ans = x[0] * 2 ** (len(x) - 2) + solve(x[1:]) + solve([x[0] * 10 + x[1]] + x[2:])
	return ans
S = input()
T = []
for i in S:
	T.append(int(i))
print(solve(T))

Submission status: Accepted

Solution code:
s = str(input())
ans = 0
for bits in range(1 << len(s)-1):
    a = s[0]
    for i in range(len(s)-1):
        if (bits >> i & 1) == 1:
            a += '+'
        a += s[i+1]
    ans += eval(a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
t=list(int(S[i]) for i in range(len(S)))
s=2**(len(S)-1)
b=0
for i in range(len(S)):
    for j in range(i+1):
        b+=t[-(i+1)]*(10**j)*s//(2**min(i,j+1))
print(b)

Submission status: Accepted

Solution code:
S=input()
s=2**(len(S)-1)
b=0
for i in range(len(S)):
    for j in range(i+1):
        b+=int(S[-(i+1)])*(10**j)*s//(2**min(i,j+1))
print(b)

Submission status: Accepted

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

def DFS(plus=[], depth=0):
    global ans
    if depth >= n:
        command = s
        tmp = 1
        for i in plus:
            command = command[:tmp+i] + "+" + command[tmp+i:]
            tmp += 1
        # print(command)
        ans += eval(command)
        return
    DFS(plus[::], depth+1)
    DFS(plus[::] + [depth], depth+1)

DFS([], 0)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def getsum(S, delimiter, idx):
    if idx == len(S):
        retval = 0
        prev = 0
        for d in delimiter:
            retval += int(S[prev:d])
            prev = d
        retval += int(S[prev:])
        return retval
    return getsum(S, delimiter, idx+1) + getsum(S, delimiter + [idx], idx+1)


def main():
    S = input()

    print(getsum(S, [], 1))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = list(input())
if len(S) == 1:
  print(int("".join(S)))
  exit()
l = []
for i in range(2*len(S) - 1):
    if i % 2 == 0:
        l.append(S[int(i/2)])
    elif i % 2 == 1:
        l.append("")
L_1 = []
L_2 = []
L_1.append(l)
def saiki(list_1,list_2,t): # 1 <= t = 2k-1 <= len(S) - 2
    for e in list_1:
        for b in [0,1]:
            if b == 0:
                list_2.append(e)
            elif t > len(e) - 1:
                print("error: t = {}, len(e) - 1 = {}".format(t,len(e) - 1))
            elif b == 1:
                e_copy = e[:]
                e_copy[t] = "+"
                list_2.append(e_copy)
    list_1.clear()
    if t < len(l) - 2:
        return saiki(list_2,list_1,t+2)
    else:
        return list_2
result = saiki(L_1,L_2,1)    
ans = 0
for e in result:
    ans += eval("".join(e))
print(ans)

Submission status: Accepted

Solution code:
S = input().strip()

L = len(S)

sum_ = 0
for p in range(1 << (L - 1)):
    val = 0
    for i, c in enumerate(S):
        c = int(c)
        val = val * 10 + c
        if i < L - 1:
            if p & (1 << i) != 0:
                sum_ += val
                val = 0
    sum_ += val
print(sum_)

Submission status: Accepted

Solution code:
s = input()

s_len = len(s)

sum_num = 0
for i in range(1<<(s_len-1), 1<<s_len):
	n, a = 0, 0
	for j in range(s_len):
		if (i>>j)%2 == 0:
			continue
		n += int(s[a:j+1])
		a = j+1
	sum_num += n

print(sum_num)

Submission status: Accepted

Solution code:

def main():
    buf = input()
    S = buf
    total = split_sum(S)
    print(total)

def split_sum(S):
    total = 0
    for i in range(int(2 ** (len(S) - 1))):
        factor = 1
        mask = 0b0000000001
        for j in range(len(S)):
            total += int(S[-j - 1]) * factor
            if i & (mask << j):
                factor = 1
            else:
                factor *= 10
    return total

if __name__ == '__main__':
    main()

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):   # mask
        if i & (1<<j):  # iと1をjbitシフトしたものを比較
            tmp += "+"
        tmp += S[j+1]
    ans += eval(tmp)
print(ans)

Submission status: Accepted

Solution code:
if __name__=='__main__':
  S=input()
  sums=0
  num=[x for x in range(1,len(S))]
  for i in range(0,1<<len(num)):
    output=[]
    for j in range(len(num)):
      if ((i>>j)&1)==1:
        output.append(num[j])
    output.append(10)
    t=0
    for o in output:
      sums+=int(S[t:o])
      t=o
  print(sums)

Submission status: Accepted

Solution code:
s = input()

def manyformulas(s):
    if len(s)==1:
        return 1,int(s[0])
    else:
        sum = int(s)
        count = 1
        for i in range(len(s)-1):
            c, recursive = manyformulas(s[(i+1):])
            sum += c*int(s[:(i+1)]) + recursive
            count += c

        return count, sum

print(manyformulas(s)[1])

Submission status: Accepted

Solution code:
s = input()
x = []
l = len(s)
for i in range(l):
    x.append(int(s[i]))

sum = 0
for n in range(2**(l-1)):
    bin_str = format(n,'0'+str(l-1)+'b')
    prev = 0
    for i in range(l-1):
        if bin_str[i]=='0':
            prev = prev*10 + x[i]
        else:
            sum += prev*10 + x[i]
            prev = 0
    sum += prev*10 + x[l-1]

print(sum)

Submission status: Accepted

Solution code:
# abc 045 c
from itertools import zip_longest

s = input()

sum_num = 0
for i in range(0, 2**(len(s)-1)):
	sings = bin(i)[2:].zfill(len(s)-1).replace("1", "+").replace("0", " ")
	formula = ("".join("".join(t) for t in zip_longest(s, sings, fillvalue=" "))).replace(" ", "")
	sum_num += eval(formula)

print(sum_num)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# input
s = input()
# calc
n = len(s)
int_s = []
for i in range(n):
    int_s.append(int(s[i]))
ans = 0
for i in range(n):
    for j in range(i, n):
        value = 0
        for k in range(j - i + 1):
            value += (10 ** k) * int_s[j - k]
        # i, jの位置によってansに足す値を場合分け
        if i == 0:
            if j == n - 1:
                ans += value
            else:
                ans += value * (2 ** (n + i - j - 2))
        elif j == n - 1:
            ans += value * (2 ** (n + i - j - 2))
        else:
            ans += value * (2 ** (n + i - j - 3))
# output
print(ans)

Submission status: Accepted

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

def dfs(i):
    global st,S,ans
    if i==n-1:
        st=S
        c=0
        off=0
        for j in lis:
            c+=1
            if j==1:
                S=S[:c+off]+'+'+S[c+off:]
                off+=1
        #print(S)
        tm=S.split('+')
        for j in range(len(tm)):
            #print(tm[j])
            ans+=int(tm[j])

        S=st
        return
    lis.append(0)
    dfs(i+1)
    lis.pop(-1)
    lis.append(1)
    dfs(i+1)
    lis.pop(-1)
lis=[]
ans=0
dfs(0)
print(ans)

Submission status: Accepted

Solution code:
s = list(input())
total = []
n = len(s)

def search(i,s):
	if i == n-1:
		li = []
		s = "".join(s)
		li = list(map(int,s.split("+")))
		total.append(sum(li))
		return

	else:
		search(i+1,s)

		_s = s[:-(n-i)+1] + ["+"] + s[-(n-i)+1:]
		search(i+1,_s)

search(0,s)
print(sum(total))

Submission status: Accepted

Solution code:
def keta(N):
    bit_s = bin(N)[2:]#Nの2ビット変換
    bit_s = (bit_s.zfill(S_n))[::-1]#ゼロ埋/反転 
    
    res =[1]
    temp = 1
                               
    for i in range(len(bit_s)-1):
        if int(bit_s[i]):#1
            temp = 1
            res.insert(0, temp)
        else:#0
            temp *= 10
            res.insert(0, temp)
    
    return res


def solve():
    S_l = list(map(int, list(S)))#分割
    res = 0
    
    for n in range(2**(S_n-1)):
        K_l = keta(n)
        for i in range(S_n):
            res += K_l[i] * S_l[i]
    
    return res
        

if __name__ == '__main__':
    S = input()
    S_n = len(S)
    
    print(solve())

Submission status: Accepted

Solution code:
S = input()
L = len(S)
goukei = 0

for i in range(2**(L-1)):
  f = ""
  for j in range(L-1):
    f += S[j]
    if i & 1:
      f += "+"
    i >>= 1
  goukei += eval(f+S[-1])

print(goukei)

Submission status: Accepted

Solution code:
#!/usr/bin/python3                                                                                                                                                                                          

import itertools

def all_comb(n):
    comb = []
    for i in range(0, n+1):
        comb.extend(list(itertools.combinations(range(n), i)))
    return comb

if __name__=='__main__':
    str = input()
    comb = all_comb(len(str)-1)
    tail = 0
    sum = 0
    for plus_positions in comb:
        head = 0
        for plus_position in plus_positions:
            num = int(str[head:plus_position+1])
            sum += num
            head = plus_position + 1
        num = int(str[head:])
        sum += num
    print(sum)

Submission status: Accepted

Solution code:
from itertools import product
s=list(input())
a=list(product(['','+'],repeat=len(s)-1))
a_list=[]
for i in a:
    an=[s[0]]
    for j,k in zip(i,s[1:]):
        an+=j+k
    a_list.append(an)
count=0
for i in a_list:
    count+=eval(''.join(i))
print(count)

Submission status: Accepted

Solution code:
answer = 0
S = input()
L = len(S)
for bit in range(2**(L-1)):
    string = ""
    for m in range(L-1):
        if bit & 2**m:
            string += S[m]
            answer += int(string)
            string = ""
        else:
            string += S[m]
    string += S[L-1]
    answer += int(string)
print(answer)

Submission status: Accepted

Solution code:
L = list(input())

results = []

for i in range(2**(len(L)-1)) :
    calc = ""
    for j in range(len(L)-1) :
        calc += L[j]
        if i % 2 != 0 :
            calc += "+"
        i >>= 1
    f = calc + L[-1]
    results.append(eval(f))
print(sum(results))

Submission status: Accepted

Solution code:
import itertools

number = input()
answer = int(number)
length = len(number)

empty = [""] * length
plus = ["+"] * length

results = []
for i in range(2**(length - 1)):
    calc = ""
    for j in range(length - 1):
        calc += number[j]
        if i & 1:
            calc += "+"
        i >>= 1
    f = calc + number[-1]
    results.append(eval(f))
print(sum(results))

Submission status: Accepted

Solution code:
def su(s, k):
    count = 0
    for i in range(0, len(s)-1):
        tmp = k % 2
        k //= 2
        if(tmp == 1):
            s = s[:i+1+count] + '+' + s[i+1+count:]
            count += 1
    arr = s.split("+")
    arr = list(map(int, arr))
    return sum(arr)

s = input()
ans = 0
for i in range(0, (2 ** (len(s) - 1))):
    ans += su(s, i)
print(ans)

Submission status: Accepted

Solution code:
n = 0
nums = []

def dfs(i,num):
  if (i==n-1):
    nums.append(num)
    return False
  if (dfs(i+1,num+'+')):
    return True
  if (dfs(i+1, num + '_')):
    return True
  return False

def calc():
  ans = 0
  p = 0
  for num in nums:
    for i in range(n):
      if (i==n-1):
        ans += int(s[p:n])
      elif (num[i]=='+'):
        ans += int(s[p:i+1])
        p = i + 1
    p = 0

  return ans

s = input()
n = len(s)
dfs(0,"")
print(calc())

Submission status: Accepted

Solution code:
Ss = list(map(int, input()))

n = len(Ss)
ans = 0
for pat in range(1 << (n - 1)):
    num = 0
    temp = Ss[0]
    mask = 1
    for i in range(n - 1):
        if pat & mask:
            num += temp
            temp = Ss[i + 1]
        else:
            temp = temp * 10 + Ss[i + 1]
        mask <<= 1
    num += temp
    ans += num

print(ans)

Submission status: Accepted

Solution code:
s = input()

ans = 0

for i in range(1 << (len(s) - 1)):
    last = 0
    sm = 0
    for j in range(len(s) - 1):
        if (i >> j) & 1:
            sm += int(s[last:j + 1])
            last = j + 1
    sm += int(s[last:])
    # print(i, sm)
    ans += sm
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S=input()
N = len(S)
result = 0
for i in range(2**(N-1)):
    T = str(S[0])
    for k in range(N-1):
        if (i>>k )& 1 == 1:
            T += "+" + str(S[k+1])
        else:
            T += str(S[k+1])
           
    result += eval(T)

print(result)

Submission status: Accepted

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

l = len(list(str(bin(2**(n-1))))) - 2
ans = [int(s)]

for i in range(1,2**(n-1)):
    bit = bin(i)
    bit = str(bit)
    bit = list(bit)
    bit.pop(0)
    bit.pop(0)
    for k in range(l-len(bit)):
        bit.insert(0,"0")
    
    temp = 0
    start = 0
    for k in range(l):
        if bit[k] == '1':
            temp += int(s[start:k])
            start = k
    temp += int(s[start:n])
    ans.append(temp)

print(sum(ans))

Submission status: Accepted

Solution code:
n = 0
eqs = []

def dfs(i, eq):

    if(i == n - 1):
        eqs.append(eq)
        return False

    if(dfs(i+1, eq + "+")):
        return True

    if(dfs(i+1, eq + "_" )):
        return True

    return False

def calc():
    ans = 0
    p = 0
    for eq in eqs:
        for i in range(n):
            if(i == n-1):
               # print("end: " + S[p:n])
                ans += int(S[p:n])
            elif(eq[i] == "+"):
                #print(S[p:i+1])
                ans += int(S[p:i+1])
                p = i + 1
        #print(eq)
        #print("----")
        p = 0
    return ans

S = input()
n = len(S)
dfs(0, "")
print(calc())

Submission status: Accepted

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


for i in range(2**(n-1)):
    calc_str = s[0]
    operator_maker = str(format(i, 'b')).zfill(n-1)
    for j, c in enumerate(operator_maker):
        if c == '1':
            calc_str += '+'
        if n != 1:
            calc_str += s[j+1]
    answer += eval(calc_str)

print(answer)

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

blist = []
for i in range(2**(n-1)):
    blist.append(list(map(int,list(bin(i)[2::].zfill(n-1)))))

ssum = 0
for k,num in enumerate(blist):
    bi = 0
    bsum = 0
    for i,j in enumerate(num):
        if j == 1:
            bsum += int(sr[bi:i+1])
            bi = i+1
        if i == (len(num)-1):
            bsum += int(sr[bi:])
    ssum += bsum
print(ssum)

Submission status: Accepted

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

#長さからビット列を作る
for i in range(2**N):
    B.append(bin(i)[2:].zfill(N))
if N == 0:
    print(1)
    
else:
    for b in B:
        t = ""
        for i, plus in enumerate(b):
            t += S[i]
            if plus == "1":
                t += "+"

        t += S[-1]
        ans += sum([int(x) for x in t.split("+")])
        
    print(ans)

Submission status: Accepted

Solution code:
n = str(input())
ans = 0
if int(n) < 10:
  print(int(n))
  exit()
for i in range(2 ** (len(n) -1)):
  num = format(i,"b").zfill(len(n)-1)
  lis = ""
  for j in range(len(str(num))):
    if str(num[j]) == "1":
      lis += (str(n[j])+"+")
    else:
      lis += str(n[j])
  lis += n[-1]
  li = lis.split("+")
  for h in range(len(li)):
    li[h] = int(li[h])
  ans += sum(li)
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(1 << (n - 1)):
    t = ''
    for j in range(n - 1):
        t += s[j]

        if (1 & i >> j) == 1:
            t += '+'

    t += s[-1]
    ans += eval(t)

print(ans)

Submission status: Accepted

Solution code:
S = input()
tmp = 0
ans = 0
if len(S) == 1:
    print(S)
else:
    for i in range(2**(len(S)-1)):
        form = ''
        for j, x in enumerate(format(i ^ 0, '0'+str(len(S)-1)+'b')):
            form += S[j]
            if x == '0':
                continue
            form += '+'
        form += S[-1]
        ans += eval(form)

    print(ans)

Submission status: Accepted

Solution code:
from itertools import product
import copy


def calc_sum(sub):
    ret = 0
    cnt = 0
    for i in sub[::-1]:
        if i == "+":
            cnt = 0
        else:
            ret += int(i) * 10 ** cnt
            cnt += 1
    return ret


s = list(input())
l = len(s)

ans = 0
for i in product((0, 1), repeat=l-1):
    sub = copy.copy(s)
    indexes = [m for m, x in enumerate(i) if x == 1]
    if sum(i) != 0:
        for k, ind in enumerate(indexes):
            sub.insert(ind+1+k, "+")
    ans += calc_sum(sub)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import product
s = input()
ans = 0
for p in product('+ ', repeat=len(s)-1):
    f = s[0]
    for i in range(len(s)-1):
        f += p[i]+s[i+1]
    ans += eval(f.replace(' ',''))
print(ans)

Submission status: Accepted

Solution code:
import itertools

s = input()
n = len(s)
num_list = [num for num in range(n-1)]
total = int(s)
for i in range(1,n):
    temp_list = list(itertools.combinations(num_list, i))
    temp_len = len(temp_list)
    for j in range(temp_len):
        temp_sum = 0
        for k in range(i):
            if k == 0:
                part1 = 0
            part2 = list(temp_list[j])[k]
            s_part = s[part1:part2+1]
            temp_sum += int(s_part)
            part1 = part2 + 1
            if k == i-1:
                temp_sum += int(s[part1:])
        total += temp_sum
print(total)

Submission status: Accepted

Solution code:
from itertools import combinations

S = input()
patterns = []

for i in range(1, len(S)):
    patterns += list(combinations(range(1, len(S)), i)) 

answer = int(S)
for pattern in patterns:
    s = 0 
    for pos in pattern:
        answer += int(S[s:pos])
        s = pos 
    answer += int(S[pos:])

print(answer)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from itertools import combinations
s = input()

ret = 0
for i in range(len(s)):
    for c in combinations(range(1, len(s)), i):
        e = s
        for idx,j in enumerate(c):
            e = e[:idx+j]+"+"+e[idx+j:]
        exec("ret+="+e)
print(ret)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 16 04:23:00 2018

@author: Yuki
"""
def sum_from_bit(bit, string, bin_len):
    res = []
    tmp_str = string[0]
    for i in range(bin_len):
        if bit[i] == '0':
            tmp_str += string[1+i]
        else:
            res.append(int(tmp_str))
            tmp_str = string[1+i]
    res.append(int(tmp_str))
    return sum(res)

def main():
    S = input()
    
    n_bit = len(S)-1
    result = []
    for i in range(2**n_bit):
        tmp_bit = bin(i)[2:].zfill(n_bit)
        result.append(sum_from_bit(tmp_bit, S, n_bit))
    print(sum(result))
if __name__=='__main__':
    main()

Submission status: Accepted

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


    sums = 0
    for i, c in enumerate(t):
        if c != "+":
            sums *= 10
            sums += int(c)
        elif c == "+":
            ans += sums
            sums = 0
        if i == len(t) -1:
           ans += sums

print(ans)

Submission status: Accepted

Solution code:
n = raw_input()
l = len(n)

ans = 0

t = 2**(l-1)

if l == 1:
	print n
	quit()

for i in range(t):
	bit = (bin(i)[2:]).zfill(l-1)
	formula = ''

	p = 0
	b = 0

	while b < len(bit):
		formula += n[p]
		formula += "+" if bit[b] == "1" else ""
		p += 1
		b += 1

	formula += n[-1]
	ans += eval(formula)

print ans

Submission status: Accepted

Solution code:
S = input()

cnt =0
for i in range(1<<(len(S)-1)):
    num = int(S[0])
    for j in range(len(S)- 1):
        if i & (1 << j):
            cnt += num
            num = 0
        num = num*10 + int(S[j+1])
    cnt += num

print(cnt)