QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 512 MB 満点: 100

#9642. Sprint

統計

Madeline meets Oshiro on her way down after reaching the summit, and he asks her to help him collect strawberries hidden in the high parts of the hotel.

For convenience, we ignore the width of the hotel and describe it as a $10^9 \times 10^9$ plane. Madeline starts at $(0,0)$, and there are $n$ strawberries, with the $i$-th strawberry located at $(u_i, v_i)$. Since the hotel is extremely large, Madeline decides to use a combination of jumping and dashing to collect the strawberries. Suppose she is at $(x, y)$. If $\min(x, y) < 10^9$, she performs the following operations:

First, she jumps to $(x+1, y)$ with probability $q$, or to $(x, y+1)$ with probability $1-q$.

Then, she enters the dash phase. A single dash to the upper-right moves Madeline directly from $(s, t)$ to $(s+1, t+1)$. She performs one dash to the upper-right first. Because there are energy crystals in the hotel, she will enter the dash phase again with probability $p$, or exit with probability $1-p$. You can assume that in this phase, Madeline performs $i+1$ consecutive dashes to the upper-right with probability $(1-p)p^i$ ($i \ge 0$), after which the round of operations ends.

If Madeline passes through a strawberry at any moment, it is considered collected. Calculate the expected number of strawberries collected. For convenience, all calculations are performed modulo $P = 1004535809 = 479 \times 2^{21} + 1$.

Input

The first line contains three integers $n, p, q$.

The next $n$ lines each contain two integers $u_i, v_i$.

Output

Output a single integer representing the answer.

Examples

Input 1

3 502267905 502267905
1 0
1 2
2 2

Output 1

753401858

Note 1

It can be assumed that $p = q = \frac{1}{2}$, and the probabilities of passing through the three points are $\frac{1}{2}, \frac{1}{2}, \frac{1}{4}$ respectively.

Examples 2 ~ 7

See the provided files, which satisfy the constraints of subtasks $1, 3, 4, 5, 7, 9$ respectively.

Constraints

For all test cases, $1 \le n \le 5000, 0 \le u_i, v_i \le 10^7, |u_i - v_i| \le 5000, 0 \le p, q < P, p \ne 1$.

Let $V = \max \left(\max_{i=1}^n u_i, \max_{i=1}^n v_i\right), b = \max_{i=1}^n |u_i - v_i|$.

Subtask $V \le$ Special Property Score
$1$ $300$ None $5$
$2$ $5000$ None $5$
$3$ $10^7$ $p=0$ $5$
$4$ $10^7$ $q=0$ $5$
$5$ $5 \times 10^5$ $b=0$ $5$
$6$ $10^7$ $b=0$ $15$
$7$ $10^7$ $b \le 1$ $10$
$8$ $5 \times 10^5$ None $10$
$9$ $5 \times 10^6$ $n \le 3000$ $25$
$10$ $10^7$ None $15$

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.