#d1301. 连续子序列

连续子序列

Consecutive Subsequence

Problem Description

Given an array a1,a2,…,ana_1, a_2, \dots, a_n of length nn, find the longest consecutive increasing subsequence. That is, we want to find a subsequence p1,p2,…,pmp_1, p_2, \dots, p_m satisfying 1≤p1<p2<⋯<pm≤n1 \le p_1 < p_2 < \dots < p_m \le n and $a_{p_m} - a_{p_{m-1}} = a_{p_{m-1}} - a_{p_{m-2}} = \dots = a_{p_2} - a_{p_1} = 1$. Output the maximum mm and the answer subsequence with the smallest lexicographic order.

Input Format

The first line contains an integer nn.

The next line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n.

Output Format

The first line contains an integer mm, the length of the answer subsequence.

The second line contains mm integers, the answer subsequence.

Sample Input

7
3 3 4 7 5 6 8

Sample Output

4
3 4 5 6

Constraints

All data guarantee 1≤n≤2000001 \le n \le 200000, 1≤ai≤1091 \le a_i \le 10^9.