Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

The problem statement has recently been changed. View the changes.

×
E. Desk Disorder

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputA new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engineering team asking each engineer the number of the desk they currently sit at, and the number of the desk they would like to sit at (which may be the same as their current desk). Each engineer must either remain where they sit, or move to the desired seat they indicated in the survey. No two engineers currently sit at the same desk, nor may any two engineers sit at the same desk in the new seating arrangement.

How many seating arrangements can you create that meet the specified requirements? The answer may be very large, so compute it modulo 1000000007 = 10^{9} + 7.

Input

Input will begin with a line containing *N* (1 ≤ *N* ≤ 100000), the number of engineers.

*N* lines follow, each containing exactly two integers. The *i*-th line contains the number of the current desk of the *i*-th engineer and the number of the desk the *i*-th engineer wants to move to. Desks are numbered from 1 to 2·*N*. It is guaranteed that no two engineers sit at the same desk.

Output

Print the number of possible assignments, modulo 1000000007 = 10^{9} + 7.

Examples

Input

4

1 5

5 2

3 7

7 3

Output

6

Input

5

1 10

2 10

3 10

4 10

5 5

Output

5

Note

These are the possible assignments for the first example:

- 1 5 3 7
- 1 2 3 7
- 5 2 3 7
- 1 5 7 3
- 1 2 7 3
- 5 2 7 3

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Dec/04/2021 18:00:30 (j2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|