#arc140d. [arc140_d]One to One

[arc140_d]One to One

Problem Statement

For an integer sequence X=(X1,X2,dots,XN)X=(X_1,X_2,\\dots,X_N) of length NN whose elements are all between 11 and NN (inclusive), consider the question below, and let f(X)f(X) be the answer.

There is an undirected graph GG with NN vertices (and possibly multi-edges and self-loops). GG has NN edges, the ii-th of which connects Vertex ii and Vertex XiX_i. Find the number of connected components in GG.

You are given an integer sequence A=(A1,A2,dots,AN)A=(A_1,A_2,\\dots,A_N) of length NN, where each AiA_i is an integer between 11 and NN (inclusive) or \-1\-1.

Consider an integer sequence X=(X1,X2,dots,XN)X=(X_1,X_2,\\dots,X_N) of length NN whose elements are all between 11 and NN such that Aineq1RightarrowAi=XiA_i \\neq -1 \\Rightarrow A_i = X_i. Find the sum of f(X)f(X) over all such XX, modulo 998244353998244353.

Constraints

  • 1leNle20001 \\le N \\le 2000
  • AiA_i is between 11 and NN (inclusive) or \-1\-1.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN A1A_1 A2A_2 dots\\dots ANA_N

Output

Prin the answer.


Sample Input 1

3
-1 1 3

Sample Output 1

5

There are three sequences XX satisfying the requirement, as follows.

  • X=(1,1,3)X=(1,1,3), for which the answer to the question is 22.
  • X=(2,1,3)X=(2,1,3), for which the answer to the question is 22.
  • X=(3,1,3)X=(3,1,3), for which the answer to the question is 11.

Thus, the answer is 2+2+1=52+2+1=5.


Sample Input 2

1
1

Sample Output 2

1

Sample Input 3

8
-1 3 -1 -1 8 -1 -1 -1

Sample Output 3

433760