## LCC/Moose '18 Contest 3 J2 - Dereck's Procrastination

View as PDF

Points: 3
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

Dereck is currently taking an online summer school course, but he has one big problem: he is an avid procrastinator who consistently submits all of his work exactly 0 seconds before it's due.

Being the good friend you are, can you help Dereck by telling him when he should be starting his work?

Given:

• assignments to do, due at the same time
• The number of hours, , it takes to complete each assignment
• And how many times, , he has to do each assignment (He does assignments multiple times to procrastinate on doing other assignments)

How many hours before the due date should Dereck start his homework and assignments?

#### Input Specification

The first line will contain one integer, .

The following lines will each contain two integers, and .

#### Output Specification

Output the number of hours before the due date that Dereck should be starting his work.

#### Sample Input

5
1 2
3 1
4 4
3 1
5 3

#### Sample Output

39

#### Explanation

If Dereck starts 39 hours before the due date, he should finish exactly 0 seconds before it's due.