#P7205. [COCI 2019/2020 #3] Drvca

[COCI 2019/2020 #3] Drvca

Description

To welcome Santa Claus, the city hall has prepared NN Christmas trees. The staff want to arrange these trees into two rows, such that in each row:

  • The height difference between any two adjacent trees is the same.
  • The Christmas trees are ordered from shorter to taller by height.

Please help them find a suitable arrangement.

Input Format

The first line contains an integer NN, the total number of Christmas trees.

The second line contains NN integers. The ii-th integer is hih_i, the height of the ii-th Christmas tree.

Output Format

The first line outputs an integer AA, the number of Christmas trees in the first row.

The second line outputs AA integers, in order, the heights of the trees in the first row.

The third line outputs an integer BB, the number of Christmas trees in the second row.

The fourth line outputs BB integers, in order, the heights of the trees in the second row.

In the output, each row must contain at least one tree, i.e. A>0,B>0A \gt 0, B \gt 0, and every tree must be placed into one of the two rows, i.e. A+B=NA + B = N. Also, the trees in each row must be listed in increasing order of height. If there are multiple valid solutions, output any one of them. Otherwise, output a single integer -1.

4
1 2 3 4
2
1 2
2
3 4
6
23 4 7 6 8 15
3
4 6 8
3
7 15 23
6
1 2 3 7 9 10
-1

Hint

Constraints and Notes

Subtask Score Constraints and Notes Special Property
11 2020 N15N \le 15 None
22 3030 N300N \le 300
33 N105N \le 10^5 There exists a solution where the two rows have the same number of trees.
44 None

For 100%100\% of the testdata, 2N105,1hi1092 \le N \le 10^5, 1 \le h_i \le 10^9.

Notes

The score for this problem follows the original COCI setting, with a full score of 110110.

This problem uses an unofficial Special Judge. Hacks are welcome (you can send a private message or post directly).

Translated from COCI2019-2020 CONTEST #3 T3 Drvca.

Translated by ChatGPT 5