D. Dynamic Park Pricing
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In the bustling city of Metropoville, the demand for parking spaces is as dynamic as its ever-moving traffic. To manage this demand efficiently, the city has introduced a new parking payment system in its central parking structure, known as "Dynamic Park". Unlike traditional parking lots, Dynamic Park utilizes a tiered payment system that adjusts the cost based on the duration of parking, aiming to optimize space usage and provide fair charges for its patrons.

You've spent a day in Metropoville and now need to pay for your parking at Dynamic Park. The parking structure operates on a tiered charging system where the cost per minute changes after certain time thresholds. Given the total time you've parked, expressed in hours and minutes (for example, 19 hours and 38 minutes), calculate the total parking fee based on the tiered rates provided.

Input

The first line contains two integers $$$H$$$ and $$$M$$$ ($$$0 \leq H \lt 24$$$, $$$0 \leq M \lt 60$$$), representing the number of hours and minutes you've parked, respectively.

The second line contains an integer $$$N$$$ ($$$1 \leq N \leq 10$$$), the number of different time tiers.

Each of the next $$$N$$$ lines describes a tier with two integers $$$X_i$$$ and $$$Y_i$$$ ($$$1 \leq X_i \leq 1440$$$, $$$1 \leq Y_i \leq 100$$$). $$$X_i$$$ represents the duration of the tier in minutes, and $$$Y_i$$$ is the cost per minute in that tier.

Output

Output a single integer, the total cost of parking. If the parking duration exceeds the specified tiers, calculate the cost up to the last tier for the remaining time.

Examples
Input
1 10
2
60 1
20 100
Output
1060
Input
23 59
2
10 10
20 20
Output
500