#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<long long, long long> > a(n);
  for (int i = 0; i < (n); i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  vector<pair<long long, long long> > r;
  sort(a.begin(), a.end());
  for (auto c : a) {
    if (c.second < n / 2)
      r.push_back(c);
    else
      r.insert(r.begin(), c);
  }
  long long result = 0;
  for (int i = 0; i < (n); i++) {
    int idx = r[i].second;
    long long act = r[i].first;
    result += abs(i - idx) * act;
  }
  cout << result << endl;
  for (int i = 0; i < (n); i++) cout << r[i].first << ' ';
  return 0;
}
