Under construction

Still being built. Things may change

Max and Distances

Time limit2sMemory limit1024 MB

Summary
Given an n by n distance matrix, restore a sorted point array x and permutations a and b that generate it, or report that none exist.
Level

Medium7 of 10

Topics
Sorting, Greedy, Implementation
Solved
No attempts yet

Problem

Max found an array xx of nn integer points on a line, sorted in non-decreasing order. Max also has two permutations aa and bb of the numbers from 11 to nn, which were given to him as a birthday present.

Max decided to play with them. He built a distance matrix dd where di,j=∣xai−xbj∣d_{i,j} = |x_{a_i} - x_{b_j}|. In other words, di,jd_{i,j} is the distance between points aia_i and bjb_j.

Before Max could finish playing, Katy cleaned up and xx, aa, and bb were all lost. Max only has the matrix dd left. He wants to restore a non-decreasing array xx and two permutations aa and bb that generate a matrix equal to dd. However, Max may have miscalculated dd, in which case xx, aa, and bb cannot be restored.

Help Max restore them.

Input

The first line contains a natural number nn (1≤n≤10001 \le n \le 1000). The next nn lines contain the matrix dd (0≤di,j≤1090 \le d_{i,j} \le 10^9). All numbers in the matrix are integers.

Output

If there exist xx, aa, and bb that generate a matrix equal to dd, print <<YES>> on the first line. On the second line, print the non-decreasing array of integers xx (∣xi∣≤109|x_i| \le 10^9; xi≤xi+1x_i \le x_{i+1}). On the third line, print the permutation aa of the numbers from 11 to nn. On the fourth line, print the permutation bb of the numbers from 11 to nn.

If no such xx, aa, and bb exist, print <<NO>>.

Hint

The input may be large, so it is recommended to use the fast input and output streams of your language.

Examples3

  1. Example 1

    Input
    4
    3 2 1 0
    2 1 0 1
    1 0 1 2
    0 1 2 3
    
    Expected output
    YES
    0 1 2 3
    1 2 3 4
    4 3 2 1
    
  2. Example 2

    Input
    3
    1 0 2
    1 1 1
    1 1 0
    
    Expected output
    NO
    
  3. Example 3

    Input
    4
    7 0 2 1
    9 2 0 3
    0 7 9 6
    6 1 3 0
    
    Expected output
    YES
    0 2 3 9
    2 1 4 3
    4 2 1 3