Alice has three different types of sweets. There are N sweets of each type, and each sweet has a tastiness value. The tastiness values for sweets are given in three arrays A, B, and C. The tastiness value of two sweets of a particular type can differ.
Alice wants to choose three sweets, exactly one of each type. Let the chosen sweets’ tastiness values be a, b, and c. You need to choose the sweets such that the value of the equation abs(a−b)+abs(b−c)+abs(c−a) is minimized. Here, abs(x) is the absolute value function.
Input Format
Output Format
Print the minimum value of the equation mentioned in the problem statement if we can choose exactly one sweet of each type.
Constraints
1≤N≤1051≤A[i],B[i],C[i]≤108
There are 27 possible choices of sweets we can take. The minimum equation value is when we take the triplet with indices (3, 1, 1) or (3, 1, 2), or (1, 1, 1). In the first triplet, the equation value will be abs(A[3] - B[1]) + abs(B[1] - C[1]) + abs(C[1] - A[3]) = abs(5 - 3) + abs(3 - 5) + abs(5 - 5) = 4.