// Arup Guha
// 7/13/2012
// Solution to 1993 UCF HS Contest Problem: Orthogonal Latin Squares

import java.util.*;
import java.io.*;

public class latin {

	public static void main(String[] args) throws Exception {


		Scanner fin = new Scanner(new File("latin.in"));

        // Go through each case.
		while (fin.hasNext()) {

            // Read in the squares...
			int n = fin.nextInt();
			int[][] sq = new int[n][n];
			int[][] sq2 = new int[n][n];

			for (int i=0; i<n; i++)
				for (int j=0; j<n; j++)
					sq[i][j] = fin.nextInt();

			for (int i=0; i<n; i++)
				for (int j=0; j<n; j++)
					sq2[i][j] = fin.nextInt();

            // Test and output.
			if (orthogonal(sq, sq2))
				System.out.println("The Latin Squares are orthogonal.");
			else
				System.out.println("The Latin Squares are NOT orthogonal.");
		}
	}

    // Does orthogonality test.
	public static boolean orthogonal(int[][] sq, int[][] sq2) {

		int n = sq.length;

		boolean[] flag = new boolean[n*n];

        // Go through each item.
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {

                // Unique marker for this ordered pair.
				int num = (sq[i][j]-1)*n + sq2[i][j] - 1;

				// Oops, we've seen this ordered pair before!
				if (flag[num]) return false;

				// Mark this pair as seen now.
				flag[num] = true;
			}

		}

		// Passed our test.
		return true;
	}

}
