Under construction

Still being built. Things may change

Intervals

Time limit1sMemory limit1024 MB

Summary
For each non-empty subset of the intervals, sum the intersection lengths and count those of length at least 1, modulo 1000000007.
Level

Medium6 of 10

Topics
Intervals, Sorting, Combinatorics, Math
Solved
No attempts yet

Problem

The set of all real numbers from pp to qq, inclusive, is written \[p,q]\[p,q]. This is called an interval. p>qp > q is possible, in which case the set is empty.

The intersection of kk intervals \[p1,q1]\[p_1, q_1], \[p2,q2]\[p_2, q_2], ⋯\cdots, \[pk,qk]\[p_k,q_k] is the set of values from P=max⁡(p1,p2,⋯ ,pk)P = \max{(p_1, p_2, \cdots , p_k)} to Q=min⁡(q1,q2,⋯ ,qk)Q = \min{(q_1, q_2, \cdots , q_k)} inclusive, so it can be written as the interval \[P,Q]\[P,Q].

The length of an interval \[p,q]\[p,q] is defined as max⁡(q−p,0)\max{(q-p, 0)}.

You are given NN intervals I1I_1, I2I_2, ⋯\cdots, INI_N, where Ii=\[si,ei]I_i = \[s_i,e_i]. Write a program that, for each of the 2N−12^N-1 ways to choose one or more of the intervals, computes the sum of the lengths of the intersections of the chosen intervals and the number of intersections whose length is at least 11.

Input

The first line contains one integer NN (1≤N≤1051 \le N \le 10^5), the number of intervals.

Each of the next NN lines contains two integers sis_i and eie_i (0≤si,ei≤1090 \le s_i, e_i \le 10^9) separated by a single space, describing Ii=\[si,ei]I_i = \[s_i, e_i].

Output

Print on the first line two integers separated by a space: the sum of the intersection lengths over all 2N−12^N-1 ways to choose one or more intervals, and the number of intersections with length at least 11. Since these numbers can be very large, print each one modulo 1 000 000 0071\,000\,000\,007.

Examples1

  1. Example 1

    Input
    4
    1 4
    1 3
    2 4
    5 6
    
    Expected output
    14 8