Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

def main():
    na = list(map(int, input().split()))
    N = na[0]
    K = na[1]
    x = []
    y = []
    c = []
    for i in range(N):
        sa = input().split()
        x.append(int(sa[0]))
        y.append(int(sa[1]))
        c.append(True if sa[2] == 'W' else False)

    hopes = [[0 for j in range(K * 2)] for i in range(K * 3)]
    xsum = [0 for j in range(K * 2)]
    ysum = [[0 for j in range(K * 2)] for i in range(K * 3)]

    for i in range(N):
        if c[i]:
            x[i] += K
        xmod = x[i] % (K * 2)
        ymod = y[i] % (K * 2)
        if K <= xmod and K <= ymod:
            xmod -= K
            ymod -= K
        elif K <= ymod:
            xmod += K
            ymod -= K

        hopes[xmod][ymod] += 1
        if xmod < K:
            hopes[xmod + K][ymod + K] += 1
            hopes[xmod + K * 2][ymod] += 1
        else:
            hopes[xmod - K][ymod + K] += 1
            hopes[xmod + K][ymod + K] += 1

    for j in range(K * 2):
        for i in range(K):
            xsum[j] += hopes[i][j]
    for i in range(K):
        ysum[i][0] = ysum[i + K * 2][0] = s = sum(hopes[i][:K])
        for j in range(1, K):
            s += (hopes[i][j + K - 1] - hopes[i][j - 1])
            ysum[i][j] = ysum[i + K * 2][j] = s
    for i in range(K, K * 2):
        ysum[i][0] = s = sum(hopes[i][:K])
        for j in range(1, K):
            s += (hopes[i][j + K - 1] - hopes[i][j - 1])
            ysum[i][j] = s

    h0 = []
    hmax = h = sum(xsum[:K])
    h0.append(h)
    for j in range(1, K):
        h += (xsum[j + K - 1] - xsum[j - 1])
        hmax = max(hmax, h)
        h0.append(h)
    for j in range(K):
        h = h0[j]
        for i in range(1, K * 2):
            h += (ysum[i + K - 1][j] - ysum[i - 1][j])
            hmax = max(hmax, h)

    print(hmax)


if __name__ == '__main__':
    main()



Fixed submission:
#!/usr/bin/env python3

def main():
    na = list(map(int, input().split()))
    N = na[0]
    K = na[1]
    x = []
    y = []
    c = []
    for i in range(N):
        sa = input().split()
        x.append(int(sa[0]))
        y.append(int(sa[1]))
        c.append(True if sa[2] == 'W' else False)

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

    score = 0
    for i in range(N):
        xmod = x[i] % K
        ymod = y[i] % K
        f = (int(x[i] / K) + int(y[i] / K)) % 2 == 1
        c[i] ^= f
        if c[i]:
            score += 1
        h = -1 if c[i] else 1
        hopes[xmod][ymod] += h

    for i in range(K):
        s = 0
        for j in range(K):
            s += hopes[i][j]
            ysum[i][j] = s
        for j in range(K):
            s -= hopes[i][j]
            ysum[i][K + j] = s

    smax = 0
    for j in range(K):
        s = 0
        for i in range(K):
            s += ysum[i][K + j]
        for i in range(K):
            s += (ysum[i][j] - ysum[i][K + j])
            smax = max(smax, s)
        for i in range(K):
            s -= (ysum[i][j] - ysum[i][K + j])
            smax = max(smax, s)

    print(score + smax)


if __name__ == '__main__':
    main()