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 collections import deque

def dfs(xs):
    x = xs.popleft()

    if len(xs) == 0:
        return x

    # not +
    xs2 = xs.copy()
    y   = xs2.popleft()
    xy  = int(str(x)+str(y))
    xs2.appendleft(xy)
    b = dfs(xs2)

    # has +
    a = x * 2 + dfs(xs)


    return a+b


s  = str(input())
xs = list(map(int,s))
xs = deque(xs)

print(dfs(xs))

from collections import deque

def dfs(xs):
    print("xs",xs)
    x = xs.popleft()

    if len(xs) == 0:
        return x

    # not +
    xs2 = xs.copy()
    y   = xs2.popleft()
    xy  = int(str(x)+str(y))
    xs2.appendleft(xy)
    b = dfs(xs2)

    # has +
    a = x * 2 + dfs(xs)


    return a+b


s  = str(input())
xs = list(map(int,s))
xs = deque(xs)

print(dfs(xs))

from collections import deque

def dfs(xs):

    x = xs.popleft()

    if len(xs) == 0:
        return x

    # not +
    xs2 = xs.copy()
    y   = xs2.popleft()
    xy  = int(str(x)+str(y))
    xs2.appendleft(xy)
    b = dfs(xs2)

    # has +
    a = x + dfs(xs)


    return a+b


s  = str(input())
xs = list(map(int,s))
xs = deque(xs)

print(dfs(xs))

import sys
from collections import deque

sys.setrecursionlimit(1000000000)

def dfs(xs):
    x = xs.popleft()

    if len(xs) == 0:
        return x

    # not +
    xs2 = xs.copy()
    y   = xs2.popleft()
    xy  = int(str(x)+str(y))
    xs2.appendleft(xy)
    b = dfs(xs2)

    # has +
    a = x + x + dfs(xs)


    return a+b


s  = str(input())
xs = list(map(int,s))
xs = deque(xs)

print(sum(xs))

import sys
from collections import deque

sys.setrecursionlimit(1000000000)

def dfs(xs):
    x = xs.popleft()

    if len(xs) == 0:
        return x

    # not +
    xs2 = xs.copy()
    y   = xs2.popleft()
    xy  = int(str(x)+str(y))
    xs2.appendleft(xy)
    b = dfs(xs2)

    # has +
    a = x + x + dfs(xs)


    return a+b


s  = str(input())
xs = list(map(int,s))
xs = deque(xs)

print(dfs(xs))

from collections import deque

def dfs(xs):
    x = xs.popleft()

    if len(xs) == 0:
        return x

    # not +
    xs2 = xs.copy()
    y   = xs2.popleft()
    xy  = int(str(x)+str(y))
    xs2.appendleft(xy)
    b = dfs(xs2)

    # has +
    a = x + x + dfs(xs)


    return a+b


s  = str(input())
xs = list(map(int,s))
xs = deque(xs)

print(sum(xs))

import sys
import copy
from collections import deque

sys.setrecursionlimit(1000000000)

def dfs(xs,q):
    if len(xs) == 0:
        return sum(int(i) for i in q)

    x = xs.popleft()

    if len(q) == 0:
        q.append(x)
        return dfs(xs,q)


    a1 = copy.copy(xs)
    a2 = copy.copy(xs)

    q1 = copy.copy(q)
    q2 = copy.copy(q)

    q1.append(x)

    y  = q2.pop()
    yx = y + x
    q2.append(yx)

    return dfs(a1,q1) + dfs(a2,q2)


s  = str(input())
xs = deque(list(s))

print(dfs(xs,deque([])))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Accepted