P27373 [AtCoder] Holes in Coins
普及+
题目描述

Problem Description

In Japan, the coins currently in use are the ¥1, ¥5, ¥10, ¥50, ¥100, and ¥500 coins. Among these, the ¥5 and ¥50 coins have holes in them.

Takahashi runs a shop in Japan, and one day, his shop was visited by N customers. The i-th (1 ≤ i ≤ N) customer paid ¥B_i for an item worth ¥A_i, and Takahashi gave change to each customer using the minimum number of coins possible.

Determine how many of the coins used for change had holes in them.

Assume that Takahashi has a sufficient number of each of the six types of coins.

Input Format

The input is given from the standard input in the following format:

$ N $ $ A_1 $ $ B_1 $ $\vdots$ $ A_N $ $ B_N $

Output Format

Output the answer.

Sample Input and Output

Sample Input #1

2
40 100
105 120

Sample Output #1

2

Sample Input #2

6
1 2
1 6
1 11
1 51
1 101
1 501

Sample Output #2

2

Notes/Hints

Constraints

  • $1 \leq N \leq 10^5$
  • $1 \leq A_i \leq B_i \leq 10^3$
  • All inputs are integers.

Sample Explanation 1

For the first customer, ¥60 in change is given, using one ¥10 coin and one ¥50 coin to minimize the total number of coins. For the second customer, ¥15 in change is given, using one ¥5 coin and one ¥10 coin to minimize the total number of coins. Among these, the coins with holes are two in total.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 40 100 105 120
样例输出
2