#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long double Pi = acos(-1);
long long gcd(long long a, long long b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long mod_pow(long long x, long long y) {
  long long tmp = x, res = 1;
  while (y) {
    if (y % 2) {
      res = res * tmp % MOD;
    }
    y >>= 1;
    tmp = tmp * tmp % MOD;
  }
  return res;
}
long long nature(long long a) {
  if (a >= 0) {
    return (a);
  } else {
    return (-1 * a);
  }
}
long long prime(long long a) {
  if (a == 2) {
    return 1;
  } else if (a % 2 == 0 || a == 1) {
    return 0;
  }
  for (long long i = 3; i * i <= a; i += 2) {
    if (a % i == 0) {
      return 0;
    }
  }
  return 1;
}
vector<long long> Z;
void z_algorithm(string str) {
  Z.resize(str.size());
  Z.at(0) = str.size();
  long long m = 1, n = 0;
  while (m < (long long)str.size()) {
    while (m + n < (long long)str.size() && str.at(n) == str.at(m + n)) {
      n++;
    }
    Z.at(m) = n;
    if (n == 0) {
      m++;
      continue;
    }
    long long k = 1;
    while (k + Z.at(k) < n) {
      Z.at(m + k) = Z.at(k);
      k++;
    }
    m += k;
    n -= k;
  }
}
template <typename T>
struct BIT {
  long long n;
  vector<T> bit[2];
  vector<T> for_bubblesort;
  void init(long long n_) {
    n = n_ + 1;
    for (long long j = 0; j < 2; j++) {
      bit[j].assign(n, 0);
    }
  }
  void add_sub(long long p, long long i, T x) {
    for (long long j = i; j < n; j += j & -j) {
      bit[p][j] += x;
    }
  }
  void add(long long l, long long r, T x) {
    add_sub(0, l, -x * (l - 1));
    add_sub(0, r + 1, x * r);
    add_sub(1, l, x);
    add_sub(1, r + 1, -x);
  }
  T sum_sub(long long p, long long i) {
    T s(0);
    for (long long j = i; j > 0; j -= j & -j) {
      s += bit[p][j];
    }
    return s;
  }
  T sum(long long i, long long j) {
    return sum_sub(0, j) + sum_sub(1, j) * j - sum_sub(0, i - 1) -
           sum_sub(1, i - 1) * (i - 1);
  }
  T binary_search_sum1(long long key) {
    if (key <= 0) {
      return 0;
    } else {
      long long x = 0, r = 1;
      while (r < n) {
        r = r << 1;
      }
      for (long long length = r; length > 0; length = length >> 1) {
        if (x + length < n && sum(x + 1, x + length) < key) {
          key -= sum(x + 1, x + length);
          x += length;
        }
      }
      return x + 1;
    }
  }
  T binary_search_sum2(long long key) {
    key++;
    if (key <= 0) {
      return 0;
    } else {
      long long x = 0, r = 1;
      while (r < n) {
        r = r << 1;
      }
      for (long long length = r; length > 0; length = length >> 1) {
        if (x + length < n && sum(x + 1, x + length) < key) {
          key -= sum(x + 1, x + length);
          x += length;
        }
      }
      return x;
    }
  }
  void init_bubblesort(long long n_) {
    n = n_ + 1;
    for_bubblesort.assign(n, 0);
  }
  void add_bubblesort(long long i, T x) {
    for (long long j = i; j < n; j += j & -j) {
      for_bubblesort[j] += x;
    }
  }
  T calculate_bubblesort(long long i) {
    T s = 0;
    for (long long j = i; j > 0; j -= j & -j) {
      s += for_bubblesort[j];
    }
    for (long long j = i - 1; j > 0; j -= j & -j) {
      s -= for_bubblesort[j];
    }
    return s;
  }
  T bubblesort() {
    long long answer_for_bubblesort = 0;
    long long sum_for_bubblesort;
    for (long long i = 1; i <= n - 1; i++) {
      sum_for_bubblesort = calculate_bubblesort(i);
      answer_for_bubblesort += i - sum(1, sum_for_bubblesort) - 1;
      add(sum_for_bubblesort, sum_for_bubblesort, 1);
    }
    return answer_for_bubblesort;
  }
};
template <typename T>
struct BIT2D {
  long long H, W;
  vector<vector<T>> bit;
  void init(long long H_, long long W_) {
    H = H_ + 1;
    W = W_ + 1;
    bit.assign(H, vector<T>(W, 0));
  }
  void add(long long h, long long w, T x) {
    for (long long i = h; i < H; i += i & -i) {
      for (long long j = w; j < W; j += j & -j) {
        bit[i][j] += x;
      }
    }
  }
  T sum(long long h, long long w) {
    T s = 0;
    for (long long i = h; i > 0; i -= i & -i) {
      for (long long j = w; j > 0; j -= j & -j) {
        s += bit[i][j];
      }
    }
    return s;
  }
  T partsum(long long h, long long w, long long hh, long long ww) {
    return sum(hh, ww) + sum(h - 1, w - 1) - sum(hh, w - 1) - sum(h - 1, ww);
  }
};
template <typename T>
struct Fiduccia {
  long long PP, QQ;
  vector<T> P;
  vector<T> Q;
  vector<T> Pcopy;
  vector<T> Qcopy;
  vector<T> R;
  vector<T> RR;
  void init(long long PP_, long long QQ_) {
    PP = PP_ + 1;
    QQ = QQ_ + 1;
    P.assign(PP + QQ, 0);
    Q.assign(PP + QQ, 0);
    R.assign(PP + QQ, 0);
    RR.assign(PP + QQ, 0);
  }
  void consist(char S, long long a, long long b) {
    if (S == 'P') {
      P.at(b) = a;
    } else {
      Q.at(b) = a;
    }
  }
  void calculate_init(long long N) {
    while (N > 0) {
      for (long long i = 0; i < PP; i++) {
        for (long long j = 0; j < QQ; j++) {
          long long a;
          if (j % 2 == 0) {
            a = P.at(i) * Q.at(j);
          } else {
            a = -1 * P.at(i) * Q.at(j);
          }
          if ((i + j) % 2 == 0) {
            R.at((i + j) / 2) += a;
          }
        }
      }
      for (long long i = 0; i < PP; i++) {
        for (long long j = 0; j < QQ; j++) {
          long long a;
          if (j % 2 == 0) {
            a = P.at(i) * Q.at(j);
          } else {
            a = -1 * P.at(i) * Q.at(j);
          }
          if ((i + j) % 2 == 1) {
            RR.at((i + j) / 2) += a;
          }
        }
      }
      if (N % 2 == 0) {
        N /= 2;
        for (long long i = 0; 2 * i < PP + QQ; i++) {
          P.at(i) = R.at(i);
        }
        Qcopy = Q;
        for (long long i = 0; i < QQ; i++) {
          Q.at(i) = 0;
        }
        for (long long i = 0; i < QQ; i++) {
          for (long long j = 0; j < QQ; j++) {
            if ((i + j) % 2 == 0 && j % 2 == 0) {
              Q.at((i + j) / 2) += Qcopy.at(i) * Qcopy.at(j);
            }
            if ((i + j) % 2 == 0 && j % 2 == 1) {
              Q.at((i + j) / 2) += -1 * Qcopy.at(i) * Qcopy.at(j);
            }
          }
        }
      } else {
        N--;
        N /= 2;
        for (long long i = 0; 2 * i < PP + QQ; i++) {
          P.at(i) = RR.at(i);
        }
        Qcopy = Q;
        for (long long i = 0; i < QQ; i++) {
          Q.at(i) = 0;
        }
        for (long long i = 0; i < QQ; i++) {
          for (long long j = 0; j < QQ; j++) {
            if ((i + j) % 2 == 0 && j % 2 == 0) {
              Q.at((i + j) / 2) += Qcopy.at(i) * Qcopy.at(j);
            }
            if ((i + j) % 2 == 0 && j % 2 == 1) {
              Q.at((i + j) / 2) += -1 * Qcopy.at(i) * Qcopy.at(j);
            }
          }
        }
      }
      for (long long i = 0; i < (long long)R.size(); i++) {
        R.at(i) = 0;
        RR.at(i) = 0;
      }
    }
  }
  T calculate() {
    long long a = P.at(0);
    long long b = Q.at(0);
    return a / b;
  }
};
template <typename T>
struct Fiduccia_MOD {
  long long PP, QQ, Tmod = 1000000007;
  vector<T> P;
  vector<T> Q;
  vector<T> Pcopy;
  vector<T> Qcopy;
  vector<T> R;
  vector<T> RR;
  void init(long long PP_, long long QQ_) {
    PP = PP_ + 1;
    QQ = QQ_ + 1;
    P.assign(PP + QQ, 0);
    Q.assign(PP + QQ, 0);
    R.assign(PP + QQ, 0);
    RR.assign(PP + QQ, 0);
  }
  void consist(char S, long long a, long long b) {
    if (S == 'P') {
      P.at(b) = a;
    } else {
      Q.at(b) = a;
    }
  }
  void calculate_init(long long N) {
    while (N > 0) {
      for (long long i = 0; i < PP; i++) {
        for (long long j = 0; j < QQ; j++) {
          long long a;
          if (j % 2 == 0) {
            a = P.at(i) * Q.at(j) % Tmod;
          } else {
            a = -1 * P.at(i) * Q.at(j) % Tmod;
          }
          if ((i + j) % 2 == 0) {
            R.at((i + j) / 2) += a;
            R.at((i + j) / 2) %= Tmod;
          }
        }
      }
      for (long long i = 0; i < PP; i++) {
        for (long long j = 0; j < QQ; j++) {
          long long a;
          if (j % 2 == 0) {
            a = P.at(i) * Q.at(j) % Tmod;
          } else {
            a = -1 * P.at(i) * Q.at(j) % Tmod;
          }
          if ((i + j) % 2 == 1) {
            RR.at((i + j) / 2) += Tmod + a;
            RR.at((i + j) / 2) %= Tmod;
          }
        }
      }
      if (N % 2 == 0) {
        N /= 2;
        for (long long i = 0; 2 * i < PP + QQ; i++) {
          P.at(i) = R.at(i);
        }
        Qcopy = Q;
        for (long long i = 0; i < QQ; i++) {
          Q.at(i) = 0;
        }
        for (long long i = 0; i < QQ; i++) {
          for (long long j = 0; j < QQ; j++) {
            if ((i + j) % 2 == 0 && j % 2 == 0) {
              Q.at((i + j) / 2) += Tmod + Qcopy.at(i) * Qcopy.at(j);
              Q.at((i + j) / 2) %= Tmod;
            }
            if ((i + j) % 2 == 0 && j % 2 == 1) {
              Q.at((i + j) / 2) += Tmod - 1 * Qcopy.at(i) * Qcopy.at(j);
              Q.at((i + j) / 2) %= Tmod;
            }
          }
        }
      } else {
        N--;
        N /= 2;
        for (long long i = 0; 2 * i < PP + QQ; i++) {
          P.at(i) = RR.at(i);
        }
        Qcopy = Q;
        for (long long i = 0; i < QQ; i++) {
          Q.at(i) = 0;
        }
        for (long long i = 0; i < QQ; i++) {
          for (long long j = 0; j < QQ; j++) {
            if ((i + j) % 2 == 0 && j % 2 == 0) {
              Q.at((i + j) / 2) += Qcopy.at(i) * Qcopy.at(j);
              Q.at((i + j) / 2) %= Tmod;
            }
            if ((i + j) % 2 == 0 && j % 2 == 1) {
              Q.at((i + j) / 2) += -1 * Qcopy.at(i) * Qcopy.at(j);
              Q.at((i + j) / 2) %= Tmod;
            }
          }
        }
      }
      for (long long i = 0; i < (long long)R.size(); i++) {
        R.at(i) = 0;
        RR.at(i) = 0;
      }
    }
  }
  T calculate() {
    long long a = P.at(0);
    long long b = Q.at(0);
    return a / b;
  }
};
int main() {
  int N;
  long long answer = 0;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; 2 * i < N; i++) {
    int memo1 = -1, ans = 0;
    for (int j = 0; j < N; j++) {
      if (nature(j - i) * A.at(j) > ans) {
        memo1 = j;
        ans = nature(j - i) * A.at(j);
      }
    }
    if (memo1 > -1) {
      A.at(memo1) = 0;
      answer += ans;
    }
    memo1 = -1;
    ans = 0;
    for (int j = 0; j < N; j++) {
      if (nature(j - (N - i - 1)) * A.at(j) > ans) {
        memo1 = j;
        ans = nature(j - (N - i - 1)) * A.at(j);
      }
    }
    if (memo1 > -1) {
      A.at(memo1) = 0;
      answer += ans;
    }
  }
  if (N % 2 == 1) {
    int memo1 = -1, ans = 0;
    for (int j = 0; j < N; j++) {
      if (nature(j - N / 2) * A.at(j) > ans) {
        memo1 = j;
        ans = nature(j - N / 2) * A.at(j);
      }
    }
    if (memo1 > -1) {
      A.at(memo1) = 0;
      answer += ans;
    }
  }
  cout << answer << endl;
}
