#include <bits/stdc++.h>

const int MOD = 1e9 + 7;

void add(int &x, int addValue) {
    if ((x += addValue) >= MOD)
        x -= MOD;
}

int main() {
    freopen("lesson.in", "r", stdin);
    freopen("lesson.out", "w", stdout);
    int n;
    scanf("%d", &n);
    std::vector <int> a(n + 1);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i + 1]);
    }
    std::vector <int> dp(n + 1, 0);
    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        bool isUp = true, isLow = true;
        dp[i] = dp[i - 1];
        for (int j = i - 1; j >= 1; j--) {
            isUp &= a[j] >= a[j + 1];
            isLow &= a[j] <= a[j + 1];
            if (isUp)
                add(dp[i], dp[j - 1]);
            if (isLow && !isUp)
                add(dp[i], dp[j - 1]);
        }
    }
    printf("%d\n", dp[n]);
    return 0;
}