Given N dice, each with faces ranging from 1 to 6, return the minimum number of rotations necessary for all dice to show the same face.
Note that in one rotation, you can rotate a dice to an adjacent face.
For example, you can rotate a dice showing 1 to show 2, 3, 4, or 5. To make it show 6, you need two rotations.
Input
The input consists of the following arguments:
N: a list of integers representing the dice, each with faces ranging from 1 to 6
Output
Return the minimum number of rotations necessary for all dice to show the same face
Examples
Example 1
Input
N = [6, 5, 4]
Output: 2
Example 2:
Input:
N = [6, 6, 1]
Output: 2
Example 3:
Input:
N = [6, 1, 5, 4]
Output: 3