#include #include #include #include #define N 100010 #define inf 0x3f3f3f3f using namespace std; typedef long long ll; int n,sum; int a[N]; int f[N]; int main() { while(scanf("%d",&n)!=EOF) { sum=0; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); sum+=a[i]; int t=(a[i]*1890+143)%10007; a[i]=t-a[i]; } int x=-inf; memset(f,-0x3f,sizeof(f)); f[0]=0; for(int i=1;i<=n;i++) { f[i]=max(a[i],f[i-1]+a[i]); x=max(x,f[i]); } if(x<0)printf("%d\n",sum); else printf("%d\n",sum+x); } return 0; }