Codeforces Round 245 (Div. 1)
D
Tricky Function
Codeforces
2200
原题
← CE →
翻译中…

Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the problem before the contest. Because he wants to make sure Iahub will be the one qualified, he tells Iahub the following task.

翻译中…

You're given an (1-based) array $*a*$ with $*n*$ elements. Let's define function $*f*(*i*, *j*)$ $(1 ≤ *i*, *j* ≤ *n*)$ as $(*i* - *j*)^{2} + *g*(*i*, *j*)^{2}$. Function g is calculated by the following pseudo-code:

翻译中…

int g(int i, int j) {
    int sum = 0;
    for (int k = min(i, j) + 1; k <= max(i, j); k = k + 1)
        sum = sum + a[k];
    return sum;
}

翻译中…

Find a value $*min*_{*i* ≠ *j*}  *f*(*i*, *j*)$.

翻译中…

Probably by now Iahub already figured out the solution to this problem. Can you?

翻译中…

Input

翻译中…

The first line of input contains a single integer $*n*$ ($2 ≤ *n* ≤ 100000$). Next line contains $*n*$ integers $*a*[1]$, $*a*[2]$, ..., $*a*[*n*]$ ($- 10^{4} ≤ *a*[*i*] ≤ 10^{4}$).

翻译中…

Output

翻译中…

Output a single integer — the value of $*min*_{*i* ≠ *j*}  *f*(*i*, *j*)$.

翻译中…

样例

Input #1
4
1 0 0 -1
Output #1
1
InputCopy OutputCopy
Input #2
2
1 -1
Output #2
2
InputCopy OutputCopy
题目信息
题号
429D
时间限制
2 s
内存限制
256 MB
标签
数据结构
分治
计算几何

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