#d2558. 快快变大

快快变大

Growing Fast

Problem Description

You are given an array a1,a2,…,ana_1, a_2, \dots, a_n of length nn. Then n−1n-1 operations are performed. Each time, choose an index xx and merge axa_x and ax+1a_{x+1} into ax×ax+1 mod 1 000 003a_x \times a_{x+1} \bmod 1\,000\,003, and you gain (ax−ax+1)2(a_x - a_{x+1})^2 points.

So after each operation the length of the array decreases by 11; the operations stop when only one element remains. Output the maximum total score you can finally obtain.

Input Format

The first line contains an integer nn.

The next line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n.

Output Format

One number, the answer.

Sample Input

3
1 2 3

Sample Output

26

Constraints

For all data, 1≤n≤3001 \leq n \leq 300, 1≤ai≤1061 \leq a_i \leq 10^6.