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

result = []

def spstr(made, left):
    for x in range(1, len(left)+1):
        new_made = made.copy()
        new_made.append(int(left[0:x]))
        new_left = left[x:]
        if new_left == "":
            result.append(new_made)
        else:
            spstr(new_made, new_left)
spstr([], s)

count = 0
for r in result:
    for n in r:
        count += n
print(count)

Submission status: Accepted

Solution code:
s = raw_input()
n = len(s)
res = 0
for i in range(n):
    for j in range(i, n):
        cnt =  n - (j - i + 3) + (i == 0) + (j == n - 1)
        res += int(s[i:j+1])*(1<<cnt)
print res

Submission status: Accepted

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

def sum_of_digit(d, l, s): #d: その位の数が何か l: 桁の数 s:下から何桁目か 下に置ける+は2^(s-1)通り 上に置ける+は2^(l-s)通り
    # 2^(s-2) * 10^0 | 2^(s-3) * 10^1 | ... | 2^0 * 10^(s-2) | 1 * 10^(s-1)
    if s == 0:
        return d * (2 ** (l - s))
    else:
        digits = [(2 ** (s - 2 - i)) * (10 ** i) for i in range(s - 1)] + [10 ** (s - 1)]
        return d * (2 ** (l - s)) * sum(digits)

ans = 0
for i in range(len(S)):
    ans += sum_of_digit(S[i], len(S), len(S) - i)
    
print(ans)

Submission status: Accepted

Solution code:
def dfs(x,s,ans,n):
    if x == len(S):
        ans.append(eval(s))
        return
    dfs(x+1,s,ans,n)
    s = s[:x+n]+'+'+s[x+n:]
    dfs(x+1,s,ans,n+1)

S = input()
ans = [] 
n = 0
dfs(1,S,ans,n)
print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import product
S = input()
i,L = 0,len(S)
ops = list(product(" +", repeat=L-1))

T = 0
for op in ops:
    W = ""
    for i in range(L-1):
        W += S[i]+op[i]
    W += S[L-1]
    T += eval(W.replace(" ",""))
print(T)

Submission status: Accepted

Solution code:
import itertools
s = input()
ans = 0

for op in itertools.product(["+", ""], repeat=len(s)-1):
  temp = ""
  for j in range(len(op)):
    temp += s[j]
    temp += op[j]
  temp += s[-1]
  ans += eval(temp)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

s = input()
if len(s) == 1:
    total = int(s)
else:
    bitlist = []
    # 文字列の長さ-1箇所にプラスを入れるかどうかbit演算によって考える
    for i in range(2 ** (len(s) - 1)):
        bitlist.append([int(x) for x in list(bin(i)[2::].zfill(len(s) - 1))])
    # print(bitlist)
    total = 0
    for bit in bitlist:
        befnum = int(s[0])
        # print(bit)
        for i, plus in enumerate(bit):
            if plus == 0:
                # プラスが入らない場合、前のケタの数を10倍して加える
                befnum = befnum * 10 + int(s[i + 1])
                # print(befnum)
            else:  # plus==1
                # プラスが入る場合、そこまでの数をtotalに加えてbefnumを初期化
                total += befnum
                befnum = int(s[i + 1])
                # print(befnum)
            if i == len(bit) - 1:
                total += befnum
            # print('total:' + str(total))
print(total)

Submission status: Accepted

Solution code:
T=list(input())
S=[int(i) for i in T]
N=len(S)-1
K=0
for i in range(2**N):
    t=str(bin(i))[2:]
    t="0"*(N-len(t))+str(t)
    t=t.replace("1","+").replace("0", " ")
    u=str(S[0])
    for i in range(N):
        u+=str(t[i])+str(S[i+1])
    u=u.replace(" ","")
    v=u.split("+")
    M=0
    for i in v:
        M+=int(i)
    K+=M
print(K)

Submission status: Accepted

Solution code:
S=input()
def culc(s,a):
  a.sort()
  res=int(s[:a[0]])
  for i in range(1,len(a)):
    x=int(s[a[i-1]:a[i]])
    res+=x
  res+=int(s[a[-1]:])
  return res

bits=2**(len(S)-1)
ans=int(S)
for i in range(1,bits):
  cnt=[]
  for j in range(len(S)-1):
    if (i>>j)&1:
      cnt.append(j+1)
  ans+=culc(S,cnt)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def s(d, k, i, c):
	if i == len(d): return c + int(k)
	return s(d, d[i], i + 1, int(k) + c) + s(d, k + d[i], i + 1, c)

d = [x for x in input()]
print(s(d, d[0], 1, 0))

Submission status: Accepted

Solution code:
from functools import reduce

def formulas(s):
    formula_list = []
    def aux(current, i):
        if i < len(s):
            aux(current + [s[i]], i + 1)
            aux(current + ['+', s[i]], i + 1)
        else:
            formula_list.append(''.join(current))                
    
    aux([s[0]], 1)
    return formula_list
        
    
if __name__ == '__main__':
    s = input()
    print(reduce(lambda x, y: x + eval(y), formulas(s), 0))

Submission status: Accepted

Solution code:
import itertools
s=input()
ans=0
for i in itertools.product(["","+"],repeat=len(s)-1):
    e=""
    j=0
    for k in s:
        e+=k
        if j<len(i):
            e+=i[j]
            j+=1
    ans+=eval(e)
print(ans)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
val = []
for i in range(2 ** (l-1)):
	div = [0]
	for j in range((l-1)):
		if (i >> j) & 1:
			div.append(j+1)
	v = 0
	for d in range(len(div)-1):
		v += int(s[div[d]:div[d+1]])
	v += int(s[div[-1]:])

	val.append(v)

print(sum(val))

Submission status: Accepted

Solution code:
import itertools

S = input()

ans = 0
for T in itertools.product(['', '+'], repeat=len(S) - 1):
    e = ''
    i = 0
    for s in S:
        e += s
        if i < len(T):
            e+=T[i]
            i+=1
    ans += eval(e)

print(ans)

Submission status: Accepted

Solution code:
import sys
s=input()
if(len(s)==1):
  print(s)
  sys.exit()
su=0
for i in range(2**(len(s)-1)):
  b=bin(i)[2:].zfill(len(s)-1)
  calcs=s[0]
  for j in range(len(b)):
    if(b[j]=="0"):calcs+=s[j+1]
    else:calcs+="+"+s[j+1]
  su+=eval(calcs)
print(su)

Submission status: Accepted

Solution code:
s = list(input())
ans = 0
for i in range(2**(len(s)-1)):
    
    a = list(format(i,'b').zfill(len(s)-1)+'0')
    b = []
    for j in range(len(s)):
        b.append(s[j])
        if a[j] == '1':
            b.append('+')
            
    ans += eval(''.join(b))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import product, zip_longest

S = input()
cmb = list(product(["", "+"], repeat=(len(S) - 1)))

formulas = []
for c in cmb:
    formulas.append("".join(x + y for x, y in zip_longest(S, c, fillvalue="")))

ans = 0
for f in formulas:
    ans += eval(f)
print(ans)

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    s = input()
    ans = 0
    for i in range(2 ** (len(s) - 1)):
        tmp = ""
        for j in range(len(s)):
            tmp += s[j]
            if(j < len(s) - 1):
                if (i >> j) & 1:
                    tmp += "+"
        else:
            #print("i =", i, " ", ans, "+", tmp, "=", end = "")
            ans += eval(tmp)
    else:
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    s = input()
    n = len(s)
    sum = 0
    for i in range((1<<(n-1))):
        prev = 0
        exp = ""
        for j in range(n-1):
            if (i>>j)&1:
                exp += s[prev:j+1]
                prev = j+1
                exp += "+"
        exp += s[prev:]
        sum += eval(exp)
    print(sum)
        

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s=list(input())
total=0
mask=0
n=len(s)
while mask<(1<<(n-1)):
    i=0
    s_i=s[:]
    while i<n-1:
        if mask&(1<<i):
            s_i[i]=s_i[i]+"+"
        i+=1
    total+=eval("".join(s_i))
    mask+=1
print(total)

Submission status: Accepted

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

    total = 0
    mask = 0
    n = len(S)
    while mask < (1<<(n-1)):
        i = 0
        s = S[:]
        while i < n-1:
            if mask & (1<<i):
                s[i] = s[i] + '+'
            i += 1
        total += eval(''.join(s))
        mask += 1

    print(total)

main()

Submission status: Accepted

Solution code:
s=input()
count=0
for i in range(2**(len(s)-1)):
    t=""
    for j in s:
        t+=j
        if i%2==1:
            t+="+"
        i//=2
    count+=eval(t)
print(count)

Submission status: Accepted

Solution code:
from itertools import combinations
s = input()
ans = 0
for i in range(len(s)):
    for ind in combinations(range(1, len(s)), i):
        c = 0
        st = s
        for j in ind:
            st = st[:j+c] + '+' +st[j+c:]
            c += 1
        ans += eval(st)
print(ans)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
a=[]
for i in range(1<<(n-1)):
 c=""
 for j in range(n-1):
   if i>>j & 1:
     b="+"
   else:
     b=""
   c+=s[j]+b
 c+=s[-1]
 a.append(c)
k=0
for i in a:
  for j in i.split("+"):
    k+=int(j)
print(k)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc045/tasks/arc061_a

"""
import sys
from sys import stdin
from itertools import combinations
input = stdin.readline


def prepare_eq(S, c):
    # c番目の数字の後に+を入れた数式を生成する (0起算)
    if len(c) == 0:
        return S

    eq = ''
    for i, s in enumerate(S):
        eq += s
        if i == c[0]:
            eq += '+'
            c = c[1:]
            if len(c) == 0:
                eq += S[i+1:]
                break
    return eq


def solve(S):
    total = 0
    for i in range(len(S)):
        for c in combinations(range(len(S)-1), i): # 0個〜文字列の長さ-1個までの+記号を追加して、数式を生成する
            eq = prepare_eq(S, c)
            total += eval(eq)   #  その数式の値を加算
    return total


def main(args):
    S = input().strip()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
def c_ManyFormulas(S):
    import itertools
    d = len(S)  # Sの桁数
    # 桁数-1個の演算子の列と解釈(1は'+',0は空文字)
    comb = itertools.product('01', repeat=d - 1)
    ans = 0
    for c in comb:
        c = ['+' if x == '1' else '' for x in c]
        tmp = ''  # 数字の間に演算子を入れた文字列(数式と解釈する)
        for i in range(d):
            if i == d - 1:
                # 末尾に演算子は付かない
                tmp += S[d - 1]
            else:
                tmp += S[i] + c[i]
        ans += eval(tmp)
    return ans

S = input().strip()
print(c_ManyFormulas(S))

Submission status: Accepted

Solution code:
s = input()
ret = 0
for i in range(2**(len(s)-1)):
    t = ""
    for j in s:
        t += j
        if i%2==1:
            t += "+"
        i //= 2
    ret += eval(t)
print(ret)

Submission status: Accepted

Solution code:
from itertools import combinations_with_replacement, permutations, zip_longest
S = input()
cmb = list(combinations_with_replacement(["", "+"], (len(S)-1)))
prm = set()
for c in cmb:
    for p in permutations(c):
        prm.add(p)

formulas = []
for p in prm:
    formulas.append("".join(x+y for x, y in zip_longest(S, p, fillvalue="")))

ans = 0
for f in formulas:
    ans += eval(f)
print(ans)

Submission status: Accepted

Solution code:
import itertools
S=raw_input()
#print S

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

pattern=[]
for i in range(1,len(S)):
	#print list(itertools.combinations(n,i))
	pattern+=list(itertools.combinations(n,i))

#print pattern

a=[]
a.append(S)
for i in pattern:
	prev=0
	n=len(i)
	for j in range(n):
		if j==0:
			if j==n-1:
				a.append(S[0:i[j]])
				a.append(S[i[j]:])
			else:
				a.append(S[0:i[j]])
				prev=i[j]
		elif j==n-1:
			a.append(S[prev:i[j]])
			a.append(S[i[j]:])
			break	
		else:
			a.append(S[prev:i[j]])
			prev=i[j]

print sum(int(i) for i in a)

Submission status: Accepted

Solution code:
def eval(d,mask):
    s = ''
    for i in xrange(len(mask)):
        s += d[i]
        if mask[i] == '1':
            s += '+'
    s += d[-1]
    l = s.split('+')
    res = sum(map(int,l))
    return res

d = list(raw_input())
tot = 0
for i in xrange(2**(len(d)-1)):
    mask = bin(2**(len(d)-1)+i)[3:]
    tot += eval(d,mask)
print tot

Submission status: Accepted

Solution code:
s = input()


def calc(formula):
    l = formula.split('+')
    ans = 0
    for n in l:
        ans += int(n)
    # print("ans: " + str(ans))
    return ans


def rec(s, cnt, l):
    # print(s)
    # print(cnt)
    # print(l)
    ret = 0
    if cnt < l:
        ret += rec(s, cnt+1, l)
        ret += rec(s[:cnt] + "+" + s[cnt:], cnt+2, l+1)
        return ret
    else:
        return calc(s)


print(rec(s, 1, len(s)))

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    S = input()
    ans = 0
    # 2 ^ nの組み合わせの全列挙
    n = len(S) - 1
    for b in range(2 ** n):
        p_list = [i for i in range(n) if b & 1 << i]
        x, s = [], S[:]
        for p in p_list[::-1]:
            a, s = s[p + 1:], s[:p + 1]
            x.append(a)
        if s:
            x.append(s)
        ans += eval("+".join(x))

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
S = input()
A = [0,1]
N = len(S)
pt = [list(i) for i in itertools.product(A,repeat=N-1)]
ans = 0
for p in pt:
	stack = ""
	for i in range(2*N-1):
		if i % 2 == 1:
			"""
			"+"を足し込むかどうか
			"""
			if i == 0:
				if p[0]: stack += "+"
			else:
				index = i // 2
				if p[index]: stack += "+"
		else:
			"""
			stackに普通に文字を入れていく
			"""
			index = i // 2
			stack+= S[index]
	ans += sum([int(x) for x in stack.split("+")])
print(ans)

Submission status: Accepted

Solution code:
S = list(map(int,list(input())))
N = len(S)

def func(a,n,l):
    if len(l) == 0:
        return a + n

    l2 = [i for i in l]
    m = l2.pop(0)

    return func(a,10*n+m,l2) + (func(a+n,m,l2))

n = S.pop(0)
print(func(0,n,S))

Submission status: Accepted

Solution code:
s = [int(x) for x in input()]

t = set()
def calc(p):
    total = 0
    tmp = 0
    for i in range(l):
        tmp = tmp * 10 + s[i]
        if p & (2**i):
            total += tmp
            tmp = 0
    return total + tmp

l = len(s)
total = 0
for i in range(2**(l-1)):
    total += calc(i)
print(total)

Submission status: Accepted

Solution code:
S = raw_input()

formulas = [S[0]]
for i in range(1,len(S)):
    f1 = formulas[:]
    f2 = formulas[:]
    f1 = map(lambda f: f + S[i], f1)
    f2 = map(lambda f: f + '+' + S[i], f2)
    formulas = f1 + f2

all_sum = 0
for formula in formulas:
    arr = map(int, formula.split('+'))
    all_sum += sum(arr)
print all_sum

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = map(int, raw_input())
l = len(s)
ret = 0
for p, n in enumerate(s):
    for d in range(l-p):
        ret += n * 10**d * 2**p * 2**max(l-2-p-d,0)
print ret

Submission status: Accepted

Solution code:
from itertools import product as prod

def main():
    s = input()
    n = len(s)
    sum = 0
    for sym in prod(["","+"],repeat=n-1):
        exp = ""
        for i,c in enumerate(s[:-1]):
            exp += ( c + sym[i] )
        exp += s[-1:]
        sum += eval(exp)
    print(sum)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    S = [int(i) for i in input()]
    N = len(S)
    sac = [0] + list(accumulate(S))
    ans = 0

    for i in range(N):
        ans += (int(sac[i] * 2**(i - 1)) + 2**i * S[i]) * 10**(N - 1 - i)

    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    S = input()
    N = len(S) - 1
    ans = 0

    for i in range(2**N):
        bi = bin(i)[2:].zfill(N)
        # print(bi)
        ans += calc(S, bi)

    print(ans)

def calc(S, bi):
    ret = 0
    k = 0

    for i in range(len(S)):
        if i == 0:
            continue
        else:
            if bi[i-1] == '1':
                ret += int(S[k:i])
                k = i

    ret += int(S[k:])

    return ret

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from itertools import product as prod

s = list(input())
n = len(s)

ans = 0
for sym in prod(["", "+"], repeat=n-1):
    form = []
    for i, c in enumerate(s[:-1]):
        form.append(c)
        form.append(sym[i])
    form.append(s[-1])
    ans += eval("".join(form))

print(ans)

Submission status: Accepted

Solution code:
from itertools import product
s = input()
ans = 0
op = ["", "+"]
for b in product(range(2), repeat = len(s) - 1):
    v = s[0]
    for j in range(1, len(s)):
        v += op[b[j - 1]] + s[j]
    ans += eval(v)

print(ans)

Submission status: Accepted

Solution code:
S = raw_input()
X = [str(S[0])]
NX = []
for s in S[1:]:
    for x in X:
        NX.append(x + s)
        NX.append(x + "+" + s)
    X = NX[:]
    NX = []
ret = 0
for x in X:
    ret += eval(x)
print ret

Submission status: Accepted

Solution code:
from collections import defaultdict


# all_split("abc") -> [['abc'], ['ab', 'c'], ['a', 'bc'], ['a', 'b', 'c']]
def all_split(s):
    if len(s) == 1:
        return [s]

    ans = []
    for i in range(2 ** (len(s) - 1)):
        b = list(map(int, format(i, "0" + str(len(s) - 1) + "b")))
        ans.append(split(s, b))
    return ans


def split(s, split_positions):
    assert len(s) - 1 == len(split_positions)

    ans = []
    pre = 0
    for i, is_split in enumerate(split_positions, start=1):
        if is_split:
            ans.append(s[pre:i])
            pre = i

    ans.append(s[pre:])
    return ans


def main():
    s = input()
    ans = 0
    for x in all_split(s):
        ans += eval("+".join(x))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict


def split_all(s: str):
    n = len(s)

    ans = []
    for k in range(2 ** (n - 1)):
        t = s
        tmp = []
        b = format(k, "b").zfill(n - 1)
        for i in range(n - 2, -1, -1):
            if b[i] == "1":
                x, y = t[:i + 1], t[i + 1:]
                tmp.append(y)
                t = x
        if t:
            tmp.append(t)
        ans.append(tmp[::-1])

    return ans


def main():
    s = input()
    ans = 0
    for x in split_all(s):
        ans += eval("+".join(x))
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input();print(sum(eval(''.join(x+y for x,y in zip(s, t))+s[-1])for t in __import__('itertools').product(['','+'],repeat=len(s)-1)))

Submission status: Accepted

Solution code:
import itertools
total = 0
s = input()
for t in itertools.product(['', '+'], repeat=len(s) - 1):
    total += eval(''.join(c1 + c2 for c1, c2 in zip(s, t)) + s[-1])
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

s = input()
n = [i for i in s]
ans = 0

# +の個数
for i in range(len(n)):
    for j in itertools.combinations(range(len(n)-1), i):
        temp = [i for i in s]
        for k in j[::-1]:
            temp.insert(k+1, "+")
        temp = "".join(temp)
        temp = temp.split("+")
        temp = map(int, temp)
        ans += sum(temp)

print(ans)

Submission status: Accepted

Solution code:
s = map(int, list(raw_input()))
sum = 0
for i in xrange(0, int(1 << len(s) - 1)):
    temp_num = 0
    for j in xrange(0, len(s)):
        cur_num = s[j]
        if i % 2 == 1:
            temp_num += cur_num
            if j != len(s) - 1:
                sum += temp_num
                temp_num = 0
        else:
            temp_num += cur_num
        i /= 2
        if j == len(s) - 1:
            sum += temp_num
            temp_num = 0
        temp_num *= 10
print sum


def sum(total, s):
    r = 0
    for i in range(len(s)):
        if i == 0:
            r = total + int(s)
        else:
            r += sum(total + int(s[:i]), s[i:])
    return r

Submission status: Accepted

Solution code:
from itertools import combinations

S=input()
Sl=len(S)

def cin(pt):
    r=[]
    s=0
    for i in pt:
        t=s,i
        r.append(t)
        s=i
    t=s,Sl
    r.append(t)
    return r

def calc(pt):
    r=0
    for s,e in cin(pt):
        r+=int(S[s:e])
    return r

pl=[i for i in range(1,Sl)]
ans=0
for pn in range(Sl):
    for pt in combinations(pl,pn):
        ans+=calc(pt)
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

def add_combination(S, cmb):
	new_S = ''
	
	for i in range(len(S)):
		new_S += S[i]
		if i in cmb:
			new_S += '+'
	
	return eval(new_S)
	
S = input()
sum_S = int(S)

for i in range(1, len(S)):
	for cmb in combinations(range(len(S)-1), i):
		sum_S += add_combination(S, cmb)

print(sum_S)

Submission status: Accepted

Solution code:
#abc045_c

def f(s,res):
 temp=0
 for i in xrange(len(s)):
  if i==0:
   temp=res+int(s)
  else:
   temp+=f(s[i:],res+int(s[:i]))
 return temp
 
print f(raw_input(),0)

Submission status: Accepted

Solution code:
S = raw_input()
n = len(S)
total = 0
for i in xrange(1 << (n - 1)):
    value = 0
    for j in xrange(n):
        value = value * 10 + int(S[j])
        if (1 << j) & i:
            total += value
            value = 0
    total += value
print total

Submission status: Accepted

Solution code:
# coding: utf-8

answer = 0


def calc(leftnum, sum, tempsum , is_insert):

    hitoketa = leftnum % 10
    leftnum = int(leftnum / 10)

    if tempsum == 0:
        tempsum = hitoketa
    else:
        tempsum = int(str(hitoketa) + str(tempsum))

    if is_insert:
        sum += tempsum
        tempsum = 0

    if leftnum == 0:
        if is_insert:
            global answer
            answer += sum
        return

    calc(leftnum, sum, tempsum, True)
    calc(leftnum, sum, tempsum, False)

if __name__ == '__main__':
    inp = int(input())
    calc(inp, 0, 0, True)
    calc(inp, 0, 0, False)
    print(answer)

Submission status: Accepted

Solution code:
#C
S = input()
sum = 0
for i in range(1, 2**(len(S)-1) ):
    pos = format(i, 'b').zfill(len(S)-1)
    start = 0
    for (j, x) in enumerate(pos):
        if x == str(1):
            sum = sum + int(S[start:j+1])
            start = j+1
    sum = sum + int(S[start:len(S)])
print(sum+int(S))

Submission status: Accepted

Solution code:
S = map(int, list(raw_input()))

val_list = [S[0]]
exp_list = []

for i in xrange(1, len(S)):
    new_val_list = []
    new_exp_list = []
    for val in val_list:
        new_val_list.append(val + S[i])
        new_exp_list.append([val, S[i]])
    for exp in exp_list:
        new_val_list.append(exp[0] + (exp[1] * 10 + S[i]))
        new_exp_list.append([exp[0], exp[1] * 10 + S[i]])
    new_val_list.append(int(''.join(map(str, S[:i+1]))))
    val_list = new_val_list
    exp_list = new_exp_list

print sum(val_list)

Submission status: Accepted

Solution code:
def sum(total, s):
    r = 0
    for i in range(len(s)):
        if i == 0:
            r = total + int(s)
        else:
            r += sum(total + int(s[:i]), s[i:])
    return r

s = raw_input()
total = 0

print sum(total, s)

Submission status: Accepted

Solution code:
g=lambda s:max(1,sum(g(s[i+1:])for i in range(len(s))));f=lambda s:sum(int(s[:i])*g(s[i:])+f(s[i:])for i in range(1,len(s)+1));print(f(input()))

Submission status: Accepted

Solution code:
s = input()

s_p = []

#print(len(s))

for i in range(len(s)):
    s_p += s[i]
    s_p += "+"
s_p = s_p[:-1]
# print(s_p)

s_p_list = []

def bit_list(i, n, bit_str):
    #print(bit_str)
    tmp = bit_str[:]
    if (i*2+1 == n):
        tmp = "".join(tmp)
        tmp = tmp.split('+')
        tmp = sum(list(map(int, tmp)))
        #print(i, i*2+1, tmp)

        s_p_list.append(tmp)
        return

    #print(i, i*2+1)
    tmp[i*2+1] = ''
    bit_list(i+1, n, tmp)

    tmp[i*2+1] = '+'
    bit_list(i+1, n, tmp)

#print(len(s_p), s_p)
bit_list(0, len(s_p), s_p)

print(sum(s_p_list))
#print(len(s_p_list))
# print(s)

Submission status: Accepted

Solution code:
import math
import itertools

num = input()
ans = num

keta = int(math.log10(num) + 1)
s = [i for i in range(keta - 1)]

number = []
while num > 0:
    number.append(num % 10)
    num = int(num / 10)
number.reverse()

combination = []
for i in range(1, keta):
    combination.extend(list(itertools.combinations(s, i)))

for i in combination:
    temp = 0
    for j in range(keta):
        if j not in i:
            temp = temp * 10 + number[j]
        else:
            ans += temp * 10 + number[j]
            temp = 0
    ans += temp

print ans

Submission status: Accepted

Solution code:

S = raw_input()
P = len(S)


dp = [[0]*11 for i in range(11)]
def foo(p,a):
    if dp[a][p]:
        return dp[a][p]
    if p == P:
        dp[a][p] = [int(S[a:P])]
        return dp[a][p]
    
    #dp[a][p] = foo(p+1,a) + foo(p+1,p) + [int(S[a:p+1])]
    if a == p:
        dp[a][p] = foo(p+1,a)
    else:
        num = int(S[a:p])
        dp[a][p] = foo(p+1,a) + map(lambda x:x+num,foo(p+1,p))
    return dp[a][p]
print sum(foo(0,0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

def calc(x, i):
    res = 0
    if i == N:
        j = 0
        for k in x:
            res += int(S[j:k])
            j = k
        return res
    for j in xrange(i + 1, N + 1):
        res += calc(x + [j], j)
    return res

S = raw_input()
N = len(S)
print calc([], 0)

Submission status: Accepted

Solution code:


# all_split("abc") -> [['abc'], ['ab', 'c'], ['a', 'bc'], ['a', 'b', 'c']]
def all_split(s):
    if len(s) == 1:
        return [s]
    
    ans = []
    for i in range(2 ** (len(s) - 1)):
        b = list(map(int, format(i, "0" + str(len(s) - 1) + "b")))
        ans.append(split(s, b))
    return ans


def split(s, split_positions):
    assert len(s) - 1 == len(split_positions)

    ans = []
    pre = 0
    for i, is_split in enumerate(split_positions, start=1):
        if is_split:
            ans.append(s[pre:i])
            pre = i

    ans.append(s[pre:])
    return ans


def main():
    s = input()
    ans = 0
    for a in all_split(s):
        ans += eval("+".join(a))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
class NumExpression:
    def __init__(self, input_value, rank):
        self.raw_value = input_value
        self.rank = rank

    @property
    def value(self):
        list = self.expression.split("+")
        sum = 0
        for num in list:
            sum += int(num)
        return sum

    @property
    def expression(self):
        #print("rank = {0}".format(self.rank))
        points = self.gen_points(self.rank, len(self.raw_value) - 1)
        #print("gen_points = {0}".format(points))
        expression = self.insert_plus(points)
        #print("expression = {0}".format(expression))
        return expression

    def gen_points(self, num, width):
        """
        num → 2進数に変換してリストで返す
        """
        points = [0] * width
        temp = num
        i = 1
        while True:
            p = temp % 2 
            if p == 1:
                points[width - i] = 1
            temp = temp >> 1
            if temp == 0:
                break
            i += 1

        return points

    def insert_plus(self, points):
        """
        point位置に"+"を挿入する
        """
        i = 0 #points[0]
        new_value = self.raw_value[0:i]
        for point in points:
            new_value += self.raw_value[i:i+1]
            if point == 1:
                new_value += "+"
            i += 1

        new_value += self.raw_value[i:]
        return new_value

class Calculator:
    def __init__(self, input_value):
        self.input_value = input_value
        self.expressions = self.make_expressions()

    def len(self):
        return len(self.input_value)

    def make_expressions(self):
        expressions = []
        for i in range(0, pow(2, self.len()-1)):
            expression = NumExpression(self.input_value, i)
            expressions.append(expression)
        return expressions

    def compute_sum(self):
        sum = 0
        for expression in self.expressions:
            sum += expression.value

        return sum

if __name__ == "__main__":
    num = input()
    c = Calculator(num)
    print(c.compute_sum())

Submission status: Accepted

Solution code:
import sys
from itertools import combinations

def add_combination(S, cmb):
    new_S = ""

    for i in range(len(S)):
        new_S += S[i]
        if i in cmb:
            new_S += "+"

    return eval(new_S)


S = input()
sum_S = int(S)

for i in range(1, len(S)):
    for cmb in combinations(range(len(S) - 1), i):
        sum_S += add_combination(S, cmb)

print(sum_S)