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:
from sys import stdin
from math import factorial


def make_combinations(N, K):
    output=[]
    while(True):
        length = len(output)
        if length==0:
            output.append([i+1 for i in range(K)])
        else:
            previous = output[length-1].copy()
            for i in range(K):
                if previous[K-i-1]!=N-1-i:
                    newone = previous
                    newone[K-i-1] = previous[K-i-1]+1
                    for j in range(i):
                        newone[K-i-1+j+1] = newone[K-i-1+j]+1
                    output.append(newone)
                    break
                else:
                    continue
            if len(output) == length:
                break

    return output

def calc_sum(S, combinations):
    total_sum=0
    for combi in combinations:
        for i in range(len(combi)):
            if i==0:
                total_sum += int(S[:combi[i]])
            else:
                total_sum += int(S[combi[i-1]:combi[i]])
        total_sum += int(S[combi[len(combi)-1]:])
    return total_sum




S = str(stdin.readline().rstrip())

length = len(S)
total_number = int(S)
#total_number = 0

for i in range(length): #i:使用する+の数, 0~length-1
    if i==0: continue
    combinations = make_combinations(length,i)
    total_number += calc_sum(S, combinations)
#    combi = combination(length,i)
#    for j in range(i+1):
print(total_number)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
cnt= 0
for i in range(2**(n-1)):
    done = 0
    for j in range(n-1):
        if bin(i)[2:].zfill(n-1)[j] == '1':
            cnt += int(s[done:j+1])
            done = j+1
    cnt += int(s[done:n])
print(cnt)

Submission status: Accepted

Solution code:
s = input()
ans = []
l = len(s)

def rec(tmp, n):
    if n == l-1:
        ans.append(eval(tmp))
        return
    rec(tmp + "+" + s[n+1], n+1)
    rec(tmp + s[n+1], n+1)

rec(s[0], 0)
print(sum(ans))

Submission status: Accepted

Solution code:
S=input()
sum=0
for i in range(2**(len(S)-1)):
  a=""
  for j in range(len(S)-1):
    a+=S[j]
    if(i&1<<j):
      a+="+"
  a+=S[-1]
  sum+=eval(a)
print(sum)

Submission status: Accepted

Solution code:
def dfs(i,val):
    global s,n,sum
    val+=s[i-1]
    if i==n:
        sum+=eval(val)
        return
    dfs(i+1,val+"+")
    dfs(i+1,val)
s=input()
n=len(s)
val = ""
sum=0
dfs(1,val)
print(sum)

Submission status: Accepted

Solution code:
s = input()
n = len(s)

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

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

Submission status: Accepted

Solution code:
s=input()
n=len(s)
sum=0
for i in range(1<<n-1):
  t=0
  for j in range(n-1):
    if i & (1<<j):
      sum += int("".join(s[t:j+1]))
      t = j+1 
  sum += int(''.join(s[t:]))
print(sum)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
sum = 0
for b in range(1 << n-1):
    t = 0
    for i in range(n-1):
        if b & (1 << i):
            sum += int(''.join(s[t:i+1]))
            t = i+1
    sum += int(''.join(s[t:]))
print(sum)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
sum = 0
for b in range(1 << (n-1)):
    t = 0
    for i in range(n-1):
        if b & (1 << i):
            sum += int(''.join(s[t:i+1]))
            t = i+1
    sum += int(''.join(s[t:]))
print(sum)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = 0

def pm(i,j,k):
  global ans
  if i == n-1:
    k += int(s[j+1:])
    ans += k
  else:
    pm(i+1,i,k+int(s[j+1:i+1]))
    pm(i+1,j,k)
pm(0,-1,0)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    S = input().rstrip("\r\n")
    ans = 0
    for i in range(2**(len(S)-1)):
        nums = []
        num_str = S[0]
        for j in range(len(S)-1):
            if (i >> j) & 1:
                nums.append(int(num_str))
                num_str = S[j+1]
            else:
                num_str += S[j+1]
        if num_str != "":nums.append(int(num_str))
        ans += sum(nums)
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = list(map(int, list(str(input()))))
n = len(s)
ans = 0
for i in range(1 << n - 1):
    tmp = s[0]
    for j in range(n - 1):
        if (i >> j) & 1:
            ans += tmp
            tmp = s[j + 1]
        else:
            if j == 0:
                tmp = s[j] * 10 + s[j + 1]
            else:
                tmp = tmp * 10 + s[j + 1]
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)

def dfs(i,t):
  if i == n-1:
    return sum(list(map(int,t.split(chr(43)))))
  return dfs(i+1,t+s[i+1]) + dfs(i+1,t+chr(43)+s[i+1])

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

Submission status: Accepted

Solution code:
S=[]
ans=0
l=0

def bc(i,las,sum):
    global ans
    if i==l:
        ans+=int(S[las:])+sum
        return False
    if bc(i+1,las,sum):
        return True
    if bc(i+1,i+1,sum+int(S[las:i+1])):
        return True
    return False

S=input()
l=len(S)-1
bc(0,0,0)
print(ans)

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def calc(s, bag):
    for i, idx in enumerate(bag):
        s.insert(idx+i+1, '+')

    # print(s)
    # print(''.join(s))
    c = 0
    for n in ''.join(s).split('+'):
        if n == '+':
            continue
        c = c + int(n)
    return c


def solve():
    s = list(input())
    n = len(s) - 1
    # ans = int(s)
    # s = list(s)
    ans = 0
    for i in range(pow(2, n)):
        bag = []
        for j in range(n):
            if (i >> j) & 1:
                bag.append(j)
        # print(bag)
        ans = ans + calc(s.copy(), bag)
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
S=input()
ans=0

for i in range((1<<len(S)-1)):
    b=0
    for j in range(len(S)-1):
       if 1&(i>>j):
           ans+=int(S[b:j+1])
           b=j+1
    ans+=int(S[b:])

print(ans)

Submission status: Accepted

Solution code:
#ABC061-C-たくさんの数式
s = input()

n = len(s) - 1
wa = []

for i in range(2**n):
    #jビットシフト
    tmp = ""
        
    for j in range(n+1):
        tmp += s[j]
        if ((i >> j) & 1):
            tmp += '+'
    wa.append(eval("".join(tmp)))
    
        

print(sum(wa))

Submission status: Accepted

Solution code:
n = input()

def bitlist(n, a, b):
  res = []
  for i in range(2**n):
    pattern = []
    for j in range(n):
      if (i >> j) & 1:
        pattern.insert(0, a)
      else:
        pattern.insert(0, b)
    res.append(pattern)
  return res

m = len(n)
lst = bitlist(m-1, "+", "")
SUM = 0
for i in range(2**(m-1)):
  calc = ""
  for j in range(m-1):
    calc += n[j] + lst[i][j]
  calc += n[-1]
  spl = calc.split('+')
  for c in spl:
    SUM += int(c)
print(SUM)

Submission status: Accepted

Solution code:
def main():
    S = input()
    n = len(S)

    ans = 0
    for i in range(1<<n-1):
        t = ''
        for j in range(n):
            t += S[j]
            if i & (1 << j):
                t += '+'
        ans += eval(t)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
n = len(S) - 1
ans = 0

for i in range(2**n):
    A = [0] * n
    for j in range(n):
        if (i >> j) & 1 == 1:
            A[j] = 1
    a = 0
    for j in range(n):
        if A[j] == 1:
            ans += int(S[a: j+1])
            a = j+1
    ans += int(S[a:])
    a = 0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
t = []
for bit in range(1<<(len(s))):
  for i in range(len(s)):
    if bit & 1<<i and bit & 1<<(len(s)-1):
      t.append([bin(bit)[3:]])
      

p = [p[0] for p in set(map(tuple,t))]
for q in p:
  t = ''
  for i in range(len(q)):
    if q[i] == '1':
      t += s[i] + '+'
    else:
      t += s[i]
  t += s[-1]
  ans += sum(list(map(int,t.split('+'))))
  
print(ans)

Submission status: Accepted

Solution code:
n = input()
total=0
op_cnt = len(n) - 1 
for i in range(2 ** op_cnt):
    op = ["+"] * op_cnt  
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "" 
    formula = ""
    for p_n, p_o in zip(n, op + [""]):  
        formula += (p_n + p_o)
    
    total+=eval(formula)
print(total)

Submission status: Accepted

Solution code:
S = input()
ls = len(S)
ans = 0

for i in range(2 ** (ls-1)):
    susiki = ""
    shiki = []  
    for j in range(ls-1):
        if (i >> j) & 1:
            shiki.append("+")
        else:
            shiki.append("")
    
    for k in range(ls):
        if k == ls - 1:
            susiki = susiki + S[k]
        else:
            susiki = susiki + S[k] + shiki[k]
    ans += eval(susiki)

print(ans)

Submission status: Accepted

Solution code:
S = list(input())
ans = []
def f(i,tmp,carry):
  s = int(S[i])
  if i == len(S)-1:
    ans.append(tmp+carry+s)
  else:
    #＋にする場合
    f(i+1,tmp+carry+s,0)
    #なにも入れない場合
    f(i+1,tmp,(carry+s)*10)
f(0,0,0)
print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)

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

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

Submission status: Accepted

Solution code:

def resolve():
	s = input()
	k = 0
	for i in range(1 << len(s) - 1):
		ts = s
		seq = 1
		for j in range(len(s) - 1):
			if (i >> j) & 1:
				k += int(ts[:seq])
				ts = ts[seq:]
				seq = 1
			else:
				seq += 1
		k += int(ts or 0)
	print(k)
resolve()

Submission status: Accepted

Solution code:
S=input()
ans=0
if len(S)==1:
    print(S)
else:
    for i in range(2**(len(S)-1)):
        done=0
        b=bin(i)[2:].zfill(len(S)-1)
        for j in range(len(S)-1):
            if b[j]=="1":
                ans+=int(S[done:j+1])
                done=j+1
        ans+=int(S[done:])
    print(ans)

Submission status: Accepted

Solution code:
def resolve():
	s = input()
	k = 0
	for i in range(1 << len(s)-1):
		ts = s
		a = 1
		for j in range(len(s)):
			if ((i >> j) & 1):
				k += int(ts[:a] or 0)
				ts = ts[a:]
				a = 1
			else:
				a += 1
		k += int(ts or 0)
	print(k)

resolve()

Submission status: Accepted

Solution code:
import itertools

s = str(input())
length = len(s)

bins = []
for i in range(2**(length-1)):
    bins.append(list(str(format(i,'b')).zfill(length-1)))

ans = 0
for i in range(2**(length-1)):
    tmp_str=s[0]
    for j in range(length-1):
        if(bins[i][j]=='0'):
            tmp_str += s[j+1]
        else:
            ans += int(tmp_str)
            tmp_str = s[j+1]
    ans+=int(tmp_str)
print(ans)

Submission status: Accepted

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

if N == 1:
    print(S)
    exit()

ans = 0
for i in range(2 ** (N - 1)):
    signs = bin(i)[2:].zfill(N - 1).replace('0', '+').replace('1', ' ')

    tmp_s = S[0]
    for j, sign in enumerate(signs):
        tmp_s += sign + S[j + 1]

    ans += eval(tmp_s.replace(' ', ''))

print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from operator import add


def test(array: list, index: int, calc: str, result: list):
    # print("index:{}".format(index))
    # print("calc:{}".format(calc))
    # 配列の最後までチェックしたら終了
    if index == len(array) - 1:
        # print("sum:{}".format(result[0] + sum(calc + array[index])))
        result[0] += sum(calc + array[index])
        return
    test(array, index + 1, calc + array[index], result)
    test(array, index + 1, calc + array[index] + "+", result)


def sum(calc: str):
    nums = [int(item) for item in calc.split("+")]
    return reduce(add, nums)


array = list(input())
result = [0]
test(array, 0, "", result)
print(result[0])

Submission status: Accepted

Solution code:
S=int(input())
S_=list(map(str,str(S))) #['1', 'p', '2', 'p', '5']
l=len(str(S))-1 #2
l_=len(S_)-1 #4
n=list(range(1,l_,2)) #[1, 3]

ans_2=[]
ans_3=[]
for i in range(2**l):
    listA=[]
    listB=[None]*(l+1) 
    for j in range(l):
        if ((i>>j)&1):
            listB[j]='+'
    ans_1=[]
    for o,p in zip(S_,listB):
        ans_1.append(o)
        ans_1.append(p)
    ans_2=[f for f in ans_1 if not f==None]
    ans_2=''.join(ans_2)
    ans_2=ans_2.split('+')
    ans_3.append(sum(list(map(int,ans_2))))
print(sum(ans_3))

Submission status: Accepted

Solution code:
s=input()
if len(s)!=1:
	count = 0
	n=len(s)-1
	for i in range(2**n):
		op = ["" for _ in range(n)]
		for j in range(n):
			if ((i>>j)&1):
				op[j] = "+"
		formula = ""
		for j in range(n):
			formula += s[j] + op[j]
		formula += s[n]
		count += eval(formula)
	print(count)
else:
	print(s)

Submission status: Accepted

Solution code:
S = input()
keta = len(S)
ans=0
for bit in range(1 << keta-1):
    f = S[0]

    for i in range(keta-1):
        if bit & (1<<i):
            f += "+"
        f += S[i+1]
    ans += sum(map(int,f.split("+")))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)-1

bins= []

for i in range(2**n):
    bins.append(list(str(format(i,'b')).zfill(n)))

ans = 0
for i in range(2**n):
    sum = 0
    temp = str(s[0])
    for j in range(n):
        if bins[i][j] == '0':
            sum += int(temp)
            temp = ''
            temp += str(s[j+1])
        
        else:
            temp += str(s[j+1])
    sum += int(temp)
    

    ans += sum

print(ans)

Submission status: Accepted

Solution code:
S = input()
all_sum = 0
for pattern in range(1 << (len(S)-1)):
  this_sum = 0
  cut = 0
  for i in range(1,len(S)):
    if pattern & 1 << i-1:
      this_sum += int(S[cut:i])
      cut = i

  this_sum += int(S[cut:])
  all_sum += this_sum

print(all_sum)

Submission status: Accepted

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

# create ptn
ptn = []
for bit in range(2**(N-1)):
    tmp = [False]*(N-1)
    for i in range(N-1):
        if ((bit>>i) & 1):
            tmp[i] = True
    ptn.append(tmp)

# calc sum
tot = []
for p in ptn:
    a = []
    for i, s in enumerate(S):
        if i==0:
            now = int(s)
            continue
        if p[i-1]==False:
            now *= 10
            now += int(s)
        else:
            a.append(now)
            now = int(s)
    a.append(now)
    tot.append(sum(a))
print(sum(tot))

Submission status: Accepted

Solution code:
S = input()

ans = 0
for i in range(2**(len(S)-1)):
    tmp = S
    for j in range(len(S)-1):
        if((i >> j) & 1):
            tmp = tmp[:(len(S)-1-j)] + "+" + tmp[(len(S)-1-j):]
    ans += sum([int(k) for k in tmp.split("+")])       
print(ans)

Submission status: Accepted

Solution code:
def saiki_wa(S,l,ls,n):
	ret = 0
	if n == l-1:
		s = S[0]
		for i in range(l-1):
			s = s + ls[i] + S[i+1]
		ret = sum([int(i) for i in s.split('+')])
	else:
		ret += saiki_wa(S,l,ls[:],n+1)
		ls[n] = '+'
		ret += saiki_wa(S,l,ls[:],n+1)

	return ret

if __name__ == '__main__':
	S = input()
	l = len(S)

	if l == 1:
		ans = int(S)
	else:
		ls = [''] * (l-1)

		ans = saiki_wa(S,l,ls,0)

	print(ans)

Submission status: Accepted

Solution code:
s = input()

ans = 0
n = len(s) - 1
for i in range(2 ** n):
    op = [''] * n
    for j in range(n):
        if ((i >> j) & 1):
            op[n - j - 1] = '+'
    formula = ''
    for p_n, p_o in zip(s,op+['']):
        formula += (p_n+p_o)
    ans += eval(formula)

print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)

ans = 0
for i in range(2**(n-1)) :
  bit = i
  index = 0
  for j in range(n-1) :
    c = bit%2
    bit = bit//2
    if c == 1 :
      ans += int(s[index:j+1])
      index = j+1
    elif j == n - 2 :
      ans += int(s[index:j+1])*10
  ans += int(s[n-1])

print(ans)

Submission status: Accepted

Solution code:
s = input()

n = len(s) - 1
ans = 0
for bit in range(2**n):
  a = s[0]
  for j in range(n):
    if (bit >> j) & 1:
      a += "+"
    a += s[j+1]
  ans += sum(map(int,a.split("+")))

print(ans)

Submission status: Accepted

Solution code:
s = input()

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

print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)

ans = 0
for i in range(2**(n-1)) :
  bit = i
  v = 0
  vt = 0
  for j in range(n-1) :
    vt += int(s[j])
    c = bit%2
    bit = bit//2
    if c == 0 :
      vt *= 10
    else :
      v += vt
      vt = 0
  v += vt + int(s[n-1])
  ans += v

print(ans)

Submission status: Accepted

Solution code:
s=input()

outsum=0

for i in range(2**(len(s)-1)):
	temps = s
	mojisum = 0
    
	for j in range(len(s)-1):
		mojisum += 1
		if (i >> j) & 1 :
			outsum += int(temps[-mojisum:])
			temps = temps[:-mojisum]
			mojisum = 0
	outsum += int(temps)

print(outsum)

Submission status: Accepted

Solution code:
s = input()

ans = 0
n = len(s) - 1
for i in range(2 ** n):
    op = [''] * n
    for j in range(n):
        if ((i >> j) & 1):
            op[n - j - 1] = '+'
    formula = ''
    for p_n, p_o in zip(s,op+['']):
        formula += (p_n+p_o)
    ans += eval(formula)

print(ans)

Submission status: Accepted

Solution code:

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

print(ans)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

S_int = int(readline())
S_str = str(S_int)

if len(S_str) == 1:
    print(S_int)
    quit()

pattern = []
fmt = '0' + str(len(S_str)-1) + 'b'
for i in range(2**(len(S_str)-1)):
    pattern.append(format(i, fmt))

answer = 0
for plus_flags in pattern:
    tmp = []
    tmp_str = S_str[0]
    for i, is_plus in enumerate(plus_flags, start=1):
        if is_plus == "1":
            tmp.append(int(tmp_str))
            tmp_str = ""
        tmp_str += S_str[i]
    if tmp_str:
        tmp.append(int(tmp_str))
    answer += sum(tmp)
print(answer)

Submission status: Accepted

Solution code:
s = input()
def allsum(x):
    ans = int(x)
    if len(x) < 2:
        ans += 0
    else:
        for i in range(1, len(x)):
            ans += int(x[:i])*2**(len(x)-i-1) + allsum(x[i:])
    return ans
print(allsum(s))

Submission status: Accepted

Solution code:
S = input()
ans = 0
l = []

def calc(S, i, stack):
    if i == len(S):
        l.append(stack) 
    elif i == 0:
        calc(S, 1, str(S[0]))
    else:
        # わけない
        calc(S, i + 1, stack + str(S[i]))

        # わけない(スタック)
        calc(S, i + 1, stack + '+' + str(S[i]))


calc(S, 0, '')

for equation in l:
    ans += eval(equation)

print(ans)

Submission status: Accepted

Solution code:
s = input()

math_s_list = []

def plus_or_nothing(math_s, pos_s, s):
    if pos_s == len(s):
        math_s_list.append(eval(math_s))
        return
    
    plus_or_nothing(math_s+s[pos_s], pos_s+1, s)
    plus_or_nothing(math_s+'+'+s[pos_s], pos_s+1, s)
    return

plus_or_nothing(s[0], 1, s)

ans = 0
for i in math_s_list:
    ans += i

print(ans)

Submission status: Accepted

Solution code:
# import sys
# read = sys.stdin.buffer.read
# readline = sys.stdin.buffer.readline
# readlines = sys.stdin.buffer.readlines

# def myinput():
#     return map(int,readline().split())

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

for i in range(2**(l-1)):
    temp = s[0]
    for j in range(l-1):
        if i & (2**j):
            ans += int(temp)
            temp = s[j+1]
        else:
            temp += s[j+1]
    ans += int(temp)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(2 ** (N - 1)):
    tmp = 0
    prev = 0
    for j in range(N - 1):
        if i & (1 << j):
            tmp += int(S[prev : j + 1])
            prev = j + 1
    tmp += int(S[prev:])
    ans += tmp

print(ans)

Submission status: Accepted

Solution code:
n = [int(x) for x in input()]
s=len(n)-1
ans=0

for i in range(2 **s):
    op = str(n[0])
    for j in range(s):
        if ((i >> j) & 1):
            op += '+'
        op+=str(n[j+1])

    ans += eval(op)

print(ans)

Submission status: Accepted

Solution code:
a=input()
len_a=len(a)
a=list(a)

c=0
for i in range(2**(len_a-1)): # 2^(N-1)
  s=a[0]
  for j in range(len_a-1):
      if ((i >> j) & 1) == 1: # 右から順番に1ビットかどうか確認
          s += "+"
      s += a[j+1]
  c += sum(map(int, s.split("+")))

print(c)

Submission status: Accepted

Solution code:
def insert_string_to_base(target_string, insert_point, insert_string):
    return target_string[:insert_point] + insert_string + target_string[insert_point:]

def main():
    N = str(input())
    l = len(N)-1

    result = 0
    for i in range(2 ** l):
        count = 1
        st = N
        for j in range(l):
            if ((i >> j) & 1):
                st = insert_string_to_base(st, j+count, "+")
                count+=1

        for v in st.split("+"):
            if(v != ''):
                result += int(v)
    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import copy

def splitAndPlus(s,len,cursor):

	if len - 1 > cursor :

		s2 = copy.copy(s)
		joined = ''.join([s2.pop(cursor),s2.pop(cursor)])
		nokori = s2
		nokori.insert(cursor,joined)

		return splitAndPlus(s,len,cursor+1) + splitAndPlus(nokori,len-1,cursor)

	else: 
		# print('s is', s,cursor)
		if s is None:
			return 0
		else:	
			numss = [ int(i) for i in s]
			return sum(numss)



inp = input()
s = [inp[i]  for i in range(len(inp))]

print(splitAndPlus(s,len(s),0))

Submission status: Accepted

Solution code:
# 入力の取得(文字列)
s = input()

# 処理
result = 0
# ビット全探索(「2のn乗」数分ループ)
# len-1する理由：桁数 = パターン数ではないため。パターン数は数は2の「桁数-1」乗。
# 例：3桁(123)の場合 = 検証パターンは2の2乗。(1 「+」 2 「+」  3)。
for i in range(1 << len(s)-1):
    # -dev- bit = bin(i)
    left_digit = 0

    # パターン桁数分ループ(len(s)-1)
    # 12+3(123の「01」)の場合:i=0～4)
    for j in range(len(s)-1):
        # 値が１の桁が存在する場合
        if i & 1 << j:
            # 12+3(123の「01」)の場合:12を加算する式はint(s[0:2])。だからint(s[0:i(=1)+1] を実装
            result += int(s[left_digit:j + 1])
            # -dev- print("ループ中")
            # -dev- print(int(s[left_digit:j + 1]))
            # 12+3(123の「01」)の場合:12を加算後、left_digitは2になる。だから「j + 1」を代入する。
            left_digit = j + 1

    # 12+3(123の「01」)の場合:ループ終了時、3が加算されていない。だから「int(s[left_digit:])」を加算する。
    result += int(s[left_digit:])
    # -dev- print("ループ終了時")
    # -dev- print(int(s[left_digit:]))
# 結果出力
# -dev- print("最終結果")
print(result)

Submission status: Accepted

Solution code:
s = input()

ans = 0
def dfs(s,f=0):
  global ans
  for i in range(len(s)):
    if i == 0:
      ans += int(s)
    else:
      ans += int(s[:i]) + f
      dfs(s[i:],int(s[:i])+f)
  return ans

print(dfs(s))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
slen = len(S)

def function(p, c, idx):
    n = c+int(S[idx])
    if idx == slen-1:
        return p+n
    else:
        return function(p+n, 0, idx+1) + function(p, n*10, idx+1)

print(function(0,0,0))

Submission status: Accepted

Solution code:
s = list(input())

lenS = len(s)

def f(p,c,i):
  n = c+int(s[i])
  if i == lenS-1:
    return p+n
  else:
    return f(p+n,0,i+1)+f(p,n*10,i+1)
  
print(f(0,0,0))

Submission status: Accepted

Solution code:
inp = [x for x in input()]
cnt = len(inp)-1
sum_ = []

for c in range(2**cnt):
  inp_ = inp.copy()
  for j in range(cnt):
    if ((c >> j)&1):
      inp_[cnt-j-1]+='+'
      
  a = eval(''.join(inp_))
  sum_.append(a)
print(sum(sum_))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()


slen = len(S)-1

ans = 0
for flag in range(1<<slen):
    j = 0
    for i in range(0,slen):
        if flag & 1<<i:
            ans += int(S[j:i+1])
            j = i + 1
    ans += int(S[j:])

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000)
s=input()
ans=0
num=len(s)-1
def solve(moji,num):
    global ans
    if num==0:
        ans+=eval(moji)
    else:
        solve(moji,num-1)
        solve(moji[:-num]+"+"+moji[-num:],num-1)
solve(s,num)
print(ans)

Submission status: Accepted

Solution code:
S = input()
allsum = 0

for i in range(2**(len(S)-1)):
    bi = format(i,"b")
    bi = "0" * (len(S) - len(bi) - 1) + bi
    st = S[0]
    stsum = 0
    for k in range(len(S) - 1):
        if bi[k] == "0":
            stsum += int(st)
            st = S[k+1]
        else:
            st = st + S[k+1]
    stsum += int(st)
    allsum += stsum
print(allsum)

Submission status: Accepted

Solution code:
S = list(str(input()))
bit_flag = []
result_s = []
for i in range(1 << len(S)-1):
    tmp = []
    for j in range(len(S)-1):
        tmp.append((i >> j) & 1)
    bit_flag.append(tmp)

for bit in bit_flag:
    tmp = S[0]
    # [0, 0]などが入っている
    for i in range(len(S)-1):  # 2回
        if bit[i] == 1:
            tmp += "+"
        tmp += S[i+1]
    result_s.append(tmp)
ans = 0
for s in result_s:
    ans += eval(s)
print(ans)

Submission status: Accepted

Solution code:
S = str(input())
ans = []
N = len(S)  # 最後の文字の判定を行う


def rec(tmp_s, n):
    if n == N-1:  # 最後の文字なら計算を開始する
        ans.append(eval(tmp_s))
        return
    rec(tmp_s+"+"+S[n+1], n+1)
    rec(tmp_s+S[n+1], n+1)


rec(S[0], 0)
print(sum(ans))

Submission status: Accepted

Solution code:
from itertools import product
s = input()
ans = 0
for bit in product(['', '+'], repeat=len(s)-1):
    q = ''
    for i in range(len(s)*2-1):
        if i % 2 == 0:
            q += s[i//2]
        else:
            q += bit[(i-1)//2]
    ans += eval(q)
print(ans)

Submission status: Accepted

Solution code:
import sys

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

print(ans)

Submission status: Accepted

Solution code:
# AtCoder Regular Contest 061  C - たくさんの数式

s=''
aa=list(input())

for i in range(2**(len(aa)-1)):

    for j in range(len(aa)):

        s+=aa[j]

        if (i>>j) & 1:

            s += "+"

    s+="+"

s+="0"

print(eval(s))

Submission status: Accepted

Solution code:
S = input()

n = len(S)

ans_l = []

for i in range(2 ** (n-1)):
  l = []
  start = n - 1 
  end = n
  #print(bin(i))
  if i != 0:
    for j in range(n-1):
      if ((i >> j) & 1):
        #print(start,end)
        l.append(int(S[start:end]))
        end = start
      start -= 1
    l.append(int(S[0:end]))
    ans_l.append(sum(l))
  else:
    ans_l.append(int(S))
  
        
#print(ans_l)
  
print(sum(ans_l))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
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 LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	S = IS()
	S=list(map(int,"".join(S)))
	def dfs(i, total, additional):
		if i==len(S)-1:
			return total+additional
		else:
			return dfs(i+1, total, additional*10+S[i+1]) + dfs(i+1, total+additional, S[i+1])
	print(dfs(0,0,S[0]))


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
characters = input()
N = len(characters)

total = 0
for i in range(2 ** (N - 1)):
    operation = ""
    for j in range(N - 1):
        operation += characters[j]
        if ((i >> j) & 1):
            operation += "+"
    operation += characters[N - 1]
    ans = eval(operation)
    total += ans
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
total = 0

#bit search
for i in range(2 ** (len(S) - 1)):
  exp = S[0]
  for j in range(len(S) - 1):
    if i & (1 << j) != 0:
      exp += '+'
    exp += S[j + 1]
  total += eval(exp)
print(total)