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

Solution (Python):
import math as m
import time
import itertools 
from Queue import Queue

def list_to_int(numList):         
    s = map(str, numList)   
    s = ''.join(s)          
    s = int(s)              
    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)
            
            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()

Solution (Python):
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

Solution (Python):
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

for i in xrange(total):
    x = ''
    c = list(b)
    
    for j in xrange(n-1):
        if i & (1<<j):
            c[2*j+1] = '+'
    
    
    ans += eval(''.join(c))
print ans

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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

Solution (Python):


S = input()
cnt = 0
ls = []
for i in range(2**(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)

Solution (Python):
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)

Solution (Python):
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))


mylist = []

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)

tot = 0
for x in mylist:
    tot += eval_str(x)
print tot

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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()

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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)