ToshibaOA #1
Minimize Multiples Of Three
Estimated EasyJudge-ready
Topics (AI-labelled)Bits & Math
One operation adds 1 to or subtracts 1 from a number. Find the minimum total number of operations needed to make every array element divisible by 3.
This site's standard input/output format and supplementary bounds follow this problem's description.
Input
The first line contains n (1≤n≤2×10^5), and the second line contains n integers (|a[i]|≤10^9).
Output
Output the minimum number of operations.
Example 1
Input:
4
12 21 3 4
Output:
1
Example 2
Input:
2
4 5
Output:
2
Example 3
Input:
3
-2 0 7
Output:
2
Editorial
Loading solution…