Intervals
Time limit1sMemory limit1024 MB
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 to , inclusive, is written . This is called an interval. is possible, in which case the set is empty.
The intersection of intervals , , , is the set of values from to inclusive, so it can be written as the interval .
The length of an interval is defined as .
You are given intervals , , , , where . Write a program that, for each of the 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 .
Input
The first line contains one integer (), the number of intervals.
Each of the next lines contains two integers and () separated by a single space, describing .
Output
Print on the first line two integers separated by a space: the sum of the intersection lengths over all ways to choose one or more intervals, and the number of intersections with length at least . Since these numbers can be very large, print each one modulo .