Sum of Squares, via Transpose
Larkspur Labs checks a batch of machined parts by measuring how far each one sits from its target size. A part measuring under target is as bad as one measuring over, and a single large miss is far worse for the customer than several small ones, so the lab's batch score is built from the squares of the misses rather than the misses themselves: each miss contributes its own square, and the score is what those contributions come to in total.
Task: Print the batch score.
Input
Two lines. The first holds an integer n, the number of parts measured. The second holds n misses separated by single spaces; a miss may be negative, meaning the part came out under target.
Output
One line holding the batch score as a plain integer. Every graded batch scores a whole number.
Example:
Input:
3
1 2 3
Output:
14
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in