#include<bits/stdc++.h>
using namespace std;
#define ll long long

ll dp[80][8001][801],n;

ll solve(ll arr[],ll idx,ll money,ll curr)
{
  //cout<<" at "<<idx<<" "<<money<<" "<<curr<<" "<<dp[idx][money][curr]<<endl;
  if(idx>=n) return money;
  if(dp[idx][money][curr]!=-1) return dp[idx][money][curr];
  dp[idx][money][curr]=0;
  // buy some here or dont buy
  if(money)
  {
  for(int i=0;i<=money/arr[idx];i++)
  {
    dp[idx][money][curr]=max(dp[idx][money][curr],
                          solve(arr,idx+1,money- i*arr[idx],curr+i));
  }
  }
  // sell some here
  for(int i=1;i<=curr;i++)
  {
    dp[idx][money][curr]=max(dp[idx][money][curr],
                        solve(arr,idx+1,money+i*arr[idx],curr-i));
  }
  // dont do anything
  dp[idx][money][curr]=max(dp[idx][money][curr],
                        solve(arr,idx+1,money,curr));
  //cout<<idx<<" "<<money<<" "<<curr<<" "<<dp[idx][money][curr]<<endl;
  return dp[idx][money][curr];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    ll arr[n];for(int i=0;i<n;i++) cin>>arr[i];
    memset(dp,-1,sizeof dp);
    // dp[money][stock_idx][stock_store];
    cout<<solve(arr,0,1000,0);
}