#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
using namespace std;
int a[100010];
int main()
{
int n;
int i,j;
__int64 sum,ans,Loli;
int b;
while(~scanf("%d",&n))
{
sum=0;Loli=0;ans=0;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
// cout<<sum<<endl;
for(i=0;i<n;i++)
{
if((a[i]*1890+143)%10007>a[i])
{
ans+=(a[i]*1890+143)%10007-a[i];
}
else if((a[i]*1890+143)%10007<=a[i])
{
ans-=a[i]-(a[i]*1890+143)%10007;
}
if(ans>Loli)
{
Loli=ans;
}
if(ans<0)
{
ans=0;
}
// cout<<ans<<endl;
}
if(Loli>0)
{
printf("%I64d\n",Loli+sum);
}
else
{
printf("%I64d\n",sum);
}
}
return 0;
}