#GD0000013. Đưa tích về một (Make Product Equal One)
Đưa tích về một (Make Product Equal One)
Make Product Equal One
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers , one operation costs and increments or decrements one element by . Find the minimum total cost to make the product of all elements equal to .
Input
The first line contains . The second line contains integers .
Output
Print the minimum cost.
Subtasks
General constraints:
-
.
-
.
-
Subtask 1 (20 points): ,
-
Subtask 2 (30 points): ,
-
Subtask 3 (50 points): No additional constraints.
Examples
Input
5
-5 -3 5 3 0
Output
13
Explanation
Move for cost , for , for , for , and for . Total cost is , and the two negative values make the product positive.