3199.Tricky Function

Time Limit: 1s Memory Limit: 256MB

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 \le i,j \le 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  \le  max(i, j); k = k + 1)
 sum = sum + a[k];
 return sum;
}

Find a value mini \neq jf(i,j).

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

Input Format(From the terminal/stdin)

The first line of input contains a single integer n (2 \le n \le 100000). Next line contains n integers a[1], a[2], ..., a[n] (-104 \le a[i] \le 104).

Output Format(To the terminal/stdout)

Output a single integer - the value of mini \neq jf(i,j).

Sample Input 1

Copy
4
1 0 0 -1
 \n
 · · ·  \n

Sample Output 1

Copy
1
 \n

Sample Input 2

Copy
2
1 -1
 \n
 ·  \n

Sample Output 2

Copy
2
 \n

Submit

请先 登录

© 2025 FAQs