cswork / OAOpen practice workspace

VisaOA #16

Longest Selectable Non-Decreasing Subarray

Estimated MediumJudge-ready

Topics (AI-labelled)State Machines

A and B have equal length; for each position of a contiguous subarray, choose exactly one of A[i] or B[i]. Find the longest length that can form a non-decreasing sequence.

Input

n (1≤n≤200000), then two lines with arrays A and B, whose elements have absolute value ≤10⁹; the ranges are site-added.

Output

Output the maximum length.

Example 1

Input:

4
1 3 5 4
2 2 6 7

Output:

4

Example 2

Input:

3
5 4 3
1 2 3

Output:

3

Example 3

Input:

1
3
1

Output:

1

Editorial

Loading solution…