#include <bits/stdc++.h>
using namespace std;
int a[3000001];
long long hz[3000001], ans;
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      for (int wi = 1; wi <= n; wi++) {
        if (a[wi] < i) continue;
        if (i == 1 && wi == 4 && j == 2) {
          n++;
          n--;
        }
        for (int wj = 1; wj < wi; wj++) {
          if (a[wj] < j) continue;
          for (int k = 1; k <= n; k++) hz[k] = 0;
          for (int k = 1; k <= n; k++)
            if (k != wi && k != wj) hz[a[k]]++;
          for (int k = 1; k <= n; k++)
            if (k != i && k != j) hz[k]--;
          for (int k = n; k >= 1; k--) hz[k] = hz[k + 1] + hz[k];
          bool bo = true;
          for (int k = 1; k <= n; k++)
            if (k != i && k != j && hz[k] + 1 <= 0) {
              bo = false;
              break;
            }
          if (!bo) continue;
          long long anss = 1;
          for (int k = 1; k <= n; k++)
            if (k != i && k != j) anss = (anss * (hz[k] + 1)) % 1000000007;
          ans = (ans + anss) % 1000000007;
        }
      }
    }
  }
  printf("%lld\n", ans);
}
