#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define rep1(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < (t); ++i) #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define fi first #define se second #define pb push_back #define eb emplace_back #define pob pop_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define snuke srand((unsigned)clock()+(unsigned)time(NULL)); #define newline puts("") using namespace std; template using vc = vector; template using vv = vc>; template using PQ = priority_queue,greater>; using uint = unsigned; using ull = unsigned long long; using vi = vc; using vvi = vv; using vvvi = vv; using ll = long long; using vl = vc; using vvl = vv; using vvvl = vv; using P = pair; using vp = vc

; using vvp = vv

; int geti(){int x;scanf("%d",&x);return x;} vi pm(int n, int s=0) { vi a(n); iota(rng(a),s); return a;} templateistream& operator>>(istream&i,vc&v){rep(j,sz(v))i>>v[j];return i;} templatestring join(const T&v,const string& d=""){stringstream s;rep(i,sz(v))(i?s<ostream& operator<<(ostream&o,const vc&v){if(sz(v))o<istream& operator>>(istream&i,pair&v){return i>>v.fi>>v.se;} templateostream& operator<<(ostream&o,const pair&v){return o<void operator--(pair&a,int){a.fi--;a.se--;} templatevoid operator--(vc&a,int){for(T&x:a)x--;} templatevoid operator++(vc&a,int){for(T&x:a)x++;} templatevoid operator+=(vc&a,T b){for(T&x:a)x+=b;} templatevoid operator+=(vc&a,const vc&b){a.insert(a.end(),rng(b));} templatebool mins(T1& x,const T2&y){if(x>y){x=y;return true;}else return false;} templatebool maxs(T1& x,const T2&y){if(xTx dup(Tx x, Ty y){return (x+y-1)/y;} templatell suma(const vc&a){ll res(0);for(auto&&x:a)res+=x;return res;} templatell suma(const vv&a){ll res(0);for(auto&&x:a)res+=suma(x);return res;} templatevoid uni(T& a){sort(rng(a));a.erase(unique(rng(a)),a.end());} templatevoid prepend(vc&a,const T&x){a.insert(a.begin(),x);} const double eps = 1e-10; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; #define dame { puts("-1"); return;} #define yes { puts("Yes"); return;} #define no { puts("No"); return;} #define ret(x) { cout<<(x)<>(istream&i,frac&a){i>>a.a>>a.b;return i;} ostream& operator<<(ostream&o,const frac&a){o< 0 ? 1 : 3); return y > 0 ? 2 : 4; } // bool operator<(const V& a) const { // int s = side(), sa = a.side(); // if (s != sa) return s < sa; // return cross(a) > 0; // } }; istream& operator>>(istream&i,V&a){i>>a.x>>a.y;return i;} ostream& operator<<(ostream&o,const V&a){o< 0) return +1; if (dir().cross(p-s) < 0) return -1; if (dir().dot(p-s) == 0) return +2; if (dir().norm2() < (p-s).norm2()) return -2; return 0; } bool touch(const Line& l) const { int a = ccw(l.s)*ccw(l.t), b = l.ccw(s)*l.ccw(t); return !a || !b || (a == -1 && b == -1); } }; using Poly = vector; inline V pnxt(Poly& p, int i) { return p[(i+1)%sz(p)];} inline V ppre(Poly& p, int i) { return p[(i-1+sz(p))%sz(p)];} inline Line pline(Poly& p, int i) { return Line(p[i],pnxt(p,i));} Poly conv(Poly a) { // cw int n = sz(a); if (n <= 2) return a; sort(rng(a)); Poly res(n*2); int k = 0; for (int i = 0; i < n; ++i){ while (k > 1 && Line(res[k-1],res[k-2]).ccw(a[i]) != 1) --k; // <= -1 ok line res[k++] = a[i]; } int pre = k; for (int i = n - 2; 0 <= i; --i){ while (k > pre && Line(res[k-1],res[k-2]).ccw(a[i]) != 1) --k; // <= -1 ok line res[k++] = a[i]; } res.resize(k-1); return res; } ll area2(Poly& a) { ll res = 0; rep(i,sz(a)-2){ res += abs(V(a[i+1]-a[0]).cross(V(a[i+2]-a[0]))); } return res; // area*2 } struct Circle { V o; ll r; Circle(V o=V(0,0), ll r=0):o(o),r(r){} bool in(V p) { return (p-o).norm2() < r*r;} bool touch(Circle c) { return (c.o-o).norm2() < (c.r+r)*(c.r+r);} }; // geom struct Solver { void solve() { int n,k; scanf("%d%d",&n,&k); vc p(2); rep(i,n) { int x,y,c; scanf("%d%d%d",&x,&y,&c); p[c-1].eb(x,y); } Poly a = p[0], b = p[1]; Poly ca = conv(a), cb = conv(b); rep(ri,2) { int na = sz(a), nb = sz(b); rep(i,na) { vc> d; rep(j,nb) { V x = b[j]-a[i]; d.eb(frac(x.x,x.y), x.side()); } sort(rng(d)); rep(i,sz(d)-1) { if (d[i].fi == d[i+1].fi && d[i].se != d[i+1].se) yes; } } if (k >= 4 && sz(ca) >= 3) { for (V x : cb) { bool ok = true; rep(i,sz(ca)) { if (pline(ca,i).ccw(x) != -1) ok = false; } if (ok) yes; } } swap(a,b); swap(ca,cb); } if (k >= 4) { rep(i,sz(ca))rep(j,sz(cb)) { Line la = pline(ca,i); Line lb = pline(cb,j); if (la.ccw(lb.s) == la.ccw(lb.t)) continue; if (lb.ccw(la.s) == lb.ccw(la.t)) continue; yes; } } no; } }; int main() { // cin.tie(nullptr); ios::sync_with_stdio(false); int ts = 1; // scanf("%d",&ts); rep1(ti,ts) { Solver solver; solver.solve(); } return 0; }