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:
import sys
import string
import time


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


def I():
    return int(input())


def S():
    return input()


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


def MS():
    return map(str, input().split())


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


def LI_():
    return [int(i) - 1 for i in input().split()]


def StoI():
    return [ord(i) - 97 for i in input()]


def ItoS(nn):
    return chr(nn + 97)


N = {False: 'No', True: 'Yes'}
MOD = 10 ** 9 + 7
inf = float('inf')
IINF = 10 ** 10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10 ** 6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


def main():
    s = S()
    ans = 0
    # there're 2^(n-1) patterns
    for i in range(2 ** (len(s) - 1)):
        idx = 0
        rng = 1
        # we must scan all spaces between each number
        for n in range(len(s) - 1):
            if (1 << n) & i:
                ans += int(s[idx:idx + rng])
                idx += rng
                rng = 1
            else:
                rng += 1
        ans += int(s[idx:idx + rng])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

    for i in range(1 << n-1):
        temp = 0
        for j in range(n-1):
            if i & (1 << j):
                ans += int(''.join(s[temp:j+1]))
                temp = j+1
        ans += int(''.join(s[temp:]))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
s = input()
# 計算
ans = 0
for i in range(2**(len(s)-1)):
    A = s[0]
    for j in range(len(s)-1):
        if (i >> j) & 1:
            A += '+'
        A += s[j+1]
    ans += eval(A)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
S = list(input())

Ans = 0

for i in range(2**(len(S)-1)):
    W = [""]*(len(S)-1)
    for j in range(len(S)-1):
        #print(i,j)
        if ((i >> j) & 1):
            W[j] = "+"
    #print(W)
    formula = ""
    for k,l in zip(S,W+[""]):
        formula += (k+l)
    Ans += eval(formula)

print(Ans)

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
S = input()
cnt=0
result = 0
for i in range(2**(len(S)-1)):
  mark_list = S[0]
  for j in range(len(S)-1):
    if (i>>j)&1 == 1:
      mark_list+="+"+S[j+1] 
    else:
      mark_list+=S[j+1]
  result+=eval(mark_list)
print(result)

Submission status: Accepted

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

for i in range(1 << (len(S) - 1)):
    num = [S[0]]

    for j in range(len(S) - 1):
        if ((i >> j) & 1):
            num.append(S[j + 1])
        else:
            num[-1] += S[j + 1]
    ans += sum([int(n) for n in num])

print(ans)

Submission status: Accepted

Solution code:
s = list(str(input()))
ans = 0
if len(s) == 1:
  print(int(s[0]))
else:
  for i in range(2**(len(s)-1)):
    a = 0
    bin_str = format(i, 'b').zfill(len(s)-1)
    for num,j in enumerate(bin_str):
      if j == "1":
        ans += sum([int(k)*10**(num-a-l) for l,k in enumerate(s[a:num+1])]) 
        a = num+1
      if num == len(bin_str)-1:
        ans += sum([int(k)*10**(num-a+1-l) for l,k in enumerate(s[a:num+2])])
  print(ans)

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
import sys
S=input()

def allbitCalc(N):
    allbit = []
    for i in range(2**N):
        bit = [0] * N
        for j in range(N):
            if (i >> j) & 1:
                bit[j] = 1
        allbit.append(bit)
    return allbit

def split(S,bit):
    n=len(S)
    terms=[]
    cnt=1;s=int(S[n-1])
    for i,b in enumerate(bit):
        if b==0:
            s+=int(S[n-i-2])*10**cnt
            cnt+=1
        else:
            terms.append(s)
            s=0;cnt=0
            s+=int(S[n-i-2])*10**cnt
            cnt+=1

    terms.append(s)
    return(sum(terms))
        
summ=0
allb=allbitCalc(int(len(S))-1)
for ab in allb:
    tmp=split(S,ab)
    summ+=tmp

print(summ)

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:
# bit全探索の解法
s = input()
# "+"は数字の間にしか入らないので、n-1で調べる
n = len(s) -1

ans = 0
for bit in range(1<<(n)):
    f = s[0]
    for i in range(n):
        if (bit >> i) & 1 :
            f += "+"
        f += s[i + 1]
    #print(f)
    ans += eval(f)

print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/arc061/tasks/arc061_a
S = input()
op_cnt = len(S) - 1
ops = []
for i in range(2 ** op_cnt):
    op = [""] * op_cnt
    for j in range(op_cnt):
        if (i >> j) & 1:
            op[j] = "+"
    ops.append(op)

# print(ops)


def eval_fomula(S, op):
    s = list(S)
    count = 1
    for i in range(len(s) - 1):
        s.insert(i+count, op[i])
        count += 1
    fomula = ""
    for k in range(len(s)):
        fomula += s[k]

    return eval(fomula)


total = 0
for i in range(2 ** op_cnt):
    total += eval_fomula(S, ops[i])

print(total)

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:
#文字列(str)で入力
s = input()
#文字列の間なので1を引く
n = len(s) - 1
ans = 0

#bit全検索
for bit in range(2 ** n):
    f = s[0]
    for i in range(n):
        #if bit & (1 << i):
        mask = 1 << i
        if bit & mask:
            f += "+"
        f += s[i + 1]
        
    ans += eval(f)

print(ans)

Submission status: Accepted

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

ans = 0

for bit in range(2 ** n):
    f = s[0]
    for i in range(n):
        if bit & (1 << i):
            f += "+"
        f += s[i + 1]
        
    ans += eval(f)
    #ans = ans + sum(map(int, f.split("+")))
    #print(ans)

print(ans)

Submission status: Accepted

Solution code:
s = input()

def fun(s):
    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('+')))

    return ans

print(fun(s))

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/arc061/tasks/arc061_a
# -*- coding: utf-8 -*-
import itertools
S = input()
ans = 0
bit_list = list(itertools.product([0,1], repeat=len(S)-1))
for bits in bit_list:
  A =[]
  bits = list(bits)
  bits.append(0)
  for i in range(len(S)):
    A.append(S[i])
    if bits[i] == 1: A.append("+")
  ans += eval("".join(A))
print(ans)

Submission status: Accepted

Solution code:
import itertools

def solve(S):
    '''
    数字の間に+を入れるパターンと入れないパターンを全てチェックする
    125であれば、 125, 1+25, 12+5, 1+2+5
    +が入る可能性のある場所は右の通り、 1  |ここ!| 2  |ここ!| 5
    よって、組み合わせは 2 ** (文字列数 - 1)
    '''
    
    if len(S) == 1:
        print(int(S))
    else:
        count = 0
        bit_list = list(itertools.product([0, 1], repeat=len(S)-1))
        for pattern in bit_list:
            '''
            ビットの値が1の時に+が入ると考えて、0の時は入らない
            文字列を先頭から調べていき、次の文字との間に+が入る場合、そこまでの文字列をint型に変換して変数「count」に加算する
            +が入る場所の次の文字をstartに記録する
            
            '''
            start = 0
            for end in range(len(pattern)):
                if pattern[end] == 1:
                    count += int(S[start:end+1])
                    start = end + 1
    
            count += int(S[start:])

        print(count)


if __name__ == '__main__':
    S = input()
    solve(S)

Submission status: Accepted

Solution code:
import itertools

def solve(S):
    '''
    数字の間に+を入れるパターンと入れないパターンを全てチェックする
    125であれば、 125, 1+25, 12+5, 1+2+5
    +が入る可能性のある場所は右の通り、 1  |ここ!| 2  |ここ!| 5
    よって、組み合わせは 2 ** (文字列数 - 1)
    '''
    
    if len(S) == 1:
        print(int(S))
    else:
        count = 0
        bit_list = list(itertools.product([0, 1], repeat=len(S)-1))
        for pattern in bit_list:
            '''
            ビットの値が1の時に+が入ると考えて、0の時は入らない
            文字列を先頭から調べていき、次の文字との間に+が入る場合、そこまでの文字列をint型に変換して変数「count」に加算する
            +が入る場所の次の文字をstartに記録する
            
            '''
            start = 0
            for end in range(len(pattern)):
                if pattern[end] == 1:
                    count += int(S[start:end+1])
                    start = end + 1

                if end == len(pattern) - 1:
                    count += int(S[start:])

        print(count)


if __name__ == '__main__':
    S = input()
    solve(S)

Submission status: Accepted

Solution code:
s = input()
nbit = len(s) - 1
ans = 0
for bit in range(1 << nbit):
    f = s[0]
    for i in range(nbit):
        if bit & (1 << i):
            f += "+"
        f += s[i+1]

    ans += sum(map(int, f.split("+")))

print(ans)

Submission status: Accepted

Solution code:
S=input()
N=len(S)
count=0
for i in range(2**(N-1)):
  A=S
  for j in range(N):
    if ((i >> j) & 1):
      A=A[:N-j-1]+" "+A[N-j-1:]
  #print(i,A)
  count += sum(list(map(int,A.split())))
print(count)

Submission status: Accepted

Solution code:
def cal(formula: str) -> int:
    nums = formula.split("+")
    ans = 0
    for n in nums:
        ans += int(n)
    return ans


def dfs(i: int, s: str, formula: str) -> int:
    if (i == len(s) - 1):
        return cal(formula)
    return dfs(i + 1, s, formula + s[i + 1]) + dfs(i + 1, s, formula + "+" + s[i + 1])


S = input()
print(dfs(0, S, S[0]))

Submission status: Accepted

Solution code:
ans=0
def dfs(lim,cnt,p):
    P=p.copy()
    global ans
    if(cnt==lim):
        res=''
        for x,y in zip(S,P):
            res+=x+y
        ans+=eval(res)
        return
    dfs(lim,cnt+1,P)
    P[cnt]='+'
    dfs(lim,cnt+1,P)
    
S=input()
p=['']*(len(S))
dfs(len(S)-1,0,p)
print(ans)

Submission status: Accepted

Solution code:
s = str(input())
ans = 0
for i in range(2 ** (len(s) - 1)):
    num = [s[0]]
    for j in range(len(s) - 1):
        if ((i >> j) & 1): #+を挿入
            num.append(s[j + 1])
        else: #文字を結合
            num[-1] += s[j + 1]
    ans += sum(list(map(int, (num[i] for i in range(len(num))))))
print(ans)

Submission status: Accepted

Solution code:
S = input()
if len(S) == 1:
  print(int(S))
  exit()
else:
  def count(n):
    a = 0
    if len(n) == 1:
      return 0
    else:
      for i in range(1, len(n)):
        a += int(n[:i]) * 2 ** (len(n[i:]) - 1) + int(n[i:]) + count(n[i:])
      return a
  print(int(S) + count(S))

Submission status: Accepted

Solution code:
S = input()
if len(S) == 1:
  print(int(S))
else:
  def count(n):
    a = 0
    if len(n) == 1:
      return 0
    else:
      for i in range(1, len(n)):
        a += int(n[:i]) * 2 ** (len(n) - 1 - i) + int(n[i:]) + count(n[i:])
      return a
  print(int(S) + count(S))

Submission status: Accepted

Solution code:
   
s=input()

if len(s)==1:
    print(int(s))
else:
    def count(num):
        # basecase
        if len(num)==1:
            return 0
        else:
            a=0
            for j in range(1,len(num)):
                a+=int(num[:j])*2**(len(num[j:])-1)+int(num[j:])+count(num[j:])
            return a
    ans=int(s)+count(s)
    print(ans)

Submission status: Accepted

Solution code:
S = input()
if len(S) == 1:
  print(int(S))
  exit()
else:
  def count(n):
    if len(n) == 1:
      return 0
    else:
      a = 0
      for i in range(1, len(n)):
        a += int(n[:i]) * 2 ** (len(n) - 1 - i) + int(n[i:]) + count(n[i:])
      return a
  ans = int(S) + count(S)
  print(ans)

Submission status: Accepted

Solution code:
S = input()
if len(S) == 1:
  print(int(S))
  exit()
else:
  def count(n):
    a = 0
    if len(n) == 1:
      return 0
    else:
      for i in range(1, len(n)):
        a += int(n[:i]) * 2 ** (len(n) - 1 - i) + int(n[i:]) + count(n[i:])
      return a
  print(int(S) + count(S))

Submission status: Accepted

Solution code:
s=input()
n=len(s)
l=[[] for _ in range(2**(n-1))]
for b in range(2**(n-1)):
    x=b
    for i in range(n-1):
        if x%2==1:
            l[b].append(1)
        else:
            l[b].append(0)
        x//=2
#print(l)
indexes=[[] for _ in range(2**(n-1))]
for k in range(2**(n-1)):
    indexes[k]=[i for i, x in enumerate(l[k]) if x == 1]
#print(indexes)
SUM=0
for j in range(2**(n-1)):
    L=len(indexes[j])
    if L==0:
        SUM+=int(s)
        #print(SUM)
    else:
        SUM+=int(s[:indexes[j][0]+1])
        #print(SUM)
        SUM+=int(s[indexes[j][L-1]+1:])
        #print(SUM)
        if L>1:
            for h in range(L-1):
                SUM+=int(s[indexes[j][h]+1:indexes[j][h+1]+1])
                #print(SUM)
print(SUM)

Submission status: Accepted

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

ans=0
for i in range(2**(l-1)):
  x=n[0]
  for j in range(l-1):
    if((i>>j)&1):
      x+="+"
    x+=n[j+1]
  ans+=eval(x)
  
print(ans)

Submission status: Accepted

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

def cal(l):
    c = ''
    for i in range(len(l)):
        if i%2==0:
            c += l[i]
        else:
            if l[i]==1:
                c += '+'
    return eval(c)

ans = 0
for i in range(1<<N):
    cond = [0]*N
    for j in range(N):
        if 1&(i>>j):  # 右シフトして論理積（bit全探索）
            cond[j] = 1
    tmp = []
    for i in range(N):
        tmp.append(S[i])
        tmp.append(cond[i])
    tmp.append(S[-1])

    ans += cal(tmp)

print(ans)

Submission status: Accepted

Solution code:
import itertools
s = input()
ans = 0
for plus in itertools.product(['', '+'], repeat=len(s)-1):
    formula = s[0]
    formula += "".join([op+num for op, num in zip(plus, s[1:])])
    ans += eval(formula)
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
f = ''
for i in range(2**(n-1)):
  b = format(i, 'b').zfill(n)
  for j in range(n):
    if b[j] == '1':
      f += '+' + s[j]
    else:
      f += s[j]
  f+= '+'
print(eval(f[:len(f)-1]))

Submission status: Accepted

Solution code:
INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  heapq import heappop,heapify,heappush
from bisect import bisect_left

def main():
    s = input()
    l = len(s) - 1
    ans = 0
    for bit in range(1 << l):
        op = []
        for i in range(l):
            if (bit>>i)&1:
                op.append('+')
            else:
                op.append('')
        
        formula = s[0]
        for i in range(l):
            formula += op[i]
            formula += s[i + 1]
        
        ans += eval(formula)
    
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

import itertools

equation_str = []

plus_add_position = []

for i in range(len(S)):
    plus_add_position.extend(list(itertools.combinations(range(len(S)-1), i)))

for v in plus_add_position:
    if v==tuple():
        equation_str.append(S)
    else:
        eq = S[0]
        for i in range(len(S)-1):
            if i in v:
                eq += '+' + S[i+1]
            else:
                eq+= S[i+1]
        equation_str.append(eq)

ans = 0
for eq in equation_str:
    term = list(map(int, eq.split('+')))
    ans += sum(term)

print(ans)

Submission status: Accepted

Solution code:
S = input()

total = 0

for m in range(1 << len(S) - 1):
  acm = ''
  for i, c in enumerate(S):
    acm += c
    if 1 << i & m:
      total += int(acm)
      acm = ''
  if acm:
    total += int(acm)
    
print(total)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = list(input())
l = len(S)

if l == 1:
    print(int(S[0]))
    exit()

A = []
for i in range(2**(l-1)):
    B = []
    for j in range(l-1):
        if (i>>j) & 1:
            B.append(1)
        else:
            B.append(0)
    A.append(B)

ans = 0

for i in range(2**(l-1)):
    C = []
    a = S[0]
    for j in range(l-1):
        if j != l-2:
            if A[i][j] == 0:
                a += S[j+1]
            else:
                C.append(a)
                a = S[j+1]
        else:
            if A[i][j] == 0:
                a += S[j+1]
                C.append(a)
            else:
                C.append(a)
                C.append(S[j+1])
    for j in C:
        ans += int(j)

print(ans)

Submission status: Accepted

Solution code:
def resolve():
    s = input()
    print(
        sum(
            eval(s)
            for s in [
                "".join(
                    s[i] + "+" if i < 9 and 1 << i & b else s[i] for i in range(len(s))
                )
                for b in range(2 ** (len(s) - 1))
            ]
        )
    )


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
S = input()
N = len(S)
total = 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]
  total += sum(map(int, f.split('+')))

print(total)

Submission status: Accepted

Solution code:
n = list(input())
op = len(n) - 1
total = 0
for i in range(2 ** op):
    op_l = [''] * op
    for j in range(op):
        if (i >> j) & 1:
            op_l[j] = '+'
    
    formula = '' 
    for s, k in zip(n, op_l + ['']):
        formula += s + k
    
    total += eval(formula)
print(total)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
S = input().strip()

ans = 0

for bit in range(2 ** (len(S) - 1)):
    th = [0]
    for i in range(len(S) - 1):
        if bit & (0x01 << i):
            th.append(i + 1)
    th.append(len(S))
    
    ans += sum([int(S[th[i]: th[i + 1]]) for i in range(len(th) - 1)])

print(ans)

Submission status: Accepted

Solution code:
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:
S = list(input())

def f(a,c,i):
    if i == len(S)-1:
        return(a + int(S[i]) + c)
    else:
        return(f(a+c+int(S[i]),0,i+1)+f(a,10*(c+int(S[i])),i+1))


print(f(0,0,0))

Submission status: Accepted

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

if n == 1:
    sumofall = int(s)
else:
    sumofall = 0
    for i in range(1 << (n-1)):
        j_before = 0
        for j in range(1, n):
            if (1 << (j-1)) & i:
                sumofall += int(s[j_before:j])
                j_before = j
        sumofall += int(s[j_before:])

print(sumofall)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
import copy
S = list(input())
s = copy.copy(S)
p = len(S) - 1
ans = 0
for i in range(2**p):
    s = copy.copy(S)
    
    for j in range(p):
        if((i >> j) & 1):
            s.insert(p - j, "+")
            
    tmp = "".join(s)
    ans += eval(tmp)

print(ans)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy


def resolve():
	src = input()
	ans = 0
	for i in range(1 << len(src)-1):
		s = copy.copy(src)
		trim_size = 1
		for j in range(len(s)-1):
			if (i >> j) & 1 and len(s):
				ans += int(s[:trim_size])
				s = s[trim_size:]
				trim_size = 1
			else:
				trim_size += 1
		if len(s):
			ans += int(s)
	print(ans)
resolve()

Submission status: Accepted

Solution code:
s=input()
t=len(s)-1
sl=[s[i] for i in range(len(s))]
answers=[]

for i in range(2**t):
  tmp=[]
  for j in range(t):
    if (i>>j)&1:
      tmp.append(j)
  ll=['*'] * len(s)
  for k in tmp:
    ll[k]="+"
  ans=[]
  
  for k,_ in zip(sl,ll):
    ans.append(k)
    ans.append(_)
  ans=[_ for _ in ans if _ != "*"]
  ans=''.join(ans)
  ans=ans.split('+')
  ans=[int(k) for k in ans if k != '+']
  ans=sum(ans)
  answers.append(ans)
  
print(sum(answers))

Submission status: Accepted

Solution code:
import sys
import itertools
import copy

sys.setrecursionlimit(10**7)
s=input()
n=len(s)-1
a=[]

def dfs(i,arr,j):
    if i==n:
        res=sum(arr+[int(s[j:])])
    else:
        res=dfs(i+1,arr,j)+dfs(i+1,arr+[int(s[j:i+1])],i+1)
    return res

def solve():
    print(dfs(0,a,0))

solve()

Submission status: Accepted

Solution code:
n = int(input())

keta = len(str(n))
ans = 0
#fugo =[0]*pow(2,keta-1)
for i in range(pow(2,keta-1)):
  shiki = str(n)[0]
  temp = [0]*(keta-1)
  for j in range(keta-1):
    if (i>>j)&1 == 1:
      temp[j] = "+"
    else:
      temp[j] = ""
    shiki += temp[j]+str(n)[j+1]
  ans += eval(shiki)


#for i in range(pow(2,keta-1)):
#  shiki = str(n)[0]
#  for j in range(keta-1):
#    shiki += fugo[i][j]+str(n)[j+1]
#  ans += eval(shiki)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

keta = len(str(n))
ans = 0
#fugo =[0]*pow(2,keta-1)
for i in range(pow(2,keta-1)):
  shiki = str(n)[0]
  temp = [0]*(keta-1)
  for j in range(keta-1):
    if (i>>j)&1 == 1:
      temp[j] = "+"
    else:
      temp[j] = ""
    shiki += temp[j]+str(n)[j+1]
  ans += eval(shiki)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

keta = len(str(n))

fugo =[0]*pow(2,keta-1)
for i in range(pow(2,keta-1)):
  temp = [0]*(keta-1)
  for j in range(keta-1):
    if (i>>j)&1 == 1:
      temp[j] = "+"
    else:
      temp[j] = ""
  fugo[i] = temp

ans = 0
for i in range(pow(2,keta-1)):
  shiki = str(n)[0]
  for j in range(keta-1):
    shiki += fugo[i][j]+str(n)[j+1]
  ans += eval(shiki)
print(ans)

Submission status: Accepted

Solution code:
l = [int(x) for x in list(str(input()))]


def manysum(n):
    if len(n) == 1:
        return n[0]
    a = n[0] * (2 ** (len(n) - 2)) + manysum(n[1:])
    n[1] += 10 * n[0]
    b = manysum(n[1:])

    return a + b

print(manysum(l))

Submission status: Accepted

Solution code:
S=str(input())
n=len(S)
N=2**(n-1)
L=[]#要素は全てn-1桁
for i in range(N):
    Bin=bin(i)[2:]
    Bin=(Bin[::-1]+'0'*max(0,(n-1)-len(Bin)))[::-1]
    L.append(Bin)

if n==1:
    ans=int(S)
else:
    ans=0
    for j in L:#0(1024)
        s=S
        f=0
        for k in range(1,n):#O(10)
            if k!=n-1:
                s=str(s)
                if j[k-1]=='1':
                    ans+=int(s[f:k])
                    f=k
            else:
                if j[k-1]=='1':
                    ans+=int(s[f:k])+int(s[k:])
                else:
                    ans+=int(s[f:])
            #print(j,k,ans)

print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)-1
nums = [s[0]]
box = []
for i in range(2**n):
  for j in range(n):
    if (i>>j)&1:
      nums.append("+")
      nums.append(s[j+1])
    else:
      nums.append(s[j+1])
  num = 0
  now = 0
  for k in nums:
    if k == "+":
      num += now
      now = 0
    else:
      now = 10*now + int(k)
  num += now
  box.append(num)
  nums = [s[0]]
print(sum(box))

Submission status: Accepted

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

res = 0

for i in range(2**n):
    f = ""
    for idx, j in enumerate(s):
        if i >> idx & 1:
            f += j + "+"
            continue
        f += j
    res += eval(f)

print(res)

Submission status: Accepted

Solution code:
s = input()
n = len(s)-1
N = []
total = 0
for i in range(2**n):
  nums = ""
  for j in range(n+1):
    nums+=s[j]
    if ((i>>j)&1):
      nums+="+"
  nums = nums.split("+")
  
  N.append([int(i) for i in nums])

for _ in N:
  total +=sum(_)
  
print(total)

Submission status: Accepted

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

def dfs(i, s, ans):
    if i==n:
        #print(i, 'bottom', s, ans)
        ans += sum([int(i) for i in s.split('+')])
        return False, ans
    else:
        #print(i, 'left',s, ans)
        tf, ans = dfs(i+1, s, ans)
        if tf:
            return True, ans
        else:
            #print(i, 'right',s, ans)
            p = i + s.count('+')
            s = s[:p]+'+'+s[p:]
            tf, ans = dfs(i+1,  s, ans)
            return tf, ans

_, a = dfs(i, s, ans)
print(a)

Submission status: Accepted

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

def dfs(i: int, t: str):
  if i == n-1: #i = n - 1に到達したら終了
    # + で区切った数字をint型に変換して足し算
    return sum(list(map(int, t.split('+'))))

  # 文字列で次の数字をそのまま連結するパターンと、+で区切るパターン
  return dfs(i+1, t+s[i+1]) + dfs(i+1, t + '+' + s[i+1])

# 初期値でsの一文字目を入れておく
print(dfs(0, s[0]))

Submission status: Accepted

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

for i in range(2**n):
    tmp=0
    for j in range(n):
        if ((i << j) & 2**(n-1)):  #上位からbit全探索
            tot+=int(s[tmp:j+1])
            tmp=j+1
        if j==n-1:
            tot+=int(s[tmp:])
if n==0:
    tot=int(s)
print(tot)

Submission status: Accepted

Solution code:
s=input()
n=len(s)-1
sum=0
List=[s[0]]
for i in range(2**n):
    for j in range(n):
        if (i>>j)&1:
            List+=["+"]+[s[j+1]]
        else:
            List+=[s[j+1]]
    m=0
    for h in List:
        if h=="+":
            sum+=m
            m=0
        else:
            m*=10
            m+=int(h)
    sum+=m
    List=[s[0]]
print(sum)

Submission status: Accepted

Solution code:
S = input()

x = len(S)-1

s = 0
for i in range(1 << x):
    t = 0
    for j in range(x):
        if (i >> j) & 1:
            s += int(''.join(S[t:j+1]))
            t = j+1
    s += int(''.join(S[t:]))
print(s)

Submission status: Accepted

Solution code:
S = input()

x = len(S)-1

s = 0
for i in range(1 << x):
    t = 0
    for j in range(x):
        if i & (1 << j):
            s += int(''.join(S[t:j+1]))
            t = j+1
    s += int(''.join(S[t:]))
print(s)

Submission status: Accepted

Solution code:
S = input()

x = len(S)-1

s = 0
for i in range(1 << x):
    t = 0
    for j in range(x):
        if ((i >> j) & 1 == 1):
            s += int(''.join(S[t:j+1]))
            t = j+1
    s += int(''.join(S[t:]))
print(s)

Submission status: Accepted

Solution code:
s = [int(i) for i in input()]
n = len(s) - 1
ans = 0
def cnt(bit):
  plus = [False]*n + [True]
  i = n-1
  while bit > 0:
    if bit&1:
      plus[i] = True
    bit = bit >> 1
    i -= 1
  ret = 0
  tmp = 0
  for i in range(n+1):
    tmp = tmp*10+s[i]
    if plus[i]:
      ret += tmp
      tmp = 0
  return ret
for i in range(2**n):
  ans += cnt(i)
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
sum = 0
for i in range(1<<n-1):  # n-1ビット左シフト (つまりn-1=2だと4, n-1=3だと8)
    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:
from sys import stdin
from math import factorial

#長さNのビット列を列挙する
def make_bit_line(N):
    output=[]
    for i in range(0, 2**N):
        temp_list = []
        bin_num = bin(i)[2:]
        for k in range(N-len(bin_num)):
            temp_list.append(0)
        for i in range(len(bin_num)):
            temp_list.append(int(bin_num[i]))

        output.append(temp_list)
    return output

def calc_val(S,bianry):
    total_num = 0
    last_pos = 0
    for i in range(len(binary)):
        if(binary[i]==1):
            total_num += int(S[last_pos:i+1])
            last_pos = i+1
    total_num+=int(S[last_pos:])
    return total_num




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

N = len(S)

total_sum = 0
bit_line = make_bit_line(N-1)

for binary in bit_line:
    total_sum += calc_val(S, binary)

print(total_sum)