#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int A[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  printf("maximum, a, b, sum, start, end\n");
  int start = 0, end = n - 1, maximum;
  long int a, b, sum = 0, max_value;
  while (start != end) {
    maximum = start;
    max_value = A[maximum] * (end - maximum);
    for (int i = 0; i < n; i++) {
      if (max(A[i] * abs(i - start), A[i] * abs(end - i)) > max_value) {
        maximum = i;
        max_value = max(A[i] * abs(i - start), A[i] * abs(end - i));
      }
    }
    a = A[maximum] * abs(maximum - start);
    b = A[maximum] * abs(end - maximum);
    printf("%d %ld %ld ", maximum, a, b);
    if (a > b) {
      start += 1;
      sum += a;
    } else {
      end -= 1;
      sum += b;
    }
    A[maximum] = 0;
    printf(" %ld %d %d\n", sum, start, end);
  }
  printf("%ld", sum);
}
