Classical DP Problem

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

Let us consider a grid of squares with nn rows and nn columns. Arbok has cut out some part of the grid so that, for each i=1,2,,ni = 1, 2, \ldots, n, only the leftmost a_ia\_i squares are remaining in the ii-th row from the top. The values of a_ia\_i satisfy a_1a_2a_na\_1 \le a\_2 \le \ldots \le a\_n: that is, the grid looks like a Young diagram. Now, Arbok wants to place rooks into some of the remaining squares of the grid.

A rook is a chess piece that occupies one square and can move horizontally or vertically, through any number of unoccupied squares.

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 rr, the smallest number of rooks Arbok needs to place into some of the remaining squares so that every remaining square is covered. Also find ww, the number of ways to put rr rooks to satisfy the same condition, modulo 998,244,353998\\,244\\,353.

입력

The first line contains a single integer nn, denoting the size of the grid (1n50001 \le n \le 5000).

The second line contains nn integers a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n, denoting the widths of the rows left by Arbok (1a_1a_2a_nn1 \le a\_1 \le a\_2 \le \ldots \le a\_n \le n).

출력

Print two integers rr and ww, denoting the smallest number of rooks Arbok needs to place so that every remaining square is covered, and the number of ways to put rr rooks to achieve the same, modulo 998,244,353998\\,244\\,353.

힌트

In the first example test, one rook is not enough to cover every square, but two rooks are enough, and there are six ways to place two rooks to cover every square (R denotes a rook, * denotes an empty square):

R          *          *          *          *          *  
**         R*         R*         R*         *R         ** 
*R*        R**        *R*        **R        R**        RR*