#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace::std; template ostream& operator<< (ostream& o, const pair& p) { o << "<" << p.first << ", " << p.second << ">"; return o; } template ostream& operator<< (ostream& o, const vector& v) { for (const auto& x : v) o << x << " "; return o; } template ostream& operator<< (ostream& o, const set& v) { for (const auto& x : v) o << x << " "; return o; } template ostream& operator<< (ostream& o, const deque& v) { for (const auto& x : v) o << x << " "; return o; } template ostream& operator<<(ostream& o, const unordered_map& m) { o << "{"; for (const auto& [k, v] : m) o << " " << k << ": " << v << ","; o << "}"; return o; } template istream& operator>> (istream& i, vector& v) { for (auto& x : v) i >> x; return i; } int main() { ios::sync_with_stdio(false); int n, a, b; cin >> n >> a >> b; vector x(n), y(n), k(n); for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> k[i]; using State = pair, deque>; set vis {}; vector q {{{}, {}}}; while (q.size()) { State u = q.back(); q.pop_back(); if (vis.count(u)) continue; vis.insert(u); //cerr << "New State " << u << endl; for (int i = 0; i < n; ++i) { //cerr << "i " << i << endl; if (!u.first.count(i) && ( u.first.size() == 0 || (u.first.size() == 1 && a <= abs(x[i] - x[u.second.back()]) + abs(y[i] - y[u.second.back()])) || (u.first.size() >= 1 && b <= abs(k[i] - k[u.second.back()])) || (u.first.size() >= 2 && a <= abs(x[i] - x[u.second.back()]) + abs(y[i] - y[u.second.back()]) + abs(x[i] - x[u.second[0]]) + abs(y[i] - y[u.second[0]])))) { State v = u; v.first.insert(i); if (v.second.size() > 2) v.second.pop_front(); v.second.push_back(i); q.push_back(v); } } } unsigned long r = 0; for (const State& s : vis) r = max(r, s.first.size()); cout << r << endl; return 0; }