#arc114b. [arc114_b]Special Subsets

[arc114_b]Special Subsets

Problem Statement

Let SS be a set composed of all integers from 11 through NN.

ff is a function from SS to SS. You are given the values f(1),f(2),cdots,f(N)f(1), f(2), \\cdots, f(N) as f1,f2,cdots,fNf_1, f_2, \\cdots, f_N.

Find the number, modulo 998244353998244353, of non-empty subsets TT of SS satisfying both of the following conditions:

  • For every ainTa \\in T, f(a)inTf(a) \\in T.

  • For every a,binTa, b \\in T, f(a)neqf(b)f(a) \\neq f(b) if aneqba \\neq b.

Constraints

  • 1leqNleq2times1051 \\leq N \\leq 2 \\times 10^5
  • 1leqfileqN1 \\leq f_i \\leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN f1f_1 f2f_2 ldots\\ldots fNf_N

Output

Print the number of non-empty subsets of SS satisfying both of the conditions, modulo 998244353998244353.


Sample Input 1

2
2 1

Sample Output 1

1

We have f(1)=2,f(2)=1f(1) = 2, f(2) = 1. Since f(1)neqf(2)f(1) \\neq f(2), the second condition is always satisfied, but the first condition requires TT to contain 11 and 22 simultaneously.


Sample Input 2

2
1 1

Sample Output 2

1

We have f(1)=f(2)=1f(1) = f(2) = 1. The first condition requires TT to contain 11, and the second condition forbids TT to contain 22.


Sample Input 3

3
1 2 3

Sample Output 3

7

We have f(1)=1,f(2)=2,f(3)=3f(1) = 1, f(2) = 2, f(3) = 3. Both of the conditions are always satisfied, so all non-empty subsets of TT count.