This page is still under construction.

Parts of this page are still being built. What you see may change.

Star Trek

Time limit1sMemory limit1024 MB

Summary
Planets are visited in order, each offering one fuel type; refueling on planet i lets the ship reach the next planet with the same fuel type. Find the minimum number of refuelings to reach planet N and list the planets used.
Level

Medium7 of 10

Topics
Dynamic programming, Greedy, Binary search, Array
Solved
No attempts yet

Problem

An expedition is about to set off on a new-generation spaceship. It will visit NN planets of a star system in order, from planet Earth to planet Victory. The planets are numbered 11 to NN in the order they are visited; Earth has number 11 and Victory has number NN.

To fly between planets, the ship may use any type of fuel that exists in the star system. Before the expedition starts, the ship is on planet Earth and its tank is empty. The existing fuel types are numbered with integers, and on planet ii the ship can refuel only with fuel of type aia_i. When visiting planet ii, the ship can refuel by emptying the tank of whatever fuel it holds and filling it with fuel of type aia_i.

At each planet the refueling station is built so that the tank receives exactly as much fuel as is needed to fly to the next planet with fuel of the same type. If that fuel type never occurs again, refueling at this planet is impossible. In other words, after refueling on planet ii, the fuel is enough to visit planets (i+1)(i + 1) through jj inclusive, where jj is the smallest planet number such that j>ij > i and aj=aia_j = a_i. To continue the expedition beyond planet jj, the ship must refuel again on one of these planets.

Write a program that, given the fuel types on the planets, determines the minimum number of refuelings required for the expedition.

Input

The first line of the input file contains the number NN (2⩽N⩽300 0002 \leqslant N \leqslant 300\,000), the number of planets.

The second line of the input file contains NN integers a1,a2,…,aNa_1, a_2, \ldots, a_N (1⩽ai⩽300 0001 \leqslant a_i \leqslant 300\,000), the fuel types on the planets.

Output

In the first line of the output file, print the single number KK, the minimum number of refuelings that must be performed.

In the second line, print KK numbers separated by spaces: the numbers of the planets where refueling is required. Print the planet numbers in the order in which the refuelings occur.

If there are several solutions with the minimum number of refuelings, print any of them. If no solution exists, print the number 00.

Constraints

  • N≤300 000N \le 300\,000

Examples2

  1. Example 1

    Input
    7
    1 3 2 1 3 2 3
    
    Expected output
    3
    1 3 5
    
  2. Example 2

    Input
    7
    4 3 2 4 3 2 1
    
    Expected output
    0