// Fenwick Tree
#include<iostream>
#include<algorithm>
#include<cmath>
#include<climits>
#include<cstring>
#include<map>
#define fr(i, zz, zzz) for (int i = zz; i <= zzz; i++)
#define ll long long
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define frr(i, zz, zzz) for (int i = zz; i >= zzz; i--)
#define full(asdf) memset(asdf, 0, sizeof(asdf))
#define st first
#define nd second
#define IOS ios_base::sync_with_stdio(0);   cin.tie(0); cout.tie(0);
using namespace std;
const int N = 3E4 + 1;
ll a[N];
int BIT[N];
int n;
int cnt = 1;
int ans = 0;
void digitization() {
	int cnt = 0;
	pair<ll, int> tmp[N];
	cin >> n;
	fr(i, 1, n) {
		cin >> a[i];
		tmp[i].st = a[i];
		tmp[i].nd = i;
	}
	sort(tmp + 1, tmp + n + 1);
	fr(i, 1, n) {
		if (tmp[i].st != tmp[i-1].st)
			++cnt;
		a[tmp[i].nd] = cnt;
	}
		
}
ll Get(int pos) {
	int res = 0;
	while (pos > 0) {
		res = max(res, BIT[pos]);
		pos -= pos & -pos;
	}
	
	return res;
}
void Update(int val) {
	int x = Get(val - 1);
	ans = max(x, ans);
	while (val <= n) {
		BIT[val] = max(BIT[val], x + 1);
		val += val & -val;
	}
}
void solve() {
	fr(i, 1, n) {
		Update(a[i]);
	}

	fr(i, 1, n)
		cout << BIT[i] << " ";
//	cout << Get(n);
}
int main () {
	IOS
	digitization();
	solve();
}

