Problem:


Score : 300 points

Problem Statement

AtCoDeer the deer is going on a trip in a two-dimensional plane.
In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i.

If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1).
Note that he cannot stay at his place.
Determine whether he can carry out his plan.

Constraints

1 ≤ N ≤ 10^5

0 ≤ x_i ≤ 10^5

0 ≤ y_i ≤ 10^5

1 ≤ t_i ≤ 10^5

t_i < t_{i+1} (1 ≤ i ≤ N-1)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N

Output

If AtCoDeer can carry out his plan, print Yes; if he cannot, print No.

Sample Input 1

2
3 1 2
6 1 1

Sample Output 1

Yes

For example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1), (1,0), then (1,1).

Sample Input 2

1
2 100 100

Sample Output 2

No

It is impossible to be at (100,100) two seconds after being at (0,0).

Sample Input 3

2
5 1 1
100 1 1

Sample Output 3

No



Sample input:
2
3 1 2
6 1 1


Sample output:
Yes

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
import numpy as np

n, k = list(map(int,input().split()))
table = np.zeros((2*k,2*k),dtype='int32')
for i in range(n):
    t = input().split()
    if(t[2]=='B'):
        table[int(t[0])%(2*k)][int(t[1])%(2*k)] += 1
    else:
        table[(int(t[0])+k)%(2*k)][int(t[1])%(2*k)] += 1
        
n_table = np.zeros((3*k,3*k),dtype='int32')
n_table[0:2*k,0:2*k] = table
n_table[2*k:3*k,0:2*k] = table[0:k,0:2*k]
n_table[0:2*k,2*k:3*k] = table[0:2*k,0:k]
n_table[2*k:3*k,2*k:3*k] = table[0:k,0:k]

i_table = np.zeros((3*k,3*k),dtype='int32')

for i in range(0,3*k):
    i_table[i][0] = n_table[i][0]
    for j in range(1,3*k):
        i_table[i][j] += i_table[i][j-1] + n_table[i][j] 
for i in range(1,3*k):
    for j in range(0,3*k):
        i_table[i][j] += i_table[i-1][j]  

ans = 0
hope1 = i_table[k-1][k-1]
hope2 = i_table[2*k-1][2*k-1] - i_table[2*k-1][k-1] - i_table[k-1][2*k-1] + i_table[k-1][k-1]
ans = max(ans,hope1+hope2)
for i in range(1,k):
    hope1 = i_table[k-1][i+k-1] - i_table[k-1][i-1]
    hope2 = i_table[2*k-1][i+2*k-1] - i_table[2*k-1][i+k-1] - i_table[k-1][i+2*k-1] + i_table[k-1][i+k-1]
    ans = max(ans,hope1+hope2)
for i in range(1,k):        
        hope1 = i_table[i+k-1][k-1]- i_table[i-1][k-1]
        hope2 = i_table[i+2*k-1][2*k-1] - i_table[i+2*k-1][k-1] - i_table[i+k-1][2*k-1] + i_table[i+k-1][k-1]
        ans = max(ans,hope1+hope2)

for i in range(1,k):
    for j in range(1,k):        
        hope1 = i_table[i+k-1][j+k-1] - i_table[i+k-1][j-1] - i_table[i-1][j+k-1] + i_table[i-1][j-1]
        hope2 = i_table[i+2*k-1][j+2*k-1] - i_table[i+2*k-1][j+k-1] - i_table[i+k-1][j+2*k-1] + i_table[i+k-1][j+k-1]
        ans = max(ans,hope1+hope2)
print(ans)

Submission status: Runtime Error

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

def check(sx, sy, K, x, y):
    x = x % (2*K)
    y = y % (2*K)
    if x < sx or x >= sx + K:
        if y < sy:
            return 'W'
        elif y < sy + K:
            return 'B'
        else:
            return 'W'
    #elif x >= sx and x < sx + K:
    else:
        if y < sy:
            return 'B'
        elif y < sy + K:
            return 'W'
        else:
            return 'B'


ans = 0
for sx in range(K+1):
    for sy in range(K+1):
        r = 0
        for i in range(N):
            if check(sx, sy, K, xyc[i][0], xyc[i][1]) == xyc[i][2]:
                r = r + 1
        ans = max(ans, r)
print(ans)