Language: Java

import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] num = new int[6];
		int n =Integer.parseInt(sc.nextLine());
		Dice[] dice = new Dice[n];
		boolean flag=true;
		
		for(int i=0;i<n;i++){
			String[] line = sc.nextLine().split(" ");
			for(int j=0;j<6;j++){
				num[j]=Integer.parseInt(line[j]);
			}
			dice[i]=new Dice(num);
		}
		
		
		for(int i=1;i<n;i++){
			int upper = dice[i].getUpper();
			int s = dice[i].getS();
			
			if(dice[0].getLower()==s){
				dice.moveN();
			}else if(dice[0].getN()==s){
				dice.moveN();
				dice.moveN();
			}else if(dice[0].getE()==s){
				dice.moveE();
				dice.moveN();
			}else if(dice[0].getW()==s){
				dice.moveW();
				dice.moveN();
			}else if(dice[0].getUpper()==s){
				dice.moveS();
			}
             
			if(dice[0].getLower()==upper){
				dice.moveW();
				dice.moveW();
			}else if(dice[0].getW()==upper){
				dice.moveE();
			}else if(dice[0].getE()==upper){
				dice.moveW();
			}
			
			if(dice[0].getLower()==dice[i].getLower() && dice[0].getUpper()==dice[i].getUpper()&&
				dice[0].getN()==dice[i].getN() && dice[0].getE()==dice[i].getE()&&
				dice[0].getS()==dice[i].getS() && dice[0].getW()==dice[i].getW()){
			}else{
				flag=false;
				break;
			}
		}
		
		if(flag){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}
class Dice{
//
	private final int lavel1,lavel2,lavel3,lavel4,lavel5,lavel6;
	private int w,s,e,n;
	private int upper,lower;
//	
	Dice(int[] i){
		lavel1=i[0];
		lavel2=i[1];
		lavel3=i[2];
		lavel4=i[3];
		lavel5=i[4];
		lavel6=i[5];
		
		w=lavel4;
		s=lavel2;
		e=lavel3;
		n=lavel5;
		
		upper=lavel1;
		lower=lavel6;
	}
	
	public int getUpper(){
		return upper;
	}
	public int getW(){
		return w;
	}
	public int getS(){
		return s;
	}
	public int getE(){
		return e;
	}
	public int getN(){
		return n;
	}
	public int getLower(){
		return lower;
	}
	
	public void moveW(){
		int i=lower;
		lower=w;
		w=upper;
		upper=e;
		e=i;
	}
	public void moveS(){
		int i=lower;
		lower=s;
		s=upper;
		upper=n;
		n=i;
	}
	public void moveE(){
		int i=lower;
		lower=e;
		e=upper;
		upper=w;
		w=i;
	}
	public void moveN(){
		int i=lower;
		lower=n;
		n=upper;
		upper=s;
		s=i;
	}
}

Compiler output:
Main.java:25: error: cannot find symbol
				dice.moveN();
				    ^
  symbol:   method moveN()
  location: variable dice of type Dice[]
Main.java:27: error: cannot find symbol
				dice.moveN();
				    ^
  symbol:   method moveN()
  location: variable dice of type Dice[]
Main.java:28: error: cannot find symbol
				dice.moveN();
				    ^
  symbol:   method moveN()
  location: variable dice of type Dice[]
Main.java:30: error: cannot find symbol
				dice.moveE();
				    ^
  symbol:   method moveE()
  location: variable dice of type Dice[]
Main.java:31: error: cannot find symbol
				dice.moveN();
				    ^
  symbol:   method moveN()
  location: variable dice of type Dice[]
Main.java:33: error: cannot find symbol
				dice.moveW();
				    ^
  symbol:   method moveW()
  location: variable dice of type Dice[]
Main.java:34: error: cannot find symbol
				dice.moveN();
				    ^
  symbol:   method moveN()
  location: variable dice of type Dice[]
Main.java:36: error: cannot find symbol
				dice.moveS();
				    ^
  symbol:   method moveS()
  location: variable dice of type Dice[]
Main.java:40: error: cannot find symbol
				dice.moveW();
				    ^
  symbol:   method moveW()
  location: variable dice of type Dice[]
Main.java:41: error: cannot find symbol
				dice.moveW();
				    ^
  symbol:   method moveW()
  location: variable dice of type Dice[]
Main.java:43: error: cannot find symbol
				dice.moveE();
				    ^
  symbol:   method moveE()
  location: variable dice of type Dice[]
Main.java:45: error: cannot find symbol
				dice.moveW();
				    ^
  symbol:   method moveW()
  location: variable dice of type Dice[]
12 errors