#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
#include <ctype.h> // isdigit
#include <cassert>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(u) begin(u),end(u)
#define PB push_back
#define LE(n,m) ((n) < (m) + EPS * (abs(n) + abs(m)))
#define GE(n,m) ((n) + EPS * (abs(n) + abs(m)) > (m))
#define LT(n,m) ((n) + EPS * (abs(n) + abs(m)) < (m))
#define GT(n,m) ((n) > (m) + EPS * (abs(n) + abs(m)))
#define EQ(n,m) (abs((n)-(m)) < EPS * (abs(n) + abs(m)))

typedef long long int ll;
const int INF = (1<<30) - 1;
const double EPS = 1e-9;
const int MOD = 1000000007;

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);
    
    int N, W, D;
    cin >> N >> W >> D;
    int L = 2 * (W + D);
    //end, start
    vector<pair<int, int>> lines;
    
    for(int i=0; i<N; i++){
        int x, y; string f;
        cin >> x >> y >> f;
        int nx, ny;
        if(f == "S"){
            nx = x;
            ny = y;
        }
        if(f == "E"){
            nx = y + W;
            ny = W - x;
        }
        if(f == "N"){
            nx = 2*W + D - x;
            ny = D - y;
        }
        if(f == "W"){
            nx = -y;
            ny = x;
        }
        lines.emplace_back(nx + ny, nx - ny);
    }
    sort(lines.begin(), lines.end());
    
    int ans = INF;
    for(int s=0; s<N; s++){ //????????°???????§??????¨?????????
        int tans = 0;
        int p = lines[0].first;
        for(int i=0; i<N; i++){
            while(i<N && lines[i%N].second <= p) i++;
            p = lines[i--%N].first;
            tans++;
        }
        ans = min(ans, tans);
        
        lines[0].first += L;
        lines[0].second += L;
        sort(lines.begin(), lines.end());
    }
    cout << ans << endl;
    return 0;
}
### Prompt

Create a solution in Cpp for the following problem:

Example

Input

2 10 6
4 4 E
6 4 W


Output

2

### Response

```cpp
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
#include <ctype.h> // isdigit
#include <cassert>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(u) begin(u),end(u)
#define PB push_back
#define LE(n,m) ((n) < (m) + EPS * (abs(n) + abs(m)))
#define GE(n,m) ((n) + EPS * (abs(n) + abs(m)) > (m))
#define LT(n,m) ((n) + EPS * (abs(n) + abs(m)) < (m))
#define GT(n,m) ((n) > (m) + EPS * (abs(n) + abs(m)))
#define EQ(n,m) (abs((n)-(m)) < EPS * (abs(n) + abs(m)))

typedef long long int ll;
const int INF = (1<<30) - 1;
const double EPS = 1e-9;
const int MOD = 1000000007;

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);
    
    int N, W, D;
    cin >> N >> W >> D;
    int L = 2 * (W + D);
    //end, start
    vector<pair<int, int>> lines;
    
    for(int i=0; i<N; i++){
        int x, y; string f;
        cin >> x >> y >> f;
        int nx, ny;
        if(f == "S"){
            nx = x;
            ny = y;
        }
        if(f == "E"){
            nx = y + W;
            ny = W - x;
        }
        if(f == "N"){
            nx = 2*W + D - x;
            ny = D - y;
        }
        if(f == "W"){
            nx = -y;
            ny = x;
        }
        lines.emplace_back(nx + ny, nx - ny);
    }
    sort(lines.begin(), lines.end());
    
    int ans = INF;
    for(int s=0; s<N; s++){ //????????°???????§??????¨?????????
        int tans = 0;
        int p = lines[0].first;
        for(int i=0; i<N; i++){
            while(i<N && lines[i%N].second <= p) i++;
            p = lines[i--%N].first;
            tans++;
        }
        ans = min(ans, tans);
        
        lines[0].first += L;
        lines[0].second += L;
        sort(lines.begin(), lines.end());
    }
    cout << ans << endl;
    return 0;
}
```