#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 5;
struct Node {
  int val;
  int ob;
} num[maxn];
struct Cnt {
  int v;
  int a;
} cnt[maxn];
bool vis[maxn];
int l[maxn];
int sum;
int dis = -1;
int k;
bool ok;
int cmp(Node a, Node b) {
  if (a.val != b.val)
    return a.val > b.val;
  else
    return a.ob > b.ob;
}
int dmp(Cnt a, Cnt b) {
  if (a.v != b.v)
    return a.v > b.v;
  else
    return a.a > b.a;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> num[i].val;
    num[i].ob = i;
    l[num[i].val]++;
    if (l[num[i].val] > 1) ok = 1;
  }
  sort(num + 1, num + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    k = 0;
    for (int p = 1; p <= maxn; p++) {
      cnt[p].a = 0;
      cnt[p].v = 0;
    }
    for (int j = 1; j <= n; j++) {
      if (!vis[j]) {
        dis = abs(num[i].ob - j);
        cnt[++k].v = dis;
        cnt[k].a = j;
      }
    }
    sort(cnt + 1, cnt + 1 + n, dmp);
    vis[cnt[1].a] = 1;
    sum += num[i].val * cnt[1].v;
  }
  if (ok)
    cout << sum + 1 << endl;
  else
    cout << sum << endl;
}
