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: Runtime Error

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

Submission status: Runtime Error

Solution code:
ss=input()
ans=0
 for i in range(2**(len(ss)-1)):
    temp=ss[0]
    for j in range(len(ss)-1):
        if i&(1<<j)!=0:
            temp+="+"
        temp+=ss[j+1]
    ans+=eval(temp)
print(ans)

Submission status: Runtime Error

Solution code:
S = input()

ans = 0
N = 2**(len(S) - 1)

for i in range(N):
    bit = bin(i)[2:]
    if len(bit) != len(S):
        bit = '0'*(len(S)-len(bit) - 1) + bit

    tmp = S[0]
#    print(bit)
    for i,b in enumerate(bit):
        if b == '0':
            tmp += S[i+1]
        else:
            ans += int(tmp)
            tmp  = S[i+1]
#            tmp += '+' + S[i+1]
    if len(tmp) > 0:
        ans += int(tmp)
print(ans)

Submission status: Runtime Error

Solution code:
def make(x):
    x = bin(x)[2:]
    while len(x) < len(S) - 1:
        x = "0" + x
    return list(x)

S = input()
a = pow(2, len(S) - 1)
b = []

for i in range(0, a):
    b.append(make(i))

i = 0
j = 0
key = int(S[0])
snum = 1
ans = 0
for i in b:
    snum = 1
    key = int(S[0])
    for j in i:
        if j == "0":
            key *= 10
            key += int(S[snum])
        elif j == "1":
            ans += key
            key = int(S[snum])
        #print(i, j, key)
        snum += 1
    ans += key
print(ans)

Submission status: Runtime Error

Solution code:
S = input()

ans = 0
count_list = [[2 ** (len(S)-1)]]

for i in range(1, len(S)):
    if i == 1:
        count_list.append([2 ** (len(S)-2), 2 ** (len(S)-2)])
    else:
        count_list.append([*count_list[i-1][:i-1], count_list[i-1][-1]//2, count_list[i-1][-1]//2])

count_list = count_list[::-1]

for i in range(len(S)):
    flag = 1
    for j in count_list[i]:
        ans += int(S[i]) * flag * j
        flag *= 10

print(ans)

Submission status: Runtime Error

Solution code:
S=str(input())
formula=[""]*(len(S)*2-1)
ans=0
for i in range(len(S)*2-1):
    if i%2==0:
        formula[i]=S[i//2]
place=pow(2,len(S)-1)-1
for i in range(place+1):
    for j in range(len(bin(i))-2):
        #strしたbinには0bのprefixが付く。
        if int(str(bin(i))[-j-1])==1:
            formula[2*j+1]="+"
    ans+=eval(''.join(formula))
    for k in range((len(formula)-1)/2):
        formula[2*k+1]=""
print(ans)

Submission status: Runtime Error

Solution code:
S=str(input())
formula=[""]*(len(S)*2-1)
ans=0
for i in range(len(S)*2-1):
    if i%2==0:
        formula[i]=S[i//2]
place=pow(2,len(S)-1)-1
for i in range(place+1):
    for j in range(len(bin(i))-2):
        #strしたbinには0bのprefixが付く。
        if int(str(bin(i))[-j-1])==1:
            formula[2*j+1]="+"
    ans+=eval(''.join(formula))
    for k in range(len(bin(i))-2):
        formula[2*k+1]=""
print(ans)

Submission status: Runtime Error

Solution code:
S=str(input())
formula=[""]*(len(S)*2-1)
ans=0
for i in range(len(S)*2-1):
    if i%2==0:
        formula[i]=S[i//2]
place=pow(2,len(S)-1)-1
for i in range(place+1):
    for j in range(len(bin(i))-2):
        #strしたbinには0bのprefixが付く。
        if int(str(bin(i))[-j-1])==1:
            formula[2*j+1]="+"
    ans+=eval(''.join(formula))
    for k in range(len(bin(i))-2):
        formula[2*j+1]=""
print(ans)

Submission status: Runtime Error

Solution code:
S = input()

# 2^n-1の2進数は全組み合わせを表す
combs = pow(2, len(S) - 1)
total = 0
for i in range(combs):
    # i番目の組み合わせ（2進数）
    comb_i = format(i, '0' + str(len(S)) + 'b')
    if len(comb_i) > 1:
        comb_i = comb_i[1:]

    tmp = S[0]
    for j in range(len(comb_i)):
        b = int(comb_i[j])
        if b == 1:
            tmp += "+"
        tmp += S[j + 1]
    total += eval(tmp)
print(total)

Submission status: Runtime Error

Solution code:
n = int(input())
s = n
a = int(input())
b = int(input())
c = int(input())
count = 0
ng = [a,b,c]
flag = 0
while count < 100 and n != (a or b or c) and n >=4:
    if not (n-3 in ng):
        count += 1
        n = n-3
    elif not (n-2 in ng):
        count += 1
        n = n-2
    elif not (n-1 in ng):
        count += 1
        n = n-1
    else:
        flag = 0
        break
if (n == 1 or n == 2 or n ==3) and count<=99 and (n not in ng):
    n = 0
    
if n > 0:
    flag = 0
    
if (flag == 1 or n == 0) and not (s in ng):
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
memo = [0,0,[[10,1], [1,1]]]
def lis(n):
    if len(memo) == n+1:
        return memo[n]
    else:
        l = lis(n-1)
        for i in range(len(l)):
            for j in range(len(l[i])):
                l[i][j] *= 10
                l[i].append(1)
        l.append([1 for i in range(len(l[0]))])
        memo.append(l)
        return memo[n]
s = input()
li = lis(len(s))
sum = 0
for i in range(len(li)):
    for j in range(len(li[i])):
        sum += int(s[i])*li[i][j]
print(sum)

Submission status: Runtime Error

Solution code:
def lis(n):
    if n == 2:
        return [[10,1], [1,1]]
    else:
        l = lis(n-1)
        for i in range(len(l)):
            for j in range(len(l[i])):
                l[i][j] *= 10
                l[i].append(1)
        l.append([1 for i in range(len(l[0]))])
        return l
s = input()
li = lis(len(s))
sum = 0
for i in range(len(li)):
    for j in range(len(li[i])):
        sum += int(s[i])*li[i][j]
print(sum)

Submission status: Runtime Error

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

s = input()
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: Runtime Error

Solution code:
s=input()
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: Runtime Error

Solution code:
s=input()
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]
  sum+=eval(calcs)
print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
    s = input()
    ans = 0
    for i in range((len(s) - 1) ** 2):
        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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s,g=raw_input(),0
for i in range(len(s))
	p=int(s[:i])
	q=int(s[i+1:)
	r=p+q
	g+=r
print g

Submission status: Runtime Error

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

# renketsu wo riyou sita kaihou ga kirei datta node
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: Runtime Error

Solution code:


# all_split("abc") -> [['abc'], ['ab', 'c'], ['a', 'bc'], ['a', 'b', 'c']]
def all_split(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: Runtime Error

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()
	pcandidstr = '0' + str(len(nums) - 1) + 'b'
	pcandid = 0
	maxcandid = int('1' * (len(nums) - 1),2)
	#add = format(1,pcandidstr)
	ALLSUM = 0
	while pcandid <= maxcandid:
		ALLSUM = ALLSUM + SumIndicatedPoint(format(pcandid,pcandidstr))
		pcandid = pcandid + 1
	print(str(ALLSUM))

Submission status: Runtime Error

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 = []

pattern(list(li), el, '+', [], xs)
pattern(list(li), el, '', [], xs)

print(sum(xs))

Submission status: Runtime Error

Solution code:
from math import factorial
total = 0

def cs(k):
    t = 0
    for i in range(1,k+1):
        t += factorial(k)/(factorial(i)*factorial(k-i))
    return t

def combine(l):
    t = 0
    if l == []:
        return 0
    for i in range(0,len(l)):
        sub1 = []
        sub2 = []
        for j in range(0,i):
            sub1.append(l[j])
        for j in range(i,len(l)):
            sub2.append(l[j])
        #print(sub1)
        sub_str = ''.join(sub1)
        #print(sub_str)
        t += int(sub_str)*cs(len(sub2)) + combine(sub2)
    return t
        
    

inpt = input()
numbers = []
for n in inpt:
    numbers.append(n)

total = combine(numbers)

print(total)

Submission status: Runtime Error

Solution code:
S = input()
ans = 0

for i in range(2 ** len(S-1)):
    tmp = []
    count = 1
    while(count != len(S)-1):
        if(i % 2 == 1):
            tmp.append(S[:count])
        count += 1
    ans += sum(tmp)
print(ans)

Submission status: Runtime Error

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+"+"
        s = s + S[inx+1]
    cnt += sum(map(int, s.split("+")))
print(cnt)

Submission status: Runtime Error

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

s = input().strip()
print(solve(s))