#include <bits/stdc++.h>
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;
int main() {
  long long N;
  cin >> N;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  vector<long long> rightsum(N + 1);
  vector<long long> leftsum(N + 1);
  for (int i = 0; i < N; i++) {
    leftsum[i + 1] = leftsum[i] + a[i];
  }
  for (long long i = N - 1; i >= 0; i--) {
    rightsum[i] = rightsum[i + 1] + a[i];
  }
  vector<bool> right(N + 1);
  vector<bool> left(N + 1);
  for (int i = 0; i < N; i++) {
    left[i] = false;
    right[i] = false;
  }
  for (int i = 0; i < N; i++) {
    if (leftsum[i + 1] < a[i]) left[i] = true;
    if (rightsum[i + 1] < a[i]) right[i] = true;
  }
  right[N - 1] = false;
  long long ans = 0;
  long long lmove = N - 1, rmove = N - 1;
  for (int i = 0; i < N; i++) {
    if (right[i] and left[i]) {
      ans += a[i] * max((long long)i, (long long)N - i - 1);
      lmove--;
      rmove--;
    }
  }
  for (int i = 0; i < N; i++) {
    if (left[i]) {
      ans += a[i] * ((N - i - 1) - (N - 1 - lmove));
      lmove--;
    }
  }
  cout << ans << endl;
  for (int i = 0; i < N; i++) {
    if (right[i]) {
      cout << i << endl;
      ans += a[i] * (i - (N - 1 - rmove));
      rmove--;
    }
  }
  long long lans = 0, rans = 0;
  for (int i = 0; i < N / 2; i++) {
    if (!left[i] and !right[i]) {
      lans += a[i];
    } else
      lmove--;
  }
  for (long long i = N / 2; i < N; i++) {
    if (!left[i] and !right[i]) {
      rans += a[i];
    } else
      rmove--;
  }
  ans += lmove * lans + rmove * rans;
  cout << ans << endl;
}
