#P2947. [USACO09MAR] Look Up S

[USACO09MAR] Look Up S

Description

Farmer John's N(1N105)N(1 \le N \le 10^5) cows, conveniently numbered 11 to NN, are once again standing in a row. Cow ii has height Hi(1Hi106)H_i(1 \le H_i \le 10^6).

Each cow is looking to her right toward those with higher index numbers. We say that cow ii "looks up to" cow jj if i<ji < j and Hi<HjH_i < H_j. For each cow ii, FJ would like to know the index of the first cow in line "looked up to" by cow ii.

Note: about 50%50\% of the test data will have N103N \le 10^3.

Input Format

Line 11 : A single integer: NN.

Lines 22 to N+1N+1 : Line i+1i+1 contains the single integer: HiH_i.

Output Format

Lines 11 to NN: Line ii contains a single integer representing the smallest index of a cow up to which cow ii looks. If no such cow exists, print 00.

6 
3 
2 
6 
1 
1 
2 

3 
3 
0 
6 
6 
0 

Hint

FJ has six cows of heights 33, 22, 66, 11, 11, and 22.

Cows 11 and 22 both look up to cow 33; cows 44 and 55 both look up to cow 66. Cows 33 and 66 do not look up to any cow.