QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 32 MB Points totaux : 10

#13518. Supernumbers

Statistiques

An $n$-element permutation is an $n$-element sequence consisting of distinct numbers from the set $\{1, 2, \dots, n\}$. For example, the sequence 2, 1, 4, 5, 3 is a 5-element permutation.

In permutations of numbers, we are interested in the longest increasing subsequences. In the example permutation, they have a length of 3, and there are exactly two such subsequences: 2, 4, 5 and 1, 4, 5.

A supernumber is any number that belongs to at least one of the longest increasing subsequences. In the permutation 2, 1, 4, 5, 3, the supernumbers are 1, 2, 4, 5, while the number 3 is not a supernumber.

Your task is to find all supernumbers for a given permutation.

Task

Write a program that:

  • reads the permutation from standard input,
  • finds all supernumbers,
  • prints the found supernumbers to standard output.

Input

The input consists of two lines. The first line contains a single integer $n$, $1 \le n \le 100\,000$. The second line contains $n$ numbers forming an $n$-element permutation, separated by single spaces.

Output

The output should consist of two lines. The first line should contain a single integer $m$ — the number of supernumbers in the input permutation. The second line should contain the supernumbers separated by single spaces, listed in increasing order.

Examples

Input 1

5
2 1 4 5 3

Output 1

4
1 2 4 5

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.