Problem:


Score : 500 points

Problem Statement

AtCoDeer is thinking of painting an infinite two-dimensional grid in a checked pattern of side K.
Here, a checked pattern of side K is a pattern where each square is painted black or white so that each connected component of each color is a K × K square.
Below is an example of a checked pattern of side 3:

AtCoDeer has N desires.
The i-th desire is represented by x_i, y_i and c_i.
If c_i is B, it means that he wants to paint the square (x_i,y_i) black; if c_i is W, he wants to paint the square (x_i,y_i) white.
At most how many desires can he satisfy at the same time?

Constraints

1 ≤ N ≤ 10^5

1 ≤ K ≤ 1000

0 ≤ x_i ≤ 10^9

0 ≤ y_i ≤ 10^9

If i ≠ j, then (x_i,y_i) ≠ (x_j,y_j).

c_i is B or W.

N, K, x_i and y_i are integers.

Input

Input is given from Standard Input in the following format:

N K
x_1 y_1 c_1
x_2 y_2 c_2
:
x_N y_N c_N

Output

Print the maximum number of desires that can be satisfied at the same time.

Sample Input 1

4 3
0 1 W
1 2 W
5 3 B
5 4 B

Sample Output 1

4

He can satisfy all his desires by painting as shown in the example above.

Sample Input 2

2 1000
0 0 B
0 1 W

Sample Output 2

2

Sample Input 3

6 2
1 2 B
2 1 W
2 2 B
1 0 B
0 6 W
4 5 W

Sample Output 3

4



Sample input:
4 3
0 1 W
1 2 W
5 3 B
5 4 B


Sample output:
4

Submission status: Runtime Error

Solution code:
import numpy as np
n, k = [int(item) for item in input().split()]
xyc = [[item for item in input().split()] for _ in range(n)]

a = [[0] * 2*k for _ in range(2*k)]
for x, y, c in xyc:
    x = int(x)
    y = int(y)
    if c == "W":
        a[x%(2*k)][y%(2*k)] +=  1
    else: 
        a[(x+k)%(2*k)][(y)%(2*k)] += 1

cumsum = np.cumsum(np.cumsum(a, axis=0), axis=1)
aflip = np.flip(np.flip(a, axis=1), axis=0)
cumsum_flip =  np.cumsum(np.cumsum(aflip, axis=0), axis=1)

ans = 0
for i in range(k):
    for j in range(k):
        ret = 0
        ik = i+k
        jk = j+k
        hm = 2*k-1
        ret += (cumsum[ik][hm] - cumsum[i][hm] + 2 * cumsum[i][jk] + 
                cumsum[hm][j+k] - cumsum[hm][j] + 2 * cumsum[ik][j] -
                2 * cumsum[ik][jk] - 2 * cumsum[i][j])
        ans = max(ans, ret, n-ret)

print(ans)

Submission status: Runtime Error

Solution code:
class BIT2D:
    '''2 dimensional 1-indexed BIT
    '''

    def __init__(self, size: int):
        self.__size = size
        self.__data = [[0] * (size+1) for _ in range(size+1)]

    def update(self, x: int, y: int, v: int):
        tx, ty = x, y
        while tx <= self.__size:
            ty = y
            while ty <= self.__size:
                self.__data[tx][ty] += v
                ty += ty & -ty
            tx += tx & -tx

    def sum(self, x1: int, y1: int, x2: int, y2: int)->int:
        return self.__sum(x2, y2) - self.__sum(x2, y1) - self.__sum(x1, y2) + self.__sum(x1, y1)

    def __sum(self, x: int, y: int)->int:
        s, tx, ty = 0, x, y
        while tx > 0:
            ty = y
            while ty > 0:
                s += self.__data[tx][ty]
                ty -= ty & -ty
            tx -= tx & -tx
        return s


def points(cx: int, cy: int, K: int)->list:
    # 中心
    ps = [(max(0, cx-K), max(0, cy-K), cx, cy)]

    # 右上
    x2, y2 = min(2*K, cx+K), min(2*K, cy+K)
    x1, y1 = cx, cy
    ps.append((x1, y1, x2, y2))

    if K < cy:
        # 右下
        x2, y2 = min(2*K, cx+K), cy - K
        x1, y1 = cx, max(0, y2-K)
        ps.append((x1, y1, x2, y2))

    if cx < K:
        # 右
        x2, y2 = min(2*K, cx+2*K), cy
        x1, y1 = cx + K, max(0, cy-K)
        ps.append((x1, y1, x2, y2))

    if K < cx:
        # 左上
        x2, y2 = cx - K, min(2*K, cy+K)
        x1, y1 = max(0, x2-K), cy
        ps.append((x1, y1, x2, y2))

    if K < cx and K < cy:
        # 左下
        x2, y2 = cx - K, cy - K
        x1, y1 = max(0, x2-K), max(0, y2-K)
        ps.append((x1, y1, x2, y2))

    return ps


def checker(N: int, K: int, XYC: list)->int:
    white, black = BIT2D(2*K), BIT2D(2*K)
    for x, y, c in XYC:
        if c == 'B':
            x = x + K
        tx, ty = (x % (2*K)) + 1, (y % (2*K)) + 1
        # black.update(tx, ty, 1)
        # if c == 'W':
        white.update(tx, ty, 1)

    # white = [[0] * (2*K + 1) for _ in range(2*K + 1)]
    # black = [[0] * (2*K + 1) for _ in range(2*K + 1)]
    # # sorted(sorted(XYC, key=lambda x: x[0]), key=lambda x: x[1]):
    # for x, y, c in XYC:
    #     tx, ty = (x % (2*K)) + 1, (y % (2*K)) + 1
    #     if c == 'W':
    #         white[tx][ty] += 1
    #     if c == 'B':
    #         black[tx][ty] += 1

    # for ky in range(2*K):
    #     for kx in range(2*K):
    #         white[ky+1][kx+1] = white[ky+1][kx] + white[ky][kx+1]
    #         black[ky+1][kx+1] = black[ky+1][kx] + black[ky][kx+1]

    # print('finished initialized')

    max_count = 0
    for ky in range(K, 2*K):
        for kx in range(2*K):
            count = 0
            # print('-'*30)
            for x1, y1, x2, y2 in points(kx, ky, K):
                count += white.sum(x1, y1, x2, y2)
                # count += white[x2][y2] - white[x2][y1] - \
                #     white[x1][y2] + white[x1][y1]
                op += 1
                # print('white ({}, {}, {}, {})'.format(x1, y1, x2, y2))
                # print(count)

            # for x1, y1, x2, y2 in points((kx+K) % (2*K), ky, K):
            #     count += black.sum(x1, y1, x2, y2)
            #     # count += black[x2][y2] - black[x2][y1] - \
            #     #     black[x1][y2] + black[x1][y1]
            #     op += 1
            #     # print('black ({}, {}, {}, {})'.format(x1, y1, x2, y2))
            #     # print(count)

            max_count = max(max_count, count)
            if max_count == N:
                break
    return max_count


if __name__ == "__main__":
    N = 0
    N, K = map(int, input().split())
    XYC = []
    for _ in range(N):
        x, y, c = input().split()
        XYC.append((int(x), int(y), c))
    ans = checker(N, K, XYC)
    print(ans)

Submission status: Runtime Error

Solution code:
give up

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

N, K = map(int, raw_input().split())
DP = [[0] * (K + 1) for i in range(K + 1)]
bias = 0

for i in range(N):
    x, y, c = raw_input().split()
    x, y, c = int(x), int(y), (c == 'W')
    p = (x / K + y / K + c) % 2
    DP[y % K + 1][x % K + 1] += -1 ** p
    bias += p

for i in range(K): for j in range(K + 1): DP[i + 1][j] += DP[i][j]
for i in range(K + 1): for j in range(K): DP[i][j + 1] += DP[i][j]

ans = 0

for i in range(K + 1):
    for j in range(K + 1):
        S1 = DP[i][j] * 2 - DP[i][K] - DP[K][j] + DP[K][K]
        S2 = DP[i][K] + DP[K][j] - DP[i][j] * 2
        ans = max(ans, S1, S2)

print ans + bias

Submission status: Runtime Error

Solution code:
import numpy as np
n, k = map(int, raw_input().split())
hopes = [raw_input().split() for i in range(n)]
hopes = np.array([[int(hope[0]),int(hope[1]),0 if(hope[2]=='W') else 1] for hope in hopes])

mx = np.arange(k)
my = np.arange(k)
mxmx, mymy = np.meshgrid(mx,my)

loc = (hopes[:,0,None,None]-mxmx)/k + (hopes[:,1,None,None]-mymy)/k
cometrue = loc%2
cometrue = (loc%2+hopes[:,2,None,None])%2
ncometrue = np.sum(cometrue,axis=0)
maxhope = np.max(ncometrue)
minhope = np.min(ncometrue)

print max(maxhope,n-minhope)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
M=[[0 for i in range(2*K)] for j in range(2*K)]

for i in range(N):
  a,b,c = map(str,input().split())
  if c == 'W':
    a=(int(a)+K)%(2*K)
    b=int(b)%(2*K)
  else:
    a=int(a)%(2*K)
    b=int(b)%(2*K)
  M[a][b]+=1

for i in range(1,2*K):
  M[i][0]+=M[i-1][0]
  M[0][i]+=M[0][i-1]
  
for i in range(1,2*K):
  for j in range(1,2*K):
    M[i][j]+=(M[i-1][j]+M[i][j-1]-M[i-1][j-1])

def solve(x,y):
  res=0
  if x==0 and y==0:
    res=M[2*K-1][2*K-1]-M[K-1][2*K-1]-M[2*K-1][K-1]+M[K-1][K-1]
  elif x==0:
    res=M[K-1][K-1+y]-M[K-1][y-1]+M[2*K-1][y-1]-M[K-1][y-1]+M[2*K-1][2*K-1]-M[K-1][2*K-1]-M[2*K-1][K-1+y]+M[K-1][K-1+y]
  elif y==0:
    res=M[K-1+x][K-1]-M[x-1][K-1]+M[x-1][2*K-1]-M[x-1][K-1]+M[2*K-1][2*K-1]-M[2*K-1][K-1]-M[K-1+x][2*K-1]+M[K-1+x][K-1]
  else:
    res=M[2*K-1][2*K-1]-((M[x-1][K-1+y]-M[x-1][y-1])+(M[K-1+x][y-1]-M[x-1][y-1])+(M[K-1+x][2*K-1]-M[x-1][2*K-1]-M[K-1+x][K-1+y]+M[x-1][K-1+y])+(M[2*K-1][K-1+y]-M[K-1+x][K-1+y]-M[2*K-1][y-1]+M[K-1+x][y-1]))
return max(res,N-res)
    
ans=0
for i in range(K+1//2):
  for j in range(K+1//2):
    ans=max(ans,solve(i,j))
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
x = y = 0
for i in range(N):
    t, nx, ny = map(int,input().split())
    d = abs(nx - x) + abs(ny - y)
    if t < d or (t - d) % 2==1:
        print(“No”)
        break
else:
    print(“Yes”)

Submission status: Runtime Error

Solution code:
import time

nk = [int(x) for x in raw_input().strip().split()]
d = []
for i in range(nk[0]):
    d_tmp = raw_input().strip().split()
    d.append([int(d_tmp[0]), int(d_tmp[1]), int(d_tmp[2] == 'B')])

n1 = nk[0]
k1 = nk[1]

check_x = [0] * n1 * 4
check_y = [0] * n1 * 4
for i in range(n1):
    check_x[i * 4] = [d[i][0] - k1
    check_x[i * 4 + 1] = d[i][0] - k1 + 1
    check_x[i * 4 + 2] = d[i][0]
    check_x[i * 4 + 3] = d[i][0] + 1
    check_y[i * 4] = [d[i][1] - k1
    check_y[i * 4 + 1] = d[i][1] - k1 + 1
    check_y[i * 4 + 2] = d[i][1]
    check_y[i * 4 + 3] = d[i][1] + 1
check_x = list(set(check_x))
check_y = list(set(check_y))

#d = tuple(d)
n = 0
#t = time.clock()
for i in check_x:
    for j in check_y:
        n_tmp = [0, 0]
        for k in range(n1):
            x = (d[k][0] - i) // k1 % 2
            y = (d[k][1] - j) // k1 % 2
#            if x == y:
#                n_tmp[1 - d[k][2]] += 1
#            else:
#                n_tmp[d[k][2]] += 1
            n_tmp[(x == y) ^ d[k][2]] += 1
        if n_tmp[0] > n:
            n = n_tmp[0]
        if n_tmp[1] > n:
            n = n_tmp[1]
#print time.clock() - t
print n

Submission status: Runtime Error

Solution code:
import numpy as np
N, K = map(int, input().split())
ub = K * 2
b = [[0 for j in range(ub + 1)] for i in range(ub + 1)]
ADD = {"B": 0, "W": K}
 
def create_bound(p, K, ub):
	if p - K + 1 >= 0:
		return [(p - K + 1, p + 1)]
	else:
		return [(0, p + 1), ((p - K + 1) % ub, ub)]
 
for i in range(N):
	x, y, c = input().split()
	nx = int(x) % ub
	ny = (int(y) + ADD[c]) % ub
	for add in [0, K]:
		for xlb, xub in create_bound((nx + add) % ub, K, ub):
			for ylb, yub in create_bound((ny + add) % ub, K, ub):
				b[xlb][ylb] += 1
				b[xlb][yub] -= 1
				b[xub][ylb] -= 1
				b[xub][yub] += 1
 
b_arr = np.array(b)
for i in range(ub):
	b_arr[i + 1, :] += b_arr[i, :]
for j in range(ub):
	b_arr[:, j + 1] += b_arr[:, j]
print(b_arr.max())
import numpy as np
N, K = map(int, input().split())
ub = K * 2
b = [[0 for j in range(ub + 1)] for i in range(ub + 1)]
ADD = {"B": 0, "W": K}

def create_bound(p, K, ub):
	if p - K + 1 >= 0:
		return [(p - K + 1, p + 1)]
	else:
		return [(0, p + 1), ((p - K + 1) % ub, ub)]

for i in range(N):
	x, y, c = input().split()
	nx = int(x) % ub
	ny = (int(y) + ADD[c]) % ub
	for add in [0, K]:
		for xlb, xub in create_bound((nx + add) % ub, K, ub):
			for ylb, yub in create_bound((ny + add) % ub, K, ub):
				b[xlb][ylb] += 1
				b[xlb][yub] -= 1
				b[xub][ylb] -= 1
				b[xub][yub] += 1

b_arr = np.array(b)
for i in range(ub):
	b_arr[i + 1, :] += b_arr[i, :]
for j in range(ub):
	b_arr[:, j + 1] += b_arr[:, j]
print(b_arr.max())
Submission

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# coding=utf-8

import sys

import numpy as np

n, k = map(int, sys.stdin.readline().strip().split(" "))
xyc = [l.strip().split(" ") for l in sys.stdin.readlines()]
xy = [tuple((int(_x), int(_y) if _c == "W" else int(_y) + k)) for (_x, _y, _c) in xyc]
xy = [tuple((_x % (2 * k), _y % (2 * k))) for (_x, _y) in xy]

ans = np.zeros((n, 2 * k, 2 * k), dtype=np.uint8)
for _x, _y in xy:
    check = np.zeros((n, 2 * k, 2 * k), dtype=np.uint8)
    check[_x:_x + k] = 1
    if _x > k:
        check[:_x - k] = 1
    check[:, _y:_y + k] = 1 - check[:, _y:_y + k]
    if _y > k:
        check[:, :_y - k] = 1 - check[:, :_y - k]
    check = 1 - check
    ans += check
print(np.max(ans))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# coding=utf-8

import sys

import numpy as np

n, k = map(int, sys.stdin.readline().strip().split(" "))
xyc = [l.strip().split(" ") for l in sys.stdin.readlines()]
xy = [tuple((int(_x), int(_y) if _c == "W" else int(_y) + k)) for (_x, _y, _c) in xyc]
xy = [tuple((_x % (2 * k), _y % (2 * k))) for (_x, _y) in xy]

ans = np.zeros((n, 2 * k, 2 * k), dtype=int)
for _i, (_x, _y) in enumerate(xy):
    check = np.zeros((2 * k, 2 * k), dtype=int)
    check[_x:_x + k, :] = 1
    if _x > k:
        check[:_x - k, :] = 1
    check[:, _y:_y + k] = 1 - check[:, _y:_y + k]
    if _y > k:
        check[:, :_y - k] = 1 - check[:, :_y - k]
    check = 1 - check
    ans += check
print(np.max(ans))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# coding=utf-8

import sys

import numpy as np

n, k = map(int, sys.stdin.readline().strip().split(" "))
xyc = [l.strip().split(" ") for l in sys.stdin.readlines()]
xy = [tuple((int(_x), int(_y) if _c == "W" else int(_y) + k)) for (_x, _y, _c) in xyc]
xy = [tuple((_x % (2 * k), _y % (2 * k))) for (_x, _y) in xy]

check = np.zeros((n, 2 * k, 2 * k))
for _i, (_x, _y) in enumerate(xy):
    check[_i, _x:_x + k, :] = 1
    if _x > k:
        check[_i, :_x - k, :] = 1
    check[_i, :, _y:_y + k] = 1 - check[_i, :, _y:_y + k]
    if _y > k:
        check[_i, :, :_y - k] = 1 - check[_i, :, :_y - k]
    check[_i] = 1 - check[_i]
print(int(np.max(np.sum(check, axis=0))))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# coding=utf-8

import itertools
import sys

import numpy as np

n, k = map(int, sys.stdin.readline().strip().split(" "))
xyc = [l.strip().split(" ") for l in sys.stdin.readlines()]
xy = [tuple((int(_x), int(_y) if _c == "W" else int(_y) + k)) for (_x, _y, _c) in xyc]
xy = [tuple((_x % (2 * k), _y % (2 * k))) for (_x, _y) in xy]

check = np.zeros((n, 2*k, 2*k))
for _i, (_x, _y) in enumerate(xy):
    for _j, _k in itertools.product(range(2*k), range(2*k)):
        check[_i, _j, _k] = 1 if ((_j - _x) // k + (_k - _y) // k) % 2 == 0 else 0
print(int(np.max(np.sum(check, axis=0))))

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<algorithm>
using namespace std;

#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)

int imos[2005][2005] = {};

int query(int x1, int y1, int x2, int y2){
    if (x1 > x2 || y1 > y2) return 0;
    else{
        return imos[y2][x2] + imos[y1-1][x1-1] - imos[y1-1][x2] - imos[y2][x1-1];
    }
}

int main()
{
    ios::sync_with_stdio(false);
    int N, K, tmp, max_color;
    int max_hope = 0;
    int x, y;
    char c;
    cin >> N >> K;
    int KK = 2*K;
    REP(i, N){
        cin >> x >> y >> c;
        if (c == 'W'){
            y += K;
        }
        x %= KK;
        y %= KK;
        imos[y][x] = 1;
    }
    REP(i, KK){
        REP(j, KK-1){
            imos[i][j+1] += imos[i][j];
        }
    }
    REP(i, KK-1){
        REP(j, KK){
            imos[i+1][j] += imos[i][j];
        }
    }
    REP(i, K){
        REP(j, K){
            tmp = query(i, j, i+K-1, j+K-1) + query(0, 0, i-1, j-1) + query(i+K, j+K, KK-1, KK-1) + query(0, j+K, i-1, KK-1) + query(i+K, 0, KK-1, j-1);
            max_color = max(tmp, N - tmp);
            max_hope = max(max_hope, max_color);
        }
    }
    cout << max_hope << "\n";
    return 0;
}

Submission status: Runtime Error

Solution code:
import numpy as np

N, K = map(int, input().split())
ub = K * 2
bw = {"B": np.full((ub, ub), 0), "W": np.full((ub, ub), 0)}
for i in range(N):
	x, y, c = input().split()
	bw[c][int(x) % ub][int(y) % ub] += 1

def accum_arr(arr):
	acc_h = np.full((ub, ub), 0)
	acc_v = np.full((ub, ub), 0)
	acc = np.full((ub, ub), 0)
	acc_h[:, 0] = arr[:, 0] + arr[:, - (K - 1):].sum(axis=1)
	acc_v[0, :] = arr[0, :] + arr[- (K - 1):, :].sum(axis=0)

	for i in range(1, ub):
		acc_h[:, i] = arr[:, i] + acc_h[:, i - 1] - arr[:, (i - K) % ub]
		acc_v[i, :] = arr[i, :] + acc_v[i - 1, :] - arr[(i - K) % ub, :]

	acc[0][0] = arr[0][0] + arr[0, - (K - 1):].sum() + arr[- (K - 1):, 0].sum() + arr[-(K - 1):, - (K - 1):].sum()

	for j in range(1, ub):
		acc[0][j] = acc[0][j - 1] + acc_v[0][j] - acc_v[0][(j - K) % ub]

	for j in range(ub):
		for i in range(1, ub):
			acc[i][j] = acc[i - 1][j] + acc_h[i][j] - acc_h[(i - K) % ub][j]

	return acc


b_acc = accum_arr(bw["B"])
w_acc = accum_arr(bw["W"])

ans = 0
for x in range(ub):
	for y in range(ub):
		x_cmp = (x + K) % ub
		y_cmp = (y + K) % ub
		tmp_ans = b_acc[x][y] + b_acc[x_cmp][y_cmp] + w_acc[x][y_cmp] + w_acc[x_cmp][y]
		if tmp_ans > ans:
			ans = tmp_ans

print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.exit(1)
N, K = map(int, input().split())
x, y, c = [0] * N, [0] * N, [0] * N
board = [[0] * (2 * K + 1) for i in range(2 * K + 1)]
MOD = 2 * K + 1
for i in range(N):
    x[i], y[i], c[i] = input().split()
    x[i], y[i] = int(x[i]), int(y[i])
    if c[i] == 'W':
        x[i] += K
        c[i] = 'B'
    x[i] %= 2 * K
    y[i] %= 2 * K
    board[y[i]+1][x[i]+1] += 1

for i in range(2*K):
    for j in range(2*K):
        board[i][j+1] += board[i][j]
for j in range(2*K+1):
    for i in range(2*K):
        board[i+1][j] += board[i][j]

# for i in range(2*K+1):
#     print(' '.join(map(str, board[i])))
ans = 0
def c(x1, y1):
    global K, board
    x1 = x1 % MOD + x1 // MOD
    y1 = y1 % MOD + y1 // MOD
    x2 = (x1 + K) % MOD + (x1 + K) // MOD
    y2 = (y1 + K) % MOD + (y1 + K) // MOD
    if x1 < x2:
        x11, x12, x21, x22 = x1, x2, 0, 0
    else:
        x11, x12, x21, x22 = x1, -1, 0, x2
    if y1 < y2:
        y11, y12, y21, y22 = y1, y2, 0, 0
    else:
        y11, y12, y21, y22 = y1, -1, 0, y2
    f = lambda a, b, c, d: board[a][b] + board[c][d]\
            - board[a][d] - board[c][b]
    # print("x11: %d, x12: %d" % (x11, x12))
    # print("x21: %d, x22: %d" % (x21, x22))
    # print("y11: %d, y12: %d" % (y11, y12))
    # print("y21: %d, y22: %d" % (y21, y22))
    # print("a1: %d" % f(y12, x12, y11, x11))
    # print("a2: %d" % f(y22, x22, y21, x21))
    # print("a3: %d" % f(y12, x22, y11, 0))
    # print("a4: %d" % f(y22, x12, 0, x11))
    ret = 0
    ret += f(y12, x12, y11, x11)
    ret += f(y22, x22, y21, x21)
    ret += f(y12, x22, y11, x21)
    ret += f(y22, x12, y21, x11)
    return ret


for i in range(2*K+1):
    for j in range(K+1):
        # print('i: %d, j: %d' % (i, j))
        # print('c(i, j): %d' % c(i, j))
        # print('c(i+K, j+K): %d' % c(i+K, j+K))
        # print('')
        ans = max((ans, c(i, j) + c(i+K, j+K)))

print(ans)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
co = []
result = [[0]*(2*k)]*(2*k)
def int_or_digit(a):
    if a.isdigit():
        return(int(a))
    else:
        return a
    
for i in range(n):
    d = tuple(map(int_or_digit,input().split()))
    if d[2] == "W":
        co.append((d[0]//(2*k),(d[1]+k)//(2*k)))
    else:
        co.append((d[0]//(2*k),d[1]//(2*k)))
        
for x,y in co:
    result[x][y] = 1
    result[x][y+k] = -1
    result[x+k][y] = -1
    result[x+k][y+k] = 1
    
import numpy as np 
ans = np.cumsum(np.cumsum(np.array(result),axis=0),axis=1)
print(str(np.max(ans)))

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
w = []
b = []
result = []
def int_or_digit(a):
    if a.isdigit():
        return(int(a))
    else:
        return a
def a(b,t):
    if (0 <= (b % (2*t))) and ((b%(2*t)) <= t-1):
        return 1
    else:
        return 0
for i in range(n):
    d = tuple(map(int_or_digit,input().split()))
    if d[2] == "W":
        w.append(d)
    else:
        b.append(d)
        
for i in range(len(w)):
    count = 0
    x,y,c = w[i]
    for j in w:
        if (a(j[0]-x,k) + a(j[1]-y,k)) %2 == 0:
            count += 1
    tmp_count = count
    for l in range(len(b)):
        count = tmp_count
        xb,yb,cb = b[i]
        for m in b:
            if (a(m[0]-x,k) + a(m[1]-y,k)) %2 == 1:
                count += 1
        result.append(count)
for i in range(len(w)):
    count = 0
    x,y,c = w[i]
    for j in w:
        if (a(j[0]-x,k) + a(j[1]-y,k)) %2 == 1:
            count += 1
    tmp_count = count
    for l in range(len(b)):
        count = tmp_count
        xb,yb,cb = b[i]
        for m in b:
            if (a(m[0]-x,k) + a(m[1]-y,k)) %2 == 0:
                count += 1
        result.append(count)
print(str(max(result)))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
#%%
def wOrB(strinp,a,b,k):
    [x,y,c] = strinp.split()
    x,y = int(x),int(y)
    x -= a
    y -= b
    if x%(2*k) <= k:
	    if y%(2*k) <= k:
        	col = 'W'
        else:
            col = 'B'
    elif y%(2*k) <= k:
       	col = 'B'
    else:
        col = 'W'
    if col == c:
        ans = 1
    else:
        ans = 0
    return ans

#%%
lst,lstinp = [],[]
n,k = map(int, input().split())
for i in range(n):
    lstinp.append(input())
for a in range(k):
    for b in range(k):
        count = 0
        for i in range(n):
            inp = lstinp[i]
            count += wOrB(inp,a,b,k)
        lst.append(count)
print(max(lst))

Submission status: Runtime Error

Solution code:
N, K = map(int,input().split())
P = [list(input().split()) for _ in range(N)]
a = 0
b = N

for i in range(1, N):
    if P[0][2] == "W":
        if P[i][2] == "W":
            if (((int(P[0][0]) - int(P[i][0]) // K) % 2 == 1 and ((int(P[0][1]) - int(P[i][1]) // K) % 2 == 1) or ((int(P[0][0]) - int(P[i][0]) // K) % 2 == 1 and ((int(P[0][1]) - int(P[i][1]) // K) % 2 == 0:
                a += 1
        else:
            if not ((((int(P[0][0]) - int(P[i][0]) // K) % 2 == 1 and ((int(P[0][1]) - int(P[i][1]) // K) % 2 == 1) or ((int(P[0][0]) - int(P[i][0]) // K) % 2 == 1 and ((int(P[0][1]) - int(P[i][1]) // K) % 2 == 0):
                a += 1
    else:
        if P[i][2] == "B":
            if (((int(P[0][0]) - int(P[i][0]) // K) % 2 == 1 and ((int(P[0][1]) - int(P[i][1]) // K) % 2 == 1) or ((int(P[0][0]) - int(P[i][0]) // K) % 2 == 1 and ((int(P[0][1]) - int(P[i][1]) // K) % 2 == 0:
                a += 1
        else:
            if not ((((int(P[0][0]) - int(P[i][0]) // K) % 2 == 1 and ((int(P[0][1]) - int(P[i][1]) // K) % 2 == 1) or ((int(P[0][0]) - int(P[i][0]) // K) % 2 == 1 and ((int(P[0][1]) - int(P[i][1]) // K) % 2 == 0):
                a += 1
print(max(a,N-a))

Submission status: Runtime Error

Solution code:
# -- coding: utf-8 --
import numpy as np
N, K = map(int, input().split(' '))
w = []
b = []
for i in range(N):
    x, y, c = input().split(' ')
    n = int(x) // K + int(y) // K
    if n % 2 != 0:
        if c == 'W':
            c = 'B'
        else:
            c = 'W'
    modx = int(x) % K
    mody = int(y) % K
    if c == 'W':
        w.append([modx, mody])
    else:
        b.append([modx, mody])
npw = np.array(w)
npb = np.array(b)
npw_min = npw.min(0)
npw_max = npw.max(0)
npb_max = npb.max(0)
npb_min = npb.min(0)
count_w = 0
count_b = 0
for i in npw:
    if npb_min[0] <= i[0] <= npb_max[0] and npb_min[1] <= i[1] <= npb_max[1]:
        count_w += 1
for i in npb:
    if npw_min[0] <= i[0] <= npw_max[0] and npw_min[1] <= i[1] <= npw_max[1]:
        count_b += 1

print(int(N - min(count_b, count_w)))

Submission status: Runtime Error

Solution code:
import math

N,K=map(int,input().rstrip().split(' '))
lst=[]

for i in range(N):
    x,y,col=input().rstrip().split(' ')
    lst.append((int(x),int(y),col))

def reverseCol(src):
    if src=="B":
        return "W"
    else:
        return "B"

def search(xc, yc, lvl, base, okCnt):
    if lvl>=N: return okCnt
    xt,yt,ct=lst[lvl]
    # X方向遷移時の色を判定
    if xt>=xc:
        cnt=math.floor((xt-xc)/K)
    else:
        cnt=math.floor((xc-xt)/K)+1
    if cnt % 2 == 0:
        cCol=base
    else:
        cCol=reverseCol(base)
        #print(base,cCol)
    #print("X方向:",xt,cnt,cCol)
    # Y方向遷移時の色を判定
    if yt>=yc:
        cnt=(yt-yc)/K
    else:
        cnt=(yc-yt)/K+1
    if cnt % 2 == 0:
        cCol=cCol
    else:
        cCol=reverseCol(cCol)
    # 対象の色が一致するか判定
    #print("Y方向:",xt,cCol)
    if cCol==base:
        okCnt=okCnt+1
    return search(xc, yc, lvl+1, base, okCnt)

xs,ys,base=(lst[0])
maxCnt=0
for xx in range(K):
    for yy in range(K):
        xc=xs+xx
        yc=ys+yy
        cnt=search(xc,yc,1,base,0)
        #print(cnt)
        if cnt>maxCnt:
            maxCnt=cnt
print(maxCnt,flush=True)

Submission status: Runtime Error

Solution code:
# -- coding: utf-8 --
import numpy as np
N, K = map(int, input().split(' '))
w = []
b = []
bminx, bminy, bmaxx, bmaxy = [0,0,0,0]
wminx, wminy, wmaxx, wmaxy = [0,0,0,0]
for i in range(N):
    x, y, c = input().split(' ')
    n = int(x) // K + int(y) // K
    if n % 2 != 0:
        if c == 'W':
            c = 'B'
        else:
            c = 'W'
    modx = int(x) % K
    mody = int(y) % K
    if c == 'W':
        w.append([modx, mody])
    else:
        b.append([modx, mody])
npw = np.array(w)
npb = np.array(b)
npw_min = npw.min(0)
npw_max = npw.max(0)
npb_max = npb.max(0)
npb_min = npb.min(0)
count_w = 0
count_b = 0
for i in npw:
    if npb_min[0] <= i[0] <= npb_max[0] and npb_min[1] <= i[1] <= npb_max[1]:
        count_w += 1
for i in npb:
    if npw_min[0] <= i[0] <= npw_max[0] and npw_min[1] <= i[1] <= npw_max[1]:
        count_b += 1

print(N - min(count_b, count_w))

Submission status: Runtime Error

Solution code:
import sys
import math


class Checkered:
    
    def __init__(self,x,y,k):
        self.x=x
        self.y=y
        self.k=k
    
    def getColor(self,x,y):
        """
        return 1:black 0:white
        """
        if self.x==x:
            dif = abs(y-self.y)
            color = math.floor(dif/self.k)%2
            if y>=self.y:
                if color==0:
                    return 1
                else:
                    return 0
            else:
                if color==0:
                    return 0
                else:
                    return 1
        elif self.y==y:
            dif = abs(x-self.x)
            color = math.floor(dif/self.k)%2
            if x>=self.x:
                if color==0:
                    return 1
                else:
                    return 0
            else:
                if color==0:
                    return 0
                else:
                    return 1
        else:
            mid = self.getColor(self.x,y)
            dif = abs(x-self.x)
            color = math.floor(dif/self.k)%2
            if mid == 1:
                if color==0:
                    return 1
                else:
                    return 0
            else:
                if color==0:
                    return 0
                else:
                    return 1
                    
n,k=map(int,input().split())
x=[0]*n
y=[0]*n
c=[0]*n

for i in range(n):
    inp=input().split()
    x[i]=int(inp[0])
    y[i]=int(inp[1])
    if inp[2]=="B":
        c[i] = 1
    else:
        c[i] = 0
        
max=0
                        
for i in range(1,k+1):
    for j in range(1,k+1):
        count=0
        m = Checkered(i,j,k)
        for l in range(n):
            if m.getColor(x[l],y[l]) == c[i]:
                count+=1
        if count == n:
            print(n)
            sys.exit()
        if count > max:
            max = count
            
            
print(max)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split(' '))

ls = [list(input().split(' ')) for _ in range(N)]

cnt_max = 0
for j in range(K):
    for k in range(K):
        new_ls = []
        for i in range(len(ls)):
            x_tmp = int(ls[i][0]) - j
            y_tmp = int(ls[i][1]) - k
            x = x_tmp % K
            y = y_tmp % K
            if (x_tmp // K) + (y_tmp // K) % 2 == 0:
                c = ls[i][2]
            else:
                if ls[i][2] == 'B':
                    c = 'W'
                else:
                    c = 'B'
            new_ls.append([x, y, c])
    

        cnt = max(Counter([new_ls[i][2] for i in range(len(new_ls))]).values())
        if cnt > cnt_max:
            cnt_max = cnt
            
        if cnt_max == N:
            break
        
print(cnt_max)