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())

ksum=0
# itertools 使用 bit全探索
import itertools
for i in itertools.product([0,1], repeat=len(s)-1):
    isum=0
    nstr=s[0]
    for ii in range(len(s)-1):
        if i[ii]==0:
            nstr=nstr+s[ii+1]
        elif i[ii]==1:
            isum=isum+int(nstr)
            nstr=s[ii+1]
    isum=isum+int(nstr)
    ksum=ksum+isum
#    print(isum,i)
print(ksum)

Submission status: Accepted

Solution code:
S = int(input())
l = len(str(S)) #Sの桁数
li = list(str(S))

S_a = l - 1 #あいだの個数

result = S

for i in range(1, 2**S_a):
  L = list(bin(i))
  del L[0:2]
  while len(L) < S_a:
    L.insert(0, "0")
#  print(L)
  indexes = [i for i, x in enumerate(L) if x == "1"]
#  print(indexes)
  li2 = li.copy()
  for j in indexes:
    li2[j] += "+"
#  print(li2)
  result += eval("".join(li2))
  
#  print("--------------")

print(result)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

s = i_s()

ans = 0
for i in range(1<<(len(s)-1)):
    tmp = s[0]
    for j in range(len(s)-1):
        if i & 1 << j:
            tmp += '+'
        tmp += s[j+1]
    ans += eval(tmp)

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    S = str(input())
    ls=len(S)


    # bit全探索
    # https://qiita.com/gogotealove/items/11f9e83218926211083a#%E4%BE%8B%E9%A1%8C-1
    n = ls-1
    # 昇順での探索だよ
    val = 0
    for i in range(2 ** n):
        split=[]
        for j in range(n):  # このループが一番のポイント
            if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
                split.append(j)
        temp=0
        for k in range(len(split)):
            val+=int(S[temp:split[k]+1])
            temp=split[k]+1
            if k==len(split)-1:
                val+=int(S[split[k]+1:])
    print(val+int(S))


resolve()

Submission status: Accepted

Solution code:
import itertools

def calc(str, tup):
  l = []
  idx = 0
  for i in tup:
    l.append(int(str[idx:i]))
    idx = i
  l.append(int(str[idx:]))
  return sum(l)

def solve(s):
  l = [i for i in range(1, len(s))]
  ans = 0
  for c in range(len(l)+1):
    for v in itertools.combinations(l,c):
      ans += calc(s, v)
  return ans

if __name__ == "__main__":
  s = input()
  print(solve(s))

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

s = i_s()

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

print(ans)

Submission status: Accepted

Solution code:
s = input()

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

print(ans)

Submission status: Accepted

Solution code:
S = input()

sum = 0
for i in range(1 << len(S)-1):
    l = []
    for j in range(len(S)-1):
        if (i >> j) & 1 == 1:
            l.append(S[j])
            l.append("+")
        else:
            l.append(S[j])
    l.append(S[len(S)-1])
    sum += eval(''.join(l))
print(sum)

Submission status: Accepted

Solution code:
s = input()

# print(s[5:], s[:5])

t = 0
import itertools
for i in range(0, len(s)):
    for j in list(itertools.combinations([i for i in range(1, len(s))], i)):
        j = list(j)
        j.append(len(s))
        # print(s[:j[0]])
        t += int(s[:j[0]])
        for k in range(len(j)-1):
            # print(s[j[k]:j[k+1]])
            t += int(s[j[k]:j[k+1]])
print(t)

Submission status: Accepted

Solution code:
from itertools import product
S=input()
N=len(S)
fa=0

def asum(X):
    ans=0
    pre=0

    for i in range(len(X)):
        if X[i]==1:
            ans+=int(S[pre:i+1])
            pre=i+1
    else:
        ans+=int(S[pre:])
    return ans

for A in product(range(2),repeat=N-1):
    fa+=asum(A)
print(fa)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = 0
def bfs(num,i):
    if i == n:
        global ans
        ans += eval(num)
    else:
        bfs(num+'+'+s[i],i+1)
        bfs(num+s[i],i+1)
bfs(s[0],1)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

num = 0
for i in range(2**(len(S)-1)):
  plus = list(" " * (len(S)-1))
  indx = bin(i)[2:].zfill(len(S)-1)
  for ind in range(len(indx)):
    if indx[ind] == "1": plus[ind] = "+"
  formula = S[0]
  for j in range(len(S)-1):
    if plus[j] == " ":
      formula += S[j+1]
    else:
      formula += "+" + S[j+1]
  num += eval(formula)
print(num)

Submission status: Accepted

Solution code:
s=input()
a=int(s)
sum=0
for i in range(2**(len(s)-1)):
  bi=list(map(int,str(format(i,"b").zfill(len(s)-1))))
  #print(bi)
  k=0
  for j in range(len(bi)):
    if bi[j]==1:
      
      sum+=int(s[k:j+1])
      #print(bi)
      #print(int(s[k:j+1]))
      k=j+1
  #print(int(s[k:]))
  #print(bi)
  sum+=int(s[k:])
    
print(sum)

Submission status: Accepted

Solution code:
import queue

n = input()

def all_combination(length):
    q = queue.Queue()
    source = (0, )
    part_list = [source + (length, )]
    q.put(source)
    while not q.empty():
        parent = q.get()
        if parent[-1] < length-1:
            for m in range(parent[-1]+1, length):
                child = parent + (m, )
                part_list.append(child + (length, ))
                q.put(child)
        else:
            pass
            
    return part_list
        
length = len(n)
part_list = all_combination(length)

sum = 0
for t in part_list:
    for i, j in zip(t[:-1], t[1:]):
        sum += int(n[i:j])
        
print(sum)

Submission status: Accepted

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

ans=0
for i in range(2**m):
    num=format(i,"b").zfill(m)
    N=list(n)
    for j,k in enumerate(num):
        if k=="1":N[j]=N[j]+"+"
    ans +=eval("".join(N))
print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

S=list(str(input()))
r_sum=0


def dec2bin(target):
	amari=[]
	while(target!=0):
		amari.append(target%2)
		target=target//2
	amari.reverse()
	return amari

    
for i in range(2**(len(S)-1)):
	add_list=dec2bin(i)
	tmp=[0]*(len(S)-1-len(add_list))
	add_list=tmp+add_list
	c=0
	for j in range(len(S)):
		r_sum += int(S[-j-1]) *(10**c)
		c += 1
		if(j<(len(S)-1)):
			if(add_list[-j-1]==1):
				c=0
print(r_sum)

Submission status: Accepted

Solution code:
#in1 = '125'        #176
#in1 = '9999999999' #12656242944
in1 = input()
len = len(in1)

in_array = [''] * ((len * 2) - 1)
for idx1 in range(len):
    in_array[idx1 * 2] = in1[idx1]

RC = 0
for idx1 in range(2 ** (len - 1)):
    pos = format(idx1, '0' + str(len - 1) + 'b')
    for idx2 in range(len - 1):
        if pos[idx2] == '1':
            in_array[idx2 * 2 + 1] = '+'
        else:
            in_array[idx2 * 2 + 1] = ''
    RC += eval(''.join(in_array))

print(RC)

Submission status: Accepted

Solution code:
S=input().rstrip()
N=len(S)
ans=0
for b in range(2**(N-1)):
  a=[]
  p=0
  for i in range(N):
    if b&(1<<i):
      a.append(S[p:i+1])
      p=i+1
  a.append(S[p:])
  ans+=eval("+".join(a))
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

s = list(input())
ans = 0

for i in range(len(s)):
    for j in combinations(range(len(s)-1),i):
        temp = [i for i in s]
        for k in j[::-1]:
            temp.insert(k+1,'+')
        temp = ''.join(temp)
        temp = temp.split('+')
        temp = map(int, temp)
        ans += sum(temp)

print(ans)

Submission status: Accepted

Solution code:
import copy
a = list(input())
n = len(a)-1
ans = 0
if n == 0:
  print(int(a[0]))
else:
  for i in range(2 ** n):
    l=[]
    l = copy.copy(a)
    dokoka = [0]*(n)
    for j in range(n):
        if ((i >> j)&1):
            dokoka[j] = 1
    x = l.pop(0)
    while True:
      d = dokoka.pop(0)
      if d == 0:
          x += l.pop(0)
      else:
          ans += int(x)
          x = l.pop(0)
      if not dokoka:
          ans += int(x)
          break
  print(ans)

Submission status: Accepted

Solution code:
S = input()

def f(i, s):
    if i == len(S) - 1:
        return sum(map(int, s.split("+")))
    else:
        return f(i + 1, s + S[i+1]) + f(i + 1, s + "+" + S[i+1])

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

Submission status: Accepted

Solution code:
c,*s=input();n=len(s);print(sum(eval(c+''.join('+'*(b>>i&1)+s[i]for i in range(n)))for b in range(2**n)))

Submission status: Accepted

Solution code:
c,*s=input();n=len(s)
print(sum(eval(c+''.join('+'*(b>>i&1)+s[i] for i in range(n))) for b in range(2**n)))

Submission status: Accepted

Solution code:
c,*s=input();n=len(s)
import itertools as it
print(sum(eval(c+''.join(p[i]+s[i] for i in range(n))) for p in it.product(['','+'],repeat=n)))

Submission status: Accepted

Solution code:
S = input()

N=len(S)

total=0
for i in range(0, 2**(N-1)):
    answer=S[0]
    for j in range(N-1):
        if (i >> j) & 1:
            answer+='+'+S[j+1]
        else:
            answer+=S[j+1]
    total+=eval(answer)
    #print(answer)
print(total)

Submission status: Accepted

Solution code:
c,*s=input()
n=len(s)
import itertools as it
a=0
for p in it.product(['','+'],repeat=n):
  t=c
  for i in range(n): t+=p[i]+s[i]
  a+=eval(t)
print(a)

Submission status: Accepted

Solution code:

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

print(ans)

Submission status: Accepted

Solution code:
S = list(input())
if len(S) != 1:
    t = 0
    for n in range(2**(len(S) - 1)):
        f = S[0]
        b = bin(n)[2:]
        b = "0"*(len(S) - len(b) - 1) + b
        for a in range(len(b)):
            if b[a] == "1":
                f += "+"
            f += S[a+1]
        t += eval(f)
    print(t)
else:
    print(S[0])

Submission status: Accepted

Solution code:
import itertools

S = input()
ans = 0
r = len(S) - 1
for t in itertools.product([0, 1], repeat=r):
    lst = [S[0]]
    for i in range(r):
        if t[i]:
            lst.append('+')
        lst.append(S[i + 1])
    ans += eval(''.join(map(str, lst)))
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    S = Scanner.string()
    n = len(S) - 1
    ans = 0
    for i in range(1 << n):
        tmp = 0
        x = S[0]
        for j in range(n):
            if (i >> j) & 1:
                tmp += int(x)
                x = S[j + 1]
            else:
                x = x + S[j + 1]
        tmp += int(x)
        ans += tmp
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import product, zip_longest
from functools import reduce

s = input()

res = 0
for op in product(('+', ''), repeat=len(s)-1):
    formula = ''.join(reduce(lambda t, u: t+u, zip_longest(s, op, fillvalue='')))
    res += eval(formula)

print(res)

Submission status: Accepted

Solution code:
S=list(input())
n=len(S)
ans=0
for i in range(2**(n-1)):
    stack=""
    l=[]
    for j in range(n):
        stack=stack+S[j]
        if ((i >> j) & 1)or j==n-1:
            l.append(int(stack))
            stack=""
    ans+=sum(l)
print(ans)

Submission status: Accepted

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

for i in range(2**n):
    stack=""
    l=[]
    for j in range(n):
        stack=stack+S[j]
        if ((i >> j) & 1)or j==n-1:
            l.append(int(stack))
            stack=""
    ans+=sum(l)
    if len(l)==len(S):
        break
print(ans)

Submission status: Accepted

Solution code:
import copy

s = input()
n = len(s)
li = []
ans = 0

def make_list():
    global li
    if len(li) < n - 1:
        li.append(0)
        make_list()
        li.pop(-1)
        li.append(1)
        make_list()
        li.pop(-1)
    else:
        calc(li)

def calc(li):
    global ans
    tmp = 0
    cnt = 0
    s1 = copy.copy(s)
    for i in range(n-1):
        if li[i] == 0:
            tmp += int(s1[cnt:i+1])
            cnt = i+1
    tmp += int(s1[cnt:])
    ans += tmp

make_list()

print(ans)

Submission status: Accepted

Solution code:
from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
from bisect import *
input=lambda :sys.stdin.readline().rstrip()

S=input()
N=len(S)
lst=[]
for bitlst in [[i>>m&1 for m in range(N-1)] for i in range(2**(N-1))]:
    z=S[0]
    num=0
    for i,b in enumerate(bitlst):
        if b==1:
            num+=int(z)
            z=S[i+1]
        else:
            z+=S[i+1]
    num+=int(z)
    lst.append(num)
print(sum(lst))

Submission status: Accepted

Solution code:
S=list(input())
n=len(S)
ans=0
for i in range(2**(n-1)):
  A=[0]
  s=format(i,"12b")
  for j in range(1,n):
    if s[-j]=="1":
      A.append(j)
  A.append(n)
  for j in range(len(A)-1):
    a=""
    for k in range(A[j+1]-A[j]):
      a=a+S[A[j]+k]
    ans=ans+int(a)
print(ans)

Submission status: Accepted

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

for i in range(2**(n-1)):
  ds=[]
  for j in range(n-1):
    ds.append(s[j])
    if ((i>>j)&1):
      ds.append("+")
  ds.append(s[-1])
  keisa="".join(ds)
  ans+=eval(keisa)
  
print(ans)

Submission status: Accepted

Solution code:
s = input()
num = 0
for bit in range(2**(len(s)-1)):
    before = 0
    for g in range(len(s)-1):
        if bit >> g & 1:
            num += (int(s[before:g+1]))
            before = g+1
    num += int(s[before:])
print(num)

Submission status: Accepted

Solution code:
inp = input()
n = len(inp)
s = []
for i in range(n):
  s += inp[i]

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

ans = 0
for i in range(len(com)):
  tmp = ""
  idx = 0
  for j in range(n-1):
    tmp += s[j]
    tmp += com[i][idx]
    idx += 1
  tmp += s[n-1]
  ans += eval(tmp)

print(ans)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
ans=0
for i in range(2**(n-1)):
  S=format(i,"12b")
  A=[0]
  for j in range(1,n):
    if S[-j]=="1":
      A.append(j)
  A.append(n)
  for j in range(len(A)-1):
    ans=ans+int(s[A[j]:A[j+1]])
print(ans)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
if n==1:
    print(int(s))
else:
    n-=1
    ans=0
    for i in range(1<<n):
        l=[]
  #      print(i)
        for j in range(n-1,-1,-1):
            if (i>>j)&1:
                l.append(n-1-j)
   #     print(l)
        j=0
        k=0
        while j<len(l):
            num=''
            while k<=l[j]:
                num+=s[k]
                k+=1
    #        print(num,end=' , ')
            ans+=int(num)
            j+=1
        num=''
        while k<n+1:
            num+=s[k]
            k+=1
     #   print(num)
        ans+=int(num)
    print(ans)

Submission status: Accepted

Solution code:
from itertools import product
S = input()
len_s = len(S)
patterns = product([0,1], repeat=len(S) - 1)

ans = 0

for pattern in patterns:
  tmp_st = ''
  tmp_arr = []
  for i in range(len_s):
    tmp_st += S[i]
    if i <= len_s-2 and pattern[i]:
      ans += int(tmp_st)
      tmp_st = ''
  ans += int(tmp_st)

print(ans)

Submission status: Accepted

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

ans = 0
for bit in range(1 << N):
    s = []
    prev = 0
    for i in range(N):
        if bit & (1 << i):
            s.append(S[prev:i + 1])
            s.append('+')
            prev = i + 1
    else:
        s.append(S[prev:])
    ans += eval(''.join(s))
print(ans)

Submission status: Accepted

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

from itertools import product
sign = ['+','']
signs = list(product(sign, repeat=(n-1)))
signs = list(list(_) for _ in signs)

S = []
for i in range(len(signs)):
    temp = [s[0]]
    s_copy = s[:]
    for j in range((n-1)*2):
        if j % 2 == 0:
            temp += [signs[i].pop(0)]
        else:
            temp += [s_copy.pop(1)]
    else:
        S += [temp]

x = 0
for k in range(len(signs)):
    x += eval(''.join(S[k]))

print(x)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def dfs(i,f):
    #n個回目なら合計値を返す
    if i == len(s)-1: 
        return sum(list(map(int,f.split("+"))))
    return dfs(i+1,f+s[i+1]) + dfs(i+1,f+"+"+s[i+1])
s = list(input())
print(dfs(0,s[0]))

Submission status: Accepted

Solution code:
import copy
s = input()
li = []
for ss in s:
    li.append(ss)
l = len(li) - 1 #演算子を挿入する個数
ans = 0


for i in range(2**l):
    tmp = copy.deepcopy(li)
    count = 1
    #どのビットが立っているかを確認する
    for j in range(l):
        #奇数インデックスに演算子を挿入する
        if (i >> j) & 1 == 1:
            tmp.insert(count,'+')
        else:
            tmp.insert(count,'')
        count += 2
    #evalで文字列をそのまま演算させ、総数にカウント
    ans += eval("".join(tmp))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
n = len(S)
pattern = []
total = 0
for i in range(2 ** (n - 1)):
    tmp = [''] * (n - 1)
    for j in range(n - 1):
        if i >> j & 1:
            tmp[j] = '+'
    pattern.append(tmp)

for i in range(2 ** (n - 1)):
    tmp = ''
    for j in range(n - 1):
        tmp += S[j] + pattern[i][j]
    tmp += S[n - 1]
    total += sum(list(map(int, tmp.split('+'))))

print(total)

Submission status: Accepted

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

from itertools import product

PL=list(product(['+',''],repeat=n-1))

ans=0
for pl in PL:
    SS=S.copy()
    for i,p in enumerate(pl):
        SS.insert(i*2+1,p)
    ans+=eval(''.join(SS))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
## coding: UTF-8
from itertools import permutations, combinations,combinations_with_replacement,product


N_str = input()
L = (len(N_str)) #桁数
s = [] #各桁の数を格納
for i in range(L):
    s.append((N_str[i]))
#print(s)
#ビット演算、式を計算
a=list(product(['','+'],repeat=L-1))
#print(a)
answer = 0
for i in a:
    if(L == 1):
        tmp=s[0]    
    if(L == 2):
        tmp=s[0]+i[0]+s[1]
    if(L == 3):
        tmp=s[0]+i[0]+s[1]+i[1]+s[2]
    if(L == 4):
        tmp=s[0]+i[0]+s[1]+i[1]+s[2]+i[2]+s[3]
    if(L == 5):
        tmp=s[0]+i[0]+s[1]+i[1]+s[2]+i[2]+s[3]+i[3]+s[4]
    if(L == 6):
        tmp=s[0]+i[0]+s[1]+i[1]+s[2]+i[2]+s[3]+i[3]+s[4]+i[4]+s[5]   
    if(L == 7):
        tmp=s[0]+i[0]+s[1]+i[1]+s[2]+i[2]+s[3]+i[3]+s[4]+i[4]+s[5]+i[5]+s[6]       
    if(L == 8):
        tmp=s[0]+i[0]+s[1]+i[1]+s[2]+i[2]+s[3]+i[3]+s[4]+i[4]+s[5]+i[5]+s[6]+i[6]+s[7]
    if(L == 9):
        tmp=s[0]+i[0]+s[1]+i[1]+s[2]+i[2]+s[3]+i[3]+s[4]+i[4]+s[5]+i[5]+s[6]+i[6]+s[7]+i[7]+s[8]
    if(L == 10):
        tmp=s[0]+i[0]+s[1]+i[1]+s[2]+i[2]+s[3]+i[3]+s[4]+i[4]+s[5]+i[5]+s[6]+i[6]+s[7]+i[7]+s[8]+i[8]+s[9]





    answer += eval(tmp)
print(answer)



'''
answer = N #+を1個もいれない

sp = []
for i in range(L):
    if(i == 0):
        sp.append([0])
        sp.append([1])
        print(sp)
        print(len(sp))
    else:
        print(i)
        for j in range(len(sp)):
#未解決…
'''
'''
a=['a','b','C']
print(list(permutations(a)))
print(list(combinations(a,2)))
print(list(combinations_with_replacement(a,3)))
'''

'''
#ビット演算、式を計算
a=list(product(['','-'],repeat=3))
print(a)
s=['5', '5', '3', '4']
for i in a:
    ans=s[0]+i[0]+s[1]+i[1]+s[2]+i[2]+s[3]
    print(ans)

    if eval(ans)==21:
        print(ans+'=21')
        break
'''

Submission status: Accepted

Solution code:
S=input()
SS=[str(a) for a in S]
SSS=tuple(SS)
kaisuu=len(S)-1
answers=[]
for i in range(2**kaisuu):
    T=list(SSS)
    for j in range(kaisuu):
        if ((i>>j)&1):
            T.insert(j*2+1,'+')
        else:
            T.insert(j*2+1,'')
    answers.append(T)
answer=[]
for a in answers:
    kotae=''
    for b in a:
        kotae+=b
    answer.append(kotae)
kotaes=[]
for a in answer:
    b=a.split('+')
    kotaes.append(b)
B=[]
for a in kotaes:
    C=[]
    for b in a:
        b=int(b)
        C.append(b)
    B.append(C)
A=0
for a in B:
    A+=sum(a)
print(A)

Submission status: Accepted

Solution code:

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

def main():
    mod=10**9+7
    S=input()
    N=len(S)
    
    ans=int(S)
    import itertools
    for r in range(N-1):
        for ite in itertools.combinations(range(1,N), r+1):
            a=[0]+list(ite)+[N]

            for i in range(len(a)-1):
                b=int(S[a[i]:a[i+1]])
                ans+=b
                
                
    print(ans)

main()

Submission status: Accepted

Solution code:
def dfs(i, f):
    if i == len(s) - 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()
print(dfs(0, s[0]))

Submission status: Accepted

Solution code:
S = input()
n = len(S)
def cal(i, f):
    if i == n-1:
        return eval(f)
    return cal(i+1, f+S[i+1]) + cal(i+1, f+'+'+S[i+1])
print(cal(0, S[0]))

Submission status: Accepted

Solution code:
import itertools
def main():
    S = input()
    ans = 0
    plus = itertools.product([0,1], repeat=len(S)-1)
    for pl in plus:
        now = '0'
        for p, s in zip(pl+(1,), S):
            now += s
            if p:
                ans += int(now)
                now = '0'
    print(ans)
main()

Submission status: Accepted

Solution code:
s=input()

sum = 0

for bit in range(2 ** (len(s) - 1)):
    t = []
    
    idx=0
    for i in range(len(s) - 1):
        if 1 & (bit >> i):
            t.append(s[idx:i+1])
            idx = i+1
        
    t.append(s[idx:])

    for tt in t:
        sum+=int(tt)

print(sum)

Submission status: Accepted

Solution code:
def main(S,l):
    if l == 1:
        return S

    ans = 0
    digit = 0

    # for every subset of positions
    for i in range(2**(l-1)):
        digit = 0
        for j in range(l):
            ans += int(S[l-j-1])*(10**digit)
            if i&(2**j) == 0:   # "+" is not inserted into the left of the number
                digit += 1
            else:
                digit = 0

    return ans

S = input()
l = len(S)
print(main(S,l))

Submission status: Accepted

Solution code:
s = input()
chk = []
def f(a,b):
  if a==len(b):
    chk.append(eval(b))
  else:
    return f(a+1,b),f(a+2,b[:a]+'+'+b[a:])
f(1,s)
print(sum(chk))

Submission status: Accepted

Solution code:
s = input()
l = len(s)
cases = 2 ** (l - 1)
ans = 0

for i in range(cases):
    tmp = int(s)
    adjust = str(format(i, 'b').zfill(l-1))
    k = 0
    for j in range(l-1):
        if adjust[j] == '1':
            ans += tmp % (10 ** (k+1))
            tmp //= 10 ** (k+1)
            k = 0
        else:
            k += 1
    ans += tmp

print(ans)

Submission status: Accepted

Solution code:
s = list(map(int, input()))[::-1]
l = len(s)
b = 1<<(l-1)

sum = 0
for i in range(b):
  conseq = 0
  for j in range(l):
    sum += s[j] * 10**conseq
    if i>>j & 1:
      conseq = 0
    else:
      conseq += 1
      
print(sum)

Submission status: Accepted

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

def tasu(a,b):
    if a == n-1:
        return sum(list(map(int,b.split("+"))))

    return tasu(a+1,b+s[a+1])+ \
        tasu(a+1,b+"+"+s[a+1])
print(tasu(0,s[0]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for bit in range(1<<l-1):
    plus = []
    for i in range(l-1):
        if 1<<i & bit:
            plus.append(i)
    
    if plus:
        a = 0
        b = 0
        for i in range(len(plus)):
            a = b
            b = plus[i] + 1
            ans += int(s[a:b])
        ans += int(s[b:])

print(ans)

Submission status: Accepted

Solution code:
Sstr = list(input())
l = len(Sstr)
final_ans = 0
for i in range(2 ** (l-1)):
    ans = list(Sstr[0])
    for j in range(l - 1):
        if (i >> j) & 1:
            ans.append('+')
            ans.append(Sstr[j+1])
        else:
            ans.append(Sstr[j + 1])
    final_ans += eval(''.join(ans))
print(final_ans)

Submission status: Accepted

Solution code:
import sys
import itertools
readline = sys.stdin.buffer.readline

s = readline().rstrip().decode('utf-8')
n = len(s)
dig = n-1 #桁数
bit_mask = list(itertools.product([0,1],repeat=dig))
ans = 0
for i in bit_mask:
    res = []
    p = s[0]
    for j,k in enumerate(i,1):
        if k == 0:
            p = p + s[j]
        else:
            res.append(p)
            p = s[j]
    res.append(p)
    for i in res:
        ans += int(i)

print(ans)

Submission status: Accepted

Solution code:
s=str(input())
ans=0
rang=len(s)-1
for i in range(2**rang):
  l=[]
  for j in range(rang):
    if i>>j&1:
      l.append(j)
  if len(l)==0:
    ans+=int(s)
  elif len(l)==1:
    ans+=(int(s[0:l[0]+1])+int(s[l[0]+1:]))
  else: 
    for k in range(len(l)):
      if k==0:
        ans+=int(s[0:l[k]+1])
      elif k==len(l)-1:
        ans+=(int(s[l[k-1]+1:l[k]+1])+int(s[l[k]+1:]))
      else:
        ans+=int(s[l[k-1]+1:l[k]+1])   
print(ans)

Submission status: Accepted

Solution code:
s = input()
sum = int(s)
length = len(s)
inputlist = list(s)
#print(s)

for i in range(1,2**(length-1)):
    addlist = []
    addflag = format(i,'0'+str(len(s)-1)+'b')
#    print('---cut point :{}---'.format(addflag))
    begin = 0
    for j in range(length-1):#max 9 items : index:0-8
        if addflag[j] == '1':
            addlist.append(s[begin:j+1])
            begin = j+1
        if j == length-2:#last index
            addlist.append(s[begin::])
#    print(addlist)
    for item in addlist:
        sum += int(item)
print(sum)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s = input().strip()
  sum = 0
  for i in range(2**(len(s)-1)):
    num = [s[0]]
    for j in range(1, len(s)):
      if i & (2**(j-1)) != 0:
        sum += int(''.join(num))
        num = [s[j]]
      else:
        num.append(s[j])
    sum += int(''.join(num))
  print(sum)

if __name__=='__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

keta = int(len(s))
cases = 2 ** (keta - 1)

lst = []
for i in range(cases):
    sushiki_moji = s[0]
    adjust = format(i, 'b').zfill(keta - 1)
    for j in range(keta - 1):
        if adjust[j] == '1':
            sushiki_moji += '+'
        sushiki_moji += s[j+1]
    lst.append(sushiki_moji)

eval_number = [eval(i) for i in lst]
print(sum(eval_number))