#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>

struct TDice
{
    int Top;
    int Front;
    int Right;
    int Back;
    int Left;
    int Bottom;
};
TDice MakeDice(std::istream& in)
{
    TDice Dice;
    in
       >> Dice.Top
       >> Dice.Front
       >> Dice.Right
       >> Dice.Left
       >> Dice.Back
       >> Dice.Bottom;
    return Dice;
}
void RollN(TDice& Dice)
{
    int temp    = Dice.Top;
    Dice.Top    = Dice.Front;
    Dice.Front  = Dice.Bottom;
    Dice.Bottom = Dice.Back;
    Dice.Back   = temp;
}
void RollE(TDice& Dice)
{
    int temp    = Dice.Top;
    Dice.Top    = Dice.Left;
    Dice.Left   = Dice.Bottom;
    Dice.Bottom = Dice.Right;
    Dice.Right  = temp;
}
void RollW(TDice& Dice)
{
    int temp    = Dice.Top;
    Dice.Top    = Dice.Right;
    Dice.Right  = Dice.Bottom;
    Dice.Bottom = Dice.Left;
    Dice.Left   = temp;
}
void RollS(TDice& Dice)
{
    int temp    = Dice.Top;
    Dice.Top    = Dice.Back;
    Dice.Back   = Dice.Bottom;
    Dice.Bottom = Dice.Front;
    Dice.Front  = temp;
}

void Roll(char c, TDice& Dice)
{
    switch(c){
    case 'N': RollN(Dice); break;
    case 'E': RollE(Dice); break;
    case 'W': RollW(Dice); break;
    case 'S': RollS(Dice); break;
    }
}
bool IsInclude(int Num, const TDice& Dice)
{
    return
        Dice.Top    == Num ||
        Dice.Front  == Num ||
        Dice.Right  == Num ||
        Dice.Back   == Num ||
        Dice.Left   == Num ||
        Dice.Bottom == Num; 
}
bool RollToTop(int Num, TDice& Dice)
{
    // assert(IsInclude(Num, Dice));
    if(IsInclude(Num, Dice) == false){
        return false;
    }
    if(Dice.Top == Num){
    }else
    if(Dice.Left == Num){
        RollE(Dice);
    }else
    if(Dice.Right == Num){
        RollW(Dice);
    }else
    if(Dice.Front == Num){
        RollN(Dice);
    }else
    if(Dice.Back == Num){
        RollS(Dice);
    }else
    if(Dice.Bottom == Num){
        RollE(Dice);
        RollE(Dice);
    }else{
        return false;
    }
    return true;
}
bool RollToFront(int Num, TDice& Dice)
{
    if(RollToTop(Num, Dice) == false){
        return false;
    }
    RollS(Dice);
    return true;
}
bool RollToTopFront(int Top, int Front, TDice& Dice)
{
    return RollToFront(Front, Dice) &&  RollToTop(Top, Dice);
}

bool Equal(const TDice& A, const TDice& B)
{
    return
        A.Top    == B.Top &&
        A.Front  == B.Front &&
        A.Right  == B.Right &&
        A.Back   == B.Back &&
        A.Left   == B.Left &&
        A.Bottom == B.Bottom;
}
bool EqualIfRoll(const TDice&A, const TDice&B)
{
    TDice X = A;
    std::string Directions = "SESESE";
    for(int i = 0; i < Directions.size(); ++i){
        if(X.Top == B.Front){
            RollS(X);
            TDice Y = B;
            for(int j = 0; j < 4; ++j){
                if(Equal(X, Y)){
                    return true;
                }
                RollE(Y);
            }
            RollN(X);
        }
        Roll(Directions[i], X);
    }
    return false;
}
bool IsUnique(std::vector<TDice> List)
{
    for(int i = 0; i < List.size(); ++i){
        for(int j = i + 1; j < List.size(); ++j){
            if(EqualIfRoll(List[i], List[j])){
                return false;
            }
        }
    }
    return true;
}
int main()
{
    int n;
    std::cin >> n;
    std::vector<TDice> List(n);
    for(int i = 0; i < n; ++i){
        List[i] = MakeDice(std::cin);
        
    }
    std::cout << (IsUnique(List) ? "Yes" : "No") << std::endl;
    return 0;
}

Measured memory_bytes: 3208