#include #include #include #include #include #include #include #include #include #include using namespace std; int bit_count(long long x){ long long ret = 0; while(x){ ret++; x -= x&-x; } return ret; } int main(){ int n; cin >> n; vector m(n); for(int i=0; i> m[i]; } vector dp(1<> bits(n+1); for(int i=0; i<(1<>k)&1){ x += m[k]; } } x %= 1000; for(int k=0; k>k)&1) continue; int& next = dp[s|(1< dfs = [&](int state){ if(state == 0) return 0; if(dp[state] != 1e8) return dp[state]; int ret = 1e8; int x = 0; for(int i=0; i