#include using namespace std; #define fast_io ios::sync_with_stdio(false); cin.tie(nullptr); #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") typedef long long ll; typedef long double ld; #define chmin(a,b) a = min(a,b); #define chmax(a,b) a = max(a,b); #define bit_count(x) __builtin_popcountll(x) #define leading_zero_count(x) __builtin_clz(x) #define trailing_zero_count(x) __builtin_ctz(x) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) a / gcd(a,b) * b #define rep(i,n) for(int i = 0 ; i < n ; i++) #define rrep(i,a,b) for(int i = a ; i < b ; i++) #define repi(it,S) for(auto it = S.begin() ; it != S.end() ; it++) #define pt(a) cout << a << endl; #define debug(a) cout << #a << " " << a << endl; #define all(a) a.begin(), a.end() #define endl "\n"; #define v1(n,a) vector(n,a) #define v2(n,m,a) vector>(n,v1(m,a)) #define v3(n,m,k,a) vector>>(n,v2(m,k,a)) #define v4(n,m,k,l,a) vector>>>(n,v3(m,k,l,a)) templateistream &operator>>(istream&is,pair&p){is>>p.first>>p.second;return is;} templateostream &operator<<(ostream&os,const pair&p){os<istream &operator>>(istream&is,vector&v){for(T &in:v){is>>in;}return is;} templateostream &operator<<(ostream&os,const vector&v){for(auto it=v.begin();it!=v.end();){os<<*it<<((++it)!=v.end()?" ":"");}return os;} templateistream &operator>>(istream&is,vector>&v){for(T &in:v){is>>in;}return is;} templateostream &operator<<(ostream&os,const vector>&v){for(auto it=v.begin();it!=v.end();){os<<*it<<((++it)!=v.end()?"\n":"");}return os;} templateostream &operator<<(ostream&os,const set&v){for(auto it=v.begin();it!=v.end();){os<<*it<<((++it)!=v.end()?" ":"");}return os;} templateostream &operator<<(ostream&os,const multiset&v){for(auto it=v.begin();it!=v.end();){os<<*it<<((++it)!=v.end()?" ":"");}return os;} #define dist(a,b,c,d) abs(a-c) + abs(b-d) void solve(){ int n, a, b; cin >> n >> a >> b; vector X(n), Y(n), K(n); rep(i,n) cin >> X[i] >> Y[i] >> K[i]; auto dp = v3(1<= b) dp[(1 << i) | (1 << j)][i][j] = true; int x = X[i], y = Y[i]; int nx = X[j], ny = Y[j]; if(dist(x,y,nx,ny) >= a) dp[(1 << i) | (1 << j)][i][j] = true; } } rep(S,1<> i & 1)) continue; rep(j,n){ if(!(S >> j & 1)) continue; if(!dp[S][i][j]) continue; rep(x,n){ if(S >> x & 1) continue; if(abs(K[x] - K[i]) >= b) dp[S | 1 << x][x][i] = true; int ppx = X[j], ppy = Y[j]; int px = X[i], py = Y[i]; int nx = X[x], ny = Y[x]; if(dist(px,py,nx,ny) >= a) dp[S | 1 << x][x][i] = true; if(dist(px,py,nx,ny) + dist(ppx,ppy,nx,ny) >= a) dp[S | 1 << x][x][i] = true; } } } } int res = 1; rep(S,1<> t; rep(i,t) solve(); }