This page is still under construction.

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

Apples

Time limit1sMemory limit256 MB

Summary
Each school splits its apples evenly among its students, and the program sums the leftover apples.
Level

Easy1 of 10

Topics
Math
Solved
No attempts yet

Problem

Apples, a specialty of Gyeongsangbuk-do, were assigned to several schools so that the students could share them. The number of assigned apples can differ from school to school, and so can the number of students. Each school gives every one of its students the same number of apples and wants as few apples as possible left over. Students at different schools can receive different numbers of apples.

For example, suppose the student counts and the assigned apple counts of five schools are as follows.

SchoolABCDE
Students24135237
Apples5222531070

School A gives two apples to every student and 4 apples are left over. School B gives one apple to every student and 9 apples are left over. In the same way school C is left with 3 apples, school D with 10 apples, and school E with 0 apples, so the total number of leftover apples is 4+9+3+10+0=264 + 9 + 3 + 10 + 0 = 26.

Given the number of students and the number of assigned apples at each school, write a program that computes the total number of apples left over after the students receive theirs.

Input

The first line contains an integer NN (1≤N≤1001 \le N \le 100), the number of schools. Each of the next NN lines contains two integers, the number of students at that school and the number of apples assigned to it. Both the student count and the apple count are between 1 and 100.

Output

Print one integer, the total number of leftover apples.

Examples2

  1. Example 1

    Input
    5
    24 52
    13 22
    5 53
    23 10
    7 70
    
    Expected output
    26
    
  2. Example 2

    Input
    3
    10 20
    5 5
    1 13
    
    Expected output
    0