Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02995 (python)

Fixed submission:
import itertools
import math
import fractions
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a, b, c, d = map(int, input().split())


def func(n, c, d):
    x = n//c
    y = n//d
    z = n//((c * d) // fractions.gcd(c, d))
    zz = (x+y)-z
    return zz


tmp = b-func(b, c, d)
tmp2 = (a-1)-func(a-1, c, d)
print(tmp-tmp2)
#print('test', func(6, 2, 3))

Buggy submission (verdict: Runtime Error):
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a, b, c, d = map(int, input().split())


def func(n, c, d):
    x = n//c
    y = n//d
    z = n//((c * d) // math.gcd(c, d))
    zz = (x+y)-z
    return zz


tmp = b-func(b, c, d)
tmp2 = (a-1)-func(a-1, c, d)
print(tmp-tmp2)
#print('test', func(6, 2, 3))
Problem p02999 (python)

Fixed submission:
x, a = map(int, input().split())
if x < a:
    print(0)
else:
    print(10)

Buggy submission (verdict: Runtime Error):
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


n, x = map(int, input().split())
l = list(map(int, input().split()))
#print(l)
ll = [0]
sum = 0
for i in range(n):
    sum += l[i]
    ll.append(sum)
#print(ll)

cnt = 0
for i in range(n+1):
    if ll[i] <= x:
        cnt += 1
print(cnt)
Problem p03324 (python)

Fixed submission:
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


d, n = map(int, input().split())


def func(x):
    cnt = 0
    while x % 100 == 0:
        cnt += 1
        x /= 100
    return cnt == d


cntcnt = 0

for i in range(1, 10000000):
    if func(i):
        cntcnt += 1
        if cntcnt == n:
            print(i)
            exit()

Buggy submission (verdict: Runtime Error):
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


d, n = map(int, input().split())


def func(x):
    cnt = 0
    while x % 100 == 0:
        cnt += 1
        x /= 100
    return cnt == d


a = []

for i in range(1, 1000000):
    if func(i):
        a.append(i)
print(a[n-1])
Problem p03352 (python)

Fixed submission:
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

x = int(input())
a = [1]
for i in range(2, 1001):
    for j in range(2, 10):
        a.append(i**j)
aa = sorted(set(a))
# print(aa)
b = []
for i in range(len(aa)):
    if aa[i] <= x:
        b.append(aa[i])
print(max(b))

Buggy submission (verdict: Runtime Error):
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

#N = int(input())
#s = [input() for i in range(N)]
#M = int(input())
#t = [input() for i in range(M)]
# print(s)
# print(t)

h, w = map(int, input().split())
if (w == 1) or(h == 1):
    print(1)
    exit()

sum = 0

sum += (math.ceil(w/2))*(math.ceil(h/2))  # 切り上げ
sum += (math.floor(w/2))*(math.floor(h/2))  # 切り捨て

print(sum)
Problem p03359 (python)

Fixed submission:
def readints():
    return list(map(int, input().split()))


a, b = map(int, input().split())
if a == b:
    print(a)
    exit()
if a > b:
    print(a-1)
if a < b:
    print(a)

Buggy submission (verdict: Runtime Error):
import math
import string
import collections
from collections import Counter
from collections import deque


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

H, W = map(int, input().split())
s = [None]*H
for i in range(H):
    s[i] = input()
d = deque()
d.append((0, 0))
while(len(d) != 0):
    g, r = d.popleft()
    if s[g][r] == '#':
        if g != 0 and s[g-1][r] == '#':
            d.append((g-1, r))
        else:
            print('No')
            break
        if g != H-1 and s[g+1][r] == '#':
            d.append((g+1, r))
        else:
            print('No')
            break
        if r != 0 and s[g][r-1] == '#':
            d.append((g, r-1))
        else:
            print('No')
            break
        if r != W-1 and s[g][r+1] == '#':
            d.append((g, r+1))
        else:
            print('No')
            break
    print('Yes')
Problem p03455 (python)

Fixed submission:
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


a, b = map(int, input().split())

print("Even" if (a*b) % 2 == 0 else "Odd")

Buggy submission (verdict: Runtime Error):
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


a = int(input())
b = int(input())

print("Odd" if (a*b) % 2 == 0 else "Even")
Problem p03473 (python)

Fixed submission:
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


m = int(input())
print(24+(24-m))

Buggy submission (verdict: Runtime Error):
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


m = int(input)
print(24+(24-m))

Buggy submission (verdict: Runtime Error):
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


m = int(input)
print(24+(24-m)s)
Problem p03574 (python)

Fixed submission:
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


h, w = map(int, input().split())
a = [None]*h
for i in range(h):
    a[i] = input()
# print(a)

dx = [-1, -1, -1, 0, 1, 1, 1, 0]
dy = [-1, 0, 1, 1, 1, 0, -1, -1]

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            print('#', end="")
        else:
            count = 0
            for k in range(8):
                x = i+dx[k]  # (i,j)の位置からk移動させたときのx座標
                y = j+dy[k]  # (i,j)の位置からk移動させたときのy座標
                if x < 0 or x >= h or y < 0 or y >= w:
                    # x,yが盤面の中に入っていて'#'のとき
                    continue

                if a[x][y] == '#':
                    count += 1

            print(count, end="")

    print('\n', end="")

Buggy submission (verdict: Runtime Error):
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


h, w = map(int, input().split())
a = [None]*h
for i in range(h):
    a[i] = input()
# print(a)

dx = [1, 1, 0-1, -1, -1, 0, 1]
dy = [0, 1, 1, 1, 0, -1, -1, -1]

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            print('#', end="")
        else:
            count = 0
            for k in range(8):
                x = i+dx[k]  # (i,j)の位置からk移動させたときのx座標
                y = j+dy[k]  # (i,j)の位置からk移動させたときのy座標
                if (x <= 0 and x < h)and(y <= 0 and y < w)and(a[x][y] == '#'):
                    # x,yが盤面の中に入っていて'#'のとき
                    continue
                if a[x][y] == '#':
                    count += 1
            print(count, end="")
    print('\n', end="")
Problem p03605 (python)

Fixed submission:
# coding: utf-8
# Your code here!
n=input()
if n[0]=='9':
    print('Yes')
    exit()
if n[1]=='9':
    print('Yes')
    exit()
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n=input()
4.if n[0]==9 or n[1]==9:
5.    print('Yes')
      exit()
6.else:
7.    print('No')

Buggy submission (verdict: Runtime Error):
n=input()
for i in range(len(n)):
    if n[i] ==9:
        print('Yes')
        break
        else:
            print('No')
Problem p03636 (python)

Fixed submission:
s=input()
ss=len(s[1:len(s)-1])
sss=str(ss)
print(s[0]+sss+s[-1])

Buggy submission (verdict: Runtime Error):
s=input()
ss=len(s[1:len(s)-1])
sss=str(ss)
 print(s[0]+sss+s[-1])
Problem p03657 (python)

Fixed submission:
a,b=map(int,input().split())
print('Possible' if (((a+b)%3==0)or(a%3==0)or(b%3==0)) else 'Impossible')

Buggy submission (verdict: Runtime Error):
    a,b=map(int,input().split())
    print('Possible' if ((a+b)%3==0) or (a%3==0) or(b%3==0) else 'Impossible')
Problem p03721 (python)

Fixed submission:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n, k = map(int, input().split())
ab = [readints() for _ in range(n)]
# print(ab)
abab = sorted(ab)
# print(abab)
tmp = 0
for i in range(n):
    tmp += abab[i][1]
    if tmp >= k:
        print(abab[i][0])
        break

Buggy submission (verdict: Runtime Error):
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n, k = map(int, input().split())
ab = [readints() for _ in range(n)]
# print(ab)
abab = sorted(ab)
# print(abab)
tmp = 0
for i in range(n):
    tmp += ab[i][1]
    if tmp >= k:
        print(ab[tmp-k][0])
        break

Buggy submission (verdict: Runtime Error):
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n, k = map(int, input().split())
ab = [readints() for _ in range(n)]
# print(ab)
abab = sorted(ab)
# print(abab)
tmp = 0
for i in range(n):
    tmp += ab[i][1]
    if tmp >= k:
        print(ab[tmp-k][0])
        exit()
Problem p02642 (python)

Fixed submission:
from collections import defaultdict
import sys
n = int(input())
A = list(map(int, input().split()))

# if n == 1:
#     print(1)
#     sys.exit()

d = defaultdict(int)

for key in A:
    d[key] += 1

# if len(d) == 1: # 全部同じ数
#     print(0)
#     sys.exit()

B = list(d)
# B.sort()

# if B[0] == 1: # 1が含まれる場合
#     print(d[1])
#     sys.exit()
# length = len(d)
m = max(d)
flag = [0 for i in range(m+1)]

for i in B:
    t = i
    while t <= m:
        flag[t] += 1
        t += i

ans = 0
for i in B:
    if flag[i] == 1 and d[i] == 1:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
n = int(input())
L = []
for i in range(n):
    L.append(input())

ANS = ['blank page']
d = deque()
d.append('blank page')

for i in range(1, n):
    if L[i] == 'use the back button':
        d.pop()
        t = d.pop()
        ANS.append(t)
        d.append(t)
    else:
        s = L[i][6:]
        ANS.append(s)
        d.append(s)
        # s = L[i].split()
        # s = s[2:]
        # ANS.append(' '.join(s))
        # d.append(' '.join(s))

for i in ANS:
    print(i)
Problem p02675 (python)

Fixed submission:
s = input()
if s[-1] == '3':
    print('bon')
elif s[-1]=='0' or s[-1]=='1' or s[-1]=='6' or s[-1]=='8':
    print('pon')
else:
    print('hon')

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
ANS = [-1]*(n+1)
P = []
L = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())

    if a == 1:
        ANS[b] = 1
        P.append(b)
    elif b == 1:
        ANS[a] = 1
        P.append(a)
    else:    
        L[a].append(b)
        L[b].append(a)

# print(L, ANS, P)

i = 0
while len(P) < n-1:
    for j in range(1, n+1):
        if P[i] in L[j] and ANS[j] == -1:
            P.append(j)
            L[j].remove(P[i])
            ANS[j] = P[i]
            # print(i, P[i], j, L, ANS, P)
    i += 1

print('Yes')
for i in range(2, n+1):
    print(ANS[i])
Problem p02681 (python)

Fixed submission:
s = input()
t = input()
if s == t[:-1]:
    print("Yes")
else:
    print("No")

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

# リストを扱いやすいように変形
def subtraction(x):
    return x - 1
A = list(map(subtraction, A))
# print(A)

# 通ったことのある場所を持っておく
ROUTE = [0]
t = A[0]
while not (t in ROUTE):
    ROUTE.append(t)
    t = A[t]


x=ROUTE.index(t) # ループのスタート地点
length = len(ROUTE) - x
# print(ROUTE, length)

if k < x:
    print(ROUTE[k]+1)
else:
    k = k - x
    s = k % length
    print(ROUTE[x + s]+1)


# 再び町1に戻ってくるまでの経路を調べる
# ROUTE = [0]
# t = A[0] # 現在地
# while t != 0:
#     ROUTE.append(t)
#     t = A[t]
# # print(ROUTE)

# length = len(ROUTE)
# print(ROUTE[k % length]+1)
Problem p02804 (python)

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

MOD = 10 ** 9 + 7


def pow(a, n):
    if n == 0:
        return 1
    else:
        temp = pow(a, n // 2)
        if n % 2 == 0:
            return temp * temp % MOD
        else:
            return temp * temp * a % MOD
        
        
ans = 0
combinations = list()
for j, i in enumerate(range(k - 1, n)):
    if i == (k - 1):
        combinations.append(1)
    else:
        combinations.append(combinations[-1] * i * pow(i - k + 1, MOD - 2))
    combinations[-1] = combinations[-1] % MOD
    # print(i, 'C', k - 1, '=', combinations[-1])

# print(combinations)
# print(A)
combinations = combinations[::-1]
for j, i in enumerate(range(k - 1, n)):
    ans += (A[-j - 1] * combinations[j] % MOD)

for j, i in enumerate(range(k - 1, n)):
    ans -= (A[j] * combinations[j] % MOD)
    if ans < 0:
        ans = ans + (- ans // MOD + 1) * MOD

ans %= MOD
print(ans)

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

MOD = 10 ** 9 + 7

ans = 0
combinations = list()
for j, i in enumerate(range(k - 1, n)):
    if i == (k - 1):
        combinations.append(1)
    else:
        combinations.append(combinations[-1] * i // (i - k + 1))
    combinations[-1] = combinations % MOD
    # print(i, 'C', k - 1, '=', combinations[-1])

# print(combinations)
# print(A)
combinations = combinations[::-1]
for j, i in enumerate(range(k - 1, n)):
    ans += (A[-j - 1] * combinations[j] % MOD)

for j, i in enumerate(range(k - 1, n)):
    ans -= (A[j] * combinations[j] % MOD)
    if ans < 0:
        ans = ans - (ans // MOD) * MOD

ans %= MOD
print(ans)
Problem p03014 (python)

Fixed submission:
from collections import defaultdict


H, W = map(int, input().split())
mass = list()
for i in range(H):
    mass.append(input())

values_col = defaultdict(int)
values_row = defaultdict(int)

ind_row = [[0 for i in range(W)] for j in range(H)]
ind_col = [[0 for i in range(W)] for j in range(H)]

ind = 0
for i, m_row in enumerate(mass):
    ind += 1
    for j, chr in enumerate(mass[i]):
        if chr == '#':
            ind += 1
        else:
            values_row[ind] += 1
            ind_row[i][j] = ind

# print('ROW')
# for i in range(H):
#     for j in range(W):
#         print(values_row[ind_row[i][j]], end=' ')
#     print()

ind = 0
for j in range(W):
    ind += 1
    for i in range(H):
        chr = mass[i][j]
        if chr == '#':
            ind += 1
        else:
            values_col[ind] += 1
            ind_col[i][j] = ind

# print('COL')
# for i in range(H):
#     for j in range(W):
#         print(values_col[ind_col[i][j]], end=' ')
#     print()

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, values_row[ind_row[i][j]] + values_col[ind_col[i][j]] - 1)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict


H, W = map(int, input().split())
mass = list()
for i in range(H):
    mass.append(input())

values_col = defaultdict(int)
values_row = defaultdict(int)

ind_row = [[0 for i in range(H)] for j in range(W)]
ind_col = [[0 for i in range(H)] for j in range(W)]

ind = 0
for i, m_row in enumerate(mass):
    ind += 1
    for j, chr in enumerate(mass[i]):
        if chr == '#':
            ind += 1
        else:
            values_row[ind] += 1
            ind_row[i][j] = ind

# print('ROW')
# for i in range(H):
#     for j in range(W):
#         print(values_row[ind_row[i][j]], end=' ')
#     print()

ind = 0
for j in range(W):
    ind += 1
    for i in range(H):
        chr = mass[i][j]
        if chr == '#':
            ind += 1
        else:
            values_col[ind] += 1
            ind_col[i][j] = ind

# print('COL')
# for i in range(H):
#     for j in range(W):
#         print(values_col[ind_col[i][j]], end=' ')
#     print()

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, values_row[ind_row[i][j]] + values_col[ind_col[i][j]] - 1)
print(ans)
Problem p03063 (python)

Fixed submission:
import sys
sys.setrecursionlimit(200000)


N = int(input())
S = input()
S = list(S)


indices_black = list()
for i, c in enumerate(S):
    if c == '#':
        indices_black.append(i)

count_white = dict()
count = 0
for i, c in enumerate(S[::-1]):
    if c == '.':
        count += 1
    count_white[N - i - 1] = count


def get_answer(S):
    # most left
    if len(indices_black) == 0:
        return 0

    idx = indices_black.pop(0)
    if count_white[idx] == 0:
        return 0
    # count white: turn all white -> black
    ans_w = count_white[idx]

    # turn most left black -> white
    S[idx] = '.'
    ans_b = get_answer(S) + 1
    return min(ans_w, ans_b)


print(get_answer(S))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
S = list(S)


indices_black = list()
for i, c in enumerate(S):
    if c == '#':
        indices_black.append(i)

count_white = dict()
count = 0
for i, c in enumerate(S[::-1]):
    if c == '.':
        count += 1
    count_white[N - i - 1] = count


def get_answer(S):
    # most left
    if len(indices_black) == 0:
        return 0

    idx = indices_black.pop(0)
    if count_white[idx] == 0:
        return 0
    # count white: turn all white -> black
    ans_w = count_white[idx]

    # turn most left black -> white
    S[idx] = '.'
    ans_b = get_answer(S) + 1
    return min(ans_w, ans_b)


print(get_answer(S))
Problem p03089 (python)

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


def fast():
    candidate = list()
    
    while len(b) != 0:
        for i in range(len(b))[::-1]:
            if b[i] == (i+1):
                value = b.pop(i)
                candidate.append(value)
                break
            
        else:
            return [-1]

    candidate.reverse()
    return candidate

ans_list = fast()
for ans in ans_list:
    print(ans)

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


def naive():
    # (1), (1,2), ..., (1,...,N)
    import itertools
    candidates = itertools.product(*[range(1, i + 1) for i in range(1, N+1)])
    for candidate in candidates:
        a = list()
        for j in candidate:
            a.insert(j-1, j)

        if a == b:
            return candidate
    
    return -1


def fast():
    candidate = list()
    
    while len(b) != 0:
        for i in range(len(b))[::-1]:
            if b[i] == (i+1):
                value = b.pop(i)
                candidate.append(value)
                break
            
        else:
            return -1

    candidate.reverse()
    return candidate
 
# print(naive())
# print(fast())
ans_list = fast()
for ans in ans_list:
    print(ans)