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;

int main(){

    int n, w, h; cin >> n >> w >> h;
    vector<pair<int, int> > p;     //{r, l}
    for(int i = 0; i < n; i++){
        int x, y;
        char c;
        cin >> x >> y >> c;
        if(c == 'W') {
            p.push_back({x + y, -x + y});
        } else if(c == 'N') {
            p.push_back({2*h + x - y, x + y});
        } else if(c == 'E') {
            p.push_back({2*(h+w) - x - y, 2*h + x - y});
        } else {
            p.push_back({2*(h+w) - x + y ,2*(h+w) - x - y});
        }

        //if(p[i].first < 0) p[i].first += 2 * (h + w) - 1;
        //if(p[i].second < 0) p[i].second += 2 * (h + w) - 1;
        
    }

    
    sort(p.begin(), p.end());

    /*for(int i = 0; i < p.size(); i++){
        cout << "(" << p[i].first << ", " << p[i].second << ")" << endl;
    }*/

    //スタート位置でループ
    int ans = n;
    int L = 2*(w + h);
    for(int i=0; i<n; ++i) {
        vector<pair<int, int> > tmp;
        tmp = p;
        for(int j=i-1; j>=0; --j) {
            if(tmp[j].first < tmp[i].first) {
                tmp[j].first += L;
                tmp[j].second += L;
            }
        }
        sort(tmp.begin(), tmp.end());
        int cnt = 1;
        int now = tmp[0].first;
        for(int j=0; j<n; ++j) {
            if(tmp[j].second > now) {
                now = tmp[j].first;
                cnt++;
            }
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}