#USACOC2214B. Air Cownditioning

Air Cownditioning

Description

Farmer John's cows NN are very particular about the room temperature in theirbarn. Some cows like the temperature to be on the cooler side, while othersprefer more warmth.

Farmer John's barn contains a sequence of NN stalls, numbered 1N1 \ldots N,each containing a single cow. The ii-th cow prefers the temperature of her stallto be pip_i, and right now the temperature in her stall is tit_i. In order tomake sure every cow is comfortable, Farmer John installs a new air conditioningsystem that is controlled in a somewhat interesting way. He can send commandsto the system telling it to either raise or lower the temperature in aconsecutive series of stalls by 1 unit --- for example "raise the temperaturein stalls 585 \ldots 8 by 1 unit". The series of stalls could be as short asjust a single stall.

Please help Farmer John determine the minimum number of commands he needs tosend his new air conditioning system so that every cow's stall is at the idealtemperature for its resident cow.

Input Format

The first line of input contains NN. The next line contains the NNnon-negative integers p1pNp_1 \ldots p_N, separated by spaces. The final linecontains the NN non-negative integers t1tNt_1 \ldots t_N.

Output Format

Please write a single integer as output containing the minimum number ofcommands Farmer John needs to use.

5
1 5 3 3 4
1 2 2 2 1
5
1 5 3 3 4
1 2 2 2 1

Scoring

  • Test cases 2-5 satisfy N100N \leq 100.
  • Test cases 6-8 satisfy N1000N \leq 1000.
  • Test cases 9-10 satisfy N100,000N \leq 100,000.
  • In test cases 1-6 and 9, temperature values are at most 100100.
  • In test cases 7-8 and 10, temperature values are at most 10,00010,000.

Problem Credit

Problem credits: Brian Dean