时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld
题目描述
Two arrays u and v each with m distinct elements are called equivalent if and only if
%20%3D%20%5Cmathrm%7BRMQ%7D(v%2C%20l%2C%20r))
for all

where
)
denotes the index of the minimum element among

.
Since the array contains distinct elements, the definition of minimum is unambiguous.
Bobo has two arrays a and b each with n distinct elements. Find the maximum number

where

and

are equivalent.
输入描述:
The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains an integer n.
The second line contains n integers
.
The third line contains n integers
.
* 
* 
*
are distinct.
*
are distinct.
* The sum of n does not exceed
.
输出描述:
For each test case, print an integer which denotes the result.
示例1
输入
复制
2
1 2
2 1
3
2 1 3
3 1 2
5
3 1 5 2 4
5 2 4 3 1