Mooball Teams III
Time limit2sMemory limit1024 MB
Count pairs of nonempty, disjoint red and blue cow sets that one horizontal or vertical net at a half-integer coordinate separates, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Combinatorics, Math, Implementation
- Solved
- No attempts yet
Problem
Farmer John has cows on his farm (), numbered . Cow is located at integer coordinates (). Farmer John wants to pick two teams for a game of mooball.
One team is the "red" team and the other is the "blue" team. Neither team can be empty, and each cow may be on at most one team (or on neither). Mooball has one more rule. An infinitely long net must be placed as either a horizontal or vertical line at a non-integer coordinate, such as , and the two teams must be separated by that net. The cows will not move to make this true.
Count the ways to pick a red team and a blue team that satisfy these conditions, modulo .
Input
The first line contains a single integer .
Each of the next lines contains two space-separated integers and . The form a permutation of , and the form a permutation of .
Output
Print a single integer: the number of ways to pick a red team and a blue team that satisfy the conditions, modulo .