#abc199b. B - Intersection

B - Intersection

Score : 200200 points

问题描述

给定两个长度均为 NN 的序列:A=(A1,A2,A3,,AN)A = (A_1, A_2, A_3, \dots, A_N)B=(B1,B2,B3,,BN)B = (B_1, B_2, B_3, \dots, B_N)

任务是找出满足以下条件的整数 xx 的个数:

  • 对于所有满足 1iN1 \le i \le N 的整数 ii,有 AixBiA_i \le x \le B_i 成立。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given sequences of length NN each: A=(A1,A2,A3,,AN)A = (A_1, A_2, A_3, \dots, A_N) and B=(B1,B2,B3,,BN)B = (B_1, B_2, B_3, \dots, B_N).
Find the number of integers xx satisfying the following condition:

  • AixBiA_i \le x \le B_i holds for every integer ii such that 1iN1 \le i \le N.

Constraints

  • 1N1001 \le N \le 100
  • 1AiBi10001 \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:

NN

A1A_1 A2A_2 A3A_3 \dots ANA_N

B1B_1 B2B_2 B3B_3 \dots BNB_N

Output

Print the answer.

Sample Input 1

2
3 2
7 5

Sample Output 1

3

xx must satisfy both 3x73 \le x \le 7 and 2x52 \le x \le 5.
There are three such integers: 33, 44, and 55.

Sample Input 2

3
1 5 3
10 7 3

Sample Output 2

0

There may be no integer xx satisfying the condition.

Sample Input 3

3
3 2 5
6 9 8

Sample Output 3

2