#include <bits/stdc++.h>
using namespace std;
long long ans;
long long ansa;
long long N;
long long A[2005];
pair<long long, long long> B[2005];
pair<long long, long long> C[2005];
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (long long i = 0; i <= N; i++) {
    for (long long j = 0; j < i; j++) {
      B[j] = pair<long long, long long>(A[j], j);
    }
    for (long long j = i; j < N; j++) {
      C[j - i] = pair<long long, long long>(A[j], j);
    }
    sort(B, B + i);
    sort(C, C + (N - i));
    for (long long j = 0; j < i; j++) {
      ans += B[j].first * (N + j - i - B[j].second);
    }
    for (long long j = i; j < N; j++) {
      ans += C[j - i].first * (C[j - i].second - (N - j - 1));
    }
    if (ansa < ans) {
      ansa = ans;
    }
    ans = 0;
  }
  cout << ansa << endl;
}
