Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Dice IV

Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.

Input

In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.

Output

Print "Yes" if given dices are all different, otherwise "No" in a line.

Constraints

$2 \leq n \leq 100$

$0 \leq $ the integer assigned to a face $ \leq 100$

Sample Input 1

3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1

Sample Output 1

No

Sample Input 2

3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6

Sample Output 2

Yes

Solution in Rust (judge verdict: Accepted)

#![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");
    }
}