#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int m = 1e9 + 7;
using P = pair<int, int>;
struct d {
  ll i, j, x;
  bool operator<(const d e) const { return x < e.x; }
};
int main() {
  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  ll b[n];
  for (int i = 0; i < n; i++) b[i] = i;
  for (int i = 0; i < n; i++) cout << b[i] << " ";
  cout << endl;
  bool update = true;
  ll an = 0;
  while (update) {
    update = false;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j) continue;
        if (b[i] == i && b[j] == j) {
          b[i] = j, b[j] = i, an += (a[i] + a[j]) * abs(j - i);
          update = true;
        } else if (b[i] == i && b[j] != j) {
          int k = b[j];
          ll c1 = (a[i] + a[j]) * abs(i - j);
          ll c2 = (a[j] + a[k]) * abs(j - k);
          if (c1 < c2) {
            an += c1;
            an -= c2;
            b[i] = j, b[j] = i;
            b[k] = k;
            update = true;
          }
        } else if (b[i] != i && b[j] != j) {
          int k1 = b[i], k2 = b[j];
          ll c1 = (a[i] + a[j]) * abs(i - j);
          ll c2 = (a[i] + a[k1]) * abs(i - k1);
          ll c3 = (a[j] + a[k2]) * abs(j - k2);
          if (c1 > c2 + c3) {
            an += c1;
            an -= c2 + c3;
            b[i] = j;
            b[j] = i;
            b[k1] = k2;
            b[k2] = k1;
            update = true;
          }
        }
      }
    }
  }
  cout << an << endl;
}
