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:
from sys import stdin

def main():
    S=input()
    andbit = 2**10 -1
    ans = 0
    length = 2**(len(S) -1)
    
    # print("length:{}".format(length))
    for i in range (length):
      bitup = andbit & i
      # print("bin(bitup):{}".format(bin(bitup)))
      bitcheck = 1
      tmp=0
      for j in range(1,len(S),1):
        # print("bitup & bitcheck:{}".format(bitup & bitcheck))
        if bitup & bitcheck > 0:
          # print("S[tmp:j]:{}".format(S[tmp:j]))
          ans += int(S[tmp:j])
          tmp = j
        bitcheck = bitcheck << 1
      # print("S[tmp:len(S)]:{}".format(S[tmp:len(S)]))
      ans += int(S[tmp:len(S)])

    print(ans)

input = lambda: stdin.readline()
main()

Submission status: Runtime Error

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

ans_lst = []
for i in range(2**n):
op = ["+"] * n 
    for j in range(n):
        if ((i >> j) & 1):
            op[n-j-1] = ""
    for num,opp in zip(s, op + [""]):
        formula += (num + opp)
    ans_lst = ans_lst + [eval(formula)]

print(sum(ans_lst))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S=input()
c=0
op_cnt=len(S)-1

for i in range(2**op_cnt):
    T=""
    for j in range(2**op_cnt):
        T += S[j]
        if ((i>>j) & 1):
            T += "+"
            print(j)
    T += S[op_cnt]
    c +=eval(T)
print(c)

Submission status: Runtime Error

Solution code:
s=input()
sl=[]
ans=0
for iii in range(2**(len(s)-1)):
  sind='{:0'+str(len(s)-1)+'b}'
  astr=sind.format(iii)
  astr=astr.replace("1","+")
  astr=astr.replace("0","x")
  lans=s[0]
  for jjj in range(len(astr)):
    lans+=astr[jjj]+s[jjj+1]
  lans=lans.replace("x","")
  ans+=int(eval(lans))
print(ans)

Submission status: Runtime Error

Solution code:
s = input()

max_plus = len(s) - 1

numList = [int(c) for c in s]

sMax = (1 << max_plus) - 1

ans = 0

for plus_pos in range(sMax + 1):
    sum = 0

    num = numList[0]

    for i in range(max_plus):
        if ((plus_pos >> i) & 1) == 1:
            sum += num
            num = numList[i + 1]
        else:
            num = num * 10 + numList[i + 1]

    sum += num
    ans += sum

print(ans)s = input()

max_plus = len(s) - 1

numList = [int(c) for c in s]

sMax = (1 << max_plus) - 1

ans = 0

for plus_pos in range(sMax + 1):
    sum = 0

    num = numList[0]

    for i in range(max_plus):
        if ((plus_pos >> i) & 1) == 1:
            sum += num
            num = numList[i + 1]
        else:
            num = num * 10 + numList[i + 1]

    sum += num
    ans += sum

print(ans)

Submission status: Runtime Error

Solution code:
s = input()
sum = 0
for i in range(2**(len(s)-1)):
    term = 0
    for j in range(len(s)-1):
        term *= 10
        if (i//(2**j))%2 == 0:
            sum += term + int(s[j])
            term = 0
            if j == len(s)-2:
                sum += int(s[-1])
        else:
            term += int(s[j])
            if j == len(s)-2:
                sum += term*10 + int(s[-1])
if len(s) = 1:
    sum = int(s)

print(sum)

Submission status: Runtime Error

Solution code:

num = input()
num_array = [i for i in num]

splits = len(num) - 1
n = 2 ** splits

sum = 0

for i in range(n):
    bin = format(i, "0{}b".format(splits))
    bin_array = [i for i in bin]
    tmp_num = str(num_array[0])
    for index, value in enumerate(bin_array):
        if value == "0":
            tmp_num += num_array[index+1]
        else:
            sum += int(tmp_num)
            tmp_num = num_array[index+1]
    sum += int(tmp_num)

print(sum)

Submission status: Runtime Error

Solution code:
s = input()
answer = 0
sumList = []
numStr = ""
for i in range(2**(len(s)-1)):
  bit = "0" + str(len(s) - 1) + "b"
  iStr = format(i, bit)
  numStr += s[0]
  for j in range(len(iStr)):
    if iStr[j] == "1":
      sumList.append(int(numStr))
      numStr = s[j+1]
    else:
      numStr += s[j+1]
  sumList.append(int(numStr))
  numStr = ""
  answer += sum(sumList)
  sumList = []
print(answer)

Submission status: Runtime Error

Solution code:
N=input()
ans=0
l=itertools.product(range(2),repeat=len(N)-1)
for i in l:
	tmp=''
	for j in range(len(i)):
		if i[j]==0:
			tmp+=N[j]
		else:
			tmp+=N[j]+'+'
	tmp+=N[-1]
	ans+=eval(tmp)
print(ans)

Submission status: Runtime Error

Solution code:
S=input()
ans=0
for i in range(2**(len(S)-1)):
    k=bin(i)[2:].zfill(len(S)-1)
    l=int(S[0])
    for j in range(len(k)):
        t=int(k[j])
        if t==1:
            ans+=l
            l=int(S[j+1])
        else:
            l=l*10+int(S[j+1])
    ans+=l
print(ans)

Submission status: Runtime Error

Solution code:
S=list(map(int,list(input())))
def manyformulas(s):
    if len(s)==1:
        return s[0]
    return s[0]*2**(len(s)-2)+manyformulas(s[1:])+manyformulas([s[0]*10+s[1], *s[2:]])
print(manyformulas(S))

Submission status: Runtime Error

Solution code:
from itertools import product
S = input()
ans = 0

for string in product(["","+"],repeat=len(S) - 1):
    string = list(string)
    string.append("")
    sum_ = [a + b for a,b in zip(S,string)]
    ans += sum_

print(ans)

Submission status: Runtime Error

Solution code:
sum = 0
A = list(map(int, input().split))

def makenum(ar):
    s = 0
    for i in range(len(ar)):
        s += ar[i] * (10 ** (len(ar) - i - 1))
    return s

for i in range(1 << len(A)):
    output = []
    for j in range(len(A)):
        if((i >> j) & 1) == 1:
            output.append(A[j])
    sum += makenum(output)
print(sum)

Submission status: Runtime Error

Solution code:
#import sys
#input=sys.stdin.readline

s=input()
ans=0

for i in range(2 ** (len(s)-1)):
  bin_i = bin(i)[2:].rjust(len(s)-1,"0")
  li=[]
  n=s[0]
  for ix,sign in enumerate(bin_i):
    if sign=="0":
      n+=s[ix+1]
    else:
      li.append(int(n))
      n=s[ix+1]
  li.append(int(n))
  ans+=sum(li)

print(ans)

Submission status: Runtime Error

Solution code:
#import sys
#input=sys.stdin.readline

s=input()
ans=0

for i in range(2 ** (len(s)-1)):
  bin_i = bin(i)[2:].rjust(len(s)-1,"0")
  li=[]
  n=s[0]
  #0がなし、1が+
  for ix,sign in enumerate(bin_i):
    if sign=="0":
      n+=s[ix+1]
    else:
      li.append(int(n))
      n=s[ix+1]
  li.append(int(n))
  ans+=sum(li)

print(ans)

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline

s=input()
ans=0

for i in range(2 ** (len(s)-1)):
  bin_i = bin(i)[2:].rjust(len(s)-1,"0")
  li=[]
  n=s[0]
  #0がなし、1が+
  for ix,sign in enumerate(bin_i):
    if sign=="0":
      n+=s[ix+1]
    else:
      li.append(int(n))
      n=s[ix+1]
  li.append(int(n))
  ans+=sum(li)

print(ans)

Submission status: Runtime Error

Solution code:
import sys
# import bisect
# import math
# import itertools
# import numpy as np
# import collections

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e, p = range, enumerate, print
    ip = IP()
    id = Idea()
    mod = 10 ** 9 + 7

    """この下から書いてね"""
    s = ip.S()
    ans = 0
    for i in r(1 << len(s)):
        output = 0
        res = 0
        for j in r(len(s)):
            if (i >> j) & 1:
                output += int(s[res:j + 1])
                res += j + 1
        output += int(s[res:])
        ans += output
    p(ans)


main()

Submission status: Runtime Error

Solution code:
from sys import stdin

a = stdin.readline().rstrip()
print(a.upper())
print(output)

Submission status: Runtime Error

Solution code:
S = input()

N = len(S)-1
sumsum = 0


for i in range(2**N):
    binary = bin(i)
    binary = binary[2:].zfill(N)

    tmps = S[0]
    for j in range(N):
        if binary[j] == '0':　　　　#ゼロの時はストックする　１２＜＝３　＝　１２３
            tmps = tmps + S[j+1]
        else :
            sumsum += int(tmps)
            tmps = S[j+1]

    sumsum += int(tmps)

if N == 0:    #一桁の時対策
    sumsum = int(S)

print(sumsum)

Submission status: Runtime Error

Solution code:
s = input()
op = ['','+']
if len(s) == 1:
    print(s)
else:
    s = s + 'X'*(10 -len(s))
    ans = []
    for a in op:
        for b in op:
            for c in op:
                for d in op:
                    for e in op:
                        for f in op:
                            for g in op:
                                for h in op:
                                    for i in op:
                                        　　　ans.append(s[0]+a+s[1]+b+s[2]+c+s[3]+d+s[4]+e+s[5]+f+s[6]+g+s[7]+h+s[8]+i+s[9])
    for i in range(len(ans)):
        for j in range(len(ans[i])):
            if ans[i][j] == 'X':
                if ans[i][j-1] == '+':
                    ans[i] = ans[i][:j-1]
                else:
                    ans[i] = ans[i][:j]
                break
    sums = 0
    for i in set(ans):
        sums += eval(i)
    print(sums)

Submission status: Runtime Error

Solution code:
s = input().split("")
sum = 0
for i in range(2 ** (len(s)-1)) :
  st = str(s[0])
  for j in range(len(s)-1) : 
    if ((i >> j) & 1) :
      st = st + "+" + str(s[j+1])
    else :
      st = st + str(s[j+1])
  
  for item in st.split('+') :
    sum += int(item)
print(sum)

Submission status: Runtime Error

Solution code:
s=int(input())
S=str(s)
w=len(str(s))-1
l=[]
L=[]
for i in range(2**w):
    l.append(format(i, '0{}b'.format(w)))
for e in l:
    q=[]
    x=int(S[0])
    for i in range(len(e)):
        if e[i]=='0':
            x=x*10+int(S[i+1])
        else:
            q.append(x)
            x=int(S[i+1])
    q.append(x)
    L.append(sum(q))
print(sum(L))

Submission status: Runtime Error

Solution code:
s=int(input())
S=str(s)
w=len(str(s))-1
l=[]
L=[]
for i in range(2**w):
    l.append(format(i, '0{}b'.format(w)))
for e in l:
    q=[]
    x=int(S[0])
    for i in range(len(e)):
        if e[i]=='0':
            x=x*10+int(S[i+1])
        else:
            q.append(x)
            x=int(S[i+1])
    q.append(x)
    L.append(sum(q))
print(sum(L)

Submission status: Runtime Error

Solution code:
#2-1-1 #ABC045C
s=input()
lenth=len(s)
kugiri=set()
def roop(before,now,kugiri):
    if now==lenth:
        kugiri|={before,}
        return kugiri
    kugiri = roop(before+(0,),now+1,kugiri)
    kugiri = roop(before+(1,),now+1,kugiri)
    return kugiri
kugiri = roop((0,),2,kugiri)
kugiri = roop((1,),2,kugiri)
def calc(ans,kugiri,s):
    test=s
    now=test[0]
    test=test[1:]
    for i in range(len(s)-1):
        k=kugiri[i]
        if k==0:
            now+=test[0]
        elif k==1:
            ans+=int(now)
            now=test[0]
        test=test[1:]
        if i==len(s)-2:ans+=int(now)
    return ans
            
ans=0
for i in kugiri:
    ans=calc(ans,i,s)
print(ans)

Submission status: Runtime Error

Solution code:
s=input()
l=list(s)
b=[]
lst=[]
# bi=[bin(2**i) for i in range(0,len(s))]
for i in range(2**(len(s)-1)):
    b=list(str(bin(i))[2:].zfill(len(s)-1))
    st=l[0]
    for j in range(len(b)):
        if int(b[j]):
            st+=l[j+1]
        else:
            st+='+'+l[j+1]
    lst.append(eval(st))
print(sum(lst))

Submission status: Runtime Error

Solution code:
S = input()
power = 0
answer = 0
temps = int(S)
while True:
    temps = temps/10
    power += 1
    if temps < 10:
        break

SS = list(S)

for i in range(1 << power):
    output = []
    for j in range(power):
        if (i>>j)&1 == 1:
            output.append(SS[j])
            output.append('+')
        else:
            output.append(SS[j])
    output.append(SS[power])
    temp_string = ''.join(output)
    answer += eval(temp_string)
    output.clear()
    
print(answer)

Submission status: Runtime Error

Solution code:
S = input()
power = 0
answer = 0
temps = int(S)
while True:
    temps = temps/10
    power += 1
    if temps < 10:
        break

SS = list(S)

for i in range(1 << power):
    output = []
    for j in range(power):
        if (i>>j)&1 == 1:
            output.append(SS[j])
            output.append('+')
        else:
            output.append(SS[j])
    output.append(SS[power])
    temp_string = ''.join(output)
    answer += eval(temp_string)
    
print(answer)

Submission status: Runtime Error

Solution code:
H, W, N = map(int, input().split())
mat = [[0]*W for _ in range(H)]

for _ in range(N):
    a, b = map(int, input().split())
    mat[a-1][b-1] = 1


dp = [[0]*W for _ in range(H)]
for h in range(H):
    cnt = 0
    if mat[h][0] == 1:
        dp[h][0] = 1
    for w in range(1, W):
        if mat[h][w] == 1:
            dp[h][w] += 1
        dp[h][w] += dp[h][w-1]


ans = [0]*10
for i in range(10):
    tmp = 0
    for h in range(H-3):
        for w in range(W-3):
            s = 0
            for k in range(3):
                s += dp[h+k][w+2]-dp[h+k][w]
            if s == i:
                tmp += 1
    ans[i] = tmp

for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
N=input()
slen=len(N)-1
ans=0
for i in range(2<<(slen-1)):
    k=N
    ins=0
    for j in range(slen): 
        if((i>>j)&1):
            k=k[:j+1+ins]+"+"+k[j+1+ins:]
            ins+=1
    ans+=eval(k)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools

S = input()

nums = [s for s in S]
idxs = np.arange(1, len(nums))
masks = list(itertools.product([False, True], repeat=len(idxs)))

ret = 0 
for mask in masks:
    selected_idxs = [0] +list( idxs[ np.array(mask)]) + [len(nums)]
    for i in range(len(selected_idxs) - 1):
        ret += (int(''.join(nums[selected_idxs[i]: selected_idxs[i+1]])))

print(ret)

Submission status: Runtime Error

Solution code:
#import itertools
list1=[k for k in input()]
#print(list1)
num1=len(list1)
#print(num1)
list00=[format(int(k), 'b') for k in range(2**(num1-1))]
#print(list00)

list0=['','+']

list01=[]
for count1 in range(num1):
  x=list00[count1]
  list01.extend(x)
#print(list01)
total=0

for step1 in range(2):
  for step2 in range(2):
    list2=[list0[step2],list0[step1]]
    num = min(len(list1), len(list2))
    result = [None]*(num*2)
    result[::2] = list1[:num]
    result[1::2] = list2[:num]
    result.extend(list1[num:])
    result.extend(list2[num:])
    result1 = ''.join(result)
#    print(result1)
    total+=eval(result1)

print(total)
#176

Submission status: Runtime Error

Solution code:
#import itertools
list1=[k for k in input()]
print(list1)
num1=len(list1)
print(num1)
list00=[format(int(k), 'b') for k in range(2**(num1-1))]
print(list00)

list0=['','+']

list01=[]
for count1 in range(num1):
  x=list00[count1]
  list01.extend(x)
print(list01)
total=0

for step1 in range(2):
  for step2 in range(2):
    list2=[list0[step2],list0[step1]]
    num = min(len(list1), len(list2))
    result = [None]*(num*2)
    result[::2] = list1[:num]
    result[1::2] = list2[:num]
    result.extend(list1[num:])
    result.extend(list2[num:])
    result1 = ''.join(result)
    print(result1)
    total+=eval(result1)

print(total)
#176

Submission status: Runtime Error

Solution code:
def search(i,s):
	if i == n-1:
		li = []
		s = "".join(s)
		li = list(map(int,s.split("+")))
		total.append(sum(li))
		return

	else:
		search(i+1,s)

		_s = s[:-(n-i)+1] + ["+"] + s[-(n-i)+1:]
		search(i+1,_s)

search(0,s)
print(sum(total))

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3                                                                                                                                                                                          

import itertools

def all_comb(n):
    comb = []
    for i in range(0, n+1):
        comb.extend(list(itertools.combinations(range(n), i)))
    return comb

if __name__=='__main__':
    str = input()
    comb = all_comb(len(str)-1)
    tail = 0
    sum = 0
    for plus_positions in comb:
        head = 0
        for plus_position in plus_positions:
            num = int(str[head:plus_position+1])
            sum += num
            head = plus_position + 1
        num = int(str[head:])
	sum += num
    print(sum)

Submission status: Runtime Error

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


for i in range(2**(n-1)):
    calc_str = s[0]
    operator_maker = str(format(i, 'b')).zfill(n-1)
    for j, c in enumerate(operator_maker):
        if c == '1':
            calc_str += '+'
        calc_str += s[j+1]
    answer += eval(calc_str)

print(answer)

Submission status: Runtime Error

Solution code:
from collections import Counter

h, w, n = map(int, input().split())
dots = [list(map(int, input().split())) for _ in range(n)]

c = Counter()

for dot in dots:
	for i in range(-2, 1):
		for j in range(-2, 1):
			if 1 <= dot[0] + i < h - 1 and 1 <= dot[1] + j < w - 1:
				c[(dot[0] + i) * w + dot[1] + j] += 1

ans = [0] * 10

for v in c.values():
	ans[v] += 1

ans[0] = (h - 2) * (w - 2) - sum(ans[1:])

for a in ans:
	print(a)

Submission status: Runtime Error

Solution code:
# 問題文
# 1 以上 9 以下の数字のみからなる文字列 S が与えられます。 この文字列の中で、あなたはこれら文字と文字の間のうち、いくつかの場所に + を入れることができます。 一つも入れなくてもかまいません。 ただし、+ が連続してはいけません。
# このようにして出来る全ての文字列を数式とみなし、和を計算することができます。
# ありうる全ての数式の値を計算し、その合計を出力してください。

# キーワード
# 2n2n 通りを調べる全探索 (bit 全探索)

# メモ化再帰が使えそう

# 方向性
# 普通に計算すると、+ のありなし　* n で2:2 3:4 4:8 2^n-1の通り数がある
# 1234
# input = 123

# 間に入れれる通り数をもとめる
num_list = list(str(input()))
binary_length = len(num_list) - 1

lists = []

# 間に入れれる数分の配列を作る
for i in range(2**binary_length):
    bi_array = []
    
    # 2進数の数字を求める
    num = i
    while num >= 1:
        bi_array.insert(0,int(num % 2) ) 
        num = num // 2 
    tmp_list = []
    for j in range(binary_length):
        if len(bi_array) > j:
            tmp_list.insert(0,bi_array[-j-1])
        else:
            tmp_list.insert(0,0)

    lists.append(tmp_list)

result_list = []
# 0なら数字をjoin,1ならjoinしない
for bi_list in lists:

    num_list = list(str(input))
    current_num = int(num_list[0])
    concat_num_list = []

    for i,binary in enumerate(bi_list):
        if binary == 0:
            current_num = current_num * 10 + int(num_list[i+1])
        else:
            concat_num_list.append(current_num)
            current_num = int(num_list[i+1])

        if i+1 == len(bi_list):
            concat_num_list.append(current_num)
    result_list.append(sum(concat_num_list))


# リストの中身をすべて合算する
result = sum(result_list)
print(result)

Submission status: Runtime Error

Solution code:
from collections import deque

N, M = map(int, input().split())
F_C_of_S = [{} for i in range(N)]
# Companies of Station
C_of_S = {}

# def Union-find
parent = [-1]*M
def root(x):
    if (parent[x] < 0): return x
    else:
        parent[x] = y = root(parent[x])
        return y

def unite(x, y):
    px = root(x); py = root(y);
    if (px == py): return False
    if (parent[px] > parent[py]):
        px = root(y); py = root(x);
    parent[px] += parent[py]
    parent[py] = px
    return True

# Union-find
pqcs = []
for i in range(M):
    p, q, c = map(int, input().split())
    p -= 1; q -= 1;
    pqcs += [(p, q, c)]
    # The first
    if not c in F_C_of_S[p]:
        F_C_of_S[p][c] = i
    # else
    else:
        unite(F_C_of_S[p][c], i)
    C_of_S.setdefault(p, set()).add(c)
    # The first
    if not (c in F_C_of_S[q]):
        F_C_of_S[q][c] = i
    # else
    else:
        unite(F_C_of_S[q][c], i)
    C_of_S.setdefault(q, set()).add(c)

# stations of company
S_of_C = {}
for i in range(M):
    p, q, c = pqcs[i]
    c_set = S_of_C.setdefault(root(i), set())
    c_set.add(p); c_set.add(q);

Q = deque([(0, 0, 0)])
# cost to go to the stations from station_0
dist = [float('inf')] * N
dist[0] = 0

gdist = [float('inf')] * M

while Q:
    cost, v, flag = Q.popleft()
    if not (flag):  # (flag == 0) then gdist_update
        for l in F_C_of_S[v].values():
            l = root(l)
            if (cost < gdist[l]):
                gdist[l] = cost
                Q.appendleft((cost, l, 1))
    else:  # (flag == 1) then dist_update
        for s in S_of_C[v]:
            if (cost + 1 < dist[s]):
                dist[s] = cost + 1
                Q.append((cost + 1, s, 0))

print(dist[N - 1] if dist[N - 1] < float('inf') else -1)

Submission status: Runtime Error

Solution code:
from collections import deque
N,M = map(int, input().split())
distance = [[float('inf'), 0]]*N
distance[0] = [0, 0]
Q = deque([[distance[0], 0]])
edges = [[] for _ in range(N)]
for i in range(M):
	p,q,c = map(int, input().split())
	edges[p-1] += [[q-1, c]]
	edges[q-1] += [[p-1, c]]

flag = False
while Q:
	dist,now = Q.popleft()
	for t, c in edges[now]:
		if distance[t][0] > dist[0] + (dist[1] != c):
			distance[t] = [dist[0] + (dist[1] != c), c]
			if dist[1] == c:
				Q.appendleft([distance[t], t])
				continue
			Q.append([distance[t], t])
print(distance[N-1][0] if distance[N-1][0] != float('inf') else -1)

Submission status: Runtime Error

Solution code:
N,M = map(int, input().split())
if M == 0:
    print(-1)
    exit()
pqcs = [list(map(int, input().split())) for _ in range(M)]
c_max = max(list(map(lambda x: x[2],pqcs)))
node_num = (c_max+1)*N
unsearached_nodes = list(range(node_num))#0～N-1(n-1)が乗換経由ノード/路線iの駅nは3*i+(n-1)番ノード
#opt_nodes = [-1]*node_num
distance = [float('inf')]*node_num
distance[0] = 0
cost = 0
edges = [[float('inf')]*node_num for _ in range(node_num)]
#辺へ重み付け
for p,q,c in pqcs:
    edges[3*c+(p-1)][3*c+(q-1)] = 0
    edges[3*c+(q-1)][3*c+(p-1)] = 0
    edges[p-1][3*c+(p-1)] = 1
    edges[q-1][3*c+(q-1)] = 1
    edges[3*c+(p-1)][p-1] = 0
    edges[3*c+(q-1)][q-1] = 0

while (distance[N-1] == float('inf')):
    temp_min_dist = float('inf')
    for unsearched_ind in unsearached_nodes:
        if temp_min_dist > distance[unsearched_ind]:
            temp_min_dist = distance[unsearched_ind]
            target_min_ind = unsearched_ind
    unsearached_nodes.remove(target_min_ind)
    target_node = edges[target_min_ind]
    for index, rota_dist in enumerate(target_node):
        if rota_dist != float('inf'):
            if distance[index] > distance[target_min_ind] + rota_dist:
                distance[index] = distance[target_min_ind] + rota_dist
                #opt_nodes[index] = target_min_ind

print(distance[N-1])

Submission status: Runtime Error

Solution code:
S = input()
ans = 0
for i in range(1 << (len(S)-1)):
    eq = S
    for j in range(len(S)-1):
        if i & (1 << j):
            eq = eq[:j+1] + "," + eq[j+1:]
        else:
            pass
    eq = eq.split(",")
    eq = list(map(int,eq))
    ans += sum(eq)
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
ans = 0
for i in range(1 << (len(S)-1)):
    eq = S
    for j in range(len(S)-1):
        if i & (1 << j):
            eq = eq[:j+1] + "," + eq[j+1:]
        else:
            pass
    eq = eq.split(",")
    ans += sum(eq)
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
R = 0
S = list(S)
temp = []
if len(S)-1 == 0:
    R = int(S)
for i in range(2**(len(S)-1)):
    for m in range(len(S)-1):
        if i+1 & 2**(m) > 0:
            temp.append(S[m] + "+")
        else:
            temp.append(S[m])
    temp.append(S[len(S)-1])
    temp = "".join(temp)
    R += eval(temp)
    temp = []    
print(R)

Submission status: Runtime Error

Solution code:
nums = map(int, list(input()))
all_sum = 0
stack = [[0]*len(nums) -1]

print(dfs(0, [0]*len(num) - 1))

def dfs(i, pluses):
  if i == len(num) - 2:
    pluses[i] = 0
    sum1 = calc(pluses)
    pluses[i] = 1
    sum2 = calc(pluses)
    return sum1 + sum2
  else:
    i += 1
    pluses[i] = 0
    sum1 += dfs(i, pluses)
    pluses[i] = 1
    sum2 = dfs(i, pluses)
    return sum1 + sum2

def calc(pluses):
  num = 0
  sum = 0
  for i, elm in enumerate(nums):
    num += elm
    if i == len(nums):
      sum += num
    elif pluses[i] == 1:
      sum += num
    else:
      num *= 10
  return sum

Submission status: Runtime Error

Solution code:
s=input()
def solve(decided, left, idx):
    if idx==len(s):
        return decided+left
    # 手前に+を入れる
    ret1 = solve(decided+left,int(s[idx]),idx+1)
    # 入れない
    ret2 = solve(decided, left*10int(s[idx]), idx+1)
    return ret1+ret2
print(solve(0,int(s[0]),1))

Submission status: Runtime Error

Solution code:
def pt(s: list):
    if len(s) = 1:
        return eval(s[0])
    return pt([s[0]+s[1]]+s[2:]) + pt([s[0]+'+'+s[1]]+s[2:])
print(pt(list((input()))))

Submission status: Runtime Error

Solution code:
def search(s):
    if len(s) <= 1:
        return eval(s[0])
    return search([s[0]+s[1]]+s[2:]) + search([s[0]+'+'+s[1]]+s[2:])
print(search(input()))

Submission status: Runtime Error

Solution code:
from collections import Counter
h, w, num = map(int, input().split())
lis = []
for i in range(num):
    k, j = map(lambda x: int(x) - 1,input().split())
    for a in range(3):
        for b in range(3):
            cou1 = k - a
            cou2 = j - b 
            if cou1 < 0 or cou1 > h - 3:
                continue
            if cou2 < 0 or cou2 > w - 3:
                continue
            lis.append((cou1, cou2))

lis = Counter(Counter(lis).values())

print((h - 2) * (w - 2) - sum(lis.values()))
for i in range(1, 10):print(lis[i])

Submission status: Runtime Error

Solution code:
#s = int(raw_input())
  8 ssl = list(sl)
  9 print('ssl',ssl)
 10 total = 0
 11 ss = sl
 12 ss2 = ''
 13 print('ss',ss)
 14
 15 for i in ss:
 16         print('i',i,type(i),len(ss),type(len(ss)))
 17         ss2 += str(i)
 18         if i is str(len(ss)):
 19             pass
 20         else:
 21             ss2 += '+'
 22         #total = total + int(i)
 23
 24 print(eval(ss2))
 25 print('total',total)
 26
 27 #def disp_num_str(a,b,c,s='text'):

Submission status: Runtime Error

Solution code:
s=list(map(int,list(input())))
n=len(s)
ans=0
for i in range(1<<(n-1)):
"""ここで既に、n-1個の文字間のうち、どこに+を入れるかが決まる。入れるところにはbitが立ち(その桁が1となる)、入れないところにはbitが立たない(その桁が0となる)"""
    S=s[0]
    for j in range(n-1):
        if i & (1<<j): #bitが立っている時
            S+="+"+s[j+1]
        else: #bitが立っていない時
            S+=s[j+1]
    ans+=eval(S)
print(ans)

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
ans=0
for i in range(1<<n-1):#+を入れるかどうか
    num=s[0]
    for j in range(n-1):#+を入れるかどうか
        if i&(1<<j):#bitで考える,iと1<<jが同じ数字であれば実行
            num+="+"+s[j+1]
        else:
            num+=s[j+1]
    ans+=eval(ins)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N, M = map(int, input().split())
routes = np.array([list(map(int, input().split())) for _ in range(M)], 'i')
#print(routes)

# i駅まで到達したときの最小コスト（最終電車がjで示される）
dp = [{} for _ in range(N + 1)]
dp[1][0] = 0

for i in range(2, N + 1):
    for (f, t, m) in routes:
        if t != i:
            continue

        if m in dp[f]:
            dp[t][m] = dp[f][m]
        else:
            values = []
            for k, v in dp[f].items():
                if k != m: values.append(v)
            if len(values) > 0:
                dp[t][m] = min(values) + 1

if len(dp[N].values()) > 0:
    print(min(dp[N].values()))
else:
    print(-1)