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

Fixed submission:
def inv(x, ava):
    if x == 2:
        if 1 in ava:
            return 1
        else:
            return -1
    if x == 3:
        if 7 in ava:
            return 7
        else:
            return -1
    if x == 4:
        if 4 in ava:
            return 4
        else:
            return -1
    if x == 5:
        if 5 in ava:
            return 5
        if 3 in ava:
            return 3
        if 2 in ava:
            return 2
        else:
            return -1
    if x == 6:
        if 9 in ava:
            return 9
        if 6 in ava:
            return 6
        else:
            return -1
    if x == 7:
        if 8 in ava:
            return 8
        else:
            return -1
n, m = map(int, input().split())
ava = list(map(int, input().split()))
dp = [[] for _ in range(n+1)]
number = [inv(x,ava) for x in range(2,8)]
avapre = []
for i in range(6):
    if number[i] != -1:
        avapre.append(i+2)
avapresort = sorted(avapre,key = lambda x: number[x-2],reverse=True)
dp = [0 for _ in range(n+1)]
for i in range(1, n+1):
    if i < avapre[0]:
        dp[i] = -1
    else:
        dp[i] = -1
        for pre in avapre:
            if i - pre >= 0:
                dp[i] = max(dp[i], dp[i-pre]+1)
i = n
while(i > 0):
    for pre in avapresort:
        if i - pre >= 0 and dp[i] == dp[i-pre] + 1:
            print(number[pre-2], end='')
            i -= pre
            break
print()

Buggy submission (verdict: Runtime Error):
def inv(x, ava):
    if x == 2:
        if 1 in ava:
            return 1
        else:
            return -1
    if x == 3:
        if 7 in ava:
            return 7
        else:
            return -1
    if x == 4:
        if 4 in ava:
            return 4
        else:
            return -1
    if x == 5:
        if 5 in ava:
            return 5
        if 3 in ava:
            return 3
        if 2 in ava:
            return 2
        else:
            return -1
    if x == 6:
        if 9 in ava:
            return 9
        if 6 in ava:
            return 6
        else:
            return -1
    if x == 7:
        if 8 in ava:
            return 8
        else:
            return -1
n, m = map(int, input().split())
ava = list(map(int, input().split()))
dp = [[] for _ in range(n+1)]
number = [inv(x,ava) for x in range(2,8)]
avapre = []
for i in range(6):
    if number[i] != -1:
        avapre.append(i+2)
avapresort = sorted(key = lambda x: number[x-2], avapre)
dp = [0 for _ in range(n+1)]
for i in range(1, n+1):
    if i < avapre[0]:
        dp[i] = -1
    else:
        dp[i] = -1
        for pre in avapre:
            if i - pre >= 0:
                dp[i] = max(dp[i], dp[i-pre]+1)
i = n
while(i > 0):
    for pre in avapresort:
        if i - pre >= 0 and dp[i] == dp[i-pre] + 1:
            print(number[pre-2], end='')
            i -= pre
            break
print()
Problem p03138 (python)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
bitcount = []
k += 1
m = k
f = [sum(a)]
while(m > 0 or max(a) > 0):
    odd = sum(list(map(lambda x: x%2, a)))
    bitcount.append(odd)
    a = list(map(lambda x: x//2, a))
    m = m//2
for keta in range(len(bitcount)):
    if k & (2 ** keta) != 0:
        ans = 0
        for i in range(keta):
            ans += max(bitcount[i], n - bitcount[i]) * 2 ** i
        for i in range(keta + 1, len(bitcount)):
            if k & (2 ** i) == 0:
                ans += bitcount[i] * 2 ** i
            else:
                ans += (n - bitcount[i]) * 2 ** i
        ans += bitcount[keta] * 2 ** keta
        f.append(ans)
print(max(f))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
bitcount = []
k += 1
f = [sum(a)]
while(m > 0 or max(a) > 0):
    odd = sum(list(map(lambda x: x%2, a)))
    bitcount.append(odd)
    a = list(map(lambda x: x//2, a))
    m = m//2
for keta in range(len(bitcount)):
    if k & (2 ** keta) != 0:
        ans = 0
        for i in range(keta):
            ans += max(bitcount[i], n - bitcount[i]) * 2 ** i
        for i in range(keta + 1, len(bitcount)):
            if k & (2 ** i) == 0:
                ans += bitcount[i] * 2 ** i
            else:
                ans += (n - bitcount[i]) * 2 ** i
        ans += bitcount[keta] * 2 ** keta
        f.append(ans)
print(max(f))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
bitcount = []
m = k
while(m > 0):
    odd = sum(list(map(lambda x: x%2, a)))
    bitcount.append(odd)
    a = list(map(lambda x: x//2, a))
    m = m//2
f = []
for keta in range(len(bitcount)+1):
    ans = 0
    for i in range(keta):
        ans += max(bitcount[i], n - bitcount[i]) * 2 ** i
    for i in range(keta, len(bitcount)):
        if k & (2 ** i) == 0
            ans += bitcount[i] * 2 ** i
        else:
            ans += (n - bitcount[i]) * 2 ** i
    f.append(ans)
print(max(f))
Problem p03231 (python)

Fixed submission:
ls, lt = map(int, input().split())
s = list(input())
t = list(input())
def gcd(m,n):
    if n == 0:
        return m
    else:
        return gcd(n,m%n)
g = gcd(ls,lt)
m = ls // g
n = lt // g
ret = g*m*n
for i in range(g):
    if s[i*m] != t[i*n]:
        ret = -1
        break
print(ret)

Buggy submission (verdict: Runtime Error):
import math
ls, lt = map(int, input().split())
s = list(input())
t = list(input())
g = math.gcd(ls,lt)
if (g == ls):
    d = lt//g
    for i in range(ls):
        if (s[i]!=t[i*d]):
            print(-1)
            exit()
elif (g == lt):
    d = ls//g
    for i in range(lt):
        if (t[i]!=s[i*d]):
            print(-1)
            exit()
print(ls*lt//g)
Problem p03240 (python)

Fixed submission:
n = int(input())
x = [0] * n
y = [0] * n
h = [0] * n
for i in range(n):
    x[i], y[i], h[i] = map(int, input().split())
for a in range(101):
    for b in range(101):
        hset = set()
        for i in range(n):
            if h[i] != 0:
                hset.add(h[i] + abs(x[i]-a) + abs(y[i]-b))
        if len(hset) == 1:
            height = hset.pop()
            check = True
            for i in range(n):
                if h[i] == 0:
                    if height - abs(x[i]-a) - abs(y[i]-b) > 0:
                        check = False
                        break
            if check:
                print(a,b,height)
                exit()
print('ERROR EXIT')

Buggy submission (verdict: Runtime Error):
n = int(input())
info = [tuple(map(int, input().split()))]
nonzeroinfo = []
for x, y, h in info:
    if h > 0:
        nonzeroinfo.append((x, y, h))
zeroinfo = []
for x, y, h in info:
    if h == 0:
        zeroinfo.append((x, y, h))
def checknonzero(x, y, h):
    for a, b, c in nonzeroinfo:
        if h != abs(x-a) + abs(y-b) + c:
            return False
    return True
def checkzero(x, y, h):
    for a, b, _ in zeroinfo:
        if abs(x-a) + abs(y-b) < h:
            return False
    return True
for x in range(101):
    for y in range(101):
        x1, y1, h1 = nonzeroinfo[0]
        h = abs(x-x1) + abs(y-y1) + h1
        ret1 = checknonzero(x, y, h)
        ret2 = checkzero(x, y, h)
        if ret1 and ret2:
            print(x, y, h)
            exit()
Problem p03241 (python)

Fixed submission:
n, m = map(int, input().split())
divisors = []
for i in range(1,m+1):
    if i * i > m:
        break
    if i * i == m:
        divisors.append(i)
        break
    if m % i == 0:
        divisors.append(i)
        divisors.append(m // i)
ans = filter(lambda d: d <= m//n, divisors)
print(max(ans))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
if m % n == 0:
    print(m // n)
    exit()
for i in range(1,m//n):
    if m % i == 0:
        ret = i
print(ret)
Problem p03254 (python)

Fixed submission:
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ret = 0
for i in a:
    x -= i
    if x < 0:
        break
    ret += 1
if x > 0:
    ret -= 1
print(ret)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
s = list(input())
out = [set() for _ in range(n)]
count = [[0, 0] for _ in range(n)]
def f(c):
    if c == 'A': return 0
    else: return 1
for _ in range(m):
    a, b = map(int, input().split())
    if a == b:
        count[a-1][f(s[a-1])] += 1
    elif b-1 not in out[a-1]:
        count[a-1][f(s[b-1])] += 1
        count[b-1][f(s[a-1])] += 1
    out[a-1].add(b-1)
    out[b-1].add(a-1)
elim = set()
def eliminate(x):
    elim.add(x)
    c = f(s[x])
    for node in out[x]:
        if node not in elim:
            count[node][c] -= 1
            if count[node][0] * count[node][1] == 0:
                eliminate(node)
for i in range(n):
    if i not in elim and count[i][0] * count[i][1] == 0:
        eliminate(i)
if len(elim) < n: print('Yes')
else: print('No')
Problem p03255 (python)

Fixed submission:
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.reverse()
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + x[i]
mincost = 2 * n * m + 5 * cum[n]
for k in range(1,n):
    cost = m * (n + k)
    for i in range(n//k):
        cost += (cum[(i+1)*k] - cum[i*k]) * max(5, 3 + i*2)
    cost += (cum[n] - cum[n//k * k]) * max(5, 3 + n//k*2)
    mincost = min(mincost, cost)
print(mincost)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.reverse()
mincost = 2 * n * m + 5 * sum(x)
for k in range(1,n):
    cost = m * (n + k)
    for i in range(n):
        cost += max(5, 3 + i//k * 2) * x[i]
    mincost = min(mincost, min)
print(mincost)
Problem p03262 (python)

Fixed submission:
n, init = map(int,input().split())
x = list(map(lambda x: abs(int(x)-init), input().split()))
g = x[0]
def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x%y)
for i in range(1,n):
    g = gcd(g,x[i])
print(g)

Buggy submission (verdict: Runtime Error):
import math
n, init = map(int,input().split())
x = list(map(lambda x: abs(int(x)-init), input().split()))
g = x[0]
for i in range(1,n):
    g = math.gcd(g,x[i])
print(g)

Buggy submission (verdict: Runtime Error):
import math
n, init = map(int,input().split())
x = list(map(lambda x: abs(int(x)-init), input().split()))
g = x[0]
for i in range(n):
    g = math.gcd(g,x[i])
print(g)

Buggy submission (verdict: Runtime Error):
n, init = map(int, input().split())
x = list(map(int, input().split()))
def gcd(m,n):
    if n > m:
        gcd(n,m)
    elif m%n == 0:
        return n
    else:
        gcd(n,m%n)
def myabs(x):
    if x < 0:
        return -x
    else:
        return x
g = myabs(x[0]-init)
for i in range(n):
    if g == 1:
        break
    elif (myabs(x[i]-init) % g) != 0:
        g = gcd(g,x[i])
print(g)

Buggy submission (verdict: Runtime Error):
n, init = map(int, input().split())
y = list(map(int, input().split()))
x = list(map(lambda a: abs(a-init),y))
def gcd(m,n):
    if n > m:
        gcd(n,m)
    elif m%n == 0:
        return n
    else:
        gcd(n,m%n)
g = x[0]
for i in range(n):
    if g == 1:
        break
    elif (x[i] % g) != 0:
        g = gcd(g,x[i])
print(g)

Buggy submission (verdict: Runtime Error):
n, init = map(int, input().split())
x = list(map(lambda a: abs(int(a)-init), input().split()))
def gcd(m,n):
    if n > m:
        gcd(n,m)
    elif m%n == 0:
        return n
    else:
        gcd(n,m%n)
g = x[0]
for i in range(n):
    if g == 1:
        break
    elif x[i] % g != 0:
        g = gcd(g,x[i])
print(g)

Buggy submission (verdict: Runtime Error):
import math
n, init = map(int, input().split())
x = list(map(lambda a: abs(int(a)-init), input().split()))
g = x[0]
for i in range(n):
    if g == 1:
        break
    elif x[i] % g != 0:
        g = math.gcd(g,x[i])
print(g)

Buggy submission (verdict: Runtime Error):
import math
n, init = map(int, input().split())
x = list(map(lambda a: int(a)-init, input().split()))
g = x[0]
for i in range(n-1):
    if g == 1:
        break
    elif x[i+1] % g != 0:
        g = math.gcd(g,x[i+1])
print(g)

Buggy submission (verdict: Runtime Error):
import math
n, init = map(int, input().split())
x = list(map(lambda a: int(a)-init, input().split()))
g = x[0]
for i in range(n-1):
    g = math.gcd(g,x[i+1])
print(g)
Problem p03282 (python)

Fixed submission:
s = list(input())
k = int(input())
nonone = 0
for c in s:
    if c == '1':
        nonone += 1
    else: break
if k - 1 >= nonone:
    print(s[nonone])
else:
    print(1)

Buggy submission (verdict: Runtime Error):
s = list(input())
k = int(input())
nonone = 0
for c in s:
    if c == '1':
        nonone += 1
    else: break
if k >= nonone:
    print(s[nonone])
else:
    print(1)
Problem p03283 (python)

Fixed submission:
n, m, q = map(int, input().split())
train = [tuple(map(int, input().split())) for _ in range(m)]
quest = [tuple(map(int, input().split())) for _ in range(q)]
dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
d = {}
for l in range(n):
    for r in range(l,n):
        d[(l+1,r+1)] = 0
for p, q in train:
    d[(p,q)] += 1
for l in range(1,n+1):
    dp[l][l] = d[(l,l)]
for w in range(1,n):
    for l in range(n-w):
        dp[l+1][l+w+1] = dp[l+1][l+w] + dp[l+2][l+w+1] - dp[l+2][l+w] + d[(l+1,l+w+1)]
for l, r in quest:
    print(dp[l][r])

Buggy submission (verdict: Runtime Error):
n, m, q = map(int, input().split())
train = [tuple(map(int, input().split())) for _ in range(m)]
dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
d = {}
for l in range(n):
    for r in range(l,n):
        d[(l+1,r+1)] = 0
for p, q in train:
    d[(p,q)] += 1
for l in range(1,n+1):
    dp[l][l] = d[(l,l)]
for w in range(1,n):
    for l in range(n-w):
        dp[l+1][l+w+1] = dp[l+1][l+w] + dp[l+2][l+w+1] - dp[l+2][l+w] + d[(l+1,l+w+1)]
for _ in range(q):
    l, r = map(int, input().split())
    print(dp[l][r])

Buggy submission (verdict: Runtime Error):
n, m, q = map(int, input().split())
train = [tuple(map(int, input().split())) for _ in range(m)]
quest = [tuple(map(int, input().split())) for _ in range(q)]
dp = [[0 for _ in range(n)] for _ in range(n)]
d = {}
for l in range(n):
    for r in range(l,n):
        d[(l,r)] = 0
for p, q in train:
        d[(p,q)] += 1
for l in range(n):
    dp[l][l] = d[(l+1,l+1)]
for w in range(1,n):
    for l in range(n-w):
        dp[l][l+w] = dp[l][l+w-1] + d[(l,l+w)]
for l, r in quest:
    print(dp[l-1][r-1])

Buggy submission (verdict: Runtime Error):
n, m, q = map(int, input().split())
train = [tuple(map(int, input().split())) for _ in range(m)]
quest = [tuple(map(int, input().split())) for _ in range(q)]
dp = [[0 for _ in range(n)] for _ in range(n)]
d = {}
for l in range(n):
    for r in range(l,n):
        d[(l,r)] = 0
for p, q in train:
    else:
        d[(p,q)] += 1
for l in range(n):
    dp[l][l] = d[(l+1,l+1)]
for w in range(1,n):
    for l in range(n-w):
        dp[l][l+w] = dp[l][l+w-1] + d[(l,l+w)]
for l, r in quest:
    print(dp[l-1][r-1])
Problem p03308 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
print(max(a) - min(a))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
return max(a) - min(a)
Problem p03309 (python)

Fixed submission:
n = int(input())
A_list = list(map(int, input().split()))
for i in range(n):
    A_list[i] -= i
A_list.sort()

def sadness(a, mid):
    sad = 0
    for i in range(mid):
        sad += a[mid] - a[i]
    for i in range(mid+1,len(a)):
        sad += a[i] - a[mid]
    return sad

if n % 2 != 0:
    print(sadness(A_list, n//2))
else:
    print(min(sadness(A_list, n//2), sadness(A_list, n//2+1)))

Buggy submission (verdict: Runtime Error):
n = int(input())
A_list = list(map(int, input().split()))
for i in range(n):
    A_list[i] -= i
A_list.sort()
A_cum = [0] * n
for i in range(n):
    if i == 0:
        A_cum[0] = A_list[0]
    else:
        A_cum[i] = A_cum[i-1] + A_list[i]

def findinfindex(sortedlist, key, l, r):
    if r - l <= 0:
        return l
    m = (l+r+1)//2
    if sortedlist[m] > key:
        return findinfindex(sortedlist, key, l, m-1)
    else:
        return findinfindex(sortedlist, key, m, r)

sadmin = -1
for b in range(A_list[n//2],A_list[(n+1)//2]+1):
    lastminus = findinfindex(A_list, b, 0, n-1)
    sadness = (2*lastminus - n + 2)*b - 2*A_cum[lastminus] + A_cum[n-1]
    if sadmin == -1:
        sadmin = sadness
    elif sadness < sadmin:
        sadmin = sadness
    else:
        break
print(sadmin)

Buggy submission (verdict: Runtime Error):
n = int(input())
A_list = list(map(int, input().split()))
for i in range(n):
    A_list[i] -= i
A_list.sort()
A_cum = [0] * n
for i in range(n):
    if i == 0:
        A_cum[0] = A_list[0]
    else:
        A_cum[i] = A_cum[i-1] + A_list[i]
def findinfindex(sortedlist, key, l, r):
    if r - l <= 0:
        return l
    m = (l+r+1)//2
    if sortedlist[m] > key:
        return findinfindex(sortedlist, key, l, m-1)
    else:
        return findinfindex(sortedlist, key, m, r)
sadmin = -1
for b in range(A_list[n//2],A_list[(n+1)//2]+1):
    lastminus = findinfindex(A_list, b, 0, n-1)
    sadness = (2*lastminus - n + 2)*b - 2*A_cum[lastminus] + A_cum[n-1]
    if sadmin == -1:
        sadmin = sadness
    elif sadness < sadmin:
        sadmin = sadness
    else:
        break
print(sadmin)
Problem p03318 (python)

Fixed submission:
k = int(input())
sunuke_list = [1,2,3,4,5,6,7,8]
def s(n):
    n_charlist = list(str(n))
    return sum(list(map(int, n_charlist)))
def combine_int(i,n):
    i_charlist = list(str(i))
    n_charlist = ['9'] * n
    ret_charlist = i_charlist + n_charlist
    ret_str = ''.join(ret_charlist)
    return int(ret_str)
for n in range(1,14):
    if n >= 12:
        i = n-2
    else:
        i = n-1
    while((i+1)/(s(i)+9*n) <= (i+2)/(s(i+1)+9*n)):
        sunuke_list.append(combine_int(i,n))
        i += 1
for i in range(k):
    print(sunuke_list[i])

Buggy submission (verdict: Runtime Error):
k = int(input())
sunuke_list = [1,2,3,4,5,6,7,8]
def s(n):
    n_charlist = list(str(n))
    return sum(list(map(int, n_charlist)))
def combine_int(i,n):
    i_charlist = list(str(i))
    n_charlist = ['9'] * n
    ret_charlist = i_charlist + n_charlist
    ret_str = ''.join(ret_charlist)
    return int(ret_str)
for n in range(1,13):
    i = n-1
    while((i+1)/(s(i)+9*n) <= (i+2)/(s(i+1)+9*n)):
        sunuke_list.append(combine_int(i,n))
        i += 1
for i in range(k):
    print(sunuke_list[i])
Problem p03340 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + a[i]
l = 0
r = 0
count = 0
while(r < n or l < n):
    if r < n and (cum[r] - cum[l]) & a[r] == 0:
        r += 1
    else:
        count += r - l
        l += 1
print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + a[i]
l = 0
r = 0
count = 0
while(r + 1 < n):
    if (cum[r] - cum[l]) & a[r+1] == 0:
        r += 1
        count += 1
    else:
        j += 1
print(count)
Problem p03353 (python)

Fixed submission:
s = input()
k = int(input())
n = len(s)
koho = set()
for i in range(n):
    for j in range(k):
        if i + j < n:
            koho.add(s[i:(i+j+1)])
so = sorted(list(koho))
print(so[k-1])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
def all(s, k):
    if s == '':
        return {}
    ret = set()
    for i in range(k):
        if i < len(s):
            ret.add(s[:(i+1)])
    return ret.union(all(s[1:], k))
koho = sorted(list(all(s,k)))
print(koho[k-1])
Problem p03387 (python)

Fixed submission:
a = list(map(int, input().split()))
a.sort()
diff1 = a[1] - a[0]
diff2 = a[2] - a[1]
diff3 = a[2] - a[0]
if diff1 % 2 == 0:
    if diff3 % 2 == 0:
        print((diff3 + diff2)//2)
    else:
        print(diff3//2 + diff2//2 + 1)
else:
    if diff3 % 2 == 0:
        print(diff3//2 + diff2//2 + 2)
    else:
        print(diff3//2 + diff2//2 + 2)

Buggy submission (verdict: Runtime Error):
a = list(map(int, input().split()))
a.sort()
diff1 = a[1] - a[0]
diff2 = a[2] - a[1]
diff3 = a[2] - a[0]
if diff1 % 2 == 0:
    if diff3 % 2 == 0:
        print((diff3 + diff2)//2)
    else:
        print(diff3//2 + diff2//2 + 1)
else:
    if diff3 % 2 == 0:
        print(diff3//2 + diff2//2 + 2)
    else:
        prnit(diff3//2 + diff2//2 + 2)
Problem p03472 (python)

Fixed submission:
n, h = map(int, input().split())
katana = [tuple(map(int, input().split())) for _ in range(n)]
maxa = 0
for a, _ in katana:
    maxa = max(maxa, a)
bgreedy = 0
count = 0
katana.sort(key = lambda x: x[1], reverse = True)
for a, b in katana:
    if b < maxa:
        break
    bgreedy += b
    count += 1
    if h <= bgreedy:
        print(count)
        exit()
print(count + (h - bgreedy)//maxa + int((h-bgreedy) % maxa != 0))

Buggy submission (verdict: Runtime Error):
n, h = map(int, input().split())
katana = [tuple(map(int, input().split())) for _ in range(n)]
maxa = 0
for a, _ in katana:
    maxa = max(maxa, a)
bgreedy = 0
count = 0
katana.sort(lambda x: x[1], reverse = True)
for a, b in katana:
    if b < maxa:
        break
    bgreedy += b
    count += 1
    if h <= bgreedy:
        print(count)
        exit()
print(count + (h - bgreedy)//maxa + int((h-bgreedy) % maxa != 0))
Problem p03488 (python)

Fixed submission:
s = input()
x, y = map(int, input().split())
edge = [[], []]
# delete first edge
firstedge = 0
for c in s:
    if c == 'T': break
    else: firstedge += 1
x -= firstedge
dir = 0
cur = 0
for c in s[firstedge:]:
    if c == 'T':
        if cur > 0:
            edge[dir].append(cur)
            cur = 0
        dir = (dir + 1) % 2
    else:
        cur += 1
if cur > 0:
    edge[dir].append(cur)
xtar = sum(edge[0]) + x
ytar = sum(edge[1]) + y
if xtar < 0 or ytar < 0 or x > sum(edge[0]) or y > sum(edge[1]):
    print('No')
    exit()
# partition dp
dx = [0] * (xtar + 1)
dy = [0] * (ytar + 1)
dx[0], dy[0] = 1, 1
for e in edge[0]:
    preone = []
    for i in range(xtar+1 - 2*e):
        if dx[i] == 1:
            preone.append(i)
    for i in preone:
        dx[i+2*e] = 1
    if dx[xtar]: break
for e in edge[1]:
    preone = []
    for i in range(ytar+1 - 2*e):
        if dy[i] == 1:
            preone.append(i)
    for i in preone:
        dy[i+2*e] = 1
    if dy[ytar]: break
if dx[xtar] and dy[ytar]: print('Yes')
else: print('No')

Buggy submission (verdict: Runtime Error):
s = input()
x, y = map(int, input().split())
edge = [[], []]
# delete first edge
firstedge = 0
for c in s:
    if c == 'T': break
    else: firstedge += 1
x -= firstedge
dir = 0
cur = 0
for c in s[firstedge:]:
    if c == 'T':
        if cur > 0:
            edge[dir].append(cur)
            cur = 0
        dir = (dir + 1) % 2
    else:
        cur += 1
if cur > 0:
    edge[dir].append(cur)
xtar = sum(edge[0]) + x
ytar = sum(edge[1]) + y
if xtar < 0 or ytar < 0:
    print('No')
    exit()
# partition dp
dx = [0] * (xtar + 1)
dy = [0] * (ytar + 1)
dx[0], dy[0] = 1, 1
for e in edge[0]:
    for i in range(xtar+1 - 2*e):
        pre = dx.copy()
        if pre[i] == 1:
            dx[i+2*e] = 1
    if dx[xtar]: break
for e in edge[1]:
    for i in range(ytar+1 - 2*e):
        pre = dy.copy()
        if pre[i] == 1:
            dy[i+2*e] = 1
    if dy[ytar]: break
if dx[xtar] and dy[ytar]: print('Yes')
else: print('No')
Problem p03612 (python)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        ans += 1
if p[n-1] == n:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if p[i] == i+1:
        print(p)
        p[i], p[i+1] = p[i+1], p[i]
        ans += 1
if p[-1] == n:
    ans += 1
print(ans)