Problem: The sales department of Japanese Ancient Giant Corp. is visiting a hot spring resort for their recreational trip. For deepening their friendships, they are staying in one large room of a Japanese-style hotel called a ryokan.

In the ryokan, people sleep in Japanese-style beds called futons. They all have put their futons on the floor just as they like. Now they are ready for sleeping but they have one concern: they don’t like to go into their futons with their legs toward heads — this is regarded as a bad custom in Japanese tradition. However, it is not obvious whether they can follow a good custom. You are requested to write a program answering their question, as a talented programmer.

Here let's model the situation. The room is considered to be a grid on an xy-plane. As usual, x-axis points toward right and y-axis points toward up. Each futon occupies two adjacent cells. People put their pillows on either of the two cells. Their heads come to the pillows; their foots come to the other cells. If the cell of some person's foot becomes adjacent to the cell of another person's head, regardless their directions, then it is considered as a bad case. Otherwise people are all right.



Input

The input is a sequence of datasets. Each dataset is given in the following format:

n
x1 y1 dir1
...
xn yn dirn


n is the number of futons (1 ≤ n ≤ 20,000); (xi, yi) denotes the coordinates of the left-bottom corner of the i-th futon; diri is either 'x' or 'y' and denotes the direction of the i-th futon, where 'x' means the futon is put horizontally and 'y' means vertically. All coordinate values are non-negative integers not greater than 109 .

It is guaranteed that no two futons in the input overlap each other.

The input is terminated by a line with a single zero. This is not part of any dataset and thus should not be processed.

Output

For each dataset, print "Yes" in a line if it is possible to avoid a bad case, or "No" otherwise.

Example

Input

4
0 0 x
2 0 x
0 1 x
2 1 x
4
1 0 x
0 1 x
2 1 x
1 2 x
4
0 0 x
2 0 y
0 1 y
1 2 x
0


Output

Yes
No
Yes

Solution (in CPP):

Solution:
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

class Cell{
public:
  int id;
  int x;
  int y;
  bool has_head;
  bool has_leg;
  Cell(){}
  Cell(int _id,int _x,int _y) : id(_id), x(_x), y(_y),has_head(false),has_leg(false) {}
};

class Bed{
public:
  Cell head;
  Cell tail;
  bool has_head;

  Bed() {}
  Bed (Cell _c1, Cell _c2) : head(_c1),tail(_c2),has_head(false){}
  Cell* getCell(int x,int y){
    if(head.x == x && head.y == y){
      return &head;
    }

    else if(tail.x == x && tail.y == y){
      return &tail;
    }
  }

  Cell* getCellOtherSide(int x,int y){
    if(head.x == x && head.y == y){
      return &tail;
    }

    else if(tail.x == x && tail.y == y){
      return &head;
    }
  }

  bool is_used(){
    return (head.has_head || tail.has_head || head.has_leg || tail.has_leg);
  }

  bool is_same_bed(int x,int y){
    if((head.x == x && head.y == y) || (tail.x == x && tail.y == y)){
      return true;
    }
    return false;
  }
};

void dfs(map<P,Bed*>& stage, map<P,Bed*>::iterator it, bool used[20000]){
  int id = it->second->head.id;
  used[id] = true;

  int head_x = it->second->head.x;
  int head_y = it->second->head.y;
  bool is_head_leg = it->second->head.has_leg;
  bool is_head_head = it->second->head.has_head;

  int tail_x = it->second->tail.x;
  int tail_y = it->second->tail.y;
  bool is_tail_leg = it->second->tail.has_leg;
  bool is_tail_head = it->second->tail.has_head;

  map<P,Bed*>::iterator dst_bed;
  for(int i=0;i<4;i++){
    int dx = head_x + tx[i];
    int dy = head_y + ty[i];

    if(is_head_head){
      if((dst_bed = stage.find(P(dx,dy))) != stage.end()){
	if(dst_bed->second->is_used()) continue;

	dst_bed->second->getCell(dx,dy)->has_head = true;
	dst_bed->second->getCellOtherSide(dx,dy)->has_leg = true;
	// printf("x:%d y:%d %s\n",dx,dy,"h");
	dfs(stage,dst_bed,used);
      }
    }

    else if(is_head_leg){
      if((dst_bed = stage.find(P(dx,dy))) != stage.end()){
	if(dst_bed->second->is_used()) continue;

	dst_bed->second->getCell(dx,dy)->has_leg = true;
	dst_bed->second->getCellOtherSide(dx,dy)->has_head = true;
	// printf("x:%d y:%d %s\n",dx,dy,"l");
	dfs(stage,dst_bed,used);
      }
    }
  }
  for(int i=0;i<4;i++){
    int dx = tail_x + tx[i];
    int dy = tail_y + ty[i];
    
    if(is_tail_leg){
      if((dst_bed = stage.find(P(dx,dy))) != stage.end()){
	if(dst_bed->second->is_used()) continue;

	dst_bed->second->getCell(dx,dy)->has_leg = true;
	dst_bed->second->getCellOtherSide(dx,dy)->has_head = true;
	// printf("x:%d y:%d %s\n",dx,dy,"l");
	dfs(stage,dst_bed,used);
      }
    }

    else if(is_tail_head){
      if((dst_bed = stage.find(P(dx,dy))) != stage.end()){
	if(dst_bed->second->is_used()) continue;

	dst_bed->second->getCell(dx,dy)->has_head = true;
	dst_bed->second->getCellOtherSide(dx,dy)->has_leg = true;
	// printf("x:%d y:%d %s\n",dx,dy,"h");
	dfs(stage,dst_bed,used);
      }
    }
  }
}

bool checkStage(map<P,Bed*>& stage){
  for(map<P,Bed*>::iterator it = stage.begin();
    	it != stage.end();
    	it++){
    int id = it->second->head.id;

    int head_x = it->second->head.x;
    int head_y = it->second->head.y;
    bool is_head_leg = it->second->head.has_leg;
    bool is_head_head = it->second->head.has_head;

    int tail_x = it->second->tail.x;
    int tail_y = it->second->tail.y;
    bool is_tail_leg = it->second->tail.has_leg;
    bool is_tail_head = it->second->tail.has_head;

    map<P,Bed*>::iterator dst_bed;
    for(int i=0;i<4;i++){
      int dx = head_x + tx[i];
      int dy = head_y + ty[i];
      if(it->second->is_same_bed(dx,dy)) continue;
      if((dst_bed = stage.find(P(dx,dy))) != stage.end()){
	if(is_head_leg){
	  if(dst_bed->second->getCell(dx,dy)->has_head) return false;
	}
	else if(is_head_head){
	  if(dst_bed->second->getCell(dx,dy)->has_leg) return false;
	}
      }
    }

    for(int i=0;i<4;i++){
      int dx = tail_x + tx[i];
      int dy = tail_y + ty[i];
      if(it->second->is_same_bed(dx,dy)) continue;
      if((dst_bed = stage.find(P(dx,dy))) != stage.end()){
	if(is_tail_leg){
	  if(dst_bed->second->getCell(dx,dy)->has_head) return false;
	}
	else if(is_tail_head){
	  if(dst_bed->second->getCell(dx,dy)->has_leg) return false;
	}
      }
    }
  }
  return true;
}

int main(){
  int total_beds;
  while(~scanf("%d",&total_beds)){
    if(total_beds == 0) break;

    map<P,Bed*> stage;
    bool used[20000];
    memset(used,false,sizeof(used));
    
    for(int bed_idx = 0; bed_idx < total_beds; bed_idx++){
      int x,y;
      char dir[2];
      scanf("%d %d %s",&x,&y,dir);

      int dx = 0;
      int dy = 0;
      if(dir[0] == 'x'){
	dx = x+1;
	dy = y;
      }
      else if(dir[0] == 'y'){
	dx = x;
	dy = y+1;
      }

      Cell head(bed_idx,x,y);
      Cell tail(bed_idx,dx,dy);

      Bed* bed = new Bed(head,tail);

      stage[P(x,y)] = bed;
      stage[P(dx,dy)] = bed;
    }

    for(map<P,Bed*>::iterator it = stage.begin();
    	it != stage.end();
    	it++){
      int id = it->second->head.id;
      if(used[id]) continue;

      // printf("x:%d y:%d %s\n",it->second->head.x,it->second->head.y,"h");
      it->second->head.has_head = true;
      it->second->tail.has_leg = true;
      dfs(stage,it,used);
    }

    bool isok = checkStage(stage);
    printf("%s\n",isok ? "Yes" : "No");
  }
}