#![allow(dead_code)]
use std::io;

fn main() {
    solve_d();
}

fn solve_d() {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    let n = n.trim().parse::<usize>().unwrap();

    let mut dices: Vec<Vec<u16>> = Vec::new();
    for _i in 0..n {
        let mut d1 = String::new();
        io::stdin().read_line(&mut d1).unwrap();
        let d1: Vec<_> = d1.trim()
            .split_whitespace()
            .map(|s| s.parse::<u16>().unwrap())
            .collect();
        dices.push(d1);
    }

    let mut count = 0;
    for i in 0..(n - 1) {
        for j in (i + 1)..n {
            let dices2 = dices.clone();
            let mut dice = dices2[i].clone();
            let d3 = dices2[j].clone();
            for d in "HHHH N HHHH N HHHH N W HHHH W HHHH W HHHH W HHHH"
                .replace(" ", "")
                .chars()
            {
                let mut newnum = vec![0_u16; 6];
                if d == 'N' {
                    // t 0 => N 4
                    newnum[4] = dice[0];
                    // s 1 => T 0
                    newnum[0] = dice[1];
                    // e 2 => e 2
                    newnum[2] = dice[2];
                    // w 3 => w 3
                    newnum[3] = dice[3];
                    // n 4 => b 5
                    newnum[5] = dice[4];
                    // b 5 => s 1
                    newnum[1] = dice[5];
                } else if d == 'S' {
                    // t 0 => s 1;
                    newnum[1] = dice[0];
                    // s 1 => b 5;
                    newnum[5] = dice[1];
                    // n 4 => t 0;
                    newnum[0] = dice[4];
                    // b 5 => n 4;
                    newnum[4] = dice[5];

                    newnum[2] = dice[2];
                    newnum[3] = dice[3];
                } else if d == 'E' {
                    // t 0 => e 2;
                    newnum[2] = dice[0];
                    // w 3 => t 0;
                    newnum[0] = dice[3];
                    // b 5 => w 3;
                    newnum[3] = dice[5];
                    // e 2 => b 5;
                    newnum[5] = dice[2];

                    newnum[1] = dice[1];
                    newnum[4] = dice[4];
                } else if d == 'W' {
                    // t 0 => w 3;
                    newnum[3] = dice[0];
                    // e 2 => t 0;
                    newnum[0] = dice[2];
                    // b 5 => e 2;
                    newnum[2] = dice[5];
                    // w 3 => b 5;
                    newnum[5] = dice[3];

                    newnum[1] = dice[1];
                    newnum[4] = dice[4];
                } else {
                    // t 0 => t 0;
                    newnum[0] = dice[0];
                    // b 5 => b 5;
                    newnum[5] = dice[5];
                    // s 1 => w 3;
                    newnum[3] = dice[1];
                    // w 3 => n 4;
                    newnum[4] = dice[3];
                    // n 4 => e 2;
                    newnum[2] = dice[4];
                    // e 2 => s 1;
                    newnum[1] = dice[2];
                }
                dice = newnum;

                if dice == d3 {
                    count = 1;
                    break;
                }
            }
        }
    }

    if count == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}



Measured memory_bytes: 5052