Codeforces Round 796 (Div. 1)
D
Cute number
Codeforces
2900
原题
← CE →
翻译中…

Ran is especially skilled in computation and mathematics. It is said that she can do unimaginable calculation work in an instant.—Perfect Memento in Strict Sense

翻译中…

Ran Yakumo is a cute girl who loves creating cute Maths problems.

翻译中…

Let $f(x)$ be the minimal square number strictly greater than $x$, and $g(x)$ be the maximal square number less than or equal to $x$. For example, $f(1)=f(2)=g(4)=g(8)=4$.

翻译中…

A positive integer $x$ is cute if $x-g(x) \lt f(x)-x$. For example, $1,5,11$ are cute integers, while $3,8,15$ are not.

翻译中…

Ran gives you an array $a$ of length $n$. She wants you to find the smallest non-negative integer $k$ such that $a_i + k$ is a cute number for any element of $a$.

翻译中…

Input

翻译中…

The first line contains one integer $n$ ($1 \leq n \leq 10^6$) — the length of $a$.

翻译中…

The second line contains $n$ intergers $a_1,a_2,\ldots,a_n$ ($1 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 2\cdot 10^6$) — the array $a$.

翻译中…

Output

翻译中…

Print a single interger $k$ — the answer.

翻译中…

Note

翻译中…

Test case 1:

翻译中…

$3$ is not cute integer, so $k\ne 0$.

翻译中…

$2,4,9,11$ are cute integers, so $k=1$.

翻译中…

样例

Input #1
4
1 3 8 10
Output #1
1
InputCopy OutputCopy
Input #2
5
2 3 8 9 11
Output #2
8
InputCopy OutputCopy
Input #3
8
1 2 3 4 5 6 7 8
Output #3
48
InputCopy OutputCopy
题目信息
题号
1687D
时间限制
2 s
内存限制
256 MB
标签
二分
暴力
数据结构
并查集
模拟
数学

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