#include #include #include #include #include #include #include #include #define inf 0x3f3f3f3f #define mod 10007 using namespace std; typedef __int64 LL; const int N=100005; LL s[N],f[N],dp[N];int n; int main(){ while(scanf("%d",&n)!=EOF){ LL sum=0; memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++){ scanf("%I64d",&s[i]); f[i]=((1890*s[i]+143)%10007)-s[i]; sum+=s[i]; } LL maxx=0; for(int i=1;i<=n;i++){ dp[i]=max((LL)0,dp[i-1])+f[i]; maxx=max(dp[i],maxx); } printf("%I64d\n",sum+maxx); } return 0; }