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

typedef pair<int, int> P;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int n,h,w;

bool valid(P p){
  return p.fi>=0&&p.fi<=w&&p.se>=0&&p.se<=h;
}

P ur(int x,int y){
  int d=y-x;
  P p1=P(w,w+d),p2=P(h-d,h);
  if(valid(p1))return p1;
  else return p2;
}

P ll(int x,int y){
  int d=y-x;
  P p1=P(0,0+d),p2=P(0-d,0);
  if(valid(p1))return p1;
  else return p2;
}

P ul(int x,int y){
  int d=y+x;
  P p1=P(0,d-0),p2=P(d-h,h);
  if(valid(p1))return p1;
  else return p2;
}

P lr(int x,int y){
  int d=y+x;
  P p1=P(w,d-w),p2=P(d-0,0);
  if(valid(p1))return p1;
  else return p2;
}

int calc(P p){
  assert(p.fi==0||p.fi==w||p.se==0||p.se==h);
  if(p.se==0){
    return p.fi;
  }else if(p.fi==w){
    return w+p.se;
  }else if(p.se==h){
    return w+h+(w-p.fi);
  }else if(p.fi==0){
    return w+h+w+(h-p.se);
  }
  return -1;
}

int main(){
  cin>>n>>w>>h;
  int M=w*2+h*2;
  vector<P> rs;
  rep(i,n){
    int x,y;
    cin>>x>>y;
    char c;
    cin>>c;
    if(c=='E'){
      P p1=lr(x,y); P p2=ur(x,y);
      rs.push_back(P(calc(p1),calc(p2)));
    }else if(c=='N'){
      P p1=ur(x,y); P p2=ul(x,y);
      rs.push_back(P(calc(p1),calc(p2)));
    }else if(c=='W'){
      P p1=ul(x,y); P p2=ll(x,y);
      rs.push_back(P(calc(p1),calc(p2)));
    }else{
      P p1=ll(x,y); P p2=lr(x,y);
      rs.push_back(P(calc(p1),calc(p2)));
    }
  }

  vector<P> ps;
  rep(i,rs.size()){
    if(rs[i].fi>rs[i].se)rs[i].se+=M;
    ps.push_back(P(rs[i].se,rs[i].fi));
    ps.push_back(P(rs[i].se+M,rs[i].fi+M));
  }
  sort(all(ps));

  int res=0;
  rep(i,n){
    int tmp=0,last=0;
    for(int j=i;ps[j].fi<ps[i].se+M;j++){
      if(last<ps[j].se){
        tmp++;
        last=ps[j].fi;
      }
    }
    maxch(res,tmp);
  }

  cout<<res<<endl;
  return 0;
}


### Prompt

Please create a solution in Cpp 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 pair<int, int> P;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int n,h,w;

bool valid(P p){
  return p.fi>=0&&p.fi<=w&&p.se>=0&&p.se<=h;
}

P ur(int x,int y){
  int d=y-x;
  P p1=P(w,w+d),p2=P(h-d,h);
  if(valid(p1))return p1;
  else return p2;
}

P ll(int x,int y){
  int d=y-x;
  P p1=P(0,0+d),p2=P(0-d,0);
  if(valid(p1))return p1;
  else return p2;
}

P ul(int x,int y){
  int d=y+x;
  P p1=P(0,d-0),p2=P(d-h,h);
  if(valid(p1))return p1;
  else return p2;
}

P lr(int x,int y){
  int d=y+x;
  P p1=P(w,d-w),p2=P(d-0,0);
  if(valid(p1))return p1;
  else return p2;
}

int calc(P p){
  assert(p.fi==0||p.fi==w||p.se==0||p.se==h);
  if(p.se==0){
    return p.fi;
  }else if(p.fi==w){
    return w+p.se;
  }else if(p.se==h){
    return w+h+(w-p.fi);
  }else if(p.fi==0){
    return w+h+w+(h-p.se);
  }
  return -1;
}

int main(){
  cin>>n>>w>>h;
  int M=w*2+h*2;
  vector<P> rs;
  rep(i,n){
    int x,y;
    cin>>x>>y;
    char c;
    cin>>c;
    if(c=='E'){
      P p1=lr(x,y); P p2=ur(x,y);
      rs.push_back(P(calc(p1),calc(p2)));
    }else if(c=='N'){
      P p1=ur(x,y); P p2=ul(x,y);
      rs.push_back(P(calc(p1),calc(p2)));
    }else if(c=='W'){
      P p1=ul(x,y); P p2=ll(x,y);
      rs.push_back(P(calc(p1),calc(p2)));
    }else{
      P p1=ll(x,y); P p2=lr(x,y);
      rs.push_back(P(calc(p1),calc(p2)));
    }
  }

  vector<P> ps;
  rep(i,rs.size()){
    if(rs[i].fi>rs[i].se)rs[i].se+=M;
    ps.push_back(P(rs[i].se,rs[i].fi));
    ps.push_back(P(rs[i].se+M,rs[i].fi+M));
  }
  sort(all(ps));

  int res=0;
  rep(i,n){
    int tmp=0,last=0;
    for(int j=i;ps[j].fi<ps[i].se+M;j++){
      if(last<ps[j].se){
        tmp++;
        last=ps[j].fi;
      }
    }
    maxch(res,tmp);
  }

  cout<<res<<endl;
  return 0;
}


```