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:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 20000;

const int dxs[] = {1, 0, -1, 0};
const int dys[] = {0, 1, 0, -1};

/* typedef */

typedef pair<int,int> pii;
typedef map<pii,int> mpii;

struct Futon {
  int x0, y0, x1, y1;
  Futon() {}

  void init(int x, int y, char dir) {
    x0 = x, y0 = y;
    if (dir == 'x') x1 = x + 1, y1 = y;
    else x1 = x, y1 = y + 1;
  }

  bool _adjcell(int ax, int ay, int bx, int by) const {
    return
      (ax == bx && (ay == by - 1 || ay == by + 1)) ||
      (ay == by && (ax == bx - 1 || ax == bx + 1));
  }
  
  bool adj(const Futon& f0) const {
    return
      _adjcell(x0, y0, f0.x0, f0.y0) ||
      _adjcell(x0, y0, f0.x1, f0.y1) ||
      _adjcell(x1, y1, f0.x0, f0.y0) ||
      _adjcell(x1, y1, f0.x1, f0.y1);
  }

  bool operator<(const Futon& f0) const {
    return (x0 < f0.x0 || (x0 == f0.x0 && y0 < f0.y0));
  }
  
  void print() { printf("(%d,%d)-(%d,%d)\n", x0, y0, x1, y1); }
};

typedef set<Futon> sftn;

enum { CH = -1, CF = -2 };

/* global variables */

int n;
Futon ftns[MAX_N];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> n;
    if (n == 0) break;

    mpii cells;
    sftn sf;
    
    for (int i = 0; i < n; i++) {
      int x, y;
      char dir;
      cin >> x >> y >> dir;

      ftns[i].init(x, y, dir);
      cells[pii(ftns[i].x0, ftns[i].y0)] = i;
      cells[pii(ftns[i].x1, ftns[i].y1)] = i;
      sf.insert(ftns[i]);
    }

    bool ok = true;
    
    while (! sf.empty()) {
      Futon f = *(sf.begin());
      sf.erase(f);

      queue<Futon> q;
      q.push(f);
      cells[pii(f.x0, f.y0)] = CH;
      cells[pii(f.x1, f.y1)] = CF;

      while (! q.empty()) {
	Futon u = q.front(); q.pop();

	int c0 = cells[pii(u.x0, u.y0)];
	int c1 = cells[pii(u.x1, u.y1)];

	for (int di = 0; di < 4; di++) {
	  int cx = u.x0 + dxs[di], cy = u.y0 + dys[di];
	  if (cx != u.x1 || cy != u.y1) {
	    mpii::iterator mit = cells.find(pii(cx, cy));
	    if (mit != cells.end()) {
	      int ax = mit->first.first;
	      int ay = mit->first.second;
	      int k = mit->second;
	      if (k >= 0) {
		Futon& v = ftns[k];
		cells[pii(cx, cy)] = c0;
		if (cx == v.x0 && cy == v.y0)
		  cells[pii(v.x1, v.y1)] = c1;
		else
		  cells[pii(v.x0, v.y0)] = c1;
		sf.erase(v);
		q.push(v);
	      }
	      else if (k != c0) {
		ok = false;
		break;
	      }
	    }
	  }
	}
	if (! ok) break;
	
	for (int di = 0; di < 4; di++) {
	  int cx = u.x1 + dxs[di], cy = u.y1 + dys[di];
	  if (cx != u.x0 || cy != u.y0) {
	    mpii::iterator mit = cells.find(pii(cx, cy));
	    if (mit != cells.end()) {
	      int ax = mit->first.first;
	      int ay = mit->first.second;
	      int k = mit->second;
	      if (k >= 0) {
		Futon& v = ftns[k];
		cells[pii(cx, cy)] = c1;
		if (cx == v.x0 && cy == v.y0)
		  cells[pii(v.x1, v.y1)] = c0;
		else
		  cells[pii(v.x0, v.y0)] = c0;
		sf.erase(v);
		q.push(v);
	      }
	      else if (k != c1) {
		ok = false;
		break;
	      }
	    }
	  }
	}
	if (! ok) break;
      }
      if (! ok) break;
    }

    if (false) {
      for (mpii::iterator mit = cells.begin(); mit != cells.end(); mit++) {
	int x = mit->first.first;
	int y = mit->first.second;
	int k = mit->second;
	printf("(%d,%d)=%d\n", x, y, k);
      }
    }
    
    cout << (ok ? "Yes" : "No") << endl;
  }

  return 0;
}