Alice has three different types of sweets. There are
Alice wants to choose three sweets, exactly one of each type. Let the chosen sweets’ tastiness values be
Input Format
- The first line contains a single integer
denoting the number of sweets of each type. - The second line contains
space-separated integers denoting the array . - The third line contains
space-separated integers denoting the array . - The fourth line contains
space-separated integers denoting the array .
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
3 4 2 5 3 2 1 5 5 5
4
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.
Please login to use the editor
You need to be logged in to access the code editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor