#include <bits/stdc++.h>
using namespace std;
long long a[500001];
long long f(long long a[], long long s, long long e) {
  if (s == e) return 0;
  long long mn = a[s];
  long long j = s;
  for (long long i = s + 1; i < e + 1; i++) {
    if (a[i] < mn) {
      mn = a[i];
      j = i;
    }
  }
  long long p = 0;
  long long q = 0;
  for (long long i = s; i < j; i++) {
    if (a[i] > a[j]) p += a[i] - a[j];
  }
  for (long long i = j + 1; i < e + 1; i++) {
    if (a[i] > a[j]) q += a[i] - a[j];
  }
  if (j == s) {
    long long c = f(a, j + 1, e);
    return c;
  } else if (j == e) {
    long long c = f(a, s, j - 1);
    return c;
  }
  long long c = f(a, j + 1, e);
  long long d = f(a, s, j - 1);
  if (p + c < q + d) {
    for (long long i = s; i < j; i++) a[i] = a[j];
  } else {
    for (long long i = j + 1; i < e + 1; i++) a[i] = a[j];
  }
  return (min(p + c, q + d));
}
void solve() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long ans = f(a, 0, n - 1);
  for (long long i = 0; i < n; i++) cout << a[i] << " ";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long test;
  test = 1;
  while (test--) {
    solve();
  }
  return 0;
}
