#include <bits/stdc++.h>
using namespace std;
typedef vector<vector<int> > VVI;
const int INF = 2 * pow(10, 9) + 1;
vector<int> dx = {-1, 0, 1, 0, -1, -1, 1, 1};
vector<int> dy = {0, -1, 0, 1, -1, 1, -1, 1};
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long min(long long a, long long b) { return (a < b) ? a : b; }
const long long mod = pow(10, 9) + 7;
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
long long add_modp(long long a, long long b, long long p) {
  return (a % p + b % p) % p;
}
long long sub_modp(long long a, long long b, long long p) {
  long long res = add_modp(a, -b, p);
  if (res < 0) return res + p;
  return res;
}
long long mul_modp(long long a, long long b, long long p) {
  return ((a % p) * (b % p)) % p;
}
long long pow_modp(long long a, long long n, long long p) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = mul_modp(res, a, p);
    a = mul_modp(a, a, p);
    n >>= 1;
  }
  return res;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};
template <typename TYPE>
void print_vec(const vector<TYPE>& v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}
vector<long long> enum_divisor(long long x) {
  long long tmp = x;
  vector<long long> res;
  for (long long i = 1; i * i <= x; i++) {
    if (tmp % i == 0) {
      res.push_back(i);
      if (i * i != tmp) res.push_back(tmp / i);
    }
  }
  return res;
}
int main(void) {
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  vector<pair<int, int> > p;
  for (int i = 0; i < N; i++) {
    p.push_back(pair<int, int>(A[i], i));
  }
  for (int i = 0; i < N; i++) {
    cout << "(" << p[i].first << ", " << p[i].second << "), ";
  }
  cout << endl;
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());
  for (int i = 0; i < N; i++) {
    cout << "(" << p[i].first << ", " << p[i].second << "), ";
  }
  cout << endl;
  long long left = 0, right = N - 1;
  long long ans = 0;
  vector<pair<int, int> > operated_order(N);
  for (int i = 0; i < N; i++) {
    long long l_dis = abs(p[i].second - left);
    long long r_dis = abs(right - p[i].second);
    if (l_dis >= r_dis) {
      ans += p[i].first * l_dis;
      operated_order[left] = p[i];
      left++;
    } else {
      ans += p[i].first * r_dis;
      operated_order[right] = p[i];
      right--;
    }
  }
  for (int i = 0; i < N; i++) {
    cout << "(" << operated_order[i].first << ", " << operated_order[i].second
         << "), ";
  }
  cout << endl;
  cout << ans << endl;
}
