//#define _CRT_SECURE_NO_WARNINGS

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<cmath>
#include<string>
#include<cassert>
#include<iomanip>
#include<unordered_set>
#include<deque>
#include<queue>

#define all(v) v.begin(), v.end()
#define MOD ((int)1e9 + 7)
#define li long int
#define ll long long
#define ull unsigned long long
#define usi unsigned short
#define si short
#define ld long double
#define nint signed
#define PAI pair<int, int>
#define MP make_pair
#define FORN(i, a, n) for (int i = a; i < n; ++i)
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define pob pop_back
#define veci vector<int>
#define precision(x) cout << fixed; cout << setprecision(x);
#define MAXN 300000
#define file_inp(TASKNAME_IN, TASKNAME_OUT) assert(freopen(TASKNAME_IN".in", "r", stdin)); assert(freopen(TASKNAME_OUT".out", "w", stdout));
#define sq 400

using namespace std;

int n, a[MAXN], p[MAXN], res[MAXN];
veci bb[MAXN];

struct segt {
	int sum[MAXN << 2], pre[MAXN << 2], suf[MAXN << 2];
	void update(int id) {
		int ls = id << 1, rs = id << 1 | 1;
		sum[id] = sum[ls] + sum[rs];
		pre[id] = max(pre[ls], sum[ls] + pre[rs]);
		suf[id] = max(suf[rs], sum[rs] + suf[ls]);
	}
	void modify(int id, int l, int r, int x, int c) {
		if (l == r) {
			sum[id] = c; pre[id] = suf[id] = max(c, 0); return;
		}
		int mid = (l + r) >> 1;
		x <= mid ? modify(id << 1, l, mid, x, c) : modify(id << 1 | 1, mid + 1, r, x, c);
		update(id);
	}
	PAI qpre(int id, int l, int r, int ql, int qr) {
		if (l == ql && r == qr) return MP(sum[id], pre[id]);
		int mid = (l + r) >> 1;
		if (qr <= mid) return qpre(id << 1, l, mid, ql, qr);
		if (ql > mid) return qpre(id << 1 | 1, mid + 1, r, ql, qr);
		PAI pl = qpre(id << 1, l, mid, ql, mid), pr = qpre(id << 1 | 1, mid + 1, r, mid + 1, qr);
		return MP(pl.first + pr.first, max(pl.second, pl.first + pr.second));
	}
	PAI qsuf(int id, int l, int r, int ql, int qr) {
		if (l == ql && r == qr) return MP(sum[id], suf[id]);
		int mid = (l + r) >> 1;
		if (qr <= mid) return qsuf(id << 1, l, mid, ql, qr);
		if (ql > mid) return qsuf(id << 1 | 1, mid + 1, r, ql, qr);
		PAI pl = qsuf(id << 1, l, mid, ql, mid), pr = qsuf(id << 1 | 1, mid + 1, r, mid + 1, qr);
		return MP(pl.first + pr.first, max(pr.second, pr.first + pl.second));
	}
};

segt s1, s2;

nint main() {
	fastio;
	cin >> n;
	FORN(i, 1, n + 1) {
		cin >> a[i]; 
		p[i] = i;
		bb[a[i]].pb(i);
	}
	sort(p + 1, p + n + 1, [&](int x, int y) { return a[x] < a[y]; });
	FORN(i, 1, n + 1) {
		s1.modify(1, 1, n, i, 1); 
		s2.modify(1, 1, n, i, -1);
	}
	for (int ii = 1, c1 = 1, c2 = 1; ii <= n; ++ii) {
		int i = p[ii];
		for (; c1 < a[i]; ++c1) {
			for (auto j : bb[c1]) {
				s1.modify(1, 1, n, j, -1);
			}
		}
		for (; c2 <= a[i]; ++c2) {
			for (auto j : bb[c2]) {
				s2.modify(1, 1, n, j, 1);
			}
		}
		int r1 = (i > 1 ? s1.qsuf(1, 1, n, 1, i - 1).second : 0) + (i < n ? s1.qpre(1, 1, n, i + 1, n).second : 0) + 1,
			r2 = (i > 1 ? s2.qsuf(1, 1, n, 1, i - 1).second : 0) + (i < n ? s2.qpre(1, 1, n, i + 1, n).second : 0);
		res[i] = max(r1 / 2, r2 / 2);
	}
	FORN(i, 1, n + 1)
		cout << res[i] << ' ';
}