#include#include using namespace std; int max1(int a,int b) { return a>b?a:b; } int dp[10100]; int main() { int n,t,wi[10100],max,p,i,j,s; while(cin>>n) { if(n==0) { break; } max=-1; memset(wi,0,sizeof(wi)); s=0; p=0; for(i=0;i >wi[i]; cin>>t; for(i=0;i max) { max=wi[i]; p=i; } } wi[p]=0; memset(dp,0,sizeof(dp)); if(t<5) cout< =wi[i];j--) { dp[j]=max1(dp[j],dp[j-wi[i]]+wi[i]); } } s=t+5-dp[t]-max; cout<