#include <bits/stdc++.h>
using namespace std;
typedef int Long;

const Long BQ = 450;
const Long MX = 2e5 + 10;
const Long INF = 1e9;

Long rr[MX];
Long id[MX];
Long sum[BQ];
Long A[BQ][BQ];
Long block[4][BQ][BQ];

Long f(Long a, Long b, Long t){
	if(t < 2) return max(a,b);
	return min(a,b);
}

void updatet(Long bq, Long pos, Long t){
	if(t % 2 == 0){
		block[t][bq][pos] = A[bq][pos];
		if(pos != BQ - 1) block[t][bq][pos] = f(A[bq][pos], A[bq][pos] + block[t][bq][pos+1],t);
		for(Long i = pos - 1; i >= 0; i--) block[t][bq][i] = f(A[bq][i], A[bq][i] + block[t][bq][i+1], t);
	}else{
		block[t][bq][pos] = A[bq][pos];
		if(pos != 0) block[t][bq][pos] = f(A[bq][pos], A[bq][pos] + block[t][bq][pos-1],t);
		for(Long i = pos + 1; i < BQ; i++) block[t][bq][i] = f(A[bq][i], A[bq][i] + block[t][bq][i-1], t);
	}
}

Long query(Long u, Long t){
	Long bq = id[u];
	Long pos = rr[u];
	Long cur = 0;
	Long ans;
	if(t % 2 == 0){
		if(t == 0) ans = -INF;
		else ans = INF;
		
		for(Long i = pos; i < BQ; i++){
			cur += A[bq][i];
			ans = f(ans,cur,t);
		}
		for(Long i = bq + 1; i < BQ; i++){
			ans = f(ans,cur + block[t][i][0],t);
			cur += sum[i];
			ans = f(ans,cur,t);
		}
	}else{
		if(t == 1) ans = -INF;
		else ans = INF;
		for(Long i = pos; i >= 0; i--){
			cur += A[bq][i];
			ans = f(ans,cur,t);
		}
		for(Long i = bq - 1; i >= 0; i--){
			ans = f(ans,cur + block[t][i][BQ-1], t);
			cur += sum[i];
			ans = f(ans,cur,t);
		}
	}
	return ans;
}

void update(Long u, Long val){
	Long bq = id[u];
	Long pos = rr[u];
	sum[bq] -= A[bq][pos];
	sum[bq] += val;
	A[bq][pos] = val;
	updatet(bq,pos,0);
	updatet(bq,pos,1);
	updatet(bq,pos,2);
	updatet(bq,pos,3);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	cout << fixed;
	
	for(Long i = 0; i < MX; i++){
		id[i] = i / BQ;
		rr[i] = i % BQ;
	}
	
	Long n;
	cin >> n;
	vector<Long> v(n);
	for(Long i = 0; i < n; i++) cin >> v[i];
	
	vector<pair<Long,Long>> ord;
	for(Long i = 0; i < n; i++) ord.push_back({v[i],i});
	sort(ord.begin(),ord.end());
	
	for(Long i = 0; i < n; i++) update(i,1);
	
	vector<Long> ans(n,0);
	for(Long i = 0; i < n; i++){
		Long l = i;
		while(i < n && ord[i].first == ord[l].first) i++;
		i--;
		Long r = i;
		
		for(Long j = l; j <= r; j++){
			Long pos = ord[j].second;
			Long R = query(pos,0);
			Long L = query(pos,1);
			Long tot = R + L - 1;
			ans[pos] = max(ans[pos],tot/2);
		}
		
		for(Long j = l; j <= r; j++) update(ord[j].second,-1);
		
		for(Long j = l; j <= r; j++){
			Long pos = ord[j].second;
			Long R = query(pos,2);
			Long L = query(pos,3);
			Long tot = abs(R + L + 1);
			ans[pos] = max(ans[pos],(tot-1)/2);
		}
	}
	
	for(Long xx : ans) cout << xx << " ";
	cout << "\n";
	return 0;
}
