#t378. 最长上升序列(LIS)

最长上升序列(LIS)

Longest Increasing Subsequence

Background

Special for beginners, ^_^

Problem Description

Consider a sequence composed of nn distinct integers, denoted b1,b2,…,bnb_1, b_2, \dots, b_n with bi≠bjb_i \neq b_j (i≠ji \neq j). If there exist indices i1<i2<i3<⋯<iei_1 < i_2 < i_3 < \dots < i_e such that bi1<bi2<⋯<bieb_{i_1} < b_{i_2} < \dots < b_{i_e}, then this is called an increasing subsequence of length ee.

Given the original sequence, find its longest increasing subsequence.

For example, 13, 7, 9, 16, 38, 24, 37, 18, 44, 19, 21, 22, 63, 15.

In this example, 13, 16, 18, 19, 21, 22, 63 is an increasing subsequence of length 7, and at the same time 7, 9, 16, 18, 19, 21, 22, 63 is an increasing subsequence of length 8.

Input Format

One line containing several positive integers; the count is less than 100, and each value is less than 50000.

Output Format

Output two lines.

The first line outputs an integer ee.

The second line outputs ee integers, the longest increasing subsequence.

Sample Input 1

300 250 275 252 200 138 245

Sample Output 1

2
250 275 

Constraints

1s, 1024KiB for each test case.