Problem:


Score : 300 points

Problem Statement

You are given a string S consisting of digits between 1 and 9, inclusive.
You can insert the letter + into some of the positions (possibly none) between two letters in this string.
Here, + must not occur consecutively after insertion.

All strings that can be obtained in this way can be evaluated as formulas.

Evaluate all possible formulas, and print the sum of the results.

Constraints

1 \leq |S| \leq 10

All letters in S are digits between 1 and 9, inclusive.

Input

The input is given from Standard Input in the following format:

S

Output

Print the sum of the evaluated value over all possible formulas.

Sample Input 1

125

Sample Output 1

176

There are 4 formulas that can be obtained: 125, 1+25, 12+5 and 1+2+5. When each formula is evaluated,

125

1+25=26

12+5=17

1+2+5=8

Thus, the sum is 125+26+17+8=176.

Sample Input 2

9999999999

Sample Output 2

12656242944



Sample input:
125


Sample output:
176

Submission status: Accepted

Solution code:
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(4100000)
from functools import lru_cache

#ここから書き始める
s = input()
ans = 0

@lru_cache(maxsize=None)
def dfs(index, ret):
    if index == len(s) - 1:
        ret += s[index]
        ret2 = map(int, ret.split("+"))
        global ans
        ans += sum(ret2)
        return
    dfs(index + 1, ret + s[index]) or dfs(index + 1, ret + s[index] + "+")

dfs(0, "")
print(ans)

Submission status: Accepted

Solution code:
s = input()
ans = 0

def dfs(index, ret):
    if index == len(s) - 1:
        ret += s[index]
        ret2 = map(int, ret.split("+"))
        global ans
        ans += sum(ret2)
        return
    dfs(index + 1, ret + s[index]) or dfs(index + 1, ret + s[index] + "+")

dfs(0, "")
print(ans)

Submission status: Accepted

Solution code:
s = input()

n = len(s) - 1
sum = 0
for i in range(2**n):
    dig = bin(i)[2:].zfill(n)
    tp = "0"
    for i in range(n):
        tp += s[i]
        if (dig[i] == "1"):  # number
            sum += int(tp)
            tp = "0"
        #print(tp)
    #for i in range():
    #sum+=
    tp += s[-1]
    sum += int(tp)
print(sum)

Submission status: Accepted

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

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

print(sum(ans))

Submission status: Accepted

Solution code:
def str_plus(splus):
    cnt = 0
    start = 0
    for i in range(len(splus)):
        #print(str(splus[i]))
        if(splus[i] == '+'):
            cnt += int(splus[start:i])
            start = i
        elif(i == len(splus)-1):
            cnt += int(splus[start:i+1])

    return cnt

def str_ary_start(s):
    splus = []
    for i in range(len(s)):
        splus.append(s[i])
        if(i != len(s)-1):
            splus.append("")

    return splus


s = input()
ans = 0

for i in range(2**(len(s)-1)):
    splus = str_ary_start(s)
    for j in range(len(s)-1):
        #print(str(i) + ' ' + str(j))
        if((i>>j)&1 == 1):
            splus[j*2+1] = '+'
    #print(splus)
    #print(str_plus("".join(splus)))
    ans += str_plus("".join(splus))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue
import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
sys.setrecursionlimit(1000000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    s = input()
    sl = [i for i in s]
    n = len(s)-1
    ans = []
    anslist = []
    sublist = [-1]*n
    for i in range(1 << n):
        for j in range(n):
            if (i>>j)&1:
                sublist[j] = "+"
        anslist.append(sl[0])
        for j in range(n):
            if sublist[j] == "+":
                anslist.append("+")
                anslist.append(sl[j+1])
            else:
                anslist.append(sl[j+1])
        ans.append(eval("".join(anslist)))
        anslist = []
        sublist = [-1]*n
    print(sum(ans))
if __name__ == "__main__":
    main() 
    
#endline===============================================

Submission status: Accepted

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

Submission status: Accepted

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

total = 0
for bit in range(2 ** l):
    n_list = []
    index = 0
    for i in range(l):
        if bit & (1 << i):
            total += int(S[index:i+1])
            index = i+1
    total += int(S[index:])
print(total)

Submission status: Accepted

Solution code:
import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint=====================================
N, K = map(int, input().split())
N, M = map(int, input().split())
A, B = map(int, input().split())

H, W = map(int, input().split())

L, R = map(int, input().split())

1行のstring=================================
S, T = input().split()

1行の整数配列================================
P = list(map(int,input().split()))

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

D = list(map(int,input().split()))

L = list(map(int,input().split()))
R = list(map(int,input().split()))

T = list(map(int,input().split()))

改行あり整数==================================
X = []
Y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    X.append(x1)
    Y.append(y1)

A = []
for i in range(N):
    a=int(input())
    A.append(a)

Pair = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    Pair.append((x1, y1))
    
2次元整数配列=====================================
A = []
for i in range(N):
    tmp = list(map(int,input().split()))
    A.append(tmp)


N行M列の初期化====================================
dp = [[VAL] * RETU for i in range(GYO)]

'''



S = input()

S = S[::-1]



ans = int(S[0]) * (2**(len(S)-1))
for i in range(1, len(S)):
    final = 0    
    for keta in range(0, i+1):
        if keta == i:
            final = 1
        ans += int(S[i]) * (10**keta) * (2**int(len(S)-2-keta+final))
        #print(S[i], keta, int(S[i]) * (10**keta) * (2**int(len(S)-2-keta+final)))
print(ans)

Submission status: Accepted

Solution code:
import itertools

s = input()
n = len(s)
ans = 0

for item in itertools.product([0, 1], repeat=n-1):
    s_new = s[0]
    for i in range(len(item)):
        if item[i]:
            s_new += '+' + s[i+1]
        else:
            s_new += s[i+1]
    ans += sum([int(item) for item in s_new.split('+')])
print(ans)

Submission status: Accepted

Solution code:
s = input() #bit全探索
l = len(s) -1
n = 2**l
cnt = 0

for i in range(n):
    ls = []
    for j in range(l):
        if (n-i >> j) & 1:
            ls.append(j+1)
    ls.append(l+1)
    a = 0
    for z in ls:
        cnt += int(s[a:z])
        a = z
print(cnt)

Submission status: Accepted

Solution code:
import itertools

S = input()
S_list = list(S)
keta = len(S)

plus=list(itertools.product([0,1], repeat = keta-1))

All = 0
for posi in plus:
    preserved = [S_list[0]]
    for k in range(len(posi)):
        if posi[k] == 1:
            preserved.append(S_list[k+1])
        else:
            All += int("".join(str(n) for n in preserved))
            preserved = [S_list[k+1]]
    All += int("".join(str(n) for n in preserved))

print(All)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

s = list(input())
g,s_len=0,len(s)
for i in range(2**(s_len-1)):
    siki = s[0]
    for j in range(s_len-1):
        if i&(1<<j): siki+='+'
        siki+=s[j+1]
    tmp=0
    for j in range(len(siki)):
        if siki[j]!='+':
            tmp = tmp*10+int(siki[j])
        else:
            g+=tmp
            tmp=0
    g+=tmp
print(g)

Submission status: Accepted

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

ans=0
for bit in range(1<<n):
  l=[s[0]]
  for i in range(n):
    if (bit>>i)&1:
      l.extend(['+',s[i+1]])
    else:
      l.append(s[i+1])
  ans+=eval(''.join(l))
print(ans)

Submission status: Accepted

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

def dfs(i,s):
  if i==n-1:
    return eval(''.join(s))
  else:
    s1,s2=s.copy(),s.copy()
    s1.insert(2*i+1,'+')
    s2.insert(2*i+1,'')
    return dfs(i+1,s1)+dfs(i+1,s2)
  
print(dfs(0,s))

Submission status: Accepted

Solution code:
s=input()

def dfs(i,j):
    ans = 0
    if i == len(s) - 1:
        return sum(list(map(int,j.split("+"))))
    return dfs(i+1,j + s[i+1]) + dfs(i+1,j+"+"+s[i+1])

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

Submission status: Accepted

Solution code:
# たくさんの数式 https://atcoder.jp/contests/arc061/tasks/arc061_a
S = input()
ans = 0
for i in range(1<<(len(S)-1)):
    chars = S[0]
    for j in range(len(S)-1):
        if ((i >> j) & 1) == 1:
            chars += '+' + S[j+1]
        else:
            chars += S[j+1]
    ans += eval(chars)
print(ans)

Submission status: Accepted

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

ans = 0

for bit in range(1 << n):
	L = []
	f = 0
	s = 0
	for i in range(n):
		if bit & (1 << i):
			s = i + 1
			L.append(int(S[f:s]))
			f = s
	L.append(int(S[s:]))
	ans += sum(L)

print(ans)

Submission status: Accepted

Solution code:
S = input()
bit = 0
sum = 0
while bit < (1<<len(S)-1):
    b = 0
    keta = 0
    for i in range(len(S)):
        if bit & (1<<i):
            sum += b + int(S[len(S)-1-i])*(10**keta)
            b = 0
            keta = 0
        else:
            b += int(S[len(S)-1-i])*(10**keta)
            keta += 1
            if i == len(S) - 1:
                sum += b
    bit += 1
print(sum)

Submission status: Accepted

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

for i in range(2 ** n):
    sep = [0] * n
    nums = []
    for j in range(n):
        if (i >> j) & 1:
            sep[j] = 1
    for ind, su in enumerate(s):
        tmp += su
        if ind < len(sep):
            if sep[ind] == 1:
                tmp += ","
    ans += sum(list(map(int, tmp.split(","))))
    tmp = ""

print(ans)

Submission status: Accepted

Solution code:
S = input()
n = len(S)
ans = 0
def eval(s):
    ls = s.split("+")
    return sum(map(int,ls))
b = list("x".join(list(S)))
for i in range(2**(n-1)):
    a = b.copy()
    for j in range(n-1):
        if i >> j & 1:
            a[j*2+1] = "+"
        else:
            a[j*2+1] = ""
    ans += eval("".join(a))
print(ans)

Submission status: Accepted

Solution code:
def main():
  s=str(input())
  l=len(s)
  ans=0
  
  for i in range(2**(l-1)):
    j=bin(i)[::-1]
    t=s
    c=1
    for k in j:
      if k=="1":
        ans+=int(t[-c:])
        t=t[:-c]
        c=1
      else:
        c+=1
    else:
      ans+=int(t)
    
  print(ans)
  
  
if __name__=="__main__":
  main()

Submission status: Accepted

Solution code:
def main():
  s=str(input())
  l=len(s)
  ans=0
  
  for i in range(2**(l-1)):
    j=bin(i)[::-1]
    tmp=[]
    t=s
    c=1
    for k in j:
      if k=="1":
        tmp.append(int(t[-c:]))
        t=t[:-c]
        c=1
      else:
        c+=1
    else:
      tmp.append(int(t))
    ans+=sum(tmp)
    
  print(ans)
  
  
if __name__=="__main__":
  main()

Submission status: Accepted

Solution code:
def main():
  s=str(input())
  l=len(s)
  ans=0
  
  for i in range(2**(l-1)):
    j=bin(i)[::-1]
    tmp=[]
    t=s
    c=1
    for k in j:
      if k=="1":
        tmp.append(t[-c:])
        t=t[:-c]
        c=1
      else:
        c+=1
    else:
      tmp.append(t)
    ans+=sum(map(int,tmp))
    
  print(ans)
  
  
if __name__=="__main__":
  main()

Submission status: Accepted

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

        for j in range(len(b)):
            c += s[j]
            if b[j] == "1":
                c += "+"
        c += s[-1]
        total = sum(map(int, c.split("+")))
        ans += total
    print(ans)

Submission status: Accepted

Solution code:
# 出力したい合計値
str_input = input()
sum_all = 0

# strで入力される

# str_input = "1234567891"
# str_input = "9999999999"
# 文字列の長さを読み取る
n = len(str_input)

# 文字列の長さから+を入れる組み合わせの総数を取得

plus_pattern_2 = (2**(n-1))-1

# plus_pattern_2 = 1000

for value in range(plus_pattern_2+1):
    # print("plus_pattarn", value)
    # 右端
    right = n
    
    tmp_number = 0

    for i in range(1, n+1):
        # print(i, "番目")
        # print(bin(value))
        result = value & 1
        if result == 1:
            # print("hit")
            tmp_number = int(str_input[n-i:right])
            # print(tmp_number)
            sum_all += tmp_number
            right = n-i
        value = value >> 1
        # print("next")
        # print("")

    # print("left number")

    tmp_number = int(str_input[n-i:right])
    # print("tmp_number", tmp_number)
    sum_all += tmp_number
    # print("tmp_all", sum_all)

print(sum_all)

Submission status: Accepted

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)


class Dijkstra:
 
    def __init__(self, rote_map, start_point, goal_point=None):
        self.rote_map = rote_map
        self.start_point = start_point
        self.goal_point = goal_point
 
    def execute(self):
        num_of_city = len(self.rote_map)
        dist = [float("inf") for _ in range(num_of_city)]
        prev = [float("inf") for _ in range(num_of_city)]
 
        dist[self.start_point] = 0
        heap_q = []
        heapq.heappush(heap_q, (0, self.start_point))
        route_count = [0 for _ in range(num_of_city)]
        route_count[self.start_point] = 1
        while len(heap_q) != 0:
            prev_cost, src = heapq.heappop(heap_q)
 
            if dist[src] < prev_cost:
                continue
 
            for dest, cost in self.rote_map[src].items():
                if cost != float("inf") and dist[dest] > dist[src] + cost:
                    dist[dest] = dist[src] + cost
                    heapq.heappush(heap_q, (dist[dest], dest))
                    prev[dest] = src
                if dist[dest] == dist[src] + cost:
                    route_count[dest] += route_count[src]
 
        if self.goal_point is not None:
            return self._get_path(self.goal_point, prev)
        else:
            return dist, route_count
 
    def _get_path(self, goal, prev):
        path = [goal]
        dest = goal
 
        while prev[dest] != float("inf"):
            path.append(prev[dest])
            dest = prev[dest]
 
        return list(reversed(path))

        
def main(): #startline--------------------------------------------
    s = input()
    sl = [i for i in s]
    n = len(s)-1
    ans = []
    anslist = []
    sublist = [-1]*n
    for i in range(1 << n):
        for j in range(n):
            if (i>>j)&1:
                sublist[j] = "+"
        anslist.append(sl[0])
        for j in range(n):
            if sublist[j] == "+":
                anslist.append("+")
                anslist.append(sl[j+1])
            else:
                anslist.append(sl[j+1])
        ans.append(eval("".join(anslist)))
        anslist = []
        sublist = [-1]*n
    print(sum(ans))
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Accepted

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

def count(s,l):
    return int(s)+sum([2**(l-i-1)*int(s[:i])+count(s[i:],l-i) for i in range(1,l)])

print(count(s,n))

Submission status: Accepted

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)


class Dijkstra:
 
    def __init__(self, rote_map, start_point, goal_point=None):
        self.rote_map = rote_map
        self.start_point = start_point
        self.goal_point = goal_point
 
    def execute(self):
        num_of_city = len(self.rote_map)
        dist = [float("inf") for _ in range(num_of_city)]
        prev = [float("inf") for _ in range(num_of_city)]
 
        dist[self.start_point] = 0
        heap_q = []
        heapq.heappush(heap_q, (0, self.start_point))
        route_count = [0 for _ in range(num_of_city)]
        route_count[self.start_point] = 1
        while len(heap_q) != 0:
            prev_cost, src = heapq.heappop(heap_q)
 
            if dist[src] < prev_cost:
                continue
 
            for dest, cost in self.rote_map[src].items():
                if cost != float("inf") and dist[dest] > dist[src] + cost:
                    dist[dest] = dist[src] + cost
                    heapq.heappush(heap_q, (dist[dest], dest))
                    prev[dest] = src
                if dist[dest] == dist[src] + cost:
                    route_count[dest] += route_count[src]
 
        if self.goal_point is not None:
            return self._get_path(self.goal_point, prev)
        else:
            return dist, route_count
 
    def _get_path(self, goal, prev):
        path = [goal]
        dest = goal
 
        while prev[dest] != float("inf"):
            path.append(prev[dest])
            dest = prev[dest]
 
        return list(reversed(path))

        
def main(): #startline--------------------------------------------
    s = input()
    sl = [i for i in s]
    n = len(s)-1
    ans = []
    sublist = [-1]*n
    anslist = []
    for i in range(1 << n):
        for j in range(n):
            if (i >> j)&1:
                sublist[j] = "+"
        anslist.append(sl[0])
        for j in range(n):
            if sublist[j] == "+":
                anslist.append("+")
                anslist.append(sl[j+1])
            else:
                anslist.append(sl[j+1])
        ans.append(eval("".join(anslist)))
        anslist = []
        sublist = [-1]*n

    print(sum(ans))
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Accepted

Solution code:
S = list(input())

ans = 0
for i in range(2 ** (len(S) - 1)):
    bit = format(i,  '0' + str(len(S) - 1) + 'b')
    formula = str("")
    # bitが1の場合は"+"を付与する
    for j in range(len(S) - 1):
        formula = formula + (S[j] + "+" * int(bit[j]))
    # 末尾の値を足す
    formula = formula + S[-1]
    # 数式の値を解に加算する
    ans += eval(formula)

print(ans)

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
total = 0
for i in range(2 ** (n-1)):
    bag = []
    for j in range(n):
        if ((i >> j) & 1):
            bag.append(s[j])
            bag.append('+')
        else:
            bag.append(s[j])
        #print(bag)
    bag = ''.join(bag)
    #print(bag)
    for m in bag.split('+'):
        total += int(m)
print(total)

Submission status: Accepted

Solution code:
s = input()
total = 0

for bit in range(1 << len(s)-1):
  lis = s[0]
  for i in range(len(s)-1):
    if ((bit>>i) & 1):
      lis += "+"
    lis += s[i+1]
  total += sum(map(int, lis.split("+")))

print(total)

Submission status: Accepted

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    s = input()
    sl = [i for i in s]
    n = len(s)-1
    sublist = [-1]*n
    anslist = []
    ans = []
    for i in range(1<<n):
        for j in range(n):
            if (i>>j)&1:
                sublist[j] = "+"
        anslist.append(sl[0])
        for j in range(n):
            if sublist[j] == "+":
                anslist.append(sublist[j])
                anslist.append(sl[j+1])
            else:
                anslist.append(sl[j+1])
        ans.append(eval("".join(anslist)))
        anslist = []
        sublist = [-1]*n
    print(sum(ans))
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
listbit = []
lenplus = len(S)-1
for i in range(2**lenplus):
    suuji = ''
    for j in range(len(S)):
        suuji += S[j]
        if (i >> j & 1):
            suuji += '+'
    listbit.append(suuji)

ans = 0
for i in listbit:
    ans += eval(i)
print(ans)

Submission status: Accepted

Solution code:
from itertools import zip_longest as Zip
s=input()
l=len(s)-1
ans=0
for i in range(2**l):
  d=s
  ans+=eval("".join([x+y for x,y in Zip(d,format(i,"b").zfill(l).replace("0","#").replace("1","+"),fillvalue="")]).replace("#",""))
print(ans)

Submission status: Accepted

Solution code:
S = list(input())

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

Submission status: Accepted

Solution code:
def main(s):
    sumval = 0
    #2 ** (入力文字列の長さ - 1)が探索範囲
    for i in range(2 ** (len(s) - 1)):
        #数式作成
        t = ""
        for j in range(len(s)):
            t += s[j]
            if (i >> j) & 1:
                t += "+"
        lst = list(map(int, t.split("+")))
        sumval += sum(lst)
    return sumval

s = input()
print(main(s))

Submission status: Accepted

Solution code:
S = [s for s in input()]

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

Submission status: Accepted

Solution code:
#coding:utf-8
S=str(input())
n=len(S)-1
answer=0
for i in range(2**(n)):
  formula=S[0]
  for j in range(n):
    if ((i>>j)&1):
      formula+="+"
    formula+=S[j+1]
  answer+=sum(map(int,formula.split("+")))
print(answer)

Submission status: Accepted

Solution code:
s = input()
s_len = len(s)
s_ary = list(s)

#print(s_ary)
sowa = 0

for i in range(2**(s_len-1)):
    x="{:0" + str(s_len-1) + "b}"
    keisan = list(str(x.format(i)))
    #print(keisan)
    zentai = 0
    flag = 0
    for j in range(s_len-1):
        #print(int(s_ary[s_len-1-j])*10**flag)
        zentai += int(s_ary[s_len-1-j])*10**flag
        if(keisan[j]=="0"):
            flag = 0
        else:
            flag += 1
    
    #print(int(s_ary[0])*10**flag)
    zentai += int(s_ary[0])*10**flag
    sowa += zentai

print(sowa)

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
if n == 1:
    print(int(s[0]))
else:    
    n2 = 2**(n-1)
    #print(n2)
    n3 = (n-1)*-1
    # if n2 = 1
    ans=0
    for i in range(n2):
        li = list(format(i,'010b'))
        li = li[n3:]
        #    print(li)
        tmpstr=s[0]
        tmpnum=0
        index = 0
        for j in li:
            #        print("ans",ans,"tmpstr",tmpstr,"tmpnum",tmpnum,"index",index)
            if j == '0':
                # string
                tmpstr=tmpstr+s[index+1]
            else:
                # plus
                if tmpstr =="":
                    tmpnum=0
                else:
                    tmpnum=int(tmpstr)
                    tmpstr=s[index+1]
                    ans=ans+tmpnum
            index += 1
        if tmpstr != "":
            #        print("ans",ans,"tmpstr",tmpstr)
            tmpnum=int(tmpstr)
            ans=ans+tmpnum
    print(ans)

Submission status: Accepted

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

ans=0

for b in range(1<<(n-1)):
  f=s[0]
  for i in range(n-1):
    if b&(1<<i):
      f+='+'
    f+=s[i+1]
  ans+=sum(map(int,f.split('+')))
print(ans)

Submission status: Accepted

Solution code:
from itertools import zip_longest as Zip
s=input()
ans=0
g=len(s)
for i in range(2**(g-1)):
  d=s
  k=bin(i)[2:]
  k="0"*(g-len(k)-1)+k+"0"
  ans+=eval("".join([d[j]+ ("+" if k[j]=="1" else "") for j in range(g)]))
print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
from itertools import product

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

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

ans = 0
for plus in product([0,1], repeat=n):
    num = []
    a = s[0]
    for i, flag in enumerate(plus):
        if flag == 0:
            a = a + s[i+1]
        else:
            num.append(a)
            a = s[i+1]
    num.append(a)
    ans += sum(map(int, num))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def calc(S,n):
    if n==len(S):
        return eval(S)
    return calc(S,n+1)+calc(S[:n]+"+"+S[n:],n+2)

def main():
    S=input()
    print(calc(S,1))

main()

Submission status: Accepted

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

Submission status: Accepted

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

answer = 0

for bit in range(1 << (N-1)):
    f = S[0]

    for i in range(N-1):
        if bit & (1 << i):
            f += '+'
        f += S[i+1]

    answer += sum(map(int, f.split('+')))

print(answer)

Submission status: Accepted

Solution code:
from itertools import product
n = list(input())
L = (1,0)
ss = ""
li = []
for v in product(L,repeat =len(n)-1):
    v = list(v)+[0]
    for i in range(len(n)):
        ss += str(n[i])
        
        if v[i] == 1:
            ss += "+"
    li.append(eval(ss))
    ss = ""
print(sum(li))