#Lutece1357. 柱爷与最大区间和

柱爷与最大区间和

Migrated from Lutece 1357 柱爷与最大区间和

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

柱爷爱思考,凡事喜欢举一反三,常常能想到别人没想过的问题。

比如最大区间和这个问题:在一数列上选出一段区间,使得这段区间和最大。

柱爷想:如果选出两段区间(不相邻)会怎样呢?

柱爷很快想到了答案,你呢?

Input

第一行输入一个数NN,表示数组的长度。

第二行输入NN个数,表示各元素的值。

数据保证:

  • 3N5000003 \le N \le 500000

  • 100<Ai<100 -100 < A_i < 100

Output

输出一个数,表示数组的两段区间(不相邻)之和的最大值。

Samples

6
2 3 -3 3 -2 4
10

Note

对于样例,选择2,32,33,2,43,-2,4这两个区间,和为1010.

PS.区间不相邻是指前一个区间的最后一个数和后一个区间的第一个数不相邻

Resources

2016 UESTC Training for Dynamic Programming