Problem: Example

Input

2 10 6
4 4 E
6 4 W


Output

2

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(){
  int w,h,n;
  cin>>n>>w>>h;
  int x,y,B=2*(w+h),ans=n;
  char c;
  vector<P> m;
  for(int i=0;i<n;i++){
    cin>>x>>y>>c;
    if(c=='S')m.push_back(P(x+y,(x-y+B)%B));
    if(c=='E')m.push_back(P(w+y+(w-x),w+y-(w-x)));
    if(c=='N')m.push_back(P(w+h+(w-x)+(h-y),w+h+(w-x)-(h-y)));
    if(c=='W')m.push_back(P((w*2+h+(h-y)+x)%B,w*2+h+(h-y)-x));
  }
  sort(m.begin(),m.end());
  for(int i=0;i<n;i++){
    int tp=1,p=m[i].first;
    for(int j=0;j<n;j++){
      int s=m[(i+j)%n].second,g=m[(i+j)%n].first;
      if(s>g&&!(g<p&&p<s))continue;
      if(s<g&&s<=p&&p<=g)continue;
      tp++,p=g;
    }
    ans=min(tp,ans);
  }
  cout<<ans<<endl;
  return 0;
}