Determinant#3693

Determinant

4 seconds
256 megabytes
Hard

Given a matrix of size N \times N, where each element is either or . In every row, the elements that are are contiguous.

Your task is to calculate the determinant of this matrix.

Input

The first line of the input contains an integer (1 \leq N \leq 10^6) representing the size of the matrix. The next lines each contain two integers l_i and r_i (1 \leq l_i \leq r_i \leq N), which specify that in the -th row, the elements from position l_i to r_i (inclusive) are ones, while all other elements are zeros.

Output

Print a single integer, which is the determinant of the matrix.

Examples

Example 1

Loading
Loading