#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n = 0;
cin >> n;
vector<int> vec(n);
vector<int> wei(n);
for(int i = 0; i < n; i++)
{
cin >> vec[i];
if(vec[i] % 512 == 0)
{
wei[i] = vec[i] / 512;
}
else
{
wei[i] = vec[i] / 512 + 1;
}
}
int bag = 1474560 / 512;
vector<int> dp(bag+1, 0);
for(int i = 0; i < n; i++)
{
for(int j = bag; j >= wei[i]; j--)
{
dp[j] = max(dp[j], dp[j - wei[i]] + vec[i]);
}
}
cout << dp[bag] << endl;
return 0;
}