#P6251. Azulejo Display Arrangement

    ID: 19470 Type: Default 1000ms 256MiB

Azulejo Display Arrangement

Azulejo Display Arrangement

Ceramic artists Maria and João are setting up their azulejo shop display in Porto. They have exactly n hand‐crafted tiles each. Maria's tiles form the front row and João's tiles form the back row. Each tile in the back row must be paired with exactly one tile in the front row (and vice versa).

There are two conditions that the final arrangement must satisfy:

  • For every position i (from left‐to‐right), the price of the tile is non–decreasing in each row. That is, if the tile at position i has price p_i and the next tile has price p_{i+1}, then p_i \le p_{i+1} in each row. Tiles of equal price can be reordered arbitrarily.
  • For every paired position i, if the height of Maria's (front) tile is h_i^{(M)} and the height of João's (back) tile is h_i^{(J)}, then it must hold that $$ h_i^{(J)} > h_i^{(M)}. $$ This ensures that the back tile is taller than the front tile so that both are visible to passers‐by.

Your task is to determine an ordering of the tiles in each row that satisfies these constraints. If such an ordering exists, output it; otherwise, output NO.

inputFormat

The input begins with a positive integer n denoting the number of tile pairs.

The following n lines each contain two integers, representing the price and height of Maria's tiles (front row).

This is followed by another n lines, each containing two integers, representing the price and height of João's tiles (back row).

Note: The tiles are given in arbitrary order. The output order in each row must be non–decreasing by price.

outputFormat

If a valid ordering exists, output YES on the first line. On the next line, output n space–separated integers representing the 1–indexed ordering of Maria's tiles (front row), and on the third line, output n space–separated integers representing the ordering of João's tiles (back row). These orderings denote the left–to–right positions on the shelf.

If no valid ordering exists, output a single line with NO.

sample

3
5 10
5 9
10 10
5 10
5 11
10 11
YES

2 1 3 1 2 3

</p>