This page is still under construction.

Parts of this page are still being built. What you see may change.

Speed Limit

Time limit1sMemory limit128 MB

Summary
Given segments of constant speed with cumulative elapsed times, compute the total distance for each data set until n equals -1.
Level

Easy1 of 10

Topics
Implementation, Math, Simulation
Solved
No attempts yet

Problem

Bill and Ted are on a road trip, but their car's odometer is broken, so they don't know how far they have driven. Fortunately, Bill has a working stopwatch, so they can record their speed and the total time driven since the start of the trip. Their record-keeping is a little unusual, so they need help computing the total distance. Write a program to do this computation.

For example, suppose their log is:

Speed (miles per hour)Total elapsed time (hours)
202
306
107

This means they drove 2 hours at 20 mph, then 6−2=46 - 2 = 4 hours at 30 mph, then 7−6=17 - 6 = 1 hour at 10 mph. The total distance driven is (2)(20)+(4)(30)+(1)(10)=40+120+10=170(2)(20) + (4)(30) + (1)(10) = 40 + 120 + 10 = 170 miles. Note that each elapsed time is measured from the beginning of the trip, not from the previous log entry.

Input

The input consists of one or more data sets. Each set begins with a line containing an integer nn (1≤n≤101 \le n \le 10), followed by nn pairs of values, one pair per line. In each pair, the first value ss is the speed in miles per hour and the second value tt is the total elapsed time; both are integers with 1≤s≤901 \le s \le 90 and 1≤t≤121 \le t \le 12. The values of tt are always in strictly increasing order. A value of −1-1 for nn signals the end of the input.

Output

For each data set, print the distance driven, followed by a space, followed by the word "miles".

Examples2

  1. Example 1

    Input
    3
    20 2
    30 6
    10 7
    2
    60 1
    30 5
    4
    15 1
    25 2
    30 3
    10 5
    -1
    
    Expected output
    170 miles
    180 miles
    90 miles
    
  2. Example 2

    Input
    5
    1 1
    2 2
    3 3
    4 4
    5 5
    -1
    
    Expected output
    15 miles