#P7205. Double Row Christmas Trees Arrangement

    ID: 20409 Type: Default 1000ms 256MiB

Double Row Christmas Trees Arrangement

Double Row Christmas Trees Arrangement

In preparation for Santa Claus, the City Hall has arranged (N) Christmas trees. The organizers wish to set them in two rows such that each row satisfies the following conditions:

1. The difference between the heights of any two adjacent trees is equal. In other words, for a row with trees (a_1, a_2, \ldots, a_k), we have
[ a_{2} - a_{1} = a_{3} - a_{2} = \cdots = a_{k} - a_{k-1}. ]

2. The trees in each row are arranged in increasing order of height.

You are given an integer (N) and an array of (N) integers representing the heights of the trees. Your task is to partition these trees into two rows such that each row (when arranged in increasing order) forms an arithmetic progression. Note: Each row must contain at least two trees. If such an arrangement exists, output the two rows (each row’s numbers separated by a single space). Otherwise, output -1.

inputFormat

The first line contains an integer (N) (with (N \ge 4)), representing the number of trees. The second line contains (N) space‐separated integers representing the heights of the trees.

outputFormat

If a valid arrangement exists, output two lines:
- The first line contains the heights of the trees in the first row in increasing order.
- The second line contains the heights of the trees in the second row in increasing order.
If no valid arrangement exists, output -1.

sample

6
1 3 5 2 4 6
1 3 5

2 4 6

</p>