#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target_tbl("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


//#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>
#include "random"
#include "chrono"
#include "cstring"


using namespace std;

#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);

/////////////////
#define endl '\n'
/////////////////

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;

//#define int unsigned int
#define int long long
#define double ld
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<vi> vvi;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

int xx[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int yy[8] = { 0, 0, 1, -1, -1, -1, 1, 1 };
string dir = "RDLU";
string travel = "ENWS";

const int N = 1e5 + 50, oo = 1e18 + 500;
const int mod = 998244353;
//const int mod = 1e9 + 7;
//const int mod = 1e9 + 9;
const int M2 = 1000000093, x2 = 27162;
const int M1 = 1000000087, x1 = 241;
const double eps = 1e-18, PI = 2 * acos(0.0);
int cnt = 0;
//vvi g;
vector<set<int>> g;
vi visit;

struct ST
{
	int N = 1;
	vi mx;
	vi mn;
	vi p;

	void init(int n)
	{
		while (N < n) N <<= 1;
		mx.assign(N << 1, -oo);
		mn.assign(N << 1, oo);
		p.assign(N << 1, 0);
	}

	void build(vi &p)
	{
		int n = SZ(p);
		init(n);
		for (int i = 0; i < n; i++)
		{
			mx[i + N] = mn[i + N] = p[i];
		}
		for (int i = N - 1; i; i--)
		{
			mx[i] = max(mx[i << 1], mx[i << 1 | 1]);
			mn[i] = min(mn[i << 1], mn[i << 1 | 1]);
		}
	}

	void push(int v)
	{
		if (v >= N || !p[v])
			return;

		mx[v << 1] += p[v];
		mx[v << 1 | 1] += p[v];
		mn[v << 1] += p[v];
		mn[v << 1 | 1] += p[v];
		p[v << 1] += p[v];
		p[v << 1 | 1] += p[v];
		p[v] = 0;
	}

	void set(int v, int lv, int rv, int l, int r, int val)
	{
		if (l > r)
			return;

		push(v);

		if (lv == l && rv == r)
		{
			p[v] += val;
			mx[v] += val;
			mn[v] += val;
			return;
		}

		int md = (lv + rv) >> 1;

		set(v << 1, lv, md, l, min(r, md), val);
		set(v << 1 | 1, md + 1, rv, max(l, md + 1), r, val);
		mx[v] = max(mx[v << 1], mx[v << 1 | 1]);
		mn[v] = min(mn[v << 1], mn[v << 1 | 1]);
	}

	int get_mx(int v, int lv, int rv, int l, int r)
	{
		if (l > r)
			return -oo;

		push(v);

		if (lv == l && rv == r)
		{
			return mx[v];
		}

		int md = (lv + rv) >> 1;

		return max(get_mx(v << 1, lv, md, l, min(r, md)), 
		get_mx(v << 1 | 1, md + 1, rv, max(l, md + 1), r));
	}

	int get_mn(int v, int lv, int rv, int l, int r)
	{
		if (l > r)
			return oo;

		push(v);

		if (lv == l && rv == r)
		{
			return mn[v];
		}

		int md = (lv + rv) >> 1;

		return min(get_mn(v << 1, lv, md, l, min(r, md)),
			get_mn(v << 1 | 1, md + 1, rv, max(l, md + 1), r));
	}

	void set(int l, int r, int val)
	{
		set(1, 0, N - 1, l, r, val);
	}

	int get_mx(int l, int r)
	{
		return get_mx(1, 0, N - 1, l, r);
	}

	int get_mn(int l, int r)
	{
		return get_mn(1, 0, N - 1, l, r);
	}
};

signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//freopen("paintbarn.in", "r", stdin);
	//freopen("paintbarn.out", "w", stdout);

	int n;
	cin >> n;

	vi a(n);
	vvi inds(n + 1);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		inds[a[i]].push_back(i);
	}

	vi p(n + 1);
	for (int i = 1; i <= n; i++)
	{
		p[i] = p[i - 1] + 1;
	}

	vi ans(n);

	{
		ST st;
		st.build(p);

		for (int v = 1; v <= n; v++)
		{
			for (auto i : inds[v])
			{
				int r = st.get_mx(i + 1, n);
				int l = st.get_mn(0, i + 1);
				maxi(ans[i], (r - l) / 2);
			}

			for (auto i : inds[v])
			{
				st.set(i + 1, n, -2);
			}
		}
	}
	
	{
		ST st;
		st.build(p);

		for (int v = n; v >= 1; v--)
		{
			for (auto i : inds[v])
			{
				int r = st.get_mx(i + 1, n);
				int l = st.get_mn(0, i + 1);
				maxi(ans[i], (r - l - 1) / 2);
			}

			for (auto i : inds[v])
			{
				st.set(i + 1, n, -2);
			}
		}
	}

	show(ans);
}

