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 sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = map(int, readline().split())
    l = 2 * k
    grid = [[0] * (2 * l) for _ in range(2 * l)]

    for i in range(n):
        x, y, c = input().split()
        x, y = int(x), int(y)
        if c == "W":
            x += k
        mx, my = x % l, y % l
        grid[mx][my] += 1
        grid[mx + k][my] -= 1
        grid[mx][my + k] -= 1
        grid[mx + k][my + k] += 1
        grid[mx + k][my + k] += 1
        grid[mx + 2 * k][my + k] -= 1
        grid[mx + k][my + 2 * k] -= 1
        grid[mx + 2 * k][my + 2 * k] += 1

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

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

    count = [[0] * l for _ in range(l)]

    for x in range(2 * l):
        for y in range(2 * l):
            count[x % l][y % l] += grid[x][y]
    ans = 0
    for x in range(l):
        for y in range(l):
            ans = max(ans, count[x][y])

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# N=int(input())

N,K=map(int,input().split())
white=[]
black=[]

for i in range(N):
    array = []
    x,y,c = map(str,input().split())
    x=int(x)
    y=int(y)
    K_2=2*K

    array=[[x,y],[x+K_2,y],[x-K_2,y],[x,y+K_2],[x,y-K_2]]
    array_op=[[x+K,y],[x-K,y],[x,y+K],[x,y-K]]
    if c == "W":
        for j_w in array:
            if (j_w in white)==False:
                white.append(j_w)
            else:
                print(i)
                exit()
        for j_w_op in array_op:
            if (j_w_op in black)==False:
                black.append(j_w_op)
            else:
                print(i)
                exit()

    elif c == "B":
        for j_b in array:
            if (j_b in black)==False:
                black.append(j_b)
            else:
                print(i)
                exit()
        for j_b_op in array_op:
            if (j_b_op in white)==False:
                white.append(j_b_op)
            else:
                print(i)
                exit()

print(i+1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
MX = 2*K
A = [[0]*MX for _ in range(MX)]
for i in range(N):
    x, y, c = input().split()
    x, y = int(x), int(y)
    if c == "W":
        y += K
    A[y%MX][x%MX] += 1
S = [[0]*(MX+1) for _ in range(MX+1)]
for y in range(MX):
    for x in range(MX):
        S[y+1][x+1] = S[y+1][x] + S[y][x+1] - S[y][x] + A[y][x]
ans = 0
for y in range(K, MX+1):
    for x in range(K, MX+1):
        s = S[y][x] - S[y-K][x] - S[y][x-K] + S[y-K][x-K]
        s2 = S[y-K][x-K]
        s3 = S[MX][x-K] - S[y][x-K]
        s4 = S[y-K][MX] - S[y-K][x]
        s5 = S[MX][MX] - S[y][MX] - S[MX][x] + S[y][x]
        ans = max(ans, s+s2+s3+s4+s5)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def main():
    N, K = map(int, input().split())
    black = [[0]*(2*K) for _ in range(2*K)]
    for i in range(N):
        x, y, c = input().split()
        x, y = int(x), int(y)
        if c == "B":
            black[x % (2*K)][y % (2*K)] += 1
        else:
            black[(x+K) % (2*K)][y % (2*K)] += 1
    for i in range(2*K):
        for j in range(1, 2*K):
            black[i][j] += black[i][j-1]
    for i in range(1, 2*K):
        for j in range(2*K):
            black[i][j] += black[i-1][j]
    # print(*black, sep="\n")
    # return
    # print(*white, sep="\n")
    mtot = 0
    mi = 0
    for offx in range(K+1):
        for offy in range(K+1):
            if offx == offy == K:
                continue
            tot = 0
            # 領域1
            if 0 <= offx-1 and 0 <= offy-1:
                tot += black[offx-1][offy-1]
            # 領域2
            # if 0 <= offy-1:
            #     tot += white[offx-1+K][offy-1]
            #     if 0 <= offx-1:
            #         tot += -white[offx-1][offy-1]
            # 領域3
            if 0 <= offy-1 and offx+K < 2*K:
                tot += black[-1][offy-1]
                tot += -black[offx-1+K][offy-1]
            # 領域4
            # if 0 <= offx-1:
            #     tot += white[offx-1][offy-1+K]
            #     if 0 <= offy-1:
            #         tot -= white[offx-1][offy-1]
            # 領域5
            tot += black[offx-1+K][offy-1+K]
            if 0 <= offx-1:
                tot -= black[offx-1][offy-1+K]
            if 0 <= offy-1:
                tot -= black[offx-1+K][offy-1]
            if 0 <= offx-1 and 0 <= offy-1:
                tot += black[offx-1][offy-1]
            # 領域6
            # if offx+K < 2*K:
            #     tot += white[-1][offy-1+K]
            #     tot -= white[offx-1+K][offy-1+K]
            #     if 0 <= offy-1:
            #         tot -= white[-1][offy-1]
            #         tot += white[offx-1+K][offy-1]
            # 領域7
            if 0 <= offx-1 and offy+K < 2*K:
                tot += black[offx-1][-1]
                tot -= black[offx-1][offy-1+K]
            # 領域8
            # if offy+K < 2*K:
            #     tot += white[offx-1+K][-1]
            #     tot -= white[offx-1+K][offy-1+K]
            #     if 0 <= offx-1:
            #         tot -= white[offx-1][-1]
            #         tot += white[offx-1][offy-1+K]
            # 領域9
            if offy+K < 2*K and offx+K < 2*K:
                tot += black[-1][-1]
                tot -= black[-1][offy-1+K]
                tot -= black[offx-1+K][-1]
                tot += black[offx-1+K][offy-1+K]

            if mtot < tot:
                mtot = tot
                mi = (offx, offy)
            # mtot = max(mtot, tot)

    print(mtot)
    # print(mi)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def main():
    N, K = map(int, input().split())
    black = [[0]*(2*K) for _ in range(2*K)]
    white = [[0]*(2*K) for _ in range(2*K)]
    for i in range(N):
        x, y, c = input().split()
        x, y = int(x), int(y)
        if c == "B":
            black[x % (2*K)][y % (2*K)] += 1
        else:
            white[x % (2*K)][y % (2*K)] += 1
    for i in range(2*K):
        for j in range(1, 2*K):
            black[i][j] += black[i][j-1]
            white[i][j] += white[i][j-1]
    for i in range(1, 2*K):
        for j in range(2*K):
            black[i][j] += black[i-1][j]
            white[i][j] += white[i-1][j]
    # print(*black, sep="\n")
    # print(*white, sep="\n")
    mtot = 0
    for offx in range(K+1):
        for offy in range(K+1):
            if offx == offy == K:
                continue
            tot = 0
            # 領域1
            if 0 <= offx-1 and 0 <= offy-1:
                tot += black[offx-1][offy-1]
            # 領域2
            if 0 <= offy-1:
                tot += white[offx-1+K][offy-1]
                if 0 <= offx-1:
                    tot += -white[offx-1][offy-1]
            # 領域3
            if 0 <= offy-1 and offx+K < 2*K:
                tot += black[-1][offy-1]
                tot += -black[offx-1+K][offy-1]
            # 領域4
            if 0 <= offx-1:
                tot += white[offx-1][offy-1+K]
                if 0 <= offy-1:
                    tot -= white[offx-1][offy-1]
            # 領域5
            tot += black[offx-1+K][offy-1+K]
            if 0 <= offx-1:
                tot -= black[offx-1][offy-1+K]
            if 0 <= offy-1:
                tot -= black[offx-1+K][offy-1]
            if 0 <= offx-1 and 0 <= offy-1:
                tot += black[offx-1][offy-1]
            # 領域6
            if offx+K < 2*K:
                tot += white[-1][offy-1+K]
                tot -= white[offx-1+K][offy-1+K]
                if 0 <= offy-1:
                    tot -= white[-1][offy-1]
                    tot += white[offx-1+K][offy-1]
            # 領域7
            if 0 <= offx-1 and offy+K < 2*K:
                tot += black[offx-1][-1]
                tot -= black[offx-1][offy-1+K]
            # 領域8
            if offy+K < 2*K:
                tot += white[offx-1+K][-1]
                tot -= white[offx-1+K][offy-1+K]
                if 0 <= offx-1:
                    tot -= white[offx-1][-1]
                    tot += white[offx-1][offy-1+K]
            # 領域9
            if offy+K < 2*K and offx+K < 2*K:
                tot += black[-1][-1]
                tot -= black[-1][offy-1+K]
                tot -= black[offx-1+K][-1]
                tot += black[offx-1+K][offy-1+K]

            mtot = max(mtot, tot)

    print(mtot)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def main():
    N, K = map(int, input().split())
    black = [[0]*(2*K) for _ in range(2*K)]
    white = [[0]*(2*K) for _ in range(2*K)]
    for i in range(N):
        x, y, c = input().split()
        x, y = int(x), int(y)
        if c == "B":
            black[x % (2*K)][y % (2*K)] += 1
        else:
            white[x % (2*K)][y % (2*K)] += 1
    for i in range(2*K):
        for j in range(1, 2*K):
            black[i][j] += black[i][j-1]
            white[i][j] += white[i][j-1]
    for i in range(1, 2*K):
        for j in range(2*K):
            black[i][j] += black[i-1][j]
            white[i][j] += white[i-1][j]
    # print(*black, sep="\n")
    # print(*white, sep="\n")
    mtot = 0
    for offx in range(K):
        for offy in range(K):
            if offx == offy == K:
                continue
            tot = 0
            if 0 <= offx-1 and 0 <= offy-1:
                tot += 2*black[offx-1][offy-1]
                tot += -2*white[offx-1][offy-1]
            if 0 <= offy-1:
                tot += -2*black[offx-1+K][offy-1]
                tot += 2*white[offx-1+K][offy-1]
                tot += black[-1][offy-1]
                tot += -white[-1][offy-1]
            if 0 <= offx-1:
                tot += -2*black[offx-1][offy-1+K]
                tot += black[offx-1][-1]
                tot += 2*white[offx-1][offy-1+K]
                tot += -white[offx-1][-1]
            tot += 2*black[offx-1+K][offy-1+K]
            tot += -black[offx-1+K][-1]
            tot += -black[-1][offy-1+K]
            tot += black[-1][-1]
            tot += -2*white[offx-1+K][offy-1+K]
            tot += white[offx-1+K][-1]
            tot += white[-1][offy-1+K]
            mtot = max(mtot, tot)

    offx = K
    for offy in range(K):
        tot = 0
        if 0 <= offy-1:
            tot += 2*black[offx-1][offy-1]
            tot += -black[-1][offy-1]
            tot += -2*white[offx-1][offy-1]
            tot += white[-1][offy-1]
        tot += -2*black[offx-1][offy-1+K]
        tot += black[offx-1][-1]
        tot += black[-1][offy-1+K]
        tot += 2*white[offx-1][offy-1+K]
        tot += -white[offx-1][-1]
        tot += -white[-1][offy-1+K]
        tot += white[-1][-1]
        mtot = max(mtot, tot)

    offy = K
    for offx in range(K):
        tot = 0
        if 0 <= offx-1:
            tot += 2*black[offx-1][offy-1]
            tot += -black[offx-1][-1]
            tot += -2*white[offx-1][offy-1]
            tot += white[offx-1][-1]
        tot += -2*black[offx-1+K][offy-1]
        tot += black[offx-1+K][-1]
        tot += black[-1][offy-1]
        tot += 2*white[offx-1+K][offy-1]
        tot += -white[offx-1+K][-1]
        tot += -white[-1][offy-1]
        tot += white[-1][-1]
        mtot = max(mtot, tot)

    print(mtot)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def main():
    N, K = map(int, input().split())
    black = [[0]*(2*K) for _ in range(2*K)]
    white = [[0]*(2*K) for _ in range(2*K)]
    for i in range(N):
        x, y, c = input().split()
        x, y = int(x), int(y)
        if c == "B":
            black[x % (2*K)][y % (2*K)] += 1
        else:
            white[x % (2*K)][y % (2*K)] += 1
    for i in range(2*K):
        for j in range(1, 2*K):
            black[i][j] += black[i][j-1]
            white[i][j] += white[i][j-1]
    for i in range(1, 2*K):
        for j in range(2*K):
            black[i][j] += black[i-1][j]
            white[i][j] += white[i-1][j]
    # print(*black, sep="\n")
    # print(*white, sep="\n")
    mtot = 0
    for offx in range(K):
        for offy in range(K):
            tot = 0
            if 0 <= offx-1 and 0 <= offy-1:
                tot += 2*black[offx-1][offy-1]
                tot -= 2*white[offx-1][offy-1]
            if 0 <= offy-1:
                tot -= 2*black[offx-1+K][offy-1]
                tot += black[-1][offy-1]
                tot += 2*white[offx-1+K][offy-1]
                tot -= white[-1][offy-1]
            if 0 <= offx-1:
                tot -= 2*black[offx-1][offy-1+K]
                tot += black[offx-1][-1]
                tot += 2*white[offx-1][offy-1+K]
                tot -= white[offx-1][-1]
            tot += 2*black[offx-1+K][offy-1+K]
            tot -= black[offx-1+K][-1]
            tot -= black[-1][offy-1+K]
            tot += black[-1][-1]
            tot -= 2*white[offx-1+K][offy-1+K]
            tot += white[offx-1+K][-1]
            tot += white[-1][offy-1+K]

            mtot = max(mtot, tot)
    print(mtot)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def main():
    N, K = map(int, input().split())
    black = [[0]*(2*K) for _ in range(2*K)]
    white = [[0]*(2*K) for _ in range(2*K)]
    for i in range(N):
        x, y, c = input().split()
        x, y = int(x), int(y)
        if c == "B":
            black[x % (2*K)][y % (2*K)] += 1
        else:
            white[x % (2*K)][y % (2*K)] += 1
    for i in range(2*K):
        for j in range(1, 2*K):
            black[i][j] += black[i][j-1]
            white[i][j] += white[i][j-1]
    for i in range(1, 2*K):
        for j in range(2*K):
            black[i][j] += black[i-1][j]
            white[i][j] += white[i-1][j]
    # print(*black, sep="\n")
    # print(*white, sep="\n")
    mtot = 0
    for offx in range(K):
        for offy in range(K):
            tot = 0
            # 領域1
            if 0 <= offx-1 and 0 <= offy-1:
                tot += black[offx-1][offy-1]
            # 領域2
            if 0 <= offy-1:
                tot += black[2*K-1][offy-1]
                tot -= black[offx-1+K][offy-1]
            # 領域3
            if 0 <= offx-1:
                tot += black[offx-1][2*K-1]
                tot -= black[offx-1][offy-1+K]
            # 領域4
            tot += black[2*K-1][2*K-1]
            tot -= black[offx-1+K][offy-1+K]
            # 領域5
            tot += black[offx-1+K][offy-1+K]
            if 0 <= offy-1:
                tot -= black[offx-1+K][offy-1]
            if 0 <= offx-1:
                tot -= black[offx-1][offy-1+K]
            if 0 <= offx-1 and 0 <= offy-1:
                tot += black[offx-1][offy-1]

            # 領域6
            if 0 <= offy-1:
                tot += white[offx-1+K][offy-1]
                if 0 <= offx-1:
                    tot -= white[offx-1][offy-1]
            # 領域7
            if 0 <= offx-1:
                tot += white[offx-1][offy-1+K]
                if 0 <= offy-1:
                    tot -= white[offx-1][offy-1]
            # 領域8
            tot += white[2*K-1][offy-1+K]
            tot -= white[offx-1+K][offy-1+K]
            if 0 <= offy-1:
                tot -= white[2*K-1][offy-1]
                tot += white[offx-1+K][offy-1]
            # 領域9
            tot += white[offx-1+K][2*K-1]
            tot -= white[offx-1+K][offy-1+K]
            if 0 <= offx-1:
                tot -= white[offx-1][2*K-1]
                tot += white[offx-1][offy-1+K]

            mtot = max(mtot, tot)
    print(mtot)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def main():
    N, K = map(int, input().split())
    black = [[0]*(2*K) for _ in range(2*K)]
    white = [[0]*(2*K) for _ in range(2*K)]
    for i in range(N):
        x, y, c = input().split()
        x, y = int(x), int(y)
        if c == "B":
            black[x % (2*K)][y % (2*K)] += 1
        else:
            white[x % (2*K)][y % (2*K)] += 1
    for i in range(2*K):
        for j in range(1, 2*K):
            black[i][j] += black[i][j-1]
            white[i][j] += white[i][j-1]
    for i in range(1, 2*K):
        for j in range(2*K):
            black[i][j] += black[i-1][j]
            white[i][j] += white[i-1][j]
    # print(*black, sep="\n")
    # print(*white, sep="\n")
    M = 2*K
    mtot = 0
    for offx in range(K):
        for offy in range(K):
            tot = 0
            if 0 <= offx-1 and 0 <= offy-1:
                tot += 2*black[offx-1][offy-1]
            if 0 <= offy-1:
                tot += black[-1][offy-1]
                tot -= 2*black[offx-1+K][offy-1]
            if 0 <= offx-1:
                tot += black[offx-1][-1]
                tot -= 2*black[offx-1][offy-1+K]
            tot += black[-1][-1]

            # 領域6
            if 0 <= offy-1:
                tot += 2*white[offx-1+K][offy-1]
                tot -= white[-1][offy-1]
            if 0 <= offx-1:
                tot += 2*white[offx-1][offy-1+K]
                tot -= white[offx-1][-1]
            if 0 <= offx-1 and 0 <= offy-1:
                tot -= 2*white[offx-1][offy-1]
            tot += white[-1][offy-1+K]
            tot -= 2*white[offx-1+K][offy-1+K]
            tot += white[offx-1+K][-1]

            mtot = max(mtot, tot)
    print(mtot)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    black = [[0]*(2*K+1) for _ in range(2*K+1)]
    white = [[0]*(2*K+1) for _ in range(2*K+1)]
    for i in range(N):
        x, y, c = input().split()
        x, y = int(x), int(y)
        if c == "B":
            black[1+x % (2*K)][1+y % (2*K)] += 1
        else:
            white[1+x % (2*K)][1+y % (2*K)] += 1
    for i in range(2*K+1):
        for j in range(1, 2*K+1):
            black[i][j] += black[i][j-1]
            white[i][j] += white[i][j-1]
    for i in range(1, 2*K+1):
        for j in range(2*K+1):
            black[i][j] += black[i-1][j]
            white[i][j] += white[i-1][j]
    # print(*black, sep="\n")
    # print(*white, sep="\n")
    M = 2*K
    mtot = 0
    for offx in range(K):
        for offy in range(K):
            tot = 0
            tot += 2*black[offx][offy]
            tot -= 2*black[offx+K][offy]
            tot -= 2*black[offx][offy+K]
            tot += black[-1][offy]
            tot += black[offx][-1]
            tot += black[-1][-1]

            # 領域6
            tot += 2*white[offx+K][offy]
            tot += 2*white[offx][offy+K]
            tot -= 2*white[offx][offy]
            tot -= 2*white[offx+K][offy+K]
            tot -= white[-1][offy]
            tot += white[-1][offy+K]
            tot -= white[offx][-1]
            tot += white[offx+K][-1]

            mtot = max(mtot, tot)
    print(mtot)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 縦K、横2*Kの長方形に全ての希望をWとして入れる
# numpyの累積和、最後にmaxをとる
N, K = lr()
table = [[0] * 2*K for _ in range(K)]
for _ in range(N):
    x, y, c = sr().split()
    x = int(x); y = int(y)
    if c == 'B':
        x -= K  # ここで全てWとして扱える
    x %= 2 * K; y %= 2 * K
    if x >= K and y >= K:
        x -= K; y -= K
    elif y >= K:
        x += K; y -= K
    # 長方形に入った
    table[y][x] += 1

table = np.array(table, dtype=np.int32)
table2 = np.roll(table, K, axis=1)
table = np.concatenate([table, table2], axis=0)
table_cum = table.cumsum(axis=1).cumsum(axis=0)
prev = table_cum.copy()
table_cum[:, K:] -= prev[:, :-K]
table_cum[K:, :] -= prev[:-K, :]
table_cum[K:, K:] += prev[:-K, :-K]
answer = table_cum.max()
print(answer)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 縦K、横2*Kの長方形に全ての希望をWとして入れる
# numpyの累積和、最後にmaxをとる
N, K = lr()
table = [[0] * 2*K for _ in range(K)]
for _ in range(N):
    x, y, c = sr().split()
    x = int(x); y = int(y)
    if c == 'B':
        y -= K  # ここで全てWとして扱える
    x %= 2 * K; y %= 2 * K
    if x >= K and y >= K:
        x -= K; y -= K
    elif y >= K:
        x += K; y -= K
    # 長方形に入った
    table[y][x] += 1

table = np.array(table, dtype=np.int32)
table_cum = table.cumsum(axis=1).cumsum(axis=0)
table_cum[:, K:] -= table_cum[:, :-K]
answer = table_cum.max()
print(answer)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
ab = [list(input().split()) for _ in range(n)]

dpb=[[ 0 for i in range(k)] for j in range(k)]
dpw=[[ 0 for i in range(k)] for j in range(k)]

for i in range(n):
    x = int(ab[i][0]) % k
    y = int(ab[i][0]) % k
    z = (int(ab[i][0])//k + int(ab[i][1])//k) % 2
    if ab[i][2] =="B" and z ==0:
        dpb[x][y] +=1
    elif ab[i][2] =="W" and z ==1:
        dpb[x][y] +=1
    else:
        dpw[x][y] +=1

import itertools
dpbl =[]
dpwl =[]

for i in range(k):
    x = list(itertools.accumulate(dpb[i]))
    dpbl.append(x)

for i in range(k):
    x = list(itertools.accumulate(dpw[i]))
    dpwl.append(x)


dpbl_t = [list(x) for x in zip(*dpbl)]
dpwl_t = [list(x) for x in zip(*dpwl)]

dpblt =[]
dpwlt =[]

for i in range(k):
    x = list(itertools.accumulate(dpbl_t[i]))
    dpblt.append(x)

for i in range(k):
    x = list(itertools.accumulate(dpwl_t[i]))
    dpwlt.append(x)
  
res = 0
temp = 0
for i in range(k):
    for j in range(k):
        temp = dpblt[i][j]
        tempp = n-temp
    res = max(res,temp,tempp)
    temp = 0

print(res)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
ab = [list(input().split()) for _ in range(n)]

dpb=[[ 0 for i in range(k)] for j in range(k)]
dpw=[[ 0 for i in range(k)] for j in range(k)]

for i in range(n):
    x = int(ab[i][0]) % k
    y = int(ab[i][0]) % k
    z = (int(ab[i][0])//k + int(ab[i][1])//k) % 2
    if ab[i][2] =="B" and z ==0:
        dpb[x][y] +=1
    elif ab[i][2] =="W" and z ==1:
        dpb[x][y] +=1
    else:
        dpw[x][y] +=1


res = 0

for i in range(k):
    for j in range(k):
        res += max(dpb[i][j],dpw[i][j])

print(res)

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, K = map(int, input().split())
X, Y, C = [[0] * N for _ in range(3)]

mem = [[0] * (4 * K + 1) for _ in range(4 * K + 1)]

for i in range(N):
    S = input().split()
    X[i], Y[i], C[i] = int(S[0]), int(S[1]), S[2]
    x, y = X[i] % (2 * K) + 1, (Y[i] + (K if C[i] == "W" else 0)) % (2 * K) + 1
    mem[x][y] += 1
    mem[x + K][y] -= 1
    mem[x][y + K] -= 1
    mem[x + K][y + K] += 1

for h in range(1, 4 * K + 1):
    for w in range(1, 4 * K + 1):
        mem[h][w] += mem[h - 1][w] + mem[h][w - 1] - mem[h - 1][w - 1]

ans = 0
for h in range(2 * K + 1):
    for w in range(2 * K + 1):
        s = mem[h][w] + mem[h + 2 * K][w] + mem[h][w + 2 * K] + mem[h + K][w + K] + mem[h + 2 * K][w + 2 * K]
        ans = max(ans, s)

print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = [[0 for _ in range(k+1)] for _ in range(k+1)]
e = [[0 for _ in range(k+1)] for _ in range(k+1)]

for _ in range(n):
    x, y, c = input().split()
    x, y = int(x), int(y)

    res = (x // k + y // k) % 2
    if (res == 0 and c == 'B') or (res == 1 and c == 'W'):
        d[x%k+1][y%k+1] += 1
    else:
        e[x%k+1][y%k+1] += 1

for i in range(k+1):
    for j in range(k):
        d[i][j+1] += d[i][j]
        e[i][j+1] += e[i][j]

for j in range(k+1):
    for i in range(k):
        d[i+1][j] += d[i][j]
        e[i+1][j] += e[i][j]


ans = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        res_d = d[-1][-1] - d[i-1][-1] - d[-1][j-1] + 2 * d[i-1][j-1]
        res_e = e[-1][-1] - e[i-1][-1] - e[-1][j-1] + 2 * e[i-1][j-1]
        ans = max(ans,res_d, res_e)

print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = [[0 for _ in range(k+1)] for _ in range(k+1)]

for _ in range(n):
    x, y, c = input().split()
    x, y = int(x), int(y)

    res = (x // k + y // k) % 2
    if (res == 0 and c == 'B') or (res == 1 and c == 'W'):
        d[x%k+1][y%k+1] += 1

for i in range(k+1):
    for j in range(k):
        d[i][j+1] += d[i][j]

for j in range(k+1):
    for i in range(k):
        d[i+1][j] += d[i][j]


ans = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        res = d[-1][-1] - d[i-1][-1] - d[-1][j-1] + 2 * d[i-1][j-1]
        ans = max(ans, max(res, n - res))

print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
MI = [['W']*k + ['B']*k for _ in range(k)] + [['B']*k + ['W']*k for _ in range(k)]
MC = dict()

for _ in range(n):
    x, y, c = input().split()
    x = int(x)%(2*k)
    y = int(y)%(2*k)

    MC.setdefault((x, y), 0)
    if c == 'B':
        MC[(x, y)] -= 1
    else:
        MC[(x, y)] += 1

ans = 0
for i in range(2*k):
    for j in range(2*k):
        tmp = 0
        for (x, y), v in MC.items():
            if MI[(x+i)%(2*k)][(y+j)%(2*k)] == 'B':
                tmp += max(0, -v)
            else:
                tmp += max(0, v)
        ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n,k = map(int,input().split())
    e = [[0]*(2*k) for i in range(2*k)]
    mod = 2*k
    for i in range(n):
        x,y,c = input().split()
        if c == "W":
            x = int(x)%mod
            y = (int(y)+k)%mod
        else:
            x = int(x)%mod
            y = int(y)%mod
        e[x][y] += 1

    for i in range(mod):
        for j in range(mod):
            if i != 0 and j != 0:
                e[i][j] -= e[i-1][j-1]
            if i != 0:
                e[i][j] += e[i-1][j]
            if j != 0:
                e[i][j] +=e[i][j-1]

    ans = 0
    for i in range(k+1):
        for j in range(k+1):
            count = e[-1][-1]+2*e[i+k-1][j+k-1]-e[-1][j+k-1]-e[i+k-1][-1]
            if i != 0 and j != 0:
                count += 2*e[i-1][j-1]
            if i != 0:
                count += e[i-1][-1]-2*e[i-1][j+k-1]
            if j != 0:
                count += e[-1][j-1]-2*e[i+k-1][j-1]
            ans = max(ans,count)
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n,k = map(int,input().split())
    e = [[0]*(2*k+1) for i in range(2*k+1)]
    mod = 2*k
    for i in range(n):
        x,y,c = input().split()
        if c == "W":
            x = int(x)%mod
            y = (int(x)+k)%mod
        else:
            x = int(x)%mod
            y = int(y)%mod
        e[x+1][y+1] += 1
    
    for i in range(1,mod+1):
        for j in range(1,mod+1):
            e[i][j] += e[i-1][j]+e[i][j-1]-e[i-1][j-1]
    
    def count(ax,ay,bx,by):
        return e[ax][ay] +e[bx][by] - e[ax][by]-e[bx][ay]
    ans = 0
    for i in range(k+1):
        for j in range(k+1):
            c = count(2*k,2*k,i+k,j+k)+count(2*k,j,i+k,0)+count(i,2*k,0,j+k)+count(i,j,0,0)+count(i+k,j+k,i,j)
            ans = max(ans,c,n-c)
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n,k = map(int,input().split())
    e = [[0]*(2*k+1) for i in range(2*k+1)]
    mod = 2*k
    for i in range(n):
        x,y,c = input().split()
        if c == "W":
            x = int(x)%mod
            y = (int(x)+k)%mod
        else:
            x = int(x)%mod
            y = int(y)%mod
        e[x+1][y+1] += 1

    for i in range(1,mod+1):
        for j in range(1,mod+1):
            e[i][j] = e[i-1][j]+e[i][j-1]-e[i-1][j-1]
    def count(ax,ay,bx,by):
        return e[ax][ay] +e[bx][by] - e[ax][by]-e[bx][ay]
    ans = 0
    for i in range(k+1):
        for j in range(k+1):
            c = count(2*k,2*k,i+k,j+k)+count(2*k,j,i+k,0)+count(i,2*k,0,j+k)+count(i,j,0,0)+count(i+k,j+k,i,j)
            ans = max(ans,c,n-c)
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n,k = map(int,input().split())
    e = [[0]*(2*k) for i in range(2*k)]
    mod = 2*k
    for i in range(n):
        x,y,c = input().split()
        if c == "W":
            x = int(x)%mod
            y = (int(x)+k)%mod
        else:
            x = int(x)%mod
            y = int(y)%mod
        e[x][y] += 1

    for i in range(mod):
        for j in range(mod):
            if i != 0 and j != 0:
                e[i][j] -= e[i-1][j-1]
            if i != 0:
                e[i][j] += e[i-1][j]
            if j != 0:
                e[i][j] +=e[i][j-1]

    ans = 0
    for i in range(k+1):
        for j in range(k+1):
            count = e[-1][-1]+2*e[i+k-1][j+k-1]-e[-1][j+k-1]-e[i+k-1][-1]
            if i != 0 and j != 0:
                count += 2*e[i-1][j-1]
            if i != 0:
                count += e[i-1][-1]-2*e[i-1][j+k-1]
            if j != 0:
                count += e[-1][j-1]-2*e[i+k-1][j-1]
            ans = max(ans,count)
    print(ans)
if __name__ == "__main__":
    main()