Language: C++

#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; (i) < (long long)(n); ++ (i))
#define REP3(i, m, n) for (long long i = (m); (i) < (long long)(n); ++ (i))
#define REP_R(i, n) for (long long i = (long long)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (long long i = (long long)(n) - 1; (i) >= (long long)(m); -- (i))
#define REPP(i, n) for (long long i = 1; (i) < (long long)(n+1); ++ (i))
#define REPR(i, n) for (long long i = (long long)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(long long i = m; i < n; i++)
#define FORR(i, m, n) for(long long i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) long long((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<long long>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
using namespace std;
using Graph = vector<vector<long long> >;
using WeightedGraph = vector<vector<pair<long long, long long> > >;
typedef long double LD;
typedef vector<long long> VI;
typedef vector<vector<long long> > VVI;
typedef vector<string> VS;
typedef pair<long long, long long> PII;
typedef vector<PII> VPII;
const long long INF = 2000000000;
const long double PI = acosl(-1);
const long long MOD = 1000000007;
void prlong long() {cout << endl;}
template <class Head, class... Tail> void prlong long(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";prlong long(forward<Tail>(tail)...);}
template <class T> void prlong long(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void prlong long(vector<vector<T>> &df) { for (auto& vec : df) { prlong long(vec);}}

long long longest_increasing_subsequence(long long n, vector<long long> &A){
    vector<long long> L(n+1,0);
    L[0] = A[0];
    long long length = 1;

    FOR(i,1,n){
        if (L[length-1] < A[i]) L[length++] = A[i];
        else *lower_bound(L.begin(),next(L.begin(),length),A[i]) = A[i];
    }

    return length;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    long long ans = 0;
    
    long long N;
    cin >> N;
    vector<long long> A(N);
    REP (i, N) {
        cin >> A[i];
    }

    vector<long long> dp(N+1,0);
    dp[0] = 1000;
    FOR(i,1,N+1){
        dp[i] = dp[i-1];
        REP(j,i) {
            dp[i] = max(dp[i], (A[i]-A[j])*(dp[j]/A[j]));
        }
    }
    cout << dp[N] << endl;


    /*

    long long money = 1000;
    long long now = 0;
    REP(i,N-1) {
        while (A[i] >= A[i+1] && i < N-2) {
            i++;
        }
        now = money / A[i];
        money = money % A[i];
        while (A[i] <= A[i+1] && i < N-1) {
            i++;
        }
        money += now * A[i];
        now = 0;
        money = max(1000,money);
    }
    ans = max(1000,money);
    cout << ans << endl;




    
    ans = 1000;
    long long m = INF;
    long long idm = 0;
    REP(i, N) {
        if (m > A[i]) {
            idm = i;
            m = A[i];
        }
    }
    long long M = 0;
    long long idM = 0;
    FOR(i,idm,N) {
        if (M < A[i]) {
            idM = i;
            M = A[i];
        }
    }
    ans = max(ans, 1000/m * M);

    M = 0;
    idM = 0;
    REP(i, N) {
        if (M < A[i]) {
            idM = i;
            M = A[i];
        }
    }
    m = INF;
    idm = 0;
    FOR(i,0,idM) {
        if (m > A[i]) {
            idm = i;
            m = A[i];
        }
    }
    ans = max(ans, 1000/m * M);
    cout << ans << endl;
    */
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/m-solutions2020/m_solutions2020_d && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/m-solutions2020/m_solutions2020_d && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/m-solutions2020/m_solutions2020_d && sh shellscripts/submit_cpp.sh
*/


Compiler output:
a.cc:35:13: error: expected initializer before 'long'
   35 | void prlong long() {cout << endl;}
      |             ^~~~
a.cc:36:50: error: expected initializer before 'long'
   36 | template <class Head, class... Tail> void prlong long(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";prlong long(forward<Tail>(tail)...);}
      |                                                  ^~~~
a.cc:37:32: error: expected initializer before 'long'
   37 | template <class T> void prlong long(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
      |                                ^~~~
a.cc:38:32: error: expected initializer before 'long'
   38 | template <class T> void prlong long(vector<vector<T>> &df) { for (auto& vec : df) { prlong long(vec);}}
      |                                ^~~~