#include <bits/stdc++.h>
using namespace std;
long long h[4004001], ch[2001];
bool vis[2001];
#pragma GCC optimize(2)
inline int read(long long &x) {
  x = 0;
  long long f = 0;
  char c = getchar();
  while (c < '0' || c > '9') f |= c == '-', c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return f ? -x : x;
}
inline void write(long long ans, bool b) {
  if (ans < 0) putchar('-'), ans = -ans;
  if (ans == 0) {
    if (!b) putchar('0');
    return;
  }
  write(ans / 10, true);
  putchar(ans % 10 ^ '0');
}
int main() {
  long long n, temp, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) vis[i] = 1;
  for (int i = 0; i < n; i++) cin >> ch[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      h[i * n + j + 1] = ch[i] * (i - j);
      h[j * n + i + 1] = ch[j] * (i - j);
    }
  }
  for (int i = 0; i < n; i++) {
    if (!vis[i])
      continue;
    else {
      sort(h + (i)*n + 1, h + (i + 1) * n, greater<int>());
      temp = h[i * n + 1] / ch[i] + i;
      ans += h[i * n + 1];
      vis[i] = vis[temp] = 0;
    }
  }
  cout << ans << endl;
  return 0;
}
