Under construction

Still being built. Things may change

The Next Different Number

Interview

Time limit1sMemory limit1024 MB

Summary
For each position i in a sequence, find the smallest later index j whose value differs from A[i], or -1 if none exists.
Level

Easy3 of 10

Topics
Array, Implementation, Greedy
Solved
No attempts yet

Problem

A sequence of length NN, A1 A2 ⋯ ANA_1 \ A_2 \ \cdots \ A_N, is given. For each integer ii with 1≤i≤N1 \le i \le N, output the smallest integer jj such that i<j≤Ni < j \le N and Ai≠AjA_i \ne A_j. If no such jj exists, output −1-1.

Input

The first line gives NN, the size of the sequence AA. The second line gives A1 A2 ⋯ ANA_1 \ A_2 \ \cdots \ A_N separated by spaces. (1≤N≤106(1 \le N \le 10^6, −109≤Ai≤109)-10^9 \le A_i \le 10^9 )

Every number in the input is an integer.

Output

For each ii, output the smallest jj that satisfies the condition. If no such jj exists, output −1-1.

Examples1

  1. Example 1

    Input
    6
    3 3 1 1 4 4
    
    Expected output
    3 3 5 5 -1 -1