Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

eats = sorted(p, reverse=True)[:x] + sorted(q, reverse=True)[:y]
while r and max(r) >= min(eats):
    eats[eats.index(min(eats))] = max(r)
    r.remove(max(r))

print(sum(eats))

Fixed submission:
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

eats = sorted(p, reverse=True)[:x] + sorted(q, reverse=True)[:y] + r
eats.sort(reverse=True)
print(sum(eats[:x+y]))

Buggy python submission (verdict: Time Limit Exceeded):
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

# まずは赤と緑の中だけで最大となるようX+Y個のりんごを選ぶ．
p_x = sorted(p, reverse=True)[:x].copy()
q_y = sorted(q, reverse=True)[:y].copy()
eats = p_x + q_y
i, j = 0, 0
while r and max(r) >= min(eats):
    mi = min(eats)
    eats[eats.index(mi)] = max(r)
    r.remove(max(r))

print(sum(eats))

Fixed submission:
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

eats = sorted(p, reverse=True)[:x] + sorted(q, reverse=True)[:y] + r
eats.sort(reverse=True)
print(sum(eats[:x+y]))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [10 ** 9] * n
dp[0] = 0

a = min(n, k)
for i in range(n):
    for j in range(1, min(k + 1, n - i)):
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))

print(dp[-1])

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

dp = [10 ** 9] * n
dp[0] = 0

for i in range(1, n):
    j = max(0, i - k)
    hi = h[i]
    dp[i] = min(dpj + abs(hi - hj) for dpj, hj in zip(dp[j:i], h[j:i]))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [10 ** 9] * n
dp[0] = 0

a = min(n, k)
for i in range(1, n):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    
    for j in range(2, a+1):
        dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))

print(dp[-1])

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

dp = [10 ** 9] * n
dp[0] = 0

for i in range(1, n):
    j = max(0, i - k)
    hi = h[i]
    dp[i] = min(dpj + abs(hi - hj) for dpj, hj in zip(dp[j:i], h[j:i]))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [10 ** 9] * n
dp[0] = 0

for i in range(1, n):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))

    for j in range(2, k+1):
        if i >= j:
            dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))

print(dp[-1])

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

dp = [10 ** 9] * n
dp[0] = 0

for i in range(1, n):
    j = max(0, i - k)
    hi = h[i]
    dp[i] = min(dpj + abs(hi - hj) for dpj, hj in zip(dp[j:i], h[j:i]))

print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, w = map(int, input().split())
shina = np.array(tuple(tuple(map(int, input().split())) for _ in range(n)))

dp = np.array([[0 for i in range(w+1)] for j in range(n+1)])

for i, wv in enumerate(shina):
    wi = wv[0]
    vi = wv[1]
    dpi = dp[i]

    for sum_w in range(w+1):
        if sum_w - wi >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dpi[sum_w - wi] + vi)

        dp[i+1][sum_w] = max(dp[i+1][sum_w], dpi[sum_w])

print(dp[-1][-1])

Fixed submission:
import numpy as np
n, w = map(int, input().split())
wv_list = [[int(i) for i in input().split()] for i in range(n)]

dp = np.zeros(w+1)
for wv in wv_list:
    w = wv[0]
    v = wv[1]
    dp[w:] = np.maximum(dp[:-w]+v, dp[w:])

print(int(np.max(dp)))

Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
shina = tuple(tuple(map(int, input().split())) for _ in range(n))

dp = [[0 for i in range(w+1)] for j in range(n+1)]

for i, wv in enumerate(shina):
    wi = wv[0]
    vi = wv[1]
    dpi = dp[i]

    for sum_w in range(w+1):
        if sum_w - wi >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dpi[sum_w - wi] + vi)

        dp[i+1][sum_w] = max(dp[i+1][sum_w], dpi[sum_w])

print(dp[-1][-1])

Fixed submission:
import numpy as np
n, w = map(int, input().split())
wv_list = [[int(i) for i in input().split()] for i in range(n)]

dp = np.zeros(w+1)
for wv in wv_list:
    w = wv[0]
    v = wv[1]
    dp[w:] = np.maximum(dp[:-w]+v, dp[w:])

print(int(np.max(dp)))

Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
shina = tuple(tuple(map(int, input().split())) for _ in range(n))

dp = [[0 for i in range(w+1)] for j in range(n+1)]

for i in range(n):
    wi = shina[i][0]
    vi = shina[i][1]
    for sum_w in range(w+1):
        if sum_w - wi >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - wi] + vi)

        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])

print(dp[-1][-1])

Fixed submission:
import numpy as np
n, w = map(int, input().split())
wv_list = [[int(i) for i in input().split()] for i in range(n)]

dp = np.zeros(w+1)
for wv in wv_list:
    w = wv[0]
    v = wv[1]
    dp[w:] = np.maximum(dp[:-w]+v, dp[w:])

print(int(np.max(dp)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n % 1000 == 0:
  return 0
return 1000 - (n % 1000)

Fixed submission:
n = int(input())
x = n % 1000
if x == 0:
    print(x)
else:
    print(1000 - x)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(n):
    ans *= a[i]
print(ans if ans <= 10**18 else -1)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(n):
    if ans != -1:
        ans *= a[i]
    elif a[i] == 0:
        ans = 0
        break
    if ans > 10**18:
        ans = -1
print(ans)
Buggy python submission (verdict: Runtime Error):
mod = 10**9 + 7
n = int(input())
d = {}
for _ in range(n):
    a, b = map(int, input().split())
    if a/b in d:
        d[a/b] += 1
    else:
        d[a/b] = 1
ans = 1
for k in d.keys():
    if d[k] > 0:
        t = 2**d[k]
        if -1/k in d:
            t += 2**d[-1/k] - 1
            d[-1/k] = 0
        ans *= t
        ans %= mod
print(ans-1)

Fixed submission:
import math
mod = 10**9 + 7
n = int(input())
d = {}
d0 = 0
for _ in range(n):
    a, b = map(int, input().split())
    g = math.gcd(a, b)
    if g == 0:
        d0 += 1
    else:
        a //= g
        b //= g
        if a < 0:
            a = -a
            b = -b
        elif a == 0 and b < 0:
            b = -b
        if (a,b) in d:
            d[(a,b)] += 1
        else:
            d[(a,b)] = 1
ans = 1
for (a,b) in d.keys():
    if d[(a,b)] > 0:
        t = 2**d[(a,b)]
        if b <= 0:
            a = -a
            b = -b
        if (b,-a) in d:
            t += 2**d[(b,-a)] - 1
            d[(b,-a)] = 0
        ans *= t
        ans %= mod
print((ans+d0-1)%mod)
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
div = []
for i in range(1, int(x**0.5)+1):
    if x % i == 0:
        div.append(i)
        if i != x // i:
            div.append(x//i)

def f():
    for d in div:
        a = 0
        while True:
            b = a - d
            if a**5 - b**5 == x:
                return a, b
            elif b > 0 and a**5 - b**5 > x:
                break
            a += 1

print(*f())

Fixed submission:
x = int(input())

def f():
    for a in range(1, 200):
        for b in range(-200, a):
            if a**5 - b**5 == x:
                print(a, b)
                return

f()
Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map(int, input().split())
if a == 1 or b == 1:
    print(0)
else:
    ans = 0
    prev = 0
    for x in range(n+1):
        tmp = (a*x)//b - a*(x//b)
        if prev > 0 and tmp == 0:
            ans = prev
            break
        prev = tmp
    else:
        ans = prev
    print(ans)

Fixed submission:
a, b, n = map(int, input().split())
print((a*min(b-1,n))//b)

Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map(int, input().split())
if a == 0 or b == 0:
    print(0)
else:
    ans = 0
    prev = 0
    for x in range(n+1):
        tmp = (a*x)//b - a*(x//b)
        if prev > 0 and tmp == 0:
            ans = prev
            break
        prev = tmp
    else:
        ans = prev
    print(ans)

Fixed submission:
a, b, n = map(int, input().split())
print((a*min(b-1,n))//b)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
mod = 10**9 + 7
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
def p(n, k):
    x = 1
    for i in range(k):
        x *= n - i
        x %= mod
    return x
def f(x, par):
    L = len(G[x])
    if x == par:
        if L <= K-1:
            ans = K*p(K-1,L) % mod
        else:
            return 0
    elif x != par:
        if L-1 <= K-2:
            ans = p(K-2,L-1)
        else:
            return 0
    for i in G[x]:
        if i != par:
            ans *= f(i, x)
            ans %= mod
    return ans
print(f(0, 0))

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
N, K = map(int, input().split())
mod = 10**9 + 7
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
def p(n, k):
    x = 1
    for i in range(k):
        x *= n - i
        x %= mod
    return x
def f(x, par):
    L = len(G[x])
    if x == par:
        if L <= K-1:
            ans = K*p(K-1,L) % mod
        else:
            return 0
    elif x != par:
        if L-1 <= K-2:
            ans = p(K-2,L-1)
        else:
            return 0
    for i in G[x]:
        if i != par:
            ans *= f(i, x)
            ans %= mod
    return ans
print(f(0, 0))
Buggy python submission (verdict: Runtime Error):
N = int(input())
SP = sorted([(*input().split(), i) for i in range(N)], key=lambda x:(x[0], -int(x[1])))
for i in range(N):
    print(SP[i][2]+1)

Fixed submission:
N = int(input())
SP = sorted([(input().split(), i) for i in range(N)], key=lambda x:(x[0][0], -int(x[0][1])))
for i in range(N):
    print(SP[i][1]+1)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
for _ in range(M):
    B, C = map(int, input().split())
    if C >= A[0]:
        if C >= A[B-1]:
            if C >= A[N-1]:
                A = A[B:] + [C]*B
            else:
                x = bisect.bisect(A[B:], C)
                A = A[B:B+x] + [C]*B + A[B+x:]
        else:
            x = bisect.bisect(A[:B], C)
            A = [C]*x + A[x:]
print(sum(A))

Fixed submission:
N, M = map(int, input().split())
A = sorted(map(int, input().split()))
BC = sorted((tuple(map(int, input().split())) for _ in range(M)), key=lambda x:x[1])
D = []
x = 0
for i in range(M-1,-1,-1):
    if x + BC[i][0] >= N:
        D += [BC[i][1]]*(N-x)
        break
    D += [BC[i][1]]*BC[i][0]
    x += BC[i][0]
for i in range(len(D)):
    if A[i] >= D[i]:
        break
    A[i] = D[i]
print(sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9 + 7

def comb(n, k):
    x, y = 1, 1
    k = min(k, n-k)
    for i in range(k):
        x *= n - i
        y *= i + 1
    return x*pow(y, mod-2, mod) % mod

N, M, K = map(int, input().split())
print((sum(i*(N-i)*M**2 for i in range(N))+sum(i*(M-i)*N**2 for i in range(M)))*comb(N*M-2, K-2) % mod)

Fixed submission:
mod = 10**9 + 7

def comb(n, k):
    x, y = 1, 1
    k = min(k, n-k)
    for i in range(k):
        x *= n - i
        x %= mod
        y *= i + 1
        y %= mod
    return x*pow(y, mod-2, mod) % mod

N, M, K = map(int, input().split())
print((sum(i*(N-i)*M**2 for i in range(N))+sum(i*(M-i)*N**2 for i in range(M)))*comb(N*M-2, K-2) % mod)

Buggy python submission (verdict: Time Limit Exceeded):
def comb(n, k):
    x, y = 1, 1
    if 2*k > n:
        k = n - k
    for i in range(k):
        x *= n - i
        y *= i + 1
    return x//y

N, M, K = map(int, input().split())
print((sum(i*(N-i)*M**2 for i in range(N))+sum(i*(M-i)*N**2 for i in range(M)))*comb(N*M-2, K-2) % (10**9+7))

Fixed submission:
mod = 10**9 + 7

def comb(n, k):
    x, y = 1, 1
    k = min(k, n-k)
    for i in range(k):
        x *= n - i
        x %= mod
        y *= i + 1
        y %= mod
    return x*pow(y, mod-2, mod) % mod

N, M, K = map(int, input().split())
print((sum(i*(N-i)*M**2 for i in range(N))+sum(i*(M-i)*N**2 for i in range(M)))*comb(N*M-2, K-2) % mod)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [-1]*n
b = []
for i in range(m):
    x, y, z = map(int, input().split())
    if a[x-1] != -1:
        if a[y-1] != -1:
            if a[x-1] != a[y-1]:
                b[a[x-1]] |= b[a[y-1]]
                for j in b[a[y-1]]:
                    a[j] = a[x-1]
                b.pop(a[y-1])
        else:
            b[a[x-1]].add(y-1)
            a[y-1] = a[x-1]
    else:
        if a[y-1] != -1:
            b[a[y-1]].add(x-1)
            a[x-1] = a[y-1]
        else:
            b.append({x-1, y-1})
            a[x-1] = a[y-1] = len(b) - 1
print(len(b)+a.count(-1))

Fixed submission:
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0]*n

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
    x, y, z = map(int, input().split())
    uf.unite(x-1, y-1)
print(len(set(uf.find(i) for i in range(n))))
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
ans = 0
for r in range(N//R+2):
    for g in range((N-r*R)//G+2):
        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-r*R)//G+1):
        if (N - r*R - g*G) % B == 0:
            ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
print(min(s[:i].count('#')+s[i:].count('.') for i in range(n+1)))

Fixed submission:
n = int(input())
s = list(input())
bi = [0]
wi = [0]
b = 0
w = 0
for i in range(n):
    if s[i] == '#':
        b += 1
    if s[-i-1] == '.':
        w += 1
    bi.append(b)
    wi.append(w)
print(min(bi[i]+wi[-i-1] for i in range(n+1)))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = list(map(int, input()))
a = []
c = 1
m = 0
for i in range(n):
    if s[i] == c:
        m += 1
    else:
        a.append(m)
        c = 1 - c
        m = 1
a.append(m)
if len(a) % 2 == 0:
    a.append(0)
r = len(a) // 2
if k >= r:
    print(n)
else:
    print(max(sum(a[2*i:2*(i+k)+1]) for i in range(r-k+1)))

Fixed submission:
n, k = map(int, input().split())
s = list(map(int, input()))
x = [0]
if s[0] == 0:
    x.append(0)
for i in range(n-1):
    if s[i] != s[i+1]:
        x.append(i+1)
x.append(n)
if s[n-1] == 0:
    x.append(n)
r = len(x) // 2 - 1
if k >= r:
    print(n)
else:
    print(max(x[2*(i+k)+1]-x[2*i] for i in range(r-k+1)))
Buggy python submission (verdict: Time Limit Exceeded):
import functools
A, B = map(int, input().split())
print(functools.reduce(lambda x, y: x^y, range(A, B+1)))

Fixed submission:
A, B = map(int, input().split())
print([A-1, 1, A, 0][(A-1)%4]^[B, 1, B+1, 0][B%4])

Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
C = list(range(A, B+1))
N = B - A + 1
D = []
while C[N-1] > 0:
    D.append(sum(C[i] % 2 == 1 for i in range(N)) % 2)
    C = [C[i] // 2 for i in range(N)]
ans = 0
for i in reversed(range(len(D))):
    ans = ans*2 + D[i]
print(ans)

Fixed submission:
A, B = map(int, input().split())
print([A-1, 1, A, 0][(A-1)%4]^[B, 1, B+1, 0][B%4])
Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
print([i for i in range(1, max(A,B)+1) if A % i == 0 && B % i == 0][K-1])

Fixed submission:
A, B, K = map(int, input().split())
print([i for i in reversed(range(1, max(A,B)+1)) if A % i == 0 and B % i == 0][K-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nn = (n + 1) // 2
s = [0]*n
print(0)
s[0] = input()
if s[0] == "Vacant":
    exit()
print(n-1)
s[n-1] = input()
if s[n-1] == "Vacant":
    exit()
ll = 0
hh = nn-1
while hh - ll > 1:
    l = ll*2
    h = hh*2
    ii = (ll + hh) // 2
    i = ii*2
    print(i)
    s[i] = input()
    if s[i] == "Vacant":
        exit()
    elif s[i] != s[l]:
        ll = ii
    else:
        hh = ii
print(ll+hh)

Fixed submission:
n = int(input())
nn = (n + 1) // 2
s = [0]*n
print(0)
s[0] = input()
if s[0] == "Vacant":
    exit()
print(n-1)
s[n-1] = input()
if s[n-1] == "Vacant":
    exit()
ll = 0
hh = nn-1
while hh - ll > 1:
    l = ll*2
    h = hh*2
    ii = (ll + hh) // 2
    i = ii*2
    print(i)
    s[i] = input()
    if s[i] == "Vacant":
        exit()
    elif s[i] != s[l]:
        hh = ii
    else:
        ll = ii
print(ll+hh)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nn = (n + 1) / 2
s = [0]*n
print(0)
s[0] = input()
if s[0] == "Vacant":
    exit()
print(n-1)
s[n-1] = input()
if s[n-1] == "Vacant":
    exit()
ll = 0
hh = nn-1
while hh - ll > 1:
    l = ll*2
    h = hh*2
    ii = (ll + hh) / 2
    i = ii*2
    print(i)
    s[i] = input()
    if s[i] == "Vacant":
        exit()
    elif s[i] != s[l]:
        ll = ii
    else:
        hh = ii
print(ll+hh)
exit()

Fixed submission:
n = int(input())
nn = (n + 1) // 2
s = [0]*n
print(0)
s[0] = input()
if s[0] == "Vacant":
    exit()
print(n-1)
s[n-1] = input()
if s[n-1] == "Vacant":
    exit()
ll = 0
hh = nn-1
while hh - ll > 1:
    l = ll*2
    h = hh*2
    ii = (ll + hh) // 2
    i = ii*2
    print(i)
    s[i] = input()
    if s[i] == "Vacant":
        exit()
    elif s[i] != s[l]:
        hh = ii
    else:
        ll = ii
print(ll+hh)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nn = (n + 1) / 2
s = [0]*n
print(0)
s[0] = input()
if s[0] == "Vacant":
    exit()
print(n-1)
s[n-1] = input()
if s[n-1] == "Vacant":
    exit()
ll = 0
hh = nn-1
while hh - ll > 1:
    l = ll*2
    h = hh*2
    ii = (ll + hh) / 2
    i = ii*2
    print(i)
    s[i] = input()
    if s[i] == "Vacant":
        exit()
    elif s[i] != s[l]:
        ll = ii
    else:
        hh = ii
print(ll+hh)

Fixed submission:
n = int(input())
nn = (n + 1) // 2
s = [0]*n
print(0)
s[0] = input()
if s[0] == "Vacant":
    exit()
print(n-1)
s[n-1] = input()
if s[n-1] == "Vacant":
    exit()
ll = 0
hh = nn-1
while hh - ll > 1:
    l = ll*2
    h = hh*2
    ii = (ll + hh) // 2
    i = ii*2
    print(i)
    s[i] = input()
    if s[i] == "Vacant":
        exit()
    elif s[i] != s[l]:
        hh = ii
    else:
        ll = ii
print(ll+hh)
Buggy python submission (verdict: Runtime Error):
S=input()
N=len(S)
print(min([max(i,N-i) for i in range(1,N) if S[i-1]!=S[i]]))

Fixed submission:
S=input()
N=K=len(S)
for i in range(1,N):
    if S[i-1]!=S[i]:
        K=min(K,max(i,N-i))
print(K)

Buggy python submission (verdict: Runtime Error):
S=input()
N=len(S)
print(min(max(i,N-i) for i in range(1,N) if S[i-1]!=S[i]))

Fixed submission:
S=input()
N=K=len(S)
for i in range(1,N):
    if S[i-1]!=S[i]:
        K=min(K,max(i,N-i))
print(K)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
m=list(map(len,S.split("0")))
while 0 in m:
    m.remove(0)
n=list(map(len,S.split("1")))
while 0 in n:
    n.remove(0)
print(max(sum(m),sum(n)))

Fixed submission:
S=input()
N=K=len(S)
for i in range(1,N):
    if S[i-1]!=S[i]:
        K=min(K,max(i,N-i))
print(K)
Buggy python submission (verdict: Runtime Error):
s=list(map(len,input().split("T")))
x,y=map(int,input().split())
def f(i,w):
    if i==0:
        return w==0
    if (i,w) not in m:
        m[(i,w)]=f(i-1,w-t[i-1]) or f(i-1,w+t[i-1])
    return m[(i,w)]
m={}
t=sorted(s[2::2])
a=f(len(t),x-s[0])
m={}
t=sorted(s[1::2])
print(["No","Yes"][a and f(len(t),y)])

Fixed submission:
s=list(map(len,input().split("T")))
x,y=map(int,input().split())
def f(t,w):
    m=[{} for i in range(len(t)+1)]
    m[0][0]=1
    for i in range(len(t)):
        for z in m[i]:
            m[i+1][z+t[i]]=1
            m[i+1][z-t[i]]=1
    return w in m[len(t)]
print(["No","Yes"][f(s[2::2],x-s[0]) and f(s[1::2],y)])

Buggy python submission (verdict: Runtime Error):
s=list(map(len,input().split("T")))
x,y=map(int,input().split())
def f(t,i,w):
    if i==0:
        return w==0
    return f(t,i-1,w-t[i-1]) or f(t,i-1,w+t[i-1])
print(["No","Yes"][f(sorted(s[2::2]),len(s[2::2]),x-s[0]) and f(sorted(s[1::2]),len(s[1::2]),y)])

Fixed submission:
s=list(map(len,input().split("T")))
x,y=map(int,input().split())
def f(t,w):
    m=[{} for i in range(len(t)+1)]
    m[0][0]=1
    for i in range(len(t)):
        for z in m[i]:
            m[i+1][z+t[i]]=1
            m[i+1][z-t[i]]=1
    return w in m[len(t)]
print(["No","Yes"][f(s[2::2],x-s[0]) and f(s[1::2],y)])

Buggy python submission (verdict: Time Limit Exceeded):
s=list(map(len,input().split("T")))
x,y=map(int,input().split())
def f(t,w):
    for i in range(1<<len(t)):
        z=0
        for j in range(len(t)):
            z+=[1,-1][i>>j&1]*t[j]
        if z==w:
            return True
    return False
print("Yes"if f(s[2::2],x-s[0]) and f(s[1::2],y) else "No")

Fixed submission:
s=list(map(len,input().split("T")))
x,y=map(int,input().split())
def f(t,w):
    m=[{} for i in range(len(t)+1)]
    m[0][0]=1
    for i in range(len(t)):
        for z in m[i]:
            m[i+1][z+t[i]]=1
            m[i+1][z-t[i]]=1
    return w in m[len(t)]
print(["No","Yes"][f(s[2::2],x-s[0]) and f(s[1::2],y)])