Note: this is a harder version of this problem. The only difference between this problem and that one are the constraints.
Keen Keen Guglor the Keener is keen to know more about a sequence of
Constraints
Input Specification
The first line will contain the integer
The second line will contain the space-separated integers
Output Specification
On one line, output the number of
Sample Input 1
Copy
4
1 2 4 8
Sample Output 1
Copy
8
Explanation for Sample Output 1
Our
Sample Input 2
Copy
4
5 5 5 5
Sample Output 2
Copy
24
Sample Input 3
Copy
10
1 4 8 6 2 9 4 2 5 3
Sample Output 3
Copy
160
Comments
No editorial?
The editorial can be found on the page of the original problem: https://dmoj.ca/problem/rccc1s2