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: Runtime Error

Solution code:
def __main__():
    h, w, n = list(map(int, input().split()))
    grid = []
    for i in range(h):
        row = []
        for j in range(w):
            row.append(0)
        grid.append(row)
    for i in range(n):
        ai, bi = list(map(int, input().split()))
        grid[ai - 1][bi - 1] = 1
    
    result = [0] * 10
    for i in range(h - 2):
        for j in range(w - 2):
            black = 0
            for i2 in range(3):
                for j2 in range(3):
                    if grid[i + i2][j + j2] == 1: black += 1 
            result[black] += 1
            
    for i in range(9):
        print(result[i])

__main__()

Submission status: Runtime Error

Solution code:
from collections import deque

def main():
    n,m=map(int,raw_input().split())
    g=[[] for _ in xrange(n)]
    gc=[[] for _ in xrange(10**6)]
    mxc=0

    for i in xrange(m):
        p,q,c=map(int,raw_input().split())
        p-=1;q-=1;c-=1
        g[p].append(c)
        g[q].append(c)
        gc[c].append(p)
        gc[c].append(q)
        mxc=max(mxc,c+1)

    visited=[False]*mxc
    q=deque([[0,1]])
    while len(q)!=0:
        p,dist=q.popleft()
        for i in g[p]:
            if not visited[i]:
                for j in gc[i]:
                    if j!=p:
                        if j==n-1:
                            print(dist)
                            exit()
                        q.append([j,dist+1])
    print(-1)

main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
dp=["","+"]
s=input()
su=0
for i in range(2**(len(s)-1)):
    val=""
    for j in range(len(s)-1):
        val+=s[j]
        val+=dp[bin(i)[j+2]]
    val+=s[len(s)-1]
    su+=eval(val)
print(su)

Submission status: Runtime Error

Solution code:
dp=["","+"]
s=input()
su=0
for i in range(2**(len(s)-1)):
    val=""
    for j in range(len(s)-1):
        val+=s[j]+dp[bin(i)[j+2]]
    val+=s[len(s)-1]
    su+=eval(val)
print(su)

Submission status: Runtime Error

Solution code:
from itertools import product
H, W, N = list(map(int, input().split()))
A = [tuple(map(int, input().split())) for _ in range(N)]
count = {}
for x, y in A:
    for xx, yy in product(range(x-1, x+2), range(y-1, y+2)):
        if not(2 <= xx <= H-1 and 2 <= yy <= W-1):
            continue
        count[(xx, yy)] = count.get((xx, yy), 0) + 1
ans = [0] * 10
for k, v in count.items():
    ans[v] += 1
ans[0] = (H - 2) * (W - 2) - sum(ans)
print(*ans, sep="\n")

Submission status: Runtime Error

Solution code:
s = input()

l = len(s) - 1 # 各数の間の数
# 書く数の間に'+'を入れるときは1そうでないときは0にして2進数で表す
# 全てで 2 ** l　= 2 << (l - 1)通りできる
total_patterns = 2 << (l - 1)

ans = 0
for i in range(total_patterns):
    num_between = format(i,'b').zfill(l) # 10進数を2進数に変換
    tmp = ''
    for j in range(l):
     if num_between[j] == '1':
         tmp += (s[j] + '+')
     else:
         tmp += s[j]
    tmp += s[-1]
    ans += sum([int(i) for i in tmp.split('+')])

print(ans)

Submission status: Runtime Error

Solution code:
s = input()

start = time.time()
l = len(s) - 1 # 各数の間の数
total_patterns = 2 << (l)

ans = 0
for i in range(total_patterns):
    num_between = format(i,'b').zfill(l) # 10進数を2進数に変換
    tmp = ''
    for j in range(l):
     if num_between[j] == '1':
         tmp += (s[j] + '+')
     else:
         tmp += s[j]
    tmp += s[-1]
    ans += sum([int(i) for i in tmp.split('+')])
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
int_s = [int(i) for i in s]
l = len(int_s)
total_patterns = 2 << (l - 2)


def calc_sum(s):
    # '+'を区切りとして和を求める
    num = s.split('+')
    return sum(list(map(int, num)))

ans = 0
for i in range(total_patterns):
    between = format(i,'b').zfill(l - 1) # 10進数を2進数に変換
    tmp = ''
    for j in range(len(between)):
        if between[j] == '1':
            tmp += (s[j] + '+')
        else:
            tmp += s[j]
    tmp += s[-1]
    ans += calc_sum(tmp)

print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from itertools import product
from sys import stdin
def gen_b(x,B):
	if x < 3: lb = 2
	else: lb = x - 1
	if x > B-2: ub = B-1
	else: ub = x + 1
	return xrange(lb,ub+1)
def solve():
	count = defaultdict(int)
	ans = [0]*10
	L = map(lambda x:map(int,x.split()),stdin.readlines())
	H,W,N = L[0]
	for i in xrange(1,N+1):
		for x,y in product(gen_b(L[i][0],H),gen_b(L[i][1],W)):
			count[x+(y<<34)] += 1
	for v in count.itervalues():ans[v] += 1
	ans[0] = (H-2)*(W-2) - sum(ans[1:])
	for c in ans: print c
solve()

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from sys import stdin
def gen_bound(x,B):
	if x < 3: lb = 2
	else: lb = x - 1
	if x > B-2: ub = B-1
	else: ub = x + 1
	return lb,ub+1
def solve():
	count = defaultdict(int)
	ans = [0]*10
	L = map(lambda x:map(int,x.split()),stdin.readlines())
	H,W,N = L[0]
	for i in xrange(1,N+1):
		xlb,xub = gen_bound(L[i][0],H)
		ylb,yub = gen_bound(L[i][1],W)
		for x in xrange(xlb,xub):
			for y in xrange(ylb,yub):
				count[x+(y<<34)] += 1
	for v in count.itervalues():ans[v] += 1
	ans[0] = (H-2)*(W-2) - sum(ans[1:])
	for c in ans: print c
solve()

Submission status: Runtime Error

Solution code:
from collections import defaultdict
H, W, N = map(int, input().split())
poss = [list(map(int, input().split())) for _ in range(N)]
d = defaultdict(int)
for a, b in poss:
    for i, j in ((i, j) for i in range(a-1, a+2) for j in range(b-1, b+2)):
        if 1<i<H and 1<j<W:
            s = str(i)+":"+str(j)
            d[s] += 1
anss = [0] * 10
for x in d.values():
    anss[x] += 1
print((H-2)*(W-2) - sum(anss[1:]))
for ans in anss[1:]:
    print(ans)

Submission status: Runtime Error

Solution code:
import sys
grid = []
painted = []

height, width, n = sys.stdin.readline().strip().split()
height, width, n = int(height), int(width), int(n)

def checkGrid(x, y, grid):
    count = 0
    for col in range(x, x+3):
        for row in range(y, y+3):
            if grid[row][col] == 1:
                count += 1
    return count

inp = sys.stdin.readline().strip()
while inp:
    a, b = inp.split()
    grid.append([int(a) - 1, int(b) - 1])
    inp = sys.stdin.readline().strip()

# Build empty grid
for i in range(height):
    painted.append([])
    for j in range(width):
        if [i, j] in grid:
            painted[i].append(1)
        else:
            painted[i].append(0)

# Build painted cells
for cell in grid:
    painted[cell[0]][cell[1]] = 1

for i in range(0, 10):
    count = 0
    for col in range(width - 2):
        for row in range(height - 2):
            if checkGrid(col, row, painted) == i:
                count += 1
    print(count)

Submission status: Runtime Error

Solution code:
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# 


s = input()
l = len(s)

ans = 0

m = int('1'*(l-1), 2)
for i in range(m+1):
	now = format(i, 'b').zfill(l-1)
	tmp = s[0]
	for k in range(l-1):
		if now[k] == '0':
			tmp += s[k+1]
		else:
			ans += int(tmp)
			tmp = s[k+1]
	ans += int(tmp)
print(ans)