Example for m=2 and a={1,3,5,2}:
m=2
a={1,3,5,2}
The bruteforce solution is:
1+3+5+2 + 1^3+1^5+1^2+3^5+3^2+5^2 = 34
Do you know