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 = list(input())

x = len(S) #Sの長さ
y = x-1 #切れる場所の数
#print ('y', y)
S = [int(s) for s in S] #Sを文字列のリストから、数値のリストに変換

#print (S)
ans = 0
for i in range(0, x): #i番目の数に着目
    #print ('i', i)
    j=1
    a =S[i] #i番目の数をメモ
    while y-j >= i:
        #print('j', j)
        ans += a * (10 ** (j-1)) * (2**(y-j))
        j += 1
    if y-j < i:
        ans += a * (10 ** (j-1)) * (2 ** i)

print (ans)

Submission status: Accepted

Solution code:

from itertools import combinations


def read_input():
    s = input().strip()
    return s

def split_and_sum(s, indice):
    indice_e = [0] + indice + [10]

    result = []
    for start,end in zip(indice_e, indice_e[1:]):
        result.append(int(s[start:end]))

    return sum(result)

def submit():
    s = read_input()
    max_index = len(s)

    acc = 0
    for i in range(max_index):
        for c in combinations(range(1, max_index), i):
            acc += split_and_sum(s, list(c))

    print(acc)

if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
S = input()


def D2NC(D: int, N: int, link=False) -> list:
    alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    res = []
    while D > 0:
        if D % N > 9:
            tmp = alp[D % N - 10]
            res.insert(0, str(tmp))
        else:
            res.insert(0, str(D % N))
        D //= N
    if not res:
        res.append('0')
    if link:
        res = ''.join(res)
    return res


n = len(S)
Sum = 0
for i in range(2**(n-1)):
    op = D2NC(i, 2, link=True).zfill(n-1)
    idx = 0
    num = []
    for i in range(len(op)):
        if op[i] == '1':
            num.append(int(S[idx:i+1]))
            idx = i+1
    num.append(int(S[idx:]))
    Sum += sum(num)

print(Sum)

Submission status: Accepted

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

def solve(S):
    res = 0
    for i in range(1<<(len(S)-1)):
        A = []
        A.append(S[0])
        for j in range(len(S)-1):
            if((i>>j)&1):
                A.append("+")
                A.append(S[j+1])
            else:
                A.append(S[j+1])
        res += eval("".join(A))
    print(res)
                
if __name__ == '__main__':
    S = list(input())
    solve(S)

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math


S = str(input())
ret = 0

def solve(i,n,sm):
  if i == len(S)-1:
    return sum(sm+[n*10+int(S[i])])

  ret = 0
  # +を入れる
  ret += solve(i+1, 0, sm+[n*10+int(S[i])])
  # +を入れない
  ret += solve(i+1, n*10+int(S[i]), sm)
  return ret

if __name__ == "__main__":
  print(solve(0,0,[]))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
S = input()
N = 2 ** (len(S) - 1)
ans = 0
for i in range(N):
    l = ""  #空の文字列に挿入していく
    for j in range(len(S) - 1):
        l += S[j]
        if((i >> j) & 1):
            l += "+"
    l += (S[len(S) - 1])
    #print(l)
    li = list(map(int,l.split("+")))
    for num in li:
        ans += num

print(ans)

Submission status: Accepted

Solution code:
n=input()
m=[[]for _ in range(len(n))]
m[0]+=[[0,int(n[0])]]
for i in range(1,len(n)):
  a=int(n[i])
  for m0,m1 in m[i-1]:
    m[i]+=[[m0+m1,a]]
    m[i]+=[[m0,m1*10+a]]
ans=0
for m0,m1 in m[len(n)-1]:
  ans+=m0+m1
print(ans)

Submission status: Accepted

Solution code:
S = input()
leng = len(S) - 1
count = 0
for i in range(2 ** leng):
    op = [''] * leng
    for j in range(leng):
        if ((i >> j) & 1):
            op[-1 * (j + 1)] = '+'
    
    formula = ''
    for num, i in zip(S, op + ['']):
        formula += num + i
    count += eval(formula)
print(count)

Submission status: Accepted

Solution code:
s = input().rstrip()
length = len(s) - 1

ans = 0
for i in range(2**length):
    val = 0
    nums = s[:]
    prev_j = 0
    for j in range(length):
        if i >> j & 1:
            val += int(nums[prev_j:j+1])
            prev_j = j+1
    val += int(nums[prev_j:])
    ans += val
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque

def main():
    input = sys.stdin.readline
    S = [s for s in input().strip()]
    q = deque()

    s = S.pop(0)
    q.append(s)
    while len(S) > 0:
        s = S.pop(0)
        q_ = deque()
        while len(q) > 0:
            a = q.popleft()
            q_.append(a + s)
            q_.append(a + '+' + s)

        q = q_

    ans = 0
    for a in q:
        ans += sum([int(i) for i in a.split('+')])

    return ans


if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
S = input()
ans = 0

for bit in range(1 << (len(S) - 1)):
    left = 0
    sum_list = []
    for i in range(0, len(S) + 1):
        if (bit >> i) & 1:
            sum_list.append(int(S[left : i + 1]))
            left = i + 1
        elif i == len(S):
            sum_list.append(int(S[left:i]))
    ans += sum(sum_list)
print(ans)

Submission status: Accepted

Solution code:
S = int(input())
def ans(L):
    if len(list(str(L))) == 1:
        return(int(L))
    elif len(list(str(L))) == 2:
        LI = list(str(L))
        return(int(LI[0])+int(LI[1])+int(L))
    else:
        LI = list(str(L))
        SUM = 0
        for i in range(len(list(str(L)))):
            if i != len(list(str(L)))-1:
                LISTA = LI[0:i+1]
                LISTB = LI[i+1:len(list(str(L)))] 
                SUM += (2**(len(LISTB)-1))*int("".join(LISTA)) + ans(int("".join(LISTB)))
            else:
                SUM += L
        return(SUM)
    
print(ans(S))

Submission status: Accepted

Solution code:
s=input()
s2 = ''.join([c + ' ' for c in s])
res = 0
for i in range(2**(len(s)-1)):
  t = list(s2)
  for j in range(len(s)-1):
    if (i >> j) & 1:
      t[2*j+1] = '+'
  res += eval(''.join([c for c in t if c!=' ']))
print(res)

Submission status: Accepted

Solution code:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

s = ns()
ans = 0
for i in range(2 ** (len(s) - 1)):
    lis = list(bin(i)[2:].zfill(len(s) - 1))
    b = 0
    for j in range(len(lis)):
        if lis[j] == '1':
            ans += int(s[b:j + 1])
            b = j + 1
    ans += int(s[b:])
print(ans)

Submission status: Accepted

Solution code:
# dfs

def dfs(lst, char_n, i, tmp_sum):
    if i == len(lst):
        return tmp_sum + int(char_n)
    return dfs(lst, lst[i], i + 1, int(char_n) + tmp_sum) + dfs(lst, char_n + lst[i], i + 1, tmp_sum)


lst = [x for x in input()]
print(dfs(lst, lst[0], 1, 0))

Submission status: Accepted

Solution code:
# dfs

def dfs(lst_args, n_each_digit, i_num, n_calc):
    if i_num == len(lst_args):
        return n_calc + int(n_each_digit)
    return dfs(lst_args, lst_args[i_num], i_num + 1, int(n_each_digit) + n_calc) + dfs(lst_args, n_each_digit + lst_args[i_num], i_num + 1, n_calc)

lst = [x for x in input()]
print(dfs(lst, lst[0], 1, 0))

Submission status: Accepted

Solution code:
import itertools
A = list(input())
n = len(A)

if(n == 1):
  ans = A[0]

elif(n == 2):
  ans = int(A[0])+int(A[1])+int(A[0]+A[1])
  
else:
 Comb =  []
 for i in range(n-1):
  Comb.append(['','+'])
 Comb = list(itertools.product(*Comb))
 
 ans = 0
 for i in range(len(Comb)):
  tmp = list(Comb[i])
  tmp_list,tmp_str = [],A[0]
  for j in range(n):
   if(j != n-1):
    if(tmp[j] == ''): 
      tmp_str += A[j+1]
    elif(tmp[j] == '+'): 
      tmp_list.append(tmp_str)
      tmp_str = A[j+1]
   elif((j == n-1)and(j >= 2)):
      tmp_list.append(tmp_str) 
  tmp_list = list(map(int,tmp_list))
  ans += sum(tmp_list)
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
S = input()
N = len(S)
#演算子
oper = ['+','']
# 合計値
num = 0
#デカルト積,operatorの組み合わせの集合
oper_set = list(itertools.product(oper,repeat=N-1))
#オペレーターの組み合わせ分だけ回す
for i in range(len(oper_set)):
  x = ''
  for j in range(N-1):
    x += S[j] + oper_set[i][j]
  x += S[N-1]
  num += eval(x)


print(num)

Submission status: Accepted

Solution code:
def dfs(nums: list) -> int:
    if len(nums) == 1:
        return nums[0]

    # + を先頭の数字の後ろに入れる
    n1 = nums[0] * (1 << (len(nums) - 2)) + dfs(nums[1:])

    # + をいれない。
    headless = nums[1:]
    headless[0] += nums[0] * 10
    n2 = dfs(headless)

    return n1 + n2


def many_formulas(s: str) -> int:
    nums = list(map(int, s))
    return dfs(nums)


if __name__ == "__main__":
    s = input()
    ans = many_formulas(s)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
s = ""
S = input()
l = len(S)
S = list(S.zfill(10))
sum = 0
for i in range(2**(l-1)):
	i = list(str(format(i, "08b").zfill(9)))
	s = S[0]
	for j in range(len(i)):
		# print(S)
		# print(i)
		if i[j] == '1' and s != "": # 取り出す
			sum += int(s)
			s = S[j+1]
		else:
			s += S[j+1]
		# print(s)
	sum += int(s)
	# print(sum)
print(sum)

Submission status: Accepted

Solution code:
S = input()

def dfs(s):
    if len(s) == len(S) - 1:
        index = 0
        sum_v = 0
        for i, bl in enumerate(s):
            if bl == "1":
                sum_v += int(S[index:i + 1])
                index = i + 1
        sum_v += int(S[index:])
        return sum_v
    else:
        return dfs(s + "0") + dfs(s + "1")

print(dfs(""))

Submission status: Accepted

Solution code:
n=input()
ans=0
def dfs(i,flag):
  global ans
  if i!=len(n)-1:
    dfs(i+1,flag)
    dfs(i+1,flag|2**i)
  else:
    num=[]
    start=0
    for i in range(len(n)):
      if flag&2**i>0:
        num.append(int(n[start:i+1]))
        start=i+1
    if start!=n:
      num.append(int(n[start:]))
    ans+=sum(num)
dfs(0,0)
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce

def main():
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 一文字のみを読み込み
    # s = input().rstrip().split(' ')
    
    # スペース区切りで標準入力を配列として読み込み
    # s = input().rstrip().split(' ')

    # 位置文字ずつ標準入力を配列として読み込み
    s = list(input().rstrip())
    # N, A = [int(_) for _ in input().split()]
    # X = [int(_) for _ in input().split()]
    sum = 0
    for i in range(1 << len(s)-1):
        e = s[0]
        for j in range(len(s)-1):
            # iのうち、jbit目が立っているか
            if(i & (1 << j)):
                e = e + '+' + s[j+1]
            else:
                e = e + s[j+1]
        sum += eval(e)
        
    print(sum)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = list(input())

cand = []

#bit全探索
n = len(s) - 1
arr = [0] * n
for i in range(2 ** n):
    diff = 0
    for j in range(n):
        if((1&i>>j) == 1):
            arr[j] = 1
        else:
            arr[j] = 0
    #ここに処理
    s_copy = s[:]
    diff = 0
    for j in range(len(arr)):
        if arr[j] == 1:
            s_copy = s_copy[:(j+diff+1)] + ["+"] + s_copy[(j+diff+1):]
            diff += 1
    cand.append(s_copy)

cand_sum = []

for i in range(len(cand)):
    t = "".join(cand[i])
    tt = []
    tt = t.split("+")
    tt = list(map(int,tt))
    cand_sum.append(sum(tt))

print(sum(cand_sum))

Submission status: Accepted

Solution code:
s = str(input())
ans = 0
for i in range(1 << (len(s)-1)):
    si = s[0]
    for j in range(len(s)-1):
        if i & (1 << j):
            si += "+"+s[j+1]
        else:
            si += s[j+1]
    ans += eval(si)
print(ans)

Submission status: Accepted

Solution code:
import itertools
s=input()
C=['+','']
X=list(itertools.product(C,repeat=len(s)-1))
ans=0
for i in range(len(X)):
    res=''
    for j in range(len(s)-1):
        res+=s[j]+X[i][j]
    res+=s[len(s)-1]
    ans+=eval(res)

print(ans)

Submission status: Accepted

Solution code:
s=input();ans=0
def m(b):
  global s
  ans=""
  for i in range(len(s)-1):ans+=s[i]+("+"if b[i]=="1"else"")
  return eval(ans+s[-1])
for i in range(2**(len(s)-1)):ans+=m(bin(i)[2:].zfill(len(s)-1))
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

S=input()
n=len(S) #9文字

answer=0
for _l in product([0,1], repeat=n-1): #8個
  #print(_l)
  __l = [0] + list(filter(lambda x:_l[x-1], range(1,n))) + [n] #0,1,2,3,4,5,6,7
  #print(__l)
  answer += sum([int(S[__l[i]:__l[i+1]]) for i in range(len(__l)-1)])
  
print(answer)

Submission status: Accepted

Solution code:
S = input()
n = len(S)
if n == 1:
    print(S)
    quit()
import itertools as it
def sum_insert(x,S): 
    z = zip(S,x)
    L = []
    for x in z:
        L.append(x[0])
        if x[1] == '1':
            L.append('+')
    L.append(S[-1])
    s = ''.join(L)
    return eval(s)
ans = 0
variation = []
for i in range (2**(n-1)):
    variation.append(format(i,'b').zfill(n-1))

for x in variation:
    ans += sum_insert(x,S)
print(ans)

Submission status: Accepted

Solution code:
s = input()

res = int(s)
for i in range(1,len(s)):
    l = len(s)-i
    for j in range(len(s)-l+1):
        x = i-1
        if j>0 and j<len(s)-l:
            x -=1
        res+=int(s[j:j+l])*(2**x)

print(res)

Submission status: Accepted

Solution code:
""" AtCoder """

S = input()

l = ['+', '']

n = 2** (len(S) - 1)
ans = 0

for i in range(n):
    tmp = ''
    for j in range(len(S) - 1):
        tmp += S[j] + l[(i >> j) & 1]
    tmp += S[-1]
    ans += eval(tmp)

print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
for i in range(2 ** (len(S)-1)):
    bit = format(i, "b").zfill(len(S))[::-1]
    k = ""
    for j, s in enumerate(S):
        k += s
        if bit[j] == "1":
            k += "+"
    ans += eval(k)
print(ans)

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
s = list(map(int,list(input())))

if len(s) == 1:
    print(s[0])
    exit()

from collections import deque

cands=deque([[0],[1]])

while len(cands[0]) != len(s)-1:
    newcands = []
    for cand in cands:
        newcands.append(cand+[0])
        newcands.append(cand+[1])
    cands = newcands

memo = []
while cands:
    pos = cands.pop()
    siki = ''
    for i, p in enumerate(pos):
        siki += str(s[i])
        if p == 1:
            siki += '+'
    siki += str(s[-1])
    memo.append(eval(siki))

print(sum(memo))

Submission status: Accepted

Solution code:
def f(s):
  if len(s) > 1:
    cnt = 1
    ans = int(s)
    for i in range(1,len(s)):
      a, c = f(s[i:])
      ans += int(s[:i]) * c + a
      cnt += c
    return ans, cnt
  else:
    return int(s), 1
  
print(f(input())[0])

Submission status: Accepted

Solution code:
import itertools


def main():
    S = input()
    ans = 0
    for p in itertools.product(("", "+"), repeat=len(S)-1):
        p = list(p) + ['']
        fig = "".join([a+b for a, b in zip(S, p)])
        ans += eval(fig)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
ans = 0
for pt in range((1 << (N-1))):#1 == 線あり 0 == 線なし　とする
    # if "11" in bin(pt): continue
    tmpS = S.copy()
    # v = []
    inscnt = 1
    for i in range(N-1):
        if (1 << i) & pt:
            tmpS.insert(i+inscnt,'+')
            inscnt+=1
    # print(tmpS)
    tmpsum=eval("".join(tmpS))
    # print(tmpsum)
    ans+=tmpsum
    # print(v)
print(ans)

Submission status: Accepted

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

    val_sum = 0
    for i in range(2**n):
        idx = 0
        for j in range(n):
            if 1 & (i >> j) == 1:
                val_sum += int(S[idx:j+1])
                idx = j+1
        val_sum += int(S[idx:])

    print(val_sum)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product # 全探索
from bisect import bisect_left, bisect_right

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

S = input()

def dfs(s):
    if len(s) == 1:
        return [s]
    def add(l, r):
        return [l+ri for ri in r]
    return add(s[0], dfs(s[1:])) + add(s[0] + "+", dfs(s[1:]))

print(sum(map(eval,dfs(S))))

Submission status: Accepted

Solution code:
n = list(map(int, input()))


ans = 0
ind = len(n) - 1

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

Submission status: Accepted

Solution code:
s = list(map(int, list(input())))

if len(s) == 1:
    print(s[0])
    exit()

m = len(s) - 1

n = 2 ** m

ans = 0
for i in range(n):
    d = list(map(int, list(str(bin(i)))[2:]))
    if len(d) < m:
        d = [0] * (m - len(d)) + d

    temp = s[0]
    for j in range(m):
        if d[j] == 0:
            ans += temp
            temp = s[j+1]
        else:
            temp *= 10
            temp += s[j+1]
    ans += temp
    #print(d, ans)

print(ans)

Submission status: Accepted

Solution code:
s = input()
n = int(s)
r = 0
# bitの２進数表記で+を入れる位置を総当たりする
for bit in range(2**(len(s)-1)):
    # eは先頭文字
    e = s[0]
    # +が入る位置が、右からi桁目（0<= i <= Sの長さ－1）のとき
    for i in range(len(s)-1):
        if ((bit>>i)&1) == 1:
            # bitの２進数表記で右からi桁目が1のとき
            # '+'を入れる
            e += '+'
        # 次の文字（左からi番目）を入れる
        e += s[i+1]
    # +を入れた文字列を+で分割して整数に変換し、加算する
    r += sum(map(int, e.split('+')))
print(r)

Submission status: Accepted

Solution code:
S = input()

def DP(x , i):
    #print("x:i:",x,i)
    ans = 0
    # iがSの長さになっていれば、評価する
    if i == len(S):
        # +が入っていればevalで評価する必要がある
        #print("評価")
        if '+' in x:
            return eval(x)
        else:
            return int(x)
    else:
        # i番目の数字の前に+を挟まない場合
        ans += DP(x + S[i] , i+1)
        if i > 0:
            # i番目の数字の前に+を挟む場合
            ans += DP(x + '+' + S[i], i+1)
        return ans

print(DP('',0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
op_cnt = len(S) - 1
ResSum = 0

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_S, p_o in zip(S, op + [""]):
        formula += (p_S + p_o)

    ResSum += eval(formula)

print(ResSum)

Submission status: Accepted

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

total = 0

for i in range(2**n):
    l = [""] * n
    for j in range(n):
        if (i >> j) & 1 :
            l[j] = "+"
    formula = ""
    for p, q in zip(s, l+[""]):
        formula += p + q
    total += eval(formula)

print(total)

Submission status: Accepted

Solution code:
#ABC045C
S=input()
def DP(x,i):
    ans=0
    if i==len(S):
        if '+' in x:
            return eval(x)
        else:
            return int(x)
    else:
        ans+=DP(x+S[i],i+1)
        if i>0:
            ans+=DP(x+'+'+S[i],i+1)
        return ans
print(DP('',0))

Submission status: Accepted

Solution code:
def cal(d, i, k, total):
  if i == len(d):
    return total + int(k)
  return cal(d, i+1, d[i], total + int(k)) + cal(d, i+1, k + d[i], total)

d = [x for x in input()]
print(cal(d, 1, d[0], 0))

Submission status: Accepted

Solution code:
S = input()

ans = [S[0]]

for i in range(1,len(S)):
    candidate = []
    for j in ans:
        candidate.append(j+S[i])
        candidate.append(j+'+'+S[i])
        ans = candidate

num = 0
for a in ans:
    num += eval(a)

print(num)

Submission status: Accepted

Solution code:
S = input()

ans = [S[0]]

for i in range(1,len(S)):
    candidate = []
    for j in ans:
        candidate.append(j+S[i])
        candidate.append(j+'+'+S[i])
        ans = candidate

num = []
for a in ans:
    num.append(eval(a))

print(sum(num))

Submission status: Accepted

Solution code:
s = list(str(input()))
n = len(s) - 1 #間の数

t = []
y = 0

t.append(int(s[n]) * (2 ** n ))

for i in range(n):
    y = 0
    for j in range(1,len(s)+1):
        if j == len(s) + 1 - i:
            continue
        elif j == len(s) - i:
            y = y + int(s[i]) * (10 ** (n - i)) * (2 ** i)
            t.append(y)
        else:
            y = y + int(s[i]) * (10 ** (j - 1)) * (2 ** (n - j))

print(sum(t))

Submission status: Accepted

Solution code:
#C問題
S = str(input())
Slist=list(S)
Slen=len(S)
Smax=2**(Slen-1)
ans=0
for i in range(Smax):
    I=bin(i)
    I=I.lstrip("0b")
    Ilen=len(I)
    if Ilen<Slen-1:
        j=0
        for j in range(Slen-Ilen-1):
            I="0"+I
    
    k=0
    Ilist=list(I)
    klist=[]
    now=Slist[0]
    for k in range(Slen-1):
        if Ilist[k]=="0":
            klist.append(int(now))
            now=Slist[k+1]
        else:
            now+=Slist[k+1]
    klist.append(int(now))
    ans+=sum(klist)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
n=len(s)-1
if n==0:
  print(s)
else:
  l=[]
  a=len(bin(1<<n))-3
  for i in range(1<<n):
    l.append(str(bin(i))[2:].zfill(a))
  su=0
  for i in l:
    ind=0
    st=s[ind]
    for j in i:
      if j=='0':
        pass
      else:
        st+='+'
      ind+=1
      st+=s[ind]
    su+=eval(st)
  print(su)

Submission status: Accepted

Solution code:
import itertools
s = input()
ans = 0
ss = [s[i//2] if i%2==0 else "+" for i in range(2*len(s)-1)]

for li in itertools.product(range(2),repeat=len(s)-1):
  for j in range(len(s)-1):
    if li[j] ==1:
      ss[j*2+1] = "+"
    else:
      ss[j*2+1] = ""
  ans = ans+ eval("".join(ss))
print(ans)

Submission status: Accepted

Solution code:
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
l = [i for i in s]
A = l[1:]

ans = 0
for i in range(1 << len(A)):
	for j in range(len(A)):
		if ((i >> j) & 1) == 1:
			if f == 1:
				continue
			f = 1
		else:
			f = 0
	else:
		s = l[0]
		for j in range(len(A)):
			if ((i >> j) & 1) == 1:
				ans += int(s)
				s = A[j]
			else:
				s += A[j]
		else:
			ans += int(s)

print(ans)

Submission status: Accepted

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

    #'+'の追加位置を示すビットパターンpt 0~2^(n-1)-1
    for pt in range(2**(length-1)):
        plus_num = 0
        s_tmp = s
        num =[]

        for i in range(length-1):
            if (pt >> i)&1 :
                s_tmp = s_tmp[:i+1+plus_num] + '+' + s_tmp[i+1+plus_num:]
                #+を追加したぶんのズレ
                plus_num += 1
        
        num = s_tmp.split('+')
        for i in num:
            ans += int(i)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    s = list(map(int, input()))
    r = sum(a + b for a, b in iter_formulas(s))
    print(r)

def iter_formulas(s):
    if len(s) == 1:
        yield 0, s[0]
        return
    
    for a, b in iter_formulas(s[:-1]):
        yield a + b, s[-1]
        yield a, b * 10 + s[-1]

main()

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()
T=[s for s in S]
N = len(S)-1
ans=0
for i in range(1<<N):
    T=[s for s in S]
    U=''
    b=[]
    for j in range(N,-1,-1):
        if (i>>j)&1:
            b.append(j)
    for B in b:
        T.insert(B+1,'+')
    for t in T:
        U+=t
    ans += eval(U)
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools

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

ls = []
a = [0, 1]
for i in itertools.product(a, repeat=len(S)-1):
    ans = 0
    start = 0
    for j, x in enumerate(i):
        if x == 1:
            ans += int(S[start:j+1])
            start = j + 1
    ans += int(S[start:len(S)])
    ls.append(ans)
print(sum(ls))

Submission status: Accepted

Solution code:
import sys

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

ls = []
for i in range(1<<(len(S)-1)):
    ans = 0
    num = format(i, 'b').zfill(len(S)-1)
    start = 0
    for j, x in enumerate(num):
        if x == '1':
            ans += int(S[start:j+1])
            start = j + 1
    ans += int(S[start:len(S)])
    ls.append(ans)
print(sum(ls))

Submission status: Accepted

Solution code:
import sys

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

ls = []
for i in range(1<<(len(S)-1)):
    ans = 0
    num = format(i, 'b').zfill(len(S)-1)
    start = 0
    for (j, x) in enumerate(num):
        if x == '1':
            ans += int(S[start:j+1])
            start = j + 1
    ans += int(S[start:len(S)])
    ls.append(ans)
print(sum(ls))

Submission status: Accepted

Solution code:
from itertools import product

S = list(input())

states = list(product([i for i in range(2)], repeat=len(S)-1))

res = 0

#print(states)

for state in states:
    formula = S[0]
    for i in range(len(state)):
        if state[i] == 0:
            formula += S[i+1]
        else:
            formula += '+' + S[i+1]

    #print(formula)
    res += eval(formula)

print(res)

Submission status: Accepted

Solution code:
S = list(input())
"""
if(len(S) == 1):
  print(S[0])
  exit()
cnt = 0
for i in range(1 << len(S)-1):
  f = S[0]
  for j, b in enumerate(format(i, 'b').zfill(len(S)-1)):
    if(b == '1'):
      f += '+'
    f += S[j+1]
  cnt += sum(map(int,f.split('+')))
print(cnt)

"""

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

Submission status: Accepted

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

s = input()
n = len(s)

print(dfs(0, s, 0))

Submission status: Accepted

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

s = input()
n = len(s)

print(dfs(0, s, 0))

Submission status: Accepted

Solution code:
def bit_all(a,n):
    ans = 0
    for i in range(2**n):
        mini_ans = 0
        now = 0
        for j in range(n):
            if i>>j & 1:
                mini_ans += int(a[now:j+1])
                now = j+1
        mini_ans += int(a[now:])
        ans += mini_ans
    print(ans)
                
                
a = input()
bit_all(a,len(a)-1)

Submission status: Accepted

Solution code:
S = input()


def f(s, n):
    # print(format(n, "b"))
    r = 0
    a = 0
    for i in range(len(s) - 1):
        if n & (1 << i) == 0:
            a += int(s[i])
            a *= 10
        else:
            a += int(s[i])
            r += a
            a = 0

    a += int(s[len(s) - 1])
    r += a

    return r


N = (1 << (len(S) - 1))
ans = 0
for n in range(N):
    a = f(S, n)
    # print(a)
    ans += a

print(ans)

Submission status: Accepted

Solution code:
s = input()
ret = 0
for i in range(1 << (len(s)-1)):
    x = 0
    sum = 0
    for j in range(len(s)-1):
        if 1<<j & i :
            sum=sum+int(s[x:j+1])
            x = j+1
    sum=sum+int(s[x:])
    ret=ret+sum
print(ret)

Submission status: Accepted

Solution code:
n = input()
L = []
s = 0
for i in range(len(n)):
  L.append(int(n[i]))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8
S = input()
l = len(S)
S = [int(S[i]) for i in range(l)]

def f(i,sl):
    if i == l-1:
        left = 0
        sumEx = 0
        for j in range(l-1):
            #j番目まで+それより左
            left = left*10+S[j]
            if sl[j] == "1":
                sumEx = sumEx + left
                left = 0
        left = left * 10 + S[-1]
        return sumEx + left
                
    else:
        return f(i+1,sl+"1")+f(i+1,sl+"0")
print(f(0,""))

Submission status: Accepted

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