시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 512 MB 20 16 13 86.667%

## 문제

You are given a bipartite graph with n vertices in each part.

In this graph, each vertex from the left part is connected to some prefix of vertices from the right part. Namely, the i-th vertex in the left part is connected with vertices 1, 2, . . . , ai in the right part.

Find the number of vertex-simple cycles in this graph. Two cycles are different if there exists some edge which is present in one cycle but not in the other.

As this number may be large, find it modulo 998 244 353.

## 입력

The first line of input contains one integer n (1 ≤ n ≤ 5000): the number of vertices in each part.

The next line of input contains n integers a1, a2, . . . , an (1 ≤ ai ≤ n): a description of the given graph.

## 출력

Output one integer: the number of vertex-simple cycles in the given graph, modulo 998 244 353.

## 예제 입력 1

1
1


## 예제 출력 1

0


## 예제 입력 2

2
2 2


## 예제 출력 2

1


## 예제 입력 3

3
3 3 2


## 예제 출력 3

7


## 예제 입력 4

10
6 6 7 7 8 8 9 9 10 10


## 예제 출력 4

410150080


## 출처

• 문제를 만든 사람: 300iq