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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)

def f(A, N, K):
    A.sort()
    I = (np.abs(A)).argsort()
    A = A[I][::-1]
    if N == K:
        return A
    # 全部負
    if np.all(A < 0):
        if K % 2 == 0:
            return A[:K]
        else:
            return A[-K:]
    # これ以外の場合は、必ず正を実現できる
    pos = A[A >= 0]
    neg = A[A < 0]
    nums = [1]
    if K & 1:
        nums = [pos[0]]
        pos = pos[1:]
        K -= 1
    # K は偶数
    # pos, neg から偶数個ずつセットにする
    pos = pos[::2] * pos[1::2]
    neg = neg[::2] * neg[1::2]
    A = np.concatenate([pos, neg])
    A.sort()
    A = A[::-1]
    return np.concatenate([nums, A[:K // 2]])

MOD = 10**9 + 7
B = f(A, N, K).tolist()
ans = 1
for x in B:
    ans = ans * x % MOD
print(ans)

Fixed submission:
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)

def f(A, N, K):
    A.sort()
    I = (np.abs(A)).argsort()
    A = A[I][::-1]
    if N == K:
        return A
    # 全部負
    if np.all(A < 0):
        if K % 2 == 0:
            return A[:K]
        else:
            return A[-K:]
    # これ以外の場合は、必ず正を実現できる
    pos = A[A >= 0]
    neg = A[A < 0]
    nums = [1]
    if K & 1:
        nums = [pos[0]]
        pos = pos[1:]
        K -= 1
    # K は偶数
    # pos, neg から偶数個ずつセットにする
    if len(pos) & 1:
        pos = pos[:-1]
    if len(neg) & 1:
        neg = neg[:-1]
    pos = pos[::2] * pos[1::2]
    neg = neg[::2] * neg[1::2]
    A = np.concatenate([pos, neg])
    A.sort()
    A = A[::-1]
    return np.concatenate([nums, A[:K // 2]])

MOD = 10**9 + 7
B = f(A, N, K).tolist()
ans = 1
for x in B:
    ans = ans * x % MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import numba

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@numba.njit
def main(N):
    x = 0
    for a in range(1, N+1):
        for b in range(1, N//a+1):
            x += a*b
    return x

from my_module import main

N = int(read())
print(main(N))


Fixed submission:
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def prime_table(N):
    is_prime = np.zeros(N, np.int64)
    is_prime[2:3] = 1
    is_prime[3::2] = 1
    for p in range(3, N, 2):
        if p * p >= N:
            break
        if is_prime[p]:
            is_prime[p * p::p + p] = 0
    return is_prime, np.where(is_prime)[0]

def main(N, primes):
    div = np.ones(N + 1, dtype=np.int64)
    for p in primes:
        for i in range(N // p + 1):
            div[p * i] += div[i]
    div *= np.arange(N + 1)
    return div.sum()

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i8 = numba.int64
    cc = CC('my_module')

    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return numba.njit(f)

    main = cc_export(main, (i8, i8[:]))
    cc.compile()

from my_module import main

N = int(read())
is_prime, primes = prime_table(N + 1)
print(main(N, primes))

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main(N):
    div = np.zeros(N+1, np.int64)
    for n in range(1, N+1):
      div[::n] += 1
    div *= np.arange(N + 1)
    return div.sum()

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i8 = numba.int64
    cc = CC('my_module')

    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return numba.njit(f)

    main = cc_export(main, (i8, ))
    cc.compile()

from my_module import main

N = int(read())
print(main(N))


Fixed submission:
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def prime_table(N):
    is_prime = np.zeros(N, np.int64)
    is_prime[2:3] = 1
    is_prime[3::2] = 1
    for p in range(3, N, 2):
        if p * p >= N:
            break
        if is_prime[p]:
            is_prime[p * p::p + p] = 0
    return is_prime, np.where(is_prime)[0]

def main(N, primes):
    div = np.ones(N + 1, dtype=np.int64)
    for p in primes:
        for i in range(N // p + 1):
            div[p * i] += div[i]
    div *= np.arange(N + 1)
    return div.sum()

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i8 = numba.int64
    cc = CC('my_module')

    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return numba.njit(f)

    main = cc_export(main, (i8, i8[:]))
    cc.compile()

from my_module import main

N = int(read())
is_prime, primes = prime_table(N + 1)
print(main(N, primes))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

U = 10**6 + 10

def prime_table(N):
    is_prime = np.zeros(N, np.int64)
    is_prime[2:3] = 1
    is_prime[3::2] = 1
    for p in range(3, N, 2):
        if p * p >= N:
            break
        if is_prime[p]:
            is_prime[p * p::p + p] = 0
    return is_prime, np.where(is_prime)[0]

def main(A, primes):
    B = np.zeros(U + 1, np.int64)
    for x in A:
        B[x] += 1
    for p in primes:
        for i in range(U // p + 1):
            B[p * i] += B[i]
    ret = 0
    for x in A:
        ret += B[x] == 1
    return ret

A = np.array(read().split(), np.int64)[1:]
_, primes = prime_table(U)

print(main(A, primes))


Fixed submission:
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit('(i4[::1],)', cache=True)
def solve(A):
    count = np.zeros(10**6 + 10, np.int32)
    for x in A:
        if count[x] > 1:
            continue
        count[::x] += 1
    ret = 0
    for x in A:
        ret += count[x] == 1
    return ret

A = np.array(read().split(), np.int32)[1:]

print(solve(A))

Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

U = 10**6 + 10

def main(A, primes):
    B = np.zeros(U + 1, np.int64)
    for x in A:
        B[x] += 1
    for p in primes:
        for i in range(U // p + 1):
            B[p * i] += B[i]
    ret = 0
    for x in A:
        ret += B[x] == 1
    return ret

if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', '(i8[::1],i8[::1])')(main)
    cc.compile()
    exit()
from my_module import main

def prime_table(N):
    is_prime = np.zeros(N, np.int64)
    is_prime[2:3] = 1
    is_prime[3::2] = 1
    for p in range(3, N, 2):
        if p * p >= N:
            break
        if is_prime[p]:
            is_prime[p * p::p + p] = 0
    return is_prime, np.where(is_prime)[0]

A = np.array(read().split(), np.int64)[1:]
_, primes = prime_table(U)

print(solve(A, primes))

Fixed submission:
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit('(i4[::1],)', cache=True)
def solve(A):
    count = np.zeros(10**6 + 10, np.int32)
    for x in A:
        if count[x] > 1:
            continue
        count[::x] += 1
    ret = 0
    for x in A:
        ret += count[x] == 1
    return ret

A = np.array(read().split(), np.int32)[1:]

print(solve(A))
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit('(i4[::1],i4[::1])', cache=True)
def f(S, T):
    m, x, M = 0, 0, 0
    for i in range(len(S)):
        if S[i] == -1:
            x -= 1
        elif S[i] == 1:
            x += 1
        else:
            if x - 1 + T[i] >= m:
                x -= 1
            else:
                x += 1
        m = min(m, x)
        M = max(M, x)
    return M - m

S = np.array(list(read().rstrip().decode()), 'U1')

Si = np.zeros(len(S), np.int32)
Si[S == '0'] = -1
Si[S == '1'] = 1
S = Si

T = S.copy()
T[S == 0] = 1
T = np.cumsum(T)
T = np.minimum.accumulate(T[::-1])[::-1] - T
print(f(S, T))

Fixed submission:
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit('(i8[::1],i8)', cache=True)
def test(S, A):
    def f(L, R):
        if L > R:
            return False
        for x in S:
            if x == 1:
                L, R = L + 1, R + 1
                if R > A:
                    R -= 2
            elif x == -1:
                L, R = L - 1, R - 1
                if L < 0:
                    L += 2
            else:
                L -= 1
                R += 1
                if L < 0:
                    L += 2
                if R > A:
                    R -= 2
            if L > R:
                return False
        return True

    for parity in (0, 1):
        L, R = 0, A
        if parity == 0:
            R -= A & 1
        else:
            L = 1
            R -= 1 - (A & 1)
        if f(L, R):
            return True
    return False

S = np.array(list(read().rstrip().decode()), 'U1')
Si = np.zeros(len(S), np.int64)
Si[S == '0'] = -1
Si[S == '1'] = 1
S = Si

low = 0  # むり
high = len(S) + 10  # おさめられる
while low + 1 < high:
    x = (low + high) // 2
    if test(S, x):
        high = x
    else:
        low = x

print(high)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce
N, *A = map(int, open(0).read().split())
x = reduce(mul, A)
if x > 10 ** 18:
  x = -1
print(x)

Fixed submission:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *A = map(int, read().split())

U = 10 ** 18
p = 1
for x in A:
    p *= x
    if p > U:
        p = U + 1

if p > U:
    print(-1)
else:
    print(p)
Buggy python submission (verdict: Runtime Error):
import sys
from math import exp, pi

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B, H, M = map(int, read().split())

H += M / 60

t1 = 2 * pi * H / 12
t2 = 2 * pi * H

z1 = A * exp(t1 * 1j)
z2 = B * exp(t1 * 1j)

print(abs(z1 - z2))


Fixed submission:
import sys
from math import cos, sin, pi

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B, H, M = map(int, read().split())

H += M / 60

t1 = 2 * pi * H / 12
t2 = 2 * pi * H

z1 = A * complex(cos(t1), sin(t1))
z2 = B * complex(cos(t2), sin(t2))

print(abs(z1 - z2))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import networkx as nx

N, M, S = map(int, readline().split())

edges = []
for _ in range(M):
    u, v, a, b = map(int, readline().split())
    for coin in range(a, 2500):
        edges.append(((u, coin), (v, coin - a), b))
        edges.append(((v, coin), (u, coin - a), b))

for u in range(1, N + 1):
    c, d = map(int, readline().split())
    for coin in range(2500):
        edges.append(((u, coin), (u, min(coin + c, 2499)), d))

if S >= 2500:
    S = 2499


G = nx.DiGraph()
G.add_weighted_edges_from(edges)
path_lengths = nx.single_source_dijkstra_path_length(G, (1, S))

INF = 10 ** 18
answer = [INF] * (N + 1)
for key, L in path_lengths.items():
    u, c = key
    if answer[u] > L:
        answer[u] = L

print(*answer[2:], sep='\n')


Fixed submission:
import sys
from heapq import *
import numpy as np
import numba
from numba import njit
i8 = numba.int64

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((i8, i8, i8[:, :], i8[:]), cache=True)
def main(N, S, G, CD):
    ind = np.searchsorted(G[:, 0], np.arange(N + 1), 'right')
    U = 2600
    C, D = CD[::2], CD[1::2]
    C = np.minimum(C, U)
    S = np.minimum(S, U)
    INF = 10**18
    dist = np.full((N + 1, U + 1), INF, np.int64)
    dist[1, S] = 0
    q = [(0, 1, S)]
    while q:
        d, v, coin = heappop(q)
        if dist[v, coin] < d:
            continue
        for i in range(ind[v - 1], ind[v]):
            w, a, b = G[i, 1:]
            if coin < a:
                continue
            if dist[w, coin - a] <= d + b:
                continue
            dist[w, coin - a] = d + b
            heappush(q, (d + b, w, coin - a))
        c = min(U, coin + C[v - 1])
        if dist[v, c] <= d + D[v - 1]:
            continue
        dist[v, c] = d + D[v - 1]
        heappush(q, (d + D[v - 1], v, c))
    return dist

N, M, S = map(int, readline().split())
nums = np.array(read().split(), np.int64)
UVAB = nums[:4 * M]
CD = nums[4 * M:]

U, V, A, B = UVAB.reshape(-1, 4).T

G = np.empty((M + M, 4), np.int64)
G[:, 0] = np.concatenate((U, V))
G[:, 1] = np.concatenate((V, U))
G[:, 2] = np.concatenate((A, A))
G[:, 3] = np.concatenate((B, B))
G = G[G[:, 0].argsort()]

ans = main(N, S, G, CD)[2:].min(axis=1)
print('\n'.join(map(str, ans.tolist())))
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

K = int(read())

x = np.arange(1, K + 1)
nums = np.gcd.outer(x, x, x)
print(nums.sum())


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

K = int(read())

x = np.arange(1, K + 1)
nums = np.gcd.outer(np.gcd.outer(x, x), x)
print(nums.sum())
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

MOD = 10**9 + 7
N, K = map(int, read().split())

is_prime = np.zeros(K + 1, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, K + 1, 2):
    if p * p >= K:
        break
    if is_prime[p]:
        is_prime[p * p:: p + p] = 0
primes = np.where(is_prime)[0]


A = [0] * (K + 1)
for d in range(1, K + 1):
    A[d] = pow(K // d, N, MOD)

for p in primes.tolist():
    for i in range(K // p + 1):
        A[i] -= A[i * p]

answer = sum(i * x for i, x in enumerate(A))
print(answer % MOD)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9 + 7

N, K = map(int, read().split())

A = [0] * (K + 1)
for d in range(1, K + 1):
    A[d] = pow(K // d, N, MOD)

for d in range(K, 0, -1):
    for i in range(2, K // d + 1):
        A[d] -= A[d * i]

answer = sum(d * x for d, x in enumerate(A))
print(answer % MOD)

Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

MOD = 10**9 + 7
N, K = map(int, read().split())

is_prime = np.zeros(K + 1, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, K + 1, 2):
    if p * p >= K:
        break
    if is_prime[p]:
        is_prime[p * p:: p + p] = 0
primes = np.where(is_prime)[0]


A = [0] * (K + 1)
for d in range(1, K + 1):
    A[d] = pow(K // d, N, MOD)

for p in primes.tolist():
    for i in range(N // p + 1):
        A[i] -= A[i * p]

answer = sum(i * x for i, x in enumerate(A))
print(answer % MOD)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9 + 7

N, K = map(int, read().split())

A = [0] * (K + 1)
for d in range(1, K + 1):
    A[d] = pow(K // d, N, MOD)

for d in range(K, 0, -1):
    for i in range(2, K // d + 1):
        A[d] -= A[d * i]

answer = sum(d * x for d, x in enumerate(A))
print(answer % MOD)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
m = map(int, read().split())
AB = zip(m, m)

MOD = 10 ** 9 + 7

graph = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)

root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

fact = [1] * (N + 10)
for n in range(1, N + 10):
    fact[n] = n * fact[n - 1] % MOD
fact_inv = [1] * (N + 10)
fact_inv[-1] = pow(fact[-1], MOD - 2, MOD)
for n in range(N + 9, 0, -1):
    fact_inv[n - 1] = fact_inv[n] * n % MOD

size_d = [0] * (N + 1)
dp_d = [1] * (N + 1)

for v in order[::-1]:
    dp_d[v] *= fact[size_d[v]]
    dp_d[v] %= MOD
    p = parent[v]
    s = size_d[v] + 1
    size_d[p] += s
    dp_d[p] *= fact_inv[s] * dp_d[v]
    dp_d[p] %= MOD

size_u = [N - 2 - x for x in size_d]
dp_u = [1] * (N + 1)

for v in order[1:]:
    p = parent[v]
    x = dp_d[p]
    x *= dp_u[p]
    x *= fact_inv[size_d[p]]
    x *= fact[size_d[v] + 1]
    x *= pow(dp_d[v], MOD - 2, MOD)
    x *= fact[size_u[v]]
    x *= fact_inv[size_u[p] + 1]
    dp_u[v] = x % MOD

for xd, xu, sd, su in zip(dp_d[1:], dp_u[1:], size_d[1:], size_u[1:]):
    su += 1
    x = xd * xu * fact[sd + su] * fact_inv[sd] * fact_inv[su] % MOD
    print(x)


Fixed submission:
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X, Y, A, B, C = map(int, readline().split())
P = sorted(map(int, readline().split()), reverse=True)
Q = sorted(map(int, readline().split()), reverse=True)
R = sorted(map(int, readline().split()), reverse=True)

P = P[:X]
Q = Q[:Y]
nums = P + Q + R
nums.sort(reverse=True)
answer = sum(nums[:X + Y])
print(answer)
Buggy python submission (verdict: Runtime Error):
from numpy import *
M=998244353
N,S,*A=map(int,open(0).read().split())
a=0
f = np.zeros(S+1, np.int64)
for b in As:
  f[0]+=1
  f[b:] += f[:-b].copy()
  f%=M
  a+=f[S]
print(a%M)

Fixed submission:
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

MOD = 998244353

N, S, *As = map(int, read().split())

U = 3010
answer = 0
f = np.zeros(U, np.int64)
for A in As:
    f[0] += 1
    f[A:] += f[:-A].copy()
    f %= MOD
    answer += f[S]

answer %= MOD
print(answer)
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
A = list(map(int, read().decode().rstrip()))

U = N + 10
fact_ord = [0] * U
for n in range(1,U):
    fact_ord[n] = fact_ord[n//2] + (n//2)

def solve_01(A):
    ret = 0
    N = len(A) - 1
    comb_ord = [fact_ord[N] - fact_ord[i] - fact_ord[N-i] for i in range(N+1)]
    return sum(x * (y==0) for x,y in zip(A, comb_ord)) % 2

def solve(A):
    if len(A) == 1:
        return A[0]
    A = [abs(x - y) for x,y in zip(A, A[1:])]
    if all(x != 1 for x in A):
        B = [x // 2 for x in A]
        return 2 * solve_01(B)
    # 1 が存在
    A = [x % 2 for x in A]
    return solve_01(A)

print(solve(A))

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = list(map(int, read().decode().rstrip()))

U = N + 10
fact_ord = [0] * U
for n in range(1,U):
    fact_ord[n] = fact_ord[n//2] + (n//2)

def solve_01(A):
    ret = 0
    N = len(A) - 1
    comb_ord = [fact_ord[N] - fact_ord[i] - fact_ord[N-i] for i in range(N+1)]
    return sum(x * (y==0) for x,y in zip(A, comb_ord)) % 2

def solve(A):
    if len(A) == 1:
        return A[0]
    A = [abs(x - y) for x,y in zip(A, A[1:])]
    if all(x != 1 for x in A):
        B = [x // 2 for x in A]
        return 2 * solve_01(B)
    # 1 が存在
    A = [x % 2 for x in A]
    return solve_01(A)

print(solve(A))
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,M = map(int,read().split())

def solve(N,M):
    if N > M:
        return solve(M,N).T
    H = np.array([[0]], np.int8)
    for i in range(M):
        H = np.tile(H, (2,2))
        H[1<<i:,1<<i:] ^= 1
    H = np.diff(H, axis=0)
    H = np.diff(H, axis=1)
    return (H % 2)[:(1<<N) - 1]

H = solve(N,M)
rows = (''.join(map(str, row)) for row in H)
print('\n'.join(rows))


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = read().rstrip().decode()

def solve(S):
    N = len(S)
    if N % 2 == 1:
        return False
    T = 'hi' * (N//2)
    return S == T

print('Yes' if solve(S) else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,M = map(int,read().split())

def solve(N,M):
    if N > M:
        return solve(M,N).T
    H = np.array([[0]], np.int8)
    for i in range(M):
        H = np.tile(H, (2,2))
        H[1<<i:,1<<i:] ^= 1
    H = np.diff(H, axis=0)
    H = np.diff(H, axis=1)
    return (H % 2)[:(1<<N) - 1]

H = solve(N,M)
rows = (''.join(map(str, row)) for row in H)
print('\n'.join(rows))


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,M = map(int,read().split())

def solve(N,M):
    if N > M:
        return solve(M,N).T
    H = np.array([[0]], np.int8)
    for i in range(M):
        H = np.tile(H, (2,2))
        H[1<<i:,1<<i:] ^= 1
    H = np.diff(H, axis=0)
    H = np.diff(H, axis=1)
    return (H % 2)[:(1<<N) - 1]

H = solve(N,M)
size = 0
for row in H:
    word = ''.join(row.astype(str))
    print(word)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,M = map(int,read().split())

def solve(N,M):
    if N > M:
        return solve(M,N).T
    H = np.array([[0]], np.int8)
    for i in range(M):
        H = np.tile(H, (2,2))
        H[1<<i:,1<<i:] ^= 1
    H = np.diff(H, axis=0)
    H = np.diff(H, axis=1)
    return (H % 2)[:(1<<N) - 1]

H = solve(N,M)
rows = (''.join(map(str, row)) for row in H)
print('\n'.join(rows))

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,M = map(int,read().split())

def solve(N,M):
    if N > M:
        return solve(M,N).T
    H = np.array([[0]], np.int8)
    for i in range(M):
        H = np.tile(H, (2,2))
        H[1<<i:,1<<i:] ^= 1
    H = np.diff(H, axis=0)
    H = np.diff(H, axis=1)
    return (H % 2)[:(1<<N) - 1]

H = solve(N,M)
size = 0
for row in H:
    word = ''.join(row.astype(str))
    print(word)