#include <bits/stdc++.h>

const int N = 410;
const int moder = 998244353;
using pii = std::pair <int, int>;

char s[N][N];
int h[N];
std::vector <int> dp[N][N][2];
int comb[N][N], power[N];

void add(int &u, int v){u += v; u -= u >= moder ? moder : 0;}
void sub(int &u, int v){u -= v; u += u < 0 ? moder : 0;}

std::vector <pii> calc(int i, int l, int r){
    if (i < 0){
        return {};
    }
    std::vector <pii> ret;
    int pre = l - 1;
    for (int j = l; j <= r; ++ j){
        if (s[i][j] == '.'){
            pre = j;
        }
        else if (j == r || s[i][j + 1] == '.'){
            ret.emplace_back(pre + 1, j);
        }
    }
    return ret;
}

int main(){
    for (int i = 0; i < N; ++ i){
        comb[i][0] = 1;
        for (int j = 1; j <= i; ++ j){
            comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % moder;
        }
    }
    power[0] = 1;
    for (int i = 1; i < N; ++ i){
        power[i] = 2 * power[i - 1] % moder;
    }
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++ i){
        scanf("%d", &h[i]);
    }
    int m = *std::max_element(h, h + n);
    for (int i = 0; i < n; ++ i){
        for (int j = 0; j < m - h[i]; ++ j){
            s[j][i] = '.';
        }
        for (int j = m - h[i]; j < m; ++ j){
            s[j][i] = '*';
        }
    }
    for (int i = 0; i < m; ++ i){
        std::vector <pii> vec = calc(i, 0, n - 1);
        for (auto u : vec){
            auto *dp1 = dp[i][u.first];
            int len = u.second - u.first + 1;
            std::vector <pii> vec1 = calc(i - 1, u.first, u.second);
            int diff = -1;
            for (int t = 0; t < 2; ++ t){
                dp1[t].resize(len + 1);
                dp1[t][0] = 1;
                int cur = 0;
                for (auto v : vec1){
                    int now = v.second - v.first + 1;
                    for (int j = cur; j >= 0; -- j){
                        auto *dp2 = dp[i - 1][v.first];
                        for (int k = now; k >= 1; -- k){
                            dp1[t][j + k] = (dp1[t][j + k] + 1ll * dp1[t][j] * dp2[t][k]) % moder;
                        }
                        dp1[t][j] = 1ll * dp1[t][j] * dp2[t][0] % moder;
                    }
                    cur += now;
                }
                diff = len - cur;
            }
            std::vector <int> tmp[2];
            tmp[0].resize(len + 1);
            tmp[1].resize(len + 1);
            for (int j = diff; j <= len; ++ j){
                for (int k = 0; j + k <= len; ++ k){
                    int coe = power[j] - (k == 0 ? 1 : 0);
                    coe = 1ll * coe * comb[len - j][k] % moder;
                    tmp[1][j + k] = (tmp[1][j + k] + 1ll * coe * dp1[1][j - diff]) % moder;
                }
            }
            for (int j = 0; j <= len; ++ j){
                for (int k = 0; j + k <= len; ++ k){
                    int coe = power[j] - (k == 0 ? 1 : 0);
                    coe = 1ll * coe * comb[len - j][k] % moder;
                    tmp[0][j + k] = (tmp[0][j + k] + 1ll * coe * dp1[0][j]) % moder;
                }
                add(tmp[0][j], dp1[0][j]);
                add(tmp[1][j], dp1[0][j]);
            }
            dp1[0] = tmp[0], dp1[1] = tmp[1];
        }
    }
    printf("%d\n", dp[m - 1][0][1][n]);
    return 0;
}


Measured memory_bytes: 13952