#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
int h[n];
int m[n];
for (int i = 0; i < n; i++)
{
cin >> h[i];
}
int suunta = 0;
bool b[n+1], T = 0, Te = 0;
for (int i = 0; i < n; i++)
{
b[i] = 1;
m[i] = 0;
}
b[n] = 0;
int s = -1, S = -1;
int p = 0, P = -1;
int q = 0, Q = 0;
for (int j = 0; j < n; j++)
{
for (int i = 0; i < n; i++)
{
while (b[i] == 1)
{
m[i]++;
if (h[i] >= S)
{
S = h[i];
P = i;
//cout << p << endl;
}
if (h[i] > s)
{
s = h[i];
p = i;
//cout << p << endl;
}
i++;
}
s = -1;
S = -1;
if (b[p] == 0) continue;
b[p] = 0;
m[p]--;
//
if (P != p)
{
for (int x = p + 1; x<=P; x++)
{
if (m[P] > m[x] + 1)
{
suunta = 1;
break;
}
else if (m[P] > m[x])
{
suunta = 2;
break;
}
if (m[P] > m[x] + 1)
{
suunta += 3;
break;
}
else if (m[P] > m[x])
{
suunta += 6;
break;
}
}
q = p;
Q = P;
if (suunta == 6 || suunta == 8)
{
T = 1;
for (int x = p + 1; x<P; x++)
{
if (h[x] == h[p])
{
q = x;
T = 0
break;
}
}
}
if (suunta == 2 || suunta == 8)
{
Te = 1;
for (int x = P - 1; x>p; x++)
{
if (h[x] == h[p])
{
Q = x;
Te = 0;
break;
}
}
}
if (T == 0 && Te ==0)
{
for (int we = q + 1; we < Q; we++)
{
m[we]--;
}
}
for (int x = p + 1; x<=P; x++)
{
if (h[x] == h[p])
{
b[x] = 0;
m[x]--;
}
}
}
//
}
s = -1;
for (int i = 0; i < n; i++)
{
cout << m[i] << " ";
//cout << b[i] << " b:";
}
cout << endl;
}
int v = 0;
for (int i = 0; i < n; i++)
{
if (m[i] > v) v = m[i];
//cout << m[i] << " ";
//cout << b[i] << endl;
}
cout << v+1 << endl;
}