#include <bits/stdc++.h>

#define sf(x) scanf("%d", &x)
#define lsf(x) scanf("%lld", &x)
#define pf(x) printf("%d\n", x)
#define lpf(x) printf("%lld\n",x)
#define rep(i,x,y) for(int i=x;i<y;i++)  
#define repp(i,x,y) for(int i=x;i<=y;i++)
#define mem(a,x) memset(a,x,sizeof(a))  
#define abs(x)    ((x) < 0 ? -(x) : (x))
#define all(x) x.begin(),x.end()
#define sz(x) (x).size()
#define pb push_back
#define x first
#define y second
#define bug(x) cerr<<#x<<'='<<x<<' '
#define debug(x) cerr<<#x<<'='<<x<<endl
#define gcd(a,b) __gcd(a,b)  

#define mod 1000000007
#define INF 0x3f3f3f3f3f
#define delta 0.85
#define eps 1e-6	
#define PI 3.14159265358979323846
#define MAX_N 200010
#define MAX_M 1 << 19 | 7

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

int n;

struct node {
	int s, l, r;
	node() {}
	node(int S, int L, int R) : s(S), l(L), r(R){} 
	friend node operator + (node a, node b) {
		return node(a.s + b.s, std::max(a.l, a.s + b.l), std::max(b.r, b.s + a.r));
	}
}tr[MAX_M * 4];

struct Node{
	int x, idx;
	bool operator < (const Node & t) const {
		return x < t.x;
	}
}a[MAX_N];

int ans[MAX_N];

void build(int u, int l, int r) {
	if (l == r) {
		tr[u] = {-1, -1, -1};
		return;
	}
	int mid = l + r >> 1;
	build(u << 1, l, mid);
	build(u << 1 | 1, mid + 1, r);
	tr[u] = tr[u << 1] + tr[u << 1 | 1];
}

void update (int u, int l, int r, int v) {
	if (l == r) {
		tr[u] = {1, 1, 1};
		return;
	}
	v <= (l + r >> 1) ? update(u << 1, l, (l + r) >> 1, v) : update(u << 1 | 1, ((l + r >> 1) + 1), r, v);
	tr[u] = tr[u << 1] + tr[u << 1 | 1]; 
}

node query(int u, int l, int r, int a, int b) {
	if (a <= l && r <= b) return tr[u];
	else if (r < a || l > b) return node(0, 0, 0);
	return query(u << 1, l, (l + r) >> 1, a, b) + query(u << 1 | 1, ((l + r >> 1) + 1), r, a, b);
}

void solve() {
	sf(n);
	repp(i, 1, n) {
		sf(a[i].x);
		a[i].idx= i;
		
	}
	sort(a + 1, a + 1 + n); 
	
//	repp(i, 1, n)
//	bug(a[i].x), debug(a[i].idx);
	
	build(1, 1, n);
	
	repp(i, 1, n) {
		int j = i;
		while(j + 1 <= n && a[i].x == a[j + 1].x) ++ j;
		repp(k, i, j) update(1, 1, n, a[k].idx);
		repp(k, i, j) {
			int idx = a[k].idx;
			node l = query(1, 1, n, 1, idx);
			node r = query(1, 1, n, idx, n);
			ans[idx] = std::max(ans[idx], (l.r + r.l) / 2 - 1);
		}
		i = j;
	}
	
	build(1, 1, n);
	for (int i = n; i >= 1; i -- ) {
		int j = i;
		while(j - 1 >= 1 && a[i].x == a[j - 1].x) -- j;
		
		for (int k = i; k >= j; k -- ) {
			update(1, 1, n, a[k].idx);
		}
		for (int k = i; k >= j; k -- ) {
			int idx = a[k].idx;
			node l = query(1, 1, n, 1, idx);
			node r = query(1, 1, n, idx, n);
			ans[idx] = std::max(ans[idx], (l.r + r.l - 1) / 2);
		}
		i = j;
	}
	
	repp(i, 1, n) {
		printf("%d%c", ans[i], " \n"[i == n]);
	}
	return;
}

int main() {
	int t;
	t = 1;
	while (t --) {
		solve();
	} 
	return 0;
}
