Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead.

The first task he faced is to check whether the king is in check. Anton doesn't know how to implement this so he asks you to help.

Consider that an infinite chess board contains one white king and the number of black pieces. There are only rooks, bishops and queens, as the other pieces are not supported yet. The white king is said to be in check if at least one black piece can reach the cell with the king in one move. 

Help Anton and write the program that for the given position determines whether the white king is in check.

Remainder, on how do chess pieces move:   Bishop moves any number of cells diagonally, but it can't "leap" over the occupied cells.  Rook moves any number of cells horizontally or vertically, but it also can't "leap" over the occupied cells.  Queen is able to move any number of cells horizontally, vertically or diagonally, but it also can't "leap". 


-----Input-----

The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of black pieces.

The second line contains two integers x_0 and y_0 ( - 10^9 ≤ x_0, y_0 ≤ 10^9) — coordinates of the white king.

Then follow n lines, each of them contains a character and two integers x_{i} and y_{i} ( - 10^9 ≤ x_{i}, y_{i} ≤ 10^9) — type of the i-th piece and its position. Character 'B' stands for the bishop, 'R' for the rook and 'Q' for the queen. It's guaranteed that no two pieces occupy the same position.


-----Output-----

The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise.


-----Examples-----
Input
2
4 2
R 1 1
B 1 5

Output
YES

Input
2
4 2
R 3 3
B 1 5

Output
NO



-----Note-----

Picture for the first sample:  [Image]  White king is in check, because the black bishop can reach the cell with the white king in one move. The answer is "YES".

Picture for the second sample:  [Image]  Here bishop can't reach the cell with the white king, because his path is blocked by the rook, and the bishop cant "leap" over it. Rook can't reach the white king, because it can't move diagonally. Hence, the king is not in check and the answer is "NO".

Difficulty: interview

Starter code:

Solutions:
from collections import defaultdict
import bisect

n = int(input())
x0, y0 = list(map(int, input().split(' ')))
verticale = []
horizontale = []
diagonale1 = []
diagonale2 = []
for _ in range(n):
    t, x, y = input().split(' ')
    x, y = int(x), int(y)
    if x == x0:
        verticale.append((y, t))
    if y == y0:
        horizontale.append((x, t))
    if x+y == x0+y0:
        diagonale1.append((x, t))
    if x-y == x0-y0:
        diagonale2.append((x, t))

dead = False
v = sorted(verticale)
if v:
    l = bisect.bisect(v, (y0, 'K'))
    if 0 < l < len(v):
        if v[l][1] in {'Q', 'R'} or v[l-1][1] in {'Q', 'R'}:
            dead = True
    elif l == 0:
        if v[0][1] in {'Q', 'R'}:
            dead = True
    else:
        if v[len(v)-1][1] in {'Q', 'R'}:
            dead = True
v = sorted(horizontale)
if v:
    l = bisect.bisect(v, (x0, 'K'))
    if 0 < l < len(v):
        if v[l][1] in {'Q', 'R'} or v[l-1][1] in {'Q', 'R'}:
            dead = True
    elif l == 0:
        if v[0][1] in {'Q', 'R'}:
            dead = True
    else:
        if v[len(v)-1][1] in {'Q', 'R'}:
            dead = True
v = sorted(diagonale1)
if v:
    l = bisect.bisect(v, (x0, 'K'))
    if 0 < l < len(v):
        if v[l][1] in {'Q', 'B'} or v[l-1][1] in {'Q', 'B'}:
            dead = True
    elif l == 0:
        if v[0][1] in {'Q', 'B'}:
            dead = True
    else:
        if v[len(v)-1][1] in {'Q', 'B'}:
            dead = True
v = sorted(diagonale2)
if v:
    l = bisect.bisect(v, (x0, 'K'))
    if 0 < l < len(v):
        if v[l][1] in {'Q', 'B'} or v[l-1][1] in {'Q', 'B'}:
            dead = True
    elif l == 0:
        if v[0][1] in {'Q', 'B'}:
            dead = True
    else:
        if v[len(v)-1][1] in {'Q', 'B'}:
            dead = True
if dead:
    print('YES')
else:
    print('NO')


from sys import stdin

n = int(stdin.readline())
x, y = map(int, stdin.readline().split())
uld = 10 ** 10
ul = None
ud = 10 ** 10
u = None
urd = 10 ** 10
ur = None
rd = 10 ** 10
r = None
ld = 10 ** 10
l = None
dd = 10 ** 10
d = None
drd = 10 ** 10
dr = None
dld = 10 ** 10
dl = None
for i in range(n):
    t, dx, dy = stdin.readline().split()
    dx = int(dx)
    dy = int(dy)
    if dx == x:
        if dy > y:
            if ud > dy - y:
                ud = dy - y
                u = t
        else:
            if dd > y - dy:
                dd = y - dy
                d = t
    if dy == y:
        if dx > x:
            if rd > dx - x:
                rd = dx - x
                r = t
        else:
            if ld > x - dx:
                ld = x - dx
                l = t
    if dx - x == dy - y:
        if dy > y:
            if urd > dy - y:
                urd = dy - y
                ur = t
        else:
            if dld > y - dy:
                dld = y - dy
                dl = t
    if -(dx - x) == dy - y:
        if dy > y:
            if uld > dy - y:
                uld = dy - y
                ul = t
        else:
            if drd > y - dy:
                drd = y - dy
                dr = t

if 'B' in (ul, ur, dl, dr) or 'R' in (u, d, l, r) or 'Q' in (ul, ur, dl, dr, u, d, l, r):
    print('YES')
else:
    print('NO')

def main():
    n = int(input())
    x, y = list(map(int, input().split()))
    a = []
    for i in range(n):
        a.append(input().split())
    for i in range(n):
        a[i][1] = int(a[i][1]) - x
        a[i][2] = int(a[i][2]) - y
    typneedbql = []
    typneedbqr = []
    typneedbqu = []
    typneedbqd = []
    typneedrlu = []
    typneedrru = []
    typneedrld = []
    typneedrrd = []
    for i in range(n):
        if (a[i][1] * a[i][2] == 0 and a[i][1] < 0):
            typneedbql.append([abs(a[i][1] + a[i][2])] + a[i])
        elif (a[i][1] * a[i][2] == 0 and a[i][1] > 0):
            typneedbqr.append([abs(a[i][1] + a[i][2])] + a[i])
        elif (a[i][1] * a[i][2] == 0 and a[i][2] > 0):
            typneedbqu.append([abs(a[i][1] + a[i][2])] + a[i])
        elif (a[i][1] * a[i][2] == 0 and a[i][2] < 0):
            typneedbqd.append([abs(a[i][1] + a[i][2])] + a[i])
        elif (abs(a[i][1] / a[i][2]) == 1 and a[i][1] < 0 and a[i][2] < 0):
            typneedrlu.append([abs(a[i][1])] + a[i])
        elif (abs(a[i][1] / a[i][2]) == 1 and a[i][1] < 0 and a[i][2] > 0):
            #print(i, a[i][1], a[i][2])
            typneedrld.append([abs(a[i][1])] + a[i])
        elif (abs(a[i][1] / a[i][2]) == 1 and a[i][1] > 0 and a[i][2] > 0):
            typneedrrd.append([abs(a[i][1])] + a[i])
        elif (abs(a[i][1] / a[i][2]) == 1 and a[i][1] > 0 and a[i][2] < 0):
            typneedrru.append([abs(a[i][1])] + a[i])
    typneedbql.sort()
    typneedbqr.sort()
    typneedbqd.sort()
    typneedbqu.sort()
    typneedrlu.sort()
    typneedrru.sort()
    typneedrld.sort()
    typneedrrd.sort()
    #print(a)
    #print(typneedrld)
    for i in range(len(typneedbql)):
        if typneedbql[i][1] == "R" or typneedbql[i][1] == "Q":
            print("YES")
            return
        else:
            break
    for i in range(len(typneedbqr)):
        if typneedbqr[i][1] == "R" or typneedbqr[i][1] == "Q":
            print("YES")
            return
        else:
            break
    for i in range(len(typneedbqu)):
        if typneedbqu[i][1] == "R" or typneedbqu[i][1] == "Q":
            print("YES")
            return
        else:
            break
    for i in range(len(typneedbqd)):
        if typneedbqd[i][1] == "R" or typneedbqd[i][1] == "Q":
            print("YES")
            return
        else:
            break
    for i in range(len(typneedrlu)):
        if typneedrlu[i][1] == "B" or typneedrlu[i][1] == "Q":
            print("YES")
            return
        else:
            break
    for i in range(len(typneedrld)):
        if typneedrld[i][1] == "B" or typneedrld[i][1] == "Q":
            print("YES")
            return
        else:
            break
    for i in range(len(typneedrrd)):
        if typneedrrd[i][1] == "B" or typneedrrd[i][1] == "Q":
            print("YES")
            return
        else:
            break
    for i in range(len(typneedrru)):
        if typneedrru[i][1] == "B" or typneedrru[i][1] == "Q":
            print("YES")
            return
        else:
            break
    print("NO")
main()


n = int(input())
kx, ky = map(int, input().split())
nearest = [None]*8 
for i in range(n):
  ft, fx, fy = input().split()
  fx = int(fx)
  fy = int(fy)
  if kx == fx:
    if ky > fy:
      if not nearest[0] or nearest[0][1] < fy:
        nearest[0] = (ft, fy)
    else:
      if not nearest[1] or nearest[1][1] > fy:
        nearest[1] = (ft, fy)
  elif ky == fy: 
    if kx > fx:
      if not nearest[2] or nearest[2][1] < fx:
        nearest[2] = (ft, fx)
    else:
      if not nearest[3] or nearest[3][1] > fx:
        nearest[3] = (ft, fx)
  elif kx + ky == fx + fy: 
    if kx - ky > fx - fy:
      if not nearest[4] or nearest[4][1] < fx - fy:
        nearest[4] = (ft, fx - fy)
    else:
      if not nearest[5] or nearest[5][1] > fx - fy:
        nearest[5] = (ft, fx - fy)
  elif kx - ky == fx - fy: 
    if kx + ky > fx + fy:
      if not nearest[6] or nearest[6][1] < fx + fy:
        nearest[6] = (ft, fx + fy)
    else:
      if not nearest[7] or nearest[7][1] > fx + fy:
        nearest[7] = (ft, fx + fy)

res = "NO"
for i in range(4):
  if nearest[i] and nearest[i][0] != "B":
    res = "YES"
for i in range(4,8):
  if nearest[i] and nearest[i][0] != "R":
    res = "YES"
print(res)

n = int(input())
xo,yo = (int(x) for x in input().split())
inf = 1000000000000
above = [inf,'N']
below = [inf,'N']
left = [inf,'N']
right = [inf,'N']
upright = [inf,'N']
upleft = [inf,'N']
botright = [inf,'N']
botleft = [inf,'N']
for i in range(n):
	[T,curx,cury] = input().split()
	x = int(curx)
	y = int(cury)
	if x == xo:
		if y > yo and y - yo < above[0]:
			above[0] = y - yo
			above[1] = T
		elif y < yo and yo - y < below[0]:
			below[0] = yo - y
			below[1] = T
	elif y == yo:
		if x > xo and x - xo < right[0]:
			right[0] = x - xo
			right[1] = T
		elif x < xo and xo - x < left[0]:
			left[0] = xo - x
			left[1] = T

	if x - xo == y - yo:
		if x > xo and x - xo < upright[0]:
			upright[0] = x - xo
			upright[1] = T
		elif x < xo and xo - x < botleft[0]:
			botleft[0] = xo - x
			botleft[1] = T
	elif x - xo == yo - y:
		if x > xo and x - xo < botright[0]:
			botright[0] = x - xo
			botright[1] = T
		elif x < xo and xo - x < upleft[0]:
			upleft[0] = xo - x
			upleft[1] = T


if botright[1] == 'B' or botright[1] == 'Q' or botleft[1] == 'B' or botleft[1] == 'Q' or upleft[1] == 'B' or upleft[1] == 'Q' or upright[1] == 'B' or upright[1] == 'Q' or above[1] == 'R' or above[1] == 'Q' or below[1] == 'R' or below[1] == 'Q' or left[1] == 'R' or left[1] == 'Q' or right[1] == 'R' or right[1] == 'Q':
	print("YES")
else:
	print("NO")


n = int(input())
x0, y0 = [int(x) for x in input().split()]
uv = [-1, -10**10, 'n']
dv = [-1, 10**10, 'n']
lh = [-10**10, -1 , 'n']
rh = [10**10, -1, 'n']
ldd = [-10**10, -1, 'n']
lud = [-10**10, -1, 'n']
rdd = [10**10, -1, 'n']
rud = [10**10, -1, 'n']
for i in range(n):
    t, x, y = [x for x in input().split()]
    x = int(x)
    y = int(y)
    if x == x0:
        if y < y0:
            if y0 - y < y0 - uv[1]:
                uv = [x, y, t]
        else:
            if y - y0 < dv[1] - y0:
                dv = [x, y, t]
    if y == y0:
        if x < x0:
            if x0 - x < x0 - lh[0]:
                lh = [x, y, t]
        else:
            if x - x0 < rh[0] - x0:
                rh = [x, y, t]
    if abs(x-x0) == abs(y-y0):
        if x < x0 and y < y0:
            if x0 - x < x0 - ldd[0]:
                ldd = [x,y,t]
        if x < x0 and y > y0:
            if x0 - x < x0 - lud[0]:
                lud = [x,y,t]
        if x > x0 and y < y0:
            if x - x0 < rdd[0] - x0:
                rdd = [x,y,t]
        if x > x0 and y > y0:
            if x - x0 < rud[0] - x0:
                rud = [x,y,t]

ans = 'NO'
if uv[2] in ('R', 'Q') or dv[2] in ('R', 'Q') or lh[2] in ('R', 'Q') or rh[2] in ('R', 'Q'):
    ans = 'YES'

if ldd[2] in ('B', 'Q') or lud[2] in ('B', 'Q') or rdd[2] in ('B', 'Q') or rud[2] in ('B', 'Q'):
    ans = 'YES'
print(ans)

n = int(input())
x0, y0 = map(int, input().split())
Nord = 10 ** 9 + 1
fNord = '-'
East = 10 ** 9 + 1
fEast = '-'
South = -10 ** 9 - 1
fSouth = '-'
West = -10 ** 9 - 1
fWest = '-'

NE = 10 ** 9 + 1
fNE = '-'
NW = 10 ** 9 + 1
fNW = '-'
SE = -10 ** 9 - 1
fSE = '-'
SW = -10 ** 9 - 1
fSW = '-'

for i in range(n):
    f, x, y = input().split()
    x = int(x)
    y = int(y)
    if x == x0:
        if y0 < y < Nord:
            fNord = f
            Nord = y
        elif y0 > y > South:
            fSouth = f
            South = y
    if y == y0:
        if x0 < x < East:
            fEast = f
            East = x
        elif x0 > x > West:
            fWest = f
            West = x
            
    if x + y == x0 + y0:
        if y0 < y < NW:
            fNW = f
            NW = y
        elif y0 > y > SE:
            fSE = f
            SE = y
    if x - y == x0 - y0:
        if y0 < y < NE:
            fNE = f
            NE = y
        elif y0 > y > SW:
            fSW = f
            SW = y
ans  = False
if fSW == 'Q' or fSE == 'Q' or fNW == 'Q' or fNE == 'Q':
    ans = True
if fNord == 'Q' or fSouth == 'Q' or fWest == 'Q' or fEast == 'Q':
    ans = True
if fSW == 'B' or fSE == 'B' or fNW == 'B' or fNE == 'B':
    ans = True
if fNord == 'R' or fSouth == 'R' or fWest == 'R' or fEast == 'R':
    ans = True

#print(fSW, fSE, fNW, fNE) 
#print(fNord, fSouth, fWest, fEast)
print('YES' if ans else 'NO')

n = int(input())

x, y = map(int, input().split())

directions = [None for x in range(8)]
# u, ur, r, rd, d, dl, l, lu

for i in range(n):
    line = input().split()
    xi = int(line[1])
    yi = int(line[2])
    
    if yi == y:
        if xi < x:
            #left
            if directions[6] == None:
                directions[6] = (xi, yi, line[0])
            elif directions[6][0] < xi:
                directions[6] = (xi, yi, line[0])
        else:
            #right
            if directions[2] == None:
                directions[2] = (xi, yi, line[0])
            elif directions[2][0] > xi:
                directions[2] = (xi, yi, line[0])
    elif xi == x:
        if yi < y:
            #down
            if directions[4] == None:
                directions[4] = (xi, yi, line[0])
            elif directions[4][1] < yi:
                directions[4] = (xi, yi, line[0])
        else:
            #up
            if directions[0] == None:
                directions[0] = (xi, yi, line[0])
            elif directions[0][1] > yi:
                directions[0] = (xi, yi, line[0])
    elif xi - x == yi - y:
        if xi > x:
            #upright
            if directions[1] == None:
                directions[1] = (xi, yi, line[0])
            elif directions[1][0] > xi:
                directions[1] = (xi, yi, line[0])
        else:
            #downleft
            if directions[5] == None:
                directions[5] = (xi, yi, line[0])
            elif directions[5][1] < yi:
                directions[5] = (xi, yi, line[0])
    elif xi - x == y - yi:
        if xi > x:
            #rightdown
            if directions[3] == None:
                directions[3] = (xi, yi, line[0])
            elif directions[3][0] > xi:
                directions[3] = (xi, yi, line[0])
        else:
            #leftup
            if directions[7] == None:
                directions[7] = (xi, yi, line[0])
            elif directions[7][1] > yi:
                directions[7] = (xi, yi, line[0])
                
for i in range(8):
    if directions[i] != None:
        if i % 2 == 0:
            if directions[i][2] == "R" or directions[i][2] == "Q":
                print("YES")
                return
        else:
            if directions[i][2] == "B" or directions[i][2] == "Q":
                print("YES") 
                return
            
print("NO")

BORDER = 10 ** 10

def get_type(x, y):
	if x == 0:
		return 1 if y > 0 else 5
	if y == 0:
		return 3 if x > 0 else 7
	if x == -y:
		return 0 if y > 0 else 4
	if x == y:
		return 2 if y > 0 else 6
	return -1

def __starting_point():
	n, = list(map(int, input().split()))
	x0, y0 = list(map(int, input().split()))
	check = False
	block = [(-BORDER, BORDER), (0, BORDER), (BORDER, BORDER), (BORDER, 0), (BORDER, -BORDER), (0, -BORDER), (-BORDER, -BORDER), (-BORDER, 0)]
	killer = [None for _ in range(8)]
	for _ in range(n):
		f, xs, ys = input().split()
		x, y = list(map(int, (xs, ys)))
		x, y = x-x0, y-y0
		tp = get_type(x, y)
		if tp < 0:
			continue
		if ((f == 'B' and tp % 2 == 1) or (f == 'R' and tp % 2 == 0)):
			if abs(block[tp][0]) + abs(block[tp][1]) > abs(x) + abs(y):
				block[tp] = (x, y)
		else:
			if abs(block[tp][0]) + abs(block[tp][1]) < abs(x) + abs(y):
				continue
			if killer[tp] is None:
				killer[tp] = (x, y)
				continue
			if abs(killer[tp][0]) + abs(killer[tp][1]) > abs(x) + abs(y):
				killer[tp] = (x, y)
				continue
	for tp in range(8):
		if killer[tp] is None:
			continue
		if abs(killer[tp][0]) + abs(killer[tp][1]) < abs(block[tp][0]) + abs(block[tp][1]):
			check = True
			break
	if check:
		print("YES")
	else:
		print("NO")

__starting_point()

n=int(input())
temp=input().split()
x0=int(temp[0])
y0=int(temp[1])

N=['T',10**20]
NE=['T',10**20]
E=['T',10**20]
SE=['T',10**20]
S=['T',10**20]
SW=['T',10**20]
W=['T',10**20]
NW=['T',10**20]

for i in range(n):
	temp=input().split()
	x=int(temp[1])
	y=int(temp[2])
	if x-x0==0 and y-y0>0 and y-y0<N[1]:
		N=[temp[0],y-y0]
	elif x-x0==y-y0 and x-x0>0 and x-x0<NE[1]:
		NE=[temp[0],x-x0]
	elif y-y0==0 and x-x0>0 and x-x0<E[1]:
		E=[temp[0],x-x0]
	elif x-x0==-(y-y0) and x-x0>0 and x-x0<SE[1]:
		SE=[temp[0],x-x0]
	elif x-x0==0 and y-y0<0 and y0-y<S[1]:
		S=[temp[0],y0-y]
	elif x-x0==y-y0 and x-x0<0 and x0-x<SW[1]:
		SW=[temp[0],x0-x]
	elif y-y0==0 and x-x0<0 and x0-x<W[1]:
		W=[temp[0],x0-x]
	elif x-x0==-(y-y0) and x-x0<0 and x0-x<NW[1]:
		NW=[temp[0],x0-x]

if 'R' in [N[0],E[0],S[0],W[0]] or 'B' in [NE[0],SE[0],SW[0],NW[0]]:
	print("YES")
elif 'Q' in [N[0],E[0],S[0],W[0],NE[0],SE[0],SW[0],NW[0]]:
	print("YES")
else:
	print("NO")

n = int(input())
x, y = map(int, input().split())
x += (10 ** 9 + 1)
y += (10 ** 9 + 1)
arr = [[] for i in range(n)]
for i in range(n):
    arr[i] = input().split()
    arr[i][1] = int(arr[i][1]) + (10 ** 9 + 1)
    arr[i][2] = int(arr[i][2]) + (10 ** 9 + 1)
t1 = -1
t2 = -1
t3 = -1
t4 = -1
t5 = -1
t6 = -1
t7 = -1
t8 = -1

ind1 = ''
ind2 = ''
ind3 = ''
ind4 = ''
ind5 = ''
ind6 = ''
ind7 = ''
ind8 = ''

for i in range(n):
    x1 = arr[i][1]
    y1 = arr[i][2]
    if x1 == x:
        if y > y1:
            if t4 == -1:
                t4 = y - y1
                ind4 = arr[i][0]
            elif (y - y1) < t4:
                t4 = y - y1
                ind4 = arr[i][0]
        else:
            if t2 == -1:
                t2 = y1 - y
                ind2 = arr[i][0]
            elif y1 - y < t2:
                t2 = y1 - y
                ind2 = arr[i][0]
    
    
    if y1 == y:
        if x > x1:
            if t1 == -1:
                t1 = x - x1
                ind1 = arr[i][0]
            elif (x - x1) < t1:
                t1 = x - x1
                ind1 = arr[i][0]
        else:
            if t3 == -1:
                t3 = x1 - x
                ind3 = arr[i][0]
            elif x1 - x < t3:
                t3 = x1 - x
                ind3 = arr[i][0]
                
    
    if abs(x1 - x) == abs(y1 - y):
        if y1 > y:
            if x1 < x:
                if t5 == -1:
                    t5 = x - x1
                    ind5 = arr[i][0]
                elif(x - x1) < t5:
                    t5 = x - x1
                    ind5 = arr[i][0]
            else:
                if t6 == -1:
                    t6 = x1 - x
                    ind6 = arr[i][0]
                elif(x1 - x) < t6:
                    t6 = x1 - x
                    ind6 = arr[i][0]
        else:
            if x1 < x:
                if t8 == -1:
                    t8 = x - x1
                    ind8 = arr[i][0]
                elif (x - x1) < t8:
                    t8 = x - x1
                    ind8 = arr[i][0]
            else:
                if t7 == -1:
                    t7 = x1 - x
                    ind7 = arr[i][0]
                elif (x1 - x) < t7:
                    t7 = x1 - x
                    ind7 = arr[i][0]
if ind1 == "R" or ind1 == 'Q' or ind2 == "R" or ind2 == 'Q' or ind3 == "R" or ind3 == 'Q' or ind4 == "R" or ind4 == 'Q' or ind5 == 'B' or ind5 == 'Q' or ind6 == 'B' or ind6 == 'Q' or ind7 == 'B' or ind7 == 'Q' or ind8 == 'B' or ind8 == 'Q':
    print("YES")
else:
    print("NO")

def is_parallel(x1, y1, x2, y2):
    return x1 == x2 or y1 == y2

def is_diagonal(x1, y1, x2, y2):
    return abs(x1 - x2) == abs(y1 - y2)

n = int(input())
xs = input().split(" ")
x0 = int(xs[0])
y0 = int(xs[1])

inf = 1000000000000000000
mins = [inf, inf, inf, inf, inf, inf, inf, inf]
#       <-    ^    ->   v    NE   SE   SW   NW
minx = ['B', 'B', 'B', 'B', 'R', 'R', 'R', 'R']

for i in range(0, n):
    xs = input().split(" ")
    t = xs[0]
    x = int(xs[1])
    y = int(xs[2])

    if (is_parallel(x0, y0, x, y)):
        if (y > y0):
            if (y - y0 < mins[1]):
                mins[1] = y - y0
                minx[1] = t
        elif (y < y0):
            if (y0 - y < mins[3]):
                mins[3] = y0 - y
                minx[3] = t
        elif (x > x0):
            if (x - x0 < mins[2]):
                mins[2] = x - x0
                minx[2] = t
        else:
            if (x0 - x < mins[0]):
                mins[0] = x0 - x
                minx[0] = t
    elif (is_diagonal(x0, y0, x, y)):
        if (x > x0 and y > y0):
            if (x - x0 < mins[4]):
                mins[4] = x - x0
                minx[4] = t
        elif (x > x0 and y < y0):
            if (x - x0 < mins[5]):
                mins[5] = x - x0
                minx[5] = t
        elif (x < x0 and y < y0):
            if (x0 - x < mins[6]):
                mins[6] = x0 - x
                minx[6] = t
        else:
            if (x0 - x < mins[7]):
                mins[7] = x0 - x
                minx[7] = t

if (minx[0] != 'B' or minx[1] != 'B' or minx[2] != 'B' or minx[3] != 'B' or minx[4] != 'R' or minx[5] != 'R' or minx[6] != 'R' or minx[7] != 'R'):
    print ("YES")
else:
    print ("NO")



def main():
    n = int(input())
    inf = 10 ** 10
    x0, y0 = list(map(int, input().split()))
    h, v, d1, d2 = ([(-inf, 'K'), (0, 'K'), (inf, 'K')] for _ in range(4))
    for _ in range(n):
        f, x, y = input().split()
        x = int(x) - x0
        y = int(y) - y0
        if not x:
            h.append((y, f))
        elif not y:
            v.append((x, f))
        elif x == y:
            d1.append((x, f))
        elif x == -y:
            d1.append((x, f))
    res = False
    for l in h, v, d1, d2:
        l.sort()
    i = h.index((0, 'K'))
    if h[i - 1][1] in "RQ":
        res = True
    if h[i + 1][1] in "RQ":
        res = True
    i = v.index((0, 'K'))
    if v[i - 1][1] in "RQ":
        res = True
    if v[i + 1][1] in "RQ":
        res = True
    i = d1.index((0, 'K'))
    if d1[i - 1][1] in "BQ":
        res = True
    if d1[i + 1][1] in "BQ":
        res = True
    i = d2.index((0, 'K'))
    if d2[i - 1][1] in "BQ":
        res = True
    if d2[i + 1][1] in "BQ":
        res = True
    print(("NO", "YES")[res])


def __starting_point():
    main()

__starting_point()

n = int(input())
x,y = [int(i) for i in input().split()]

MIN_B = -10**9-1
MAX_B = 10**9+1

l_v = [MIN_B,0]
u_v = [MAX_B,0]
l_h = [MIN_B,0]
u_h = [MAX_B,0]
l_v1  = [MIN_B,MIN_B,0]
u_v1 = [MAX_B,MAX_B,0]
l_v2 = [MIN_B,MAX_B,0]
u_v2 = [MAX_B,MIN_B,0]

chess = []

def ok(type1,x1,y1,x,y):
    if type(type1) is int:
        return False
    if type1 == 'R':
        return x1 == x or y1 == y
    elif type1 == 'B':
        return -x1+y1 == y-x or x1+y1 == x+y
    elif type1 == 'Q':
        return x1 == x or y1 == y or -x1+y1 == y-x or x1+y1 == x+y

for i in range(n):
    t1,t2,t3 = [i for i in input().split()]
    chess.append((t1,int(t2),int(t3)))

for i in chess:
    if i[1] == x: #vertical
        if i[2] > y and i[2] < u_v[0]:
            u_v = [i[2],i[0]]
        if i[2] < y and i[2] > l_v[0]:
            l_v = [i[2],i[0]]
    if i[2] == y: #hori
        if i[1] > x and i[1] < u_h[0]:
            u_h = [i[1],i[0]]
        if i[1] < x and i[1] > l_h[0]:
            l_h = [i[1],i[0]]
    if -i[1] + i[2] == y - x:
        if (i[1] > x and i[2] > y) and (i[1] < u_v1[0] and i[2] < u_v1[1]):
            u_v1 = [i[1],i[2],i[0]]
        if (i[1] < x and i[2] < y) and (i[1] > l_v1[0] and i[2] > l_v1[1]):
            l_v1 = [i[1],i[2],i[0]]
    if i[1] + i[2] == x+y:
        if (i[1] > x and i[2] < y) and (i[1] < u_v2[0] and i[2] > u_v2[1]):
            u_v2 = [i[1],i[2],i[0]]
        if (i[1] < x and i[2] > y) and (i[1] > l_v2[0] and i[2] < l_v2[1]):
            l_v2 = [i[1],i[2],i[0]]

c = False
c = c or ok(l_v[1],x,l_v[0],x,y)
c = c or ok(u_v[1],x,u_v[0],x,y)
c = c or ok(l_h[1],l_h[0],y,x,y)
c = c or ok(u_h[1],u_h[0],y,x,y)
c = c or ok(l_v1[2],l_v1[0],l_v1[1],x,y)
c = c or ok(u_v1[2],u_v1[0],u_v1[1],x,y)
c = c or ok(l_v2[2],l_v2[0],l_v2[1],x,y)
c = c or ok(u_v2[2],u_v2[0],u_v2[1],x,y)

if c:
    print('YES')
else:
    print('NO')


        
    
        
        
        
    
                 
    



import math,sys,re,itertools,pprint,collections,copy
rs,ri,rai,raf=input,lambda:int(input()),lambda:list(map(int, input().split())),lambda:list(map(float, input().split()))

n = ri()
x0, y0 = rai()

rays = [
    [ [], lambda x, y: x == x0 and y > y0 ],             # top
    [ [], lambda x, y: x == x0 and y < y0 ],             # bottom
    [ [], lambda x, y: y == y0 and x > x0 ],             # right
    [ [], lambda x, y: y == y0 and x < x0 ],             # left
    [ [], lambda x, y: x - x0 == y - y0 and x > x0 ],    # right top
    [ [], lambda x, y: x - x0 == y - y0 and x < x0 ],    # left bottom
    [ [], lambda x, y: x - x0 == -(y - y0) and x > x0 ], # right bottom
    [ [], lambda x, y: x - x0 == -(y - y0) and x < x0 ], # left top
]

for i in range(n):
    t = input().split()
    x, y = int(t[1]), int(t[2])
    t = (t[0], x, y)
    for k, v in rays:
        if v(x, y):
            k.append(t)

dist = lambda a: abs(x0 - a[1]) + abs(y0 - a[2])

flag = False
for i, (k, v) in enumerate(rays):
    k.sort(key=dist)
    if len(k) > 0 and i > 3 and k[0][0] in "BQ":
        flag = True
        break
    if len(k) > 0 and i <= 3 and k[0][0] in "RQ":
        flag = True
        break

print("YES" if flag else "NO")


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from math import sqrt
from copy import copy
class figure:
    def __init__(self,ras=None,type=None):
        self.ras=copy(ras)
        self.type=type
n=int(input())
x0,y0=map(int,input().split())
sup='NO'
f=[]
for i in range(8):
    d=figure(10**11)
    f.append(d)
for i in range(n):
    teg,x,y=map(str,input().split())
    x,y=int(x),int(y)
    if x==x0:
        if y<y0:
            ras=abs(y-y0)
            if ras<f[0].ras:
                f[0]=figure(ras,teg)
        if y>y0:
            ras=abs(y0-y)
            if ras<f[1].ras:
                f[1]=figure(ras,teg)
    if y==y0:
        if x>x0:
            ras=abs(x-x0)
            if ras<f[2].ras:
                f[2]=figure(ras,teg)
        if x<x0:
            ras=abs(x0-x)
            if ras<f[3].ras:
                f[3]=figure(ras,teg)
    if abs(x-x0)==abs(y-y0):
        if y<y0 and x<x0:
            ras=sqrt(2)*abs(x-x0)
            if ras<f[4].ras:
                f[4]=figure(ras,teg)
        if y<y0 and x>x0:
            ras=sqrt(2)*abs(x-x0)
            if ras<f[5].ras:
                f[5]=figure(ras,teg)
        if y>y0 and x>x0:
            ras=sqrt(2)*abs(x-x0)
            if ras<f[6].ras:
                f[6]=figure(ras,teg)
        if y>y0 and x<x0:
            ras=sqrt(2)*abs(x-x0)
            if ras<f[7].ras:
                f[7]=figure(ras,teg)
for i in range(8):
    if i in [0,1,2,3]:
        if f[i].type=='R' or f[i].type=='Q':
            sup='YES'
    elif i in [4,5,6,7]:
        if f[i].type=='Q' or f[i].type=='B':
            sup='YES'
print(sup)

n = int(input())
king_x, king_y = map(int, input().split())
nomakers = {'Rook': {'right-down':[], 'right-up':[], 'left-down':[], 'left-up':[]}, 'Bishop': {'left':[], 'right':[], 'up':[], 'down':[]}}
yes = {'Queen':{'right-down':[], 'right-up':[], 'left-down':[], 'left-up':[],'left':[], 'right':[], 'up':[], 'down':[]},'Bishop': {'right-down':[], 'right-up':[], 'left-down':[], 'left-up':[]}, 'Rook': {'left':[], 'right':[], 'up':[], 'down':[]}}
for i in range(n):
    figure, figure_x, figure_y = input().split()
    figure_x, figure_y = int(figure_x), int(figure_y)
    if figure == 'Q':
        if figure_x == king_x:
            if figure_y < king_y: half = 'down'
            else: half = 'up'
            yes['Queen'][half].append(abs(king_y - figure_y))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Queen'][half][-1]:
                    del yes['Queen'][half][-1]
                    break
        elif figure_y == king_y:
            if figure_x < king_x: half = 'left'
            else: half = 'right'
            yes['Queen'][half].append(abs(king_x - figure_x))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Queen'][half][-1]:
                    del yes['Queen'][half][-1]
                    break
        elif abs(figure_x - king_x) == abs(figure_y - king_y):
            if figure_x > king_x:
                if figure_y > king_y: quarter = 'right-up'
                else: quarter = 'right-down'
            else:
                if figure_y > king_y: quarter = 'left-up'
                else: quarter = 'left-down'
            yes['Queen'][quarter].append(abs(king_x - figure_x))
            for i in range(len(nomakers['Rook'][quarter])):
                if nomakers['Rook'][quarter][i]<yes['Queen'][quarter][-1]:
                    del yes['Queen'][quarter][-1]
                    break
    elif figure == 'R':
        if figure_x == king_x:
            if figure_y < king_y: half = 'down'
            else: half = 'up'
            yes['Rook'][half].append(abs(king_y - figure_y))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Rook'][half][-1]:
                    del yes['Rook'][half][-1]
                    break
        elif figure_y == king_y:
            if figure_x > king_x: half = 'right'
            else: half = 'left'
            yes['Rook'][half].append(abs(king_x - figure_x))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Rook'][half][-1]:
                    del yes['Rook'][half][-1]
                    break
        elif abs(figure_x - king_x) == abs(figure_y - king_y):
            if figure_x > king_x:
                if figure_y > king_y: quarter = 'right-up'
                else: quarter = 'right-down'
            else:
                if figure_y > king_y: quarter = 'left-up'
                else: quarter = 'left-down'
            nomakers['Rook'][quarter].append(abs(figure_x - king_x))
            i = 0
            n = len(yes['Queen'][quarter])
            while i < n:
                element = yes['Queen'][quarter][i]
                if nomakers['Rook'][quarter][-1] < element:
                    del yes['Queen'][quarter][i]
                    n = n - 1
                else:
                    i = i + 1
            i = 0
            n = len(yes['Bishop'][quarter])
            while i < n:
                element = yes['Bishop'][quarter][i]
                if nomakers['Rook'][quarter][-1] < element:
                    del yes['Bishop'][quarter][i]
                    n = n - 1
                else:
                    i = i + 1
    else:
        if abs(figure_x - king_x) == abs(figure_y - king_y):
            if figure_x > king_x:
                if figure_y > king_y: quarter = 'right-up'
                else: quarter = 'right-down'
            else:
                if figure_y > king_y: quarter = 'left-up'
                else: quarter = 'left-down'
            yes['Bishop'][quarter].append(abs(figure_x - king_x))
            for i in range(len(nomakers['Rook'][quarter])):
                if nomakers['Rook'][quarter][i] < yes['Bishop'][quarter][-1]:
                    del yes['Bishop'][quarter][-1]
                    break
        elif figure_x == king_x or figure_y == king_y:
            if figure_y < king_y:
                a = figure_y - king_y
                half = 'down'
            elif figure_y > king_y:
                half = 'up'
                a = figure_y - king_y
            elif figure_x > king_x:
                a = figure_x - king_x
                half = 'right'
            else:
                a = figure_x - king_x
                half = 'left'
            nomakers['Bishop'][half].append(abs(a))
            i = 0
            n = len(yes['Rook'][half])
            while i < n:
                element = yes['Rook'][half][i]
                if nomakers['Bishop'][half][-1] < element:
                    del yes['Rook'][half][i]
                    n = n - 1
                else:
                    i = i + 1
            i = 0
            n = len(yes['Queen'][half])
            while i < n:
                element = yes['Queen'][half][i]
                if nomakers['Bishop'][half][-1] < element:
                    del yes['Queen'][half][i]
                    n = n - 1
                else:
                    i = i + 1
if len(yes['Queen']['left']) > 0 or len(yes['Queen']['right']) > 0 or len(yes['Queen']['down']) > 0 or len(yes['Queen']['up']) > 0 or len(yes['Queen']['left-up']) > 0 or len(yes['Queen']['left-down']) > 0 or len(yes['Queen']['right-up']) > 0 or len(yes['Queen']['right-down']) > 0 or len(yes['Bishop']['right-down']) > 0 or len(yes['Bishop']['right-up']) > 0 or len(yes['Bishop']['left-up']) > 0 or len(yes['Bishop']['left-down']) > 0 or len(yes['Rook']['left']) > 0 or len(yes['Rook']['right']) > 0 or len(yes['Rook']['up']) > 0 or len(yes['Rook']['down']) > 0:
    print("YES")
else: print("NO")

def in_ls(name_type,string):
	string = string.split()
	string = map(name_type, string)
	string = list(string)
	return string
n = int(input())
king = in_ls(int,input())
cord = {}
for i in range(0,n):
	in_str = input().split()
	x = int(in_str[1])
	y = int(in_str[2])
	cord[(x,y)] = in_str[0]
nearest = []
for i in range (0,8):
    nearest.append((1000000000000000000, 0))
for el in cord.keys():
    res = (el[0]-king[0], el[1]-king[1])
    if res[0] == 0:
        if res[1] > 0:
            if abs(res[1]) < nearest[0][0]:
                nearest[0] = (abs(res[1]), el)
        else:
            if abs(res[1]) < nearest[4][0]:
                nearest[4] = (abs(res[1]), el)
    if res[1] == 0:
        if res[0] > 0:
            if abs(res[0]) < nearest[6][0]:
                nearest[6] = (abs(res[0]), el)
        else:
            if abs(res[0]) < nearest[2][0]:
                nearest[2] = (abs(res[0]), el)
    if abs(res[0]) == abs(res[1]):
        if res[0] > 0 and res[1] > 0:
            if abs(res[0]) < nearest[7][0]:
                nearest[7] = (abs(res[0]), el)
        if res[0] < 0 and res[1] > 0:
            if abs(res[0]) < nearest[1][0]:
                nearest[1] = (abs(res[0]), el)
        if res[0] < 0 and res[1] < 0:
            if abs(res[0]) < nearest[3][0]:
                nearest[3] = (abs(res[0]), el)
        if res[0] > 0 and res[1] < 0:
            if abs(res[0]) < nearest[5][0]:
                nearest[5] = (abs(res[0]), el)
check = False
for i in range (8):
    if nearest[i][1] != 0:
        if i in [1,3,5,7]:
            if cord[nearest[i][1]] == "Q" or cord[nearest[i][1]] == "B":
                check = True
        else:
            if cord[nearest[i][1]] == "R" or cord[nearest[i][1]] == "Q":
                check = True

if check:
    print("YES")
else:
    print("NO")

def dist(cur, king):
    distance = abs(cur[0] - king[0]) ** 2 + abs(cur[1] - king[1]) ** 2
    direction = ''
    if cur[0] > king[0]:
        direction += 'l'
    elif cur[0] < king[0]:
        direction += 'r'

    if cur[1] > king[1]:
        direction += 'u'
    elif cur[1] < king[1]:
        direction += 'd'

    return distance, direction


amount = int(input())

king = input().split()
king = [int(k) for k in king]

all_figurs = {}
figurs = {}
for i in range(amount):
    figura = input().split()
    all_figurs[(int(figura[1]), int(figura[2]))] = figura[0]

for key in all_figurs.keys():
    if key[0] == king[0] or key[1] == king[1] or abs(king[0] - key[0]) == abs(king[1] - key[1]):
        figurs[key] = all_figurs[key]

nearest = {k:(10**100, '?')  for k in ['l', 'lu', 'ld', 'r', 'ru', 'rd', 'u', 'd']}

for key in figurs.keys():
    distance, direction = dist(key, king)
    if nearest[direction][0] > distance:
        nearest[direction] = (distance, figurs[key])

is_shah = False

for key in nearest.keys():
    if nearest[key][1] in ['Q', 'B'] and len(key) == 2:
        is_shah = True
        break
    if nearest[key][1] in ['Q', 'R'] and len(key) == 1:
        is_shah = True
        break


if is_shah:
    print('YES')
else:
    print('NO')

MAX_NUM = 10**9
n = int(input())
king_x, king_y = map(int, input().split())
nomakers = {'Rook': {'right-down':[], 'right-up':[], 'left-down':[], 'left-up':[]}, 'Bishop': {'left':[], 'right':[], 'up':[], 'down':[]}}
yes = {'Queen':{'right-down':[], 'right-up':[], 'left-down':[], 'left-up':[],'left':[], 'right':[], 'up':[], 'down':[]},'Bishop': {'right-down':[], 'right-up':[], 'left-down':[], 'left-up':[]}, 'Rook': {'left':[], 'right':[], 'up':[], 'down':[]}}
for i in range(n):
    figure, figure_x, figure_y = input().split()
    figure_x, figure_y = int(figure_x), int(figure_y)
    if figure == 'Q':
        if figure_x == king_x:
            if figure_y < king_y: half = 'down'
            else: half = 'up'
            yes['Queen'][half].append(abs(king_y - figure_y))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Queen'][half][-1]:
                    del yes['Queen'][half][-1]
                    break
        elif figure_y == king_y:
            if figure_x < king_x: half = 'left'
            else: half = 'right'
            yes['Queen'][half].append(abs(king_x - figure_x))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Queen'][half][-1]:
                    del yes['Queen'][half][-1]
                    break
        elif abs(figure_x - king_x) == abs(figure_y - king_y):
            if figure_x > king_x:
                if figure_y > king_y: quarter = 'right-up'
                else: quarter = 'right-down'
            else:
                if figure_y > king_y: quarter = 'left-up'
                else: quarter = 'left-down'
            yes['Queen'][quarter].append(abs(king_x - figure_x))
            for i in range(len(nomakers['Rook'][quarter])):
                if nomakers['Rook'][quarter][i]<yes['Queen'][quarter][-1]:
                    del yes['Queen'][quarter][-1]
                    break
    elif figure == 'R':
        if figure_x == king_x:
            if figure_y < king_y: half = 'down'
            else: half = 'up'
            yes['Rook'][half].append(abs(king_y - figure_y))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Rook'][half][-1]:
                    del yes['Rook'][half][-1]
                    break
        elif figure_y == king_y:
            if figure_x > king_x: half = 'right'
            else: half = 'left'
            yes['Rook'][half].append(abs(king_x - figure_x))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Rook'][half][-1]:
                    del yes['Rook'][half][-1]
                    break
        elif abs(figure_x - king_x) == abs(figure_y - king_y):
            if figure_x > king_x:
                if figure_y > king_y: quarter = 'right-up'
                else: quarter = 'right-down'
            else:
                if figure_y > king_y: quarter = 'left-up'
                else: quarter = 'left-down'
            nomakers['Rook'][quarter].append(abs(figure_x - king_x))
            i = 0
            n = len(yes['Queen'][quarter])
            while i < n:
                element = yes['Queen'][quarter][i]
                if nomakers['Rook'][quarter][-1] < element:
                    del yes['Queen'][quarter][i]
                    n = n - 1
                else:
                    i = i + 1
            i = 0
            n = len(yes['Bishop'][quarter])
            while i < n:
                element = yes['Bishop'][quarter][i]
                if nomakers['Rook'][quarter][-1] < element:
                    del yes['Bishop'][quarter][i]
                    n = n - 1
                else:
                    i = i + 1
    else:
        if abs(figure_x - king_x) == abs(figure_y - king_y):
            if figure_x > king_x:
                if figure_y > king_y: quarter = 'right-up'
                else: quarter = 'right-down'
            else:
                if figure_y > king_y: quarter = 'left-up'
                else: quarter = 'left-down'
            yes['Bishop'][quarter].append(abs(figure_x - king_x))
            for i in range(len(nomakers['Rook'][quarter])):
                if nomakers['Rook'][quarter][i] < yes['Bishop'][quarter][-1]:
                    del yes['Bishop'][quarter][-1]
                    break
        elif figure_x == king_x or figure_y == king_y:
            if figure_y < king_y:
                a = figure_y - king_y
                half = 'down'
            elif figure_y > king_y:
                half = 'up'
                a = figure_y - king_y
            elif figure_x > king_x:
                a = figure_x - king_x
                half = 'right'
            else:
                a = figure_x - king_x
                half = 'left'
            nomakers['Bishop'][half].append(abs(a))
            i = 0
            n = len(yes['Rook'][half])
            while i < n:
                element = yes['Rook'][half][i]
                if nomakers['Bishop'][half][-1] < element:
                    del yes['Rook'][half][i]
                    n = n - 1
                else:
                    i = i + 1
            i = 0
            n = len(yes['Queen'][half])
            while i < n:
                element = yes['Queen'][half][i]
                if nomakers['Bishop'][half][-1] < element:
                    del yes['Queen'][half][i]
                    n = n - 1
                else:
                    i = i + 1
if len(yes['Queen']['left']) > 0 or len(yes['Queen']['right']) > 0 or len(yes['Queen']['down']) > 0 or len(yes['Queen']['up']) > 0 or len(yes['Queen']['left-up']) > 0 or len(yes['Queen']['left-down']) > 0 or len(yes['Queen']['right-up']) > 0 or len(yes['Queen']['right-down']) > 0 or len(yes['Bishop']['right-down']) > 0 or len(yes['Bishop']['right-up']) > 0 or len(yes['Bishop']['left-up']) > 0 or len(yes['Bishop']['left-down']) > 0 or len(yes['Rook']['left']) > 0 or len(yes['Rook']['right']) > 0 or len(yes['Rook']['up']) > 0 or len(yes['Rook']['down']) > 0:
    print("YES")
else: print("NO")

MAX_NUM = 10**9
n = int(input())
king_x, king_y = [int(x) for x in input().split()]
nomakers = {'Rook': {'right-down':[], 'right-up':[], 'left-down':[], 'left-up':[]}, 'Bishop': {'left':[], 'right':[], 'up':[], 'down':[]}}
yes = {'Queen':{'right-down':[], 'right-up':[], 'left-down':[], 'left-up':[],'left':[], 'right':[], 'up':[], 'down':[]},'Bishop': {'right-down':[], 'right-up':[], 'left-down':[], 'left-up':[]}, 'Rook': {'left':[], 'right':[], 'up':[], 'down':[]}}
for i in range(n):
    figure, figure_x, figure_y = input().split()
    figure_x, figure_y = [int(x) for x in [figure_x, figure_y]]
    if figure == 'Q':
        if figure_x == king_x:
            if figure_y < king_y: half = 'down'
            else: half = 'up'
            yes['Queen'][half].append(abs(king_y - figure_y))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Queen'][half][-1]:
                    del yes['Queen'][half][-1]
                    break
        elif figure_y == king_y:
            if figure_x < king_x: half = 'left'
            else: half = 'right'
            yes['Queen'][half].append(abs(king_x - figure_x))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Queen'][half][-1]:
                    del yes['Queen'][half][-1]
                    break
        elif abs(figure_x - king_x) == abs(figure_y - king_y):
            if figure_x > king_x:
                if figure_y > king_y: quarter = 'right-up'
                else: quarter = 'right-down'
            else:
                if figure_y > king_y: quarter = 'left-up'
                else: quarter = 'left-down'
            yes['Queen'][quarter].append(abs(king_x - figure_x))
            for i in range(len(nomakers['Rook'][quarter])):
                if nomakers['Rook'][quarter][i]<yes['Queen'][quarter][-1]:
                    del yes['Queen'][quarter][-1]
                    break
    elif figure == 'R':
        if figure_x == king_x:
            if figure_y < king_y: half = 'down'
            else: half = 'up'
            yes['Rook'][half].append(abs(king_y - figure_y))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Rook'][half][-1]:
                    del yes['Rook'][half][-1]
                    break
        elif figure_y == king_y:
            if figure_x > king_x: half = 'right'
            else: half = 'left'
            yes['Rook'][half].append(abs(king_x - figure_x))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Rook'][half][-1]:
                    del yes['Rook'][half][-1]
                    break
        elif abs(figure_x - king_x) == abs(figure_y - king_y):
            if figure_x > king_x:
                if figure_y > king_y: quarter = 'right-up'
                else: quarter = 'right-down'
            else:
                if figure_y > king_y: quarter = 'left-up'
                else: quarter = 'left-down'
            nomakers['Rook'][quarter].append(abs(figure_x - king_x))
            i = 0
            n = len(yes['Queen'][quarter])
            while i < n:
                element = yes['Queen'][quarter][i]
                if nomakers['Rook'][quarter][-1] < element:
                    del yes['Queen'][quarter][i]
                    n = n - 1
                else:
                    i = i + 1
            i = 0
            n = len(yes['Bishop'][quarter])
            while i < n:
                element = yes['Bishop'][quarter][i]
                if nomakers['Rook'][quarter][-1] < element:
                    del yes['Bishop'][quarter][i]
                    n = n - 1
                else:
                    i = i + 1
    else:
        if abs(figure_x - king_x) == abs(figure_y - king_y):
            if figure_x > king_x:
                if figure_y > king_y: quarter = 'right-up'
                else: quarter = 'right-down'
            else:
                if figure_y > king_y: quarter = 'left-up'
                else: quarter = 'left-down'
            yes['Bishop'][quarter].append(abs(figure_x - king_x))
            for i in range(len(nomakers['Rook'][quarter])):
                if nomakers['Rook'][quarter][i] < yes['Bishop'][quarter][-1]:
                    del yes['Bishop'][quarter][-1]
                    break
        elif figure_x == king_x or figure_y == king_y:
            if figure_y < king_y:
                a = figure_y - king_y
                half = 'down'
            elif figure_y > king_y:
                half = 'up'
                a = figure_y - king_y
            elif figure_x > king_x:
                a = figure_x - king_x
                half = 'right'
            else:
                a = figure_x - king_x
                half = 'left'
            nomakers['Bishop'][half].append(abs(a))
            i = 0
            n = len(yes['Rook'][half])
            while i < n:
                element = yes['Rook'][half][i]
                if nomakers['Bishop'][half][-1] < element:
                    del yes['Rook'][half][i]
                    n = n - 1
                else:
                    i = i + 1
            i = 0
            n = len(yes['Queen'][half])
            while i < n:
                element = yes['Queen'][half][i]
                if nomakers['Bishop'][half][-1] < element:
                    del yes['Queen'][half][i]
                    n = n - 1
                else:
                    i = i + 1
if len(yes['Queen']['left']) > 0 or len(yes['Queen']['right']) > 0 or len(yes['Queen']['down']) > 0 or len(yes['Queen']['up']) > 0 or len(yes['Queen']['left-up']) > 0 or len(yes['Queen']['left-down']) > 0 or len(yes['Queen']['right-up']) > 0 or len(yes['Queen']['right-down']) > 0 or len(yes['Bishop']['right-down']) > 0 or len(yes['Bishop']['right-up']) > 0 or len(yes['Bishop']['left-up']) > 0 or len(yes['Bishop']['left-down']) > 0 or len(yes['Rook']['left']) > 0 or len(yes['Rook']['right']) > 0 or len(yes['Rook']['up']) > 0 or len(yes['Rook']['down']) > 0:
    print("YES")
else: print("NO")

MAX_NUM = 10**9
n = int(input())
king_x, king_y = map(int, input().split())
nomakers = {'Rook': {'right-down':[], 'right-up':[], 'left-down':[], 'left-up':[]}, 'Bishop': {'left':[], 'right':[], 'up':[], 'down':[]}}
yes = {'Queen':{'right-down':[], 'right-up':[], 'left-down':[], 'left-up':[],'left':[], 'right':[], 'up':[], 'down':[]},'Bishop': {'right-down':[], 'right-up':[], 'left-down':[], 'left-up':[]}, 'Rook': {'left':[], 'right':[], 'up':[], 'down':[]}}
for i in range(n):
    figure, figure_x, figure_y = input().split()
    figure_x, figure_y = map(int, [figure_x,figure_y])
    if figure == 'Q':
        if figure_x == king_x:
            if figure_y < king_y: half = 'down'
            else: half = 'up'
            yes['Queen'][half].append(abs(king_y - figure_y))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Queen'][half][-1]:
                    del yes['Queen'][half][-1]
                    break
        elif figure_y == king_y:
            if figure_x < king_x: half = 'left'
            else: half = 'right'
            yes['Queen'][half].append(abs(king_x - figure_x))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Queen'][half][-1]:
                    del yes['Queen'][half][-1]
                    break
        elif abs(figure_x - king_x) == abs(figure_y - king_y):
            if figure_x > king_x:
                if figure_y > king_y: quarter = 'right-up'
                else: quarter = 'right-down'
            else:
                if figure_y > king_y: quarter = 'left-up'
                else: quarter = 'left-down'
            yes['Queen'][quarter].append(abs(king_x - figure_x))
            for i in range(len(nomakers['Rook'][quarter])):
                if nomakers['Rook'][quarter][i]<yes['Queen'][quarter][-1]:
                    del yes['Queen'][quarter][-1]
                    break
    elif figure == 'R':
        if figure_x == king_x:
            if figure_y < king_y: half = 'down'
            else: half = 'up'
            yes['Rook'][half].append(abs(king_y - figure_y))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Rook'][half][-1]:
                    del yes['Rook'][half][-1]
                    break
        elif figure_y == king_y:
            if figure_x > king_x: half = 'right'
            else: half = 'left'
            yes['Rook'][half].append(abs(king_x - figure_x))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Rook'][half][-1]:
                    del yes['Rook'][half][-1]
                    break
        elif abs(figure_x - king_x) == abs(figure_y - king_y):
            if figure_x > king_x:
                if figure_y > king_y: quarter = 'right-up'
                else: quarter = 'right-down'
            else:
                if figure_y > king_y: quarter = 'left-up'
                else: quarter = 'left-down'
            nomakers['Rook'][quarter].append(abs(figure_x - king_x))
            i = 0
            n = len(yes['Queen'][quarter])
            while i < n:
                element = yes['Queen'][quarter][i]
                if nomakers['Rook'][quarter][-1] < element:
                    del yes['Queen'][quarter][i]
                    n = n - 1
                else:
                    i = i + 1
            i = 0
            n = len(yes['Bishop'][quarter])
            while i < n:
                element = yes['Bishop'][quarter][i]
                if nomakers['Rook'][quarter][-1] < element:
                    del yes['Bishop'][quarter][i]
                    n = n - 1
                else:
                    i = i + 1
    else:
        if abs(figure_x - king_x) == abs(figure_y - king_y):
            if figure_x > king_x:
                if figure_y > king_y: quarter = 'right-up'
                else: quarter = 'right-down'
            else:
                if figure_y > king_y: quarter = 'left-up'
                else: quarter = 'left-down'
            yes['Bishop'][quarter].append(abs(figure_x - king_x))
            for i in range(len(nomakers['Rook'][quarter])):
                if nomakers['Rook'][quarter][i] < yes['Bishop'][quarter][-1]:
                    del yes['Bishop'][quarter][-1]
                    break
        elif figure_x == king_x or figure_y == king_y:
            if figure_y < king_y:
                a = figure_y - king_y
                half = 'down'
            elif figure_y > king_y:
                half = 'up'
                a = figure_y - king_y
            elif figure_x > king_x:
                a = figure_x - king_x
                half = 'right'
            else:
                a = figure_x - king_x
                half = 'left'
            nomakers['Bishop'][half].append(abs(a))
            i = 0
            n = len(yes['Rook'][half])
            while i < n:
                element = yes['Rook'][half][i]
                if nomakers['Bishop'][half][-1] < element:
                    del yes['Rook'][half][i]
                    n = n - 1
                else:
                    i = i + 1
            i = 0
            n = len(yes['Queen'][half])
            while i < n:
                element = yes['Queen'][half][i]
                if nomakers['Bishop'][half][-1] < element:
                    del yes['Queen'][half][i]
                    n = n - 1
                else:
                    i = i + 1
if len(yes['Queen']['left']) > 0 or len(yes['Queen']['right']) > 0 or len(yes['Queen']['down']) > 0 or len(yes['Queen']['up']) > 0 or len(yes['Queen']['left-up']) > 0 or len(yes['Queen']['left-down']) > 0 or len(yes['Queen']['right-up']) > 0 or len(yes['Queen']['right-down']) > 0 or len(yes['Bishop']['right-down']) > 0 or len(yes['Bishop']['right-up']) > 0 or len(yes['Bishop']['left-up']) > 0 or len(yes['Bishop']['left-down']) > 0 or len(yes['Rook']['left']) > 0 or len(yes['Rook']['right']) > 0 or len(yes['Rook']['up']) > 0 or len(yes['Rook']['down']) > 0:
    print("YES")
else: print("NO")

MAX_NUM = 10**9
MIN_NUM = -10**9
n = int(input())
king_x, king_y = map(int, input().split())
nomakers = {'Rook': {'right-down':[], 'right-up':[], 'left-down':[], 'left-up':[]}, 'Bishop': {'left':[], 'right':[], 'up':[], 'down':[]}}
yes = {'Queen':{'right-down':[], 'right-up':[], 'left-down':[], 'left-up':[],'left':[], 'right':[], 'up':[], 'down':[]},'Bishop': {'right-down':[], 'right-up':[], 'left-down':[], 'left-up':[]}, 'Rook': {'left':[], 'right':[], 'up':[], 'down':[]}}
for i in range(n):
    figure, figure_x, figure_y = input().split()
    figure_x, figure_y = int(figure_x), int(figure_y)
    if figure == 'Q':
        if figure_x == king_x:
            if figure_y < king_y: half = 'down'
            else: half = 'up'
            yes['Queen'][half].append(abs(king_y - figure_y))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Queen'][half][-1]:
                    del yes['Queen'][half][-1]
                    break
        elif figure_y == king_y:
            if figure_x < king_x: half = 'left'
            else: half = 'right'
            yes['Queen'][half].append(abs(king_x - figure_x))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Queen'][half][-1]:
                    del yes['Queen'][half][-1]
                    break
        elif abs(figure_x - king_x) == abs(figure_y - king_y):
            if figure_x > king_x:
                if figure_y > king_y: quarter = 'right-up'
                else: quarter = 'right-down'
            else:
                if figure_y > king_y: quarter = 'left-up'
                else: quarter = 'left-down'
            yes['Queen'][quarter].append(abs(king_x - figure_x))
            for i in range(len(nomakers['Rook'][quarter])):
                if nomakers['Rook'][quarter][i]<yes['Queen'][quarter][-1]:
                    del yes['Queen'][quarter][-1]
                    break
    elif figure == 'R':
        if figure_x == king_x:
            if figure_y < king_y: half = 'down'
            else: half = 'up'
            yes['Rook'][half].append(abs(king_y - figure_y))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Rook'][half][-1]:
                    del yes['Rook'][half][-1]
                    break
        elif figure_y == king_y:
            if figure_x > king_x: half = 'right'
            else: half = 'left'
            yes['Rook'][half].append(abs(king_x - figure_x))
            for i in range(len(nomakers['Bishop'][half])):
                if nomakers['Bishop'][half][i]<yes['Rook'][half][-1]:
                    del yes['Rook'][half][-1]
                    break
        elif abs(figure_x - king_x) == abs(figure_y - king_y):
            if figure_x > king_x:
                if figure_y > king_y: quarter = 'right-up'
                else: quarter = 'right-down'
            else:
                if figure_y > king_y: quarter = 'left-up'
                else: quarter = 'left-down'
            nomakers['Rook'][quarter].append(abs(figure_x - king_x))
            i = 0
            n = len(yes['Queen'][quarter])
            while i < n:
                element = yes['Queen'][quarter][i]
                if nomakers['Rook'][quarter][-1] < element:
                    del yes['Queen'][quarter][i]
                    n = n - 1
                else:
                    i = i + 1
            i = 0
            n = len(yes['Bishop'][quarter])
            while i < n:
                element = yes['Bishop'][quarter][i]
                if nomakers['Rook'][quarter][-1] < element:
                    del yes['Bishop'][quarter][i]
                    n = n - 1
                else:
                    i = i + 1
    else:
        if abs(figure_x - king_x) == abs(figure_y - king_y):
            if figure_x > king_x:
                if figure_y > king_y: quarter = 'right-up'
                else: quarter = 'right-down'
            else:
                if figure_y > king_y: quarter = 'left-up'
                else: quarter = 'left-down'
            yes['Bishop'][quarter].append(abs(figure_x - king_x))
            for i in range(len(nomakers['Rook'][quarter])):
                if nomakers['Rook'][quarter][i] < yes['Bishop'][quarter][-1]:
                    del yes['Bishop'][quarter][-1]
                    break
        elif figure_x == king_x or figure_y == king_y:
            if figure_y < king_y:
                a = figure_y - king_y
                half = 'down'
            elif figure_y > king_y:
                half = 'up'
                a = figure_y - king_y
            elif figure_x > king_x:
                a = figure_x - king_x
                half = 'right'
            else:
                a = figure_x - king_x
                half = 'left'
            nomakers['Bishop'][half].append(abs(a))
            i = 0
            n = len(yes['Rook'][half])
            while i < n:
                element = yes['Rook'][half][i]
                if nomakers['Bishop'][half][-1] < element:
                    del yes['Rook'][half][i]
                    n = n - 1
                else:
                    i = i + 1
            i = 0
            n = len(yes['Queen'][half])
            while i < n:
                element = yes['Queen'][half][i]
                if nomakers['Bishop'][half][-1] < element:
                    del yes['Queen'][half][i]
                    n = n - 1
                else:
                    i = i + 1
if len(yes['Queen']['left']) > 0 or len(yes['Queen']['right']) > 0 or len(yes['Queen']['down']) > 0 or len(yes['Queen']['up']) > 0 or len(yes['Queen']['left-up']) > 0 or len(yes['Queen']['left-down']) > 0 or len(yes['Queen']['right-up']) > 0 or len(yes['Queen']['right-down']) > 0 or len(yes['Bishop']['right-down']) > 0 or len(yes['Bishop']['right-up']) > 0 or len(yes['Bishop']['left-up']) > 0 or len(yes['Bishop']['left-down']) > 0 or len(yes['Rook']['left']) > 0 or len(yes['Rook']['right']) > 0 or len(yes['Rook']['up']) > 0 or len(yes['Rook']['down']) > 0:
    print("YES")
else: print("NO")