#GD0000009. Dãy con tăng tham lam (Greedily Increasing Subsequence)

Dãy con tăng tham lam (Greedily Increasing Subsequence)

Greedily Increasing Subsequence

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

Given a permutation A=(a1,…,aN)A=(a_1,\ldots,a_N) of 1,2,…,N1,2,\ldots,N, build its greedily increasing subsequence (GIS): set g1=a1g_1=a_1, then repeatedly take the first later element that is strictly larger than the last chosen element. Stop when no such element remains. Print the GIS.

Input

The first line contains NN. The second line contains the permutation a1,…,aNa_1,\ldots,a_N.

Output

Print the GIS length on the first line and the GIS elements on the second line.

Subtasks

General constraints:

  • 1≤N≤2⋅1051 \le N \le 2\cdot10^5.

  • AA is a permutation of 1,2,…,N1,2,\ldots,N.

  • Subtask 1 (20 points): N≤20N \le 20

  • Subtask 2 (30 points): N≤5000N \le 5000

  • Subtask 3 (50 points): No additional constraints.

Examples

Input

7
2 3 1 5 4 7 6

Output

4
2 3 5 7

Explanation

Start with 22. The first later value larger than 22 is 33, then 55, then 77. No later value exceeds 77.