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:
import math

def func(n_str, ptr):
#    print(n_str)
    if len(n_str)==ptr:
        return int(eval(n_str))
    return func(n_str, ptr+1) + func(n_str[:ptr]+"+"+n_str[ptr:], ptr+2)
s = input()    
print(func(s, 1))

Submission status: Accepted

Solution code:
def SumIndicatedPoint(pcandid):
	point = list(str(pcandid))
	conNum = nums[0]
	count = 1
	sum = 0
	for p in point:
		if p == '0':
			conNum = conNum + nums[count]
		elif p == '1':
			sum = sum + int(conNum)
			conNum = nums[count]
		count = count + 1
	sum = sum + int(conNum)
	#print(str(sum))	
	return sum
	
if __name__ == '__main__':	
	nums = list(input())
	#nums.reverse()
	ALLSUM = 0
	pcandidstr = '0' + str(len(nums) - 1) + 'b'
	pcandid = 0
	if len(nums) > 1:
		maxcandid = int('1' * (len(nums) - 1),2)
		#add = format(1,pcandidstr)
		while pcandid <= maxcandid:
			ALLSUM = ALLSUM + SumIndicatedPoint(format(pcandid,pcandidstr))
			pcandid = pcandid + 1
	elif len(nums) == 1:
		ALLSUM = int(nums[0])
	print(str(ALLSUM))

Submission status: Accepted

Solution code:
s = input()
res = 0

for mask in range(1 << len(s) - 1):
    cur = 0
    for i in range(len(s)):
        cur *= 10
        cur += int(s[i])
        if mask & (1 << i):
            res += cur
            cur = 0
    res += cur

print(res)

Submission status: Accepted

Solution code:
import itertools


def sum_split_num(num, idxs):
    idxs.insert(0, 0)
    idxs.append(len(num))
    return sum(int(num[idxs[i]:idxs[i+1]]) for i in range(len(idxs)-1))


S = input()
ans = int(S)
all_idxs = list(range(1, len(S)))
for i in range(1, len(S)):
    for idxs in itertools.combinations(all_idxs, i):
        ans += sum_split_num(S, list(idxs))
print(ans)

Submission status: Accepted

Solution code:
s=str(input())
n=len(s)-1
sum_s=0
for i in range(2**n):
    k_str=format(i,'b').zfill(n)

    ans=''

    for i in range(n):
        ans += s[i]
        if k_str[i]=='0':
            ans= ans + ''
        else:
            ans= ans +','

    ans=ans+s[-1]
    sum_s += sum(list(map(int,ans.split(','))))

print(sum_s)

Submission status: Accepted

Solution code:
import itertools

S = raw_input()

n = len(S)-1
retu = range(n)
ans = 0
for r in range(n+1):
    for c in itertools.combinations(retu, r):
        if not c:
            ans += int(S)
        else:
            ans += int(S[0:c[0]+1])
            for i in range(r-1):
                ans += int(S[c[i]+1:c[i+1]+1])
            ans += int(S[c[r-1]+1:])

print ans

Submission status: Accepted

Solution code:
import itertools
S = raw_input()
ans = 0
for p in itertools.product([True, False], repeat=len(S)-1):
  t = ''
  for i in xrange(len(S)):
    t += S[i]
    if i != len(S)-1 and p[i]:
      t += '+'
  ans += eval(t)

print ans

Submission status: Accepted

Solution code:
s = str(input())
b = 2**(len(s)-1)-1
suma = 0

for i in range(0,(2**(len(s)-1)-1)+1):
    ans = list(str(s))
    binlist = list(str(format(b,'0' + str(len(s)-1) + 'b')))
    a = 0
    for i in range(0,len(binlist)):
        if binlist[i] == '1':
            ans.insert((i+1)+a,"+")
            a+=1

    b-=1
    suma += eval(''.join(ans))

print(suma)

Submission status: Accepted

Solution code:
(lambda nums: (lambda index, itertools=__import__("itertools"): print(sum([eval("".join((lambda t: [[t.insert(j, "+") for j in reversed(i)], t][1])(list(nums)))) for i in itertools.chain(*[itertools.combinations(index, x) for x in range(len(index) + 1)])])))(range(1, len(nums))))(input())

Submission status: Accepted

Solution code:
orig_a = input().strip()
total = 0
l = len(orig_a)

for i in range(2 ** (l - 1)):
    a = orig_a[:]
    for j in range(l - 1):
        if (i >> j) % 2:
            a = a[:l-j-1] + "+" + a[l-j-1:]
    total += eval(a)
print(total)

Submission status: Accepted

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

s = raw_input()
print sum_loop(0, s)

Submission status: Accepted

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

def add_roop(pre_result, pro_s):
    result = 0

    for i in range(len(pro_s)):
        if i == 0 :
            result = pre_result + int(pro_s)
        else:
            result =  result + add_roop(pre_result + int(pro_s[:i]), pro_s[i:])

    return result

if __name__ == "__main__":
    #
    s = raw_input()
    print add_roop(0, s)

Submission status: Accepted

Solution code:
S = input()


def f(s):
    if len(s)==1:
        return [s]
    def add(st,ls):
        return [st+s for s in ls]
    return add(s[0],f(s[1:])) +add(s[0]+'+',f(s[1:]))

#print(f(S))
print(sum(map(eval,f(S))))

Submission status: Accepted

Solution code:
#coding:utf-8
import math

data = raw_input()
len_data = len(data)
split_point = []
range_max = 2**(len_data-1)
for i in xrange(range_max):
	split_point.append(format(i,"0"+str(int(math.log(range_max,2)))+"b"))
# for spoint in split_point:
#     for i in xrange(len(spoint)):
#         if spoint[i] == "1":
#             split_end = i+1
#             result.append(data[split_start:split_end])
#             split_start = split_end
#     for i in result:
#         tmp = tmp + int(i)
#     sum = sum + tmp
#     split_start = 0
#     result = []
#     tmp = 0
# print sum
result = 0
bias = 0
for bit_str in split_point:
	origin = data
	for i in xrange(len(bit_str)):
		if bit_str[i] == "1":
			origin = origin[:i+1+bias] + "+" + origin[i+1+bias:]
			bias = bias+1
	result = result + eval(origin)
	bias = 0
print result

Submission status: Accepted

Solution code:
import sys

s = list(raw_input())
if len(s) == 1:
	print str(int(''.join(s)))
	sys.exit()

sequence = [x for x in range(2**( len(s) -1 ))]

total = 0
def get_binary(seq):
	r = ''
	while seq > 0:
		r = r + str(seq % 2)
		seq = seq / 2
	if (len(list(r)) < (len(s) - 1)):
		for _ in range(len(s) - 1 - len(list(r))):
			r = r + '0'
	return list(r)

for seq in sequence:
	subtotal = 0
	index = 1
	num = s[0]
	b = get_binary(seq)
	for x in b:
		if x == '0':
			num = num + s[index]
		else:
			subtotal = subtotal + int(num)
			num = s[index]
		index = index + 1
	total = total + subtotal + int(num)

print str(total)

Submission status: Accepted

Solution code:
import itertools

s = input()

sum = 0

for bs in itertools.product([0, 1], repeat = len(s) - 1):
    ps = list(itertools.compress(range(1, len(s)), bs))
    ls = [0] + ps
    rs = ps + [len(s)]
    for l, r in zip(ls, rs):
        sum += int(s[l:r])

print(sum)

Submission status: Accepted

Solution code:
S = input()
Slist = list(S)
def cut(l, i): #iは重複して追加される部分つまり1+25と1+2+5の1に当たる
    n = len(l)
    if n == 1:
        return int(l[0])+i #一桁になったらそれ以上分割しない
    if n == 0:
        return 0
    else: #そのままでは返せない
        sum = int(''.join(l))+i #全く分割しないパターン
        for jj in range(n-1):
            #sum = 0
            j=jj+1 #1~n-1
            #sum += cut(l[j:n], int(''.join(l[0:j]))) + i
            sum += cut(l[j:n], int(''.join(l[0:j]))+i)
            #print("nowsum:"+str(k)+" (i):"+str(i)+ "(j):"+str(j)+" (sum):"+str(sum))
        return int(sum)
        
print(cut(Slist, 0))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def solve(s):
    n = len(s)
    base = list("+".join(s))
    ans = 0
    for t in range(1 << (n - 1)):
        xs = base[:]
        for i in range(n - 1):
            if t & (1 << i) > 0:
                xs[2 * i + 1] = ""
        eq = "".join(xs)
        ans += eval(eq)
    return ans


def main():
    print(solve(input()))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def rec(S, i):
    if len(S) < i+1:
        return [S]
    # add + dont add
    return rec(S[:i] + "+" + S[i:], i+2) + rec(S, i+1) + [S[:i] + "+" + S[i:], S]


S = raw_input()
print sum([eval(s) for s in list(set(rec(S, 1)))])

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    S = input()
    N = len(S)
    result = 0
    for bit in range(1 << (N - 1)):
        tmp = ""
        for x in range(N - 1):
            tmp += S[x]
            if ((bit >> x) & 1):
                tmp += '+'
        tmp += S[-1]
        result += eval(tmp)
    print (result)

Submission status: Accepted

Solution code:
import ast

def pattern(li, el, space, acc, xs):
  if len(li) != 1:
    acc.append(el)
    acc.append(space)
    al = li.pop(0)
    pattern(list(li), al, '+', list(acc), xs)
    pattern(list(li), al, '', list(acc), xs)
  else:
    acc.append(el)
    acc.append(space)
    al = li.pop(0)
    acc.append(al)
    xs.append(ast.literal_eval(''.join(acc)))

li = list(input())
el = li.pop(0)
xs = []

if len(li) != 0:
  pattern(list(li), el, '+', [], xs)
  pattern(list(li), el, '', [], xs)

if len(li) != 0:
  print(sum(xs))
else:
  print(int(el))

Submission status: Accepted

Solution code:
class ManyFormulas:
	def getSum(self,string):
		length = len(string)
		ans = 0
		t = 0
		while t<1<<(length-1):
			num = int(string[0]) - int("0")
			for i in range(length-1):
				if t & (1<<i):
					ans += num
					num = 0
				num = num * 10 + int(string[i+1]) - int("0")
			ans += num
			t += 1
		print ans

if __name__ == "__main__":
	string = raw_input()
	m = ManyFormulas()
	m.getSum(string)

Submission status: Accepted

Solution code:
memo = set([])
def f(a):
    global ans
    ans += eval('+'.join(a))
    n = len(a)
    for i in range(n-1):
        b = a[:i] + [a[i]+a[i+1]] + (a[i+2:] if i != n-2 else [])
        s = '+'.join(b)
        if not s in memo:
            memo.add(s)
            f(b)
l = list(input())
ans = 0
f(l)
print(ans)

Submission status: Accepted

Solution code:
s = list(input())
ans=0
for i in range(2**(len(s)-1)):
    ops=[]
    d=i
    for j in range(len(s)-1):
        if d%2==1:
            ops.append('+')
        else:
            ops.append('')
        d//=2
    form=[]
    for i in range(len(ops)):
        form.append(s[i])
        form.append(ops[i])
    form.append(s[-1])
    #print(form)
    ans+=eval(''.join(form))
print(ans)

Submission status: Accepted

Solution code:
S = list(input())

totals = [[]] * len(S)
def rec(S, num, totals):
    totals[num] = [int(''.join(S[:num+1]))]
    for idx in range(num):
        for item in totals[idx]:
            totals[num].append( item + int(''.join(S[idx+1:num+1])) )
    return totals

sl = len(S)
num = 1
totals[0].append( int(S[0]) )
while num < sl:
    totals = rec(S, num, totals)
    num += 1

print( sum(totals[-1]) )

Submission status: Accepted

Solution code:
import itertools

def split(xs, t):
    total = 0
    tmp = []
    for i, x in enumerate(xs):
        if i in t:
            total += int(''.join(tmp))
            tmp = [x]
        else:
            tmp.append(x)
    if tmp:
        total += int(''.join(tmp))
    return total


def main():
    nums = list(input())
    length = len(nums)
    total = 0
    for i in range(length):
        for t in itertools.combinations(range(1, length), i):
            total += split(nums, t)
    print(total)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
memo = set([])
def f(a):
    global ans
    ans += eval('+'.join(a))
    if len(a) < 3 : return
    for i in range(len(a)-1):
        b = a[:i] + [a[i]+a[i+1]]
        if i != len(a)-2 : b += a[-(len(a)-2-i):]
        c = '+'.join(b)
        if not c in memo:
            memo.add(c)
            f(b)
s = input()
l = list(s)
ans = int(s)
if len(l)>1:
    f(l)
print(ans)

Submission status: Accepted

Solution code:
import itertools

def spl(s, t):
    lst = list(s)
    for x in reversed(t):
        lst.insert(x, '+')
    return eval(''.join(lst))


def main():
    nums = input()
    length = len(nums)
    total = 0
    for i in range(length):
        for ts in itertools.combinations(range(1, length), i):
            total += spl(nums, ts)
    print(total)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import combinations
import copy

def add_combo(c, len_S, len_combo, S):
    S_copy = copy.deepcopy(S)
    total_len = len_S + len_combo
    combo_total = 0
    cnt = 1
    for i in c:
        S_copy.insert(i+cnt, '+')
        cnt += 1
    last = 0
    nums = []
    plus_count = 0
    for j in range(0, total_len):
        if S_copy[j] == '+':
            nums.append(S_copy[last:j])
            plus_count += 1
            if plus_count == len_combo:
                nums.append(S_copy[j+1:])
            last = j+1
    for n in nums:
        combo_total += int("".join(n))
    return combo_total


if __name__ == '__main__':
    S = list(input())
    no_plus = int("".join(S))
    len = len(S)
    all_plus = 0
    total = 0
    for x in S:
        all_plus += int(x)
    for i in range(1, len):
        combo = combinations(range(0, len-1), i)
        for c in combo:
            total += add_combo(c, len, i, S)
            # print(c)
    total += no_plus
    # total += all_plus
    print(total)

Submission status: Accepted

Solution code:

def combi(n):
  cmb = []
  end = 2 ** n
  for i in range(end):
    b = list(bin(i).replace('0b', ''))
    b = '0' * n + ''.join(b)
    b = b[-n:]
    cmb.append(list(b))
  return cmb


str = input()

n = len(str) - 1
cmb = combi(n)
sentences = []
for c in cmb:
  s = str
  for i in range(n - 1, -1, -1):
    if c[i] == '1':
      i += 1
      s = s[:i] + '+' + s[i:]
  sentences.append(s)

sum = 0
for sentence in sentences:
  nums = sentence.split('+')
  for num in nums:
    sum += int(num)
    
print(sum)

Submission status: Accepted

Solution code:
import math as m
import time
import itertools 
from Queue import Queue

def list_to_int(numList):         # [1,2,3]
    s = map(str, numList)   # ['1','2','3']
    s = ''.join(s)          # '123'
    s = int(s)              # 123
    return s

class Program:
    
    def main(self):
        S = map(int,list(raw_input()))
        l = len(S)
        all_v = 0
        for i in itertools.product([0,1],repeat=l-1):
            i = list(i)
            #https://teratail.com/questions/26730
            indexes = [i+1 for i, x in enumerate(i) if x == 1] 
            indexes.reverse()
            s = list(S)
            v = 0
            for index in indexes:
                v += list_to_int(s[index:])
                s = s[:index]
            v += list_to_int(s)
            all_v += v
        print all_v

if __name__ == '__main__':
    p=Program();
    p.main()

Submission status: Accepted

Solution code:
S = raw_input()

val = int(S)

if len(S) >= 2:
    for sep in xrange(1, len(S)):
        val += int(S[:sep]) + int(S[sep:])

if len(S) >= 3:
    for sep1 in xrange(1, len(S)-1):
        for sep2 in xrange(sep1 + 1, len(S)):
            val += int(S[:sep1]) + int(S[sep1:sep2]) + int(S[sep2:])

if len(S) >= 4:
    for sep1 in xrange(1, len(S)-2):
        for sep2 in xrange(sep1 + 1, len(S)-1):
            for sep3 in xrange(sep2 + 1, len(S)):
                val += int(S[:sep1]) + int(S[sep1:sep2]) + int(S[sep2:sep3]) + int(S[sep3:])

if len(S) >= 5:
    for sep1 in xrange(1, len(S)-3):
        for sep2 in xrange(sep1 + 1, len(S)-2):
            for sep3 in xrange(sep2 + 1, len(S)-1):
                for sep4 in xrange(sep3 + 1, len(S)):
                    val += int(S[:sep1]) + int(S[sep1:sep2]) + int(S[sep2:sep3]) + int(S[sep3:sep4]) + int(S[sep4:])

if len(S) >= 6:
    for sep1 in xrange(1, len(S)-4):
        for sep2 in xrange(sep1 + 1, len(S)-3):
            for sep3 in xrange(sep2 + 1, len(S)-2):
                for sep4 in xrange(sep3 + 1, len(S)-1):
                    for sep5 in xrange(sep4 + 1, len(S)):
                        val += int(S[:sep1]) + int(S[sep1:sep2]) + int(S[sep2:sep3]) + int(S[sep3:sep4]) + int(S[sep4:sep5]) + int(S[sep5:])

if len(S) >= 7:
    for sep1 in xrange(1, len(S)-5):
        for sep2 in xrange(sep1 + 1, len(S)-4):
            for sep3 in xrange(sep2 + 1, len(S)-3):
                for sep4 in xrange(sep3 + 1, len(S)-2):
                    for sep5 in xrange(sep4 + 1, len(S)-1):
                        for sep6 in xrange(sep5 + 1, len(S)):
                            val += int(S[:sep1]) + int(S[sep1:sep2]) + int(S[sep2:sep3]) + int(S[sep3:sep4]) + int(S[sep4:sep5]) + int(S[sep5:sep6]) + int(S[sep6:])

if len(S) >= 8:
    for sep1 in xrange(1, len(S)-6):
        for sep2 in xrange(sep1 + 1, len(S)-5):
            for sep3 in xrange(sep2 + 1, len(S)-4):
                for sep4 in xrange(sep3 + 1, len(S)-3):
                    for sep5 in xrange(sep4 + 1, len(S)-2):
                        for sep6 in xrange(sep5 + 1, len(S)-1):
                            for sep7 in xrange(sep6 + 1, len(S)):
                                val += int(S[:sep1]) + int(S[sep1:sep2]) + int(S[sep2:sep3]) + int(S[sep3:sep4]) + int(S[sep4:sep5]) + int(S[sep5:sep6]) + int(S[sep6:sep7]) + int(S[sep7:])

if len(S) >= 9:
    for sep1 in xrange(1, len(S)-7):
        for sep2 in xrange(sep1 + 1, len(S)-6):
            for sep3 in xrange(sep2 + 1, len(S)-5):
                for sep4 in xrange(sep3 + 1, len(S)-4):
                    for sep5 in xrange(sep4 + 1, len(S)-3):
                        for sep6 in xrange(sep5 + 1, len(S)-2):
                            for sep7 in xrange(sep6 + 1, len(S)-1):
                                for sep8 in xrange(sep7 + 1, len(S)):
                                    val += int(S[:sep1]) + int(S[sep1:sep2]) + int(S[sep2:sep3]) + int(S[sep3:sep4]) + int(S[sep4:sep5]) + int(S[sep5:sep6]) + int(S[sep6:sep7]) + int(S[sep7:sep8]) + int(S[sep8:])

if len(S) >= 10:
    for sep1 in xrange(1, len(S)-8):
        for sep2 in xrange(sep1 + 1, len(S)-7):
            for sep3 in xrange(sep2 + 1, len(S)-6):
                for sep4 in xrange(sep3 + 1, len(S)-5):
                    for sep5 in xrange(sep4 + 1, len(S)-4):
                        for sep6 in xrange(sep5 + 1, len(S)-3):
                            for sep7 in xrange(sep6 + 1, len(S)-2):
                                for sep8 in xrange(sep7 + 1, len(S)-1):
                                    for sep9 in xrange(sep8 + 1, len(S)):
                                        val += int(S[:sep1]) + int(S[sep1:sep2]) + int(S[sep2:sep3]) + int(S[sep3:sep4]) + int(S[sep4:sep5]) + int(S[sep5:sep6]) + int(S[sep6:sep7]) + int(S[sep7:sep8]) + int(S[sep8:sep9]) + int(S[sep9:])

print val

Submission status: Accepted

Solution code:
from sys import stdin
a = stdin.readline().strip()
ans = 0
n = len(a)
plus = n-1
b = [a[0]]
for i in xrange(1,n):
    b.append('')
    b.append(a[i])
    
total = 1<<plus
#print b,total
for i in xrange(total):
    x = ''
    c = list(b)
    #print "mask",i,c
    for j in xrange(n-1):
        if i & (1<<j):
            c[2*j+1] = '+'
    #print c            
    #print ''.join(c)
    ans += eval(''.join(c))
print ans

Submission status: Accepted

Solution code:
a = list(reversed([int(_) for _ in input()]))
n = len(a)
ans = 0
tmp = 1
for i in range(0, n):
    tmp = 1 << (n - i - 1)
    for j in range(0, i + 1):
        ans += (10 ** j) * a[i] * tmp * (1 << max(0, (i - 1 - j)))
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

class unique_element:
    def __init__(self,value,occurrences):
        self.value = value
        self.occurrences = occurrences

def perm_unique(elements):
    eset=set(elements)
    listunique = [unique_element(i,elements.count(i)) for i in eset]
    u=len(elements)
    return perm_unique_helper(listunique,[0]*u,u-1)

def perm_unique_helper(listunique,result_list,d):
    if d < 0:
        yield tuple(result_list)
    else:
        for i in listunique:
            if i.occurrences > 0:
                result_list[d]=i.value
                i.occurrences-=1
                for g in  perm_unique_helper(listunique,result_list,d-1):
                    yield g
                i.occurrences+=1


def partitioned(n):
    table = defaultdict(list)
    table[1] = [[1]]

    for i in range(2, n + 1):
        table[i].append([i])
        a, b = i - 1, 1
        while a >= b:
            l = [a, b]
            table[i].append(l)
            for k in table[a][1:]:
                if k[-1] >= b:
                    l = k + [b]
                    table[i].append(l)
            a, b = a - 1, b + 1
        else:
            table[i].sort(reverse=True)

    return [tuple(x) for x in table[n]]


a = list(raw_input())
total = 0

for leng in partitioned(len(a)):
    for p in perm_unique(leng):
        i = 0
        for ind in p:
            total+= int(''.join(a[i:i+ind]))
            i+=ind
print total

Submission status: Accepted

Solution code:
import itertools
import functools

s = input()
nums = list(s)

add_table = list(itertools.product((1, 0), repeat=len(nums)-1))

sum = 0

for row in add_table:
    case = []
    for i, v in enumerate(nums):
        if i == 0 or row[i - 1] == 1:
            case.append(v)
        else:
            case[-1] += v

    sum += int(functools.reduce(lambda x, y: int(x) + int(y), case))

print(sum)

Submission status: Accepted

Solution code:
def solve(S, ops):
    global res
    if len(ops) < (len(S) - 1):
        a = ops[:]
        b = ops[:]
        a.append(0)
        b.append(1)
        solve(S, a)
        solve(S, b)
    else:
        tmp = ""
        tmp += str(S[0])
        for n, op in enumerate(ops):
            if op == 0:
                tmp += str(S[n+1])
            else:
                res += int(tmp)
                tmp = str(S[n+1])
        res += int(tmp)

S = raw_input()
S = [int(x) for x in S]
res = 0
ops = []
solve(S, ops)
print res

Submission status: Accepted

Solution code:
# coding: utf-8

S = input()
cnt = 0
ls = []
for i in range(2**(len(S)-1)):
    #print(str(bin(i))[2:].zfill(len(S)-1))
    bi = list(str(bin(i))[2:].zfill(len(S)-1))
    ls.append(bi)

for item in ls:
    s = S[0]
    for inx, bi in enumerate(item):
        if bi == "0":
            pass
        else:
            s = s+"+"
        if len(S) != 1:
            s = s + S[inx+1]
        else:
            s = S
    cnt += sum(map(int, s.split("+")))
print(cnt)

Submission status: Accepted

Solution code:
S = input()
T = [letter for letter in S]
que = [T]
a = 0
while que:
	T1 = que[0]
	if len(T1) > 1:
		a += int(T1[0])*2**(len(T1) - 2)
		t2 = T1[:]
		t2[1] = t2[0] + t2[1]
		t2 = t2[1:]
		que.append(t2)
		t1 = T1[1:]
		que.append(t1)
	else:
		a += int(T1[0])
	que = que[1:]
print(a)

Submission status: Accepted

Solution code:
from itertools import combinations, chain

def eval_str(string):
    s = string.split("+")
    return int(reduce(lambda x,y: int(x)+int(y), s))

mystr = raw_input()
allsubsets = lambda n: list(chain(*[combinations(range(1,n), ni) for ni in range(n+1)]))
l = allsubsets(len(mystr))
#for i in xrange(len(l)):
#    l[i] = list(l[i])
mylist = []
#print l
for x in l:
    s = ""
    prev = 0
    for y in x:
        s += mystr[prev:int(y)]
        s += "+"
        prev = int(y)
    s += mystr[prev:]
    mylist.append(s)
#print mylist
tot = 0
for x in mylist:
    tot += eval_str(x)
print tot

Submission status: Accepted

Solution code:
S = [int(c) for c in input()]
ans = 0

for i in range(1 << (len(S) - 1)):
    c, s = 0, 0
    for c2, d in enumerate(S):
        if (i << 1) & (1 << c2):
            s += c
            c = 0
        c = 10 * c + d
    s += c
    ans += s

print(ans)

Submission status: Accepted

Solution code:
s=raw_input()
t=len(s)-1
tmp=2**t
ans=0
for i in range(tmp):
    p=bin(i)[2:]
    p='0'*(t-len(p))+p
    x=''
    for j,k in enumerate(s):
        x+=k
        if j!=t and p[j]=='1':
            x+='+'
    ans+=eval(x)
print ans

Submission status: Accepted

Solution code:
def solve():
    n = input()
    ans = 0
    for i in range(2 ** (len(n) - 1)):
        insertcount = 0
        count = 0
        line = list(n)
        j = i
        while j > 0:
            if j & 1 == 1:
                line.insert(1 + count + insertcount, "+")
                insertcount += 1
            count += 1
            j >>= 1
        ans += eval("".join(line))
    print(ans)

if __name__=="__main__":
    solve()

Submission status: Accepted

Solution code:
S = raw_input()

ans = 0
for i in range(2**(len(S)-1)):
    b = bin(i)[2:]
    while len(b) < len(S)-1:
        b = "0"+b
    
    cal = S[0]
    for v, w in zip(S[1:], b):
        if w == "1":
            cal += "+"
        cal += v
    
    ans += eval(cal)
    
print ans

Submission status: Accepted

Solution code:
s = input()
n = int(s)
r = 0

for bit in range(2**(len(s)-1)):
    e = s[0]
    for i in range(len(s)-1):
        if ((bit>>i)&1) == 1:
            e += '+'
        e += s[i+1]
    r += sum(map(int, e.split('+')))
print(r)

Submission status: Accepted

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

ans = 0
for i in xrange(N):
    for keta in xrange(1, N-i+1):
        if keta == N:
            ans += int(S)
        elif i == 0 or i+keta==N:
            ans += int(S[i:i+keta]) * 2**(N-keta-1)
        else:
            ans += int(S[i:i+keta]) * 2**(N-keta-2)
print ans

Submission status: Accepted

Solution code:
def solve(s):
	if len(s) == 0:
		return 0, 1
	l = len(s)
	ans = 0
	cnt = 0
	for i in range(1, l+1):
		left = s[:i]
		right = s[i:]
		a, b = solve(right)
		ans += int(left) * b + a
		cnt += b
	return ans, cnt

s = input().strip()
ans, _ = solve(s)
print(ans)

Submission status: Accepted

Solution code:
def rek(erg, rest):
    if not rest:
        return erg

    p = []

    for i in erg:
        p.append(i+"+"+rest[0])
        p.append(i+rest[0])

    return rek(p, rest[1:])


a = input()

erg = 0
comb = rek([a[0]], a[1:])

for i in comb:
    erg += eval(i)

print(erg)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
import sys
import itertools


a, b, c, d = list(input())

lst = ['-', '+']
for i, j, k in itertools.product(range(2), range(2), range(2)):
    ans = int(a)
    if i:
        ans += int(b)
    else:
        ans -= int(b)
    if j:
        ans += int(c)
    else:
        ans -= int(c)
    if k:
        ans += int(d)
    else:
        ans -= int(d)
        
    if ans == 7:
        print(a,lst[i],b,lst[j],c,lst[k],d,'=7',sep='')
        sys.exit()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = str(int(input()))
total = 0
l = len(N)-1

for i in range(2**l):
    b = format(i, '0'+str(l)+'b')
    subtotal = 0
    s = N[0]

    for j in range(len(b)):
        if int(b[j]):
            subtotal += int(s)
            s = N[j+1]
        else:
            s += N[j+1]

    subtotal += int(s)
    total += subtotal

print(total)

Submission status: Runtime Error

Solution code:
def dfs(i,f):
    if i == n-1:
        return sum(list(map(int,input().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: Runtime Error

Solution code:
# https://atcoder.jp/contests/abc045/tasks/arc061_a

s = input()

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

Submission status: Runtime Error

Solution code:
def dfs(i, f):
    if i == n:
        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: Runtime Error

Solution code:
import sys
S = sys.stdin.readline()
number = [i for i in S]
N = len(number)

ans = 0
for bit in range(1<<(N-1)):
    f = str(number[0])
    for i in range(N-1):
        if (bit&(1<<i)):
            f = f+'+'+str(number[i+1])
        else:
            f = f+str(number[i+1])
    ans = ans + eval(f)

print(ans)

Submission status: Runtime Error

Solution code:
S =input()
ans_list = []
for i in range(2**(len(S)-1)):
    comb = bin(i)[2:].zfill(len(S)-1)
    num_list = []
    num = S[0]
    for i in range(len(comb)):
        if comb[i] == "1":
            num_list.append(int(num))
            num = S[i+1]
        else:
            num += S[i+1]
    num_list.append(int(num))
    ans_list.append(sum(num_list))
print(sum(ans_list))

Submission status: Runtime Error

Solution code:
S=input()
N=len(S)
ans=0
for i in range(2**(N-1)):
  S=S[0]
  q="{:0>10b}".format(i)[::-1]
  for j in range(1,N):
    if int(q[j-1])&1:
      F+="+"
    F+=S[j]
  ans+=eval(F)    
print(ans)

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    S_arr = _in[0]  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    N = len(S_arr)-1
    cnt = 0
    for bit in range(1<<N):
        # bit = 0: '', 1: '+'
        tmp = []
        pointa = 0
        for i in range(N):
            if bit&(1<<i):
                tmp.append(int(S_arr[pointa:i+1]))
                pointa = i+1
        else:
            i+=1
            tmp.append(int(S_arr[pointa:i+1]))
        cnt += sum(tmp)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)