Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
from numpy.fft import rfft, irfft
MOD = 10 ** 9 + 7
K = [int(x) for x in input().rstrip()]
L = len(K)
D = int(input())

fft_len = 1
while fft_len < 2*D:
    fft_len *= 2

def fft_convolve(A,B):
    return np.round(irfft(rfft(A,fft_len) * rfft(B,fft_len))).astype(np.int64) % MOD

def convolve(A,B):
    M = 1 << 16
    mask = M - 1
    A1,A2 = A>>16, A&mask
    B1,B2 = B>>16, B&mask
    X,Y,Z = [fft_convolve(P,Q) for P,Q in [[A1,B1],[A1-A2,B1-B2],[A2,B2]]]
    X = (X << 32) + ((X-Y+Z) << 16) + Z
    X[:D] += X[D:D+D]
    return X[:D] % MOD

# d桁以下、自由に使った場合の余りごとの個数。0を含めて数えておく
ones = [np.zeros(D,dtype=np.int64)]
for x in range(10):
    arr = ones[-1].copy()
    arr[x%D] += 1
    ones.append(arr)
full = []
dp = np.zeros(D, dtype=np.int64)
dp[0] = 1
full.append(dp)
for d in range(1,L):
    dp = convolve(dp,ones[10])
    full.append(dp)

dist = np.zeros(D+D, dtype=np.int64)

cumsum = 0
for i,x in enumerate(K):
    arr = convolve(ones[x], full[L-i-1])
    dist[cumsum:cumsum+D] += arr
    cumsum += x
    cumsum %= D
dist[cumsum] += 1 # 全部そのまま使う

answer = dist[::D].sum() - 1 # 0除外
answer %= MOD
print(answer)



Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
from numpy.fft import rfft, irfft
MOD = 10 ** 9 + 7
K = [int(x) for x in input().rstrip()]
L = len(K)
D = int(input())

def convolve_ones(x,arr):
    # 0,1,...,x-1
    after = np.zeros(D+x,dtype=np.int64)
    for i in range(x):
        after[i:i+D] += arr
    for i in range(D,D+x):
        after[i%D]+= after[i]
    return after[:D] % MOD

# d桁以下、自由に使った場合の余りごとの個数。0を含めて数えておく
full = [np.zeros(D, dtype=np.int64)]
full[0][0] = 1
for d in range(1,L):
    full.append(convolve_ones(10,full[-1]))

dist = np.zeros(D+D, dtype=np.int64)

cumsum = 0
for i,x in enumerate(K):
    arr = convolve_ones(x, full[L-i-1])
    dist[cumsum:cumsum+D] += arr
    cumsum += x
    cumsum %= D
dist[cumsum] += 1 # 全部そのまま使う

answer = dist[::D].sum() - 1 # 0除外
answer %= MOD
print(answer)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

N = int(input())
WSV = [[int(x) for x in input().split()] for _ in range(N)]

# 上から見てこの順であるとしてよい
WSV.sort(key = lambda x: x[0] + x[1])

# 総重量 -> 価値
dp = np.zeros(2*10**4,dtype=np.int64)
for w,s,v in WSV:
    np.maximum(dp[w+s:w-1:-1], dp[s::-1] + v, out=dp[w+s:w-1:-1])

answer = dp.max()
print(answer)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

N = int(input())
WSV = [[int(x) for x in input().split()] for _ in range(N)]

# 上から見てこの順であるとしてよい
WSV.sort(key = lambda x: x[0] + x[1])

# 総重量 -> 価値
dp = np.zeros(2*10**4+100,dtype=np.int64)
for w,s,v in WSV:
    np.maximum(dp[w+s:w-1:-1], dp[s::-1] + v, out=dp[w+s:w-1:-1])

answer = dp.max()
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,P = map(int,input().split())

answer = 1
x = 1
if N < 100:
    while True:
        x += 1
        y = x ** N
        if y > P:
            break
        if P % y == 0:
            answer = x

print(answer)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,P = map(int,input().split())

f = []
x = 2
while x*x <= P:
    if P%x == 0:
        f.append(x)
        P //= x
        continue
    x += 1

if P > 1:
    f.append(P)

from collections import Counter
counter = Counter(f)

answer = 1
for p,k in counter.items():
    answer *= p ** (k//N)
print(answer)
Buggy python submission (verdict: Runtime Error):
print('Christmas'+' Eve'*(25-int(input()))

Fixed submission:
print('Christmas'+' Eve'*(25-int(input())))
Buggy python submission (verdict: Runtime Error):
N,M = map(int, input())

# Mの約数dのうち、Nd <= Mとなるものの最大

divisors = []
for d in range(1, M+1):
    if d*d > M:
        break
    divisors.append(d)
    divisors.append(M//d)

ans = 1

for d in divisors:
    if N*d <= M:
        ans = d

print(ans)

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

# Mの約数dのうち、Nd <= Mとなるものの最大

divisors = []
for d in range(1, M+1):
    if d*d > M:
        break
    if M%d == 0:
        divisors.append(d)
        divisors.append(M//d)

ans = 1

divisors.sort()

for d in divisors:
    if N*d <= M:
        ans = d

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

import numpy as np

N,B = map(int,input().split())
X = np.array(input().split(), dtype=np.int64)

Xcum = X.cumsum()

coef = np.full(N,2,dtype=np.int64)
coef[0] = 5
coef[1] = 0

answer = 10**18
for n in range(1,N+1):
    # 往復回数
    cost = (Xcum[::-n]*coef[:1+(N-1)//n]).sum() + B*(N+n)
    answer = min(answer, cost)

print(answer)


Fixed submission:
import sys
input = sys.stdin.readline
import itertools

N,B = map(int,input().split())
X = [int(x) for x in input().split()]

Xcum = tuple(itertools.accumulate(X))

coef = [2] * N
coef[0] = 5
coef[1] = 0

answer = min(sum(x*y for x,y in zip(Xcum[::-n], coef[:1+(N-1)//n])) + B*(N+n) for n in range(1,N+1))
print(answer)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

import numpy as np

N,B = map(int,input().split())
X = np.array(input().split(), dtype=np.int64)

Xcum = X.cumsum()

coef = np.full(N,2,dtype=np.int64)
coef[0] = 5
coef[1] = 0

answer = 10**18
for n in range(1,N+1):
    # 往復回数
    cost = (Xcum[::-n]*coef[:N//n]).sum() + B*(N+n)
    answer = min(answer, cost)

print(answer)


Fixed submission:
import sys
input = sys.stdin.readline
import itertools

N,B = map(int,input().split())
X = [int(x) for x in input().split()]

Xcum = tuple(itertools.accumulate(X))

coef = [2] * N
coef[0] = 5
coef[1] = 0

answer = min(sum(x*y for x,y in zip(Xcum[::-n], coef[:1+(N-1)//n])) + B*(N+n) for n in range(1,N+1))
print(answer)

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

import numpy as np

N,B = map(int,input().split())
X = np.array(input().split(), dtype=np.int64)

Xcum = X.cumsum()

coef = np.full(N,2,dtype=np.int64)
coef[0] = 5
coef[1] = 0

answer = 10**18
for n in range(1,N+1):
    # 往復回数
    x = Xcum[::-n]
    cost = x.sum()*2 + 3*x[0] + B*(N+n)
    if len(x) > 1:
        cost -= 2*x[1]
    if answer > cost:
        answer = cost

print(answer)

Fixed submission:
import sys
input = sys.stdin.readline
import itertools

N,B = map(int,input().split())
X = [int(x) for x in input().split()]

Xcum = tuple(itertools.accumulate(X))

coef = [2] * N
coef[0] = 5
coef[1] = 0

answer = min(sum(x*y for x,y in zip(Xcum[::-n], coef[:1+(N-1)//n])) + B*(N+n) for n in range(1,N+1))
print(answer)

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

import numpy as np

N,B = map(int,input().split())
X = np.array(input().split(), dtype=np.int64)

Xcum = X.cumsum()

coef = np.full(N,2,dtype=np.int64)
coef[0] = 5
coef[1] = 0

answer = 10**18
for n in range(1,N+1):
    # 往復回数
    x = Xcum[::-1][::n]
    cost = (x*coef[:len(x)]).sum() + B*(N+n)
    answer = min(answer, cost)

print(answer)

Fixed submission:
import sys
input = sys.stdin.readline
import itertools

N,B = map(int,input().split())
X = [int(x) for x in input().split()]

Xcum = tuple(itertools.accumulate(X))

coef = [2] * N
coef[0] = 5
coef[1] = 0

answer = min(sum(x*y for x,y in zip(Xcum[::-n], coef[:1+(N-1)//n])) + B*(N+n) for n in range(1,N+1))
print(answer)
Buggy python submission (verdict: Runtime Error):
A,B = int(input()),int(input())
print('Yes' if A&B&1 else 'No')

Fixed submission:
A,B = map(int,input().split())
print('Yes' if A&B&1 else 'No')

Buggy python submission (verdict: Runtime Error):
A,B = int(input()),int(input())
print('Yes' if A&B&1 else 'No)

Fixed submission:
A,B = map(int,input().split())
print('Yes' if A&B&1 else 'No')
Buggy python submission (verdict: Runtime Error):
import numpy as np

N,M = map(int,input().split())
A = np.array(input().split(), dtype=np.int64)
np.cumsum(A, out = A)
A %= M

counter = np.bincount(A)
counter[0] += 1 # empty
answer = (counter * (counter-1)).sum() // 2
print(answer)


Fixed submission:
import numpy as np
from collections import Counter

N,M = map(int,input().split())
A = np.array([0]+[int(x) for x in input().split()],dtype=np.int64)
A_cum = np.mod(A.cumsum(),M)

c = Counter(A_cum)

answer = 0
for x in c.values():
  answer += x*(x-1)//2
print(answer)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N,M = map(int,input().split())
A = np.array(input().split(), dtype=np.int64)
A_cum = np.mod(A.cumsum(),M)

counter = np.bincount(A_cum)
counter[0] += 1 # empty
answer = (counter * (counter-1)).sum() // 2
print(answer)


Fixed submission:
import numpy as np
from collections import Counter

N,M = map(int,input().split())
A = np.array([0]+[int(x) for x in input().split()],dtype=np.int64)
A_cum = np.mod(A.cumsum(),M)

c = Counter(A_cum)

answer = 0
for x in c.values():
  answer += x*(x-1)//2
print(answer)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N,M = map(int,input().split())
A = np.array([0]+[int(x) for x in input().split()],dtype=np.int64)
A_cum = np.mod(A.cumsum(),M)

counter = np.bincount(A_cum)
counter[0] += 1 # empty
answer = (counter * (counter-1)).sum() // 2
print(answer)

Fixed submission:
import numpy as np
from collections import Counter

N,M = map(int,input().split())
A = np.array([0]+[int(x) for x in input().split()],dtype=np.int64)
A_cum = np.mod(A.cumsum(),M)

c = Counter(A_cum)

answer = 0
for x in c.values():
  answer += x*(x-1)//2
print(answer)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N,M = map(int,input().split())
A = np.array([0]+[int(x) for x in input().split()],dtype=np.int64)
A_cum = np.mod(A.cumsum(),M)

counter = np.bincount(A_cum, dtype=np.int64)
counter[0] += 1 # empty
answer = (counter * (counter-1)).sum() // 2
print(answer)

Fixed submission:
import numpy as np
from collections import Counter

N,M = map(int,input().split())
A = np.array([0]+[int(x) for x in input().split()],dtype=np.int64)
A_cum = np.mod(A.cumsum(),M)

c = Counter(A_cum)

answer = 0
for x in c.values():
  answer += x*(x-1)//2
print(answer)
Buggy python submission (verdict: Runtime Error):
N = input()
A = [int(x) for x in input().split()]

answer = 0
for i in range(1,N):
  if A[i] == A[i-1]:
    A[i] = -1
    answer += 1
print(answer)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]

answer = 0
for i in range(1,N):
  if A[i] == A[i-1]:
    A[i] = -1
    answer += 1
print(answer)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
from heapq import heappush, heappop

N,M,S,T = map(int,input().split())
graph = [[] for _ in range(N+1)]
for _ in range(M):
    u,v,a,b = map(int,input().split())
    graph[u].append((v,a,b))
    graph[v].append((u,a,b))

def dijkstra(start, mode):
    INF = 10 ** 15
    dist = [INF] * (N+1)
    dist[start] = 0
    q = [(0,start)]
    while q:
        d,v = heappop(q)
        if dist[v] < d:
            continue
        for w,*a in graph[v]:
            d1 = d + a[mode]
            if dist[w] > d1:
                dist[w] = d1
                heappush(q, (d1,w))
    return dist

d1 = np.array(dijkstra(S,0))
d2 = np.array(dijkstra(T,1))

d1 += d2
answer = 10 ** 15 - np.minimum.accumulate(d1[::-1])[::-1][1:]

print('\n'.join(answer.astype(str)))

Fixed submission:
a,b = map(int,input().split())
answer = 'x'
if a+b == 15:
  answer = '+'
elif a*b == 15:
  answer = '*'
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

N,M,S,T = map(int,input().split())
UVAB = [[int(x) for x in input().split()] for _ in range(M)]
U,V,A,B = zip(*UVAB)

g1 = csr_matrix((A,(U,V)), (N+1,N+1))
g2 = csr_matrix((B,(U,V)), (N+1,N+1))
d1 = dijkstra(g1, indices=S, directed=False)
d2 = dijkstra(g2, indices=T, directed=False)

d = d1 + d2 # 各頂点を両替所に選ぶ場合

d = (np.minimum.accumulate(d[::-1])[::-1]).astype(int)

answer = 10 ** 15 - d[1:]
print('\n'.join(answer.astype(str)))

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
from heapq import heappush, heappop

N,M,S,T = map(int,input().split())
graph = [[] for _ in range(N+1)]
for _ in range(M):
    u,v,a,b = map(int,input().split())
    graph[u].append((v,a,b))
    graph[v].append((u,a,b))

def dijkstra(start, mode):
    INF = 10 ** 15
    dist = [INF] * (N+1)
    dist[start] = 0
    q = [(0,start)]
    while q:
        d,v = heappop(q)
        if dist[v] < d:
            continue
        for w,*a in graph[v]:
            d1 = d + a[mode]
            if dist[w] > d1:
                dist[w] = d1
                heappush(q, (d1,w))
    return dist

d1 = np.array(dijkstra(S,0))
d2 = np.array(dijkstra(T,1))

d1 += d2
answer = 10 ** 15 - np.minimum.accumulate(d1[::-1])[::-1][1:]

print(*answer, sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

N,M,S,T = map(int,input().split())
UVAB = [[int(x) for x in input().split()] for _ in range(M)]
U,V,A,B = zip(*UVAB)

g1 = csr_matrix((A,(U,V)), (N+1,N+1))
g2 = csr_matrix((B,(U,V)), (N+1,N+1))
d1 = dijkstra(g1, indices=S, directed=False)
d2 = dijkstra(g2, indices=T, directed=False)

d = d1 + d2 # 各頂点を両替所に選ぶ場合

d = (np.minimum.accumulate(d[::-1])[::-1]).astype(int)

answer = 10 ** 15 - d[1:]
print(*answer, sep='\n')

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
from heapq import heappush, heappop

N,M,S,T = map(int,input().split())
graph = [[] for _ in range(N+1)]
for _ in range(M):
    u,v,a,b = map(int,input().split())
    graph[u].append((v,a,b))
    graph[v].append((u,a,b))

def dijkstra(start, mode):
    INF = 10 ** 15
    dist = [INF] * (N+1)
    dist[start] = 0
    q = [(0,start)]
    while q:
        d,v = heappop(q)
        if dist[v] < d:
            continue
        for w,*a in graph[v]:
            d1 = d + a[mode]
            if dist[w] > d1:
                dist[w] = d1
                heappush(q, (d1,w))
    return dist

d1 = np.array(dijkstra(S,0))
d2 = np.array(dijkstra(T,1))

d1 += d2
answer = 10 ** 15 - np.minimum.accumulate(d1[::-1])[::-1][1:]

print(*answer, sep='\n')
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
print(min(a,b)+min(c,d))

Fixed submission:
a,b,c,d = [int(input()) for _ in range(4)]
print(min(a,b)+min(c,d))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from scipy.optimize import linear_sum_assignment
import numpy as np

N = int(input())
AB = [[int(x) for x in input().split()] for _ in range(N)]
CD = [[int(x) for x in input().split()] for _ in range(N)]

mat = np.zeros((N,N),dtype=np.int32)

for i,(a,b) in enumerate(AB):
    for j,(c,d) in enumerate(CD):
        if a<c and b<d:
            mat[i,j] -= 1


I,J = linear_sum_assignment(mat)

answer = -mat[I,J].sum()
print(answer)

Fixed submission:
from scipy.sparse.csgraph import dijkstra
# 二部グラフ完全マッチング
# 最大フロー
N = int(input())
NN = N * 2
XY = [[int(x) for x in input().split()] for _ in range(NN)]
graph = [[0] * (NN+2) for _ in range(NN+2)]
start = NN
goal = NN+1

for i,(a,b) in enumerate(XY[:N]):
  for j,(c,d) in enumerate(XY[N:], N):
    if a < c and b < d:
      graph[i][j] = 1

for i in range(N):
  graph[start][i] = 1
for i in range(N,NN):
  graph[i][goal] = 1
  
INF = 10 ** 9

def max_flow(graph):
  dist, pred = dijkstra(graph, indices = start, return_predecessors = True)
  if dist[goal] > INF:
    return 0
  y = goal
  while y != start:
    x = pred[y]
    graph[x][y] -= 1
    graph[y][x] += 1
    y = x
  return 1 + max_flow(graph)

answer = max_flow(graph)
print(answer)
Buggy python submission (verdict: Runtime Error):
# a%b >= K iff xb+K <= a < (x+1)b
# bごとに数えるだけ

N,K = map(int,input().split())
ans = 0

for b in range(K+1,N+1):
  cnt = 0
  x_max = N//b
  # 0 <= x < x_max
  # 各xに対してb-K個ある
  cnt += x_max * (b-K)
  # x = x_max
  lower = x_max*b+K
  if lower <= N:
	upper = min((x_max+1)*b-1,N)
    cnt += upper - lower + 1
  ans += cnt
  
print(ans)

Fixed submission:
# a%b >= K iff xb+K <= a < (x+1)b
# bごとに数えるだけ

N,K = map(int,input().split())
ans = 0

for b in range(K+1,N+1):
  cnt = 0
  x_max = N//b
  # 0 <= x < x_max
  # 各xに対してb-K個ある
  cnt += x_max * (b-K)
  # x = x_max
  lower = x_max*b+K
  if lower <= N:
    upper = min((x_max+1)*b-1,N)
    cnt += upper - lower + 1
  ans += cnt

# N=0除外
if K == 0:
  ans -= N
  
print(ans)
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())
AK = np.array(read().split(),np.int32)

A = AK[::2]; K = AK[1::2]

G = 0

for t in range(50000):
    q = A//K; r = A%K
    q += 1
    r += (-r)%q
    A -= r
    if t%1000==0:
        ind = r!=0
        G ^= np.bitwise_xor.reduce(A[~ind]//K[~ind])
        A=A[ind];K=K[ind]
        if len(A)==0:
            break

answer = 'Takahashi' if G else 'Aoki'
print(answer)

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

import numpy as np

N = int(readline())
AK = np.array(read().split(),np.int32)

A = AK[::2]; K = AK[1::2]

for _ in range(50000):
    q = A//K; r = A%K
    q += 1
    r += (-r)%q
    A -= r

A //= K #grundy
g = np.bitwise_xor.reduce(A)

answer = 'Takahashi' if g else 'Aoki'
print(answer)
Buggy python submission (verdict: Runtime Error):
N = int(input())

def ask(n):
    print(n, flush=True)
    resp = input().rstrip()[0]
    if resp == 'V':
        exit()
    return resp

resp = ask(0)

def condition(L,R,resp_L,resp_R):
    if (R-L)&1:
        return resp_L == resp_R
    else:
        return resp_L != resp_R

L = 0
R = 0
resp_L = resp
resp_R = resp
for _ in range(19):
    M = (L + R) // 2
    resp_M = ask(M)
    if condition(L,M,resp_L,resp_M):
        R,resp_R = M,resp_M
    else:
        L,resp_L = M,resp_M

Fixed submission:
x,y = map(int,input().split())
answer = x if x%y else -1
print(answer)

Buggy python submission (verdict: Runtime Error):
def ask(n):
    print(n, flush=True)
    resp = input().rstrip()[0]
    if resp == 'V':
        exit()
    return resp

resp = ask(0)

def condition(L,R,resp_L,resp_R):
    if (R-L)&1:
        return resp_L == resp_R
    else:
        return resp_L != resp_R

L = 0
R = N
resp_L = resp
resp_R = resp
for _ in range(19):
    M = (L + R) // 2
    resp_M = ask(M)
    if condition(L,M,resp_L,resp_M):
        R,resp_R = M,resp_M
    else:
        L,resp_L = M,resp_M

Fixed submission:
x,y = map(int,input().split())
answer = x if x%y else -1
print(answer)
Buggy python submission (verdict: Runtime Error):
6 2
1 2 B
2 1 W
2 2 B
1 0 B
0 6 W
4 5 W

Fixed submission:
#(6,6)周期
#36種の希望

import numpy as np
N,K = map(int,input().split())
KK = 2*K
hope = np.zeros((KK,KK),dtype=np.int32)

XYC = [input().split() for _ in range(N)]

for x,y,c in XYC:
  x = int(x)
  y = int(y)
  if c == 'B':
    x -= K
  x %= KK
  y %= KK
  hope[x,y] += 1
# (x,y)を希望された場合、[x,x+K), [y,y+K)に終点があるべき
# 区間の重なってる枚数を集計。1,0,0,-1, cumsum
A = np.zeros((KK+K,KK+K),dtype=np.int32)
A[:-K,:-K] = hope[:]
A[K:,:-K] += -hope[:]
A[:-K,K:] += -hope[:]
A[K:,K:] += hope[:]
A = A.cumsum(axis = 0).cumsum(axis = 1)

# 実質同じ場所をまとめる
B = A[:,:KK]
B[:,:K] += A[:,KK:] #(3K,2K)
A = B[:KK,:]
A[:K,:] += B[KK:,:] #(2K,2K)
B = A[:K,:] #(K,2K)
B[:,:K] += A[K:,K:]
B[:,K:] += A[K:,:K]

answer = B.max()
print(answer)

Buggy python submission (verdict: Runtime Error):
#(6,6)周期
#36種の希望

import numpy as np
N,K = map(int,input().split())
KK = 2*K
hope = np.zeros((KK,KK),dtype=np.int32)

XYC = [input().split() for _ in range(N)]

for _ in range(N):
  x,y,c  = input().split()
  x = int(x)
  y = int(y)
  if c == 'B':
    x -= K
  hope[x%KK,y%KK] += 1
# (x,y)を希望された場合、[x,x+K), [y,y+K)に終点があるべき
# 区間の重なってる枚数を集計。1,0,0,-1, cumsum
A = np.zeros((KK+K,KK+K),dtype=np.int32)
A[:-K,:-K] = hope[:]
A[K:,:-K] += -hope[:]
A[:-K,K:] += -hope[:]
A[K:,K:] += hope[:]
A = A.cumsum(axis = 0).cumsum(axis = 1)

# 実質同じ場所をまとめる
B = A[:,:KK]
B[:,:K] += A[:,KK:] #(3K,2K)
A = B[:KK,:]
A[:K,:] += B[KK:,:] #(2K,2K)
B = A[:K,:] #(K,2K)
B[:,:K] += A[K:,K:]
B[:,K:] += A[K:,:K]

answer = B.max()
print(answer)


Fixed submission:
#(6,6)周期
#36種の希望

import numpy as np
N,K = map(int,input().split())
KK = 2*K
hope = np.zeros((KK,KK),dtype=np.int32)

XYC = [input().split() for _ in range(N)]

for x,y,c in XYC:
  x = int(x)
  y = int(y)
  if c == 'B':
    x -= K
  x %= KK
  y %= KK
  hope[x,y] += 1
# (x,y)を希望された場合、[x,x+K), [y,y+K)に終点があるべき
# 区間の重なってる枚数を集計。1,0,0,-1, cumsum
A = np.zeros((KK+K,KK+K),dtype=np.int32)
A[:-K,:-K] = hope[:]
A[K:,:-K] += -hope[:]
A[:-K,K:] += -hope[:]
A[K:,K:] += hope[:]
A = A.cumsum(axis = 0).cumsum(axis = 1)

# 実質同じ場所をまとめる
B = A[:,:KK]
B[:,:K] += A[:,KK:] #(3K,2K)
A = B[:KK,:]
A[:K,:] += B[KK:,:] #(2K,2K)
B = A[:K,:] #(K,2K)
B[:,:K] += A[K:,K:]
B[:,K:] += A[K:,:K]

answer = B.max()
print(answer)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import deque

N,M = map(int,input().split())
words = [deque(input().rstrip()) for _ in range(N)]

# 深さLのfull treeの小さい方を計算してみる
def G_small():
    G = [0] * 100
    G_cum = [0] * 100
    G[0] = 1
    G_cum[0] = 1
    for n in range(1,100):
        can_make = set(G_cum[n-1]^G_cum[x] for x in range(n)) | set([G_cum[n-1]])
        rest = set(range(n+10)) - can_make
        G[n] = min(rest)
        G_cum[n] = G_cum[n-1] ^ G[n]
    return G

# print([(n,G[n]) for n in range(100)])
# G[n] = 2**ord_2(n+1)
# 値がわかれば証明は易しい

def G(n):
    n += 1
    x = 1
    while not n & 1:
        n >>= 1
        x <<= 1
    return x

def calc_grandy(words,L):
    if not words:
        return G(L)
    if len(words) == 1 and words[0] == deque():
        return 0
    words_0 = []
    words_1 = []
    for word in words:
        first = word.popleft()
        if first == '0':
            words_0.append(word)
        else:
            words_1.append(word)
    return calc_grandy(words_0,L-1) ^ calc_grandy(words_1,L-1)

g = calc_grandy(words,M)

answer = 'Alice' if g != 0 else 'Bob'
print(answer)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
from collections import deque

N,M = map(int,input().split())
words = [deque(input().rstrip()) for _ in range(N)]

# 深さLのfull treeの小さい方を計算してみる
def G_small():
    G = [0] * 100
    G_cum = [0] * 100
    G[0] = 1
    G_cum[0] = 1
    for n in range(1,100):
        can_make = set(G_cum[n-1]^G_cum[x] for x in range(n)) | set([G_cum[n-1]])
        rest = set(range(n+10)) - can_make
        G[n] = min(rest)
        G_cum[n] = G_cum[n-1] ^ G[n]
    return G

# print([(n,G[n]) for n in range(100)])
# G[n] = 2**ord_2(n+1)
# 値がわかれば証明は易しい

def G(n):
    n += 1
    x = 1
    while not n & 1:
        n >>= 1
        x <<= 1
    return x

def calc_grandy(words,L):
    if not words:
        return G(L)
    if len(words) == 1 and words[0] == deque():
        return 0
    words_0 = []
    words_1 = []
    for word in words:
        first = word.popleft()
        if first == '0':
            words_0.append(word)
        else:
            words_1.append(word)
    return calc_grandy(words_0,L-1) ^ calc_grandy(words_1,L-1)

g = calc_grandy(words,M)

answer = 'Alice' if g != 0 else 'Bob'
print(answer)