Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
import numpy as np

n = int(input())
xy = np.array([list(map(int, input().split())) for _ in range(n)])

x = xy[xy.argsort(axis=0)[:, 0]]
y = xy[xy.argsort(axis=0)[:, 1]]

x = [list(x) for x in np.diff(x, axis=0)]
y = [list(y) for y in np.diff(y, axis=0)]


memo_x = defaultdict(int)
memo_y = defaultdict(int)

for i, j in zip(x, y):
    memo_x[str(i)] += 1
    memo_y[str(j)] += 1

print(n - max(max(memo_x.values()), max(memo_x.values())))

Fixed submission:
from collections import defaultdict
import numpy as np
import sys

n = int(input())
xy = np.array([list(map(int, input().split())) for _ in range(n)])

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

memo = defaultdict(int)

for i in xy:
    for j in xy:
        if np.all(i == j):
            continue
        else:
            tmp = j - i
            if tmp[0] < 0:
                tmp *= -1
            elif tmp[0] == 0 and tmp[1] < 0:
                tmp *= -1
            memo[str(tmp)] += 1

print(n - max(memo.values()) // 2)
Buggy python submission (verdict: Runtime Error):
import numpy as np
from math import factorial
import math, sys

N, M = map(int, input().split())
A = [None]*M

for i in range(M):
    A[i] = int(input())

tmp = 0
x = []

for i, a in enumerate(A):
    x.append(a-tmp-1)
    tmp = a + 1

x.append(N - tmp)
    
x = np.array(x)
if x[1:].min()<1:
    print(0)
    sys.exit()

def calc_combi(a):
    ans = 0
    for i in range(int(a/2)+1):
        tmp_n = math.ceil(a/2)+i
        tmp_r = a - tmp_n
        ans += factorial(tmp_n) // factorial(max(tmp_r, tmp_n - tmp_r))                        
    return ans

memo =  list(map(lambda x: calc_combi(x), x))

ans = 1
for m in memo:
    ans = ans * m % 1000000007

print(ans)

Fixed submission:
N, M = map(int, input().split())
A = [None]*M

is_broken = [False] * (N+1)

for i in range(M):
    A[i] = int(input())
    is_broken[A[i]] = True

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

for i in range(1, N+1):
    if is_broken[i]:
        continue
    dp[i]  = (dp[i-1] + dp[i-2]) % (10**9 + 7)

print(dp[-1])

Buggy python submission (verdict: Runtime Error):
import numpy as np
from math import factorial
import math, sys

N, M = map(int, input().split())
A = [None]*M

for i in range(M):
    A[i] = int(input())

tmp = 0
x = []

for i, a in enumerate(A):
    x.append(a-tmp-1)
    tmp = a + 1

x.append(N - tmp)
    
x = np.array(x)
if x[1:].min()<1:
    print(0)
    sys.exit()

def calc_combi(a):
    ans = 0
    for i in range(int(a/2)+1):
        tmp_n = math.ceil(a/2)+i
        tmp_r = a - tmp_n
        ans += factorial(tmp_n) // factorial(max(tmp_r, tmp_n - tmp_r))                        
    return ans

memo =  list(map(lambda x: calc_combi(x), x))

ans = 1
for m in memo:
    ans = ans * m % 1000000007

Fixed submission:
N, M = map(int, input().split())
A = [None]*M

is_broken = [False] * (N+1)

for i in range(M):
    A[i] = int(input())
    is_broken[A[i]] = True

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

for i in range(1, N+1):
    if is_broken[i]:
        continue
    dp[i]  = (dp[i-1] + dp[i-2]) % (10**9 + 7)

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
import numpy as np
from itertools import product

N, M = map(int, input().split())
switch = []

for i in range(M):
    switch.append(list(map(int, input().split()))[1:])

# 剰余がこうなれば正解
p = list(map(int, input().split()))

# スイッチの状態の組み合わせを全列挙
st = list(product([0,1],repeat=N))

ans = 0

for i, s in enumerate(st):
    tmp = []
    for sw in switch:
        on = 0
        for x in sw:
            on += s[x-1]
        if (on%2)==p[m]:
            tmp.append(True)
        else:
            tmp.append(False)
    if all(tmp)==True:
        ans += 1

print(ans)

Fixed submission:
import numpy as np
from itertools import product

N, M = map(int, input().split())
switch = []

for i in range(M):
    switch.append(list(map(int, input().split()))[1:])

p = list(map(int, input().split()))

st = list(product([0,1],repeat=N))

ans = 0

for i, s in enumerate(st):
    tmp = []
    for j, sw in enumerate(switch):
        on = 0
        for x in sw:
            on += s[x-1]
        if (on%2)==p[j]:
            tmp.append(True)
        else:
            tmp.append(False)
    if all(tmp)==True:
        ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
LR = [None]*M

for i in range(M):
    l, r = map(int, input().split())
    if i==0:
        ans = set(range(l, r+1))
    else:
        ans = ans & set(range(l, r+1))

print(min(len(ans), N))

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

for i in range(M):
    l, r = map(int, input().split())
    
    if i==0:
        left = l
        right = r

    else:
        if l>left:
            left = l
        if r<right:
            right = r

print(0) if left>right else print(right-left+1)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
LR = []

for i in range(M):
    l, r = map(int, input().split())
    LR.append(set(range(l, r+1)))

ans = LR[0]

for i in range(1, M):
    ans = ans & LR[i]

print(min(len(ans), N))

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

for i in range(M):
    l, r = map(int, input().split())
    
    if i==0:
        left = l
        right = r

    else:
        if l>left:
            left = l
        if r<right:
            right = r

print(0) if left>right else print(right-left+1)
Buggy python submission (verdict: Runtime Error):
n = int(input())

ans = 0
last_a = 0
first_b = 0
cnt = 0

for i in range(n):
    s = input()
    ans += s.count("AB")
    if s[-1] == "A":
        last_a += 1
    if s[0] == "B":
        first_b += 1
    if s[-1] == "A" and s[0] == "B":
        cnt += 1

if last_a == last_b:
    ans += min(last_a, last_b) - 1
else:
    ans += min(last_a, last_b)

print(ans)

Fixed submission:
n = int(input())

ans = 0
last_a = 0
first_b = 0
cnt = 0

for i in range(n):
    s = input()
    ans += s.count("AB")
    if s[-1] == "A":
        last_a += 1
    if s[0] == "B":
        first_b += 1
    if s[-1] == "A" and s[0] == "B":
        cnt += 1

if last_a == first_b & cnt > 0:
    ans += min(last_a, first_b) - 1
else:
    ans += min(last_a, first_b)

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


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


# 約数から1引いたものが候補
arr = make_divisors(n)
arr = [x - 1 for x in arr]

#　商と剰余が不一致ならbreakできる
ans = 0
for x in arr[::-1]:
    if n // x != n % x:
        break
    ans += x

print(ans)

Fixed submission:
n = int(input())


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def is_favorite(n, m):
    if x == 0:
        return False
    else:
        return n // m == n % m


li = make_divisors(n)
li = [x - 1 for x in li]


ans = 0
for x in li:
    if is_favorite(n, x):
        ans += x

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
n = int(input())
s = list(map(str, input().rstrip()))

if s.count("#") == 0 or s.count(".") == 0:
    print(0)
    sys.exit()

s = np.array([x == "#" for x in s])

dp = np.zeros([2, n], dtype=int)

# dp0は黒の数、dp0は白の数
dp[0] = s
dp[1] = ~s

dp = dp.cumsum(axis=1)

# 白の数は「それ以降の」と読み替える
dp[1] = dp[1].max() - dp[1]

print((min(dp[0] + dp[1]).min(), s.count("#"), s.count("."))

Fixed submission:
import sys
import numpy as np
n = int(input())
s = list(map(str, input().rstrip()))

ss = s.count("#")
sd = s.count(".")

if ss == 0 or sd == 0:
    print(0)
    sys.exit()

s = np.array([x == "#" for x in s])

dp = np.zeros([2, n], dtype=int)

# dp0は黒の数、dp0は白の数
dp[0] = s
dp[1] = ~s

dp = dp.cumsum(axis=1)

# 白の数は「それ以降の」と読み替える
dp[1] = dp[1].max() - dp[1]

print(min((dp[0] + dp[1]).min(), ss, sd))
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
n, k = map(int, input().split())
s = input()

compressed = []

first = s[0]
prev = s[0]
cnt = 1
for x in s[1:]:
    if prev == x:
        cnt += 1
    else:
        if x == "1":
            compressed.append(cnt)
            cnt = 1
        else:
            compressed.append(cnt)
            cnt = 1
    prev = x
compressed.append(cnt)


result = [0] + list(accumulate(compressed))

ans = []
if first == "1":
    for i in range(0, (len(s) - 2 * k) // 2, 2):
        ans.append(result[i + 2 * k + 1] - result[i])
    for i in range(1, (len(s) - 2 * k) // 2, 2):
        ans.append(result[i + 2 * k] - result[i])
else:
    for i in range(0, (len(s) - 2 * k) // 2, 2):
        ans.append(result[i + 2 * k] - result[i])
    for i in range(1, (len(s) - 2 * k) // 2, 2):
        ans.append(result[i + 2 * k + 1] - result[i])

print(max(ans))

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
s = input() + "_"

compressed = []

first = s[0]
prev = s[0]
cnt = 1
for x in s[1:]:
    if prev == x:
        cnt += 1
    else:
        if x == "1":
            compressed.append(cnt)
            cnt = 1
        else:
            compressed.append(cnt)
            cnt = 1
    prev = x


result = [0] + list(accumulate(compressed))

ans = []
if first == "1":
    for i in range(0, len(result), 2):
        ans.append(result[min(i + k * 2 + 1, len(result) - 1)] - result[i])
    for j in range(1, len(result), 2):
        ans.append(result[min(j + k * 2, len(result) - 1)] - result[j])
else:
    for i in range(0, len(result), 2):
        ans.append(result[min(i + k * 2, len(result) - 1)] - result[i])
    for j in range(1, len(result), 2):
        ans.append(result[min(j + k * 2 + 1, len(result) - 1)] - result[j])

print(max(ans))
Buggy python submission (verdict: Runtime Error):
import numpy as np
A, B, C, D, E = [int(input()) for i in range(5)]

x = np.array([A, B, C, D, E])
ans = int((np.ceil((x / 10)) * 10).sum())
x = x %10
tmp = 10 - x[np.where(x>0)].min()
ans = ans - tmp

print(ans)

Fixed submission:
import numpy as np
A, B, C, D, E = [int(input()) for i in range(5)]

x = np.array([A, B, C, D, E])
ans = int((np.ceil((x / 10)) * 10).sum())
x = x %10

if x.sum()==0:
    tmp = 0
else:
    tmp = 10 - x[np.where(x>0)].min()

ans = ans - tmp

print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
A, B, C, D, E = [int(input()) for i in range(5)]

x = np.array([A, B, C, D, E])
ans = x.round(-1).sum()
x = x %10
tmp = 10 - x[np.where(x>0)].min()
ans = ans - tmp

print(ans)

Fixed submission:
import numpy as np
A, B, C, D, E = [int(input()) for i in range(5)]

x = np.array([A, B, C, D, E])
ans = int((np.ceil((x / 10)) * 10).sum())
x = x %10

if x.sum()==0:
    tmp = 0
else:
    tmp = 10 - x[np.where(x>0)].min()

ans = ans - tmp

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()

ans = []

for i in range(q):
    l, r = map(int, input().split())
    S = s[l - 1:r]
    ans.append(S.count("AC"))

print(*ans, sep="\n")

Fixed submission:
import numpy as np
n, q = map(int, input().split())
s = input()
ans = np.zeros(n, dtype=int)

for i in range(1, n):
    if s[i - 1:i + 1] == "AC":
        ans[i] = 1

ans = ans.cumsum()

result = []

for i in range(q):
    l, r = map(int, input().split())
    result.append(ans[r - 1] - ans[l - 1])

print(*result, sep="\n")

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = input()

ans = []

for i in range(q):
    l, r = map(int, input().split())
    S = s[l - 1:r]
    print(S)
    ans.append(S.count("AC"))

print(*ans, sep="\n")

Fixed submission:
import numpy as np
n, q = map(int, input().split())
s = input()
ans = np.zeros(n, dtype=int)

for i in range(1, n):
    if s[i - 1:i + 1] == "AC":
        ans[i] = 1

ans = ans.cumsum()

result = []

for i in range(q):
    l, r = map(int, input().split())
    result.append(ans[r - 1] - ans[l - 1])

print(*result, sep="\n")
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
s = list(map(str, input().rstrip()))

whole = 2**n - 1


c = Counter(s)

nCr = {}


def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
    return nCr[(n, r)]


c = [x for x in list(c.values()) if x >= 2]

ans = []
for i in c:
    for j in range(2, i + 1):
        if n - i >= 2:
            ans.append(cmb(i, j) * 2**(n - i) - 1)
        else:
            ans.append(cmb(i, j) * 2**(n - i))

print(whole - sum(ans))

Fixed submission:
from collections import Counter

n = int(input())
s = list(map(str, input().rstrip()))

c = Counter(s)

dp = 1
for x in c.values():
    dp = dp * (x + 1)

dp = (dp - 1) % (10 ** 9 + 7)

print(dp)
Buggy python submission (verdict: Runtime Error):
def solve(x):
    # 0123の周期でXORはリセットされるため剰余だけ考える
    if x % 4 == 3:
        return 0
    elif x % 4 == 0:
        return x
    elif x % 4 == 1:
        return x ^ (x　-　1)
    elif x % 4 == 2:
        return x ^ (x　-　1) ^ (x　-　2)


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


print(solve(a - 1) ^ solve(b))

Fixed submission:
# 0123の周期でXORはリセットされるため剰余だけ考える
def solve(x):
    if x % 4 == 3:
        return 0
    elif x % 4 == 0:
        return x
    elif x % 4 == 1:
        return x ^ (x - 1)
    elif x % 4 == 2:
        return x ^ (x - 1) ^ (x - 2)


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


print(solve(a - 1) ^ solve(b))
Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


a = set(make_divisors(a))
b = set(make_divisors(b))

ans = list(a & b)

print(ans[1])

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

cnt = 0
for i in range(min(a, b), 0, -1):
    if a % i == 0 and b % i == 0:
        cnt += 1
    if cnt == k:
        break

print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(n)]

# 最大化問題なので0で初期化
dp = [[0] * (w + 1) for _ in range(n + 1)]

# 品物iを選ばない場合で更新してから、選べる場合は再更新
for i in range(1, n + 1):
    for j in range(w + 1):
        dp[i][j] = dp[i - 1][j]
        if j - arr[i - 1][0] >= 0:
            dp[i][j] = max(dp[i][j], dp[i - 1][j - arr[i - 1][0]] + arr[i - 1][1])

print(dp[n][w])

Fixed submission:
n, w = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(n)]

# 最大化問題なので0で初期化
dp = [[0] * (w + 1) for _ in range(n + 1)]

# 品物iを選ばない場合で更新してから、選べる場合は再更新
for i in range(1, n + 1):
    for j in range(w + 1):
        dp[i][j] = dp[i - 1][j]
        if j - arr[i - 1][0] >= 0:
            dp[i][j] = max(dp[i][j], dp[i - 1][j - arr[i - 1][0]] + arr[i - 1][1])

print(dp[n][w])

Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(n)]

# 最大化問題なので0で初期化
dp = [[0] * (w + 1) for _ in range(n + 1)]

# 品物iを選べる場合、前の行からsum_wから品物iの重さを引いた要素を参照する
for i in range(1, n + 1):
    for j in range(1, w + 1):
        if j - arr[i - 1][0] >= 0:
            dp[i][j] = max(dp[i][j], dp[i - 1][j - arr[i - 1][0]] + arr[i - 1][1])
        else:
            dp[i][j] = dp[i - 1][j]

print(max(max(dp)))

Fixed submission:
n, w = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(n)]

# 最大化問題なので0で初期化
dp = [[0] * (w + 1) for _ in range(n + 1)]

# 品物iを選ばない場合で更新してから、選べる場合は再更新
for i in range(1, n + 1):
    for j in range(w + 1):
        dp[i][j] = dp[i - 1][j]
        if j - arr[i - 1][0] >= 0:
            dp[i][j] = max(dp[i][j], dp[i - 1][j - arr[i - 1][0]] + arr[i - 1][1])

print(dp[n][w])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]

MAX_V = sum(x[1] for x in wv)

INF = 1 << 60
dp = [0] + [INF] * MAX_V

for w, v in wv:
    # 退避
    dp_tmp = dp[:]
    for j in range(1, MAX_V + 1):
        prev = max(0, j - v)
        dp_tmp[j] = min(dp[j], dp[prev] + w)
    dp = dp_tmp


print(bisect.bisect_right(dp, W) - 1)

Fixed submission:
import numpy as np

N, W = map(int, input().split())
MAX_V = (10**3) * N + 1
INF = 1 << 60

dp = np.full(MAX_V, INF)
dp[0] = 0

for i in range(N):
    w, v = map(int, input().split())
    np.minimum(dp[v:], dp[:-v] + w, out=dp[v:])

print(np.where(dp <= W)[0].max())

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

# 入力部分
n, limit = map(int, input().split())
w, v = [], []
for i in range(n):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

# dpテーブルの要素数
V = sum(v)

INF = 1 << 60

dp = [[INF] * (V + 1) for _ in range(n + 1)]
dp[0][0] = 0

for i in range(n):
    for j in range(V + 1):
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
        if j - v[i] >= 0:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i])

dp = np.array(dp)

ans = 0
for arr in dp:
    ans = max(ans, np.where(arr <= limit)[0].max())

print(ans)

Fixed submission:
import numpy as np

N, W = map(int, input().split())
MAX_V = (10**3) * N + 1
INF = 1 << 60

dp = np.full(MAX_V, INF)
dp[0] = 0

for i in range(N):
    w, v = map(int, input().split())
    np.minimum(dp[v:], dp[:-v] + w, out=dp[v:])

print(np.where(dp <= W)[0].max())
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]

# 数え上げ
for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        else:
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])

# 経路復元
ans = ""
i, j = len(s), len(t)

while i > 0 and j > 0:
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j - 1]:
        j -= 1
    else:
        ans = s[i - 1] + ans
        i -= 1
        j -= 1

print(ans)

Fixed submission:
s = input()
t = input()

dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]

# 数え上げ
for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        else:
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])

# 経路復元
ans = ""
i, j = len(s), len(t)

while i > 0 and j > 0:
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j - 1]:
        j -= 1
    else:
        ans = s[i - 1] + ans
        i -= 1
        j -= 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
arr = list(map(float, input().split()))

dp = np.array([[0.0] * (n + 1) for _ in range(n + 1)])

dp[0, 0] = 1.0

for i in range(n):
    for j in range(i + 1):
        dp[i + 1, j + 1] += dp[i, j] * arr[i]
        dp[i + 1, j] += dp[i, j] * (1 - arr[i])

print(dp[-1, -(n + 1)//2:].sum())

Fixed submission:
n = int(input())
arr = list(map(float, input().split()))

dp = [[0.0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1.0

for i in range(n):
    for j in range(i + 1):
        dp[i + 1][j + 1] += dp[i][j] * arr[i]
        dp[i + 1][j] += dp[i][j] * (1 - arr[i])

dp = dp[-1]

print(sum(dp[-(n + 1) // 2:]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
arr = list(map(float, input().split()))

dp = np.array([[0.0] * (n + 1) for _ in range(n + 1)])

dp[0, 0] = 1.0

for i in range(n):
    for j in range(i + 1):
        dp[i + 1, j + 1] += dp[i, j] * arr[i]
        dp[i + 1, j] += dp[i, j] * (1 - arr[i])

print(dp[-1, -(n + 1)//2:].sum())

Fixed submission:
n = int(input())
arr = list(map(float, input().split()))

dp = [[0.0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1.0

for i in range(n):
    for j in range(i + 1):
        dp[i + 1][j + 1] += dp[i][j] * arr[i]
        dp[i + 1][j] += dp[i][j] * (1 - arr[i])

dp = dp[-1]

print(sum(dp[-(n + 1) // 2:]))
Buggy python submission (verdict: Runtime Error):
from functools import lru_cache
import numpy as np
S = np.array(list(map(str, input().rstrip())))

S[np.where(S=="W")] = 1
S[np.where(S=="B")] = 0
S = S.astype(int)

@lru_cache(maxsize=None)
def sum_n(n):
    if n<=1:
        return 1
    return (sum_n(n-1) + n)

goal = sum_n(S.sum())

now = (np.where(S==1)[0]+1).sum()

print(now - goal)

Fixed submission:
import numpy as np
S = np.array(list(map(str, input().rstrip())))

S[np.where(S=="W")] = 1
S[np.where(S=="B")] = 0
S = S.astype(int)
now = np.where(S==1)[0]
goal = np.arange(now.shape[0])

print((now - goal).sum())
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

N = int(input())
V = [3, 5, 7]

li = []


def rec(curr, use):
    if curr > N:
        return cnt
    if use == 0b111:
        li.append(curr)
    for i, b in enumerate(V):
        rec(curr * 10 + b, use | max(1, i * 2))


rec(0, 0)

print(len(li))

Fixed submission:
def is_753(n):
    n = str(n)
    return(n.count("7") >= 1 and n.count("3") >= 1 and n.count("5") >= 1)


n = int(input())


v = [7, 5, 3]
li = []
prev = [7, 5, 3]

for i in range(9):
    tmp = []
    for j in v:
        for k in prev:
            tmp.append(k * 10 + j)
    prev = tmp
    li = li + prev

li = [x for x in li if is_753(x) and x <= n]

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

if n == 1:
    print("Hello World")
else:
    a, b = map(int, input().split())
    print(a + b)

Fixed submission:
n = int(input())

if n == 1:
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a + b)
Buggy python submission (verdict: Runtime Error):
import sys

n = int(input())
xyh = [list(map(int, input().split())) for _ in range(n)]
xyh.sort(key=lambda x: x[2], reverse=True)

for cx in range(101):
    for cy in range(101):
        x, y, h = xyh[0]
        tmp_h = abs(cy - y) + abs(cx - x) + h
        H = np.zeros(n, dtype=np.bool)
        for i, a in enumerate(xyh):
            H[i] = a[2] == max(tmp_h - abs(cx - a[0]) - abs(cy - a[1]), 0)
        if np.all(H):
            print(cx, cy, tmp_h)
            sys.exit()

Fixed submission:
import sys
import numpy as np

n = int(input())
xyh = [list(map(int, input().split())) for _ in range(n)]
xyh.sort(key=lambda x: x[2], reverse=True)

for cx in range(101):
    for cy in range(101):
        x, y, h = xyh[0]
        tmp_h = abs(cy - y) + abs(cx - x) + h
        H = np.zeros(n, dtype=np.bool)
        for i, a in enumerate(xyh):
            H[i] = a[2] == max(tmp_h - abs(cx - a[0]) - abs(cy - a[1]), 0)
        if np.all(H):
            print(cx, cy, tmp_h)
            sys.exit()
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

v1 = v[0::2]
v2 = v[1::2]

c1 = Counter(v1)
c2 = Counter(v2)

c1 = c1.most_common()
c2 = c2.most_common()

if c1[0][0] != c2[0][0]:
    ans = n - c1[0][1] - c2[0][1]
elif c1[0][1] + c2[1][1] >= c2[0][1] + c1[1][1]:
    ans = n - c1[0][1] - c2[1][1]
else:
    ans = n - c2[0][1] - c1[1][1]

print(ans)

Fixed submission:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

v1 = v[0::2]
v2 = v[1::2]

c1 = Counter(v1)
c2 = Counter(v2)

c1 = c1.most_common()
c2 = c2.most_common()

if c1[0][0] != c2[0][0]:
    ans = n - c1[0][1] - c2[0][1]
else:
    if len(c2) > 1:
        choice_1 = c1[0][1] + c2[1][1]
    else:
        choice_1 = c1[0][1]
    if len(c1) > 1:
        choice_2 = c2[0][1] + c1[1][1]
    else:
        choice_2 = c2[0][1]
    ans = n - (max(choice_1, choice_2))

print(ans)