Anya is a lover of giggles. She has even invented her own assessment of the…
- User
Anya is a lover of giggles. She has even invented her own assessment of the compatibility of her sense of humor “hee-hee-hee-hee”, which is similar to the chi-square criterion. Anya decided to test how compatible her sense of humor is with Vanya. To do this, she took a collection of jokes and divided them into several non-overlapping sets. Anya also suggested to Vanya to divide the jokes into several non-overlapping sets. The number of sets need not be the same. After that, the compatibility score of sense of humor is calculated using the formula: \sum_{A,B} \frac{|o(A,B) - e(A,B)|}{e(A,B)} where o(A,B) is the actual observed number of jokes that Anya assigned to set A and Vanya to B, e(A, B) is the expected number of anecdotes, assuming that Anya and Vanya assign anecdotes to groups independently of each other. If e(A, B) is zero, the corresponding summand is not considered. Anya assigned three anecdotes to the first set, and Vanya - one. Consequently, for Anya the probability of meeting an anecdote from the first set is 3/5, and for Vanya - 1/5. The joint probability with independence is 3/25 and the mathematical expectation is 15/25. Input data format The first line contains two natural numbers M and K (1 <= M, K <= 10^5) - the number of sets into which Anya and Vanya divided the anecdotes, respectively. Some sets may be empty. The second line contains a natural number N ( 1 <= N <= 10^5) - the number of anecdotes in the collection. The next N lines contain two natural numbers ai and bi (1 <= ai <= M, 1 <= bi <= K) - the numbers of the sets to which Anya and Vanya attributed the i-th anecdote. Output data format Print one real floating-point number - an estimation of compatibility of the sense of humor “hee-hee-hee” between Anya and Vanya. Allowable absolute and relative error 10-6 Example 1 Input data 2 3 5 2 3 1 2 1 1 1 2 2 3 Output 5.833333333
- Assistant
To solve this problem efficiently, we'll calculate the compatibility score by dividing the process into manageable steps.
-
Collect Data and Frequencies
- Read data points and collect counts:
-