Company: Intuit
Difficulty: medium
Transform the Array You are given two integer arrays: array a of length n and array b of length n+1. You can perform the following operations any number of times in any order at any given time: choose any element of the array a and increase it by 1; choose any element of the array a and decrease it by 1; choose any element of the array a, copy it and append the copy to the end of the array a Your task is to calculate the minimum number of aforementioned operations (possibly zero) required to transform the array a into the array b. It can be shown that under the constraints of the problem, it is always possible. Input The first line contains a single integer, n. The second line contains n integers (a1, a2, a3...an). The third line contains n+1 integers (b1, b2, b3...bn+1). Output Print a single integer — the minimum number of operations (possibly zero) required to transform the array a into the array b. Constraints 1 ≤ n ≤ 2×10 5 1 ≤ a[i] ≤ 10 9 1 ≤ b[i] ≤ 10 9 Examples Example #1 Input