Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys, collections
range = xrange
input = raw_input

n, p = [int(x) for x in input().split()]
A = [ord(x) - 48 for x in input()]


if p == 2 or p == 5:
    ans = 0
    for i in range(n):
        if A[i]%p == 0:
            ans += i + 1
    print ans
    sys.exit()


DP = [0]*p
ans = 0
POW = 1
ind0 = 0
for a in reversed(A):
    DP[ind0] += 1
    DP = [DP[(a * POW + i) % p] for i in range(p)]
    #ind0 = (a * POW + ind0) % p
    ans += DP[ind0]
    POW = POW * 10 % p
print ans


Fixed submission:
import sys, collections
range = xrange
input = raw_input

n, p = [int(x) for x in input().split()]
A = [ord(x) - 48 for x in input()]


if p == 2 or p == 5:
    ans = 0
    for i in range(n):
        if A[i]%p == 0:
            ans += i + 1
    print ans
    sys.exit()


DP = [0]*p
ans = 0
POW = 1
ind0 = 0
for a in reversed(A):
    DP[ind0] += 1
    #DP = [DP[(a * POW + i) % p] for i in range(p)]
    ind0 = (a * POW + ind0) % p
    ans += DP[ind0]
    POW = POW * 10 % p
print ans
Buggy python submission (verdict: Runtime Error):
n=int(input())
print(ceil(n/2))

Fixed submission:
from math import ceil, floor

n = int(input())
print(ceil(n/2))
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n,m = map(lambda x: int(x), input().split())
x = [0 for i in range(10005)]
tot=0
ac=0
for i in range(m):
	p, s = input().split()
	p=int(p)
	if x[p] == -1:
		continue
	if s == 'AC':
		ac +=1
		tot+=x[p]
		x[p]=-1
	elif s == 'WA':
		x[p] += 1
print(ac, tot)

Fixed submission:
from collections import Counter

n,m = map(lambda x: int(x), input().split())
x = [0 for i in range(100005)]
tot=0
ac=0
for i in range(m):
	p, s = input().split()
	p=int(p)
	if x[p] == -1:
		continue
	if s == 'AC':
		ac +=1
		tot+=x[p]
		x[p]=-1
	elif s == 'WA':
		x[p] += 1
print(ac, tot)

Buggy python submission (verdict: Runtime Error):
from collections import Counter

n,m = map(lambda x: int(x), input().split())
x = [0 for i in range(10005)]
tot=0
ac=0
for i in range(m):
	p, s = input().split()
	p=int(p)
	if x[p] == -1:
		continue
	if s == 'AC':
		ac +=1
		tot+=x[p]
		x[p]=-1
	elif s == 'WA':
		x[p] += 1
print(ac, tot)

Fixed submission:
from collections import Counter

n,m = map(lambda x: int(x), input().split())
x = [0 for i in range(100005)]
tot=0
ac=0
for i in range(m):
	p, s = input().split()
	p=int(p)
	if x[p] == -1:
		continue
	if s == 'AC':
		ac +=1
		tot+=x[p]
		x[p]=-1
	elif s == 'WA':
		x[p] += 1
print(ac, tot)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a // gcd (a, b) * b

n = int(input())
a = list(map(int, input().split()))
l = 1
for ai in a:
    l = lcm(l, ai)

ans = 0
mod = 10**9 + 7
for ai in a:
    ans += l // ai
    ans %= mod

print(ans)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a // gcd (a, b) * b

n = int(input())
a = list(map(int, input().split()))
l = 1
for ai in a:
    l = lcm(l, ai)

ans = 0
mod = 10**9 + 7
for ai in a:
    ans += l // ai

print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a // gcd (a, b) * b

n = int(input())
a = list(map(int, input().split()))
l = 1
for ai in a:
    l = lcm(l, ai)

ans = 0
mod = 10**9 + 7
for ai in a:
    ans += l // ai
    ans %= mod

print(ans)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a // gcd (a, b) * b

n = int(input())
a = list(map(int, input().split()))
l = 1
for ai in a:
    l = lcm(l, ai)

ans = 0
mod = 10**9 + 7
for ai in a:
    ans += l // ai

print(ans % mod)
Buggy python submission (verdict: Runtime Error):
N = int(input())
# white: 0, black: 1
g = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    g[u-1].append((v-1, w))
    g[v-1].append((u-1, w))

visited = [False]*N
def dfs(num, kyori): # 始点からの距離
    if not visited[num]:
        visited[num] = '1' if kyori%2 == 1 else '0'
        for hen in g[num]:
            dfs(hen[0], kyori+hen[1])
    return visited

print('\n'.join(dfs(0,0)))

Fixed submission:
N = int(input())
# white: 0, black: 1
g = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    g[u-1].append((v-1, w))
    g[v-1].append((u-1, w))

visited = [False]*N
from collections import deque

q = deque()
q.append([0, 0])
while q:
    num, kyori = q.pop()
    visited[num] = '1' if kyori%2 == 1 else '0'
    for hen in g[num]:
        if not visited[hen[0]]:
            q.append([hen[0], kyori+hen[1]]) 

print('\n'.join(visited))

Buggy python submission (verdict: Runtime Error):
N = int(input())
# white: 0, black: 1
g = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    g[u-1].append((v-1, w))
    g[v-1].append((u-1, w))

visited = [False]*N
def dfs(num, kyori): # 始点からの距離
    if not visited[num]:
        visited[num] = '1' if kyori%2 == 1 else '0'
        for hen in g[num]:
            dfs(hen[0], kyori+hen[1])
    else:
        return visited
    return visited

print('\n'.join(dfs(0,0)))

Fixed submission:
N = int(input())
# white: 0, black: 1
g = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    g[u-1].append((v-1, w))
    g[v-1].append((u-1, w))

visited = [False]*N
from collections import deque

q = deque()
q.append([0, 0])
while q:
    num, kyori = q.pop()
    visited[num] = '1' if kyori%2 == 1 else '0'
    for hen in g[num]:
        if not visited[hen[0]]:
            q.append([hen[0], kyori+hen[1]]) 

print('\n'.join(visited))
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N = map(int, input().split())
ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        if N-r*R-g*G >= 0 and (N-r*R-g*G) % B == 0:
            ans += 1

print(ans)



Fixed submission:
R,G,B,N = map(int, input().split())
ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        if N-r*R-g*G >= 0 and (N-r*R-g*G) % B == 0:
            ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S = input()
left = -1
for i, s in enumerate(S):
    if s == '#':
        left = i
        break

now = ''
left2 = -1
for i, s in enumerate(S[::-1]):
    if s == '.' and now=='':
        now='.'
    elif s=='#' and now=='.':
        now = '#'
    elif s=='.' and now=='#':
        left2 = i
        break
 
left2 = len(S)-left2

if S[-1]=='#':
    mae = len(S.split('.')[-2])
    ato = len(S.split('#')[-2])
    ans = min(S.count('#'), S[left:].count('.'))
    ans = min(ans, S[left:left2].count('#')+min(mae, ato))
    print(ans)
else:
    mae = len(S.split('.')[-2])
    ato = len(S.split('#')[-1])
    ans = min(S.count('#'), S[left:].count('.'))
    ans = min(ans, S[left:left2].count('#')+min(mae, ato))
    print(ans)

Fixed submission:
N=int(input())
S = input()
w = [0]*(N+1)
b = [0]*(N+1)
for i, s in enumerate(S):
    if s=='.':
        w[i+1] = w[i]+1
        b[i+1] = b[i]
    elif s=='#':
        b[i+1] = b[i]+1
        w[i+1] = w[i]
ans = 10**20
for i in range(N+1):
    ans = min(ans, b[i]+w[N]-w[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
S = input()
left = -1
for i, s in enumerate(S):
    if s == '#':
        left = i
        break
if S[-1] == '#':
    sharps = S.split('.')
    t=len(sharps[-1])
    t2=len(sharps[-2])
    a=len(S.split('#')[-2])
    print(min(S.count('#')-t, S[left:].count('.'), S.count('#')-t-t2+a))
else:
    sharps = S.split('.')
    t=len(sharps[-2])
    a=len(S.split('#')[-1])
    print(min(S.count('#'), S[left:].count('.'), S.count('#')-t+a))


Fixed submission:
N=int(input())
S = input()
w = [0]*(N+1)
b = [0]*(N+1)
for i, s in enumerate(S):
    if s=='.':
        w[i+1] = w[i]+1
        b[i+1] = b[i]
    elif s=='#':
        b[i+1] = b[i]+1
        w[i+1] = w[i]
ans = 10**20
for i in range(N+1):
    ans = min(ans, b[i]+w[N]-w[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
ans = []
N, Q = map(int, input().split())
s = input()
for i in range(Q):
    l, r = map(int, input().split())
    s_q = s[l-1:r]
    ans.append( \
        (len(s_q) - len(s_q.replace('AC', '')) ) \
            // 2)

print('\n'.join(map(str, ans)))

Fixed submission:
N, Q = map(int, input().split())
S = input()
memo = [0]*(N+1)
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        memo[i+1] = memo[i]+1
    else:
        memo[i+1] = memo[i]
ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(memo[r-1]-memo[l-1])

print('\n'.join(map(str, ans)))

Buggy python submission (verdict: Time Limit Exceeded):
ans = []
N, Q = map(int, input().split())
s = input()
for i in range(Q):
    l, r = map(int, input().split())
    s_q = s[l-1:r]
    ans.append( \
        (len(s_q) - len(s_q.replace('AC', '')) ) \
            // 2)

print('\n'.join(map(str, ans)))

Fixed submission:
N, Q = map(int, input().split())
S = input()
memo = [0]*(N+1)
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        memo[i+1] = memo[i]+1
    else:
        memo[i+1] = memo[i]
ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(memo[r-1]-memo[l-1])

print('\n'.join(map(str, ans)))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
leng = len(s)


while ('01' in s) or ('10' in s):
    s = s.replace('10','')
    s = s.replace('01','')

print(leng-len(s))


Fixed submission:
s = input()
leng = len(s)
zero = s.count('0')
one = s.count('1')
print(2*min(zero, one))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
import re
leng = len(s)


while ('01' in s) or ('10' in s):
    s = re.sub(r'01|10','', s)

print(leng-len(s))


Fixed submission:
s = input()
leng = len(s)
zero = s.count('0')
one = s.count('1')
print(2*min(zero, one))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
import re
cnt = 0

while '01' in s or '10' in s:
    s = re.sub(r'01|10','', s, 1)
    cnt += 2
    continue

print(cnt)


Fixed submission:
s = input()
leng = len(s)
zero = s.count('0')
one = s.count('1')
print(2*min(zero, one))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()

cnt = 0

while '01' in s or '10' in s:
    if '01' in s:
        s = s.replace('01','', 1)
        cnt += 1
        continue
    if '10' in s:
        s = s.replace('10','', 1)
        cnt += 1
        continue

print(cnt*2)


Fixed submission:
s = input()
leng = len(s)
zero = s.count('0')
one = s.count('1')
print(2*min(zero, one))

Buggy python submission (verdict: Runtime Error):
s = input()

cnt = 0

while '01' in s or '10' in s:
    if '01' in s:
        s = s.replace('01','', 1)
        print(s,cnt)
        cnt += 1
        continue
    if '10' in s:
        s = s.replace('10','', 1)
        print(s,cnt)
        cnt += 1
        continue

print(cnt*2)


Fixed submission:
s = input()
leng = len(s)
zero = s.count('0')
one = s.count('1')
print(2*min(zero, one))
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
ans=0
moku='W'*S.count('W')+'B'*S.count('B')

while S != moku:
    S=S.replace('BW', 'WB', 1)
    ans+=1

print(ans)

Fixed submission:
S=input()
ans=0
cnt=0
for i, s in enumerate(S):
    if s=='W':
        cnt+=1
        ans+=i-cnt+1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int, input().split()))
h = [int(input()) for _ in range(N)]

h_ = sorted(h)
minn = 999999999
for i in range(len(h) - K + 1):
    min_temp = max(h_[i:i+K]) - min(h_[i:i+K])
    if min_temp <= minn:
        minn = min_temp

print(minn)


Fixed submission:
N, K = list(map(int, input().split()))
h = [int(input()) for _ in range(N)]

hs = sorted(h)
ans = hs[-1] - hs[0]
for i in range(N - K + 1):
    ans = min(ans, hs[i+K-1]-hs[i])

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
N, M = map(int, input().split())

ans = 1
for a in range(math.sqrt(M)):
    b = int(M / a)
    if M%a != 0:
        continue
    if a * N <= M:
        ans = max(ans, a)
    if b * N <= M:
        ans = max(ans, b)

print(ans)



Fixed submission:
import math
N, M = map(int, input().split())

ans = 1
for a in range(1, int(math.sqrt(M))):
    b = int(M / a)
    if M%a != 0:
        continue
    if a * N <= M:
        ans = max(ans, a)
    if b * N <= M:
        ans = max(ans, b)

print(ans)
Buggy python submission (verdict: Runtime Error):
l = [int(i) for i in input().split()]
# sort()は破壊的じゃないです
l = l.sort
print(l[0]*10 + l[1] + l[2])

Fixed submission:
l = [int(i) for i in input().split()]
# sort()は破壊的です
# sorted()は破壊的じゃないです
l.sort(reverse=True)
print(l[0]*10 + l[1] + l[2])
Buggy python submission (verdict: Runtime Error):
cnds = [int(i) for i in input().split()]

posX = [int(i) for i in input().split()]
posY = [int(i) for i in input().split()]
posX.sort()
posY.sort()

max_x = posX[-1]
min_y = posY[0]
if cnds[2] < cnds[3]:
    if max_x < max_y:
        print('No War')
    else:
        print('War')
else:
    print('War')





Fixed submission:
cnds = [int(i) for i in input().split()]

posX = [int(i) for i in input().split()]
posY = [int(i) for i in input().split()]
posX.sort()
posY.sort()

max_x = posX[-1]
min_y = posY[0]
if cnds[2] < cnds[3]:
    if max_x < min_y and cnds[2] < min_y and max_x < cnds[3]:
        print('No War')
    else:
        print('War')
else:
    print('War')
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
t = list(input())

def restr2(s, t):
    if len(set(s)) != len(set(t)):
        return False
    for i in range(len(s)):
        for j in range(i+1, len(s)):
            if s[i] == s[j]:
                if t[i] != t[j]:
                    return False
    return True

print('Yes' if restr2(s, t) else 'No')


Fixed submission:
from collections import defaultdict

def a(s):
    dic = defaultdict(list)
    for i, ch in enumerate(s):
        dic[ch].append(i)
    return sorted(list(dic.values()))

s = input()
t = input()
print('Yes' if a(s) == a(t) else 'No')

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
t = list(input())

def restr(string):
    result = []
    for i in range(len(string)):
        tmp = [i]
        for j in range(i+1, len(string)):
            if string[i] == string[j]:
                tmp.append(j)
        if len(tmp) > 1:
            result.append(tmp)
    return result

print('Yes' if restr(s) == restr(t) else 'No')


Fixed submission:
from collections import defaultdict

def a(s):
    dic = defaultdict(list)
    for i, ch in enumerate(s):
        dic[ch].append(i)
    return sorted(list(dic.values()))

s = input()
t = input()
print('Yes' if a(s) == a(t) else 'No')

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s = input()
t = input()

def restr(string):
    result = []
    for i in range(len(string)):
        tmp = [i]
        for j in range(i+1, len(string)):
            if string[i] == string[j]:
                tmp.append(j)
        if len(tmp) > 1:
            result.append(tmp)
    return result

print('Yes' if restr(s) == restr(t) else 'No')


Fixed submission:
from collections import defaultdict

def a(s):
    dic = defaultdict(list)
    for i, ch in enumerate(s):
        dic[ch].append(i)
    return sorted(list(dic.values()))

s = input()
t = input()
print('Yes' if a(s) == a(t) else 'No')
Buggy python submission (verdict: Runtime Error):
n = int(input())

lastch = ''
answer = 'Yes'
words = []
for i in range(n):
    word = list(input())
    words.append(word)
    if lastch != word[0] and i != 0:
        answer = 'No'
    lastch = word[-1]

if len(set(words)) != len(words):
    answer = 'No'

print(answer)


Fixed submission:
n = int(input())

lastch = ''
answer = 'Yes'
words = []
for i in range(n):
    word = list(input())
    words.append(''.join(word))
    if lastch != word[0] and i != 0:
        answer = 'No'
    lastch = word[-1]

if len(set(words)) != len(words):
    answer = 'No'

print(answer)

Buggy python submission (verdict: Runtime Error):
n = int(input())

lastch = ''
answer = 'No'
words = []

for i in range(n):
    word = raw_input()
    words.append(word)
    if lastch == word[0] and i != 0:
        answer = 'Yes'
    else:
        answer = 'No'
    lastch = word[-1]

print('Yes' if len(words) == len(set(words)) and answer == 'Yes' else 'No')


Fixed submission:
n = int(input())

lastch = ''
answer = 'Yes'
words = []
for i in range(n):
    word = list(input())
    words.append(''.join(word))
    if lastch != word[0] and i != 0:
        answer = 'No'
    lastch = word[-1]

if len(set(words)) != len(words):
    answer = 'No'

print(answer)

Buggy python submission (verdict: Runtime Error):
n = int(input())

lastch = ''
answer = 'No'
words = []

for i in range(n):
    word = input()[0:-1]
    words.append(word)
    if lastch == word[0] and i != 0:
        answer = 'Yes'
    else:
        answer = 'No'
    lastch = word[-1]

print('Yes' if len(words) == len(set(words)) and answer == 'Yes' else 'No')


Fixed submission:
n = int(input())

lastch = ''
answer = 'Yes'
words = []
for i in range(n):
    word = list(input())
    words.append(''.join(word))
    if lastch != word[0] and i != 0:
        answer = 'No'
    lastch = word[-1]

if len(set(words)) != len(words):
    answer = 'No'

print(answer)
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd(nums):
    return reduce(math.gcd, nums)

N, X = list(map(int, input().split()))
x = list(map(int, input().split()))

x_sorted = x
x_sorted.append(X)
x_sorted.sort()

diff = []
for i, xi in enumerate(x_sorted):
    if i == 0:
        continue
    else:
        diff.append(xi - x_sorted[i-1])

print(gcd(diff))




Fixed submission:
from functools import reduce

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

def gcd_list(nums):
    return reduce(gcd, nums)

N, X = list(map(int, input().split()))
x = list(map(int, input().split()))

x_sorted = x
x_sorted.append(X)
x_sorted.sort()

diff = []
for i, xi in enumerate(x_sorted):
    if i == 0:
        continue
    else:
        diff.append(xi - x_sorted[i-1])

print(gcd_list(diff))
Buggy python submission (verdict: Runtime Error):
x, y = list(input())

if x > y:
  print('>')
elif x < y:
  print('<')
else:
  print('=')

Fixed submission:
x, y = list(input().split())

if x > y:
  print('>')
elif x < y:
  print('<')
else:
  print('=')
Buggy python submission (verdict: Runtime Error):
N=gets.to_i
ans = 0
sq = (N**(0.5)).to_i
(sq..sq+10).each do |i|
    ans = i*i if i*i <= N
end
puts ans


Fixed submission:
N = int(input())
print(int(N**0.5)**2)
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
from collections import deque
q = deque([[0, 0]])
while q:
    xi, i = q.popleft()
    if xi == x:
        print(i-1)
        exit()
    q.append([xi, i+1])
    q.append([xi+i, i+1])
    q.append([xi-i, i+1])

Fixed submission:
x = int(input())
ans = 0
cnt = 0
i = 0
while cnt < x:
    i+=1
    cnt += i
    ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = S[::-1]
divide = list(map(lambda phrase:phrase[::-1], ['dream', 'dreamer', 'erase', 'eraser']))

flag = False
i = 0
while i != len(S):
    for d in divide:
        if S[i:i+len(d)] == d:
            flag = True
            i += len(d)
            break

    if flag == False:
        break

print('YES' if flag else 'NO')

Fixed submission:
S = input()
S = S[::-1]
divide = list(map(lambda phrase:phrase[::-1], ['dream', 'dreamer', 'erase', 'eraser']))

flag = False
i = 0
while i != len(S):
    flag = False
    for d in divide:
        if S[i:i+len(d)] == d:
            flag = True
            i += len(d)
            break

    if flag == False:
        break

print('YES' if flag else 'NO')

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = S[::-1]
divide = list(map(lambda phrase:phrase[::-1], ['dream', 'dreamer', 'erase', 'eraser']))

flag = False
i = 0
while i != len(S):
    for d in divide:
        if S[i:i+len(d)] == d:
            flag = True
            i += len(d)
            break

    if flag == False:
        break

print('YES' if flag else 'NO')


Fixed submission:
S = input()
S = S[::-1]
divide = list(map(lambda phrase:phrase[::-1], ['dream', 'dreamer', 'erase', 'eraser']))

flag = False
i = 0
while i != len(S):
    flag = False
    for d in divide:
        if S[i:i+len(d)] == d:
            flag = True
            i += len(d)
            break

    if flag == False:
        break

print('YES' if flag else 'NO')
Buggy python submission (verdict: Runtime Error):
s = list(map(int,list(input())))

if len(s) == 1:
    print(s[0])
    exit(1)

from collections import deque

cands=deque([[0],[1]])

while len(cands[0]) != len(s)-1:
    newcands = []
    for cand in cands:
        newcands.append(cand+[0])
        newcands.append(cand+[1])
    cands = newcands

memo = []
while cands:
    pos = cands.pop()
    siki = ''
    for i, p in enumerate(pos):
        siki += str(s[i])
        if p == 1:
            siki += '+'
    siki += str(s[-1])
    memo.append(eval(siki))

print(sum(memo))



Fixed submission:
s = list(map(int,list(input())))

if len(s) == 1:
    print(s[0])
    exit()

from collections import deque

cands=deque([[0],[1]])

while len(cands[0]) != len(s)-1:
    newcands = []
    for cand in cands:
        newcands.append(cand+[0])
        newcands.append(cand+[1])
    cands = newcands

memo = []
while cands:
    pos = cands.pop()
    siki = ''
    for i, p in enumerate(pos):
        siki += str(s[i])
        if p == 1:
            siki += '+'
    siki += str(s[-1])
    memo.append(eval(siki))

print(sum(memo))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(map(int,list(input())))

from collections import deque

cands=deque([[0],[1]])

while len(cands[0]) != len(s)-1:
    newcands = []
    for cand in cands:
        newcands.append(cand+[0])
        newcands.append(cand+[1])
    cands = newcands

memo = []
while cands:
    pos = cands.pop()
    siki = ''
    for i, p in enumerate(pos):
        siki += str(s[i])
        if p == 1:
            siki += '+'
    siki += str(s[-1])
    memo.append(eval(siki))

print(sum(memo))


Fixed submission:
s = list(map(int,list(input())))

if len(s) == 1:
    print(s[0])
    exit()

from collections import deque

cands=deque([[0],[1]])

while len(cands[0]) != len(s)-1:
    newcands = []
    for cand in cands:
        newcands.append(cand+[0])
        newcands.append(cand+[1])
    cands = newcands

memo = []
while cands:
    pos = cands.pop()
    siki = ''
    for i, p in enumerate(pos):
        siki += str(s[i])
        if p == 1:
            siki += '+'
    siki += str(s[-1])
    memo.append(eval(siki))

print(sum(memo))