Army parade
Practice
3.9 (7 votes)
Mathematics
Medium
Problem
85% Success 3898 Attempts 30 Points 1s Time Limit 512MB Memory 1024 KB Max Code

You are general and your life is good, but president is going to check your work results. It's a problem. So you decided to paint grass into green. It's time for choosing soldiers for this work!

Your army has \(n \cdot m\) soldiers. Each soldier is either officer or trooper. During morning greeting they are forming n rows of length m. Because this order is very comfortable for them you decided to choose equal number of rows and columns and send all soldiers which are on intersection of these rows and columns for work. You are really nervous and decided to give personal command for one of chosen soldiers that he should check quality of painting. And you understand that he can't be trooper. So you can give personal command only for officers.

For beginning you decided just calculate the number of ways to choose soldiers for this work. Two ways are different if soldiers sets in them are different or officers with personal command in them are different.

Input format

The first line of input contains three space separated integers n, m and k (\(1 \leq n, m \leq 10^9, 0 \leq k \leq min(n \cdot m, 3 \cdot 10^5)\) - number of rows, number of columns and number of troopers.

Then k lines are following. The i-th of them contains two space separated integers r and c (\(1 \leq r \leq n, 1 \leq c \leq m\)) - the row and column number of the i-th trooper during morning greeting. It is guaranteed that all \((r_i, c_i)\) are distinct. Also it is guaranteed that all other soldiers are officers.

Output format

Print the number of ways modulo \(2 \cdot 10^9+33\).

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
2 votes
Tags:
Dynamic ProgrammingCombinatoricsAd-HocMediumAlgorithmsMathematicsOpenApproved
Points:30
4 votes
Tags:
Special NumbersMediumTernary searchAlgorithmsSearching algorithmMathematicsCounting
Points:30
2 votes
Tags:
Medium