AtCoder Beginner Contest 045 - Many Formulas

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-----
125

-----Sample Output-----
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.

Source: atcoder | Difficulty: EASY


Solutions:
s = input()
total = 0
for i in range(len(s)):
	for j in range(len(s) - i):
		n = int(s[j:j + i + 1])
		if j == 0 or j == len(s) - i - 1:
			total += n * max([2 ** (len(s) - i - 2), 1])
		else:
			total += n * max([2 ** (len(s) - i - 3), 1])
print(total)


s = input()
ans = ''
for i in range(1 << len(s) - 1):
	ans += s[0]
	for j in range(len(s) - 1):
		if i >> j & 1:
			ans += ' '
		ans += s[j + 1]
	ans += ' '
print(sum(map(int, ans.split())))


s = input().strip()
ls = len(s)
total = 0
for i in range(1, ls + 1):
	for j in range(0, ls - i + 1):
		total += int(s[j:j + i]) * pow(2, max(0, j - 1) + max(0, ls - i - j - 1))
print(total)


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)


from itertools import product
s = input()
r = 0
for i in product([0, 1], repeat=len(s) - 1):
	t = ''
	for (c, j) in zip(s, list(i) + [0]):
		t += c + '+' * j
	r += eval(t)
print(r)


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)


S = input()
L = []
for i in range(len(S)):
	L.append(S[i])
n = len(S)
ans = []
for i in range(2 ** (n - 1)):
	obj = []
	for j in range(n - 1):
		if i >> j & 1:
			obj.append(j)
		else:
			obj.append(-1)
	s = ''
	s += L[0]
	for j in range(len(obj)):
		if obj[j] == -1:
			s += L[j + 1]
			continue
		else:
			s += '+'
			s += L[j + 1]
	idx = 0
	now = 0
	while True:
		if now == len(s) - 1:
			ans.append(int(s[idx:]))
			break
		if s[now] == '+':
			ans.append(int(s[idx:now]))
			idx = now + 1
			now = idx
		else:
			now += 1
print(sum(ans))


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


S = input()
l = len(S)
ans = 0
for i in range(l):
	for j in range(i + 1, l + 1):
		s = int(S[i:j])
		e = max(i - 1, 0) + max(l - j - 1, 0)
		ans += s * 2 ** e
print(ans)


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


S = input()
sum = 0
for i in range(2 ** (len(S) - 1)):
	P = ['+' if i >> j & 1 else '' for j in range(len(S) - 1)] + ['']
	T = ''.join((s + p for (s, p) in zip(S, P)))
	sum += eval(T)
print(sum)


N = str(int(input()))
total = 0
l = len(N) - 1
if l == 0:
	print(N)
else:
	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)


S = input()
ans = []

def fn(s, arr):
	ans.append(int(s) + sum(map(int, arr)))
	for i in range(1, len(s)):
		fn(s[i:], arr + [s[:i]])
fn(S, [])
print(sum(ans))


def dfs(i, f):
	if i == n - 1:
		return f
	return dfs(i + 1, f + s[i + 1]) + '+' + dfs(i + 1, f + '+' + s[i + 1])
s = input()
n = len(s)
print(eval(dfs(0, s[0])))


s = input()
import itertools
l = [*itertools.accumulate(s)]
o = []
for b in range(1 << len(s) - 1):
	q = []
	p = 0
	for i in range(len(s) - 1):
		if b & 1 << i:
			q += (int(l[i][p:]),)
			p = i + 1
	c = l[-1][p:]
	c = c if c else 0
	q += (int(c),)
	o += (sum(q),)
print(sum(o))


S = input()
L = len(S)

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


from itertools import product
S = input()
L = len(S) - 1
join = lambda x: ''.join(x)
print(sum((eval(join(map(join, zip(S, list(p) + [''])))) for p in product(('', '+'), repeat=L))))


x = input()
n = len(x) - 1
ans = 0
for i in range(2 ** n):
	cal = []
	for j in range(n):
		cal.append(x[j])
		if i >> j & 1:
			cal.append('+')
	cal.append(x[n])
	y = ''.join(cal)
	ans += eval(y)
print(ans)


s = input()
n = len(s)

def dfs(i, x):
	if i == n - 1:
		return sum(list(map(int, x.split('+'))))
	return dfs(i + 1, x + s[i + 1]) + dfs(i + 1, x + '+' + s[i + 1])
print(dfs(0, s[0]))


import itertools
s = input()
li = ['+', '']
lli = list(itertools.product(li, repeat=len(s) - 1))
ans = 0
for k in lli:
	val = ''
	for (i, j) in zip(s, k):
		val += i + j
	val += s[-1]
	ans += eval(val)
print(ans)


S = input()
n = len(S)
ans = 0
for bit in range(1 << n - 1):
	tmp = S[0]
	for i in range(n - 1):
		if bit & 1 << i:
			tmp += '+'
		tmp += S[i + 1]
	ans += sum(map(int, tmp.split('+')))
print(ans)


def dfs(i, f):
	if i == s - 1:
		return sum(map(int, f.split('+')))
	return dfs(i + 1, f + n[i + 1]) + dfs(i + 1, f + '+' + n[i + 1])
n = input()
s = len(n)
print(dfs(0, n[0]))


s = list(input())
ans = 0
for bit in range(1 << len(s) - 1):
	a = [int(s[0])]
	for i in range(len(s) - 1):
		if bit >> i & 1 == 1:
			a.append(int(s[i + 1]))
		else:
			a[-1] = 10 * a[-1] + int(s[i + 1])
	ans += sum(a)
print(ans)


from fractions import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
from sys import stdin
readline = stdin.readline

def readInts():
	return list(map(int, readline().split()))

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())
s = input()
ans = 0
for bit in range(1 << len(s) - 1):
	st = s[0]
	wa = 0
	for i in range(len(s) - 1):
		if bit & 1 << i:
			wa += int(st)
			st = s[i + 1]
		else:
			st += s[i + 1]
	ans += wa + int(st)
print(ans)


s = input()

def dfs(i, f):
	global s_sum
	if i == len(s) - 1:
		s_sum += sum(map(int, f.split('+')))
	else:
		dfs(i + 1, f + '+' + s[i + 1])
		dfs(i + 1, f + s[i + 1])
s_sum = 0
dfs(0, s[0])
print(s_sum)


S = input()
s = 0
l = len(S) - 1
for i in range(2 ** l):
	T = S
	for j in range(l):
		if i & 2 ** j:
			T = T[:l - j] + '+' + T[l - j:]
	s += eval(T)
print(s)


from itertools import product
s = input()
n = len(s)
ans = 0
for p in product([0, 1], repeat=n - 1):
	wk = s[0]
	index = 0
	for i in p:
		index += 1
		if i == 0:
			wk += s[index]
		else:
			ans += int(wk)
			wk = s[index]
	if wk != '':
		ans += int(wk)
print(ans)


s = input()
n = len(s)
a = [None] * n
a[0] = int(s[0])
for i in range(n - 1):
	a[i + 1] = a[i] * 10 + sum((int(j) for j in s[:i + 2])) * 2 ** i + int(s[i + 1]) * 2 ** i
print(a[n - 1])


s = input()
le = len(s) - 1
su = 0
for i in range(2 ** le):
	moji = s[0]
	for j in range(le):
		if i >> j & 1:
			moji += '+'
		moji += s[j + 1]
	su += eval(moji)
print(su)


S = input()
N = len(S)

def f(i, a):
	if i == N - 1:
		return sum(list(map(int, a.split('+'))))
	return f(i + 1, a + S[i + 1]) + f(i + 1, a + '+' + S[i + 1])
print(f(0, S[0]))


s = input()
n = len(s)
n -= 1
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)


S = input()
n = len(S)
ans = 0
for i in range(n):
	a = int(S[i])
	for j in range(n - i):
		ans += a * 10 ** j * 2 ** i * 2 ** max(0, n - i - j - 2)
print(ans)


def cal():
	s = input()
	(num, ans) = (len(s) - 1, 0)
	for i in range(2 ** num):
		(count0, count1) = (0, 0)
		for j in range(num):
			count1 += 1
			if i >> j & 1:
				ans += int(s[count0:count1])
				count0 = count1
		ans += int(s[count0:count1 + 1])
	print(ans)
cal()


S = input()
n = len(S)

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


S = input()
N = len(S)
total = 0
for i in range(2 ** (N - 1)):
	eq = ''
	for (j, c) in enumerate(S):
		eq += c
		if i & 1 << j:
			eq += '+'
	total += eval(eq)
print(total)


s = input()
n = len(s) - 1
ans = 0
for i in range(2 ** n):
	k = 0
	for j in range(n):
		if i >> j & 1:
			ans += int(s[k:j + 1])
			k = j + 1
	ans += int(s[k:])
print(ans)


import itertools
n = input()
l = len(n)
ans = 0
for ope in itertools.product('_+', repeat=l - 1):
	num = n[0]
	for i in range(l - 1):
		if ope[i] == '+':
			num += n[i + 1]
		else:
			ans += int(num)
			num = n[i + 1]
	ans += int(num)
print(ans)


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


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


s = input()
n = len(s)
ans = 0
for bit in range(1 << n - 1):
	f = s[0]
	for i in range(n - 1):
		if bit & 1 << i:
			f += '+'
		f += s[i + 1]
	ans += sum(map(int, f.split('+')))
print(ans)


from functools import reduce

def original_sum(X, init):
	goukei = 0
	if len(X) == 0:
		return sum(init)
	else:
		for i in range(len(X)):
			lstm = init.copy()
			num = int(reduce(lambda x, y: x + y, [str(x) for x in X[0:i + 1]]))
			lstm.append(num)
			Y = X[i + 1:len(X)].copy()
			goukei = goukei + original_sum(Y, lstm)
	return goukei
number = list(input())
init = []
print(original_sum(number, init))


s = input()
L = [[s, 0]]
for i in range(1, len(s)):
	M = []
	for l in L:
		M.append([l[0][:i + l[1]] + '+' + l[0][i + l[1]:], l[1] + 1])
	L += M
print(sum(map(lambda x: eval(x[0]), L)))


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


s = input()
ans = 0
for i in range(2 ** (len(s) - 1)):
	t = 0
	for j in range(len(s) - 1):
		if i >> j & 1:
			ans += int(s[t:j + 1])
			t = j + 1
	ans += int(s[t:])
print(ans)


import sys

def input():
	return sys.stdin.readline().rstrip()

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def main():
	s = input()
	n = len(s)
	ans = 0
	for i in range(1 << n - 1):
		idx = [0]
		for j in range(n - 1):
			if i >> j & 1:
				idx.append(j + 1)
		idx.append(n)
		for j in range(1, len(idx)):
			ans += int(s[idx[j - 1]:idx[j]])
	print(ans)

def __starting_point():
	main()
__starting_point()


a = input()
x = 0
for i in range(2 ** (len(a) - 1)):
	s = ''
	for j in range(len(a) - 1):
		s += a[j] + '+' * int(format(i, '010b')[-j - 1])
	s += a[-1]
	x += eval(s)
print(x)


s = input()
l = len(s)
ans = 0
for i in range(l):
	a = max(0, i - 1)
	ans += sum([int(s[i:j]) * (1 << a) * (1 << max(0, l - j - 1)) for j in range(i + 1, l + 1)])
print(ans)


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


def dfs(i, sum1):
	if i == len(s):
		return sum(list(map(int, sum1.split('+'))))
	return dfs(i + 1, sum1 + '+' + s[i]) + dfs(i + 1, sum1 + s[i])
s = input()
print(dfs(1, s[0]))


s = list(map(int, list(input())))
n = len(s)
m = 0
for i in range(n):
	for j in range(n - i):
		m += s[i] * 2 ** i * 10 ** j * 2 ** max(n - i - j - 2, 0)
print(m)


S = input()
l = len(S)
ls = [i for i in range(1, l)]
import itertools as it
a = 0
for i in range(l):
	for j in it.combinations(ls, i):
		t = ''
		p = 0
		for k in j:
			t += S[p:k] + '+'
			p = k
		t += S[p:]
		a += eval(''.join(t))
print(a)


s = input()
L = []
sigma = 0

def sprit_sum(string, sprit, num):
	nonlocal sigma
	for i in range(1, len(string) + num - sprit):
		str_front = string[:i]
		str_back = string[i:]
		L.append(int(str_front))
		if num < sprit:
			sprit_sum(str_back, sprit, num + 1)
		else:
			L.append(int(str_back))
			for x in L:
				sigma += x
			L.pop()
		L.pop()
for j in range(len(s)):
	sprit_sum(s, j + 1, 1)
sigma += int(s)
print(sigma)


S = input()
ans = 0

def dfs(s, sum_, n):
	if n == len(S) - 1:
		return int(s) + sum_
	return dfs(s + S[n + 1], sum_, n + 1) + dfs(S[n + 1], sum_ + int(s), n + 1)
print(dfs(S[0], 0, 0))


S = input()
num = len(S)
ans = 0
for bit in range(2 ** (num - 1)):
	f = S[0]
	for i in range(num - 1):
		if bit >> i & 1:
			f += '+'
		f += S[i + 1]
	ans += sum(map(int, f.split('+')))
print(ans)


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


S = input()
l = len(S)
ls = ''
for i in range(1, l):
	ls += str(i)
sa = [''] * (2 * l - 1)
for i in range(len(sa)):
	if i % 2 == 0:
		sa[i] = S[i // 2]
import copy
import itertools as it
ans = 0
for i in range(l):
	for j in list(it.combinations(ls, i)):
		sx = copy.copy(sa)
		for k in j:
			k = int(k)
			sx[2 * k - 1] = '+'
		ans += eval(''.join(sx))
print(ans)


s = input()
l = len(s)
ans = 0
for i in range(2 ** (l - 1)):
	tmp = ''
	sum = 0
	for j in range(l - 1):
		tmp += s[j]
		if i >> j & 1:
			sum += int(tmp)
			tmp = ''
	sum += int(tmp + s[-1])
	ans += sum
print(ans)


(a, b, k) = (0, 0, 1)
for d in input():
	(a, b) = (2 * a + b, 10 * b + int(d) * k)
	k *= 2
print(a + b)


S = input()
ans = 0

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


ss = input()
l = len(ss) - 1
ans = 0
for i in range(2 ** l):
	s = ss
	for j in reversed(range(l)):
		if i & 2 ** j > 0:
			s = s[:j + 1] + ' ' + s[j + 1:]
	num = list(map(int, s.split(' ')))
	ans += sum(num)
print(ans)


s = input()

def dfs(s):
	ans = int(s)
	for i in range(1, len(s)):
		ans += int(s[:i]) * (1 << len(s[i:]) - 1) + dfs(s[i:])
	return ans
ans = dfs(s)
print(ans)


from itertools import accumulate
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)


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)


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
s = SI()
ans = 0
for b in range(1 << len(s) - 1):
	f = ''
	for (i, c) in enumerate(s):
		f += c
		if b >> i & 1:
			f += '+'
	ans += eval(f)
print(ans)


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


s = input()
l = len(s)

def dfs(i, x):
	if i == l - 1:
		return eval(x)
	rep0 = dfs(i + 1, x + s[i + 1])
	rep1 = dfs(i + 1, x + '+' + s[i + 1])
	return rep0 + rep1
ans = dfs(0, s[0])
print(ans)


S = list(input())
N = len(S) - 1
ans = 0
for i in range(1 << N):
	a = S[0]
	for j in range(N):
		if i >> j & 1 == 0:
			a += S[j + 1]
		else:
			x = int(a)
			ans += x
			a = S[j + 1]
	x = int(a)
	ans += x
print(ans)


s = input()
l = len(s) - 1
res = 0
for i in range(2 ** l):
	t = s[0]
	for j in range(l):
		if i & 1 << j:
			t += '+'
		t += s[j + 1]
	res += eval(t)
print(res)


printn = lambda x: print(x, end='')
inn = lambda : int(input())
inl = lambda : list(map(int, input().split()))
inm = lambda : map(int, input().split())
ins = lambda : input().strip()
DBG = True
BIG = 10 ** 18
R = 10 ** 9 + 7

def ddprint(x):
	if DBG:
		print(x)
s = ins()
n = len(s)
ans = 0
for i in range(2 ** (n - 1)):
	z = []
	head = 0
	for j in range(n - 1):
		if (i >> j) % 2 > 0:
			z.append(int(s[head:j + 1]))
			head = j + 1
	z.append(int(s[head:]))
	ans += sum(z)
print(ans)


S = input()
ans = 0
for i in range(2 ** (len(S) - 1)):
	ls = []
	index = 0
	for j in range(len(S) - 1):
		if i >> j & 1:
			ls.append(int(S[index:j + 1]))
			index = j + 1
	ls.append(int(S[index:]))
	ans += sum(ls)
print(ans)


s = input()
nums = []
f = '0' + str(len(s) - 1) + 'b'
for i in range(2 ** (len(s) - 1)):
	m = format(i, f)
	l = 0
	r = 0
	while r < len(m):
		if m[r] == '1':
			nums.append(s[l:r + 1])
			l = r + 1
		r += 1
	nums.append(s[l:r + 1])
print(sum(map(int, nums)))


from itertools import product
s = input()
n = len(s)
ans = 0
for lst in product(['x', ' '], repeat=n - 1):
	ss = ''
	for i in range(n - 1):
		ss += s[i] + str(lst[i])
	ss += s[-1]
	ss = ss.replace('x', '')
	temp = [int(x) for x in ss.split()]
	ans += sum(temp)
print(ans)


S = input()
L = len(S)
from itertools import *
print(sum([eval(''.join([S[i // 2] if i % 2 == 0 else '+' if p[i // 2] else '' for i in range(L * 2 - 1)])) for p in product((0, 1), repeat=L - 1)]))


s = input()
ans = 0
for i in range(0, len(s)):
	for j in range(i + 1, len(s) + 1):
		ans += int(s[i:j]) * max(1, 2 ** (i - 1)) * max(1, 2 ** (len(s) - j - 1))
print(ans)


S = input()
total = 0
for bit in range(1 << len(S) - 1):
	evals = S[0]
	for n in range(len(S) - 1):
		if bit & 1 << n:
			evals += '+'
		evals += S[n + 1]
	total += eval(evals)
print(total)


s = input()
S = len(s)
c = 0
for i in range(2 ** (S - 1)):
	t = ''
	for j in range(S):
		t += s[j]
		if i & 1 << j:
			t += '+'
	c += eval(t)
print(c)


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


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)


s = input()
n = len(s)
ans = 0
for i in range(2 ** (n - 1)):
	eq = ''
	for (j, c) in enumerate(s):
		eq += c
		if i & 1 << j:
			eq += '+'
	ans += eval(eq)
print(ans)


num = int(input())

def the_algorithm(num):
	ary = list(str(num))
	sum = 0
	for bit in range(1 << len(ary) - 1):
		tmp = [ary[0]]
		for i in range(len(ary) - 1):
			mask = 1 << i
			if bit & mask:
				tmp.append(ary[i + 1])
			else:
				tmp[-1] = tmp[-1] + ary[i + 1]
		for i in tmp:
			sum += int(i)
	return sum
print(the_algorithm(num))


s = input()
l = len(s) - 1
ans = 0
for j in range(2 ** l):
	L = 0
	for i in range(l):
		if j >> i & 1 == 1:
			m = s[L:i + 1]
			ans += int(m)
			L = i + 1
	ans += int(s[L:])
print(ans)


def dfs(i, sall):
	if i == lenS:
		return sall
	return dfs(i + 1, sall + '+' + s[i]) + '+' + dfs(i + 1, sall + s[i])
s = input()
lenS = len(s)
print(sum(map(int, dfs(1, s[0]).split('+'))))


S = input()
ans = 0
for i in range(2 ** (len(S) - 1)):
	t = ''
	for s in S:
		t += s
		if i % 2 != 0:
			t += '+'
		i //= 2
	ans += eval(t)
print(ans)


S = input()
n = len(S) - 1
result = 0
for i in range(2 ** n):
	sum = 0
	temp = ''
	for j in range(n):
		temp += S[j]
		if i >> j & 1:
			sum += int(temp)
			temp = ''
	sum += int(temp + S[-1])
	result += sum
print(result)


(c, *s) = input()
n = len(s)
print(sum((eval(c + ''.join(('+' * (b >> i & 1) + s[i] for i in range(n)))) for b in range(2 ** n))))


S = input()
l = len(S)
print(sum((eval(''.join(sum(zip(['+' * (i & 2 ** j) for j in range(l)], S), ()))) for i in range(2 ** l))) // 2)


s = input()
n = len(s)
f = 0
for i in range(1 << n - 1):
	a = s[0]
	for j in range(n - 1):
		if i & 1 << j:
			a += '+' + s[j + 1]
		else:
			a += s[j + 1]
	f += eval(a)
print(f)


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


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


n = input()
ans = 0
for i in range(2 ** (len(n) - 1)):
	l = [0]
	for j in range(len(n) - 1):
		if i >> j & 1:
			l.append(j + 1)
	l.append(len(n))
	for j in range(len(l) - 1):
		ans += int(n[l[j]:l[j + 1]])
print(ans)


s = input()
dp = [0] * len(s)
dp[0] = int(s[0])
for i in range(1, len(s)):
	dp[i] = int(s[:i + 1]) + sum((dp[j - 1] + int(s[j:i + 1]) * 2 ** (j - 1) for j in range(1, i + 1)))
print(dp[-1])


s = input()
l_s = len(s)
b = '0%db' % (l_s - 1)
ans = 0
for i in range(2 ** (l_s - 1)):
	t = ''
	for j in range(l_s - 1):
		t += s[j] + ('+' if format(i, b)[j] == '1' else '')
	t += s[l_s - 1]
	ans += eval(t)
print(ans)


S = input()
N = len(S)
ans = 0
for sep in range(2 ** (N - 1)):
	p = 0
	for i in range(N):
		if sep >> i & 1 or i == N - 1:
			ans += int(S[p:i + 1])
			p = i + 1
print(ans)


from itertools import product
S = list(input())
N = len(S)
ans = 0
for adds in product([0, 1], repeat=N - 1):
	eqn = [''] * (2 * N - 1)
	eqn[::2] = S[:]
	for (i, has_add) in enumerate(adds):
		if has_add:
			eqn[2 * i + 1] = '+'
		else:
			eqn[2 * i + 1] = ''
	ans += eval(''.join(eqn))
print(ans)


s = input()
sum = 0
temps = list(s)
l = len(temps) - 1
for i in range(0, 2 ** l):
	temp = s[0]
	for j in range(0, l):
		if i >> j & 1:
			temp += '+'
		temp += s[j + 1]
	sum = sum + eval(temp)
print(sum)


s = input()
n = len(s)
ans = 0
for i in range(2 ** (n - 1)):
	k = 0
	num_list = []
	for j in range(n):
		if i >> j & 1:
			num = s[k:j + 1]
			k = j + 1
			num_list.append(int(num))
	num = s[k:n + 1]
	num_list.append(int(num))
	ans += sum(num_list)
print(ans)


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


from itertools import product, chain
S = input()
num = 0
for plus in product(('', '+'), repeat=len(S) - 1):
	num += eval(''.join(chain.from_iterable(zip(S, list(plus) + ['']))))
print(num)


import copy
s = input()
l = len(s)
ans = 0
if l == 1:
	ans += int(s)
	print(ans)
else:
	for i in range(2 ** (l - 1)):
		t = copy.deepcopy(s)
		f = []
		ch = 0
		for j in range(l - 1):
			if i >> j & 1:
				t = t[:j + 1 + ch] + '+' + t[j + 1 + ch:]
				ch += 1
		if '+' in t:
			y = list(map(int, t.split('+')))
			for u in y:
				ans += u
		else:
			ans += int(t)
	print(ans)


s = input()
L = len(s)
ans = 0
import itertools as it
l = [i for i in it.product(['', '+'], repeat=L - 1)]
for ll in l:
	f = ''
	for (i, j) in zip(s, list(ll) + ['']):
		f += i + j
	ans += eval(f)
print(ans)


n = input()
L = []
s = 0
for i in range(len(n)):
	L.append(int(n[i]))
for i in range(len(n)):
	s += (sum(L[0:i]) * 2 ** (i - 1) + L[i] * 2 ** i) * 10 ** (len(n) - i - 1)
print(int(s))


a = input()
n = len(a)
ans = 0
for i in range(2 ** (n - 1)):
	f = a[0]
	for j in range(n - 1):
		if i >> j & 1:
			f += '+'
		f += a[j + 1]
	ans += sum(map(int, f.split('+')))
print(ans)


(c, *s) = input()
n = len(s)
import itertools as it
a = 0
for p in it.product(['', '+'], repeat=n):
	t = c
	for i in range(n):
		t += p[i] + s[i]
	a += eval(t)
print(a)


import copy
s = list(input())
a = []
for i in range(len(s)):
	a.append(s[i])
	if i != len(s) - 1:
		a.append('')
ans = 0
for i in range(2 ** (len(s) - 1)):
	l = copy.deepcopy(a)
	for j in range(len(s) - 1):
		if i >> j & 1:
			l[2 * j + 1] = '+'
	ans += eval(''.join(l))
print(ans)


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


S = input()
N = len(S) - 1
ans = 0
for i in range(1 << N):
	eq = S[0]
	for j in range(N):
		if i & 1 << j:
			eq += '+'
		eq += S[j + 1]
	ans += eval(eq)
print(ans)


S = input().rstrip()
N = len(S)
ans = 0
for b in range(2 ** (N - 1)):
	a = []
	p = 0
	for i in range(N):
		if b & 1 << i:
			a.append(S[p:i + 1])
			p = i + 1
	a.append(S[p:])
	ans += eval('+'.join(a))
print(ans)


S = input()
if len(S) == 1:
	print(S)
else:

	def bfs(i, j, k):
		if i == len(S) - 1:
			return k + int(S[j:])
		return bfs(i + 1, i + 1, k + int(S[j:i + 1])) + bfs(i + 1, j, k)
	bns = bfs(0, 0, 0)
	print(bns)


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


from itertools import product
S = input()
total = 0
length = len(S)
List = list(product([0, 1], repeat=length - 1))
formula = ''
for item in List:
	formula = S[0]
	for i in range(length - 1):
		if item[i] == 0:
			formula += S[i + 1]
		else:
			formula += '+' + S[i + 1]
	total += eval(formula)
print(total)


S = input()
f = lambda x: 2 ** (x - 1) if x > 0 else 1
lenS = len(S)
ans = 0
for i in range(1, lenS + 1):
	for j in range(lenS - i + 1):
		ans += int(S[j:j + i]) * f(j) * f(lenS - j - i)
print(ans)


s = input()
n = len(s) - 1
ans = 0
for i in range(2 ** n):
	first = ''
	for j in range(n):
		if i >> j & 1:
			ans += int(first + s[j])
			first = ''
		else:
			first += s[j]
	ans += int(first + s[-1])
print(ans)


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


s = input()
n = len(s)
ans = 0

def bfs(num, i):
	if i == n:
		global ans
		ans += eval(num)
	else:
		bfs(num + '+' + s[i], i + 1)
		bfs(num + s[i], i + 1)
bfs(s[0], 1)
print(ans)


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


s = input()
n = len(s)
ans = 0
for i in range(2 ** (n - 1)):
	i = list(bin(i))[::-1]
	t = list(s)
	for j in range(len(i) - 1, -1, -1):
		if i[j] == '1':
			t.insert(j + 1, '+')
	t = ''.join(t)
	ans += eval(t)
print(ans)


s = input()
l = len(s) - 1
a = 0
for i in range(2 ** l):
	t = s[0]
	for j in range(l):
		t += '+' * (i >> j & 1) + s[j + 1]
	a += eval(t)
print(a)


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

def dfs(x, y):
	ans = 0
	if x == n:
		return sum(list(map(int, ''.join(y).split('+'))))
	else:
		return dfs(x + 1, y + '+' + s[x + 1]) + dfs(x + 1, y + s[x + 1])
print(dfs(0, s[0]))


S = input()
L = len(S) - 1
a = 0
for i in range(2 ** L):
	T = S[0]
	for j in range(L):
		T += '+' * (i >> j & 1) + S[j + 1]
	a += eval(T)
print(a)


S = input()
(a, b) = (0, int(S[0]))
for i in range(1, len(S)):
	d = int(S[i])
	a = 2 * a + b
	b = 10 * b + 2 ** i * d
print(a + b)


s = input()
chk = []

def f(a, b):
	if a == len(b):
		chk.append(eval(b))
	else:
		return (f(a + 1, b), f(a + 2, b[:a] + '+' + b[a:]))
f(1, s)
print(sum(chk))


(c, *s) = input()
n = len(s)
import itertools as it
print(sum((eval(c + ''.join((p[i] + s[i] for i in range(n)))) for p in it.product(['', '+'], repeat=n))))


s = input()
sm = 0
for i in range(1 << len(s) - 1):
	j = 0
	st = 0
	while j < len(s):
		if i >> j & 1 == 1:
			sm += int(s[st:j + 1])
			st = j + 1
		j += 1
	sm += int(s[st:])
print(sm)


S = input()
N = len(S)
ans = 0
for i in range(2 ** (N - 1)):
	Bit = list((i + 1 for i in range(N - 1)))
	for j in range(N - 1):
		if i >> j & 1:
			Bit[j] = 0
	Bit = [b for b in Bit if b > 0]
	L = 0
	for b in Bit:
		ans += int(S[L:b])
		L = b
	ans += int(S[L:])
print(ans)


s = input()
ans = 0
for bit in range(0, 1 << len(s) - 1):
	opr = []
	for i in range(len(s) - 1):
		opr.append('水着' if bit >> i & 1 == 1 else 'ワンピース')
	exp = [s[0]]
	for i in range(len(opr)):
		if opr[i] == 'ワンピース':
			exp[-1] += s[i + 1]
		elif opr[i] == '水着':
			exp.append(s[i + 1])
	ans += sum(list(map(int, exp)))
print(ans)


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


import math
import collections
from itertools import product
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(map(int, input().split()))
s = list(input())
n = len(s)
ans = 0
for p in product((0, 1), repeat=n):
	total = 0
	for i in range(n):
		if p[i] == 1:
			ans += total
			total = 0
		else:
			total = total * 10 + int(s[i])
	ans += total
print(ans)


s = input()
n = len(s)

def dfs(now, total, i):
	if i == n:
		return total + now
	else:
		res = 0
		res += dfs(now * 10 + int(s[i]), total, i + 1)
		res += dfs(int(s[i]), total + now, i + 1)
		return res
print(dfs(int(s[0]), 0, 1))


S = input()
n = len(S)

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


def f(s):
	if len(s) == 1:
		return [s]
	l = []
	for i in f(s[1:]):
		l.append(s[0] + '+' + i)
		l.append(s[0] + i)
	return l
print(sum(map(eval, f(input()))))


S = input()
l = len(S)
ans = int(S[-1]) * 2 ** (l - 1)
for i in range(1, l):
	a = int(S[-i - 1])
	for j in range(i + 1):
		ans += a * 10 ** j * 2 ** (l - min(j, i - 1) - 2)
print(ans)


s = input()
sum = 0
for bit in range(1 << len(s) - 1):
	f = s[0]
	for i in range(len(s) - 1):
		if bit & 1 << i:
			f += '+'
		f += s[i + 1]
	sum += eval(f)
print(sum)


from itertools import product
S = input()
N = len(S)
S2 = S[0]
for i in range(N - 1):
	S2 += '{}' + S[i + 1]
ans = 0
for p in product(['', '+'], repeat=N - 1):
	ans += eval(S2.format(*p))
print(ans)


s = input()
n = len(s)
l = [0]
for i in range(n):
	sm = 0
	for j in range(i + 1):
		sm += l[j] + int(s[j:i + 1]) * 2 ** max(j - 1, 0)
	l.append(sm)
print(sm)


S = input()

def func(S, i):
	if len(S) <= i:
		return eval(S)
	S1 = S[:i] + '+' + S[i:]
	return func(S, i + 1) + func(S1, i + 2)
print(func(S, 1))


s = input()
n = len(s) - 1
ans = 0
for i in range(2 ** n):
	op = [0] * n
	for j in range(n):
		if i >> j & 1:
			op[j] = 1
	t = s[0]
	for j in range(1, n + 1):
		if op[j - 1] == 1:
			t += '+' + s[j:j + 1]
		else:
			t += s[j:j + 1]
	ans += sum(list(map(int, t.split('+'))))
print(ans)


s = input()
len_s = len(s)
total = int(s)
eval_s = ''
insert_list = []
for i in range(1, 2 ** (len_s - 1)):
	for j in range(len_s):
		eval_s += s[j]
		if i >> j & 1:
			eval_s += '+'
	total += eval(eval_s)
	eval_s = ''
print(total)


S = input()
n = len(S)
ans = 0
for i in range(2 ** (n - 1)):
	tmp = 0
	t = 0
	for j in range(n - 1):
		if i >> j & 1:
			tmp += int(S[t:j + 1])
			t = j + 1
	tmp += int(S[t:])
	ans += tmp
print(ans)


s = input()
l = len(s)

def dfs(i, f):
	if i == l - 1:
		return eval(f)
	else:
		return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + '+' + s[i + 1])
print(dfs(0, s[0]))


a = list(input())
l = len(a) - 1
ans = 0
for i in range(1 << l):
	s = a[0]
	for j in range(l):
		if i >> j & 1:
			s += '+'
		s += a[j + 1]
	ans += eval(s)
print(ans)


S = input()
l = len(S)
ans = 0
for i in range(l):
	for j in range(i + 1, l + 1):
		temp = int(S[i:j])
		ans += temp * max(1, pow(2, i - 1)) * max(1, pow(2, l - j - 1))
print(ans)


n = input()
opr = len(n) - 1
cal_sum = 0
for i in range(2 ** opr):
	op = [''] * opr
	for j in range(opr):
		if i >> j & 1:
			op[opr - 1 - j] = '+'
	cal = ''
	for (x, y) in zip(n, op + ['']):
		cal += x + y
	cal_sum += eval(cal)
print(cal_sum)


s = input()
ans = 0
for bit in range(2 ** (len(s) - 1)):
	x = s[0]
	for i in range(len(s) - 1):
		if bit >> i & 1:
			x += '+'
		x += s[i + 1]
	ans += eval(x)
print(ans)


from itertools import product
S = input()
length = len(S)
ans = 0
for lst in product(['+', ''], repeat=length - 1):
	mystr = ''
	for i in range(length - 1):
		mystr += S[i] + lst[i]
	mystr += S[-1]
	mylist = [int(x) for x in mystr.split('+')]
	ans += sum(mylist)
print(ans)


import itertools
S = input()
npm = len(S) - 1
sum = eval(S)
pcomb = []
for i in range(npm):
	pcomb.append(list(itertools.combinations(list(range(1, npm + 1)), i + 1)))
for j in pcomb:
	k = 0
	for l in range(len(j)):
		pcomb2 = j[k]
		npmc = 0
		F = S
		for m in pcomb2:
			F = F[:m + npmc] + '+' + F[m + npmc:]
			npmc += 1
		sum += eval(F)
		k += 1
print(sum)


S = input()
N = len(S)
ans = 2 ** (N - 1) * int(S[-1])
for i in range(1 << N - 1):
	res = 1
	for j in range(N - 1):
		if (i >> j) % 2 == 1:
			res *= 10
		else:
			res = 1
		ans += res * int(S[N - 2 - j])
print(ans)


S = input()
ans = 0
for b in range(2 ** (len(S) - 1)):
	x = int(S[0])
	for i in range(1, len(S)):
		if b % 2:
			ans += x
			x = 0
		else:
			x *= 10
		x += int(S[i])
		b //= 2
	ans += x
print(ans)


from itertools import product
S = input()
A = ('+', '')
print(sum((eval(''.join([s + i for (s, i) in zip(S, I)] + [S[-1]])) for I in product(A, repeat=len(S) - 1))))


def bfs(s: str, n: int, i: int, j: int, k: int):
	return k + int(s[j:]) if i == n - 1 else bfs(s, n, i + 1, i + 1, k + int(s[j:i + 1])) + bfs(s, n, i + 1, j, k)
s = input()
n = len(s)
print(bfs(s, n, 0, 0, 0))


s = input()
s_sum = []
for i in range(2 ** (len(s) - 1)):
	sj = 0
	a = 0
	for j in range(len(s) - 1):
		if i >> j & 1:
			a += int(s[sj:j + 1])
			sj = j + 1
	a += int(s[sj:])
	s_sum.append(a)
print(sum(s_sum))


def hojyu(a):
	if len(a) != N:
		return '0' * (N - len(a)) + a
	else:
		return a
S = input()
N = len(S) - 1
R = list()
ans = 0
for i in range(2 ** N):
	s = str(bin(i)[2:])
	s = hojyu(s)
	b = 0
	mae = 0
	for k in range(len(s)):
		if s[k] == '1':
			b += int(S[mae:k + 1])
			mae = k + 1
	b += int(S[mae:])
	ans += b
print(ans)


def my_add(arg: list):
	if len(arg) == 1:
		return eval(arg[0])
	return my_add([arg[0] + arg[1]] + arg[2:]) + my_add([arg[0] + '+' + arg[1]] + arg[2:])
print(my_add(list(input())))


S = input()
len_S = len(S)
ans = 0
left = 0
is_plus = [0] * (len_S - 1)
for i in range(2 ** (len_S - 1)):
	left = 0
	for j in range(len_S - 1):
		(i, mod) = divmod(i, 2)
		if mod == 1:
			ans += int(S[left:j + 1])
			left = j + 1
	ans += int(S[left:len_S])
print(ans)


S = input()
t = len(S) - 1
sum = 0
for bit in range(2 ** t):
	f = S[0]
	for i in range(t):
		if bit & 1 << i:
			f += '+'
		f += S[i + 1]
	sum += eval(f)
print(sum)


s = input()
l = len(s)

def dfs(n):
	if n == l:
		return [0]
	ret = []
	for i in range(n + 1, l + 1):
		ret += [int(s[n:i]) + j for j in dfs(i)]
	return ret
print(sum(dfs(0)))


s = input()
n = len(s) - 1
res = 0
for i in range(1 << n):
	num_str = s[0]
	for j in range(n):
		if i >> j & 1 == 0:
			num_str += s[j + 1]
		else:
			res += int(num_str)
			num_str = s[j + 1]
	res += int(num_str)
print(res)


s = input()
n = len(s)
ans = 0
for i in range(2 ** (n - 1)):
	t = []
	x = i
	for j in range(n - 1):
		t.append(s[j])
		if x % 2 != 0:
			t.append('+')
		x = x // 2
	t.append(s[-1])
	m = 0
	for i in t:
		if i != '+':
			m *= 10
			m += int(i)
		else:
			ans += m
			m = 0
	ans += m
print(ans)


S = input()
N = len(S) - 1
ans = 0
for x in range(2 ** N):
	pvj = 0
	for j in range(N):
		if x >> j & 1:
			ans += int(S[pvj:j + 1])
			pvj = j + 1
	ans += int(S[pvj:N + 1])
print(ans)


s = input()
n = len(s)

def f(i, t):
	if i == n - 1:
		return sum(list(map(int, t.split('+'))))
	return f(i + 1, t + s[i + 1]) + f(i + 1, t + '+' + s[i + 1])
print(f(0, s[0]))


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


S = input().strip()
ans = 0
for i in range(2 ** (len(S) - 1)):
	e = ['' if c == '0' else '+' for c in format(i, 'b').zfill(len(S))]
	ans += eval(''.join((a + b for (a, b) in zip(e, S))))
print(ans)


s = [int(c) for c in input()]
n = len(s)
dp = [0] * n
dp2 = [0] * n
dp[0] = s[0]
dp2[0] = s[0]
for i in range(1, n):
	dp2[i] = dp2[i - 1] * 10 + s[i] * 2 ** i
	dp[i] = dp2[i] + 2 * dp[i - 1] - dp2[i - 1]
print(dp[n - 1])


S = input()
ans = 0

def helper(cur, res):
	global ans
	if res == '':
		ans += cur
	for i in range(1, len(res) + 1):
		helper(cur + int(res[:i]), res[i:])
helper(0, S)
print(ans)


n = input()
m = len(n) - 1
ans = 0
for i in range(2 ** m):
	num = format(i, 'b').zfill(m)
	N = list(n)
	for (j, k) in enumerate(num):
		if k == '1':
			N[j] = N[j] + '+'
	ans += eval(''.join(N))
print(ans)


S = input()
ans = 0
for i in range(2 ** (len(S) - 1)):
	l = 0
	for j in range(len(S) - 1):
		if i >> j & 1:
			ans += int(S[l:j + 1])
			l = j + 1
	ans += int(S[l:])
print(ans)


s = input()
n = len(s)

def dfs(l, r):
	if r == n:
		return int(s[l:r])
	return int(s[l:r]) * pow(2, n - r - 1) + dfs(r, r + 1) + dfs(l, r + 1)
print(dfs(0, 1))


S = input()
N = len(S)
ans = 0
for i in range(2 ** (N - 1)):
	F = 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)


s = input()
n = len(s)
a = 0
for i in range(n):
	d = int(s[i])
	for k in range(n - i):
		a += 2 ** i * int(2 ** (k - 1) + 0.5) * 10 ** (n - i - k - 1) * d
print(a)


S = input()
all_sum = 0
for n in range(1 << len(S) - 1):
	t = ''
	for (i, s) in enumerate(S):
		t += s
		if n & 1 << i != 0:
			t += '+'
	all_sum += eval(t)
print(all_sum)


N = input()
L = []
S = 0
for i in range(len(N)):
	L.append(int(N[i]))
for i in range(len(N)):
	S += (sum(L[0:i]) * 2 ** (i - 1) + L[i] * 2 ** i) * 10 ** (len(N) - i - 1)
print(int(S))


n = input()
co = 0
for i in range(2 ** (len(n) - 1)):
	a = ''
	for j in n:
		a += j
		if i % 2 == 1:
			a += '+'
		i //= 2
	co += eval(a)
print(co)


from itertools import product
s = input().strip()
ans = 0
for i in product(['', '+'], repeat=len(s) - 1):
	t = s[0]
	n = 1
	for j in i:
		t += j + s[n]
		n += 1
	ans += eval(t)
print(ans)


s = input()
ans = 0
for i in range(1 << len(s) - 1):
	t = list(s)
	for b in range(len(s) - 1):
		if i >> b & 1:
			t[b] = t[b] + '+'
	ans += eval(''.join(t))
print(ans)


n = list(map(int, input()))
ans = 0
ind = len(n) - 1
for i in range(len(n)):
	ans += 10 ** i * (n[-1] * 2 ** ind + sum(n[:-1]) * 2 ** (ind - 1))
	n = n[:-1]
	ind = len(n) - 1
print(int(ans))


s = input()
l = len(s) - 1
print(sum((eval(s[0] + ''.join(('+' * (i >> j & 1) + s[j + 1] for j in range(l)))) for i in range(2 ** l))))


class Combination:

	def __init__(self, n, mod):
		self.n = n
		self.mod = mod
		self.fac = [1 for i in range(self.n + 1)]
		self.finv = [1 for i in range(self.n + 1)]
		for i in range(2, self.n + 1):
			self.fac[i] = self.fac[i - 1] * i % self.mod
			self.finv[i] = self.finv[i - 1] * pow(i, -1, self.mod) % self.mod

	def comb(self, n, m):
		return self.fac[n] * (self.finv[n - m] * self.finv[m] % self.mod) % self.mod

def iparse():
	return list(map(int, input().split()))

def __starting_point():
	s = input()
	ans = 0
	for i in range(1 << len(s) - 1):
		prev = 0
		for j in range(len(s) - 1):
			if i >> j & 1 == 1:
				tmp = s[prev:j + 1]
				ans += int(tmp)
				prev = j + 1
		ans += int(s[prev:])
	print(ans)
__starting_point()


def f(s, t):
	if t == '':
		return sum(map(int, s.split('+')))
	else:
		return f(s + t[0], t[1:]) + f(s + '+' + t[0], t[1:])
S = input()
print(f(S[0], S[1:]))


S = input()
ans = 0
for i in range(2 ** (len(S) - 1)):
	tmp = int(S[0])
	for j in range(1, len(S)):
		if i & 1 == 1:
			ans += tmp
			tmp = int(S[j])
		else:
			tmp = tmp * 10 + int(S[j])
		i = i >> 1
	ans += tmp
print(ans)


S = input()

def f(i, s):
	if i == len(S) - 1:
		return sum(map(int, s.split('+')))
	else:
		return f(i + 1, s + S[i + 1]) + f(i + 1, s + '+' + S[i + 1])
print(f(0, S[0]))


S = input()
n = len(S)

def cal(i, f):
	if i == n - 1:
		return eval(f)
	return cal(i + 1, f + S[i + 1]) + cal(i + 1, f + '+' + S[i + 1])
print(cal(0, S[0]))


s = input()
all_s = []

def ss(index, perm):
	if index == len(s):
		all_s.append(perm)
	else:
		perm1 = [i for i in perm]
		perm1[-1] += s[index]
		ss(index + 1, perm1)
		perm2 = [i for i in perm]
		perm2.append(s[index])
		ss(index + 1, perm2)
ss(1, [s[0]])
all_sum = 0
for way in all_s:
	tmp = 0
	for n in way:
		tmp += int(n)
	all_sum += tmp
print(all_sum)


def cal(d, i, k, total):
	if i == len(d):
		return total + int(k)
	return cal(d, i + 1, d[i], total + int(k)) + cal(d, i + 1, k + d[i], total)
d = [x for x in input()]
print(cal(d, 1, d[0], 0))


import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):

	def assertIO(self, input, output):
		(stdout, stdin) = (sys.stdout, sys.stdin)
		(sys.stdout, sys.stdin) = (StringIO(), StringIO(input))
		resolve()
		sys.stdout.seek(0)
		out = sys.stdout.read()[:-1]
		(sys.stdout, sys.stdin) = (stdout, stdin)
		self.assertEqual(out, output)

	def test_入力例_1(self):
		input = '125'
		output = '176'
		self.assertIO(input, output)

	def test_入力例_2(self):
		input = '9999999999'
		output = '12656242944'
		self.assertIO(input, output)

def resolve():
	S = input()
	L = len(S)
	ans = 0
	for bit in range(1 << L - 1):
		s = ''
		for i in range(L):
			if 1 << i & bit:
				s += S[i]
				s += '+'
			else:
				s += S[i]
		ans += eval(s)
	print(ans)

def __starting_point():
	resolve()
__starting_point()


s = input()
d = len(s) - 1
ans = 0
for i in range(2 ** d):
	i = list(map(int, list(bin(i)[2:].zfill(d))))
	x = s[0]
	for j in range(d):
		if i[j] == 1:
			x += '+'
		x += s[j + 1]
	ans += eval(x)
print(ans)


import itertools
s = list(input())
ans = 0
l = list(itertools.product(['', '+'], repeat=len(s) - 1))
for d in l:
	f = ''
	for (s1, s2) in zip(s, list(d) + ['']):
		f += s1 + s2
	ans += eval(f)
print(ans)


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

def c(i, t):
	if i == n:
		return eval(''.join(t))
	return c(i + 1, t + '+' + s[i]) + c(i + 1, t + s[i])
print(c(1, s[0]))


S = input()
n = len(S)
ans = 0
for paint in range(2 ** (n - 1)):
	temp_S = S[0]
	for i in range(n - 1):
		if paint >> i & 1 == 1:
			temp_S += '+'
		temp_S += S[i + 1]
	ans += sum(map(int, temp_S.split('+')))
print(ans)


s = input()
l = len(s)

def dfs(i, f):
	if i == l - 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]))


from itertools import product
S = input()
ans = 0
ops = list(product('+ ', repeat=len(S) - 1))
for op in ops:
	ans += eval((S[0] + ''.join((x + y for (x, y) in zip(op, S[1:])))).replace(' ', ''))
print(ans)


s = input()
ans = 0
for i in range(2 ** (len(s) - 1)):
	r = 0
	d = '0' * 10 + bin(i)
	for j in range(len(s) - 1):
		if d[-j - 1] == '1':
			ans += int(s[r:j + 1])
			r = j + 1
	ans += int(s[r:])
print(ans)


n = str(input())
len_n = len(n) - 1
ans = 0
total = 0
for i in range(2 ** len_n):
	temp = n[0]
	for j in range(len_n):
		if i >> j & 1:
			temp += '+'
		temp += n[j + 1]
	total = list(map(int, temp.split('+')))
	ans += sum(total)
print(ans)


from itertools import product, chain
S = input()
ans = 0
for i in product(['+', ''], repeat=len(S) - 1):
	ans += eval(S[0] + ''.join(chain(*zip(i, S[1:]))))
print(ans)


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)


from itertools import product
s = input()
a = 0
for p in product((0, 1), repeat=len(s) - 1):
	t = s[0]
	for (i, b) in enumerate(p, start=1):
		if b == 1:
			t += '+' + s[i]
		else:
			t += s[i]
	a += eval(t)
print(a)


import itertools
s = input()
n = len(s) - 1
ans = 0
for v in itertools.product(['+', ''], repeat=n):
	x = s[0]
	for i in range(n):
		x += v[i] + s[i + 1]
	ans += eval(x)
print(ans)