#C10132. Transform List into Special List
Transform List into Special List
Transform List into Special List
You are given an integer n and a list of n integers. Your task is to determine the minimum number of operations required to transform the list into a special list. A list is considered special if every element is a multiple of 3.
In one operation, you can either increment or decrement an element by 1. For any integer x, you want to achieve the condition:
\( x \equiv 0 \pmod{3} \)
The minimal operations needed for a number x can be reasoned by calculating its remainder modulo 3. For instance, if \( r = x \bmod 3 \) and \( r \neq 0 \), then you need 1 operation (either adding or subtracting 1) to make \( x \) divisible by 3.
Print the minimum total number of operations required for the entire list.
inputFormat
The input consists of two lines:
- The first line contains a single integer n, the number of elements in the list.
- The second line contains n space-separated integers representing the list elements.
outputFormat
Output a single integer, which is the minimum number of operations required to transform the list into a special list.
## sample4
1 2 3 4
3