#include #include #include using namespace std; typedef pair pii; typedef pair ppc; int main() { int n; cin >> n; vector V(n); for (int i = 0; i < n; ++i) { int x, y; char c; cin >> x >> y >> c; V[i] = ppc(pii(2*x+y, -2*x+y), c); //store transformed coordinates } sort(V.begin(), V.end()); //for (int i = 0; i < n; ++i) // cout << V[i].first.first << " " << V[i].first.second << " " << V[i].second << endl; long long LN = 4000000000; //no leaks above this line vector V2(0); //possibly leaking components for (int i = 0; i < n; ++i) { if (V[i].second == 'N') { LN = min(LN, V[i].first.second); } else if (V[i].second == 'P') { if (V[i].first.second >= LN) { cout << "impossible" << endl; return 0; } V2.push_back(V[i]); } else if (V[i].second == '-') { } } long long LP = -4000000000; //leaks below this line already handled long long LU = -4000000000; //one more leak can handle everything below this line int r = 0; //number of leaks used for (int i = V2.size()-1; i >= 0; --i) { if (V2[i].second == 'P') { if (V2[i].first.second > LP) { ++r; LP = max(V[i].first.second, LU); } } else { LU = max(LU, V2[i].first.second); } } cout << r << endl; }