A Farewell to Holds


The MAPS marketing team has been assigned to design an Olympic bouldering wall. Since the team goes bouldering after every MAPS workshop, they wanted the wall to follow a very particular n×nn \times n layout.

For each pair (i,j)(i,j), the hold in row ii and column jj has colour ci,jc_{i,j} and visibility score ai,ja_{i,j}.

The broadcast crew has one rule: after the final design is chosen, no remaining colour may appear more than once in any row or in any column. Repainting would require another meeting, so the marketing team may instead remove the colour from some holds.

The removed holds must also be well spread out: no two removed holds may be in the same row or in the same column.

The cost of a removal set is the maximum ai,ja_{i,j} among the holds whose colour was removed. If no colour is removed, the cost is 00.

Determine whether it is possible to make the wall valid. If it is possible, find the minimum possible cost.

Input

The first line contains one integer nn (1≤n≤1031 \leq n \leq 10^3).

The next nn lines contain the colour matrix cc. The value in row ii and column jj is ci,jc_{i,j} (1≤ci,j≤1091 \leq c_{i,j} \leq 10^9).

The next nn lines contain the value matrix aa. The value in row ii and column jj is ai,ja_{i,j} (1≤ai,j≤1091 \leq a_{i,j} \leq 10^9).

Output

If it is possible to make the wall valid, print Yes; otherwise print No.

If the answer is Yes, print the minimum possible cost on the second line.

Example 1

Input 1
3
1 4 3
1 2 3
6 2 5
1 9 1
3 5 7
9 1 9
Output 1
Yes
3

Example 2

Input 2
3
1 2 3
1 2 3
1 2 3
1 9 1
3 5 7
9 1 9
Output 2
No

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.