#include #include //#include using ll=long long; #define rep(i,a,b) for(int i=a;i; using PD=pair; using PL=pair; int mod1=998244353; int mod2=1000000007; const ll INF = 1e18; const int big = 2147483647; int value[2000010],NN=1,lazy[2000010]; bool jud[2000010]; struct st{ ll x,y,z; st(ll x=0,ll y=0,ll z=0):x(x),y(y),z(z){} bool operator>(const st &a)const{ return x>a.x; } }; PL dp[100000]; int main(){ ll n,q,y=0,i,z=0,x=0,d=0,k,L,nk,sum=0,T; ll ans=INF,sum2=0,rs=-1e9,cs=0,l=0,h=0,w=0,r=0,X; ll tmp2=0,flag=0,a=0,b=0,c=0,j=0,m=0,p,S,K; ll N,M=0; cin>>N; vectorA(N); rep(i,0,100000)dp[i].fi=INF; rep(i,0,100000)dp[i].se=0; rep(i,0,N)cin>>A[i]; dp[0].fi=0; rep(i,0,1<>j)&1)continue; ll tmp=(dp[i].se)%1000; if(dp[i|(1<dp[i].fi+max(A[j]-tmp,(ll)0)){ dp[i|(1<