#include<bits/stdc++.h> #include<atcoder/all> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; using namespace atcoder; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; typedef vector<vector<int>> vvi; typedef vector<vector<long long>> vvl; typedef long double ld; typedef pair<int, int> P; template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;} template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;} template <int m> istream& operator>>(istream& is, static_modint<m>& a) {long long x; is >> x; a = x; return is;} template <int m> istream& operator>>(istream& is, dynamic_modint<m>& a) {long long x; is >> x; a = x; return is;} template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;} template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template<typename T> ostream& operator<<(ostream& os, const set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;} template<typename T> ostream& operator<<(ostream& os, const unordered_set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;} template<typename S, auto op, auto e> ostream& operator<<(ostream& os, const atcoder::segtree<S, op, e>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template<typename S, auto op, auto e, typename F, auto mapping, auto composition, auto id> ostream& operator<<(ostream& os, const atcoder::lazy_segtree<S, op, e, F, mapping, composition, id>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template<typename T> void chmin(T& a, T b){a = min(a, b);} template<typename T> void chmax(T& a, T b){a = max(a, b);} // Weighted Union Find // O(alpha(N)) // thanks for "https://ei1333.github.io/luzhiled/snippets/structure/union-find.html" template<typename T> struct WeightedUnionFind { vector<int> data; vector<T> ws; WeightedUnionFind() {} WeightedUnionFind(int sz) : data(sz, -1), ws(sz) {} int root(int k){ if(data[k] < 0) return k; auto par = root(data[k]); ws[k] += ws[data[k]]; return data[k] = par; } T weight(int t) { root(t); return ws[t]; } bool same(int x, int y){ x = root(x), y = root(y); if(x == y) return true; else return false; } bool merge(int x, int y, T w) { w += weight(x); w -= weight(y); x = root(x), y = root(y); if(x == y) return false; if(data[x] > data[y]) { swap(x, y); w *= -1; } data[x] += data[y]; data[y] = x; ws[y] = w; return true; } T dif(int x, int y) { return weight(y) - weight(x); } }; int main(){ int n; cin >> n; WeightedUnionFind<int> uf(n); map<pair<int, int>, vector<pair<int, int>>> ma; auto f = [&](int i, int pari, pair<int, int> p){ for(auto [j, parj] : ma[p]){ int w = pari ^ parj; if(uf.same(i, j)){ int diff = uf.dif(i, j) + w; if((diff % 2 + 2) % 2){} else return false; }else{ uf.merge(i, j, w + 1); } } return true; }; rep(i, n){ int a, b, c; cin >> a >> b >> c; if(!f(i, 0, make_pair(a, b))){cout << "NO\n"; return 0;} if(!f(i, 0, make_pair(b, c))){cout << "NO\n"; return 0;} if(!f(i, 1, make_pair(a, c))){cout << "NO\n"; return 0;} ma[make_pair(a, b)].emplace_back(i, 0); ma[make_pair(b, c)].emplace_back(i, 0); ma[make_pair(a, c)].emplace_back(i, 1); } cout << "YES\n"; return 0; }