#include <bits/stdc++.h>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int N, W, H;
int sz;
int idx(int x, int y){
  if(y == 0) return x;
  if(x == W) return W + y;
  if(y == H) return W + H + W-x;
  return W+H+W+H-y;
}
int projc(int x, int y, int dir){
  switch(dir){
  case 0:
	return idx(x-min(x,y),y-min(x,y));
  case 1:
	return idx(x+min(W-x,y),y-min(W-x,y));
  case 2:
	return idx(x+min(W-x,H-y),y+min(W-x,H-y));
  case 3:
	return idx(x-min(x,H-y),y+min(x,H-y));
  }
  return -1;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  cin >> N >> W >> H;
  sz = 2*(W+H); 
  vector<PII> xs(N);
  REP(i,N){
	char f;
	int x, y; cin >> x >> y >> f;
	PII p;
	int ix = string("SENW").find(f);
	p.FF = projc(x,y,ix);
	p.SS = projc(x,y,(ix+1)%4);
	if(p.SS < p.FF) p.SS += sz;
	xs[i] = p;
  }

  int ans = N;
  REP(i,N) xs.EB(xs[i].FF+sz, xs[i].SS+sz);
  SORT(xs);

  for(int i=0;i<N;++i){
	int sum = 0;
	int e = -1;
	for(int j=i;j<i+N;++j){
	  if(xs[j].FF <= e){
		e = min(e, xs[j].SS);
	  }
	  else{
		++sum;
		e = xs[j].SS;
	  }
	}
	ans = min(ans, sum);
  }

  cout << ans << endl;
  
  return 0;
}
### Prompt

Generate a Cpp solution to the following problem:

Example

Input

2 10 6
4 4 E
6 4 W


Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int N, W, H;
int sz;
int idx(int x, int y){
  if(y == 0) return x;
  if(x == W) return W + y;
  if(y == H) return W + H + W-x;
  return W+H+W+H-y;
}
int projc(int x, int y, int dir){
  switch(dir){
  case 0:
	return idx(x-min(x,y),y-min(x,y));
  case 1:
	return idx(x+min(W-x,y),y-min(W-x,y));
  case 2:
	return idx(x+min(W-x,H-y),y+min(W-x,H-y));
  case 3:
	return idx(x-min(x,H-y),y+min(x,H-y));
  }
  return -1;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  cin >> N >> W >> H;
  sz = 2*(W+H); 
  vector<PII> xs(N);
  REP(i,N){
	char f;
	int x, y; cin >> x >> y >> f;
	PII p;
	int ix = string("SENW").find(f);
	p.FF = projc(x,y,ix);
	p.SS = projc(x,y,(ix+1)%4);
	if(p.SS < p.FF) p.SS += sz;
	xs[i] = p;
  }

  int ans = N;
  REP(i,N) xs.EB(xs[i].FF+sz, xs[i].SS+sz);
  SORT(xs);

  for(int i=0;i<N;++i){
	int sum = 0;
	int e = -1;
	for(int j=i;j<i+N;++j){
	  if(xs[j].FF <= e){
		e = min(e, xs[j].SS);
	  }
	  else{
		++sum;
		e = xs[j].SS;
	  }
	}
	ans = min(ans, sum);
  }

  cout << ans << endl;
  
  return 0;
}
```