/* 소들의 헤어스타일
#include <stdio.h>
int stack[80000]= {};
int top=-1;
void push(int a)
{
top++;
stack[top]=a;
}
int pop()
{
if(top>-1)
{
top--;
}
}
int main()
{
int n;
int hi;
long long int sum=0;
scanf("%d",&n);
for(int i=0; i<n; i++)
{
scanf("%d",&hi);
while(top>-1 && stack[top]<=hi)
{
pop();
}
sum=sum+top+1;
push(hi);
}
printf("%lld",sum);
return 0;
}
*/
/* 큰 수 덧셈
#include <stdio.h>
#include <string.h>
int stack[150]={};
int top=-1;
void push(int x)
{
top++;
stack[top]=x;
}
int pop()
{
if(top>-1)
{
top--;
}
return stack[top+1];
}
int main()
{
char a[101]={}, b[101]={};
int topa, topb;
int sum=0,c=0;
scanf("%s %s",a,b);
topa = strlen(a)-1;
topb = strlen(b)-1;
while(1)
{
sum=c;
if(topa>=0)
{
sum = sum+a[topa]-'0';
topa--;
}
if(topb>=0)
{
sum = sum+b[topb]-'0';
topb--;
}
push(sum%10);
c=sum/10;
if(topa<0 && topb<0)
{
if(c!=0) push(c);
break;
}
}
while(top>-1) printf("%d",pop());
return 0;
}
*/
//탑 4654 -> 소들의 헤어스타일과 비슷하게 풀면 됨
#include <stdio.h>
int stack[500005]={};
int top=-1;
void push(int a)
{
top++;
stack[top]=a;
}
int pop()
{
if(top>-1) top--;
return stack[top+1];
}
int main()
{
int n;
int arr[500001]={};
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
while(top>-1 && stack[top]<arr[i])
{
}
}
return 0;
}



