0066. Nice Subsequence

Имя входного файла: subseq.in
Имя выходного файла: subseq.out
Ограничение по времени: 1 s
Ограничение по памяти: 64 megabytes

Let us call some sequence of positive integer numbers {\em nice} if for each i either ai = 1 or the quantity of such j < i that aj = ai - 1 is greater than the quantity of such j < i that aj = ai.

You are given a sequence of positive integer numbers and your task is to find its longest nice subsequence.

Input file

The first line of the input file contains N – the number of elements in the sequence you are given (1 ≤ N ≤ 100,000). N positive integer numbers a1, a2, …, aN follow, separated by spaces and/or line feeds.

Output file

First output L – the number of elements in the subsequence found. After that output L integer numbers 1 ≤ i1 < i2 < … < iL ≤ N, such that ai1, ai2, …, aiL is the nice subsequence found.

Examples:

subseq.insubseq.out
10 2 3 1 3 2 1 2 2 4 35 3 5 6 7 10


Источник: Petrozavodsk Winter 2003. St. Petersburg Contest I

Обсудить       Отправить решение



Версия для печати