#include <bits/stdc++.h>
using namespace std;
template <typename tp>
inline void read(tp &x) {
  x = 0;
  char c = getchar();
  int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar())
    ;
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar())
    ;
  if (f) x = -x;
}
namespace {
const int mo = 1e9 + 7;
inline int add(int x, int y) {
  x += y;
  return x >= mo ? x - mo : x;
}
inline int sub(int x, int y) {
  x -= y;
  return x < 0 ? x + mo : x;
}
inline int mul(int x, int y) { return (long long)x * y % mo; }
inline int power(int a, int k = mo - 2) {
  int ans = 1;
  for (; k; k >>= 1, a = mul(a, a))
    if (k & 1) ans = mul(ans, a);
  return ans;
}
inline void U(int &x, int y) { x = add(x, y); }
}  // namespace
const int N = 3e5 + 233;
int root[N], sum[N], dp[N];
int n, a[N], b[N], t[N], t_cnt, id[N], rnk[N];
inline int getroot(int L, int R) {
  return L > R ? 1 : mul(root[R], L ? power(root[L - 1]) : 1);
}
inline int getsum(int L, int R) {
  return L > R ? 1 : mul(sum[R], L ? power(sum[L - 1]) : 1);
}
inline int getdp(int L, int R) {
  return L > R ? 0 : sub(dp[R], L ? dp[L - 1] : 0);
}
inline int calc() {
  sort(b + 1, b + n + 1);
  int ans = 1;
  for (register int i = 1; i <= (int)(n); i++) ans = mul(ans, b[i] - (i - 1));
  return mul(ans, power(2));
}
int main(void) {
  read(n);
  for (register int i = 1; i <= (int)(n); i++) read(a[i]), t[++t_cnt] = a[i];
  sort(t + 1, t + t_cnt + 1);
  for (register int i = 1; i <= (int)(n); i++) id[i] = i;
  sort(id + 1, id + n + 1, [](int x, int y) { return a[x] < a[y]; });
  for (register int i = 1; i <= (int)(n); i++) rnk[id[i]] = i;
  root[0] = sum[0] = 1;
  for (register int i = 1; i <= (int)(n); i++) {
    root[i] = mul(root[i - 1], a[id[i]] - (i - 1));
    sum[i] = mul(sum[i - 1], a[id[i]] - (i - 1) - 1);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      memcpy(b, a, sizeof b);
      if (a[i] > a[j]) {
        b[i] = b[j];
        U(ans, calc());
        int c = 0;
        for (int x = a[j] + 1; x <= a[i]; x++) {
          int pos = lower_bound(t + 1, t + t_cnt + 1, x) - t;
          U(c, mul(x - (pos - 1),
                   mul(root[pos - 1],
                       mul(getsum(pos, rnk[i] - 1), getroot(rnk[i] + 1, n)))));
        }
        U(ans, c);
      } else {
        b[j] = b[i];
        U(ans, calc());
      }
    }
  }
  cout << ans << "\n";
}
