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: Wrong Answer

Solution code:
import math

N,K = [int(i) for i in input().split()]
X = []
Y = []
C = []
for l in range(N):
    x,y,c = input().split()
    X.append(int(x))
    Y.append(int(y))
    if c == "W":
        C.append(1)
    else:
        C.append(0)

ans = 0
for dx in range(K):
    for dy in range(K):
        a = 0
        for i in range(N):
            if (math.floor((X[i] + dx) / K) % 2 + math.floor((Y[i] + dy) / K)  % 2) % 2 == C[i]:
                a = a + 1
        ans = max(a, N-a)
        if ans == N:
            break
    if ans == N:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from math import ceil
n, k = map(int, input().split())
maxx = 0
lists = []
for i in range(n):
    a = input().split()
    lists.append([int(a[0]), int(a[1]), 0 if a[2] == "W" else 1])
lists = np.array(lists)
for i in range(-ceil((k+1)/4),ceil((k+1)/4), 2):
    for j in range(-ceil((k+1)/4),ceil((k+1)/4), 2):
        l = np.sum((lists[:,0]+i // k + lists[:,1]+j // k) % 2 != lists[:,2])
        maxx = max(maxx, max(l, n - l))
print(maxx)

Submission status: Wrong Answer

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

plan = []

for i in range(N):
    num = raw_input().split()
    plan.append(num)

max_plan = 0

#for i in range(K*K):
#    org_x = i % K
#    org_y = i / K
for i in range(K):
    for j in range(K-i):
        #    print 'In' + str(org_x) + ',' + str(org_y)
        org_x = i
        org_y = i + j

        tmp_max = 0

        tmp_plan = plan[:]
    
        avalable_num = 0

        while len(tmp_plan) > 0:
            p = tmp_plan.pop(0)
#        print p
            p_x = int(p[0])
            p_y = int(p[1])
            p_c = p[2]

            if ((p_c == 'W')and (
                    (((p_x + org_x) / K) + ((p_y + org_y) / K)) % 2 == 0)
                or (p_c == 'B')and (
                    (((p_x + org_x) / K) + ((p_y + org_y) / K)) % 2 == 1)):
                avalable_num += 1
            if (org_x != org_y) and ((p_c == 'W')and (
                    (((p_x + org_y) / K) + ((p_y + org_x) / K)) % 2 == 0)
                or (p_c == 'B')and (
                    (((p_x + org_y) / K) + ((p_y + org_x) / K)) % 2 == 1)):
                avalable_num += 1

            if avalable_num > (N / 2):
                tmp_max = avalable_num
            else:
                tmp_max = N - avalable_num

            if tmp_max > max_plan:
                max_plan = tmp_max

print max_plan

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools

def isBlack(K, shift, pos):
    x = shift[0] + pos[0]
    y = shift[1] + pos[1]

    l = int(x/K) + int(y/K)

    return l % 2 == 0

N, K = tuple(map(int, input().split(' ')))

desires = []

for i in range(N):
    inp = input().split(" ")
    inp[0] = int(inp[0])
    inp[1] = int(inp[1])
    desires.append(inp)

maxim = 0

for s1 in range(N):
    for s2 in range(N):
        shift = (s1, s2)

        count_1 = 0
        count_2 = 0

        for i in range(N):
            isB = isBlack(K, shift, desires[i][:2])

            if isB and desires[i][2] == 'B':
                count_1 += 1
            elif (not isB) and desires[i][2] == 'W':
                count_1 += 1

            if isB and desires[i][2] == 'W':
                count_2 += 1
            elif (not isB) and desires[i][2] == 'B':
                count_2 += 1

            if count_1 + N - i - 1 < maxim and count_2 + N - i - 1 < maxim:
                break

        if maxim < count_1:
            maxim = count_1
        if maxim < count_2:
            maxim = count_2

        if maxim == N:
            break

print(maxim)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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)

Submission status: Wrong Answer

Solution code:
import math

tmp = input().split()
N = int(tmp[0])
K = int(tmp[1])

ichimatsu = [[0 for i in range(K)] for j in range(2*K)]

for i in range(N):
    tmp = input().split()
    x = int(tmp[0])
    y = int(tmp[1])
    c = tmp[2]
    if c == "W":
        x = x + K
    x = x % (2 * K)
    y = y % (2 * K)
    if x >= K and y >= K:
        x = x - K
        y = y - K
    elif x < K and y >= K:
        x = x + K
        y = y - K
    
    ichimatsu[x][y] += 1
    
realmaxok = 0
for k in range(K):
    ok = 0
    for i in range(K):
        for j in range(K):
            ok+=ichimatsu[i][(j + k) % K]

    maxok = ok
    for i in range(K):
        for j in range(K):
            ok-=ichimatsu[0 + i][(j + k) % K]
            ok+=ichimatsu[K + i][(j + k) % K]
            if maxok < ok:
                maxok = ok
    if realmaxok < maxok:
        realmaxok = maxok

print(realmaxok)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

xyc = []
for i in range(N):
    xyc.append(input().split())

Ks = np.zeros(K)
for i in range(K):
    Ks[i] = i

max_count = 0
for i in range(K):
    for j in range(K):
        count = 0
        for l in range(N):
            x = int(xyc[l][0])
            y = int(xyc[l][1])
            c = xyc[l][2]

            if x % (2*K) in (Ks+i) and y % (2*K) in (Ks+j) and c == "W":
                count += 1
            elif not (x % (2*K) in (Ks+i) and y % (2*K) in (Ks+j)) and c == "B":
                count += 1
        if max_count < count:
            max_count = count

print(max_count)

Submission status: Wrong Answer

Solution code:
import sys
import random
INF = 10**10
N,K = map(int,input().split())
x, y, c = [0]*N, [0]*N, [0]*N
minX = INF
minY = INF
maxX = -INF
maxY = -INF

for i in range(N):
	sx,sy,c[i] = map(str,input().split())
	x[i],y[i] = int(sx),int(sy)
	minX = min(minX, x[i])
	minY = min(minY, y[i])
	maxX = max(maxX, x[i])
	maxY = max(maxY, y[i])

# グループの最大幅
maxK = (maxX - minX + K) // K

#for i in range(N):
#	print(x[i],y[i],c[i], file=sys.stderr)

res = 0
group = [0] * N
MAX_N = 1000
iter = 0
while iter < MAX_N:
	# 基準点
	bx = random.randint(minX - K, minX)
	by = random.randint(minY - K, minY)

	# 各点をこの基準点から算出して第何群に入るかを計算する
	for i in range(N):
		kx = (x[i] - bx) // K
		ky = (y[i] - by) // K
		group[i] = ky * maxK + kx

	for col in range(2):
		curr = 0
		if col == 0:
			# 奇数群が白、偶数群が黒
			for i in range(N):
				if group[i] % 2 == 0 and c[i] == 'B':
					curr += 1
				elif group[i] % 2 != 0 and c[i] == 'W':
					curr += 1
		else:
			# 奇数群が黒、偶数群が白
			for i in range(N):
				if group[i] % 2 != 0 and c[i] == 'B':
					curr += 1
				elif group[i] % 2 == 0 and c[i] == 'W':
					curr += 1
		res = max(res, curr)
		iter += 1

print(res)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
a=[]
for i in range(N):
    a.append(input().split())

origin=[0][0]
import numpy as np
Max=0
count=0
for i in range(K):
    for j in range(K):
        count=0
        for k in range(N):
            b=int(a[k][0])+i
            c=int(a[k][1])+j
            if (int((b+1)/K)+int((c+1)/K))%2==0:
                if a[k][2]=='W':
                    count+=1
        hanntenn=N-count
        Max=max(hanntenn,count,Max)
print(Max)

Submission status: Wrong Answer

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 and y%(2*k) <= k:
        col = 'W'
    else:
        col = 'B'
    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: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
N, K = map(int, input().strip().split())
xyc = []
for _ in range(N):
    x, y, c = input().strip().split()
    xyc.append((int(x), int(y), c))

best_count = 0
for i in range((K+1)*(K+1)):
    w_a = len([_xyc for _xyc in xyc if _xyc[2]=='W' and ((_xyc[0]-i%(K+1))//K%2==0 and (_xyc[1]-i//(K+1))//K%2==0) or ((_xyc[0]-i%(K+1))//K%2==1 and (_xyc[1]-i//(K+1))//K%2==1)])
    b_a = len([_xyc for _xyc in xyc if _xyc[2]=='B' and ((_xyc[0]-i%(K+1))//K%2==0 and (_xyc[1]-i//(K+1))//K%2==0) or ((_xyc[0]-i%(K+1))//K%2==1 and (_xyc[1]-i//(K+1))//K%2==1)])
    w_b = len([_xyc for _xyc in xyc if _xyc[2]=='W' and ((_xyc[0]-i%(K+1))//K%2==1 and (_xyc[1]-i//(K+1))//K%2==0) or ((_xyc[0]-i%(K+1))//K%2==0 and (_xyc[1]-i//(K+1))//K%2==1)])
    b_b = len([_xyc for _xyc in xyc if _xyc[2]=='B' and ((_xyc[0]-i%(K+1))//K%2==1 and (_xyc[1]-i//(K+1))//K%2==0) or ((_xyc[0]-i%(K+1))//K%2==0 and (_xyc[1]-i//(K+1))//K%2==1)])
    tmp_best = max(w_a+b_b, b_a+w_b)
    if tmp_best > best_count:
        best_count = tmp_best
    if best_count == N:
        break
print(best_count)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
p=[]
count=[0] * (K*K)
for i in range(N):
  x,y,c=input().split()
  p.append([int(x),int(y),c])
for x,y,c in p:
  for bx in range(K):
    bbx=bx-1
    for by in range(K):
      bby=bx-1
      tx=int( (abs((x-bbx))+1)/K )
      ty=int( (abs((y-bby))+1)/K )
      if ( (tx+ty)%2==0 and c=='W' ):count[by+bx*K]+=1
      elif( (tx+ty)%2==1 and c=='B' ):count[by+bx*K]+=1
maxp=max(count)
minp=N-min(count)
if(maxp > minp):
  print(maxp)
else:
  print(minp)

Submission status: Wrong Answer

Solution code:
import math
def get_while(n):
    cs = []
    ans = []
    for _ in range(n):
        s = input().split(" ")
        cs.append(s[2])
        ans.append([int(s[0]), int(s[1])])
    return ans, cs

def count(base_p, base_c, ps, cs, k):
    #print("count")
    ans = 0
    base_p_ = list(base_p)
    ps_ = list(ps)
    cs_ = list(cs)
    #base_p_ = [base_p_[0] + dx, base_p_[1] + dy]
    for p, c in list(zip(ps,cs)):
        flag = False
        if c == base_c and abs(base_p_[0] - p[0]) % (2 * k) < k and abs(base_p_[1] - p[1]) % (2 * k) < k:
            ans = ans + 1
            flag = True
        if c != base_c and (
                (abs(base_p_[0] - p[0]) % (2 * k) > k and abs(base_p_[1] - p[1]) % (2 * k) < k) or 
                (abs(base_p_[0] - p[0]) % (2 * k) < k and abs(base_p_[1] - p[1]) % (2 * k) > k) or
                (abs(base_p_[0] - p[0]) % (2 * k) > k and abs(base_p_[1] - p[1]) % (2 * k) > k)):
            ans = ans + 1
            flag = True
        #print(base_p_, p, c, flag)
    return ans
def solve(ps, cs, n, k):
    ans = 0
    for b in range(n):
        base_p = ps[b]
        base_c = cs[b]
        if count(base_p, base_c, ps, cs, k) > ans:
            ans = count(base_p, base_c, ps, cs, k) 
    return ans
if __name__ == '__main__':
    n, k = list(map(lambda x: int(x), input().split(" ")))
    ps, cs = get_while(n)
    print(solve(ps, cs, n, k))

Submission status: Wrong Answer

Solution code:
import math

N,K = [int(i) for i in input().split()]
X = []
Y = []
C = []
for l in range(N):
    x,y,c = input().split()
    X.append(int(x))
    Y.append(int(y))
    if c == "W":
        C.append(1)
    else:
        C.append(0)

ans = 0
for dx in range(K):
    for dy in range(K):
        a = 0
        for i in range(N):
            if (math.floor((X[i] - dx) / K) % 2 + math.floor((Y[i] - dy) / K)  % 2) % 2 == C[i]:
                a = a + 1
        ans = max(a, N-a)
        if ans == N:
            break
    if ans == N:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
Input = list(map(int,input().strip().split(' ')))
N = Input[0]
K = Input[1]
InputList = list()
countlist =list()

for i in range(0,N):
    InputList.append(input().strip().split(' '))

for k in range(0,K):
        count = 0
        for i in range(0,N):
            X = int(InputList[i][0])
            Y = int(InputList[i][1]) + k
            if Y % (2*K) >= K and InputList[i][2] == 'B':
                count += 1
            elif Y % (2*K) < K and InputList[i][2] == 'W':
                count += 1
            else:
                count = count
        countlist.append(count)
        
print(max([max(countlist),N-min(countlist)]))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
N, K = map(int, input().strip().split())
xyc = []
for _ in range(N):
    x, y, c = input().strip().split()
    xyc.append((int(x), int(y), c))

best_count = 0
for i in range(K*K):
    w_a = len([_xyc for _xyc in xyc if _xyc[2]=='W' and ((_xyc[0]-i%K)//K%2==0 and (_xyc[1]-i//K)//K%2==0) or ((_xyc[0]-i%K)//K%2==1 and (_xyc[1]-i//K)//K%2==1)])
    b_a = len([_xyc for _xyc in xyc if _xyc[2]=='B' and ((_xyc[0]-i%K)//K%2==0 and (_xyc[1]-i//K)//K%2==0) or ((_xyc[0]-i%K)//K%2==1 and (_xyc[1]-i//K)//K%2==1)])
    w_b = len([_xyc for _xyc in xyc if _xyc[2]=='W' and ((_xyc[0]-i%K)//K%2==1 and (_xyc[1]-i//K)//K%2==0) or ((_xyc[0]-i%K)//K%2==0 and (_xyc[1]-i//K)//K%2==1)])
    b_b = len([_xyc for _xyc in xyc if _xyc[2]=='B' and ((_xyc[0]-i%K)//K%2==1 and (_xyc[1]-i//K)//K%2==0) or ((_xyc[0]-i%K)//K%2==0 and (_xyc[1]-i//K)//K%2==1)])
    tmp_best = max(w_a+b_b, b_a+w_b)
    if tmp_best > best_count:
        best_count = tmp_best
    if best_count == N:
        break
print(best_count)

Submission status: Wrong Answer

Solution code:
import sys
import random
INF = 10**10
N,K = map(int,input().split())
x, y, c = [0]*N, [0]*N, [0]*N
minX = INF
minY = INF
maxX = -INF
maxY = -INF

for i in range(N):
	sx,sy,c[i] = map(str,input().split())
	x[i],y[i] = int(sx),int(sy)
	minX = min(minX, x[i])
	minY = min(minY, y[i])
	maxX = max(maxX, x[i])
	maxY = max(maxY, y[i])

# グループの最大幅
maxK = (maxX - minY + K) // K

#for i in range(N):
#	print(x[i],y[i],c[i], file=sys.stderr)

res = 0
MAX_N = int(1e3)
iter = 0
while iter < MAX_N:
	# 基準点
	bx = random.randint(minX - K - 1, minX + 1)
	by = random.randint(minY - K - 1, minY + 1)

	# 各点をこの基準点から算出して第何群に入るかを計算する
	group = [0] * N
	for i in range(N):
		kx = (x[i] - bx) // K
		ky = (y[i] - by) // K
		group[i] = ky * maxK + kx

	for col in range(2):
		curr = 0
		if col == 0:
			# 奇数群が白、偶数群が黒
			for i in range(N):
				if group[i] % 2 == 0 and c[i] == 'B':
					curr += 1
				elif group[i] % 2 != 0 and c[i] == 'W':
					curr += 1
		else:
			# 奇数群が黒、偶数群が白
			for i in range(N):
				if group[i] % 2 != 0 and c[i] == 'B':
					curr += 1
				elif group[i] % 2 == 0 and c[i] == 'W':
					curr += 1
		res = max(res, curr)
		iter += 1

print(res)

Submission status: Wrong Answer

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,k]=i2()
a=0
x=[0 for i in range(2*k+1)]
y=[0 for i in range(2*k+1)]
for i in range(n):
 sg=input().split()
 s=[int(sg[0]),int(sg[1]),sg[2]]
 if ((s[0]//k+s[1]//k)%2==1 and s[2]=="B") or ((s[0]//k+s[1]//k)%2==0 and s[2]=="W"):
  x[s[0]%k+1]+=1
  x[s[0]%k+k+1]+=-1
  y[s[1]%k+1]+=1
  y[s[1]%k+k+1]+=-1
  
 else:
  a+=1
  x[s[0]%k+1]+=-1
  x[s[0]%k+k+1]+=1
  y[s[1]%k+1]+=-1
  y[s[1]%k+k+1]+=1
for i in range(2*k):
 x[i+1]+=x[i]
 y[i+1]+=y[i]
ma=max(max(x),max(y))
print(a+ma)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
N, K = map(int, input().strip().split())
xyc = []
for _ in range(N):
    x, y, c = input().strip().split()
    xyc.append((int(x), int(y), c))

best_count = 0
for i in range(K*K):
    w_a = len([_xyc for _xyc in xyc if _xyc[2]=='W' and ((_xyc[0]-i%K)//K%2==0 and (_xyc[1]-i//K)//K%2==0) or ((_xyc[0]-i%K)//K%2==1 and (_xyc[1]-i//K)//K%2==1)])
    b_a = len([_xyc for _xyc in xyc if _xyc[2]=='B' and ((_xyc[0]-i%K)//K%2==0 and (_xyc[1]-i//K)//K%2==0) or ((_xyc[0]-i%K)//K%2==1 and (_xyc[1]-i//K)//K%2==1)])
    w_b = len([_xyc for _xyc in xyc if _xyc[2]=='W' and ((_xyc[0]-i%K)//K%2==1 and _xyc[1]//K%2==0) or ((_xyc[0]-i%K)//K%2==0 and (_xyc[1]-i//K)//K%2==1)])
    b_b = len([_xyc for _xyc in xyc if _xyc[2]=='B' and ((_xyc[0]-i%K)//K%2==1 and _xyc[1]//K%2==0) or ((_xyc[0]-i%K)//K%2==0 and (_xyc[1]-i//K)//K%2==1)])
    tmp_best = max(w_a+b_b, b_a+w_b)
    if tmp_best > best_count:
        best_count = tmp_best
    if best_count == N:
        break
print(best_count)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
b = []
for i in range(a[0]):
    b.append(list(map(str, input().split())))
condition = []
for j in range(a[1]):
    for k in range(a[1]):
        case = 0
        for l in range(a[0]):
            if ((int(b[l][0]) -j) // a[1] + (int(b[l][1]) - k) // a[1]) % 2 == 0:
                color = "B"
            else:
                color = "W"
            if b[l][2] == color:
                case = case + 1
        condition.append(case)
print(max(condition))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, K = map(int, (input().split()))

lx, ly = [0] * K * 2, [0] * K * 2
for i in range(N):
    x, y, c = list(input().split())
    x, y = int(x), int(y)

    if c == 'B':
        lx[x % (2 * K)] += 1
        ly[y % (2 * K)] += 1
    else:
        lx[(x + K) % (2 * K)] += 1
        ly[(y + K) % (2 * K)] += 1

ansx, ansy = 0, 0
lx = lx + lx
ly = ly + ly

for i in range(K):
    sx, sy = sum(lx[i:i + K]), sum(ly[i:i + K])
    ansx = max(ansx, sx, N - sx)
    ansy = max(ansy, sy, N - sy)

print(min(ansx, ansy))

Submission status: Wrong Answer

Solution code:
import math
def get_while(n):
    cs = []
    ans = []
    for _ in range(n):
        s = input().split(" ")
        cs.append(s[2])
        ans.append([int(s[0]), int(s[1])])
    return ans, cs

def count(base_p, base_c, ps, cs, k):
    print("count")
    ans = 0
    base_p_ = list(base_p)
    ps_ = list(ps)
    cs_ = list(cs)
    #base_p_ = [base_p_[0] + dx, base_p_[1] + dy]
    for p, c in list(zip(ps,cs)):
        flag = False
        if c == base_c and abs(base_p_[0] - p[0]) % (2 * k) < k and abs(base_p_[1] - p[1]) % (2 * k) < k:
            ans = ans + 1
            flag = True
        if c != base_c and (
                (abs(base_p_[0] - p[0]) % (2 * k) > k and abs(base_p_[1] - p[1]) % (2 * k) < k) or 
                (abs(base_p_[0] - p[0]) % (2 * k) < k and abs(base_p_[1] - p[1]) % (2 * k) > k) or
                (abs(base_p_[0] - p[0]) % (2 * k) > k and abs(base_p_[1] - p[1]) % (2 * k) > k)):
            ans = ans + 1
            flag = True
        print(base_p_, p, c, flag)
    return ans
def solve(ps, cs, n, k):
    ans = 0
    for b in range(n):
        base_p = ps[b]
        base_c = cs[b]
        if count(base_p, base_c, ps, cs, k) > ans:
            ans = count(base_p, base_c, ps, cs, k) 
    return ans
if __name__ == '__main__':
    n, k = list(map(lambda x: int(x), input().split(" ")))
    ps, cs = get_while(n)
    print(solve(ps, cs, n, k))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())		# 5 7

X=[]
Y=[]
C=[]
L=[]

for i in range(N):
	x, y, c = map(str, input().split())		# 5 7 2
	x=int(x)
	y=int(y)
	c = 1 if c=='W' else 0

	X.append(x)
	Y.append(y)
	C.append(c)
	L.append( [x,y,c] )

#print(N, K)
#print(X)
#print(Y)
#print(C)
#print(L)

for i in range(N):
	x, y, c = map(int, L[i])		# 5 7 2
	#print(x, y, c)


# 0番目を、正方形の左下から始めて、他が条件を満たすか調べる
ok_max=0

x0, y0, c0 = map(int, L[0])		# 5 7 2

for kx in range(K):
	for ky in range(K):

		ok=0
		for j in range(N):
			x, y, z = map(int, L[j])		# 5 7 2
			
			c=c0
			a = x-x0+kx
			if (a//K)%2 == 1: c=(c+1)%2
			
			b = y-y0+ky
			if (b//K)%2 == 1: c=(c+1)%2
			
			if c==z: ok += 1

		ok_max = max(ok_max, ok)
		if ok_max==N:
			break

	if ok_max==N:
		break


print(ok_max)

Submission status: Wrong Answer

Solution code:
N,K = [ int(i) for i in  input().split(" ")]
data = [input().split(" ") for i in range(N)]
def judge(start_x,start_y,x,y,c,k):
    x_id =((x - start_x)// k)%2
    y_id = ((y - start_y)// k)%2
    if (x_id ==0 and y_id==0) or (x_id == 1 and y_id ==1):
        ans = "B"
    else:
        ans = "W"
    if c==ans:
        return 1
    else:
        return 0
temp_max = 0
for i in range(K):
    for j in range(K):
        temp_sum = 0
        for l in range(N):
            temp_sum +=judge(i,j,int(data[l][0]),int(data[l][1]),data[l][2],K)
        temp_max = max(temp_max,temp_sum)
print(temp_max)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
X = []
Y = []
C = []

for _ in range(N):
    x, y, c = input().split()
    X.append(x)
    Y.append(y)
    C.append(c)

X = list(map(int, X))
Y = list(map(int, Y))

current_best = 0

for i in range(2*K):
    for j in range(2*K):
        val = 0
        
        temp_X = [(x - i) // K for x in X]
        temp_Y = [(y - j) // K for y in Y]
        flt = [(temp_X[idx] + temp_Y[idx]) % 2 for idx in range(N)]
        color = ['B' for _ in range(N)]
        
        if 1 in flt:
            color[flt.index(1)] = 'W'
        
        for idx in range(N):
            if C[idx] == color[idx]:
                val += 1
        
        if current_best < val:
            current_best = val

print(current_best)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, K = map(int, (input().split()))

lx, ly = [0] * K * 2, [0] * K * 2
for i in range(N):
    x, y, c = list(input().split())
    x, y = int(x), int(y)

    if c == 'B':
        lx[x % (2 * K)] += 1
        ly[y % (2 * K)] += 1
    else:
        lx[(x + K) % (2 * K)] += 1
        ly[(y + K) % (2 * K)] += 1

ansx, ansy = 0, 0

for i in range(K):
    sx, sy = sum(lx[i:i - K]), sum(ly[i:i - K])
    ansx = max(ansx, sx, N - sx)
    ansy = max(ansy, sy, N - sy)

print(min(ansx, ansy))

Submission status: Wrong Answer

Solution code:
import re

temp=input().split(" ")
n=int(temp[0])
k=int(temp[1])
tilew=[[0 for i in range(k)] for j in range(k)]
tileb=[[0 for i in range(k)] for j in range(k)]
for i in range(n):
    temp=input().split(" ")
    x=int(temp[0])
    y=int(temp[1])
    c=temp[2]
    if c=='B':
        tileb[x%k][y%k]+=1
    elif c=='W':
        tilew[x%k][y%k]+=1
ans=0
# print(tileb)
# print(tilew)
# for j in k:
#     for 

for w,b in zip(tilew,tileb):
    for tw,tb in zip(w,b):
        ans+=(abs(tw-tb))

print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
order = []
for i in range(n):
    x_in, y_in, c_in = map(str, input().split())
    order.append([int(x_in), int(y_in), c_in])

num = 0
for i in range(k):
    for j in range(k):
        b_num = 0
        w_num = 0
        for o in order:
            if int((o[0]+i)/k)%2 == 0:
                if int((o[1]+j)/k)%2 == 0:
                    if o[2] == "W":
                        w_num += 1
                    else:
                        b_num += 1
                else:
                    if o[2] == "B":
                        w_num += 1
                    else:
                        b_num += 1
            else:
                if o[2] == "B":
                    w_num += 1
                else:
                    b_num += 1

        num = max(num, b_num, w_num)
        if num == n:
            break

print(num)

Submission status: Wrong Answer

Solution code:
def f1(ox,oy,x,y,c,k):
    if (ox//k+oy//k)%2 != 0:
        if c=='W':
            c='B'
        else:
            c='W'
    x-=ox
    y-=oy
    a=abs(x)//k
    b=abs(y)//k
    c1='n'
    if (a+b)%2==0:
        c1='W'
    else:
        c1='B'
    if c1==c:
        return 1
    else:
        return 0
n,k=map(int,input().split())
l=[]
for i in range(n):
    ll=list(input().split())
    ll[0]=int(ll[0])
    ll[1]=int(ll[1])
    ll[0]+=2*k
    ll[1]+=k
    l.append(ll)
ans=0
for i in range(6):
    for j in range(3):
        ans1=0
        for ii in range(n):
            ans1+=f1(i,j,l[ii][0],l[ii][1],l[ii][2],k)
            #print(i,j,)
        ans=max(ans,ans1)
print(ans)

Submission status: Wrong Answer

Solution code:
N,K=[int(i) for i in raw_input().split()]
list = []
for i in range(N):
	list.append(map(str, raw_input().split()))
for i in range(N):
	list[i][0]=int(list[i][0])
	list[i][1]=int(list[i][1])
max_count = 0
for zero_tate in range(K):#tate
	for zero_yoko in range(K):#yoko
		count = 0
		for i in range(N):
			yoko = (list[i][0]-((K-1)-zero_yoko))/K
			tate = (list[i][1]-((K-1)-zero_tate))/K
			if  (yoko+tate)%2 == 0:
				color = "B"
			else:
				color = "W"
			if color == list[i][2]:
				count += 1
		if count>max_count:
			max_count = count
print(max_count)

Submission status: Wrong Answer

Solution code:
Input = list(map(int,input().strip().split(' ')))
N = Input[0]
K = Input[1]
InputList = list()
countlist =list()

for i in range(0,N):
    InputList.append(input().strip().split(' '))

for j in range(0,K):
    for k in range(0,2*K):
        count = 0
        for i in range(0,N):
            X = int(InputList[i][0]) + j 
            Y = int(InputList[i][1]) + k
            if Y % (2*K) >= K and InputList[i][2] == 'B':
                count += 1
            elif Y % (2*K) < K and InputList[i][2] == 'W':
                count += 1
            else:
                count = count
        countlist.append(count)
        
print(max(countlist))

Submission status: Wrong Answer

Solution code:
def f1(ox,oy,x,y,c,k):
    if (ox//k+oy//k)%2 != 0:
        if c=='W':
            c='B'
        else:
            c='W'
    x-=ox
    y-=oy
    a=abs(x)//k
    b=abs(y)//k
    c1='n'
    if (a+b)%2==0:
        c1='W'
    else:
        c1='B'
    if c1==c:
        return 1
    else:
        return 0
n,k=map(int,input().split())
l=[]
for i in range(n):
    ll=list(input().split())
    ll[0]=int(ll[0])
    ll[1]=int(ll[1])
    ll[0]+=k
    ll[1]+=k
    l.append(ll)
ans=0
for i in range(6):
    for j in range(3):
        ans1=0
        for ii in range(n):
            ans1+=f1(i,j,l[ii][0],l[ii][1],l[ii][2],k)
            #print(i,j,)
        ans=max(ans,ans1)
print(ans)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
b = []
for i in range(a[0]):
    b.append(list(map(str, input().split())))
condition = []
for j in range(a[1]):
    for k in range(a[1]):
        case = 0
        for l in range(a[0]):
            if ((int(b[l][0]) -j) // a[1] + (int(b[l][1]) - k) // a[1]) % 2 == 0:
                color = "B"
            else:
                color = "W"
            if b[l][2] == color:
                case = case + 1
            condition.append(case)
print(max(condition))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
p=[]
for i in range(N):
  x,y,c=input().split()
  p.append([int(x),int(y),c])
res=0
for bx in range(K):
  for by in range(K):
    tmp=0
    for x,y,c in p:
      x=int( (x-bx)/K )
      y=int( (y-by)/K )
      if ( (x+y)%2==0 and c=='W' ):tmp+=1
      elif( (x+y)%2==1 and c=='B' ):tmp+=1
    if(res < tmp):res=tmp
    elif( res < (len(p)-tmp) ):res=len(p)-tmp
print(res)

Submission status: Wrong Answer

Solution code:
import random
n,k=map(int,input().split())
x=[]
for i in range(n):
    x.append(input().split())
print(random.randint(0,k))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-

def solve():
    import numpy as np
    N, K = list(map(int, input().split()))
    grid = [[0 for _ in range(2*K)] for __ in range(K)]
    # grid = np.array(grid)

    for _ in range(N):
        x, y, c = input().split()
        x, y = int(x), int(y)
        # 全部Bに変換する
        if c == "W":
            x += K
        # x,yを[0,2K)の範囲に変換する
        x, y = x%(2*K), y%(2*K)
        # [(0,0), (K, 2K))の範囲に変換する。
        # (変換1) (x+K, y+K) -> (x, y)
        # (変換2) (x+K, y) -> (x, y+K)
        if x >= K and y >= K:
            x, y = x-K, y-K
        if x >= K:
            x, y = x-K, y+K
        grid[x][y] += 1  # 希望の位置を+1にする

        # # x=Kの線対称変換？
        # if x>=K:
        #     x -= abs(K-x)*2+1
        # grid[x][y] += 1



    # 2次元累積和rを作る
    r = [[0 for _ in range(2*K+1)] for __ in range(K+1)]
    r[1][1] = grid[0][0]
    for x in range(1, K):
        r[x+1][1] = r[x][1] + grid[x][0]
    for y in range(1, 2*K):
        r[1][y+1] = r[1][y] + grid[0][y]

    for x in range(1, K):
        for y in range(1, 2*K):
            r[x+1][y+1] = r[x+1][y] + r[x][y+1] - r[x][y] + grid[x][y]


    def calc(x1, y1, x2, y2):
        """[(x1,y1), (x2,y2)]の範囲の累積和を返す"""
        return r[x2+1][y2+1] - r[x2+1][y1] - r[x1][y2+1] + r[x1][y1]

    # 答えを探索する
    ans = 0
    for x in range(K):
        for y in range(2*K):
            total = 0
            if y+K-1 >= 2*K and x+K-1 >= K:
                # xとyが境界をまたぐとき
                x1, y1 = x, y
                x2, y2 = K-1, 2*K-1
                total += calc(x1, y1, x2, y2)

                x3, y3 = x, 0
                x4, y4 = K-1, (y+K-1)%(2*K)
                total += calc(x3, y3, x4, y4)

                x5, y5 = 0, y4+1
                x6, y6 = x1-1, y1-1
                total += calc(x5, y5, x6, y6)

            elif y+K-1 >= 2*K:
                # yのみが境界をまたぐとき
                x1, y1 = 0, y
                x2, y2 = K-1, 2*K-1
                total += calc(x1, y1, x2, y2)

                x3, y3 = 0, 0
                x4, y4 = K-1, (y+K-1)%(2*K)
                total += calc(x3, y3, x4, y4)

            elif x+K-1 >= K:
                # xのみが境界をまたぐとき
                x1, y1 = x, y
                x2, y2 = K-1, y+K-1
                total += calc(x1, y1, x2, y2)

                if y2+1 < 2*K:
                    x3, y3 = 0, y2+1
                    x4, y4 = x-1, 2*K-1
                    total += calc(x3, y3, x4, y4)

                    x5, y5 = 0, 0
                    x6, y6 = x-1, y-1
                    total += calc(x5, y5, x6, y6)
                else:
                    x3, y3 = 0, y2+1
                    x4, y4 = x-1, 2*K-1
                    total += calc(x3, y3, x4, y4)
            else:
                # xもyもまたがないとき
                x1, y1 = x, y
                x2, y2 = x+K-1, y+K-1
                total += calc(x1, y1, x2, y2)
            ans = max(ans, total)
    print(ans)


if __name__ == "__main__":
    solve()