#include <iostream>
#include <vector>
#include <unordered_map>
#include <tuple>
using namespace std;

struct Edge {
    int u, v;
    Edge(int a, int b) : u(min(a, b)), v(max(a, b)) {}
    bool operator==(const Edge& other) const {
        return u == other.u && v == other.v;
    }
};

namespace std {
    template<> struct hash<Edge> {
        size_t operator()(const Edge& e) const {
            return hash<long long>()( (static_cast<long long>(e.u) << 32) ^ e.v );
        }
    };
}

struct UnionFind {
    vector<int> parent;
    vector<int> rank;
    vector<int> weight; // 权重表示相对方向
    
    UnionFind(int n) : parent(n), rank(n, 0), weight(n, 0) {
        for (int i = 0; i < n; ++i) parent[i] = i;
    }
    
    int find(int x) {
        if (parent[x] != x) {
            int root = find(parent[x]);
            weight[x] ^= weight[parent[x]];
            parent[x] = root;
        }
        return parent[x];
    }
    
    bool unite(int x, int y, int w) {
        int px = find(x);
        int py = find(y);
        if (px == py) {
            return (weight[x] ^ weight[y]) == w;
        }
        
        if (rank[px] < rank[py]) {
            swap(px, py);
            swap(x, y);
            w ^= 1; // 方向交换需要翻转权重
        }
        
        parent[py] = px;
        weight[py] = weight[y] ^ w ^ weight[x];
        if (rank[px] == rank[py]) rank[px]++;
        return true;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int M;
    cin >> M;
    
    unordered_map<Edge, vector<int>> edgeMap;
    vector<tuple<int, int, int>> triangles(M);
    
    for (int i = 0; i < M; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        triangles[i] = {a, b, c};
        
        edgeMap[Edge(a, b)].push_back(i);
        edgeMap[Edge(b, c)].push_back(i);
        edgeMap[Edge(a, c)].push_back(i);
    }
    
    for (const auto& [e, tris] : edgeMap) {
        if (tris.size() > 2) {
            cout << "NO\n";
            return 0;
        }
    }
    
    UnionFind uf(M);
    bool possible = true;
    
    for (const auto& [e, tris] : edgeMap) {
        if (tris.size() == 2) {
            int u = tris[0], v = tris[1];
            if (!uf.unite(u, v, 1)) { // 共享边需要方向相反
                possible = false;
                break;
            }
        }
    }
    
    cout << (possible ? "YES" : "NO") << endl;
    return 0;
}