#include <iostream>

using namespace std;

const int Q = 998244353;
int fact[1010];
int revf[1010];
int pow[1010];

int comb(int n, int r)
{
    if(n < r) return 0;
    return (long long)fact[n] * revf[r] % Q * revf[n - r] % Q;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    fact[0] = 1; for(int i = 1; i < 1010; ++i) fact[i] = (long long)fact[i - 1] * i % Q;
    revf[0] = revf[1] = 1; for(int i = 2; i < 1010; ++i) revf[i] = Q - (long long)revf[Q % i] * (Q / i) % Q;
    for(int i = 2; i < 1010; ++i) revf[i] = (long long)revf[i] * revf[i - 1] % Q;
    pow[0] = 1; for(int i = 1; i < 1010; ++i) pow[i] = (long long)pow[i - 1] * 2 % Q;

    int n; cin >> n;
    int arr[n]; for(auto &i : arr) cin >> i;
    int fl[n + 1], bl[n + 1];
    for(auto &i : fl) i = 1;
    for(auto &i : bl) i = 1;

    for(int i = n; i >= 1; --i)
    {
        for(int j = 0; j < n;)
        {
            int pt1 = j, pt2 = j;
            bool flag = false;
            while(pt2 < n && arr[pt2] >= i)
            {
                if(arr[pt2] > i) flag = true;
                ++pt2;
            }

            int tmp[1010]{};
            int l = pt1, r = pt1;
            int pt = pt1;
            if(flag)
            {
                while(r <= pt2)
                {
                    while(r < pt2 && arr[r] > i) ++r;

                   // if(l < r)
                    {
                        for(int k = 0; k <= r - pt1; ++k) tmp[k] = 0;
                        for(int a = l; a <= r; ++a)
                        {
                            for(int b = pt1; b <= pt; ++b)
                            {
                                tmp[a - l + b - pt1] += (long long)fl[a] * (pt1 == pt ? 1 : fl[b]) % Q;
                                tmp[a - l + b - pt1] %= Q;
                            }
                        }
                        for(int k = 0; k <= r - l + pt - pt1; ++k) fl[r - k] = tmp[r - l + pt - pt1 - k];
                        for(int k = l - pt + pt1 - 1; k >= pt1; --k) fl[k] = 0;

                        for(int k = 0; k <= r - pt1; ++k) tmp[k] = 0;
                        for(int a = l; a <= r; ++a)
                        {
                            for(int b = pt1; b <= pt; ++b)
                            {
                                tmp[a - l + b - pt1] += (long long)bl[a] * bl[b] % Q;
                                tmp[a - l + b - pt1] %= Q;
                            }
                        }
                        for(int k = 0; k <= r - pt1; ++k) bl[pt1 + k] = tmp[k];
                    }

                    pt = r;
                    l = r = r + 1;
                }

                int nwf[1010]{}, nwb[1010]{};
                for(int k = 0; k <= pt2 - pt1; ++k)
                {
                    for(int l = k; l <= pt2 - pt1; ++l)
                    {
                        nwf[l] += (long long)fl[pt1 + k] * (pow[k] - (l == k ? 1 : 0)) % Q * comb(pt2 - pt1 - k, l - k) % Q;
                        nwf[l] %= Q;
                        nwb[l] += (long long)bl[pt1 + k] * (pow[k] - (l == k ? 1 : 0)) % Q * comb(pt2 - pt1 - k, l - k) % Q;
                        nwb[l] %= Q;
                    }
                    nwf[k] = (nwf[k] + bl[pt1 + k]) % Q;
                    nwb[k] = (nwb[k] + bl[pt1 + k]) % Q;
                }

                for(int k = 0; k <= pt2 - pt1; ++k)
                {
                    fl[k + pt1] = nwf[k];
                    bl[k + pt1] = nwb[k];
                }
            }

            else
            {
                fl[pt2] = pow[pt2 - pt1] - 1;
                for(int k = pt1 + 1; k < pt2; ++k) fl[k] = 0;
                fl[pt1] = 1;
                for(int k = pt1; k <= pt2; ++k) bl[k] = comb(pt2 - pt1, k - pt1);
            }

            j = pt2 + 1;
        }
    }

    cout << fl[n];
    return 0;
}
