TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from his friend.  Find the following:  

Submission attempts (in order):
import itertools
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))


def gutyocu():
    ans = 0
    for i, j in itertools.combinations_with_replacement(range(N), r=2):
        ans += min(A[i: j + 1])
    return ans


A = np.array(A)
pos = np.zeros(N + 1, dtype=int)
pos[0] = -1
pos[A] = np.arange(N + 1)

ans = 0
lefts = [0] * N
rights = [0] * N
for i in reversed(range(1, N + 1)):
    p = pos[i]
    if p + 1 < N and A[p + 1] > i:
        
        right = rights[p + 1]
    else:
        right = p
    if p - 1 >= 0 and A[p - 1] > i:
        
        left = lefts[p - 1]
    else:
        left = p
    lefts[right] = left
    rights[left] = right
    ans += (p - left + 1) * (right - p + 1) * i
print(ans)


import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))


def gutyocu():
    ans = 0
    for i, j in itertools.combinations_with_replacement(range(N), r=2):
        ans += min(A[i: j + 1])
    return ans


A = np.array(A)
pos = np.arange(N + 1)
pos[0] = -1
pos[A] = np.arange(N + 1)

ans = 0
lefts = np.arange(N)
rights = np.arange(N)
for i in reversed(range(1, N + 1)):
    p = pos[i]
    if p + 1 < N and A[p + 1] > i:
        
        right = rights[p + 1]
    else:
        right = p
    if p - 1 >= 0 and A[p - 1] > i:
        
        left = lefts[p - 1]
    else:
        left = p
    lefts[right] = left
    rights[left] = right
    ans += (abs(left - p) + 1) * (abs(right - p) + 1) * i
print(ans)


import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

pos = [0] * (N + 1)
pos[0] = -1
for i, a in enumerate(A):
    pos[a] = i

ans = 0
lefts = [0] * N
rights = [0] * N
for i in reversed(range(1, N + 1)):
    p = pos[i]
    if p + 1 < N and A[p + 1] > i:
        
        right = rights[p + 1]
    else:
        right = p
    if p - 1 >= 0 and A[p - 1] > i:
        
        left = lefts[p - 1]
    else:
        left = p
    lefts[right] = left
    rights[left] = right
    ans += (p - left + 1) * (right - p + 1) * i
print(ans)


Verdicts: Time Limit Exceeded

Time Limit Exceeded

Accepted
Problem: One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from his friend.  Find the following:  

Submission attempts (in order):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(list(enumerate(a)), key=lambda x: -x[1])
    L = [i for i in range(n+2)]  
    R = [i for i in range(n+2)]  
    ans = 0
    for i, j in a:  
        print(L, R)
        M = R[i+1]  
        m = L[i+1]  
        ans += j*(M-i)*(i+2-m)  
        R[m-1] = M  
        L[M+1] = m  
    print(ans)


main()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(list(enumerate(a)), key=lambda x: -x[1])
    L = [i for i in range(n+2)]  
    R = [i for i in range(n+2)]  
    ans = 0
    for i, j in a:  
        M = R[i+1]  
        m = L[i+1]  
        ans += j*(M-i)*(i+2-m)  
        R[m-1] = M  
        L[M+1] = m  
    print(ans)


main()

Verdicts: Runtime Error

Accepted
Problem: One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from his friend.  Find the following:  

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
  l,r = 1,1
  while a[i-l] > a[i] and i-l > -1:
    l += 1
  while a[i+r] > a[i] and i+r < n:
    r += 1
  ans += l*r*a[i]
print(ans)

N = int(input())
a = list(map(int, input().split()))

left = [0] * (N + 1)
right = [0] * (N + 1)


buf = list()
for i in range(N):
    while len(buf) > 0 and a[buf[-1]] > a[i]:
        buf.pop()
    if len(buf) > 0:
        left[i] = buf[-1]
    else:
        left[i] = -1
    buf.append(i)


buf = list()
for i in reversed(range(N)):
    while len(buf) > 0 and a[buf[-1]] > a[i]:
        buf.pop()
    if len(buf) > 0:
        right[i] = buf[-1]
    else:
        right[i] = N
    buf.append(i)

ans = 0
for i in range(N):
    ans += a[i] * (i - left[i]) * (right[i] - i)

print(ans)

Verdicts: Runtime Error

Accepted
Problem: One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from his friend.  Find the following:  

Submission attempts (in order):
N=int(input())
a=[int(i) for i in input().split()]
l=[0 for i in range(N)]
r=[0 for i in range(N)]
l[0]=0
k=0
for i in range(1,N):
    if a[k]<a[i]:
        l[i]=a[k]
    else:
        l[i]=a[i]
        k=i
r[N-1]=N-1
k=N-1
for i in range(N-1)[::-1]:
    if a[k]<a[i]:
        r[i]=a[k]
    else:
        r[i]=a[i]
        k=i
ans=0
for i in range(N):
    ans+=a[i]*(i-l[i]+2)*(r[i]-i)
print(ans)

N=int(input())
a=[0]+[int(i) for i in input().split()]
par=[0 for i in range(N+1)]
size=[0 for i in range(N+1)]
def find(x):
    if (par[x]==x):
        return x
    par[x]=find(par[x])
    return par[x]
def unite(x,y):
    x=find(x)
    y=find(y)
    res=size[x]*size[y]
    size[x]+=size[y]
    par[y]=x
    return res
for i in range(N+1):
    par[i]=i
    size[i]=1
b=[0 for i in range(N+1)]
for i in range(N+1):
    b[a[i]]=i
ans=0
for j in range(1,N+1)[::-1]:
    i=b[j]
    ans+=a[i]
    if i-1>=1 and a[i-1]>a[i]:
        ans+=unite(i-1,i)*a[i]
    if i+1<=N and a[i+1]>a[i]:
        ans += unite(i+1,i)*a[i]
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from his friend.  Find the following:  

Submission attempts (in order):
import bisect
N=int(input())
A=list(map(int,input().split()))

A=[N+1]+A+[0]

for i in range(len(A)):
    A[i]=5-A[i]

ans=0
for i in range(1,N+1):
    R=bisect.bisect_left(A[i:],A[i])
    L=bisect.bisect_right(A[:i+1],A[i])
    ans+=L*R
print(ans)

import sys
sys.setrecursionlimit(1000000)

N=int(input())
a=list(map(int,input().split()))

b=[i for i in range(1,N+1)]

A=[]
for i in range(N):
    A.append([a[i],b[i]])
A.sort(reverse=True)
#print(A)
PL=[i for i in range(N+1)]+[N+1]
PR=[i for i in range(N+1)]+[N+1]

def findL(x):
    if x==PL[x]:
        return x
    else:
        return findL(PL[x])
        
def findR(x):
    if x==PR[x]:
        return x
    else:
        return findR(PR[x])
#print(PR)
ans=0
for i in range(N):
    ans+=A[i][0]*(A[i][1]-findL(A[i][1]-1))*(findR(A[i][1]+1)-A[i][1])
    #print(ans,A[i][1],(A[i][1]-findL(A[i][1])+1),findR(A[i][1])-A[i][1]+1)
    #print(PR)
    PL[A[i][1]]=findL(A[i][1]-1)
    PR[A[i][1]]=findR(A[i][1]+1)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from his friend.  Find the following:  

Submission attempts (in order):
import bisect


def main():
    N = int(input())
    a = list(map(int, input().split()))

    s = [0, N+1]
    order = [0]*(N+1)

    for i in range(N):
        order[a[i]] = i+1

    ans = 0
    for i in range(1, N+1):
        bisect.insort_left(s, order[i])
        ans += i*(order[i]-s[bisect.bisect_left(s, order[i])-1]) * \
            (s[bisect.bisect_left(s, order[i])+1]-order[i])
    print(ans)

    if __name__ == "__main__":
        main()


N = int(input())
a = list(map(int, input().split()))

order = [0]*(N+1)

for i in range(N):
    order[a[i]] = i

ans = 0
checkR = list(range(N+1))
checkL = list(range(N+1))

for i in range(N, 0, -1):
    ans += i*(order[i] - checkR[order[i]] + 1)*(checkL[order[i]] - order[i]+1)
    checkR[checkL[order[i]]+1] = checkR[order[i]]
    checkL[checkR[order[i]]-1] = checkL[order[i]]
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from his friend.  Find the following:  

Submission attempts (in order):
a = list(map(int, reversed("1 3 2 4".split())))

result = target = tmp = a[0]

for index, i in enumerate(a[1:]):
    if target < i:
        tmp += i
        result += tmp
    else:
        target = i
        tmp = i * (index + 2)
        result += tmp
print(result)


n = int(input())
a = list(map(int, input().split()))

index = [-1] * (n + 1)
for i, v in enumerate(a):
    index[v] = i

area = [[i, i] for i in range(n + 1)]
result = 0
for i in range(n, 0, -1):
    position = index[i]
    l, r = area[position]
    area[r + 1][0] = l # right
    area[l - 1][1] = r # left
    result += (position - l + 1) * (r - position + 1) * i
print(result)




Verdicts: Wrong Answer

Accepted
Problem: One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from his friend.  Find the following:  

Submission attempts (in order):
#!/usr/bin/env python
# -*- coding:utf-8 -*-

N = int(input())
a = list(map(int, input().split()))

data = [float('inf')] * (2 * N - 1)

def update(i, val):
    i += N-1
    data[i] = val
    while i > 0:
        i = (i - 1) // 2
        data[i] = min(data[2*i+1], data[i*2+2])

for i in range(N):
    update(i, a[i])

def query(a, b, k, l, r):
    if l <= a and b <= r:
        return data[k]
    elif b <= l or r <= a:
        return float('inf')
    else:
        mid = (a + b) // 2
        lvalue = query(a, mid, 2 * k + 1, l, r)
        rvalue = query(mid, b, 2 * k + 2, l, r)
        return min(lvalue, rvalue)

ans = 0
for l in range(N):
    for r in range(l, N):
        ans += query(0, N, 0, l, r + 1)
print(ans)


#!/usr/bin/env python

from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))

cnt = 0
d = [0] * (N + 2)
for i in range(N):
    d[a[i]] = i


l = list(range(N + 2))
r = list(range(N + 2))

# print(a)
for i in range(N, 0, -1):
    di = d[i]
    cnt += i * (r[di] - di + 1) * (di - l[di] + 1)
    r[l[di] - 1] = r[di]
    l[r[di] + 1] = l[di]
    # print(i)
    # print(r)
    # print(l)
# print(r)
# print(l)
print(cnt)


Verdicts: Time Limit Exceeded

Accepted
Problem: Aoki loves numerical sequences and trees.  One day, Takahashi gave him an integer sequence of length N, a_1, a_2, ..., a_N, which made him want to construct a tree.  Aoki wants to construct a tree with N vertices numbered 1 through N, such that for each i = 1,2,...,N, the distance between vertex i and the farthest vertex from it is a_i, assuming that the length of each edge is 1.  Determine whether such a tree exists.

Submission attempts (in order):
from collections import Counter

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

def canMake():
    if N == 2:
        return A == [1, 1]

    cntA = Counter(A)
    mi = min(A)
    mx = max(A)

    if sum([c < 2 for c in cntA.values()]) >= 2:
        return False
    if cntA[mi] >= 2:
        return False

    for i in range(mi, mx + 1):
        if cntA[i] == 0:
            return False

    return True

print('Possible' if canMake() else 'Impossible')

from collections import Counter

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

def canMake():
    if N == 2:
        return A == [1, 1]

    cntA = Counter(A)
    mi = min(A)
    mx = max(A)

    if mi < mx // 2:
        return False

    if mx % 2 == 0 and cntA[mi] > 1:
        return False
    if mx % 2 == 1 and cntA[mi] > 2:
        return False

    for i in range(mi + 1, mx + 1):
        if cntA[i] < 2:
            return False

    return True

print('Possible' if canMake() else 'Impossible')


Verdicts: Wrong Answer

Accepted
Problem: Aoki loves numerical sequences and trees.  One day, Takahashi gave him an integer sequence of length N, a_1, a_2, ..., a_N, which made him want to construct a tree.  Aoki wants to construct a tree with N vertices numbered 1 through N, such that for each i = 1,2,...,N, the distance between vertex i and the farthest vertex from it is a_i, assuming that the length of each edge is 1.  Determine whether such a tree exists.

Submission attempts (in order):
def main():
    from collections import Counter as ct
    n = int(input())
    a = list(map(int, input().split()))
    c = ct(a)
    min_a = min(a)
    max_a = max(a)
    if min_a == 1:
        if c[min_a] == 1:
            pass
        elif a == [1, 1]:
            print("Possible")
            return 0
        else:
            print("Impossible")
            return 0
    if c[min_a] == 1 and (max_a+1)//2 > min_a:
        print("Impossible")
        return 0
    if c[min_a] == 2 and (max_a+2)//2 > min_a:
        print("Impossible")
        return 0
    if c[min_a] > 2:
        print("Impossible")
        return 0
    for i in range(min_a+1, max_a+1):
        if c[i] < 2:
            print("Impossible")
            return 0
    print("Possible")

def main():
    from collections import Counter as ct
    n = int(input())
    a = list(map(int, input().split()))
    c = ct(a)
    min_a = min(a)
    max_a = max(a)
    if min_a == 1:
        if c[min_a] == 1:
            pass
        elif a == [1, 1]:
            print("Possible")
            return 0
        else:
            print("Impossible")
            return 0
    if c[min_a] == 1 and (max_a+1)//2 > min_a:
        print("Impossible")
        return 0
    if c[min_a] == 2 and (max_a+2)//2 > min_a:
        print("Impossible")
        return 0
    if c[min_a] > 2:
        print("Impossible")
        return 0
    for i in range(min_a+1, max_a+1):
        if c[i] < 2:
            print("Impossible")
            return 0
    print("Possible")
main()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
n = len(s)
ans = 0

for i in range(2**(n-1)):
    l = list(s)
    for j in range(1, n): 
        if (1<<(j-1)) & i > 0:
            l = l[:j] + ['+'] + l[j:] 
    ans += eval(''.join(l))

print(ans)

s = input()
n = len(s)
ans = 0
 
for i in range(2**(n-1)):
    l = list(s)
    for j in reversed(range(1, n)): 
        if (1<<(j-1)) & i > 0:
            l = l[:j] + ['+'] + l[j:] 
    ans += eval(''.join(l))
 
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# arc 061 Many Formulas
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

S = read().rstrip().decode('utf-8')

def F(S):
    total = 0
    for i in range(2 ** (len(S) - 1)):
        operator_list = format(i, 'b').zfill(len(S)) 
        sum_ = 0
        num = 0
        for j, operator in zip(S, operator_list):
            if operator == "0":
                num = num * 10 + int(j)
            else:
                sum_ += num
                num = int(j)
        sum_ += num

        total += sum_
    print(total)

ans = F(S)
print(ans)

# arc 061 Many Formulas
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

S = read().rstrip().decode('utf-8')

def F(S):
    total = 0
    for i in range(2 ** (len(S) - 1)):
        operator_list = format(i, 'b').zfill(len(S)) 
        sum_ = 0
        num = 0
        for j, operator in zip(S, operator_list):
            if operator == "0":
                num = num * 10 + int(j)
            else:
                sum_ += num
                num = int(j)
        sum_ += num

        total += sum_

ans = F(S)
print(ans)

import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

S_int = int(readline())
S_str = str(S_int)

if len(S_str) == 1:
    print(S_int)
    quit()

pattern = []
fmt = '0' + str(len(S_str)-1) + 'b'
for i in range(2**(len(S_str)-1)):
    pattern.append(format(i, fmt))

answer = 0
for plus_flags in pattern:
    tmp = []
    tmp_str = S_str[0]
    for i, is_plus in enumerate(plus_flags, start=1):
        if is_plus == "1":
            tmp.append(int(tmp_str))
            tmp_str = ""
        tmp_str += S_str[i]
    if tmp_str:
        tmp.append(int(tmp_str))
    answer += sum(tmp)
print(answer)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
print(int(S))

# -*- coding: utf-8 -*-
s = list(input())
n = len(s)-1
trueans = []
for i in range(2**n):
    bag = []
    for j in range(n):
        bag.append(s[j])
        if (i>>j) & 1:
            bag.append("+")
    bag.append(s[-1])
    bag.append("+")
    kai = ""
    ans = []
    if "+" in bag:
        for j in bag:
            if j != "+":
                kai += j
            else:
                ans.append(int(kai))
                kai = ""
    trueans.append(sum(ans))
print(sum(trueans))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def abc061_c():
    s = str(input())

    l = []
    def saiki(i,moji):
        if i == len(s)-1:
            print(moji)
            l.append(sum(list(map(int,moji.split("+")))))
            return

        
        saiki(i+1,moji+"+"+s[i+1])
        
        saiki(i+1,moji+s[i+1])

    saiki(0,s[0])

    print(sum(l))


abc061_c()


def abc061_c():
    s = str(input())

    l = []
    def saiki(i,moji):
        if i == len(s)-1:
            
            l.append(sum(list(map(int,moji.split("+")))))
            return

        
        saiki(i+1,moji+"+"+s[i+1])
        
        saiki(i+1,moji+s[i+1])

    saiki(0,s[0])

    print(sum(l))


abc061_c()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = list(input())
n = len(s)-1

ans = 0
for x in list(product(["", "+"], repeat=n)):
    x = list(x)
    x.append("")
    
    strs = [i+j for i, j in zip(s, x)]
    ans += eval("".join(strs))
print(ans)

from itertools import product
s = list(input())
n = len(s)-1

ans = 0
for x in list(product(["", "+"], repeat=n)):
    x = list(x)
    x.append("")
    
    strs = [i+j for i, j in zip(s, x)]
    ans += eval("".join(strs))
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
n = len(s)
sum = 0
for b in range(1 << n-1):
    t = 0
    for i in range(n-1):
        if b & (1 << i):
            sum += int(''.join(s[t:i+1]))
            t = i
print(sum)


s = input()
n = len(s)
sum = 0
for b in range(1 << n-1):
    t = 0
    for i in range(n-1):
        if b & (1 << i):
            sum += int(''.join(s[t:i+1]))
            t = i+1
    sum += int(''.join(s[t:]))
print(sum)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys

input = sys.stdin.readline

s = input()
n = len(s)

total_sum = 0


for i in range(2 ** (n - 1)):
    
    
    now_sum = 0
    reg = int(s[0])
    for j in range(n - 1):
        if i & 1 << j:
            now_sum += reg
            reg = 0
        reg *= 10
        reg += int(s[j + 1])
    now_sum += reg

    total_sum += now_sum

print(total_sum)


import sys

input = sys.stdin.readline

s = input()
n = len(s)

total_sum = 0


for i in range(2 ** (n - 1)):
    
    
    now_sum = 0
    reg = int(s[0])
    for j in range(n - 1):
        if i & 1 << j:
            now_sum += reg
            reg = 0
        reg *= 10
        reg += int(s[j + 1])
    now_sum += reg

    total_sum += now_sum

print(total_sum)


import sys


def input():
    return sys.stdin.readline().strip()


s = input()
n = len(s)

total_sum = 0


for i in range(2 ** (n - 1)):
    
    
    now_sum = 0
    reg = int(s[0])
    for j in range(n - 1):
        if i & 1 << j:
            now_sum += reg
            reg = 0
        reg *= 10
        reg += int(s[j + 1])
    now_sum += reg

    total_sum += now_sum

print(total_sum)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys

input = sys.stdin.readline()

s = input()
n = len(s)

total_sum = 0


for i in range(2 ** (n - 1)):
    
    
    now_sum = 0
    reg = int(s[0])
    for j in range(n - 1):
        if i & 1 << j:
            now_sum += reg
            reg = 0
        reg *= 10
        reg += int(s[j + 1])
    now_sum += reg

    total_sum += now_sum

print(total_sum)


S = input()
if "\n" in S:
  print()
else:
  exit()


from itertools import product


def main():
    S = input()
    if "\n" in S:
	    return
    ans = 0
    for ops in tuple(product(("", "+"), repeat=len(S) - 1)):
        ops = ops + ("",)  # operators
        exp = "".join(i + j for i, j in zip(S, ops))  # expression
        ans += eval(exp)
    print(ans)


if __name__ == "__main__":
    main()


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
n = len(s)

ans = 0

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

print(ans)

s = input()
n = len(s)

ans = 0

for bit in range(2 ** 2 ** (n - 1)):
    f = s[0]

    for i in range(n - 1):
        if bit & (1 << i):
            f += "+"
        f += s[i + 1]

    ans += sum(map(int, f.split("+")))

print(ans)

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 & (1 << i):
            f += "+"
        f += s[i + 1]

    ans += sum(map(int, f.split("+")))

print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

def main():
    s = input()
    num = 2**(len(s)-1)
    bit_len = len(bin(num))

    def func(ｎ):
        n = bin(n)
        n_len = len(n)
        n = "0"*( bit_len - n_len - 1 ) + n[-len(n)+2:]
        indexes = [i+1 for i, x in enumerate(ｎ) if x == "1"]
        ans = 0
        temp = 0
        for i in indexes:
            ans += int(s[temp:i])
            temp = i
            print(i, ans)
        else:
            if temp != bit_len-2:
                ans += int(s[temp:])
                print(ans)

        return ans

    ans = 0
    for i in range(num):
        ans += func(i)
        print("ans : " + str(ans))
    print(ans)

main()


S = [int(i) for i in input()]
S.reverse()

N = len(S)
ans = 0
for i in range(N):
    left = i
    right = N - i - 1
    score = 1
    for k in range(0, right + 1):
        if right - k > 0:
            ans += S[i] * score * (1 << left) * (1 << (right - k - 1))
        else:
            ans += S[i] * score * (1 << left)
        score *= 10

print(ans)

S = [int(i) for i in input()]

N = len(S)
ans = 0
for i in range(N):
    left = i
    right = N - i - 1
    score = 1
    for k in range(0, right + 1):
        if right - k > 0:
            ans += S[i] * score * (1 << left) * (1 << (right - k - 1))
        else:
            ans += S[i] * score * (1 << left)
        score *= 10

print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from itertools import product
S = input()
ans = 0



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


from itertools import product
S = input()
ans = 0


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


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from sys import stdin
S = stdin.readline().rstrip()
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]))


from sys import stdin
S = stdin.readline().rstrip()
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(def(0, S[0]))


from sys import stdin
S = stdin.readline().rstrip()
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]))


from sys import stdin
S = stdin.readline().rstrip()
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]))


from sys import stdin
S = stdin.readline().rstrip()
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(def(0, s[0]))


from sys import stdin
S = stdin.readline().rstrip()
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]))


from sys import stdin
S = stdin.readline().rstrip()
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]))


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
input = sys.stdin.readline
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra



N,M = map(int,input().split())
PQC = [[int(x) for x in input().split()] for _ in range(M)]

U = 10 ** 6

V = set(range(1,N+1))
V |= set(p + c * U for p,q,c in PQC)
V |= set(q + c * U for p,q,c in PQC)
V = tuple(V)
v_to_i = {v:i for i,v in enumerate(V)}


rows, cols = [],[]
rows += [i for i,pc in enumerate(V) if pc > U]
cols += [v_to_i[pc % U] for i,pc in enumerate(V) if pc > U]
wt = [1] * len(rows)
rows += [v_to_i[p + c * U] for p,q,c in PQC]
cols += [v_to_i[q + c * U] for p,q,c in PQC]
wt += [0] * M

graph = csr_matrix((wt, (rows, cols)), (len(V), len(V)))

start = v_to_i[1]
goal = v_to_i[N]


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = read().rstrip().decode('utf-8')

def F(S):
    yield int(S)
    for i in range(len(S)-1):
        left = S[:i+1]
        right = S[i+1:]
        x = int(left)
        for y in F(right):
            yield x + y

answer = sum(F(S))
print(answer)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
n = len(s)
ans = 0

for i in range(2**(n-1)):
  form = s
  bit = []
  for _ in range(n-1):
    bit.append(i%2)
    i =  i//2
  
  for j in range(n):
    if bit[j]:
      form = form[:n-j] + '+' + form[n-j:]
    
  ans += form.eval()
print(ans)

s = input()
n = len(s)
cand = []

def func(ac,yet,sum):
  next = int(yet[0])
  
  
  if len(yet) ==1:
    cand.append(sum+ ac+ next)
    cand.append(sum+ ac*10+ next)
  else:
    func(next, yet[1:],ac+sum)
    func(ac*10+next, yet[1:],sum)

func(0,s,0)
print(sum(cand)//2)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys

S = list(map(int, sys.stdin.readline()))
len_S = len(S)
ans = 0
for i in range(2 ** (len_S - 1)):
  sum_ = S[len_S - 1]
  cursor = len_S - 1
  power = 0
  pattern = i
  while cursor > 0:
    cursor -= 1 
    if pattern % 2 == 1:
      power += 1
    else:
      power = 0
    sum_ += S[cursor] * (10 ** power)
    pattern >>= 1
  ans += sum_
print(ans)


import sys

S = list(map(int, list(sys.stdin.readline())))
len_S = len(S)
ans = 0
for i in range(2 ** (len_S - 1)):
  sum_ = S[len_S - 1]
  cursor = len_S - 1
  power = 0
  while cursor > 0:
    cursor -= 1 
    if i % 2 == 1:
      power += 1
    else:
      power = 0
    sum_ += S[cursor] * (10 ** power)
    i >>= 1
  ans += sum_
      
print(ans)
    

import sys

S = list(map(int, sys.stdin.readline()))
len_S = len(S)
ans = 0
for i in range(2 ** (len_S - 1)):
  sum_ = S[len_S - 1]
  cursor = len_S - 1
  power = 0
  pattern = i
  while cursor > 0:
    cursor -= 1 
    if pattern % 2 == 1:
      power += 1
    else:
      power = 0
    sum_ += S[cursor] * (10 ** power)
    pattern = pattern // 2
  ans += sum_
print(ans)


import sys

S = list(map(int, sys.stdin.readline()))
len_S = len(S)
ans = 0
for i in range(2 ** (len_S - 1)):
  sum_ = S[len_S - 1]
  cursor = len_S - 1
  power = 0
  while cursor > 0:
    cursor -= 1 
    if i % 2 == 1:
      power += 1
    else:
      power = 0
    sum_ += S[cursor] * (10 ** power)
    i >>= 1
  ans += sum_
      
print(ans)
    

import sys

S = list(map(int, sys.stdin.readline()))
len_S = len(S)
ans = 0
for i in range(2 ** (len_S - 1)):
  sum_ = S[len_S - 1]
  cursor = len_S - 1
  power = 0
  pattern = i
  while cursor > 0:
    cursor -= 1 
    if pattern % 2 == 1:
      power += 1
    else:
      power = 0
    sum_ += S[cursor] * (10 ** power)
    pattern //= 2
  ans += sum_
print(ans)


import sys

S = list(map(int, sys.stdin.readline().strip()))
len_S = len(S)
ans = 0
for i in range(2 ** (len_S - 1)):
  sum_ = S[len_S - 1]
  cursor = len_S - 1
  power = 0
  while cursor > 0:
    cursor -= 1 
    if i % 2 == 1:
      power += 1
    else:
      power = 0
    sum_ += S[cursor] * (10 ** power)
    i >>= 1
  ans += sum_
print(ans)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
n = len(S)

ans = 0

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

print(ans)


S = input()
n = len(S)

ans = 0

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

print(ans)


S = input()
n = len(S)

ans = 0

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

print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# n=int(input())
# lst=[int(input()) for _ in range(n)]
# ans1=sum(lst)
# max1=max(lst)
# print(ans1)
# print(0 if max1<=ans1-max1 else max1-(ans1-max1))
s=input()
n=len(s)
l=n-1
lst_1=[]
for i in range(1<<l):
    lst=[]
    for j in range(l):
        if ((i>>j)&1):
            lst.append("+")
        else:lst.append("_")
    lst_1.append(lst)
# print(lst_1)
# print(len(lst_1))
ans=0
for i in range(1<<l):
    temp=s[0]
    for j in range(l):

        if lst_1[i][j]=="+":
            temp+="+"
        temp += s[j]
    # print(temp)
    ans+=sum(map(int,temp.split("+")))
print(ans)

# n=int(input())
# lst=[int(input()) for _ in range(n)]
# ans1=sum(lst)
# max1=max(lst)
# print(ans1)
# print(0 if max1<=ans1-max1 else max1-(ans1-max1))
s=input()
n=len(s)
l=n-1
lst_1=[]
for i in range(1<<l):
    lst=[]
    for j in range(l):
        if ((i>>j)&1):
            lst.append("+")
        else:lst.append("_")
    lst_1.append(lst)

ans=0
for i in range(1<<l):
    temp=s[0]
    for j in range(l):

        if lst_1[i][j]=="+":
            temp+="+"
        temp += s[j+1]
    ans+=sum(map(int,temp.split("+")))
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
 
cnt = len(S) - 1 
 
ans = 0
 
for i in range(2 ** cnt):
  sign = [""] * cnt
  for j in range(cnt):
    if ((i>>j)&1):
      sign[j] = "+"
            
  formula = ""      
  for k in range(cnt):
    formula += S[k] + sign[k]
    print(sign)
  formula += S[cnt]
  print(formula,i)       
  ans += eval(formula)
print(ans)

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

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

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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):
            num+="+"+s[j+1]
        else:
            num+=s[j+1]
    ans+=eval(ins)
print(ans)


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):
            num+="+"+s[j+1]
        else:
            num+=s[j+1]
    ans+=eval(num)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
N = len(S)

# create ptn
ptn = []
for bit in range(2**(N-1)):
    tmp = [False]*(N-1)
    for i in range(N-1):
        if ((bit>>i) & 1):
            tmp[i] = True
    ptn.append(tmp)

# calc sum
tot = []
for p in ptn:
    a = []
    for i, s in enumerate(S):
        if i==0:
            now = int(s)
            continue
        if p[i-1]==False:
            now *= 10
            now += int(s)
        else:
            a.append(now)
            now = int(s)
    a.append(now)
    tot.append(sum(a))
sum(tot)

S = input()
N = len(S)

# create ptn
ptn = []
for bit in range(2**(N-1)):
    tmp = [False]*(N-1)
    for i in range(N-1):
        if ((bit>>i) & 1):
            tmp[i] = True
    ptn.append(tmp)

# calc sum
tot = []
for p in ptn:
    a = []
    for i, s in enumerate(S):
        if i==0:
            now = int(s)
            continue
        if p[i-1]==False:
            now *= 10
            now += int(s)
        else:
            a.append(now)
            now = int(s)
    a.append(now)
    tot.append(sum(a))
print(sum(tot))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# coding: utf-8


def solve(*args: str) -> str:
    S, = args
    n_sep = len(S)-1
    b_max = 2**n_sep
    print(S)

    ret = 0
    for b in range(b_max):
        p = 0
        for i in range(n_sep):
            if b >> i & 1:
                ret += int(S[p:i+1])
                p = i+1
        ret += int(S[p:])

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


# coding: utf-8


def solve(*args: str) -> str:
    S, = args
    n_sep = len(S)-1
    b_max = 2**n_sep

    ret = 0
    for b in range(b_max):
        p = 0
        for i in range(n_sep):
            if b >> i & 1:
                ret += int(S[p:i+1])
                p = i+1
        ret += int(S[p:])

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = input()

def func(num, code):
    total = 0
    start = 0
    length = len(num)

    for i in range(1, length):
        if code & 1 == 1: 
            total = total + int(num[start:i])
            start = i
        code = code >> 1

    total = total + int(num[start:i + 1])

    return total

total_of_all = 0

for i in range(2 ** (len(S) - 1)):
    print(func(S, i))
    total_of_all = total_of_all + func(S, i)

print(total_of_all)

S = input()

def func(num, code):
    total = 0
    start = 0
    length = len(num)

    for i in range(1, length):
        if code & 1 == 1: 
            total = total + int(num[start:i])
            start = i
        code = code >> 1

    total = total + int(num[start:length])

    return total

total_of_all = 0

for i in range(2 ** (len(S) - 1)):
    total_of_all = total_of_all + func(S, i)

print(total_of_all)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
n = len(s) -1
ans = 0
print(s)
for i in range(2**n):
  e = s[0]
  for j in range(n):
    if i >> j & 1:
      e +='+'
    e += s[j+1]
  ans += eval(e)
print(ans)

s = input()
n = len(s) -1
ans = 0
for i in range(2**n):
  e = s[0]
  for j in range(n):
    if i >> j & 1:
      e +='+'
    e += s[j+1]
  ans += eval(e)
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
k = len(s)

ans = 0

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

print(ans)

s = input()
k = len(s)


#     """



#     """

#         return sum(list(map(int, f.split('+'))))




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



ans = 0

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

print(ans)

s = input()
k = len(s)


#     """



#     """

#         return sum(list(map(int, f.split('+'))))




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



ans = 0

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

print(ans)



s = input()
k = len(s)


#     """



#     """

#         return sum(list(map(int, f.split('+'))))




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



ans = 0

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

print(ans)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s = str(input())
ans = 0

for i in 2**(len(s)-1):
    x = s[0]

    for j in range(len(s)-1):
        if (i>>j) & 1:
            x += '+'
        x += s[j+1]
        
    ans += sum(map(int,x.split('+')))
print(ans)

s = str(input())
ans = 0

for i in range(2**(len(s)-1)):
    x = s[0]

    for j in range(len(s)-1):
        if (i>>j) & 1:
            x += '+'
        x += s[j+1]
        
    ans += sum(map(int,x.split('+')))
print(ans)

Verdicts: Runtime Error

Accepted