//先想出暴力做法
//再找性质,优化代码
//暴力做法(超时)数组模拟,压根没用到栈
/*
include [HTML_REMOVED]
using namespace std;
const int N = 100010;
int st[N];
int n,top = -1,t = 0;
int main()
{
cin >> n;
for(int i = 1;i<=n;i)
{
cin >> st[i];
}
for(int i = 1;i<= n;i)
{
t = 0;
for(int j = 1;j <= i;j++)
{
if(st[j] < st[i])
{
if(j >= t) t = j;
}
}
if(t) cout << st[t] << ‘ ‘;
else cout << -1 << ‘ ‘;
}
return 0;
}
*/
//y总思想,运用栈解法
include [HTML_REMOVED]
using namespace std;
const int N = 100010;
int stk[N],top;
int main()
{
int n;
cin >> n;
for(int i = 1;i<=n;i)
{
int x;
cin >> x;
while(top && stk[top] >= x) top –;
if(top) cout << stk[top] << ‘ ‘;
else cout << -1 << ‘ ‘;
stk[ top] = x;
}
return 0;
}