Array Transformations
We have an array of positive numbers that we need to transform by repeatedly applying the same operation until fewer than two elements remain in the array:
Select two elements with the smallest absolute difference. If there are multiple such pairs, choose the pair with the smallest sum of elements. If there are still multiple pairs, choose any.
Decrease the values of the selected pair by 1.
Remove any zero elements from the array.
The process will naturally conclude after a finite number of steps.
For example, consider an array with 4 elements: {3, 2, 3, 2}. The transformation process proceeds as follows:
Step 1: {3, 2, 3, 2} becomes {3, 1, 3, 1} (decrease elements 2 and 2)
Step 2: {3, 1, 3, 1} becomes {3, 3} (further decrease results in elements 0 and 0, which are removed)
Step 3: {3, 3} becomes {2, 2}
Step 4: {2, 2} becomes {1, 1}
Step 5: {1, 1} becomes { }
We end up with an empty array. Your task is to determine the number of transformation steps.
Input
A single line contains a sequence of numbers separated by commas and spaces, ending with a period. The array size ranges from 1 to 50, and each element can have a value from 1 to 1000.
Output
Output the number of transformation steps for the given array.