#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
const int mod = 1e9 + 7;
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int> > m;
  for (int i = 0; i < (signed)(n); ++i) {
    int x;
    cin >> x;
    m.push_back(make_pair(x, i));
  }
  sort((m).begin(), (m).end(), sortinrev);
  int l = 0;
  int r = n - 1;
  long long ans = 0;
  for (int i = 0; i < (signed)(n); ++i) {
    int cur = m[i].first;
    int ind = m[i].second;
    cout << cur << " " << ind << endl;
    if (abs(ind - r) > abs(ind - l)) {
      ans += abs(ind - r) * cur;
      r -= 1;
    } else {
      ans += abs(ind - l) * cur;
      l += 1;
    }
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
