using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("4 3");
WillReturn.Add("4 1 B");
WillReturn.Add("3 2 W");
WillReturn.Add("1 3 B");
//Yes
}
else if (InputPattern == "Input2") {
WillReturn.Add("2 2");
WillReturn.Add("1 2 W");
WillReturn.Add("2 2 B");
//No
}
else if (InputPattern == "Input3") {
WillReturn.Add("1 1");
WillReturn.Add("1 1 W");
//Yes
}
else if (InputPattern == "Input4") {
WillReturn.Add("2289 10");
WillReturn.Add("1700 1083 W");
WillReturn.Add("528 967 B");
WillReturn.Add("1789 211 W");
WillReturn.Add("518 1708 W");
WillReturn.Add("1036 779 B");
WillReturn.Add("136 657 B");
WillReturn.Add("759 1497 B");
WillReturn.Add("902 1309 B");
WillReturn.Add("1814 712 B");
WillReturn.Add("936 763 B");
//No
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
struct XYCInfoDef
{
internal long X;
internal long Y;
internal string C;
}
static List<XYCInfoDef> mXYCInfoList = new List<XYCInfoDef>();
static void Main()
{
List<string> InputList = GetInputList();
var XSet = new HashSet<long>();
foreach (string Eachstr in InputList.Skip(1)) {
string[] SplitArr = Eachstr.Split(' ');
XYCInfoDef WillAdd;
WillAdd.X = long.Parse(SplitArr[0]);
WillAdd.Y = long.Parse(SplitArr[1]);
WillAdd.C = SplitArr[2];
mXYCInfoList.Add(WillAdd);
XSet.Add(WillAdd.X);
}
Dictionary<long, long> ZaatuDict = DeriveZaatuDict(XSet);
var InsLazySegmentTree = new LazySegmentTree(ZaatuDict.Count, 0);
long UB_InsLazySegmentTree = InsLazySegmentTree.GetUB();
var Query1 = mXYCInfoList.OrderBy(pX => pX.Y);
foreach (XYCInfoDef EachXYCInfo in Query1) {
if (EachXYCInfo.C != "B") continue;
long ZaatuX = ZaatuDict[EachXYCInfo.X];
InsLazySegmentTree.Internal_RangeUpdate(0, ZaatuX, EachXYCInfo.Y);
}
var Query2 = mXYCInfoList;
foreach (XYCInfoDef EachXYCInfo in Query2) {
if (EachXYCInfo.C != "W") continue;
long ZaatuX = ZaatuDict[EachXYCInfo.X];
long RangeMax = InsLazySegmentTree.Internal_Query(ZaatuX, UB_InsLazySegmentTree);
if (RangeMax >= EachXYCInfo.Y) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
//////////////////////////////////////////////////////////////////////////
// 列挙を引数として、座標圧縮し、座圧後の値[座圧前の値]なDictを返す
//////////////////////////////////////////////////////////////////////////
static Dictionary<long, long> DeriveZaatuDict(IEnumerable<long> pEnum)
{
var ZaatuDict = new Dictionary<long, long>();
var ValSet = new HashSet<long>(pEnum);
long No = 0;
foreach (long EachVal in ValSet.OrderBy(pX => pX)) {
ZaatuDict[EachVal] = No;
No++;
}
return ZaatuDict;
}
}
#region LazySegmentTree
// LazySegmentTreeクラス (RMaxQ and RUQ)
internal class LazySegmentTree
{
private long[] mTreeNodeArr;
private long UB; // 木のノードの配列のUB
private long mLeafCnt; // 葉ノードの数
private long mExternalArrUB;
private long?[] mLazyArr; // 遅延配列
// ノードの添字を引数とし、範囲の開始添字と終了添字を持つ配列
private struct RangeInfoDef
{
internal long StaInd;
internal long EndInd;
}
private RangeInfoDef[] mRangeInfo;
// ノードのIndexの列挙を返す
internal IEnumerable<long> GetNodeIndEnum()
{
for (long I = 0; I <= mExternalArrUB; I++) {
yield return I;
}
}
// 木のノードのUBを返す
internal long GetUB()
{
return mExternalArrUB;
}
// コンストラクタ
internal LazySegmentTree(long pExternalArrUB, long pInitVal)
{
mExternalArrUB = pExternalArrUB;
// 簡単のため、葉ノード数を2のべき乗に
long ArrLength = 0;
for (long I = 1; I < long.MaxValue; I *= 2) {
ArrLength += I;
mLeafCnt = I;
if (pExternalArrUB + 1 < mLeafCnt) break;
}
// すべての値をpInitValに
UB = ArrLength - 1;
mTreeNodeArr = new long[UB + 1];
for (long I = 0; I <= UB; I++) {
mTreeNodeArr[I] = pInitVal;
}
// 遅延配列を初期化
mLazyArr = new long?[UB + 1];
// ノードの添字を引数とし、範囲の開始添字と終了添字を持つ配列の作成
mRangeInfo = new RangeInfoDef[UB + 1];
for (long I = 0; I <= UB; I++) {
if (I == 0) {
RangeInfoDef WillSet1;
WillSet1.StaInd = 0;
WillSet1.EndInd = mLeafCnt - 1;
mRangeInfo[I] = WillSet1;
continue;
}
long ParentNode = DeriveParentNode(I);
RangeInfoDef ParentRangeInfo = mRangeInfo[ParentNode];
RangeInfoDef WillSet2;
long Mid = (ParentRangeInfo.StaInd + ParentRangeInfo.EndInd) / 2;
if (I % 2 == 1) { // 奇数ノードの場合
WillSet2.StaInd = ParentRangeInfo.StaInd;
WillSet2.EndInd = Mid;
}
else { // 偶数ノードの場合
WillSet2.StaInd = Mid + 1;
WillSet2.EndInd = ParentRangeInfo.EndInd;
}
mRangeInfo[I] = WillSet2;
}
}
// 親ノードの添字を取得
private long DeriveParentNode(long pTarget)
{
return (pTarget - 1) / 2;
}
// 子ノードの添字(小さいほう)を取得
private long DeriveChildNode(long pTarget)
{
return pTarget * 2 + 1;
}
// カレントノードを引数として、遅延評価を行う
private void LazyEval(long pCurrNode)
{
// 遅延配列が空なら何もしない
if (mLazyArr[pCurrNode].HasValue == false) return;
// 遅延配列の値を反映する
mTreeNodeArr[pCurrNode] = mLazyArr[pCurrNode].Value;
long ChildNode1 = DeriveChildNode(pCurrNode);
long ChildNode2 = ChildNode1 + 1;
if (ChildNode1 <= UB) {
mLazyArr[ChildNode1] = mLazyArr[pCurrNode].Value;
}
if (ChildNode2 <= UB) {
mLazyArr[ChildNode2] = mLazyArr[pCurrNode].Value;
}
// 伝播が終わったので、自ノードの遅延配列を空にする
mLazyArr[pCurrNode] = null;
}
// 開始添字と終了添字とカレントノードを引数として、区間更新を行う
internal void Internal_RangeUpdate(long pSearchStaInd, long pSearchEndInd, long pUpdateVal)
{
Private_RangeUpdate(pSearchStaInd, pSearchEndInd, pUpdateVal, 0);
}
private void Private_RangeUpdate(long pSearchStaInd, long pSearchEndInd, long pUpdateVal, long pCurrNode)
{
// カレントノードの遅延評価を行う
LazyEval(pCurrNode);
long CurrNodeStaInd = mRangeInfo[pCurrNode].StaInd;
long CurrNodeEndInd = mRangeInfo[pCurrNode].EndInd;
// OverLapしてなければ、何もしない
if (CurrNodeEndInd < pSearchStaInd || pSearchEndInd < CurrNodeStaInd) {
return;
}
// 完全に含んでいれば、遅延配列に値を入れた後に評価
if (pSearchStaInd <= CurrNodeStaInd && CurrNodeEndInd <= pSearchEndInd) {
mLazyArr[pCurrNode] = pUpdateVal;
LazyEval(pCurrNode);
return;
}
// そうでなければ、2つの区間に再帰呼出し
long ChildNode1 = DeriveChildNode(pCurrNode);
long ChildNode2 = ChildNode1 + 1;
Private_RangeUpdate(pSearchStaInd, pSearchEndInd, pUpdateVal, ChildNode1);
Private_RangeUpdate(pSearchStaInd, pSearchEndInd, pUpdateVal, ChildNode2);
// カレントノードの更新
mTreeNodeArr[pCurrNode] = Math.Max(mTreeNodeArr[ChildNode1], mTreeNodeArr[ChildNode2]);
}
// 開始添字と終了添字とカレントノードを引数として、最大値を返す
internal long Internal_Query(long pSearchStaInd, long pSearchEndInd)
{
return Private_Query(pSearchStaInd, pSearchEndInd, 0);
}
private long Private_Query(long pSearchStaInd, long pSearchEndInd, long pCurrNode)
{
// 該当ノードを遅延評価する
LazyEval(pCurrNode);
long CurrNodeStaInd = mRangeInfo[pCurrNode].StaInd;
long CurrNodeEndInd = mRangeInfo[pCurrNode].EndInd;
// OverLapしてなければ、long.MinValue
if (CurrNodeEndInd < pSearchStaInd || pSearchEndInd < CurrNodeStaInd)
return long.MinValue;
// 完全に含んでいれば、このノードの値
if (pSearchStaInd <= CurrNodeStaInd && CurrNodeEndInd <= pSearchEndInd)
return mTreeNodeArr[pCurrNode];
// そうでなければ、2つの子の最大値
long ChildNode1 = DeriveChildNode(pCurrNode);
long ChildNode2 = ChildNode1 + 1;
long ChildVal1 = Private_Query(pSearchStaInd, pSearchEndInd, ChildNode1);
long ChildVal2 = Private_Query(pSearchStaInd, pSearchEndInd, ChildNode2);
return Math.Max(ChildVal1, ChildVal2);
}
internal void DebugPrint()
{
for (long I = 0; I <= UB; I++) {
if (mLazyArr[I].HasValue) {
Console.WriteLine("mTreeNodeArr[{0}] = {1} , mLazyArr[{0}] = {2}",
I, mTreeNodeArr[I], mLazyArr[I]);
}
else {
Console.WriteLine("mTreeNodeArr[{0}] = {1}", I, mTreeNodeArr[I]);
}
}
}
}
#endregion