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())
num = len(s)
ans = 0
for i in range(2**(num-1)):
    ls = [0 for _ in range(num-1)]
    for j in range(num-1):
        if (i>>j)&1:
            ls[j]=1
    ls.insert(0,0)
    j = 1
    for i in range(num):
        if ls[num-1-i]==0:
            ans += int(s[num-i-1])*j
            j *=10
        else:
            ans += int(s[num-i-1])*j
            j =1
print(ans)

Submission status: Accepted

Solution code:
S = input()

lis = []

keta = len(S)-1

if keta == 0:
    print (S)
    
else:
    
    for i in range(2 ** keta):
        
        lis.append(format(i,"b").zfill(keta))
        
    #print (lis)
    
    ans = 0
    
    for i in lis:
        
        Q = S[0]
        
        for j in range(len(S)-1):
            
            if i[j] == "1":
                ans += int(Q)
                Q = ""
            
            Q += S[j + 1]
            
        ans += int(Q)
        
        Q = ""
        
    print (ans)

Submission status: Accepted

Solution code:
s = input()
rs = 0
sz = len(s) - 1
for mask in range(2 ** sz):
    curr, total = 0, 0
    for i in range(sz):
      curr *= 10
      curr += int(s[i])
      if mask & (1 << i):
        total += curr
        curr = 0
    curr *= 10
    curr += int(s[-1])
    rs += total + curr
print(rs)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC45 C
s = list(input())
n = len(s)

ans = 0
S = []
for i in range(2*n-1):
    if i % 2 == 0:
        S.append(s[i//2])
    else:
        S.append('')

for i in range(2**(n-1)):
    b = [0]*(n-1)
    for j in range(n-1):
        if (i>>j) & 1:
            b[j] = 1
    x = S.copy()
    k = 0
    for j in range(n-1):
        if b[j] == 1:
            x[k+1] = '+'
        k += 2
    preans = ''
    for j in range(2*n-1):
        if x[j] != '+':
            preans += x[j]
        if x[j] == '+' or j == 2*n-2:
            ans += int(preans)
            preans = ''
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

S = input()

ret = 0
for i in range(len(S)) :
    for comb in combinations(range(1, len(S)), i) :
        comb = [0] + list(comb) + [len(S)]
        for i in range(1, len(comb)) :
            ret += int(S[comb[i-1]:comb[i]])
         
print(ret)

Submission status: Accepted

Solution code:
def resolve():

    s = input()
    n = len(s)

    ans = 0

    for i in range(2 ** (n - 1)):

        cnt = 0
        for j in range(n - 1):

            if (i >> j) & 1:
                ans += int(s[j-cnt:j+1])
                cnt = 0

            else:
                cnt += 1

        ans += int(s[n-cnt-1:n])

    print(ans)
    
resolve()

Submission status: Accepted

Solution code:
s=input()
ans=0
n=len(s)
for i in range(1,n+1):
    for j in range(i):
        m=int(s[j:i])
        if j!=0:
            m*=2**(j-1)
        if i!=n:
            m*=2**(n-i-1)
        ans+=m
print(int(ans))

Submission status: Accepted

Solution code:
s=input()
ans=chk=0
for i in range(2**(len(s)-1)):
    d=bin(i)[2:]
    d=("0"*(9-len(d))+d)[::-1]
    t=int(s[0])
    for i in range(len(s)-1):
        if d[i]=="0":
            t*=10
            t+=int(s[i+1])
        else:
            ans+=t
            t=int(s[i+1])
    ans+=t

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 >> j) & 1:
            tmp += '+'
        tmp += S[j+1]
    ans += eval(tmp)
print(ans)

Submission status: Accepted

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

for i in range(2**(len(s)-1)):
        b = bin(i)[2:].zfill(len(s)-1)
        tmp = s.copy()
        cc = 1
        for j in range(len(s)-1):
                if b[j]=="1":
                        tmp.insert(int(j)+cc, "+");
                        cc += 1
        ans += eval("".join(tmp))
print(ans)

Submission status: Accepted

Solution code:
S=input()
ans=0
for i in range(1<<(len(S)-1)):
    j=format(i,"b").zfill(len(S)-1)
    s,memo=S,0
    for n in range(len(S)-1):
        if j[n]=="0":memo+=1
        else:
            ans+=int(s[:memo+1])
            s=s[memo+1:]
            memo=0
    ans+=int(s)
print(ans)

Submission status: Accepted

Solution code:
def main():
    s = list(map(int,input()))
    n = len(s)
    sq = [2**i for i in range(10)]
    ans = 0
    for i in range(n):
        ans += s[i]*2**i*10**(n-1-i)
    for i in range(n-1):
        for j in range(n-1-i):
            ans += s[i]*2**(n-2-j)*10**j

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
n = len(s)-1
ans = 0
for i in range(2**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:
import itertools
n = str(input())
a = ["","+"]
l = list(itertools.product(a,repeat=len(n)-1))
l_n = list(n)
ans=0
for i in l:
    l_a = [None]*(len(n)*2-1)
    l_a[::2] = l_n
    l_a[1::2] = i
    ans+=eval("".join(l_a))
print(ans)

Submission status: Accepted

Solution code:
s=[int(s) for s in input()]
s_len = len(s)

ans=0
for pat in range(2**(s_len-1)):
    evalstr=str(s[0])
    pat=format(pat,'0'+str(s_len-1)+'b')
    for i in range(1,s_len):
        if pat[i-1]=="1":
            evalstr+="+"
        evalstr+=str(s[i])
    ans+=eval(evalstr)
print(ans)

Submission status: Accepted

Solution code:
S=list(input())
N=len(S)
ans = 0
for b in range(2**(N-1)):
  bit = list(str(bin(b))[2:].zfill(N-1).replace('0','_').replace('1','+'))
  f = S[0]
  for bi, si in zip(bit, S[1:]):
    f += str(bi) + str(si)
  ans += eval(f.replace('_', ''))
print(ans)

Submission status: Accepted

Solution code:
# ARC061C - たくさんの数式 / Many Formulas (ABC045C)
from itertools import product


def main():
    s = input()
    ans = 0
    ops = tuple(product(("", "+"), repeat=len(s) - 1))
    for op in ops:
        e = ""
        for i in range(len(s) - 1):
            e += s[i] + op[i]
        e += s[-1]
        ans += eval(e)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
ls = len(S)
if ls == 1:
    print(S)
else:
    g = 0
    for i in range(2**(ls-1)):
        w = ''
        for u,v in zip(format(i,'#0'+str(2+ls-1)+'b')[2:],S):
            if u=='1':w=w+v+'+'
            else:w=w+v
        else:w=w+S[-1]
        g += eval(w)
    print(g)

Submission status: Accepted

Solution code:
S = input()
ans = 0
for i in range(2 ** (len(S) - 1)):
	bit = bin(i)[2:].rjust(len(S) - 1, "0")
	start = 0
	tmp = 0
	for j in range(len(bit)):
		if bit[j] == "1":
			tmp += int(S[start: j + 1])
			start = j + 1
		if j == len(bit) - 1:
			tmp += int(S[start:])
	ans += tmp
print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
for i in range(2 ** (len(S) - 1)):
	bit = bin(i)[2:].rjust(len(S) - 1, "0")
	# print("bit", bit)
	start = 0
	tmp = 0
	for j in range(len(bit)):
		if bit[j] == "1":
			tmp += int(S[start: j + 1])
			start = j + 1
			# print("now", j, tmp)
		if j == len(bit) - 1:
			tmp += int(S[start:])
	# print("tmp", tmp)
	ans += tmp
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
N=len(S)
ans = 0
for b in range(2**(N-1)):
    prev = 0
    for i in range(N-1):
        if b & (1<<i) > 0:
            ans += int(S[prev:i+1])
            prev=i+1
    ans += int(S[prev:])
print(ans)

Submission status: Accepted

Solution code:
s = input()
a = []
for i in range(2**(len(s)-1)):
    p = format(i, "0"+str(len(s)-1)+"b")
    num = ""
    for j in range(len(p)):
        if p[j] == "1":
            num += s[j]
            a.append(int(num))
            num = ""
        else:
            num += s[j]
    num += s[-1]
    a.append(int(num))
if len(s) != 1:
    print(sum(a))
else:
    print(s)

Submission status: Accepted

Solution code:
S = input()

def F(L,R):
  # cnt, sum
  if R < L:
    return 1,0
  if L == R:
    return 1, int(S[L])
  c,s = 0,0
  for r in range(L,R+1):
    x = int(S[L:r+1])
    c1,s1 = F(r+1,R)
    c += c1
    s += x * c1 + s1
  return c,s

answer = F(0,len(S)-1)[1]
print(answer)

Submission status: Accepted

Solution code:
import sys
import itertools

S = input()

num_list = []
list_S =list(S)

kugiri = [i for i in range(1,len(S))]

for i in range(len(S)):
    if i == 0:
        num_list.append(int(S))
        continue
    combi_list = list(itertools.combinations(kugiri, i))
    for j in range(len(combi_list)):
        temp_num_list = []
        for k in range(len(combi_list[j])):
            if k == 0:
                temp_num_list.append(int(S[:combi_list[j][k]]))
            if k == len(combi_list[j]) - 1:
                temp_num_list.append(int(S[combi_list[j][k]:]))
            else:
                temp_num_list.append(int(S[combi_list[j][k]:combi_list[j][k+1]]))
        num_list.append(sum(temp_num_list))

print(sum(num_list))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
a = len(s)
ans = 0
for i in range(1 << (a-1)):
    su = []
    st = -1
    for j in range(a-1):
        if (i>>j)&1 == 1:
            if st == -1:
                b = int(s[:j+1])
            else:
                b = int(s[st+1:j+1])
            su.append(b)
            st = j
    else:
        if st == -1:
            su.append(int(s))
        else:
            su.append(int(s[st+1:]))
    #print(su)
    ans += sum(su)
print(ans)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

S = str(input())

ans = 0
N = len(S)
for i in range(1,N+1): # 文字数
    for j in range(N-i+1):
        left = max(len(S[:j])-1,0)
        right = max(len(S[j+i:])-1,0)

        ans += int(S[j:j+i]) * (2**(left+right))

print(ans)

Submission status: Accepted

Solution code:
s = list(map(str, input()))
n = len(s)
sum = 0
for i in range(2 ** (n-1)):
  bag = []
  t = s[:]
  for j in range(n):
    if (i >> j) & 1:
      bag.append(j)   
  bag = sorted(bag, reverse=True)
  for k in range(len(bag)):
    t.insert(bag[k]+1, '+')
  #print(eval(''.join(t)))
  sum += eval(''.join(t))

print(sum)

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:
# -*- coding: utf-8 -*-
s = input()
len_s = len(s)

ret = 0
def calc_cumsum(idx,right_str):
    if idx == len(right_str):
        return int(right_str)
    _ifplus = int(right_str[0:idx])* (2**(len(right_str[idx:len_s]) -1 )) + calc_cumsum(1,right_str[idx:len_s])
    _ifnotplus = calc_cumsum(idx+1,right_str)
    return (_ifplus+_ifnotplus)
print(calc_cumsum(1,s))

Submission status: Accepted

Solution code:
# eval is evil
S = input()


def f(i, c):
    # i番目まで / 現在の式
    if i == len(S):
        if c[-1] == "+":
            return int(eval(c[:-1]))
        else:
            return int(eval(c))
    # i番目で区切る or 区切らない ただし+は連続しない
    if i == 0 or c[-1] == "+":
        return f(i + 1, c + S[i])
    else:
        return f(i, c + "+") + f(i + 1, c + S[i])


print(f(0, ""))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

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

# 10 -> n
def ten2n(a,n):
  x=a//n
  y=a%n
  if x:
    return ten2n(x,n)+str(y)
  return str(y)

def main():
  n=S()

  l=list(n)

  l2=[]
  for i in range(pow(2,len(n)-1)):
    l2.append(list(ten2n(i,2).zfill(len(n)-1)))

  sm=0
  for x in l2:
    s=''
    for i in range(len(x)):
      if x[i]=='0':
        s+=l[i]
      else:
        s+=l[i]+'+'
    if len(l)>1:
      s+=l[-1]
    sm+=eval(s)

  return sm


print(main())

Submission status: Accepted

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

ans = 0

for bit in range(1 << (n - 1)):
    # 各場合で式 f を生成する
    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:
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()
def dfs(s, d=0, plus=[]):
    if len(s) -1 == d:
        equation = []
        for i in range(len(s)-1):
            equation.append(s[i])
            equation.append(plus[i])
        equation.append(s[-1])
        #print(''.join(equation))
        return eval(''.join(equation))
    
    total = 0
    total += dfs(s, d+1, plus+[''])
    total += dfs(s, d+1, plus+['+'])    
    
    return total

print(dfs(s))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    S = list(input())
    N = len(S) - 1
    #print(S ,N)
    total = 0
    for i in range(1 << N):
        p = []
        for j in range(N):
            if ((i >> j) & 1) == 1:
                p.append(j+1)
        p.append(10)
        #print(p)
        b = 0
        a = 0
        for x in p:
            #print(S[b:x])
            a += int(''.join(S[b:x])) 
            b = x
        total += a
    print(total)

Submission status: Accepted

Solution code:
S = input()
ans = 0
digit  = len(S)-1
for i in range(2**digit):
    bit = format(i,"0"+str(digit)+"b")
    temp = []
    num = S[0]
    for j in range(digit):
        if j == digit - 1:
            if bit[j] == "1":
                temp.append(int(num))
                temp.append(int(S[j+1]))
            else:
                temp.append(int(num+S[j+1:]))
        else:
            if bit[j] == "1":
                temp.append(int(num))
                num = S[j+1]     
            else:
                num += S[j+1]
    ans += sum(temp)
print(int(S) if digit == 0 else ans)

Submission status: Accepted

Solution code:
def pow2(n):
	v = 1
	for i in range(0, n):
		v *= 2
	return v

S = input()
opspattern = pow2(len(S)-1)
sum = 0
for i in range(0, opspattern):
	m = i
	psum = 0
	number = S[0]
	for j in range(0, len(S)-1):
		if m%2 == 1:
			psum += int(number)
			number = ''
		number = number + S[j+1]
		m = m // 2
	psum += int(number)
	sum += psum
print(sum)

Submission status: Accepted

Solution code:
n = list(input())
d = len(n)-1
anslist = [ None for i in range(2**d)]
for i in range(2**d):
	x = bin(i)[2:].zfill(d)
	
	s = n[0]
	for j in range(d):
		if x[j] == "1":
			s += "+" 
		s += n[j+1]
	anslist[i] = s


anslist = list(map(eval, anslist))
print(sum(anslist))

Submission status: Accepted

Solution code:
# C - たくさんの数式 / Many Formulas
s = input()
d = []
ans = 0
for i in range(2 ** (len(s) - 1)):
    tmp = s[0]
    for j in range(len(s) - 1):
        # print("     i :", i)
        # print("1 << j :", 1 << j)
        # print("  1tmp :", tmp)
        if i & (1 << j):
            tmp += "+"
        tmp += s[j+1]
        # print("  2tmp :", tmp)
        d.append(tmp)
    ans += eval(tmp)

# print(d)
print(ans)

Submission status: Accepted

Solution code:
S = input()

N = len(S)
ans = 0
for i in range(2 ** (N - 1)):
    bit = '{:010b}'.format(i)[11 - N:]
    formula = S[0]
    for j in range(len(bit)):
        if bit[j] == '1':
            formula += '+'
        formula += S[j + 1]
    ans += eval(formula)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(2**n):
    num = []
    bi = format(i, '0'+str(n)+'b')
    for j in range(n):
        num.append(s[j])
        if bi[j] == '1':
            num.append('+')
    num.append(s[-1])
    calc = ''.join(num)
    ans += eval(calc)

print(ans)

Submission status: Accepted

Solution code:
s = input()
a = [int(c) for c in s]

ans = 0
for b in range(0, pow(2, len(a) - 1)):
    subans = 0
    for i in range(0, len(a)):
        subans += a[i]
        if b >> i & 1 == 1:
            ans += subans
            subans = 0
        elif i < len(a) - 1:
            subans *= 10
    ans += subans
print(ans)

# print(*data, sep='\n')

Submission status: Accepted

Solution code:
s=input()
ans=0
for i in range(2**(len(s)-1)):
    bit="{:010b}".format(i)[11-len(s):]
    formula = s[0]
    for j in range(len(bit)):
        if bit[j] =="1":
            formula+="+"
        formula+=s[j+1]
    ans+=eval(formula)
print(ans)

Submission status: Accepted

Solution code:
s = input()
ans = 0
for i in range(2**(len(s)-1)):
    bit = "{:010b}".format(i)[11-len(s):]
    formula = s[0]
    for j in range(len(bit)):
        if bit[j] == "1":
            formula += "+"
        formula += s[j+1]
    ans += eval(formula)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    s_input = input()

    n_s = len(s_input) - 1

    result_sum = 0
    for i in range(2 ** n_s):
        add_op = [''] * n_s
        for j in range(n_s):
            if ((i >> j) & 1):
                add_op[(n_s - 1) - j] = '+'

        formula = '0+'
        for k_ in range(len(s_input)):
            if k_ == 0:
                formula += s_input[0]
            else:
                formula += (add_op[k_ -1] + s_input[k_])

        result_sum += eval(formula)

    print(result_sum)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

dp = [[0]*10 for i in range(10)]
s = ''
slen = 0

def get_dp(i, j):

    if i>j:
        return 0
    if dp[i][j]!=0:
        return dp[i][j]


    ans = 0
    for k in range(i, j+1):
        ans += int(s[i:k+1]) *  (1 <<max(0,(j-k-1))) + get_dp(k+1,j)

    
    dp[i][j] = ans
    return ans



def solve():
    global s, slen
    s = input()

    slen = len(s)

    print(get_dp(0, slen-1))

solve()

Submission status: Accepted

Solution code:
import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
#n,m= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#a.popは10^5あるときTLEしやすい!注意!
#これを消すとなぜかWAになる呪い
s = 0
n = len(a)
bit = [0 for i in range(n-1)]
while sum(bit)<len(bit):
    r = 0
    bit[0]+=1
    if bit[0]==2:
        p = 0
        while bit[p] == 2:
            bit[p]=0
            p+=1
            bit[p]+=1
    str = []
    for i in range(n-1):
        str.append(a[i])
        if bit[i]:str.append(',')
    str.append(a[n-1])
    pa  = ''.join(str)
    ans = pa.split(',')
    for i in range(len(ans)):
        ans[i] = int(ans[i])
    s+=sum(ans)
print(s+int(a))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import itertools

def solve(S: int):
    se = ('+', '_')
    S = list(str(S))

    ans = 0
    for i in itertools.product(se,repeat=(len(S)-1)):
        t =[]
        t.append(S[0])
        for j,x in enumerate(i):
            t.append(x) 
            t.append(S[j+1])

        t = [x for x in t if(x != '_')]
        ts = ''.join(t)
        
        ans += sum(list(map(int,ts.split('+'))))
        
    print(ans)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

s = input()
l = len(s)
ans = int(s)
for i in range(1, l):
    x = list(itertools.combinations(list(range(1, l)), i))
    for xi in x:
        p = 0
        for q in xi:
            ans += int(s[p:q])
            p = q
        ans += int(s[q:])
print(ans)

Submission status: Accepted

Solution code:
import itertools


def sum_strlong(strlong):
    ans = int(strlong)
    for i in range(1, len(strlong)):
        for comb in itertools.combinations(range(len(strlong)-1), i):
            integer = ''
            for j, digit in enumerate(strlong):
                integer += digit
                if j in comb:
                    integer += '+'
            ans += eval(integer)
    return ans


def main():
    print(sum_strlong(input()))


main()

Submission status: Accepted

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

for i in range(2**(n-1)):
    test = ""
    num = str(bin(i))[2:].zfill(n-1)
    for j in range(n-1):
        test += s[j]
        if num[j] == '1':
            test += '+'
    test += s[-1]
    ans.append(eval(test))
print(sum(ans))

Submission status: Accepted

Solution code:
s=input()
n=int(len(s))
cnt=int(s)
s=list(map(int,s))
if n==1:
    cnt=cnt
elif n==2:
    cnt+=s[0]+s[1]
else:
    cnt=0
    cnt+=s[0]*10**(n-1)
    for i in range(0,n-1):
        cnt+=(10**i)*(sum(s[:n-i])+s[n-i-1])*2**(n-i-2)
print(cnt)

Submission status: Accepted

Solution code:
s=input()
l=len(s)
ans=int(s)
for i in range(1,2**(l-1)):
  f=format(i,'b')
  if len(f)<l:
    f='0'*(l-1-len(f))+f
  pos=[]
  for j in range(len(f)):
    if f[j]=='1':
      pos.append(j+1)
  n=[]
  if len(pos)==1:
    n.append(int(''.join(map(str,s[:pos[0]]))))
    n.append(int(''.join(map(str,s[pos[0]:]))))
  else:
    n.append(int(''.join(map(str,s[:pos[0]]))))
    for j in range(1,len(pos)):
      n.append(int(''.join(map(str,s[pos[j-1]:pos[j]]))))
    n.append(int(''.join(map(str,s[pos[len(pos)-1]:]))))
  ans+=sum(n)
print(ans)

Submission status: Accepted

Solution code:
S=input()
l=len(S)-1
ans=0
for i in range(1<<l):
    s=S
    n=[]
    k=0
    for j in range(l):
        k+=1
        if i&(1<<j):
            n.append(int(s[:k]))
            s = s[k:]
            k=0
    else:
        n.append(int(s))
    ans+=sum(n)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
s = input()
if len(s)==1:
    print(s)
    exit()
list = [[0]*(len(s)-1)]
def dfs(l,cnt):
    if cnt==len(s)-1:
        return 0
    ret = l.copy()
    ret[cnt] += 1
    if not l in list:
        list.append(l)
    list.append(ret)
    dfs(l,cnt+1)
    dfs(ret,cnt+1)
    return 0
dfs([0]*(len(s)-1),0)
ans = 0
for l_ in list:
    start = 0
    for i in range(len(l_)):
        if l_[i]==1:
            ans += int(s[start:i+1])
            start = i+1
        if i==len(l_)-1:
            ans += int(s[start:])

print(ans)

Submission status: Accepted

Solution code:
s = input()

n = len(s)
res = 0
for i in range(2**(n-1)):
    idx = n-1
    ss = s
    r = i
    while r>0:
        if r & 1:
            ss = ss[:idx]+'+'+ss[idx:]
        idx -= 1
        r>>=1
    res += sum([int(c) for c in ss.split('+')])
print(res)

Submission status: Accepted

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

ans = 0

for i in range(2 ** l):
    bin_str = format(i, "09b")[::-1] + "0"

    new_s = "".join([x + "+" if bin_str[idx] == "1" else x + "" for idx, x in enumerate(s)])

    ans += eval(new_s)

print(ans)

Submission status: Accepted

Solution code:
import itertools
import copy

num_list = [chr for chr in input()]
TF_list = [True, False]

boundary_list = list(itertools.product(TF_list, repeat = len(num_list) - 1))

num_sum = 0

for boundary in boundary_list:
    # initialize
    num_list_copy = copy.copy(num_list)
    boundary = list(boundary)
    boundary.append(True)
    boundary_list.reverse
    temp = []
    
    while num_list_copy:
        temp.append(num_list_copy.pop(0))
        if boundary.pop(0):
            post_temp = int(''.join(temp))
            num_sum += post_temp
            temp = []
            
print(num_sum)

Submission status: Accepted

Solution code:
from math import factorial
from sys import exit, stdin
S = list(stdin.readline().rstrip())
N = len(S)-1
ans = 0
for i in range(1 << N):
    tmp = []
    tmp.append(S[0])
    for j in range(N):
        if ((i >> j) & 1):
            tmp.append("+")
            tmp.append(S[j+1])
        else:
            tmp.append(S[j+1])
    ans += eval("".join(tmp))
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

ss = input()
ans = []
for pattern in product(range(2),repeat=len(ss)-1):
    if sum(list(pattern)) is 0:
        continue
    tmp = ''
    for s,p in zip(ss,pattern):
        tmp += s
        if p == 1:
            tmp += '+'
    tmp += ss[-1]
    ans.append(eval(tmp))
print(sum(ans)+int(ss))

Submission status: Accepted

Solution code:
S = input()


def dfs(num_string, p):


  
  if len(S) == 1:
    ans = int(S)
    return ans
  
  if p > len(S) - 1:
    #終わり
    ans = eval(num_string)
    return ans
  
  
  ret = 0
  
  ret += dfs(num_string + "+" + S[p], p+1)
  ret += dfs(num_string + S[p], p+1)
  
  return ret

ans = dfs(S[0],1)
print(ans)

Submission status: Accepted

Solution code:
S = input()

ans = 0
def dfs(num_string, p):

  global ans
  
  if len(S) == 1:
    ans = int(S)
    return
  
  if p > len(S) - 1:
    #終わり
    ans += eval(num_string)
    return 
  
  #先頭の数字だけ扱いが微妙
  if p == 0:
    num_string  = "" + S[0]
    p = 1
  
  tmp = 0
  
  dfs(num_string + "+" + S[p], p+1)
  dfs(num_string + S[p], p+1)
  
  return

dfs(0,0)
print(ans)

Submission status: Accepted

Solution code:
s=[i for i in input()]
t=len(s)-1
tmp=2**t
ans=0
for i in range(tmp):
    p=bin(i)[2:]
    p="0"*(t-len(p))+p
    x=""
    for j,k in enumerate(s):
        x+=k
        if j!=t and p[j]=="1":
            x+="+"
    ans+=eval(x)
print(ans)

Submission status: Accepted

Solution code:
from itertools import product, chain

S = input()
ans = 0

for plus in product(('', '+'), repeat=len(S)-1):
    ans += eval(''.join(chain.from_iterable(zip(S, list(plus)+['']))))
    
print(ans)

Submission status: Accepted

Solution code:
S = input()

def sumS(nums):
    p = 0
    if len(nums) == len(S)-1:
        num = int(S[0])
        for n, s in zip(nums, S[1:]):
            if n == 0:
                num = num * 10 + int(s)
            else:
                p += num
                num = int(s)
        p += num
        return p
    
    for i in range(2):
        nums.append(i)
        p += sumS(nums)
        nums.pop()
    return p

print(sumS([]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
	S = input()
	N = len(S)
	ans = 0
	for i in range(2**(N-1)):
		p = 0
		current = S
		for j in range(N-1):
			if (i>>j) & 1 == 1:
				ans += int(current[p:j+1])
				p = j+1
		if p != N:
			ans += int(current[p:N+1])
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
s = input()
n = len(s)-1
ans = 0
for i in range(2**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()
n=len(S)
ans=0
for i in range(2**(n-1)):
  key=str(bin(i))[2:].zfill(n-1)
  f=S[0]
  for j in range(1,n):
    if key[j-1]=="0":
      f+=S[j]
    else:
      f+="+"+S[j]
  ans+=eval(f)
print(ans)

Submission status: Accepted

Solution code:
n = input()
l = len(n)
ans = 0
for i in range(2**(l-1)):
    m = n
    b = list(bin(i)[2:])
    if len(b) < l-1:
        b = ["0"]*(l - 1 - len(b)) + b
    temp = 0
    for j, bb in enumerate(b):
        if bb == "1":
            ans += int(m[temp:j+1])
            temp = j+1
    ans += int(m[temp:])
print(ans)

Submission status: Accepted

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

def dfs(s, n):
  if n == N:
    tmp = list(map(int, s.split('+')))
    #print(tmp)
    return sum(tmp)
  c = 0
  for i in ['', '+']:
    c += dfs(s + i + S[n+1], n+1)
  return c

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