491. Footballers with Arrays

0

Medium

Messi and Ronaldo each have an array of integers, nums1 and nums2, respectively. Both arrays have the same length. In a single operation, they can swap the values at the same index in nums1 and nums2. The goal is to determine the minimum number of operations required to make both nums1 and nums2 strictly increasing.

Input Format

The first line of input contains an integer n, representing the length of the arrays. The second line contains the elements of nums1 (n space-separated integers). The third line contains the elements of nums2 (n space-separated integers).

Output Format

A single integer representing the minimum number of swaps required. The test cases are designed so that it is always possible to achieve the given input.

Example

Input

4 1 3 5 4 1 2 3 7

Output

1

Constraints

- 2 <= nums1.length <= 10^5 - nums2.length == nums1.length - 0 <= nums1[i], nums2[i] <= 2 * 105
Loading...

View Submissions

Console