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:
S = str(input())

ans = 0
N = len(S)

for i in range(2**(N-1)):
  pattern = bin(i)[2:].zfill((N-1))
  formula = ''
  for j in range(N):
    mark = ''
    if j < N-1:
      if pattern[j] == '1':
        mark = '+'
    formula += S[j]+mark
  ans += eval(formula)

print(ans)

Submission status: Accepted

Solution code:
S = str(input())

ans = 0
N = len(S)
for i in range(2**N):
  pattern = bin(i)[2:].zfill(N)
  formula = ''
  for j in range(N):
    mark = ''
    if pattern[j] == '1' and j < N-1:
      mark = '+'
    formula += S[j]+mark
  ans += eval(formula)

print(ans//2)

Submission status: Accepted

Solution code:
import sys
import itertools

s=input()

if len(s)==1:
    print(int(s))
    sys.exit()


S=0

for i in itertools.product([0,1],repeat=len(s)-1):
    sm=0
    st=0
    for j in range(len(i)):
        if i[j]==1:
            sm+=int(s[st:j+1])
            st=j+1
            if j==len(s)-2:
                sm+=int(s[j+1:len(s)])
        elif j==len(s)-2:
            sm+=int(s[st:len(s)])
    S+=sm

print(S)

Submission status: Accepted

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

s = 0
for i in range(2**n):
    A = ['+' if (i>>j) & 1 else '' for j in range(n)]
    T = S[0]
    for j in range(n):
        T += A[j]
        T += S[j+1]
    T = ''.join(T)
    s += eval(T)
print(s)

Submission status: Accepted

Solution code:
def resolve():
    s = input()
    ans = 0
    for i in range(2**(len(s)-1)):
        test = []
        cal = ""
        for j in range(len(s)-1):
            test.append((i>>j) & 1)
        for j in range(len(test)):
            if test[j] == 0:
                cal = cal + s[j]
            else:
                cal += s[j] + "+"
        cal += s[-1]
        ans += eval(cal)
    print(ans)
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

s = input()
n = len(s)
print(dfs(0, s[0]))

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    S = SI()
    l = len(S)
    ans = 0
    for case in range(2**(l-1)):
        j = 0
        N = int(S)
        ans += N % 10
        for i in range(l-1):
            if (case >> i) & 1:
                j = 0
            else:
                j += 1
            ans += int(S[-(i+2)]) * 10**j

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = input()

N = len(n)-1

i = 0
ans = 0
for i in range(2**N):
    # print("i=",i)
    n2 = n
    for j in range(N):
        if(i>>j)&1:
            n2= n2[:(N-j)] + " " + n2[N-j:]
            # print(n2)
    
    n3 = n2.split()
    for k in range(len(n3)):
        ans += int(n3[k])
    # print(n3)
print(ans)

Submission status: Accepted

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())

    ans = []
    for i in range(2 ** (len(s) - 1)):
        tmp = [s[0]]
        for j in range(len(s) - 1):
            if (i >> j) & 1:
                tmp.append(s[j + 1])
            else:
                tmp[-1] += s[j + 1]

        tmp_ans = 0
        for ti in tmp:
            tmp_ans += int(ti)
        ans.append(tmp_ans)

    print(sum(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

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

pattern = []
for i in range(2 ** (n - 1)):
    temp = [0] * (n - 1)
    for j in range(n - 1):
        if (i >> j) & 1:
            temp[j] = 1
    pattern.append(temp)

ans = 0
for p in pattern:
    sum = s[0]
    for i in range(n - 1):
        if p[i]:
            sum += '+'
        sum += s[i + 1]
    ans += eval(sum)

print(ans)

Submission status: Accepted

Solution code:
S = list(input())
l = len(S)
sub = []
for i in range(2 ** (l-1)):
    chk = []
    for j in range(l):
        chk.append(S[j])
        if i >> j & 1:
            chk.append('+')
    sub.append(''.join(chk))
ans = [eval(a) for a in sub]
print(sum(ans))

Submission status: Accepted

Solution code:
import itertools
n=list(str(input()))
ans=0
lst=list(itertools.product(["", "+"], repeat=(len(n)-1)))
for i in range(len(lst)):
  just=""
  for k in range(len(n)-1):        
    just+=n[k]+str(lst[i][k])
  just+=n[len(n)-1]
  ans+=eval(just)
print(ans)

Submission status: Accepted

Solution code:
s = input()
pat = [bin(i)[2:].zfill(len(s)-1) for i in range(2**(len(s)-1))]
ans = 0
if len(s) == 1:
    print(int(s))
    exit()
for cond in pat:
    cnt = 0
    now = int(s[0])
    for i in range(len(cond)):
        if cond[i] == "0":
            now *= 10
            now += int(s[i+1])
        else:
            cnt += now
            now = int(s[i+1])
    cnt += now
    ans += cnt
print(ans)

Submission status: Accepted

Solution code:
import copy
S = input()
EX = ' '.join(list(S))
EX = list(EX)
sum = 0
for i in range(2 ** (len(S)-1)):
    P = copy.deepcopy(EX)
    for j in range((len(S)-1)):
        if ((i >> j) & 1):
            P[j*2+1] = '+'
    sum += eval(''.join(P).replace(' ',''))
print(sum)

Submission status: Accepted

Solution code:
import itertools
S = input()

sumAns = 0
for bit in itertools.product([0, 1], repeat=len(S) - 1):
    ans = 0
    start = 0
    for fin in range(len(bit)):
        if bit[fin] == 1:
            ans += int(S[start: (fin + 1)])
            start = fin + 1
    ans += int(S[start:])

    sumAns += ans

print(sumAns)

Submission status: Accepted

Solution code:
from sys import stdin
def S(): return stdin.readline().rstrip()

def g(s):
    l = len(s)
    n = 2**l
    sum = 0
    for j in range(n):
        buff = ''
        for i in range(l):
            if j&(1<<i):
                buff += '+'
            else:
                buff += s[i]
        buff = buff.split('+')
        for _ in range(len(buff)):
            tmp = buff.pop()
            if tmp!='':
                sum += int(tmp)
    return sum


s = S()
ans = g(s)
print(ans)

Submission status: Accepted

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

  formula = ''
  for j in range(op):
    formula += s[j] + opm[j]
  formula += s[-1]
  ans += eval(formula)

print(ans)

Submission status: Accepted

Solution code:
def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split("+"))))
    # 式 f の末尾に "+" を追加するかしないかして次の数字を追加
    return dfs(i + 1, f + s[i + 1]) + \
           dfs(i + 1, f + "+" + s[i + 1])
s = input()
n = len(s)
print(dfs(0, s[0]))

Submission status: Accepted

Solution code:
def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split("+"))))
    # 式 f の末尾に "+" を追加するかしないかして次の数字を追加
    return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + "+" + s[i + 1])
s = input()
n = len(s)
print(dfs(0, s[0]))

Submission status: Accepted

Solution code:
S = input()
n = len(S) - 1
total = 0
for i in range(1 << n):
    t = S[0]
    for j in range(n):
        if (i >> j) & 1:
            t += '+' + S[j + 1]
        else:
            t += S[j + 1]
    total += eval(t)

print(total)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

s=input()
n=len(s)
que=deque()
que.append([0,s[0]])
ans=0
while len(que):
    q=que.popleft()

    if q[0]==n-1:
        ans+=sum(list(map(int, q[1].split("+"))))
    else:
        que.append([q[0]+1,q[1]+s[q[0]+1]])
        que.append([q[0]+1,q[1]+"+"+s[q[0]+1]])
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()
lenn = len(n)
ans = 0
for i in range(2**(lenn-1)):
    now = int(n[0])
    count = 0
    for j in range(lenn-1):
        if (i >> j) & 1 == 1:
            count += now
            now = int(n[j+1])
        elif (i >> j) & 1 == 0:
            now = now*10 + int(n[j+1])
    ans += count + now
print(ans)

Submission status: Accepted

Solution code:
S=list(input())
ans=0

for x in range(2**(len(S)-1)):
  bin_x = str(format(x,str(len(S)-1)+"b"))[::-1]
  
  l=0
  res=0
  for r,i in enumerate(bin_x):
    if i == "1":
      res+=int("".join(S[l:r+1]))
      l=r+1
  res+=int("".join(S[l:len(S)]))
  ans+=res
print(ans)

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
from fractions import gcd
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

from itertools import permutations
from math import factorial, hypot

#############
# Main Code #
#############

S = input()

def dfs(i, s):
    global ans
    if i == len(S):
        lista = list(map(int, s.split("+")))
        return sum(lista)
    else:
        return dfs(i + 1, s + S[i]) + dfs(i + 1, s + '+' + S[i])
print(dfs(1, S[0]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A=[int(x) for x in input()]
n=len(A)-1
P=[]
for i in range(2**n):
    L=['']*n
    for j in range(n):
        if (i>>j)&1:
            L[j]='+'
    formula=''
    for a,b in zip(A,L+['']):
        formula+=(str(a)+b)
    P.append(eval(formula))
print(sum(P))

Submission status: Accepted

Solution code:
import itertools

S = int(input())

ans = 0
cnt = 0

for i in itertools.product([0,1], repeat = len(str(S)) - 1):
    A = str(S)
    cnt = 0
    for x, sign in enumerate(i):
        if sign == 0:
            cnt += 1
            if x == len(str(S)) - 2:
                ans += int(A[0:cnt+1])
        else :
            ans += int(A[0:cnt+1])
            cnt = 0
            A = str(S)[x+1:]
            if x == len(str(S)) - 2:
                ans += int(A[-1])

if len(str(S)) == 1:
    print(S)
else:
    print(ans)

Submission status: Accepted

Solution code:
S=input()
ans=0
for i in range(2**(len(S)-1)):
    tmp=S[0]
    for j in range(len(S)-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)
ans = 0
for i in range(2**(n-1)):
    now = int(s[0])
    cou = 0
    for j in range(n-1):
        if (i >> j) & 1 == 1:
            cou += now
            now = int(s[j+1])
        elif (i >> j) & 1 == 0:
            now = now*10 + int(s[j+1])
    ans += cou + now
print(ans)

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

S = S()

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

ans = 0
for b in range(1<<(N-1)):
  rangelist = []
  for i in range(N-1):
    if (b>>i)&1:
      rangelist.append(i+1)
  rangelist.append(N)
  for i in range(len(rangelist)):
    if i == 0:
      ans += int(S[:rangelist[i]])
    else:
      ans += int(S[rangelist[i-1]:rangelist[i]])
print(ans)

Submission status: Accepted

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

#125の場合、1<ここ>2<ここ>5で2箇所に+が入るか否かの2**(N-1)通りのbit全探索
for i in range(2**(N-1)):
    #最終的に1<>2<>5の5の部分がtmp_Sに残る。これをあとで足す
    tmp_S = ""
    #1+2+5をans+=1,ans+=2としたいところでans+=12とならないようにcheck_jを残す
    check_j = 0
    for j in range(N-1):
        if i >> j & 1:
            ans += int(S[check_j:j+1])
            check_j = j+1
            tmp_S = S[j+1:]
    if tmp_S:
        ans += int(tmp_S)

# 最後に+が0個のパターンを足す
ans += int(S)
print(ans)

Submission status: Accepted

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

for i in range(1, 2**(N-1)):
    tmp_S = ""
    checked_j = 0
    for j in range(N-1):
        if i >> j & 1:
            ans += int(S[checked_j:j+1])
            checked_j = j+1
            tmp_S = S[j+1:]
    if tmp_S:
        ans += int(tmp_S)

ans += int(S)
print(ans)

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	#b , c = tin()
	s = input()
	ret=0
	for i in range(len(s)):
		for j in range(i, len(s)):
			#print(i,len(s)-j-1,s[i:j+1])
			v = int(s[i:j+1])
			if i >= 1:
				na =2 ** (i-1)
			else:
				na=1
			
			if len(s)-j-1 >= 1:
				nb= 2**(len(s)-j-2)
			else:
				nb=1
			ret += v*na*nb
			#print(na,nb)
	print(ret)
			
		
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
n=len(s)
def dfs(i,f):
    if i==n-1:
        return sum(list(map(int,f.split("+"))))

    return dfs(i+1,f+s[i+1])+dfs(i+1,f+"+"+s[i+1])
print(dfs(0,s[0]))

Submission status: Accepted

Solution code:
s = input()
sl = len(s) - 1
loop = 2 ** sl
total = 0
for i in range(loop):
    x = ''
    for index, num in enumerate(s):
        x += num
        if (i >> index) & 1:
            x += '+'

    total += eval(x)

print(total)

Submission status: Accepted

Solution code:
##2^(|S|-1)
from copy import deepcopy
from collections import deque

S = input()

s = deque([])
for i in S:
    s += [i]
    s += [""]
s.pop()

ans = 0
l = len(S)

for n in range(2**(l-1)):
    tmp = deepcopy(s)
    for i in range(l-1):
        if (n>>i)&1:
            tmp[2*i+1] = "+"
    ans += eval("".join(tmp))

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()

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

Submission status: Accepted

Solution code:
#s='125'
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)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

S = input()

def gen(s):
    l = len(s)

    for i in range(1, l):
        c = int(s[0: i])
        for v in gen(s[i:]):
            yield c + v

    yield int(s)

print(sum(gen(S)))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
N=len(S)
ans=0
for i in range(2**(N-1)):
  formula=S[0]
  q="{:0>10b}".format(i)[::-1]
  #1<=N<=10なので長さは10で良い
  #また前から見て"+"を入れるか否か決定する為後ろ向きに並び替える
  for j in range(1,N):
    if int(q[j-1])&1:
      formula+="+"
      #qの見ている桁が1ならば"+"を入れる
    formula+=S[j]
    #次の桁を式に入れる
  ans+=eval(formula)    
print(ans)

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
import itertools as it
#======================================================#
def main():
    s = IS()
    n = len(s)

    def calc(bits):
        sumv = 0
        for i in range(len(bits)-1):
            sumv += int(s[bits[i]:bits[i+1]])
        return sumv

    ans = 0
    for bit in range(1<<(n-1)):
        bits = [0]
        for i in range(n-1):
            if bit&(1<<i):
                bits.append(i+1)
        bits += [n]
        ans += calc(bits)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
num = input()

def enum(num):  # str -> list[str]
    enumerated = [num]
    for i in range(1, len(num)):
        head = num[:i]
        for tail in enum(num[i:]):
            enumerated.append(head + '+' + tail)
    return enumerated

candidates = enum(num)
ans = sum([eval(eq) for eq in candidates])
print(ans)

Submission status: Accepted

Solution code:
import itertools
S=list(input())

answer=0
for perm in itertools.product([True,False],repeat=len(S)-1):
  #print(perm)
  eval_str=""
  for i in range(len(S)-1):
    eval_str+=S[i]
    if perm[i]:
      eval_str+="+"
  eval_str+=S[len(S)-1]
  
  #print(eval_str)
  answer+=eval(eval_str)
  
print(answer)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
s = input()
plus_len = len(s) - 1
num_search = 2 ** plus_len
result = 0
for i in range(num_search):
  x = ''
  for index,value in enumerate(s):
    x += value
    if (i >> index) & 1:
      x += '+'
  
  #print(x)
  #print(eval(x))
  result += eval(x)
print(result)

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
ans = 0
for i in range(N):
    l = []
    c = 0
    now = pow(2,N-1)
    while c < i:
        now //= 2
        l.append(now)
        c += 1
    l.append(now)
    for j in range(len(l)):
        ans += int(S[N-i-1])*pow(10,j)*l[j]
print(ans)

Submission status: Accepted

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

s = input()
n = len(s)

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

Submission status: Accepted

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

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

  shiki=''
  for i,j in zip(s,bag+['']):
    shiki+=(i+j)
  
  ans+=eval(shiki)

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.getrecursionlimit()

def dfs(i,s=''):
  global ans
  if i==len(t)-1:
    s+=t[-1]
    ans+=eval(s)
  else:
    dfs(i+1,s+t[i])
    dfs(i+1,s+t[i]+'+')

ans=0
t=list(input())
dfs(0,s='')
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s) - 1
ans = 0
for i in range(1,1<<n):
    l = [0]
    dummy = 0
    for j in range(n):
        if i>>j & 1 == 1:
            l.append(n-j)
    l.append(n+1)
    l.sort()
    # print(bin(i))
    # print(l)
    for i in range(len(l)-1):
        dummy += int(s[l[i]:l[i+1]])
    # print(bin(i),dummy)
    ans += dummy
print(ans+int(s))

Submission status: Accepted

Solution code:
S = input()
# 2^(|S|-1)のbit全探索
ans = 0
N = len(S)

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

Submission status: Accepted

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

ans = 0

for bit in range(1 << l - 1):
    f = s[0]

    for i in range(l - 1):
        if bit & (1 << i):
            f += '+'
        f += s[i + 1]
    ans += sum(list(map(int, f.split('+'))))

print(ans)

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

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

# import numpy as np
# import math

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

ss = []
for l in s:
    ss.append(l)
    ss.append('')
s_list = ss[:-1]
s_list_tmp = s_list.copy()

d = 0

for i in range(1<<n):
    s_list_tmp = s_list.copy()
    for k in range(n): # 桁数でループ
        if i>>k&1:
            # print(bin(i), k)
            s_list_tmp[2*k+1] = '_'
    s_str = ''.join(s_list_tmp)
    p_str = s_str.split('_')
    p_list = list(map(int, p_str))
    d += sum(p_list)

print(d)




# A, B = map(int, input().split())
# L = list(map(int, input().split()))




# print(ans)

Submission status: Accepted

Solution code:
S=list(input())
S=[int(i) for i in S]
n=len(S)
ans=0
if n!=1:
    for k in range(1,n+1):#上からk桁目
        for j in range(n-k):#10のj乗（n-k桁まで)
            ans+=S[k-1]*(10**j)*(2**(n-2-j))
        ans+=S[k-1]*(10**(n-k))*(2**(k-1))#n-k+1桁
    print(int(ans))
else:print(S[0])

Submission status: Accepted

Solution code:
from itertools import product
s=input()
N=len(s)
res = 0
gen = [0,1]
for ls in product(gen, repeat=N-1):
    tmp = int(s[0])
    tmpsum = 0
    for i in range(1,N):
        if ls[i-1]==0:
            tmp = 10*tmp + int(s[i])
        else:
            tmpsum += tmp
            tmp = int(s[i])
    tmpsum += tmp
    res += tmpsum
print(res)

Submission status: Accepted

Solution code:
import numpy as np
def g(a,s,n):
    if len(s)<=n:
        return 0
    elif n==0:
        return a+int(s)
    elif n==len(s)-1:
        y=a
        for i in range(len(s)):
            y+=int(s[i:i+1])
        return y
    else:
        y=0
        for i in range(1,len(s)):
            y+=g(a+int(s[:i]),s[i:],n-1)
        return y
def f(s):
    a=0
    for i in range(len(s)):
        b=g(0,s,i)
        a+=b
    return a
def main():
    S=str(input())
    print(f(S))

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
N = len(S) - 1
ans = 0
for i in range(2**N):
  now = S[0]
  for j in range(N):
    if i & 1:
      ans += int(now)
      now = S[j+1]
    else:
      now += S[j+1]
    i >>= 1
  ans += int(now)

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin


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

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    N = len(S)-1

    ret = 0
    for n in range(1 << N):
        fml = ''
        for m in range(len(S)):
            fml += S[m]
            if n >> m & 1:
                 fml += '+'
        ret += eval(fml)
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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)