AlgoUniversity
  • Go Back
Discussion
Minimum Square Cost :

Author

Lokesh

Difficulty Level : Easy

Submissions : 145

Asked In :

Marks :10

: 2 | : 0

The cost of Array A is defined as:

Σn−11=(A[i]−A[i−1])2, 0 based indexing.

Insert any integer in any place in the array. Find the minimum possible cost after 1 such insertion.

Input

The first line contains 1≤N≤104, denoting the number of elements in array A

Second line contains N integers denoting elements of array A ,1≤A[i]≤105

Output

One Integers denoting minimum cost after 1 insertion

Examples

Input
5
1 3 5 2 10
Output
49
Input
4
4 7 1 4
Output
36

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.