Under construction

Still being built. Things may change

Overtaking

Time limit8sMemory limit1024 MB

Summary
Given each runner's distance per minute, count how many times the runner who was behind takes the lead.
Level

Easy3 of 10

Topics
Simulation, Array
Solved
No attempts yet

Problem

Two athletes run a long-distance race, but the race is different from usual athletics events. They run for a predetermined duration, and the one who runs longer is the winner. At every minute after the start, the distances both runners ran in the previous one minute are recorded. Write a program that, given the record of a race, counts the number of overtakings by either runner during the race. Assume that both runners keep constant paces for every one minute before their distances are recorded.

Here, an overtaking is an event where the runner previously behind takes the lead. Before an overtaking, the two runners may run side by side for a while, during which neither takes the lead. Figure B-1 shows the times and positions of two runners for the third dataset of Sample Input. The number of overtakings in this case is two.

Figure B-1: The third dataset of Sample Input

Input

The input consists of multiple datasets, each in the following format.

nn

a1⋯ana_1 \cdots a_n

b1⋯bnb_1 \cdots b_n

nn is an integer between 2 and 1000, inclusive. It is the duration of the race in minutes. Each aka_k (k=1,…,nk = 1, \ldots, n) is an integer between 1 and 1000, inclusive. It is the distance in meters that the first runner ran between k−1k - 1 minutes and kk minutes after the start. Similarly, bkb_k (k=1,…,nk = 1, \ldots, n) is the distance the second runner ran in the same interval.

The end of the input is a line containing a single zero. The number of datasets does not exceed 100.

Output

For each dataset, output the number of overtakings on a line.

Examples1

  1. Example 1

    Input
    3
    5 15 5
    10 5 15
    9
    10 10 10 10 10 10 10 10 10
    5 15 10 5 15 10 5 15 10
    9
    10 10 10 5 15 10 10 10 10
    5 15 10 10 10 10 5 15 10
    0
    
    Expected output
    2
    0
    2