跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F2036. Tricky Function

    ID: 2042 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>数据结构分治计算几何算法思想数学提高难度共享题库Codeforces英文题面题目来源题面语言

Tricky Function

题目描述

D. Tricky Function
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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,jn) 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 minijf(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] (-104a[i]≤104).

Output

Output a single integer − the value of minijf(i,j).

Examples
Input
4
1 0 0 -1
Output
1
Input
2
1 -1
Output
2

题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 1627 题。保留原作者与原赛事署名。