Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [int(i) for i in input().split()]
B = []

for i in range(n):
    B.append(A[i])
    B.reverse()

C = [str(i) for i in B]   
print(' '.join(C))


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

even = [A[i] for i in range(n) if i % 2 == 0]

odd = [A[i] for i in range(n) if i % 2 != 0]


if n % 2 == 0:
    odd.reverse()
    c = odd+even
else:
    even.reverse()
    c = even+odd
    
print(' '.join([str(i) for i in c]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = [int(input()) for i in range(n)]

B = []

for a in A:
    if a % 10 != 0:
        B.append(a)

ans = sum(A)
if ans % 10 == 0:
    ans -= min(B)
    

print(ans)

Fixed submission:
n = int(input())
A = [int(input()) for i in range(n)]

B = []

for a in A:
    if a % 10 != 0:
        B.append(a)

ans = sum(A)
if ans % 10 == 0 and len(B) != 0:
    ans -= min(B)
elif ans % 10 == 0 and len(B) == 0:
    ans = 0
    

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())

def order(a,b):
    return max(len(str(int(a))),len(str(int(b))))
    
ans = [] 


for i in range(1,int(math.ceil(math.sqrt(n)))):
    if n % i == 0:
        ans.append(order(n/i,i))

print(min(ans))

Fixed submission:
import math
n = int(input())

def order(a,b):
    return max(len(str(int(a))),len(str(int(b))))
    
ans = [] 


for i in range(1,int(math.ceil(math.sqrt(n)))+1):
    if n % i == 0:
        ans.append(order(n/i,i))

if len(ans) == 0:
    print(1)
else:
    print(min(ans))

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

def order(a,b):
    return max(len(str(int(a))),len(str(int(b))))
    
ans = [] 
numbers = []

for i in range(1,n):
    if len(numbers) != 0:
        if i > min(numbers):
            break
    if n % i == 0:
        ans.append(order(n/i,i))
        numbers.append(n/i)
        

print(min(ans))
        

Fixed submission:
import math
n = int(input())

def order(a,b):
    return max(len(str(int(a))),len(str(int(b))))
    
ans = [] 


for i in range(1,int(math.ceil(math.sqrt(n)))+1):
    if n % i == 0:
        ans.append(order(n/i,i))

if len(ans) == 0:
    print(1)
else:
    print(min(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n,a = [int(i) for i in input().split()]

X = [int(i) for i in input().split()]
X = [0]+X
m = max(X+[a])
dp = [[[0]*50*(n+1) for i in range(n+1)] for j in range(n+1)]
#print(dp)


for i in range(n+1):
    for j in range(n+1):
        for k in range(m*(n+1)):
            if i == j == k == 0:
                dp[i][j][k] = 1
            elif i >= 1 and k < X[i]:
                dp[i][j][k] = dp[i-1][j][k]
            elif i >= 1 and j >= 1 and k >= X[i]:
                dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k-X[i]]

         

ans = 0
for i in range(1,n+1):
    ans += dp[n][i][i*a]
    
print(ans)

Fixed submission:
n,a = [int(i) for i in input().split()]

X = [int(i)-a for i in input().split()]
dp = [[0]*(100*n+1) for i in range(n+1)]
#print(dp)
dp[0][50*n]=1

for i in range(n):
    for j in range(50,100*n+1-50):
            dp[i+1][j] = dp[i][j]+dp[i][j-X[i]]
        
ans = dp[n][n*50]-1
    
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections imort Counter

n = int(input())
s = [input() for _ in range(n)]
counter = Counter(s)
output = ['AC', 'WA', 'TLE', 'RE']

for key in output:
  print(f'{key} x {counter[key]}')

Fixed submission:
n = int(input())
a = [input() for i in range(n)]
ac = 0
wa = 0
tle = 0
re = 0
for s in a:
  if s=='AC':
    ac+=1
  if s=='WA':
    wa+=1
  if s=='TLE':
    tle+=1
  if s=='RE':
    re+=1
print(f'AC x {ac}')
print(f'WA x {wa}')
print(f'TLE x {tle}')
print(f'RE x {re}')
Buggy python submission (verdict: Runtime Error):
from itertools import product

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

ans = 0

for row_bit in product(range(2), repeat=h):
	for col_bit in product(range(2), repeat=w):
		cnt = 0
    for row in range(h):
    	for col in range(w):
    		if c[row][col] == '#' and (row_bit[row] and col_bit[col]):
        		cnt += 1
	if cnt == k:
    	ans += 1
      
print(ans)

Fixed submission:
from itertools import product

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

ans = 0

for row_bit in product(range(2), repeat=h):
    for col_bit in product(range(2), repeat=w):
        cnt = 0
        for row in range(h):
            for col in range(w):
                if c[row][col] == "#" and (row_bit[row] and col_bit[col]):
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
print(str(x)*len(s))

Fixed submission:
s = input()
print('x'*len(s))

Buggy python submission (verdict: Runtime Error):
print(x * len(input()))

Fixed submission:
s = input()
print('x'*len(s))
Buggy python submission (verdict: Runtime Error):
a, b = input().split()
if a >= b:
  print(a*int(b))
  break
else:
  print(b*int(a))

Fixed submission:
a, b = input().split()
print(a*int(b) if a < b else b*int(a))
Buggy python submission (verdict: Runtime Error):
n = int(input())

for i in range(1, 10):
  for j in range(1, 10):
    if i*j == n:
      print('Yes')
      return

print('No')

Fixed submission:
N=int(input())
f=0
for i in range(1,10):
    for j in range(1,10):
        if N==i*j:
            f=1
            break
    if f==1:
        break
if f==0:
    print("No")
else:
    print("Yes")

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

for i in range(1, 10):
	for j in range(1, 10):
		if i*j == n:
        	print('Yes')

print('No')

Fixed submission:
N=int(input())
f=0
for i in range(1,10):
    for j in range(1,10):
        if N==i*j:
            f=1
            break
    if f==1:
        break
if f==0:
    print("No")
else:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
n = int(input())
for i in range(n // 2):
	for j in range(n // 2):
    	if i*j == n:
        	print('Yes')
            
print('No')

Fixed submission:
N=int(input())
f=0
for i in range(1,10):
    for j in range(1,10):
        if N==i*j:
            f=1
            break
    if f==1:
        break
if f==0:
    print("No")
else:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
#! /usr/bin/env python
N = input()
for i in range(1, 10):
    m = N / i
    if m.is_integer() and 1 <= m <= 9:
        print('Yes')
        break
    else:
        print('No')

Fixed submission:
N=int(input())
f=0
for i in range(1,10):
    for j in range(1,10):
        if N==i*j:
            f=1
            break
    if f==1:
        break
if f==0:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
s = list(input())
acgt = ['A', 'C', 'G', 'T']
cnt = 0
i, j = 0, 0
maxv = -1

for j in range(len(s)):
  maxv = max(maxv, cnt)
  cnt = 0
  i = j
  while s[i] in acgt:
    cnt += 1
    i += 1
maxv = max(maxv, cnt)
print(maxv)

Fixed submission:
s=input()
clist=['A','C','G','T']
count=0
a=[]
for i in s:
  if i in clist:
    count+=1
  else:
    a.append(count)
    count=0
a.append(count)
print(max(a))

Buggy python submission (verdict: Runtime Error):
s = list(input())
acgt = ['A', 'C', 'G', 'T']
cnt = 0
i, j = 0, 0
maxv = 0

for j in range(len(s)):
  maxv = max(maxv, cnt)
  cnt = 0
  i = j
  while s[i] in acgt:
    cnt += 1
    i += 1
maxv = max(maxv, cnt)
print(maxv)

Fixed submission:
s=input()
clist=['A','C','G','T']
count=0
a=[]
for i in s:
  if i in clist:
    count+=1
  else:
    a.append(count)
    count=0
a.append(count)
print(max(a))

Buggy python submission (verdict: Runtime Error):
s = list(input())
acgt = ['A', 'C', 'G', 'T']
cnt = 0
i, j = 0, 0
maxv = 0

for j in range(len(s)):
  maxv = max(maxv, cnt)
  cnt = 0
  while s[j] in acgt:
    cnt += 1
    j += 1
maxv = max(maxv, cnt)
print(maxv)

Fixed submission:
s=input()
clist=['A','C','G','T']
count=0
a=[]
for i in s:
  if i in clist:
    count+=1
  else:
    a.append(count)
    count=0
a.append(count)
print(max(a))

Buggy python submission (verdict: Runtime Error):
s=input()
clist=['A','C','G','T']
count=0
a=[]
for i in s:
  if i in clist:
    count+=1
  else:
    a.append(count)
    count=0

print(max(a))

Fixed submission:
s=input()
clist=['A','C','G','T']
count=0
a=[]
for i in s:
  if i in clist:
    count+=1
  else:
    a.append(count)
    count=0
a.append(count)
print(max(a))

Buggy python submission (verdict: Runtime Error):
s=input()
clist=['A','C','G','T']
count=0
a=[]
for i in s:
  if i in clist:
    count+=1
  else:
    a.append(count)
    count=0
print(max(a))

Fixed submission:
s=input()
clist=['A','C','G','T']
count=0
a=[]
for i in s:
  if i in clist:
    count+=1
  else:
    a.append(count)
    count=0
a.append(count)
print(max(a))
Buggy python submission (verdict: Runtime Error):
N = int(input())
count = 0
T, X, Y = 0, 0, 0
for i in range(N):
  t, x, y = map(int, input().split())
  if abs(x-X)+abs(y-Y) <= t-T and t % 2 == (x+y) % 2:
    count += 1
  T, X, Y = t, x, y
  
 print('Yes' if count == N else 'No')

Fixed submission:
N = int(input())
count = 0
T, X, Y = 0, 0, 0
for i in range(N):
  t, x, y = map(int, input().split())
  if abs(x-X)+abs(y-Y) <= t-T and t % 2 == (x+y) % 2:
    count += 1
  T, X, Y = t, x, y
  
print('Yes' if count == N else 'No')

Buggy python submission (verdict: Runtime Error):
N = int(input())
count = 0
T, X, Y = 0, 0, 0
for i in range(N):
  t, x, y = map(int, input().split())
  if t % 2 == (x+y) % 2 and abs(x-X)+abs(y-Y) <= t-T:
    count += 1
  T, X, Y = t, x, y
  
 print('Yes' if count == N else 'No')

Fixed submission:
N = int(input())
count = 0
T, X, Y = 0, 0, 0
for i in range(N):
  t, x, y = map(int, input().split())
  if abs(x-X)+abs(y-Y) <= t-T and t % 2 == (x+y) % 2:
    count += 1
  T, X, Y = t, x, y
  
print('Yes' if count == N else 'No')

Buggy python submission (verdict: Runtime Error):
N = input()
count = 0
T, X, Y = 0, 0, 0
for i in range(N):
  t, x, y = map(int, input().split())
  if t % 2 == (x+y) % 2 and abs(x-X)+abs(y-Y) <= t-T:
    count += 1
  T, X, Y = t, x, y
  
 print('Yes' if count == N else 'No')

Fixed submission:
N = int(input())
count = 0
T, X, Y = 0, 0, 0
for i in range(N):
  t, x, y = map(int, input().split())
  if abs(x-X)+abs(y-Y) <= t-T and t % 2 == (x+y) % 2:
    count += 1
  T, X, Y = t, x, y
  
print('Yes' if count == N else 'No')

Buggy python submission (verdict: Runtime Error):
N = input()
T, X, Y = 0, 0, 0
for i in range(N):
  t, x, y = map(int, input().split())
  if t % 2 == (x+y) % 2 and abs(x-X)+abs(y-Y) <= t-T:
    count += 1
  T, X, Y = t, x, y
  
 print('Yes' if count==N else 'No')
  

Fixed submission:
N = int(input())
count = 0
T, X, Y = 0, 0, 0
for i in range(N):
  t, x, y = map(int, input().split())
  if abs(x-X)+abs(y-Y) <= t-T and t % 2 == (x+y) % 2:
    count += 1
  T, X, Y = t, x, y
  
print('Yes' if count == N else 'No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
d = [input() for i in range(N)]
print(len(list(set(d)))

Fixed submission:
N = int(input())
d = [input() for i in range(N)]
print(len(set(d)))
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
print(sum(i for i in range(N+1) if A <= sum(map(int, str(i))) <= B)

Fixed submission:
N, A, B = map(int, input().split())
print(sum(i for i in range(N+1) if A <= sum(map(int, str(i))) <= B))
Buggy python submission (verdict: Runtime Error):
a, b, c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
  print('YES')
  break
else:
  print('NO')

Fixed submission:
a, b, c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
a = input()
print(a+a*a+a*a*a)

Fixed submission:
a = int(input())
print(a+a*a+a*a*a)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from fractions import gcd

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

if N == 2:
  print(max(A))
  sys.exit()

g = gcd(A[0], A[1])
#X = set([A[0], A[1]])
X = [A[0], A[1]]

for a in A[2:]:
  XX = [g]
  g = gcd(g, a)
  for x in X:
    XX.append(gcd(x, a))
  X = XX

print(max(X))

Fixed submission:
import sys
from fractions import gcd

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

if N == 2:
  print(max(A))
  sys.exit()

g = gcd(A[0], A[1])
X = set([A[0], A[1]])

for a in A[2:]:
  XX = set([g])
  g = gcd(g, a)
  for x in X:
    XX.add(gcd(x, a))
  X = XX

print(max(X))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
b = list(map(int, input().split()))

def dfs(c):
  if len(c) == 0:
    return []

  for i in range(1, len(c)+1):
    if c[i-1] > i:
      return False

    if c[i-1] == i:
      cc = c.copy()
      del cc[i-1]
      res = dfs(cc)
      if res is not False:
        res.append(i)
        return res

  return False

res = dfs(b)
if res is False:
  print(-1)
else:
  for i in res:
    print(i)

Fixed submission:
N = int(input())
b = list(map(int, input().split()))

def dfs(c):
  if len(c) == 0:
    return []

  for i in range(len(c), 0, -1):
    if c[i-1] > i:
      return False

    if c[i-1] == i:
      cc = c.copy()
      del cc[i-1]
      res = dfs(cc)
      if res is not False:
        res.append(i)
        return res

  return False

res = dfs(b)
if res is False:
  print(-1)
else:
  for i in res:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
b = list(map(int, input().split()))

def dfs(c):
  if len(c) == 0:
    return []

  for i in range(1, len(c)+1):
    if c[i-1] == i:
      cc = c.copy()
      del cc[i-1]
      res = dfs(cc)
      if res is not False:
        res.append(i)
        return res
  return False

res = dfs(b)
if res is False:
  print(-1)
else:
  for i in res:
    print(i)

Fixed submission:
N = int(input())
b = list(map(int, input().split()))

def dfs(c):
  if len(c) == 0:
    return []

  for i in range(len(c), 0, -1):
    if c[i-1] > i:
      return False

    if c[i-1] == i:
      cc = c.copy()
      del cc[i-1]
      res = dfs(cc)
      if res is not False:
        res.append(i)
        return res

  return False

res = dfs(b)
if res is False:
  print(-1)
else:
  for i in res:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
N = len(S)
C = [0] * N
L = [None] * N

C[0] = 0
L[0] = [S[0]]
for i in range(1, N):
    if len(L[i-1]) > 0 and L[i-1][-1] != S[i]:
        C[i] = C[i-1] + 2
        L[i] = L[i-1][:-1]
    else:
        C[i] = C[i-1]
        L[i] = L[i-1] + [S[i]]
print(C[-1])

Fixed submission:
S = input()
red_count = S.count('0')
blue_count = S.count('1')
print(min(red_count, blue_count) * 2)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
N = len(S)
S = [None] + S + [None]
nxt = [i + 1 for i in range(N+2)]
prv = [i - 1 for i in range(N+2)]

def remove(i):
    prv[nxt[i]] = prv[i]
    nxt[prv[i]] = nxt[i]

def dump():
    print(S)
    print(nxt)
    print(prv)
    print()

count = 0
while(True):
    i = nxt[0]
    j = nxt[i]
    removed = False
    while(True):
        #print(i, j)
        #dump()
        if S[i] == None or S[j] == None:
            break
        if S[i] == S[j]:
            i = j
            j = nxt[j]
        else:
            remove(i)
            remove(j)
            removed = True
            count += 2
            i = nxt[prv[i]]
            j = nxt[i]
    if not removed:
        break
#dump()
print(count)

Fixed submission:
S = input()
red_count = S.count('0')
blue_count = S.count('1')
print(min(red_count, blue_count) * 2)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
N = len(S)

while(True):
    if len(S) <= 1:
        break

    popped = False
    for i in range(len(S)-1):
        if S[i] != S[i+1]:
            S.pop(i)
            S.pop(i)
            popped = True
            break

    if not popped:
        break

print(N-len(S))

Fixed submission:
S = input()
red_count = S.count('0')
blue_count = S.count('1')
print(min(red_count, blue_count) * 2)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
INF = 10**(10**4)
COST = [INF,2,5,5,4,5,6,3,7,6]

min_cost = min(list(map(lambda a: COST[a], A)))
max_digits = N // min_cost

def dfs(n, digits):
    if digits * min_cost > n:
        return -INF
    if digits == 0:
        if n == 0:
            return 0
        else:
            return -INF
    elif digits < 0:
        return - INF
    results = []
    for a in A:
        res = a * 10 ** (digits - 1) + dfs(n-COST[a], digits-1)
        results.append(res)
    return max(results)

print(dfs(N, max_digits))


Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
INF = 10**5
COST = [INF,2,5,5,4,5,6,3,7,6]
digit = [-INF]*(N+1)
digit[0] = 0
for i in range(1, N+1):
    for a in A:
        c = COST[a]
        if i - c < 0:
            continue
        digit[i] = max(digit[i], 1 + digit[i-c])
ans = ''
n = N
for i in range(digit[N], 0, -1):
    for a in A:
        new_n = n - COST[a]
        if new_n < 0 or digit[new_n] < i - 1:
            continue
        ans += str(a)
        n = new_n
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
A = list(map(int, input().split()))

F = [0]*(k+1)
for x in range(k):
  for a in A:
    F[x] += x ^ a
print(max(F))


Fixed submission:
n, k = map(int, input().split())
A = list(map(int, input().split()))

fmax = 0
for i in range(40, 0, -1):
  x = 2 ** (i - 1)
  f1 = 0
  f0 = 0
  for a in A:
    a_ = a & x
    f1 += x ^ a_
    f0 += a_
  #print(i, f0, f1)
  if f0 >= f1:
    fmax += f0
  else:
    if k >= x:
      fmax += f1
      k -= x
    else:
      fmax += f0
print(fmax)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
A = list(map(int, input().split()))

F = [0]*(k+1)
for x in range(k):
  for a in A:
    F[x] += x ^ a
print(max(F))

Fixed submission:
n, k = map(int, input().split())
A = list(map(int, input().split()))

fmax = 0
for i in range(40, 0, -1):
  x = 2 ** (i - 1)
  f1 = 0
  f0 = 0
  for a in A:
    a_ = a & x
    f1 += x ^ a_
    f0 += a_
  #print(i, f0, f1)
  if f0 >= f1:
    fmax += f0
  else:
    if k >= x:
      fmax += f1
      k -= x
    else:
      fmax += f0
print(fmax)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
H = list(map(int, input().split()))
INF = 10**10
C = [INF]*n
C[0] = 0
for i in range(1, n):
  min_j = max(i-k, 0)
  for j in range(i-1, min_j-1, -1):
    C[i] = min(C[i], C[j]+abs(H[i]-H[j]))
print(C[n-1])

Fixed submission:
n, k = map(int, input().split())
H = list(map(int, input().split()))
INF = 10**10
C = [INF]*n
C[0] = 0
for i in range(1, n):
  min_j = max(i-k, 0)
  for j in range(i-1, min_j-1, -1):
    C[i] = min(C[i], C[j]+abs(H[i]-H[j]))
print(C[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

for i in range(m//n, 0, -1):
    if m % i != 0:
        continue
    print(i)
    break


Fixed submission:
n, m = map(int, input().split())
 
for i in range(m//n, 0, -1):
    if m % i != 0:
        continue
    print(i)
    break
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left
 
n, m, q = map(int, input().split())
LR = [0]*m
for i in range(m):
    LR[i] = list(map(int, input().split()))
P = [0]*q
Q = [0]*q
for i in range(q):
    P[i], Q[i] = map(int, input().split())
 
LR.sort(key=lambda x: (x[0], x[1]))
L = list(map(lambda x: x[0], LR))
#print(LR)
 
C = [[0]*(n+1) for _ in range(n+1)]
for i in range(1,n+1):
    l = bisect_left(L, i)
    r = bisect_left(L, i+1)-1
    R2 = list(map(lambda x: x[1], LR[l:r+1]))
    #print(l, r, R2)
    for j in range(i,n+1):
        C[i][j] = bisect_left(R2, j+1)
    #print(i, C[i])
 
for i in range(q):
    ans = 0
    for j in range(P[i], Q[i]+1):
        ans += C[j][Q[i]]
    print(ans)

Fixed submission:
a, b = map(int, input().split())
print(a*b-(a+b-1))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

if a < b:
    tmp = a
    a = b
    b = tmp

r = 16 - 2a
b = b - a

if r // 2 >= b:
    print('Yay!')
else:
    print(':')

Fixed submission:
a, b = map(int, input().split())

if a > b:
    tmp = a
    a = b
    b = tmp

r = 16 - 2 * a
b = b - a

if r // 2 >= b:
    print('Yay!')
else:
    print(':(')

Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

if a < b:
    tmp = a
    a = b
    b = tmp

r = 16 - 2a
b = b - a

if r // 2 >= b:
    print('Yay!')
else:
    print(':')

Fixed submission:
a, b = map(int, input().split())

if a > b:
    tmp = a
    a = b
    b = tmp

r = 16 - 2 * a
b = b - a

if r // 2 >= b:
    print('Yay!')
else:
    print(':(')
Buggy python submission (verdict: Runtime Error):
N = int(input())

units = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]

dp = [100000]*100000
dp[0] = 0
dp[1] = 1

for i in range(2, N+1):
    for unit in units:
        if i - unit >= 0:
            dp[i] = min(dp[i-unit]+1, dp[i])

print(dp[N])


Fixed submission:
N = int(input())

units = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]

dp = [100000]*(N+1)
dp[0] = 0
dp[1] = 1

for i in range(2, N+1):
    for u in units:
        p = i-u
        if p >= 0:
            dp[i] = min(dp[p]+1, dp[i])

print(dp[N])
Buggy python submission (verdict: Runtime Error):
N, A, B, K = map(int, input().split())
M = 998244353

X = set()
for n in range(0, K//A+1):
    m = (K - n * A) // B
    if n <= N and m <= N and n * A + m * B == K:
        X.add((n, m))

comb = [0]*(N+1)
comb[0] = 1
comb[N] = 1
for i in range(1, N//2+1):
    comb[i] = comb[i-1]*(N-i+1)//i
    comb[i] = comb[i]
    comb[N-i] = comb[i]

ans = 0
for n, m in X:
    ans += comb[n] * comb[m]
    ans = ans % M
print(ans)


Fixed submission:
N = int(input())

def digit_sum(X):
    s = 0
    while(X > 0):
        s += X % 10
        X = int(X / 10)
    return s

min_ = 10 ** 5
for A in range(1, int(N/2)+1):
    B = N - A
    val = digit_sum(A) + digit_sum(B)
    min_ = min(min_, val)

print(min_)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

answer = N
mark = 0
for i in range(N-1):
    #print('%d, %d, %d' % (i, mark, answer))
    if i < mark:
        answer += mark - i
        v = A[i]
        for x in range(i+1, mark+1):
            v += A[x]
        start_j = mark + 1
    else:
        v = A[i]
        start_j = i + 1
    for j in range(start_j, N):
        vx = v ^ A[j]
        vp = v + A[j]
        if vx == vp:
            answer += 1
            v = vx
            mark = j
        else:
            break
print(answer)

Fixed submission:
N = int(input())
S = input()

from collections import defaultdict
wc = defaultdict(int)
ec = defaultdict(int)

if S[0] == 'W':
    wc[0] = 1
for i in range(1, N):
    wc[i] = wc[i-1]
    if S[i] == 'W':
        wc[i] += 1

if S[N-1] == 'E':
    ec[N-1] = 1
for i in range(N-2, -1, -1):
    ec[i] = ec[i+1]
    if S[i] == 'E':
        ec[i] += 1

min_ = N
for i in range(1, N-1):
    v = wc[i-1] + ec[i+1]
    if v < min_:
        min_ = v
v0 = ec[1]
if v0 < min_:
    min_ = v0
vn = wc[N-1]
if vn < min_:
    min_ = vn
print(min_)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

answer = N
for i in range(N-1):
    v = A[i]
    for j in range(i+1, N):
        vx = v ^ A[j]
        vp = v + A[j]
        if vx == vp:
            answer += 1
            v = vx
        else:
            break
print(answer)


Fixed submission:
N = int(input())
S = input()

from collections import defaultdict
wc = defaultdict(int)
ec = defaultdict(int)

if S[0] == 'W':
    wc[0] = 1
for i in range(1, N):
    wc[i] = wc[i-1]
    if S[i] == 'W':
        wc[i] += 1

if S[N-1] == 'E':
    ec[N-1] = 1
for i in range(N-2, -1, -1):
    ec[i] = ec[i+1]
    if S[i] == 'E':
        ec[i] += 1

min_ = N
for i in range(1, N-1):
    v = wc[i-1] + ec[i+1]
    if v < min_:
        min_ = v
v0 = ec[1]
if v0 < min_:
    min_ = v0
vn = wc[N-1]
if vn < min_:
    min_ = vn
print(min_)