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:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = list(map(int, input()))
    n = len(s)
    ans = 0
    m = 1<<(n-1)
    for b in range(m):
        a = s[0]
        m = 0
        for i in range(n-1):
            if b&(1<<i):
                a *= 10
                a += s[i+1]
            else:
                m += a
                a = s[i+1]
        ans += a+m
    print(ans)
    return

#B
def B():

    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#G
def G():

    return

#H
def H():

    return

#I
def I_():

    return

#J
def J():

    return

#Solve
if __name__ == "__main__":
    A()

Submission status: Accepted

Solution code:
from itertools import product
S=input()
s=[]
for i in range(len(S)):
    s.append(int(S[i]))
L=len(S)-1
l=list(product([1,0],repeat=L))
a=0
for i in range(len(l)):
    t=0
    a+=s[-1]
    for j in range(L-1,-1,-1):
        if l[i][j]:
            t+=1
        else:
            t=0
        a+=s[j]*10**t
print(a)

Submission status: Accepted

Solution code:
S = input()

total_sum = 0

def pros(last_str, cur, remain):
  global total_sum
  if len(remain) == 1:
    total_sum += cur + int(last_str + remain[0])
  else:
    pros(last_str + remain[0], cur, remain[1:])
    pros('', cur + int(last_str + remain[0]), remain[1:])
pros('', 0, S)
print(total_sum)

Submission status: Accepted

Solution code:
import itertools

S = input()
ans = 0
if len(S) == 1:
    print(int(S))
    exit()
for s in itertools.product(range(2), repeat=len(S)-1):
    t = 0
    for i in range(len(S)-1):
        if s[i] == 1:
            ans += int(''.join(S[t:i+1]))
            t = i+1
        if len(S)-2 == i:
            ans += int(''.join(S[t:]))
print(ans)

Submission status: Accepted

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

for i in range(2 ** (n - 1)):
    sub = []
    for j in range(n - 1):
        if (i >> j) & 1 == 1:
            sub.append('+')
        else:
            sub.append('')            
    f = S[0]
    for k in range(n - 1):
        f += sub[k] + S[k + 1]
    res += eval(f)            

print(res)

Submission status: Accepted

Solution code:
S = list(input())

def dfs(i, s):
    res = 0
    if i == len(S) - 1:
        f = S[0]
        for j in range(len(s)):
            f += s[j] + S[j + 1]
        return eval(f)

    for o in [['+'], ['']]:
        res += dfs(i + 1, s + o)

    return res

print(dfs(0, []))

Submission status: Accepted

Solution code:
from itertools import accumulate
S=[int(i) for i in input()]

N=len(S)
sac=[0]+list(accumulate(S))
ans=0

for i in range(N):
  ans+=int(sac[i]*2**(i-1)+2**i*S[i]) * 10**(N-1-i)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(map(int, input()))
rs = []
for b in range(2**(len(S)-1)):
  r = 0
  c = 0
  for i in range(len(S)-1):
    c = 10*c+S[i]
    if b&(1<<i) != 0:
      r += c
      c = 0
  c = 10*c+S[-1]
  r += c
  rs.append(r)
r = sum(rs)
print(r)

Submission status: Accepted

Solution code:
S = list(input())

def dfs(i, S):
    if i == len(S):
        #print(S)
        sum = 0
        num = 0
        for char in S:
            if num == 0 and char != '+':
                num += int(char)
            elif num != 0 and char != '+':
                num = num * 10 + int(char)
            else:
                #print(num, end=' ')
                sum += num
                num = 0
        #print(num)
        sum += num
        return sum
    else:
        # +を入れるパターン
        S.insert(i, '+')
        num1 = dfs(i + 2, S)
        S.pop(i)

        # +を入れないパターン
        num2 = dfs(i + 1, S)

    return num1 + num2

print(dfs(1, S))

Submission status: Accepted

Solution code:
from itertools import combinations

S = input()
lenS = len(S)
idx_list = [i for i in range(1,lenS)]
ans = 0
for i in range(1, lenS):
  for combination in combinations(idx_list, i):
    prv_idx = 0
    for idx in combination:
      ans += int(S[prv_idx:idx])
      prv_idx = idx
    ans += int(S[idx:])
print(ans+int(S))

Submission status: Accepted

Solution code:
#main program
S=input()
n=len(S)

ans=0

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

    for i in range(0,n-1):
        if bit & (1 << i):
            f=f+"+"
        f=f+S[i+1]
    
    ans=ans+sum(map(int,f.split("+")))

print(ans)

Submission status: Accepted

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

for i in range(2**(len(s)-1)):
    ss = s.copy()
    for j in range(len(s)-1,-1,-1):
        if (i>>j)&1:
            ss.insert(j+1, "+")
    k = "".join(ss)
    k = map(int, k.split("+"))
    ans += sum(k)
print(ans)

Submission status: Accepted

Solution code:
S=input()

ans=0
for i in range(2**(len(S)-1)):
    num=[]
    Binary=bin(i)[2:].zfill(len(S)-1)
    for j in range(len(S)):
        s=int(S[j])
        if j==0:
            num.append(s)
        else:
            if Binary[j-1]=="0":
                tmp=num.pop()*10
                num.append(tmp+s)
            else:
                num.append(s)
    ans+=sum(num)

print(ans)

Submission status: Accepted

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

def dp(s, i, used, limit):
  if i == N - 1:
    if used == limit:
      return eval(''.join(s))
    else:
      return 0
  if used > limit:
    return 0
  splus = s[:]
  splus[i] += '+'
  ret = dp(splus[:], i + 1, used + 1, limit) + dp(s[:], i + 1, used, limit)
  return ret

ret = 0
for p in range(N):
  ret += dp(S[:], 0, 0, p)

print(ret)

Submission status: Accepted

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


def fn(s, arr):
    ans.append(int(s) + sum(map(int, arr)))
    for i in range(1, len(s)):
        fn(s[i:], arr + [s[:i]])


fn(S, [])
print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
n=len(s)
if n==1:
  print(int(s))
  exit()
if n==2:
  m=int(s)
  print(m+m//10+m%10)
  exit()

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    memo = dict()

    def helper(S, i):
        # i is the starting index
        if i == len(S): return [0, 1]
        if i == len(S)-1: return [int(S[i]), 1]

        if i not in memo:
            memo[i] = [0, 0]
            for j in range(i+1, len(S)+1):
                if j not in memo:
                    memo[j] = helper(S, j)
                memo[i][0] += int(S[i:j])*memo[j][1] + memo[j][0]
                memo[i][1] += memo[j][1]
            # print(memo)
        return memo[i]

    return helper(S, 0)[0]

if __name__ == '__main__':

    print(main())

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc045/tasks/arc061_a
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    s = input()

    def build(sub):
        if len(sub) == 1:
            return [sub]
        top = sub[0]
        rest = build(sub[1:])

        ret = []
        for r in rest:
            ret.append(top + r)
            ret.append(top + '+' + r)
        return ret

    ans = sum(map(lambda inp: eval(inp), build(s)))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
ans = 0
for num in range(2**((len(S)-1))):
  before = 0
  nums = []
  for i in range(len(S)-1):
    if num>>i&1:
      nums.append(int(S[before:i+1]))
      before = i+1
  nums.append(int(S[before:]))
  ans += sum(nums)
print(ans)

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)


S = input()

"""
10こ数字がならんでいるとして、各プラスいれるかいれないかで2**10通りある
つまり1024通りしかない
普通に計算するか、dfs
"""
def dfs(l):
    global ans
    if len(l) == len(S)-1:
        #  print(l)
        s = S[0]
        for idx, is_plus in enumerate(l):
            if is_plus:
                #  print(int(s))
                ans += int(s)
                s = S[idx+1]
            else:
                s = s + S[idx+1]
        else:
            #  print(int(s))
            ans += int(s)
    else:
        dfs(l + [True])
        dfs(l + [False])

ans = 0
dfs([])
print(ans)

Submission status: Accepted

Solution code:
def dfs(i, func):
    if i == len(S) - 1:
        return eval(func)

    ret = 0
    ret += dfs(i + 1, func + S[i + 1])
    ret += dfs(i + 1, func + '+' + S[i + 1])
    return ret


S = input().strip()

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

Submission status: Accepted

Solution code:
s = input()

n = len(s)

ans = 0
for bit in range(1<<(n-1)):
    sum = 0
    insert = [0]
    for i in range(n-1):
        if bit & (1<<i):
            insert.append(i+1)
    insert.append(n+1)
    for j in range(len(insert)-1):
        sum += int(s[insert[j]:insert[j+1]])
    
    ans += sum

print(ans)

Submission status: Accepted

Solution code:
import itertools


def main():
    s = input()
    n = len(s)
    a = list(itertools.product(['+', ''], repeat=n - 1))
    ans = 0
    for i in a:
        formula = s[0]
        for index, j in enumerate(i):
            formula += j
            formula += s[index + 1]
        ans += eval(formula)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = str(input())
l = list(map(str,(map(bin,range(2**(len(S)-1))))))

ans = 0
for i in range(len(l)):
    ev = l[i][2:].zfill(len(S)-1)
    res = 0
    num_str = S[0]
    for j in range(1,len(S)):
        if(ev[j-1] == '0'):
            num_str = num_str + S[j]
        else:
            res += int(num_str)
            num_str = S[j]
    res += int(num_str)
    ans += res

print(ans)

Submission status: Accepted

Solution code:
S = input()

ans = 0
if len(S) == 1:
    ans = int(S)
else:
    for i in range(2**(len(S)-1)):
        tmp = S[0]
        for j, b in enumerate(format(i, 'b').zfill(len(S)-1)):
            if b == '1':
                tmp += '+'
            tmp += S[j+1]
        ans += eval(tmp)
print(ans)

Submission status: Accepted

Solution code:
s = input()

if len(s) == 1:
  print(s)
  exit()

a = 0
di = len(s) - 1
m = 2 ** di
for i in range(m):
  b = format(i, 'b').zfill(di)
  fs = ''
  for c, d in zip(s, b):
    fs += c
    if d == '1':
      fs += '+'
  fs += s[-1]
  a += eval(fs)

print(a)

Submission status: Accepted

Solution code:
import sys
INPUT = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 9)


def main():
    S = INPUT()
    l = len(S)
    ans = 0

    for i in range(2**(l-1)):
        tmp = S[0]
        for j in range(l-1):
            if (i >> j) & 1: tmp += "+"
            tmp += S[j+1]

        ans += eval(tmp)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    S = SI()

    ans = int(S)
    for 文字数 in range(1, len(S)):
        for 開始位置 in range(len(S)-文字数+1):
            if 開始位置 == 0 or 開始位置+文字数 == len(S):
                ans += int(S[開始位置:開始位置+文字数]) * 2**(len(S) - 1 - 文字数)
            else:
                ans += int(S[開始位置:開始位置+文字数]) * 2**(len(S) - 1 - 文字数 -1)
    print(ans)

main()

Submission status: Accepted

Solution code:
s = input()
answer = 0

if len(s) == 1:
    print(s)
else:
    for i in range(2**(len(s)-1)):
        f = s[0]
        for j,b in enumerate(str(format(i,'b').zfill(len(s)-1))):
            if b == '1':
               f += ','
            f += s[j+1]
        answer += sum(int(i) for i in f.split(','))
    print(answer)

Submission status: Accepted

Solution code:
s=list(input())

out=0
for p in range(1,2**(len(s)-1)):
  plus_p=list(str(bin(p))[2:])
  plus_p.reverse()
  plus_p=[i for i,pp in enumerate(plus_p) if pp=='1']
  for j in range(len(plus_p)):
    if j==0:
      out+=int(''.join(s[0:plus_p[j]+1]))
    if j<len(plus_p)-1:
      out+=int(''.join(s[plus_p[j]+1:plus_p[j+1]+1]))
    else:
      out+=int(''.join(s[plus_p[j]+1:]))
print(out+int(''.join(s)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import product

S = input()
n = len(S)

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

total = 0
for o in op:
    ans = S[0]
    for i in range(n - 1):
        ans += o[i] + S[i + 1]
    total += eval(ans)
print(total)

Submission status: Accepted

Solution code:
S = input().strip()

answer = 0

for n in range(2**(len(S)-1)):
    A = [0]
    for d in range(9):
        if n & (1 << d):
            A.append(d+1)
    T = []
    #print("A", A)
    for l, r in zip(A, A[1:]):
        T.append(int("".join(S[l:r])))
    T.append(int("".join(S[A[-1]:])))
    answer += sum(T)

print(answer)

Submission status: Accepted

Solution code:
import itertools
a = input()
n = len(a)
s = int(a)
num =[x for x in range(n-1)]
for i in range(1,n):
    position = list(itertools.combinations(num,i))
    for next in position:
        t=''
        for j in range(n):
            t+=a[j]
            if j in next:
                s+=int(t)
                t=''
        s+=int(t)
print(s)

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 = input()
len_s = len(s)
l = []
for i in range(len_s):
  l.append(s[i])
  l.append('')
del l[-1]
i = 0
ans = 0
while i< 2**(len_s-1):
  for j in range(len_s-1):
    l[2*j+1] = ''  if (i//2**j)%2==0 else '+'
  ans += eval(''.join(l))
  i+=1
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 = input()
n = len(s)
count = 0
for l in range(0,n):
    for r in range(l,n):
        x = int(s[l:r+1])
        if l >= 2:
            ln = 2**(l-1)
        else:
            ln = 1
        if r <= n-3:
            rn = 2**(n-2-r)
        else:
            rn = 1
        count += rn*ln*x
print(count)

Submission status: Accepted

Solution code:
import itertools
s = input()
a = ["", "+"]
a = list(itertools.product(a, repeat=len(s) - 1))
total = 0
for i in a:
    ss = ""
    for j in range(len(s)):
        ss += s[j]
        if j < len(i) and i[j] == "+":
            total += int(ss)
            ss = ""
    total += int(ss)
print(total)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = 0
def suc(time):
  if time == []:
    return 'over'
  else:
    now = n-2
    while now >= 0:
      if time[now] == 0:
        time[now] = 1
        break
      else:
        time[now] = 0
        now -= 1
    if now >= 0:
      return time
    else:
      return 'over'
time = [0 for _ in range(n-1)]
while time != 'over':
  add = 0
  st = 0
  for i in range(n):
    try:
      if time[i] == 1:
        add += int(s[st:i+1])
        st = i+1
    except:
      #i==n
      add += int(s[st:])
  ans += add
  time = suc(time)
print(ans)

Submission status: Accepted

Solution code:

import collections
import itertools
import sys
import time

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

s = input()
n = len(s)
place_pos = n - 1


def eval_expr(expr):
    expr = expr.split("+")
    res = 0
    for s in expr:
        res += int(s)
    return res

res = 0
for h in range(1 << place_pos):
    expr = s[0]
    for i in range(place_pos):
        if h >> i & 1:
            expr = expr + "+"
        expr += s[i + 1]
    res += eval_expr(expr)

print(res)

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

Submission status: Accepted

Solution code:
s=input()
l=len(s)
def base(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out.rjust(l-1,'0')
ans=0
for i in range(2**(l-1)):
    b=base(i,2)
    p=1
    ans+=int(s[-1])
    for j in range(1,l):
        if b[-j]=="0":
            p*=10
            ans+=int(s[-j-1])*p
        else:
            p=1
            ans+=int(s[-j-1])

print(ans)

Submission status: Accepted

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

def insert(s,pos,k):
    return s[:pos+1+k] + '+' + s[pos+1+k:]

ans = 0
for i in range(2**(length-1)):
    ss = s
    bit = format(i,'b')
    bit = bit.rjust(length-1,'0')
    k = 0
    for j in range(len(bit)):
        if bit[j]=='1':
            ss = insert(ss,j,k)
            k += 1
    ans += eval(ss)

print(ans)

Submission status: Accepted

Solution code:
# C Many Formulas
s = input()
n = len(s)

def dfs(string, depth):
    if depth == n-1:
        return eval(string)
    return dfs(string+s[depth+1], depth+1) + dfs(string+"+"+s[depth+1], depth+1)

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

Submission status: Accepted

Solution code:
def c_many_formulas(S):
    import itertools
    ans = 0
    for operators in itertools.product(('', '+'), repeat=len(S) - 1):
        operator = list(operators) + ['']  # zip()に渡す文字列の長さを合わせる
        formula = ''.join([value + op for value, op in zip(S, operator)])
        ans += eval(formula)
    return ans

S = input()
print(c_many_formulas(S))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, h = IR(3)
    print((a+b)*h//2)
    return

#B
def B():
    d = defaultdict(int)
    d["a"] = deque(S())
    d["b"] = deque(S())
    d["c"] = deque(S())
    tern = "a"
    while d[tern]:
        tern =  d[tern].popleft()
    print(str.capitalize(tern))
    return

#C
def C():
    s = S()
    def dfs(tmp, s):
        res = "0"
        t = tmp if s == [] else 0
        for i in range(len(s)):
            res += s[i]
            t += dfs(int(res)+tmp, s[1 + i:])
        return t
    print(dfs(0, s))
    return

#D
def D():
    h, w, n = LI()
    ans = [(h - 2) * (w - 2)] + [0] * 9
    d = defaultdict(int)
    for _ in range(n):
        a, b = LI()
        for mb in range(-1, 2):
            mb += b
            for ma in range(-1, 2):
                if mb == ma == 0:
                    continue
                ma += a
                if 2 <= ma < h and 2 <= mb < w:
                    d[(ma, mb)] += 1
    for _, value in d.items():
        ans[value] += 1
        ans[0] -= 1
    print("\n".join(map(str, ans)))
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

Solution code:
S = input()

L = [S]

for i in range(len(S)-1):
    L_new = []
    for l in L:
        L_new.append(l[:1+2*i] + '+' + l[1+2*i:])
        L_new.append(l[:1+2*i] + ' ' + l[1+2*i:])
    L = L_new

print(sum([eval(str.replace(l, ' ', '')) for l in L]))

Submission status: Accepted

Solution code:

def main():
    data = list(map(int, list(input())))
    ans = 0
    for i in range(2 ** (len(data) - 1)):
        bin_data = bin(i)[2:]
        bin_data = bin_data.zfill(len(data) - 1)
        bin_data = list(map(int, list(bin_data)))

        # print(bin_data)

        kari = 0
        for j in range(len(data) - 1):
            if bin_data[j]:
                ans += kari * 10 + data[j]
                kari = 0
            else:
                kari = kari * 10 + data[j]
        ans += kari * 10 + data[len(data) - 1]

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(S: str):
    eqs = [S[0]]
    for i in range(1, len(S)):
        c = S[i]
        nex = []
        for eq in eqs:
            nex.append(eq + '+' + c)
            nex.append(eq + c)
        eqs = nex
    #print(eqs)
    ret = 0
    for eq in eqs:
        nums = eq.split('+')
        for n in nums:
            ret += int(n)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: int
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def num(k, s, ans):
    # 長さk
    if k == N:
        for a in s:
            ans += int(a)
        return ans
    ss = s[:]
    sss = s[:]
    l = ss.pop()
    ss.append(l+S[k])
    sss.append(S[k])
    ans1 = num(k+1, ss, ans)
    ans2 = num(k+1, sss, ans1)
    return ans2

print(num(1, [S[0]], 0))

Submission status: Accepted

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

def solve():
    S = input()

    def dfs(depth, s):
        if depth == len(S):
            # 計算する
            return sum(list(map(int, s.split("+"))))
        
        ret1 = dfs(depth+1, s+"+"+S[depth])
        ret2 = dfs(depth+1, s+S[depth])

        return ret1 + ret2

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

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

op_list = []

for i in range(2**n):
  op = [""] * n
  for j in range(n):
    if (i >> j) & 1:
      op[j] = "+"
  op_list.append(op)

f_list = []

for op in op_list:
  f = s[0]
  for i in range(n):
    f += op[i]
    f += s[i+1]
  f_list.append(f)

ans = 0

for f in f_list:
  ans += eval(f)

print(ans)

Submission status: Accepted

Solution code:
s=input()
dp=[0]*len(s)
dp[0]=int(s[0])
for i in range(1,len(s)):
    dp[i]=int(s[:i+1])+sum(dp[j-1]+int(s[j:i+1])*2**(j-1) for j in range(1,i+1))
print(dp[-1])

Submission status: Accepted

Solution code:
from copy import *
from sys import *
import math
import queue
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)

#dp[i][j]: iまでからj枚えらんで和がkになるのは何通り
def main():
	s = input()
	ans = 0
	if(len(s)==1): print(int(s));exit()
	for i in range(0,2**(len(s)-1)):
		temp = []
		ix2 = base_10_to_n(i,2)
		for i in range(len(s)-len(ix2)-1):
			ix2 = '0' + ix2
		tmp = s[0]
		for j in range(len(ix2)):
			if(ix2[j]=='1'):
				temp.append(tmp)
				tmp = s[j+1]
			else:
				tmp = tmp + s[j+1]
		temp.append(tmp)
		for i in temp:
			ans+=int(i)
	print(ans)


def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Accepted

Solution code:
ans = 0

s = input()
l = []
for i in s:
  l.append(i)
  l.append('x')
l.pop()

n = len(s)

def solve(k):
  global ans, n, l
  if k >= n+n-2:
    cur = ''
    for i in range(len(l)):
      if i % 2 == 1 and l[i] == '+':
        ans += int(cur)
        cur = ''
      elif i % 2 == 0:
        cur += l[i]
    ans += int(cur)
    return
  
  l[k] = '+'
  solve(k+2)
  l[k] = 'x'
  solve(k+2)

solve(1)

print(ans)

Submission status: Accepted

Solution code:
s = input()
count = 0
for i in range(len(s)):
    for j in range(i + 1, len(s) + 1):
        count += int(s[i:j]) * (2 ** (max(0, (i - 1)) + max(0, (len(s) - j - 1))))
print(count)

Submission status: Accepted

Solution code:
S = input()
sum = 0
for i in range(0, 2**(len(S)-1)):
	m = i
	lst = [S[0]]
	for j in range(1, len(S)):
		if m % 2 == 0:
			lst[-1] = lst[-1]+S[j]
		else:
			lst.append(S[j])
		m //= 2
	for j in range(0, len(lst)):
		sum += int(lst[j])
print(sum)

Submission status: Accepted

Solution code:
import itertools

# 入力                                                                                   
S = list(input())

# 組み合わせを求める                                                                     
#list(itertools.combinations(S, 2))                                                      

# indexのリストを作成                                                                    
index = []
for i in range(len(S)):
    index.append(i)

result = 0
for i in range(1,len(S)):
    list_C =  list(itertools.combinations(index, i))
    # 組み合わせを順番に見ていく                                                         
    for one in list_C:
        T = S
        # その組み合わせに応じて足していく                                               
        sum_list = []
        devide = 0
        for key in range(0,i):
            sum_list.append(''.join(T[devide:one[key]]))
            devide = one[key]
        sum_list.append(''.join(T[devide:]))
        if '' not in sum_list:
            result += sum(list(map(int,sum_list)))
result += int(''.join(S))
print(result)

Submission status: Accepted

Solution code:
S = input()
max_plus = len(S)-1
s = S[::-1]
#print(S,max_plus)                                                             
num = 2**(max_plus)
sum = 0
#print(num)                                                                    

f = 0
#print(n)                                                                      
while(s):
    f+=1
    max = 1
    n = num
    for i in s:
        t = int(i)

        sum += max*t*n
        max = max*10
        n = n//2
    s = s[1:]
    #print(s)                                                                  
#    print(sum)                                                                
    if(f==1):
        num = num//2


print(sum)

Submission status: Accepted

Solution code:
x = input()

sum = 0

for i in range(len(x)):
  #print(x[i])
  #自分より上
  sum += 2**i * int(x[i])*(10**(len(x) - i - 1))
  #print(sum)
  #自分より下
  #print("u")
  d = len(x) - i - 1#自分より下にある数字の数
  for j in range(1,d+1):
    sum += 2**i * 2**(j-1) * int(x[i]) * 10 ** (d-j)
    #print(sum)
print(sum)

Submission status: Accepted

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