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 C (judge verdict: Time Limit Exceeded)

#include<stdio.h>

int main()
{
  int n;
  int m = 0;
  int temp;
  int d[100][6];
  int count = 0;
  scanf("%d", &n);

  for(int i  = 0 ; i < n; i++)
    {
      for(int j = 0 ; j < 6; j++)
	{
	  scanf("%d", &d[i][j]);
	}
    }
  
  for(int i = 0; i < n-1; i++)
    {
      for(int j = 0; j < 6; j++)
	{
	  for(int k = 0; k < 6; k++)
	    {
	      if(d[i][j] == d[i+1][k])
		{
		  count++;
		  break;
		}
	    }
	}
      if(count != 6)
	{
	  count = 0;
	  continue;
	}
      while(1)
	{
	  if(d[i][1] == d[i+1][1])
	    {
	      break;
	    }
	  for(int j = 0; j < 6; j++)
	    {
	      if(d[i+1][1] == d[i][j])
		{
		  m = j;
		  break;
		}
	    }
	  temp = d[i][0];
	  if(m == 3)
	    {
	      d[i][0] = d[i][3];
	      d[i][3] = d[i][5];
	      d[i][5] = d[i][2];
	      d[i][2] = temp;
	    }
	  if(m == 2)
	    {
	      d[i][0] = d[i][2];
	      d[i][2] = d[i][5];
	      d[i][5] = d[i][3];
	      d[i][3] = temp;
	    }
	  if(m == 4 || m == 0)
	    { 
	      d[i][0] = d[i][4];
	      d[i][4] = d[i][5];
	      d[i][5] = d[i][1];
	      d[i][1] = temp;
	    }
	  if(m == 1 || m == 5)
	    {
	      d[i][0] = d[i][1];
	      d[i][1] = d[i][5];
	      d[i][5] = d[i][4];
	      d[i][4] = temp;
	    }
	}
      while(1)
	{
	  for(int j = 0; j < 6; j++)
	    {
	      if(d[i+1][0] == d[i][j])
		{
		  m = j;
		}
	    }
	  if(d[i][5] == d[i+1][5] && d[i][2] == d[i+1][2])
	    {
	      printf("No\n");
	      return 0;
	    }
	  if(d[i][0] == d[i+1][0])
	    {
	      break;
	    }
	  temp = d[i][0];
	  if(m == 3)
	    {
	      d[i][0] = d[i][3];
	      d[i][3] = d[i][5];
	      d[i][5] = d[i][2];
	      d[i][2] = temp;
	    }
	  if(m == 2)
	    {
	      d[i][0] = d[i][2];
	      d[i][2] = d[i][5];
	      d[i][5] = d[i][3];
	      d[i][3] = temp;
	    }
	  if(m == 5)
	    {
	      d[i][0] = d[i][5];
	      d[i][5] = temp;
	      temp = d[i][2];
	      d[i][2] = d[i][3];
	      d[i][3] = temp;
	    }
	}
    }
  printf("Yes\n");
}