Given an array, find the nearest smaller element G[i] for every element A[i] in the array such that the element has an index smaller than i.
G[i] for an element A[i] is an element A[j] such that
j is maximum possible AND
j < i AND
A[j] < A[i]
Elements for which no smaller element exist, consider next smaller element as -1.
First line contains an integer N denoting the number of elements in the array (not necessarily distinct).
Second line contains N space separated integers denoting the elements of the array.
Print N space separated integers denoting the array G.