Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def solve(n, k, aaa):
    buf = []
    prev_last = -1

    for t in range(k + 1):
        ma, mi = min((a, i + 1) for i, a in enumerate(aaa) if i + 1 != prev_last)
        others = set(range(1, n + 1)) - {prev_last, mi}
        buf.extend(others)
        if t == k:
            aaa[mi] += 1
        else:
            buf.append(mi)

        for i in range(n):
            if i + 1 != prev_last:
                aaa[i] -= 1
                if aaa[i] < 0:
                    print(-1)
                    return

        prev_last = mi

    print(len(buf))
    print(*buf)


n, k = map(int, input().split())
aaa = list(map(int, input().split()))
solve(n, k, aaa)


Fixed submission:
def solve(n, k, aaa):
    buf = []
    prev_last = -1

    for t in range(k + 1):
        ma, mi = min((a, i + 1) for i, a in enumerate(aaa) if i + 1 != prev_last)
        others = set(range(1, n + 1)) - {prev_last, mi}
        buf.extend(others)
        buf.append(mi)
        # print(buf)

        for i in range(n):
            if i + 1 != prev_last:
                aaa[i] -= 1
                if aaa[i] < 0:
                    print(-1)
                    return

        prev_last = mi

    print(len(buf))
    print(*buf)


n, k = map(int, input().split())
aaa = list(map(int, input().split()))
solve(n, k, aaa)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate

n, k = list(map(int, input().split()))
aaa = list(map(int, input().split()))
bk = '{:041b}'.format(k)
bbb = list(map('{:041b}'.format, aaa))
ans = 0
ks = 0
for ks, c in enumerate(bk):
    if c == '1':
        break
    d = 1 << (40 - ks)
    ans += list(b[ks] for b in bbb).count('1') * d
ideal = 0
best = []
thr = []
base = []
for i, c in enumerate(bk[ks:], start=ks):
    d = 1 << (40 - i)
    c1 = list(b[i] for b in bbb).count('1')
    d0, d1 = c1 * d, (n - c1) * d
    if d0 < d1:
        ideal += d
        best.append(d1)
    else:
        best.append(d0)
    thr.append(d0 if c == '0' else d1)
    base.append(d0)

if ideal <= k:
    print(ans + sum(best))
    exit()

best = list(accumulate(best))
thr = list(accumulate(thr))
sb = best[-1]
best.append(sb)

ans2 = sum(base)
for i, c in enumerate(bk):
    if c == '0':
        continue
    ans2 = max(ans2, thr[i - 1] + base[i] + sb - best[i])

print(ans + ans2)


Fixed submission:
from itertools import accumulate

n, k = list(map(int, input().split()))
aaa = list(map(int, input().split()))
bk = '{:041b}'.format(k)
bbb = list(map('{:041b}'.format, aaa))
ks = 0
best = []
thr = []
base = []
for i, c in enumerate(bk):
    d = 1 << (40 - i)
    c1 = list(b[i] for b in bbb).count('1')
    d0, d1 = c1 * d, (n - c1) * d
    best.append(max(d0, d1))
    thr.append(d0 if c == '0' else d1)
    base.append(d0)

best.reverse()
best = list(accumulate(best))
best.reverse()
best.append(0)
thr = list(accumulate(thr))

ans = thr[-1]
for i, c in enumerate(bk):
    if c == '0':
        continue
    ans = max(ans, thr[i - 1] + base[i] + best[i + 1])

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

n, q = list(map(int, input().split()))
aaa = list(map(int, input().split()))
xxx = sorted(((int(line), i) for i, line in enumerate(sys.stdin.readlines())), reverse=True)
total = sum(aaa)
tmp = sum(aaa[n // 2:])
ans = [sum(aaa[-1::-2])] * q
if n % 2 == 0:
    l, r = 1, n // 2
else:
    l, r = 0, n // 2
while l < r:
    al, ar = aaa[l], aaa[r]
    m = (al + ar) // 2
    while xxx[-1][0] <= m:
        x, i = xxx.pop()
        ans[i] = tmp
    tmp += al - ar
    l += 2
    r += 1
print('\n'.join(map(str, ans)))


Fixed submission:
import sys

n, q = list(map(int, input().split()))
aaa = list(map(int, input().split()))
xxx = sorted(((int(line), i) for i, line in enumerate(sys.stdin.readlines())), reverse=True)
total = sum(aaa)
tmp = sum(aaa[n // 2:])
ans = [sum(aaa[-1::-2])] * q
if n % 2 == 0:
    l, r = 1, n // 2
else:
    l, r = 0, n // 2
while l < r:
    al, ar = aaa[l], aaa[r]
    m = (al + ar) // 2
    while xxx and xxx[-1][0] <= m:
        x, i = xxx.pop()
        ans[i] = tmp
    if not xxx:
        break
    tmp += al - ar
    l += 2
    r += 1
print('\n'.join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
dp = [0]
lcs = ['']
for b in t:
    search_idx = 0
    ncs = lcs.copy()
    for i, curr_idx in enumerate(dp):
        char_idx = s.find(b, search_idx)
        if char_idx == -1:
            break
        next_idx = char_idx + 1
        if next_idx < curr_idx:
            dp[i] = next_idx
            ncs[i] = lcs[i - 1] + b
        search_idx = curr_idx
    else:
        char_idx = s.find(b, search_idx)
        if char_idx > -1:
            dp.append(char_idx + 1)
            ncs.append(lcs[-1] + b)
    lcs = ncs
print(lcs[-1])


Fixed submission:
s = input()
t = input()
dp = [0]
lcs = ['']
for b in t:
    search_idx = 0
    ncs = lcs[:]
    for i, curr_idx in enumerate(dp):
        char_idx = s.find(b, search_idx)
        if char_idx == -1:
            break
        next_idx = char_idx + 1
        if next_idx < curr_idx:
            dp[i] = next_idx
            ncs[i] = lcs[i - 1] + b
        search_idx = curr_idx
    else:
        char_idx = s.find(b, search_idx)
        if char_idx > -1:
            dp.append(char_idx + 1)
            ncs.append(lcs[-1] + b)
    lcs = ncs
print(lcs[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
aaa = list(map(int, input().split()))
dp = [[[0, 0] for _ in range(n + 1)] for _ in range(n + 1)]
for w in range(1, n + 1):
    for l in range(n - w + 1):
        r = l + w
        # take left
        dpl = dp[l + 1][r]
        tl_x = aaa[l] + dpl[1]
        tl_y = dpl[0]
        tl_score = tl_x - tl_y
        # take_right
        dpr = dp[l][r - 1]
        tr_x = aaa[r - 1] + dpr[1]
        tr_y = dpr[0]
        tr_score = tr_x - tr_y
        dpc = dp[l][r]
        if tl_score > tr_score:
            dpc[0] = tl_x
            dpc[1] = tl_y
        else:
            dpc[0] = tr_x
            dpc[1] = tr_y
print(dp[0][n][0] - dp[0][n][1])


Fixed submission:
n = int(input())
aaa = list(map(int, input().split()))
dp = [[0] * (n + 1) for _ in range(n + 1)]
for w in range(1, n + 1):
    for l in range(n - w + 1):
        r = l + w
        dpl = -dp[l + 1][r] + aaa[l]
        dpr = -dp[l][r - 1] + aaa[r - 1]
        dp[l][r] = max(dpl, dpr)
print(dp[0][n])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
aaa = list(map(int, input().split()))
dp = [[0] * (n + 1) for _ in range(n)]
for i, a in enumerate(aaa):
    dp[i][i + 1] = (a, 0)
for w in range(2, n + 1):
    for l in range(n - w + 1):
        r = l + w
        # take left
        dpl, dpr = dp[l + 1][r]
        tl_x = aaa[l] + dpr
        tl_y = dpl
        tl_score = tl_x - tl_y
        # take_right
        dpl, dpr = dp[l][r - 1]
        tr_x = aaa[r - 1] + dpr
        tr_y = dpl
        tr_score = tr_x - tr_y
        if tl_score > tr_score:
            dp[l][r] = (tl_x, tl_y)
        else:
            dp[l][r] = (tr_x, tr_y)
print(dp[0][n][0] - dp[0][n][1])


Fixed submission:
n = int(input())
aaa = list(map(int, input().split()))
dp = [[0] * (n + 1) for _ in range(n + 1)]
for w in range(1, n + 1):
    for l in range(n - w + 1):
        r = l + w
        dpl = -dp[l + 1][r] + aaa[l]
        dpr = -dp[l][r - 1] + aaa[r - 1]
        dp[l][r] = max(dpl, dpr)
print(dp[0][n])
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate

n = int(input())
aaa = list(map(int, input().split()))
acc = [0] + list(accumulate(aaa))
dp = [[0] * (n + 1) for _ in range(n)]
for l, aa in enumerate(zip(aaa, aaa[1:])):
    dp[l][l + 2] = sum(aa)
for w in range(3, n + 1):
    for l in range(n - w + 1):
        r = l + w
        c = acc[r] - acc[l]
        dp[l][r] = min(dp[l][m] + dp[m][r] + c for m in range(l + 1, r))
print(dp[0][n])


Fixed submission:
from itertools import accumulate

n = int(input())
aaa = list(map(int, input().split()))
acc = [0] + list(accumulate(aaa))
dp = [[0] * (n + 1) for _ in range(n)]
for l, aa in enumerate(zip(aaa, aaa[1:])):
    dp[l][l + 2] = sum(aa)
for w in range(3, n + 1):
    for l in range(n - w + 1):
        r = l + w
        c = acc[r] - acc[l]
        dp[l][r] = min(dp[l][m] + dp[m][r] + c for m in range(l + 1, r))
print(dp[0][n])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

n = int(input())
dp = {0: 1}
MOD = 10 ** 9 + 7
for i in range(n):
    compatibilities = [1 << i for i, v in enumerate(input().split()) if v == '1']
    ndp = defaultdict(lambda: 0)
    for k, p in dp.items():
        for c in compatibilities:
            if k & c:
                continue
            ndp[k | c] += p
            ndp[k | c] %= MOD
    dp = ndp
    # print(i, len(dp))
print(sum(dp.values()) % MOD)


Fixed submission:
n = int(input())
dp = [0] * (1 << n)
dp[0] = 1
curr = {0}
MOD = 10 ** 9 + 7
for i in range(n):
    compatibilities = [1 << i for i, v in enumerate(input().split()) if v == '1']
    nxt = set()
    for k in curr:
        p = dp[k] % MOD
        for c in compatibilities:
            if k & c:
                continue
            dp[k | c] += p
            nxt.add(k | c)
    curr = nxt
print(dp[(1 << n) - 1] % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

n = int(input())
blocks = []
for line in sys.stdin.readlines():
    w, s, v = map(int, line.split())
    blocks.append((w + s, w, s, v))
blocks.sort()

dp = [-1] * 20001
dp[0] = 0
for _, w, s, v in blocks:
    for i in range(min(s, 20000 - w), -1, -1):
        dp[i + w] = max(dp[i + w], dp[i] + v)
print(max(dp))


Fixed submission:
import sys

n = int(input())
blocks = []
for line in sys.stdin.readlines():
    w, s, v = map(int, line.split())
    blocks.append((w + s, w, s, v))
blocks.sort()

dp = [-1] * 20001
dp[0] = 0
for _, w, s, v in blocks:
    for i in range(min(s, 20000 - w), -1, -1):
        dp[i + w] = max(dp[i + w], dp[i] + v)
print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
import sys


def prepare(n):
    fact = [1] * (n + 1)
    for i in range(1, n + 1):
        fact[i] = fact[i - 1] * i % MOD
    inv = [1] * (n + 1)
    inv[n] = pow(fact[n], MOD - 2, MOD)
    for i in range(n - 1, 0, -1):
        inv[i] = inv[i + 1] * (i + 1) % MOD
    return fact, inv


MOD = 10 ** 9 + 7
h, w, n = map(int, input().split())
walls = [tuple(map(int, line.split())) for line in sys.stdin.readlines()]
walls.append((1, 1))
walls.append((h, w))
walls.sort()
fact, inv = prepare(h + w)
dp = [1]
for i, (cy, cx) in enumerate(walls[1:], start=1):
    res = 0
    for j, (py, px) in enumerate(walls[:i]):
        if cx < px:
            continue
        dy, dx = cy - py, cx - px
        res -= dp[j] * fact[dy + dx] % MOD * inv[dy] % MOD * inv[dx] % MOD
        res %= MOD
    dp.append(res)
print(-dp[-1] % MOD)


Fixed submission:
import sys


def prepare(n):
    fact = [1] * (n + 1)
    for i in range(1, n + 1):
        fact[i] = fact[i - 1] * i % MOD
    inv = [1] * (n + 1)
    inv[n] = pow(fact[n], MOD - 2, MOD)
    for i in range(n - 1, 0, -1):
        inv[i] = inv[i + 1] * (i + 1) % MOD
    return fact, inv


MOD = 10 ** 9 + 7
h, w, n = map(int, input().split())
walls = [tuple(map(int, line.split())) for line in sys.stdin.readlines()]
walls.append((1, 1))
walls.append((h, w))
walls.sort()
fact, inv = prepare(h + w)
dp = [1]
for i, (cy, cx) in enumerate(walls[1:], start=1):
    res = 0
    for j, (py, px) in enumerate(walls[:i]):
        if cx < px:
            continue
        dy, dx = cy - py, cx - px
        res -= dp[j] * fact[dy + dx] % MOD * inv[dy] % MOD * inv[dx] % MOD
        res %= MOD
    dp.append(res)
print(-dp[-1] % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

n, q = list(map(int, input().split()))
MOD = 10 ** 9 + 7
INV2 = (MOD + 1) // 2
lines = sys.stdin.readlines()
aaa = list(map(int, lines[:n]))
mat = [[0] * n for _ in [0] * n]
for i in range(n):
    for j in range(n):
        mat[i][j] = int(aaa[i] < aaa[j])
# print(*mat, sep='\n')
for line in lines[n:]:
    x, y = map(int, line.split())
    x -= 1
    y -= 1
    mat[x][y] = mat[y][x] = (mat[x][y] + mat[y][x]) * INV2 % MOD
    for i in range(n):
        if i == x or i == y:
            continue
        mat[x][i] = mat[y][i] = (mat[x][i] + mat[y][i]) * INV2 % MOD
        mat[i][x] = mat[i][y] = (mat[i][x] + mat[i][y]) * INV2 % MOD
    # print(x, y)
    # print(*mat, sep='\n')

ans = sum(sum(row[:i]) for i, row in enumerate(mat)) % MOD
ans = (ans << q) % MOD
print(ans)


Fixed submission:
import sys

n, q = list(map(int, input().split()))
MOD = 10 ** 9 + 7
INV2 = (MOD + 1) // 2
lines = sys.stdin.readlines()
aaa = list(map(int, lines[:n]))
mat = [[0] * n for _ in [0] * n]
for i in range(n):
    for j in range(n):
        mat[i][j] = int(aaa[i] < aaa[j])
# print(*mat, sep='\n')
for line in lines[n:]:
    x, y = map(int, line.split())
    x -= 1
    y -= 1
    mat[x][y] = mat[y][x] = (mat[x][y] + mat[y][x]) * INV2 % MOD
    for i in range(n):
        if i == x or i == y:
            continue
        mat[x][i] = mat[y][i] = (mat[x][i] + mat[y][i]) * INV2 % MOD
        mat[i][x] = mat[i][y] = (mat[i][x] + mat[i][y]) * INV2 % MOD
    # print(x, y)
    # print(*mat, sep='\n')

ans = sum(sum(row[:i]) for i, row in enumerate(mat)) % MOD
ans = (ans << q) % MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
from operator import sub

n, k = map(int, input().split())
hhh = sorted(int(input()) for _ in range(n))
print(min(map(sub, zip(hhh[k - 1:], hhh))))


Fixed submission:
n, k = map(int, input().split())
hhh = [int(input()) for _ in range(n)]
hhh.sort()
ans = float('inf')
for i in range(n - k + 1):
    ans = min(ans, hhh[i + k - 1] - hhh[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
ans = 999999
for _ in range(n):
  c, t = map(int, input().split())
  if t > m:
    continue
  ans = min(ans, c)
if ans = 999999:
  print('TLE')
else:
  print(ans)

    

Fixed submission:
n, m = map(int, input().split())
ans = 999999
for _ in range(n):
    c, t = map(int, input().split())
    if t > m:
        continue
    ans = min(ans, c)
if ans == 999999:
    print('TLE')
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
n, s = map(int, input().split())
xxx = [abs(s - y) for y in map(int, input().split())]
d = 0
while True:
    d = min(xxx)
    xxx = [x % d for x in xxx]
    if all(x == 0 for x in xxx):
        break
print(d)


Fixed submission:
n, s = map(int, input().split())
xxx = [abs(s - y) for y in map(int, input().split())]
d = 0
while True:
    xxx = [x for x in xxx if x > 0]
    d = min(xxx)
    xxx = [x % d for x in xxx]
    if all(x == 0 for x in xxx):
        break
print(d)
Buggy python submission (verdict: Runtime Error):
n, aaa = map(int, open(0).split())
print(max(aaa) - min(aaa))

Fixed submission:
n, *aaa = map(int, open(0).read().split())
print(max(aaa) - min(aaa))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
print((n - 2) // (k - 2) + 1)


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

if n == k:
    print(1)
else:
    i = 0
    for i, a in enumerate(map(int, input().split())):
        if a == 1:
            break
    left = (i - 1) // (k - 1) + 1
    lr = (k - 1) * left + 1
    print(left + (n - lr - 1) // (k - 1) + 1)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product


def dfs(links, fixed, s):
    q = [(s, 0)]
    cnt = [0, 0]
    while q:
        v, c = q.pop()
        if fixed[v] > -1:
            if fixed[v] != c:
                return False
            continue
        fixed[v] = c
        cnt[c] += 1
        for u in links[v]:
            q.append((u, c ^ 1))
    return cnt


def is_bipartite(n, links):
    fixed = [-1] * n
    can = []
    for i in range(n):
        if fixed[i] > -1:
            continue
        cnt = dfs(links, fixed, i)
        if cnt == False:
            return -1
        can.append(cnt)
    mx = float('inf')
    for p in product(*can):
        s = sum(p)
        t = n - s
        tmx = max(s, t)
        mx = min(mx, tmx)

    mn = n - mx
    return (mx * (mx - 1) + mn * (mn - 1)) // 2


n, m = map(int, input().split())
links = [set(range(n)) - {i} for i in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    links[a].remove(b)
    links[b].remove(a)
print(is_bipartite(n, links))


Fixed submission:
def dfs(links, fixed, s):
    q = [(s, 0)]
    cnt = [0, 0]
    while q:
        v, c = q.pop()
        if fixed[v] > -1:
            if fixed[v] != c:
                return False
            continue
        fixed[v] = c
        cnt[c] += 1
        for u in links[v]:
            q.append((u, c ^ 1))
    return (max(cnt), min(cnt))


def is_bipartite(n, links):
    fixed = [-1] * n
    l, r = 0, 0
    can = []
    for i in range(n):
        if fixed[i] > -1:
            continue
        cnt = dfs(links, fixed, i)
        if cnt == False:
            return -1
        can.append(cnt)

    can.sort(reverse=True)
    for cnt in can:
        j = 0 if cnt[0] > cnt[1] else 1
        if l > r:
            j ^= 1
        l += cnt[j]
        r += cnt[j ^ 1]
    return (l * (l - 1) + r * (r - 1)) // 2


n, m = map(int, input().split())
links = [set(range(n)) - {i} for i in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    links[a].remove(b)
    links[b].remove(a)
print(is_bipartite(n, links))
Buggy python submission (verdict: Runtime Error):
8
WWWWWEEE


Fixed submission:
from itertools import accumulate

n = int(input())
s = [c == 'W' for c in input()]
l = accumulate([0] + s[:-1])
r = accumulate([0] + [not c for c in reversed(s[1:])])
print(min(e + w for e, w in zip(l, reversed(list(r)))))
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import nsmallest


def add_list(s, t, new_lists, removals):
    l = t - s
    if l >= k:
        removals.extend(nsmallest(l - k + 1, aaa[s:t]))
        new_lists.append((s, t))


n, k, q = map(int, input().split())
aaa = list(map(int, input().split()))
srt = sorted(set(aaa))
lists = [(0, n)]
ans = float('inf')
for a in srt:
    new_lists = []
    removals = []
    for s, t in lists:
        for i, b in enumerate(aaa[s:t]):
            if a > b:
                add_list(s, s + i, new_lists, removals)
                s = s + i + 1
        add_list(s, t, new_lists, removals)
    if len(removals) < q:
        break
    ans = min(ans, nsmallest(q, removals)[-1] - a)
    lists = new_lists

print(ans)


Fixed submission:
def add_list(buf, new_lists, removals):
    l = len(buf)
    if l >= k:
        sbf = sorted(buf)
        removals.extend(sbf[:l - k + 1])
        new_lists.append(buf)


n, k, q = map(int, input().split())
aaa = list(map(int, input().split()))
srt = sorted(aaa)
lists = [aaa]
ans = float('inf')
for a in srt:
    new_lists = []
    removals = []
    for lst in lists:
        buf = []
        for b in lst:
            if a > b:
                add_list(buf, new_lists, removals)
                buf = []
            else:
                buf.append(b)
        add_list(buf, new_lists, removals)
    if len(removals) < q:
        break
    removals.sort()
    ans = min(ans, removals[q - 1] - a)

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ppp = list(map(int, (input() for _ in range(n))))

tmp = [0] * n
for p in ppp:
    tmp[p] = tmp[p - 1] + 1

print(n - max(tmp))


Fixed submission:
n = int(input())
ppp = list(map(int, (input() for _ in range(n))))

tmp_f = {}
for p in ppp:
    if p - 1 in tmp_f:
        tmp_f[p] = tmp_f[p - 1] + 1
    else:
        tmp_f[p] = 1

# tmp_b = {}
# for p in ppp[::-1]:
#     if p + 1 in tmp_b:
#         tmp_b[p] = tmp_b[p + 1] + 1
#     else:
#         tmp_b[p] = 1

cnt = max(tmp_f.values())
print(n - cnt)
Buggy python submission (verdict: Runtime Error):
def solve(field):
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if field[i][j] == '.':
                continue
            if field[i - 1][j] == field[i + 1][j] == field[i][j - 1] == field[i][j + 1] == '.':
                return False
    return True


h, w = list(map(int, input().split()))
field = ['.' + input() + '.' for _ in range(h)]
field = ['.' * w] + field + ['.' * w]
print('Yes' if solve(field) else 'No')


Fixed submission:
def solve(field):
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if field[i][j] == '.':
                continue
            if field[i - 1][j] == field[i + 1][j] == field[i][j - 1] == field[i][j + 1] == '.':
                return False
    return True


h, w = list(map(int, input().split()))
field = ['.' + input() + '.' for _ in range(h)]
field = ['.' * (w + 2)] + field + ['.' * (w + 2)]
print('Yes' if solve(field) else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
s = np.array([list(map(ord, input())) for _ in range(n)])
s = np.hstack((s, s))
s = np.vstack((s, s))
ans = 0
for i in range(n):
    for j in range(n):
        p = s[i:i + n, j:j + n]
        if (p == p.T).all():
            ans += 1

print(ans)


Fixed submission:
import numpy as np

n = int(input())
s = np.array([list(map(ord, input())) for _ in range(n)])
s = np.hstack((s, s))
s = np.vstack((s, s))
ans = 0
for i in range(n):
    p = s[0:n, i:i + n]
    if (p == p.T).all():
        ans += n

print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
l = list(range(a, b + 1))
s = set(l[:k])
s.update(l[-k:])
s = sorted(s)
print('\n'.join(map(str, s)))

Fixed submission:
a, b, k = map(int, input().split())
s = set(range(a, min(b + 1, a + k)))
s.update(range(b, max(a - 1, b - k), -1))
s = sorted(s)
print('\n'.join(map(str, s)))
Buggy python submission (verdict: Runtime Error):
from scipy.sparse.csgraph import floyd_warshall
import numpy as np


def make_graph(m):
    matrix = np.zeros([m + 1, m + 1, m + 1])
    for k in range(1, m + 1):
        for s in range(k, m + 1):
            matrix[k, s, s % k] = 1
    return matrix


def is_disable(matrix, subset, aaa, bbb):
    sub_matrix = matrix[list(subset)].max(axis=0)
    sp = floyd_warshall(sub_matrix)
    return any(sp[a, b] > 50 for a, b in zip(aaa, bbb))


def solve(aaa, bbb):
    for a, b in zip(aaa, bbb):
        if a < b:
            return -1
    m = max(aaa)
    matrix = make_graph(m)
    subset = set(range(1, m + 1))
    if is_disable(matrix, subset, aaa, bbb):
        return -1

    for k in range(m, 0, -1):
        subset.remove(k)
        if is_disable(matrix, subset, aaa, bbb):
            subset.add(k)
    return sum(1 << k for k in subset)


n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
print(solve(aaa, bbb))


Fixed submission:
from scipy.sparse.csgraph import dijkstra


def make_graph(m, subset):
    matrix = [[0] * (m + 1) for _ in range(m + 1)]
    for k in subset:
        for s in range(k, m + 1):
            matrix[s][s % k] = 1
    return dijkstra(matrix)


def solve(n, aaa, bbb):
    for a, b in zip(aaa, bbb):
        if a < b:
            return -1
    m = max(aaa)
    subset = set(range(1, m + 1))
    sp = make_graph(m, subset)
    if any(sp[a, b] > 50 for a, b in zip(aaa, bbb)):
        return -1

    for k in range(m, 0, -1):
        subset.remove(k)
        sp = make_graph(m, subset)
        if any(sp[a, b] > 50 for a, b in zip(aaa, bbb)):
            subset.add(k)
    return sum(1 << k for k in subset)


n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
print(solve(n, aaa, bbb))