#include <stdio.h>

#define ZERO 0																/*0???????????????*/
#define ONE 1																/*1???????????????*/
#define TWO 2																/*2???????????????*/
#define THREE 3																/*3???????????????*/
#define FOUR 4																/*4???????????????*/
#define FIVE 5																/*5???????????????*/
#define HUNDRED 100															/*100???????????????*/
#define DICE_SURF 6															/*?????????????????¢??°*/

int main( void )
{

	unsigned char ubW_Ddice[ HUNDRED ] [ DICE_SURF ];						/*?????????????????°?????????*/
	unsigned char ubW_Dn;													/*????????????????????°*/
	unsigned char ubW_Dtrade;												/*??????????\???¨?????°*/
	unsigned char ubW_Dcalc;												/*?¨??????¨?????°*/
	unsigned char ubW_Fflug = ZERO;											/*??¶????????´????????°*/
	unsigned char ubW_Ci;													/*????????????i*/
	unsigned char ubW_Cj;													/*????????????j*/
	unsigned char ubW_Ck;													/*????????????k*/

	scanf("%d", &ubW_Dn);													/*????????????????????°????????????*/
	/*?????????????????°???????????????*/
	for( ubW_Ci = ZERO; ubW_Ci < ubW_Dn; ubW_Ci++){
		/*??¢?????°???????????????*/
		for( ubW_Cj = ZERO; ubW_Cj < DICE_SURF; ubW_Cj++ ){
			scanf("%d", &ubW_Ddice[ ubW_Ci ] [ ubW_Cj ] );						/*????????????n?????°???????????????*/
		}
	}

	/*??????????????????????????´?????????*/
	for( ubW_Ci = ZERO; ubW_Ci < ubW_Dn; ubW_Ci++){
		/*??????????????????????????´?????????*/
		for( ubW_Cj = ubW_Ci + ONE; ubW_Cj < ubW_Dn; ubW_Cj++){
			/*??¢??????????????????????????????*/
			for( ubW_Ck = ONE; ubW_Ck <= DICE_SURF; ubW_Ck++ ){
				ubW_Dcalc = ubW_Ck % TWO;											/*i%2??????switch??????????????????*/
				/*????????¢??¨????????¢?????°?????????????????£????????¨????????¢????????????*/
				switch( ubW_Dcalc ){
				case ZERO:															/*??¶??°???????????¢*/
					ubW_Dtrade = ubW_Ddice[ ubW_Cj ] [ ZERO ];					/*1?????¢???????????¨?????°?????????*/
					ubW_Ddice[ ubW_Cj ] [ ZERO ] = ubW_Ddice[ ubW_Cj] [ TWO ];		/*1?????¢???3?????¢????????????*/
					ubW_Ddice[ ubW_Cj ] [ TWO ] = ubW_Ddice[ ubW_Cj] [ FIVE ];		/*3?????¢???6?????¢????????????*/
					ubW_Ddice[ ubW_Cj ] [ FIVE ] = ubW_Ddice[ ubW_Cj] [ THREE ];	/*6?????¢???4?????¢????????????*/
					ubW_Ddice[ ubW_Cj ] [ THREE ] = ubW_Dtrade;						/*4?????¢???1?????¢????????????*/
					break;
				case ONE:															/*?\???°???????????¢*/
					ubW_Dtrade = ubW_Ddice[ ubW_Cj ] [ ZERO ];						/*1?????¢???????????¨?????°?????????*/
					ubW_Ddice[ ubW_Cj ] [ ZERO ] = ubW_Ddice[ ubW_Cj ] [ ONE ];		/*1?????¢???2?????¢????????????*/
					ubW_Ddice[ ubW_Cj ] [ ONE ] = ubW_Ddice[ ubW_Cj ] [ FIVE ];		/*2?????¢???6?????¢????????????*/
					ubW_Ddice[ ubW_Cj ] [ FIVE ] = ubW_Ddice[ ubW_Cj ] [ FOUR ];	/*6?????¢???5?????¢????????????*/
					ubW_Ddice[ ubW_Cj ] [ FOUR ] = ubW_Dtrade;						/*5?????¢???1?????¢????????????*/
					break;
				default:
					/*default?????????????????????????????\*/
					break;
				}

				/*1?????¢??¨6?????¢????????´??????????????´???*/
				if( ( ubW_Ddice[ ubW_Ci ] [ ZERO ] == ubW_Ddice[ ubW_Cj ] [ ZERO ] ) && ( ubW_Ddice[ ubW_Ci ] [ FIVE ] == ubW_Ddice[ ubW_Cj ] [ FIVE ] ) ){
					/*2?????¢??¨3?????¢????????´??????????????´???*/
					if( ( ubW_Ddice[ ubW_Ci ] [ ONE ] == ubW_Ddice[ ubW_Cj ] [ ONE ] ) && ( ubW_Ddice[ ubW_Ci ] [ TWO ] == ubW_Ddice[ ubW_Cj ] [ TWO ] ) ){
						/*5?????¢??¨4?????¢????????´??????????????´???*/
						if( ( ubW_Ddice[ ubW_Ci ] [ FOUR ] == ubW_Ddice[ ubW_Cj ] [ FOUR ] ) && ( ubW_Ddice[ ubW_Ci ] [ THREE ] == ubW_Ddice[ ubW_Cj ] [ THREE ] ) ){
							printf("No\n");													/*?????´?????????????????§flug???true???*/
							return ZERO;
						}
						else{
							/* else?????????????????????????????\ */
						}
					}
					/*?????????????????????2?????¢??¨?????????????????????3?????¢????????´???????????????????????????3?????¢??¨?????????????????????5?????¢????????´??????????????´???*/
					else if( ( ubW_Ddice[ ubW_Ci ] [ ONE ] == ubW_Ddice[ ubW_Cj ] [ TWO ] ) && ( ubW_Ddice[ ubW_Ci ] [ TWO ] == ubW_Ddice[ ubW_Cj ] [ FOUR ] ) ){
						/*?????????????????????5?????¢??¨?????????????????????4?????¢????????´???????????????????????????4?????¢??¨?????????????????????2?????¢????????´??????????????´???*/
						if( ( ubW_Ddice[ ubW_Ci ] [ FOUR ] == ubW_Ddice[ ubW_Cj ] [ THREE ] ) && ( ubW_Ddice[ ubW_Ci ] [ THREE ] == ubW_Ddice[ ubW_Cj ] [ ONE ] ) ){
							printf("No\n");													/*?????´?????????????????§flug???true???*/
							return ZERO;
						}
						else{
							/* else?????????????????????????????\ */
						}
					}
					/*?????????????????????2?????¢??¨?????????????????????5?????¢????????´???????????????????????????3?????¢??¨?????????????????????4?????¢????????´??????????????´???*/
					else if( ( ubW_Ddice[ ubW_Ci ] [ ONE ] == ubW_Ddice[ ubW_Cj ] [ FOUR ] ) && ( ubW_Ddice[ ubW_Ci ] [ TWO ] == ubW_Ddice[ ubW_Cj ] [ THREE ] ) ){
						/*?????????????????????5?????¢??¨?????????????????????2?????¢????????´???????????????????????????4?????¢??¨?????????????????????3?????¢????????´??????????????´???*/
						if( ( ubW_Ddice[ ubW_Ci ] [ FOUR ] == ubW_Ddice[ ubW_Cj ] [ ONE ] ) && ( ubW_Ddice[ ubW_Ci ] [ THREE ] == ubW_Ddice[ ubW_Cj ] [ TWO ] ) ){
							printf("No\n");													/*?????´?????????????????§flug???true???*/
							return ZERO;
						}
						else{
							/* else?????????????????????????????\ */
						}
					}
					/*?????????????????????2?????¢??¨?????????????????????4?????¢????????´???????????????????????????3?????¢??¨?????????????????????2?????¢????????´??????????????´???*/
					else if( ( ubW_Ddice[ ubW_Ci ] [ ONE ] == ubW_Ddice[ ubW_Cj ] [ THREE ] ) && ( ubW_Ddice[ ubW_Ci ] [ TWO ] == ubW_Ddice[ ubW_Cj ] [ ONE ] ) ){
						/*?????????????????????5?????¢??¨?????????????????????3?????¢????????´???????????????????????????4?????¢??¨?????????????????????5?????¢????????´??????????????´???*/
						if( ( ubW_Ddice[ ubW_Ci ] [ FOUR ] == ubW_Ddice[ ubW_Cj ] [ TWO ] ) && ( ubW_Ddice[ ubW_Ci ] [ THREE ] == ubW_Ddice[ ubW_Cj ] [ FOUR ] ) ){
							printf("No\n");													/*?????´?????????????????§flug???true???*/
							return ZERO;
						}
						else{
							/* else?????????????????????????????\ */
						}
					}
					else{
						/* else?????????????????????????????\ */
					}
				}
				else{
					/* else?????????????????????????????\ */
				}
			}/*??¢????????????????????????????????????*/
		}/* ??????????????????????????´???????????????*/
	}/*??????????????????????????´???????????????*/
	printf("Yes\n");
	
	return ZERO;
}

Measured memory_bytes: 580