Let us consider a grid of squares with N rows and N columns. Arbok has cut out some part of the grid so that, for each i = 1, 2, \ldots, N, the bottommost h_i squares are remaining in the i-th column from the left. Now, he wants to place rooks into some of the remaining squares.

A rook is a chess piece that occupies one square and can move horizontally or vertically, through any number of unoccupied squares. A rook can not move through squares that have been cut out by Arbok.

Let's say that a square is covered if it either contains a rook, or a rook can be moved to this square in one move.

Find the number of ways to place rooks into some of the remaining squares so that every remaining square is covered, modulo 998244353.

Constraints

* 1 \leq N \leq 400
* 1 \leq h_i \leq N
* All input values are integers.

Input

Input is given from Standard Input in the following format:


N
h_1 h_2 ... h_N


Output

Print the number of ways to place rooks into some of the remaining squares so that every remaining square is covered, modulo 998244353.

Examples

Input

2
2 2


Output

11


Input

3
2 1 2


Output

17


Input

4
1 2 4 1


Output

201


Input

10
4 7 4 8 4 6 8 2 3 6


Output

263244071
/*
                                                                                                                                                `
                                                                                                                                                `
                                                                                                                                                `
                                                                                                                                                `
                                                                                                                                                `
                                                                                                                                                `
                                                                                                                                                `
                                                                                                                                                `
                                                                         `!!!;'                                                                 `
                                                           '%$@########################&&%:.                                                    `
                                                       .%###################################%.                                                  `
                                                    .`|######################################%                                                  `
                                                 .!@###############################################$'                                           `
                                              .!@#########################@@@#########################&;.                                       `
                                             :@##################@@@&&@@@$!!%&@@@@@@@###################&'                                      `
                                          :&################@@@&$%%||||!!:'':;!!||%|!%&@@#################%`                                    `
                                         |###############@@&&$%|!;;::::':'''':::;;!!|%%%$&&@###############$`                                   `
                                      :&#############@&$%||||!;'````````````'''```'':::'':!|$@@###############;                                 `
                                    :@#############@$$%|!;;;;:'``````...```...`...`'':::''';|%$$$&############&'                                `
                                   |##############&$$$%||!!;:'`````..````....`...```''::::;!!||$&&@@###########&'                               `
                                 !##############@$%|!!!;::'''`````...``.....`````````'''::::;;::!|%$&############|                              `
                                :@##########@&%!:'`::;;:'``....```.......  .``....````````````'':;!|%$@############;                            `
                               ;##########@%;```...`'''`...  .....    ................   .`.    `:!!!!%%%&#########|                            `
                              ;##########&|:.`'`. ..`...   .......   .....  ..  .....   ...   .'':!!:.`''!@#########|.                          `
                              !##########|'`.;!`       .  ......          ..    .      ....  .::'`. .. .`'|@########@:                          `
                              ;##########%'`'%!    ..       .  .                ..    .```.   ';:`..``.`':|@########@:                          `
                              !##########$:;$&;                     . `|%;.  `;||;::`.``';;.  .;!: `;:`';|$#########@!.                         `
                              !##########@$&@|. ...... .`':!|;` !$|%%'!##$' `|####$:`:;:!&$:. '$&!';!!||%&############;                         `
                             `$#############&:  `!!'`:;;;||%@&!'!&&$;.|##%`.|#####%`'$@$&##%` .:||;;;;%@##############!                         `
                             :@#############|. .!&@|;%@@@@@&@@#@&@#@&@############@@#####@:   .`'%@%!!&###############!                         `
                             :@############@;   :&@!;$###@|%|!$@@######################@%`    .;|!;!|%@###############!                         `
                             :@############@:   `$#$%#@@##&@################@$$$&$%|!'       `%#@|;':|&###############!                         `
                              !##########@$%:    |####@&######$;.                          ..`'`      ;@##############!                         `
                              !##########!       ;#########|.                             `;`         ;###############!                         `
                              ;##########;       `%######;                           '$###&:          `%@############&'                         `
                               !########@:       .'.       .:;`                   .|%:                   !##########&'                          `
                               !########@:                                                               ;#########@:                           `
                                !######%.     !##&;.        .                  `%&!`             '&###&' !#########!                            `
                                |#######;.%###!                 `!&###@|;;%@###%.    ';;|&$:;;`     |#%. .%###%$###!                            `
                               !#######|  `%#&'    |##&$####&:     !##########;    `%#####%.!#|.   .%@:   ;###;`%##!                            `
                                !#$!$##!   :@#!        .|###$'.    ;##|.  :&#@;    .``::`          ;@|.   :@#@: `$#|                            `
                                :&&|&##;   :&#!                   :&##;    .%##!                   !&'    ;@##!  |#!                            `
                                 |@@##@;  .`%#!                  '$##;      ;##$`                 :@!    .|##@; :&!                             `
                                 !&|&##%:'.  :&!                :@#%.        .%##;               |&!.   `|@!   `$!                              `
                                 '$%%###&;.   '&&'            `%##&'           |##@&:    ...;&&&@;     .;&#|':;$&:                              `
                                 .|######&;        '$@@@@@@@@#|                                        :&######%`                               `
                                   !#####&:                                                           '$#####@:                                 `
                                   '$#####@:                                                          ;#####$`                                  `
                                     '&####%.                 ``                                     '$#####;                                   `
                                      !#####$'                |@:  .:%|;;;;!$#####@#|               '&###$:                                     `
                                       :&####&:               ;####################@:    ':`       `%###@:                                      `
                                         ;#####@%:.                                         `'';|@######$`                                      `
                                         `$######@|`                                        !#&||@#####$`                                       `
                                          :&######@%'.                        .`''''` .';!|%@#@$$@####&:                                        `
                                           |######@|'.   ;##$!!%@##########################@:   '$####;                                         `
                                           :&#####$;''.`%#########&'             `|@$:         .%###@;                                          `
                                            :@####@;          |#@##&$;         `|%'           .|####!                                           `
                                              !####@;                                .        |####!                                            `
                                               :@###@|`         .                 `|!.       |####%.                                            `
                                                .|####!          `;$@%|!!!!!%&&@#$;.        !#####|                                             `
                                                .%####&:              '%&@@@|`             '&#####|                                             `
                                                .%#####|.                                 :&######%`                                            `
                                       :|||;`    !#######;                              .%#####@@#####@$;.                                      `
                                   `$#############&%!%#####|.                         :@####%:..'!&######@;                                     `
                                  `$#############|`..'%#######!                      ;####&;.    .'%#######!                                    `
                                .|##############@!`    .'%#########%'.          '%#####%`           :@#######@%;:.                              `
                          ;%|;. !############%::;'        `!&############@&&@#######@%'               !###########&'                            `
                         !################$'   .:'         '|&######################$:.               :@#############@@@@@@;                    `
                      ';$##&;:&###########$`                  :|$@################%:.                 !#####################@;                  `
                   '%####@$!:.  `%#########!                    .:!%&@#######@%!;'.                   |##############%!$@####!                  `
                .|#######&;'. .    |#######%.                      .':;!!!!!!;`...                   .|############|. :$@@####%.                `
                !####&$&@#@!:'.       ;#####%`                  .`';;'... ..''``.                    !##########%`    ''':$######$`             `
                ;#####@$$;`%&:.         `%####;                   .:;;:'':;||!:`                    !#########!          :&#@@####!             `
          '%######@######!   !!            :$@$`                    ...`.'::`..                   '$######@!`         '|$$&!!@#######@!.        `
     '$#########@&$$@######@:    ;: . `'    ....                      ...``.                    `$######&'           '!;`'!@######&&########$'  `
  ;############@#@@@@@$|%@###$`  `!!.;' .     :!.                                             .%#####!.            .;::&####|`..`  ..;@########!'
  |########&|;'``..`:'    ..!##%:.    ;;      `.                                            .|###|`             `'|###@&$|`  ..   .`|&&@#######%:
  |###@#@@#&|:`.`';;:;!!!;:;''!$##&;'.  .'%; .;&###&|$!                                     '$; .|$:;|`   ...;&###$'    ....      :||%&########%:
  |#######@$;!%%:```           .!@###&|`   :|'!########@#!                                ;@! :@####%'. `|@###&:         ..`:::%$$&$$$&@##@@@##|:
  |########$;::'`         .`.     `%#####%!: .. !#####%` !#%.                        !; '%; !#############&:          `::`.```. .':.  :$@&&&###|:
  !####@%:::;;:::::` .........            '.  !#######%;;';; `%#&'             ;&: `;``$@!%########&&##&|::::'.             ':.     `!%@@######|:
  !#####%;;::.       ...... ....`..  ..  '::!|&########$';%`.'` .;%:        !#$';$%|&$!&##########$'        `';;;;!&##&%||||||%;`   .:|&###@###|:
  |#######|`...      `|$&&$$!`....           ;$:  :&#@:     `'''``.   .%########&'  .%#@&$%$#####$`     ....`:%&@@@@@@&&@@!`.      .`'%@#######|'
  |######@@$:       .`..`!@&$&&&&:                ;@#######@@#$%@######&$;    '%@##%!@###@&&@####%.     `!&@@@@@$:..`..``.``...     `|&####@@##!'
  ;###&|;::!&#&%%%%:         .'::::;|$&&$%|'..;%%&#######%;$########@&#####%`   '|@###;    '%####$;::::::`            '!|%%%%%%%%%&#$:'::.'%###|'
  `%###@|;|%$%$@#&|;::::`          '|%%%%%$%|%|;';$##@|'.   |######&'     .:|$%: :&@|'.     !####%.              `::;:!$@######&%%%%%!'  ':;&##|:
  '$##%:.    :&##@####@$;.  ..                    `$|     :; !#####|      '|%:  ``    ...   !####!          .  ..:&#@@@@##@&||$;         :&####|'
  !####&@@&;        ...`.'%@##@@#@@&!`            :&&!.       !###&'  :||:.`   !%'     ``:$######@@@&&@@@&@##$;``....             |@@@@########!'
  !#######@$||!:          ';!;;;!&###&|||||||||||%&##@!`.     !###&||%!!!:   .:;`        `;;%####$;:;;;;;;;;;;;::.         '||||||&#####%!;;$##!`
  `%#&:.`:!||||||%@#@%;::;;;'                     ;@@:    .. .%###|.   `:::'  .:!;'`':'`   `$####!             ':;;;;!%@@&%%%|;`        `;%&###|:
  .%##|..       '$##@@@@@@#&:...`..              `$#$'        !##%`   ..`.`:%@@! '%@$:''. .`|####|... .........`:%###@#@@@|`        ....`%#####|:
  !###@&!       .`.```':!&##@&&&&$:              '&#%.        !#&'     ````.    .```:%&&&&&@#####@!':|$&&$&&&&&&&&&@##|`````.       !@@@#######!'
  :&#########@$||||:            `::::;;;;;!!;;;:;$###$'  .'`  |#@|.  .:;;:.                `%####%:''':::::`               `!||&##$;;;:::.  ;##|:
  .%#@$%$%%%%%$@###$::::::'.           ...`;|!::!&##@$%|||!' .%##&%%$%'        `'.         :&####!                  .':::'::%@&$%%!` .!!':;$###%:
  :&#############@|.              .  '$##################&;..!@###@#######%'.             .!#####!          .              `$#####@|``;&|!&####|:
  |####&%'   .''''':|@###@$$$$$$%;.             |####%`      .|#@;.         .;$$$%$&$$$$$$&######$:..:|%$$$$$$$&&&&@######&;'''.    ;$&########|:
  |#######@%;;`    '!|!||$#######&|!!!;;;!!!;`.!#####@: .;|!!|&#$'   `:'':;;$######################################%!|!!!!!;.  .`;|&######@####%:
  |############$!''''..';$&&&&@########################$;'!;`:@#&:``'|$@######@@@@&&&&&&&@#######@&&&&&&&&&&&@@&&&&$|:.    .`''$########@&@####%:
  |###&%$&#################@%;'  ..      `|@############$: `%@###########$`  `%%:.     . :@######|         !#####################@$%&##########%:
  |#######################################@&&@######################@@&@#######################################################################%:
*/

#define _CRT_SECURE_NO_WARNINGS

#include <map>
#include <set>
#include <stack>
#include <ctime>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cctype>
#include <vector>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <fstream>
#include <iostream>
#include <algorithm>

using namespace std;

inline char gc() {
    static const int L = 233333;
    static char sxd[L], *sss = sxd, *ttt = sxd;
    if (sss == ttt) {
        ttt = (sss = sxd) + fread(sxd, 1, L, stdin);
        if (sss == ttt) {
            return EOF;
        }
    }
    return *sss++;
}

#ifndef _AT_HOME
#define dd c = gc()
#else
#define dd c = getchar()
#endif
inline char readalpha() {
    char dd;
    for (; !isalpha(c); dd);
    return c;
}

inline char readchar() {
    char dd;
    for (; c == ' '; dd);
    return c;
}

template <class T>
inline bool read(T& x) {
    bool flg = false;
    char dd;
    x = 0;
    for (; !isdigit(c); dd) {
        if (c == '-') {
            flg = true;
        } else if(c == EOF) {
            return false;
        }
    }
    for (; isdigit(c); dd) {
        x = (x * 10) + (c ^ 48);
    }
    if (flg) {
        x = -x;
    }
    return true;
}
#undef dd

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x < 10) {
        putchar(x | 48);
        return;
    }
    write(x / 10);
    putchar((x % 10) | 48);
}

template <class T>
inline void writesp(T x) {
    write(x);
    putchar(' ');
}

template <class T>
inline void writeln(T x) {
    write(x);
    puts("");
}

#define lowbit(x) (x & -x)

namespace dfcmd {
    typedef long long LL;

    const int maxn = 405;
    const int mod = 998244353;

    inline void add(int& x, int y) {
        x += y;
        if (x >= mod) {
            x -= mod;
        }
    }

    int n;
    int a[maxn];
    int id[maxn][maxn][maxn];
    int f[maxn * maxn][maxn][2];
    int bin[maxn];
    int C[maxn][maxn];

    inline int dfs(int l, int r, int h) {
        static int cnt = 0;
        if (l > r) {
            return 0;
        }
        if (id[l][r][h]) {
            return id[l][r][h];
        }
        int now = id[l][r][h] = ++cnt;
//        cout << "cnt = " << cnt << endl;
        int Mid = l;
        for (int i = l + 1; i <= r; ++i) {
            if (a[i] < a[Mid]) {
                Mid = i;
            }
        }
        if (a[Mid] == h) {
            int ls = dfs(l, Mid - 1, h);
            int rs = dfs(Mid + 1, r, h);
            int sizl = Mid - l;
            int sizr = r - Mid;
            for (int i = 0; i <= sizl; ++i) {
                for (int j = 0; j <= sizr; ++j) {
                    add(f[now][i + j][0], (LL) f[ls][i][0] * f[rs][j][0] % mod);
                    add(f[now][i + j + 1][1], (LL) f[ls][i][1] * f[rs][j][1] % mod);
                }
            }
        } else {
            int up = dfs(l, r, h + 1);
            int siz = r - l + 1;
//            cout << "up = " << up << endl;
            for (int i = 0; i <= siz; ++i) {
                f[now][i][0] = f[now][i][1] = f[up][i][1];
                add(f[now][i][0], (LL) f[up][i][0] * (bin[siz - i] - 1) % mod);
                add(f[now][i][1], (LL) f[up][i][1] * (bin[siz - i] - 1) % mod);
            }
            for (int i = 1; i <= siz; ++i) {
                for (int j = 1; j <= i; ++j) {
                    add(f[now][i - j][0], (LL) f[up][i][0] * C[i][j] % mod * bin[siz - i] % mod);
                    add(f[now][i - j][1], (LL) f[up][i][1] * C[i][j] % mod * bin[siz - i] % mod);
                }
            }
//            cout << "dfs " << l << ' ' << r << ' ' << h << ' ' << now << endl;
//            for (int i = 0; i <= siz; ++i) {
//                cout << f[now][i][1] << ' ';
//            }
//            cout << endl;
        }
        return now;
    }

    int Main() {
        read(n);
        for (int i = 1; i <= n; ++i) {
            read(a[i]);
        }
        C[0][0] = 1;
        for (int i = 1; i <= n; ++i) {
            C[i][0] = 1;
            for (int j = 1; j <= i; ++j) {
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
                if (C[i][j] >= mod) {
                    C[i][j] -= mod;
                }
            }
        }
        bin[0] = 1;
        for (int i = 1; i <= n; ++i) {
            bin[i] = bin[i - 1] << 1;
            if (bin[i] >= mod) {
                bin[i] -= mod;
            }
        }
        f[0][0][0] = f[0][0][1] = 1;
        writeln(f[dfs(1, n, 0)][0][0]);
        return 0;
    }
}

int main() {
    return dfcmd::Main();
}