Movie Night

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

문제

You're trying to organize an outing to a movie with a group of friends. This is made complicated by the fact that your friends will decide whether to come based on who else is coming. If you give one of your friends a call, you know you're going to have a conversation like this:

  • You: "Hi Fred, want to come with us to the 7:30 showing of Coding Horror from the Accidentally Quadratic Lagoon?"
  • Fred: "Well, I dunno... is Francine coming?"

In fact, for each one of your friends X, there is exactly one other friend Y such that X will come only if Y also comes. Of course, you must invite a subset of your friends such that everyone invited knows who else is invited and will be willing to come, and no one uninvited will need to come.

The question is, how many such subsets of your friends are there? You don't want to go to the movies alone, so every set must have at least one friend.

입력

The first line of input contains an integer nn (2n1052 \le n \le 10^5). This is the number of friends you might invite to the movie. You identify your friends by a number from 1 to nn.

Each of the next nn lines contains a single integer yy (1yn1 \le y \le n). This indicates that friend xx will only go to the movie if friend yy also goes to the movie, where xx is 11 for the first yy value, 22 for the second yy value, and so on. No one will be their own friend! (i.e., xyx \ne y)

출력

Output a single integer, which is the number of distinct nonempty subsets of your friends you could invite such that everyone you invite will be willing to come. Since this number may be quite large, output it modulo 109+710^9 + 7.