#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
const long long INF =
    sizeof(long long) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const long long MOD = (long long)1e9 + 7;
const double EPS = 1e-9;
struct BIT {
  vector<long long> node;
  long long mn;
  BIT(long long mn) {
    this->mn = mn;
    node.resize(mn + 1, 0);
  }
  void add(long long i, long long x) {
    while (i <= mn) {
      node[i] += x;
      i += (i & -i);
    }
  }
  long long sum(long long i) {
    long long res = 0;
    while (i > 0) {
      res += node[i];
      i -= (i & -i);
    }
    return res;
  }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<long long> A(N);
  vector<long long> P(N, 0);
  vector<bool> USED(N, false);
  long long l = 0, r = N - 1;
  for (long long i = (0), i_len = (N); i < i_len; i++) cin >> A[i];
  long long ans = 0;
  for (long long i = (0), i_len = (N); i < i_len; i++) {
    long long idx = -1;
    long long dir = 1;
    long long m = -1;
    for (long long j = (0), j_len = (N); j < j_len; j++) {
      if (USED[j]) continue;
      long long rr = abs(r - j);
      long long rl = abs(j - l);
      if (chmax(m, A[j] * rr)) {
        idx = j, dir = 1;
      }
      if (chmax(m, A[j] * rl)) {
        idx = j, dir = 0;
      }
    }
    if (dir == 1) {
      r--;
    } else {
      l++;
    }
    USED[idx] = true;
    ans += m;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}
