B - Intersection 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 200

問題文

長さ N の数列 A = (A_1, A_2, A_3, \dots, A_N), B = (B_1, B_2, B_3, \dots, B_N) が与えられます。
以下の条件を満たす整数 x の個数を求めてください。

  • 1 \le i \le N を満たす全ての整数 i について A_i \le x \le B_i

制約

  • 1 \le N \le 100
  • 1 \le A_i \le B_i \le 1000
  • 入力に含まれる値は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 A_2 A_3 \dots A_N
B_1 B_2 B_3 \dots B_N

出力

答えを出力せよ。


入力例 1

2
3 2
7 5

出力例 1

3

x3 \le x \le 72 \le x \le 5 の両方を満たさなければなりません。
そのような整数 x3, 4, 53 個あります。


入力例 2

3
1 5 3
10 7 3

出力例 2

0

条件を満たす整数 x が存在しないこともあります。


入力例 3

3
3 2 5
6 9 8

出力例 3

2

Score : 200 points

Problem Statement

You are given sequences of length N each: A = (A_1, A_2, A_3, \dots, A_N) and B = (B_1, B_2, B_3, \dots, B_N).
Find the number of integers x satisfying the following condition:

  • A_i \le x \le B_i holds for every integer i such that 1 \le i \le N.

Constraints

  • 1 \le N \le 100
  • 1 \le A_i \le B_i \le 1000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 A_3 \dots A_N
B_1 B_2 B_3 \dots B_N

Output

Print the answer.


Sample Input 1

2
3 2
7 5

Sample Output 1

3

x must satisfy both 3 \le x \le 7 and 2 \le x \le 5.
There are three such integers: 3, 4, and 5.


Sample Input 2

3
1 5 3
10 7 3

Sample Output 2

0

There may be no integer x satisfying the condition.


Sample Input 3

3
3 2 5
6 9 8

Sample Output 3

2