Let $$S$$ be a set of intervals of integers and $$f(S)$$ be the number of integers $$x$$ for which there exist an interval $$T$$ with $$T \in S$$ and $$x, x+1 \in T$$. In particular we have that $$f(\{ [l,r] \}) = r - l$$.
Given an integer array $$A$$ of length $$2N$$. Consider a sequence of intervals $$[l_1, r_1], [l_2, r_2], \dots, [l_N, r_N]$$ valid if $$r_1 < r_2 < \dots < r_N$$, $$l_i < r_i$$ and $$(l_1, r_1, l_2, r_2, \dots, l_N, r_N)$$ is a permutation of $$A$$.
Find the sum $$f(\{ [l_1, r_1] \} \cup \{ [l_2, r_2] \} \cup \dots \cup \{ [l_N, r_N] \})$$ modulo $$10^9 + 7$$ over all possible sequences of intervals.
$$\textbf{Input}$$
The first line contains one integer - $$N (1 \le N \le 10^5)$$.
The next line contains $$2N$$ integers - $$A_1, A_2, \dots, A_{2N}$$ $$(1 \le A_1 < A_2 < \dots < A_{2N} \le 10^9)$$.
$$\textbf{Output}$$
Output the answer modulo $$10^9 + 7$$.
The valid intervals are $$\{ ([1,2], [3,4]), ([1,3], [2,4]), ([2,3], [1,4]) \}$$ contributing with $$2, 3, 3$$ respectively to the answer.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor