#P7652. [BalticOI 1996] A NICE SEQUENCE (Day 1)

[BalticOI 1996] A NICE SEQUENCE (Day 1)

Description

There is a sequence a1,a2,,aNa_1, a_2, \cdots, a_N consisting of NN integers. A sequence b1,b2,,bLb_1, b_2, \cdots, b_L is a subsequence of the given sequence if:

  1. For each ii (1iL1 \le i \le L), there exists a jj (1jN1 \le j \le N) such that bi=ajb_i = a_j;
  2. For any i1i_1 and i2i_2 with i1<i2i_1 < i_2, if bi1=aj1b_{i1} = a_{j1} and bi2=aj2b_{i2} = a_{j2}, then the relation j1<j2j_1 < j_2 holds.

The sequence b1,b2,,bLb_1, b_2, \cdots, b_L is non-increasing if for every ii (1i<L1 \le i < L), bibi+1b_i \ge b_{i+1}.
The sequence b1,b2,,bLb_1, b_2, \cdots, b_L is non-decreasing if for every ii (1i<L1 \le i < L), bibi+1b_i \le b_{i+1}.

The given sequence is called NICE if we can choose KK subsequences of this sequence such that:

  1. Each subsequence has at least 22 elements;
  2. Each subsequence is either non-increasing or non-decreasing;
  3. Every element of the given sequence belongs to exactly one subsequence.

Find the minimum possible KK for the given sequence.

Input Format

The first line contains an integer NN. The next NN lines contain the elements of the sequence (one integer per line, and for each jj, 1aj1001 \le a_j \le 100).

Output Format

The output must contain:

  1. The value of KK in the first line;
  2. One example of a partition of the given sequence into KK subsequences (that is, there must be NN lines, each containing aja_j and the index (11 \le index K\le K) of the subsequence to which aja_j belongs).

If the given sequence is not NICE, then the first line of the output must contain only 00.

6
12
33
97
18
15
33
2
12 1
33 1
97 2
18 2
15 2
33 1
1
88
0
4
77
22
22
11
1
77 1
22 1
22 1
11 1

Hint

Constraints

For 100%100\% of the testdata, 1N251 \le N \le 25, 0<KN0 < K \le N.

Sample Explanation

In sample 1, the subsequences are 12,33,3312, 33, 33 and 97,18,1597, 18, 15.

Scoring

The score of this problem follows the original BOI settings, with a full score of 4040.

Notes

This problem comes from Day 1: A NICE SEQUENCE in Baltic Olympiad in Informatics 1996.
Translated and整理 (zhěng lǐ: organized) by @求学的企鹅.

Translated by ChatGPT 5