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.

Constraints

* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$

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.

Examples

Input

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


Output

No


Input

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


Output

Yes
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
using namespace std;


bool sol(vector<int>d1,vector<int>d2){
    for(int i=0;i<4;i++){
        int tmp1=d1[0];
        d1[0]=d1[2], d1[2]=d1[5], d1[5]=d1[3], d1[3]=tmp1;
        for(int j=0;j<4;j++){
            int tmp2=d1[0];
            d1[0]=d1[1], d1[1]=d1[5], d1[5]=d1[4], d1[4]=tmp2;
            for(int k=0;k<4;k++){
                int tmp3=d1[1];
                d1[1]=d1[2], d1[2]=d1[4], d1[4]=d1[3], d1[3]=tmp3;
                if(equal(d1.cbegin(),d1.cend(),d2.cbegin())){
                    printf("No\n");
                    return false;
                }
            }
        }
    }
    return true;
}

int main(){
    int n;
    scanf("%d",&n);
    vector<vector<int>> d(n,vector<int>(6));
    for(int i=0;i<n;i++){
        for(auto&e:d[i]){
            scanf("%d",&e);
        }
    }
    bool flag;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            flag=sol(d[i],d[j]);
            if(flag==false) return 0;;
        }
    }
    printf("Yes\n");
    return 0;
}