
#include <iostream>
#include <stdlib.h>
using namespace std;


struct node{
	long long int info;
	node * prev;
	node * next;
};

node *s=NULL,*r=NULL;

void create(long long int p)
{
	node *ptr;
	ptr = new node;
	ptr->info=p;
	ptr->prev=NULL;
	ptr->next=NULL;
	if(s==NULL)
	s=r=ptr;
	else
	{
		r->next=ptr;
		ptr->prev=r;
		r=ptr;
	}
}

void death(node * tmp)
{
	struct node *pr,*t,*ok;
	//t=s;
	pr=s;
  long	int ct=0,ans=0,flag,jt=0,j=0;
while(1)
	{
		j=0;
		ct=0;
		tmp=pr->next;
	//	cout<<pr->info<<" ";
		if(jt=0)
		{
			while(tmp->info<tmp->prev->info)
			tmp=tmp->next;
			pr=tmp->prev; //fix position
		}
		
		while(tmp!=NULL)
	   {    
	   	     //cout<<".";
	   	    jt++;
	   	    flag=0;
	    	while(tmp->info>tmp->prev->info)
		    {
		    	//cout<<tmp->info<<" ";
		   	   ct++;
		    	flag=1;
		    	
		    if(tmp->next==NULL)
		    {
		    	pr->next=NULL;
		    	break;
		    }
		    
			tmp=tmp->next;
			
	       }
	      // t=tmp->prev;
		//if(&&tmp->next==NULL) 
		//t->next=NULL;
	    if(flag==1)
		{   
			//cout<<pr->info<<"\n";
			//cout<<t->info<<" "<<k->next->info<<" "<<pr->info<<" "<<tmp->info<<" ";
			pr->next=tmp;
			
			tmp->prev=pr;
			if(tmp->info<pr->info)
			pr=tmp;
			/*
			else if(tmp->info>pr->info&&pr==tmp->prev&&tmp->next==NULL)
		    {
		    	//cout<<"here";
		    	j=1;
		    	ans++;
		    	pr->next=NULL;
		    }*/
			
		    
		}
		//cout<<pr->info<<" ";
		tmp=tmp->next;
		if(tmp==NULL)
		cout<<"wow";
	  }
	  
	  //cout<<pr->info<<" ";
	  //cout<<ct<<" ";
	  
	  ans++;
	  cout<<ans<<" ";
	  
	  if(ct==0)
	  break;
	}
	
	cout<<ans<<"\n";
}
int main() {

	long long int n,p,i;
	cin>>n;
	if(n==1)
	{
		cout<<"0";
		exit(0);
	}
	for(i=0;i<n;i++)
	{
		cin>>p;
		create(p);
	}
	
	death(s);
}