N个整数组成的循环序列a[1],a[2],a[3],…,a[n]，求该序列如a[i]+a[i+1]+…+a[j]的连续的子段和的最大值（循环序列是指n个数围成一个圈，因此需要考虑a[n-1],a[n],a[1],a[2]这样的序列）。当所给的整数均为负数时和为0。

Input

Output

Input示例
6
-2
11
-4
13
-5
-2
Output示例
20

`#include<iostream>#include<cstdio>#include<cstdlib>#include<string>#include<cstring>#include<cmath>#include<ctime>#include<algorithm>#include<utility>#include<stack>#include<queue>#include<vector>#include<set>#include<map>#define PI acos(-1.0)#define E 1e-12#define INF 0x3f3f3f3f#define LL long longconst int MOD=1000000007;const int N=100000+5;const int dx[]= {-1,1,0,0};const int dy[]= {0,0,-1,1};using namespace std;deque<int>q;LL sum[N];LL v[N];int main() {    int n;    scanf("%d",&n);    q.clear();    sum[0]=0;    LL ans=-(1<<60);    q.push_back(0);    for(int i=1; i<=n; i++) {        scanf("%lld",&v[i]);        sum[i]=sum[i-1]+v[i];    }    for(int i=n+1; i<=2*n; i++) {        sum[i]=sum[i-1]+v[i-n];    }    for(int i=1; i<=2*n; i++) {        while(!q.empty() && q.front()<i-n) q.pop_front();        ans=max(ans,sum[i]-sum[q.front()]);        while(!q.empty() && sum[q.back()]>=sum[i]) q.pop_back();        q.push_back(i);    }    printf("%lld\n",ans);    return 0;}`

`#include<cstdio>#include<cstring>#include<algorithm>using namespace std; long long a[50010];int main(){  int n;  while(~scanf("%d",&n))  {    memset(a,0,sizeof(a));    long long sum=0;    for(int i=1;i<=n;i++)    {      scanf("%lld",&a[i]);      sum+=a[i];    }    long long ans1=0,sum1=0;    for(int i=1;i<=n;i++)    {      sum1+=a[i];      if(sum1>ans1)        ans1=sum1;      if(sum1<0)        sum1=0;    }        long long ans2,sum2;    for(int i=1;i<=n;i++)    {      sum2+=a[i];      if(sum2<ans2)        ans2=sum2;      if(sum2>0)        sum2=0;    }    printf("%lld\n",max(ans1,sum-ans2));  }  return 0;}`