#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class NewCoins { public:
	int minCoins(vector <int> price) 
	{
		memo.resize(100001, -1);
		return mc(1, price);
	}

	vector<int> memo;
	int mc( int d, const vector<int>& price )
	{
		if( memo[d] != -1 )
			return memo[d];
		if( price.size() == 0 )
			return 0;

		// all 1
		int X = accumulate(price.begin(), price.end(), 0);

		int P = *max_element(price.begin(), price.end());
		for(int p=2; p<=P; ++p)
		{
			int byOne = 0;

			vector<int> p2;
			for(int i=0; i<price.size(); ++i) {
				byOne += price[i] % p;
				if( memo[d*p]==-1 )
					if(price[i] / p) p2.push_back(price[i]/p);
			}
			X = min(X, byOne + mc(d*p, p2));
		}
		return memo[d] = X;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, NewCoins().minCoins(price));}
int main(){

CASE(0)
	int price_[] = {25, 102};
	  vector <int> price(price_, price_+sizeof(price_)/sizeof(*price_)); 
	int _ = 4; 
END
CASE(1)
	int price_[] = {58};
	  vector <int> price(price_, price_+sizeof(price_)/sizeof(*price_)); 
	int _ = 1; 
END
CASE(2)
	int price_[] = {1, 4, 5, 9, 16};
	  vector <int> price(price_, price_+sizeof(price_)/sizeof(*price_)); 
	int _ = 7; 
END
CASE(3)
	int price_[] = {1, 1, 1, 1, 1};
	  vector <int> price(price_, price_+sizeof(price_)/sizeof(*price_)); 
	int _ = 5; 
END
CASE(4)
	int price_[] = {28, 569, 587, 256, 15, 87, 927, 4, 589, 73, 98, 87, 597, 163, 6, 498};
	  vector <int> price(price_, price_+sizeof(price_)/sizeof(*price_)); 
	int _ = 62; 
END
CASE(5)
	int price_[] = {1};
	  vector <int> price(price_, price_+sizeof(price_)/sizeof(*price_)); 
	int _ = 1; 
END
CASE(6)
	int price_[] = {1,2,3,4,5,6,9997,9998,9999,99910,99911,99912,99913,99914,99915,99916,99917,99918,99919,99920,99921,99922,99923,99924,87625,87626,87627,87628,87629,87630,87631,87632,87633,87634,87635,87636,87637,87638,87639,99940,99991,99992,99993,99994,99995,99996,99997,99998,99999,100000};
	  vector <int> price(price_, price_+sizeof(price_)/sizeof(*price_)); 
	int _ = 183; 
END

}
// END CUT HERE
