Codeforces Round 451 (Div. 2)
E
Squares and not squares
Codeforces
1600
原题
← DF →
翻译中…

Ann and Borya have $*n*$ piles with candies and $*n*$ is even number. There are $*a*_{*i*}$ candies in pile with number $*i*$.

翻译中…

Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is new and doesn't belong to any other pile) or remove one candy (if there is at least one candy in this pile).

翻译中…

Find out minimal number of moves that is required to make exactly $*n* / 2$ piles contain number of candies that is a square of some integer and exactly $*n* / 2$ piles contain number of candies that is not a square of any integer.

翻译中…

Input

翻译中…

First line contains one even integer $*n*$ ($2 ≤ *n* ≤ 200 000$) — number of piles with candies.

翻译中…

Second line contains sequence of integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($0 ≤ *a*_{*i*} ≤ 10^{9}$) — amounts of candies in each pile.

翻译中…

Output

翻译中…

Output minimal number of steps required to make exactly $*n* / 2$ piles contain number of candies that is a square of some integer and exactly $*n* / 2$ piles contain number of candies that is not a square of any integer. If condition is already satisfied output 0.

翻译中…

Note

翻译中…

In first example you can satisfy condition in two moves. During each move you should add one candy to second pile. After it size of second pile becomes $16$. After that Borya and Ann will have two piles with number of candies which is a square of integer (second and fourth pile) and two piles with number of candies which is not a square of any integer (first and third pile).

翻译中…

In second example you should add two candies to any three piles.

翻译中…

样例

Input #1
4
12 14 30 4
Output #1
2
InputCopy OutputCopy
Input #2
6
0 0 0 0 0 0
Output #2
6
InputCopy OutputCopy
Input #3
6
120 110 23 34 25 45
Output #3
3
InputCopy OutputCopy
Input #4
10
121 56 78 81 45 100 1 0 54 78
Output #4
0
InputCopy OutputCopy
题目信息
题号
898E
时间限制
2 s
内存限制
256 MB
标签
构造
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。