#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> m[1000010];
int n;
void build() {
  for (int i = n - 1; i >= 1; i--) {
    if (m[i << 1].first <= m[i << 1 | 1].first)
      m[i] = m[i << 1];
    else
      m[i] = m[i << 1 | 1];
  }
}
pair<long long, long long> query(int a, int b) {
  pair<long long, long long> ans = m[a + n];
  for (int i = a + n, j = b + n; i < j; i >>= 1, j >>= 1) {
    if (i & 1) {
      if (m[i].first < ans.first) ans = m[i];
      i++;
    }
    if (j & 1) {
      j--;
      if (m[j].first < ans.first) ans = m[j];
    }
  }
  return ans;
}
pair<long long, long long> pivo(int inicio, int fim) {
  if (inicio == fim) return m[inicio + n];
  if (inicio > fim) return {-1, 0};
  long long u = query(inicio, fim + 1).second;
  pair<long long, long long> b = pivo(inicio, u - 1), c = pivo(u + 1, fim);
  if (b.first + (fim - u + 1) * m[n + u].first >
      c.first + (u - inicio + 1) * m[n + u].first) {
    return {b.first + (fim - u + 1) * m[n + u].first, b.second};
  } else
    return {c.first + (u - inicio + 1) * m[n + u].first, c.second};
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m[i + n].first;
    m[i + n].second = i;
  }
  build();
  long long u = pivo(0, n - 1).second;
  vector<long long> a, b;
  long long min1 = m[u + n].first, min2 = m[u + n].first;
  for (int i = u + 1; i < n; i++) {
    if (m[i + n].first < min1)
      b.push_back(m[i + n].first), min1 = m[i + n].first;
    else
      b.push_back(min1);
  }
  for (int i = u - 1; i >= 0; i--) {
    if (m[i + n].first < min2)
      a.push_back(m[i + n].first), min2 = m[i + n].first;
    else
      a.push_back(min2);
  }
  reverse(a.begin(), a.end());
  for (int i = 0; i < a.size(); i++) cout << a[i] << " ";
  cout << m[u + n].first << " ";
  for (int i = 0; i < b.size(); i++) cout << b[i] << " ";
  printf("\n");
}
