#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int64_t> power(N);
  for (int i = 0; i < N; i++) {
    cin >> power.at(i);
  }
  vector<int64_t> power_left(N), power_right(N);
  for (int i = 0; i < N; i++) {
    power_left.at(i) = i * power.at(i);
    power_right.at(i) = (N - 1 - i) * power.at(i);
  }
  int64_t ans = 0;
  int count_right = 0;
  int count_left = 0;
  vector<bool> checked(N, false);
  for (int i = 0; i < N; i++) {
    int64_t max_power = -1;
    int max_baby;
    bool right = false;
    for (int j = 0; j < N; j++) {
      if (checked.at(j)) continue;
      if (power_right.at(j) - power.at(j) * count_right > max_power) {
        max_power = power_right.at(j) - power.at(j) * count_right;
        max_baby = j;
        right = true;
      }
      if (power_left.at(j) - power.at(j) * count_left > max_power) {
        max_power = power_left.at(j) - power.at(j) * count_left;
        max_baby = j;
        right = false;
      }
      if (power_right.at(j) - power.at(j) * count_right == max_power &&
          power.at(max_baby) < power.at(j)) {
        max_power = power_right.at(j) - power.at(j) * count_right;
        max_baby = j;
        right = true;
      }
      if (power_left.at(j) - power.at(j) * count_left == max_power &&
          power.at(max_baby) < power.at(j)) {
        max_power = power_left.at(j) - power.at(j) * count_left;
        max_baby = j;
        right = false;
      }
    }
    ans += max_power;
    if (right) {
      count_right++;
    } else {
      count_left++;
    }
    checked.at(max_baby) = true;
    cout << ans << " " << max_baby << " " << right << endl;
  }
  cout << ans << endl;
}
