Moneybox
Very easy
Execution time limit is 2 seconds
Runtime memory usage limit is 64 megabytes
Given the weight of E is empty piggy banks and weight F piggy bank with coins. In the piggy bank may be the coin of N, for each known value of P_i and the weight W_i of a coin. Find the minimum and maximum amount of money that may be in the kitty.
Input
In the first row are the number of E and F, the second - the number N, the following N lines - two numbers, P_i and W_i. 1 ≤ E ≤ F ≤ 10000, 1 ≤ N ≤ 500, 1 ≤ P_i ≤ 50000, 1 ≤ W_i ≤ 10 000, all numbers are integers.
Output
Two numbers are derived through the gap - minimum and maximum amounts. If the piggy bank may not have exactly the specified weight, provided that it is filled with coins given species - print "This is impossible.".
Examples
Input #1
Answer #1
Submissions 993
Acceptance rate 24%