Under construction

Still being built. Things may change

Weightlifter

Time limit1sMemory limit1024 MB

Summary
Sum the evening-minus-morning body mass increases on training days to get the total muscle gain.
Level

Easy2 of 10

Topics
Implementation, Array
Solved
No attempts yet

Problem

A weightlifter is preparing for a competition and wants to analyze the muscle mass he has gained. He reviews his training records for the last nn days. For each day, his body mass in the morning xix_i and in the evening yiy_i are known. It is also known on which days he trained.

On training days, an increase in body mass, if it happened, counts as a gain in muscle mass. If his body mass decreased or he did not train, the muscle gain for that day is 00.

Help the weightlifter find his total gain in muscle mass.

Input

The first line contains nn, the number of days to analyze (1≤n≤10001 \le n \le 1000).

The second line contains nn integers. The ii-th integer is 11 if there was training on day ii, and 00 if there was no training on day ii.

The next nn lines contain the body mass measurements. Each line has two integers xix_i and yiy_i, the body mass in grams (30 000≤xi,yi≤200 00030\,000 \le x_i, y_i \le 200\,000).

Output

Print one integer, the total gain in muscle mass.

Examples1

  1. Example 1

    Input
    5
    0 1 0 1 0
    80000 81000
    80500 81500
    81500 81000
    80500 80000
    80000 81800
    
    Expected output
    1000