#include #include using namespace std; const int kind = 1 << 15; int dp[15+1][kind + 1]; int main(){ memset(dp,0,sizeof(dp)); int n; cin >> n; int m[15]; for(int i = 0;i < n;i++){ cin >> m[i]; } for(int i = 0;i < n;i++){ dp[1][0+(1 << i)] = m[i]; } for(int i = 1;i < n;i++){ for(int j = 0;j < (1 <> k) % 2 == 0){ int dis=0; for(int l = 0;l < n;l++){ if((j >> l) % 2 == 1) dis += m[l]; } dis = dis % 1000; if(dp[i+1][j + (1 << k)] != 0){ dp[i+1][j + (1 << k)] = min(dp[i+1][j + (1 << k)],dp[i][j] + max(0,m[k]-dis)); }else{ dp[i+1][j + (1 << k)] = dp[i][j] + max(0,m[k]-dis); } } } } } } int ans = 1e9; for(int i = 0;i < 1<