#include <bits/stdc++.h>
using namespace std;
const int c_YET = -1;
const int INF = 1e9 + 1;
const long long LLINF = 1e17 + 1;
const int DX[9] = {0, 0, 1, -1, 1, 1, -1, -1, 0};
const int DY[9] = {1, -1, 0, 0, 1, -1, 1, -1, 0};
const long long MOD = 1e9 + 7;
const long long MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
long long RepeatSquaring(long long base, long long sisuu) {
  if (sisuu == 0) return 1;
  if (sisuu % 2 == 0) {
    long long t = RepeatSquaring(base, sisuu / 2) % MOD;
    return (t * t) % MOD;
  }
  return base * RepeatSquaring(base, sisuu - 1) % MOD;
}
uint64_t get_rand_range(uint64_t min_val, uint64_t max_val) {
  static std::mt19937_64 mt64(0);
  std::uniform_int_distribution<uint64_t> get_rand_uni_int(min_val, max_val);
  return get_rand_uni_int(mt64);
}
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(30);
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<vector<long long>> AP(N);
  for (long long i = 0; i < N; i++) {
    vector<long long> t = {A[i], max(i, N - i - 1), i};
    AP[i] = t;
  }
  sort(AP.begin(), AP.end(), greater<vector<long long>>());
  long long ret = 0;
  for (int n = 0; n < 10; n++) {
    vector<long long> ans(N);
    for (int i = 0; i < N; i++) {
      ans[i] = -1;
    }
    long long local = 0;
    for (int i = 0; i < N; i++) {
      long long now = AP[i][2];
      long long dis = AP[i][1];
      for (int d = dis; d >= 0; d--) {
        bool random_get = get_rand_range(0, 99) / 50;
        if (random_get) {
          if (now - d >= 0 && ans[now - d] == -1) {
            ans[now - d] = AP[i][0];
            local += AP[i][0] * d;
            break;
          } else if (now + d < N && ans[now + d] == -1) {
            ans[now + d] = AP[i][0];
            local += AP[i][0] * d;
            break;
          }
        } else {
          if (now + d < N && ans[now + d] == -1) {
            ans[now + d] = AP[i][0];
            local += AP[i][0] * d;
            break;
          } else if (now - d >= 0 && ans[now - d] == -1) {
            ans[now - d] = AP[i][0];
            local += AP[i][0] * d;
            break;
          }
        }
      }
    }
    for (int i = 0; i < N; i++) {
      cout << ans[i] << " ";
    }
    cout << endl;
    ret = max(ret, local);
  }
  cout << ret;
}
