ThreeRooks
Time limit8sMemory limit512 MB
Count the ways to place 3 rooks on a huge X by Y board with K rabbits, where a rabbit between two rooks blocks their attack.
- Level
Medium7 of 10
- Topics
- Math, Combinatorics, Hash map, Sorting
- Solved
- No attempts yet
Problem
A cat is practicing chess.
The cat wants to place 3 rooks on an chessboard. rabbits are sitting on of the squares. The -th rabbit is at . The top-left square has coordinates , and the bottom-right square has coordinates . A rook cannot be placed on a square that has a rabbit. Also, no two rooks can be placed on the same square.
Find the number of ways to place 3 rooks so that no two rooks attack each other, modulo 1,000,000,007. Two rooks attack each other if they are in the same row or the same column and no rabbit is between them.
Input
The input is given in the following format:
...
Output
Print the number of ways to place the rooks, modulo 1,000,000,007, on one line.
Constraints
- and are between 1 and 1,000,000,000, inclusive.
- is between 1 and 100,000, inclusive.
- is between 0 and , inclusive.
- is between 0 and , inclusive.
- No two rabbits are on the same square.