Problem:
Score: 400 points

Problem Statement

To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives.

He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows:

A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day.

In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time.

Buy stock: Pay A_i yen and receive one stock.

Sell stock: Sell one stock for A_i yen.

What is the maximum possible amount of money that M-kun can have in the end by trading optimally?

Constraints

2 \leq N \leq 80

100 \leq A_i \leq 200

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N

Output

Print the maximum possible amount of money that M-kun can have in the end, as an integer.

Sample Input 1

7
100 130 130 130 115 115 150

Sample Output 1

1685

In this sample input, M-kun has seven days of trading. One way to have 1685 yen in the end is as follows:

Initially, he has 1000 yen and no stocks.

Day 1: Buy 10 stocks for 1000 yen. Now he has 0 yen.

Day 2: Sell 7 stocks for 910 yen. Now he has 910 yen.

Day 3: Sell 3 stocks for 390 yen. Now he has 1300 yen.

Day 4: Do nothing.

Day 5: Buy 1 stock for 115 yen. Now he has 1185 yen.

Day 6: Buy 10 stocks for 1150 yen. Now he has 35 yen.

Day 7: Sell 11 stocks for 1650 yen. Now he has 1685 yen.

There is no way to have 1686 yen or more in the end, so the answer is 1685.

Sample Input 2

6
200 180 160 140 120 100

Sample Output 2

1000

In this sample input, it is optimal to do nothing throughout the six days, after which we will have 1000 yen.

Sample Input 3

2
157 193

Sample Output 3

1216

In this sample input, it is optimal to buy 6 stocks in Day 1 and sell them in Day 2, after which we will have 1216 yen.

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define debug(n) cout << "DEBUG1 " << n << "\n";
#define debug2(n, m) cout << "DEBUG2 " << n << ' ' << m << "\n";
#define debug3(n, m, x) cout << "DEBUG3 " << n << ' ' << m << ' ' << x << "\n";
#define debug4(n, m, x, y) cout << "DEBUG3 " << n << ' ' << m << ' ' << x << ' ' << y << "\n";
#define ss_def stringstream ss // stringstream, do ss_def(str), then ss >> n (n is int)
#define upzero(n) if (n < 0) n = 0
#pragma GCC optimize("Ofast")
using namespace std;
ll int BtoPmodM(ll int b, ll int p, ll int m) { // (b ^ p) % m (Big Mod)
    b %= m;
    if (p == 0) return 1;
    else if (p % 2 == 0) return (BtoPmodM(b, p / 2, m) * BtoPmodM(b, p / 2, m)) % m; // a^(p/2) * a^(p/2) = a^p
    else if (p % 2 == 1) return (BtoPmodM(b, (p - 1) / 2, m) * BtoPmodM(b, (p - 1) / 2, m) * b) % m; // +1
    else return 0; // a function must return something
}
ll int gcd(ll int a, ll int b) { // Euclidean Algorithm
    if (b == 0) return a;
    else return gcd(b,a % b);
}
bool coprime(ll int a, ll int b) {
    if (gcd(a, b) == 1) return true;
    else return false;
}
ll int factModP(ll int n, ll int p) {
    ll int fac[n - 1];
    fac[0] = 1;
    for (ll int i = 1;i <= n;i++) {
        fac[i] = fac[i - 1] * i % p;
    }
    return fac[n];
}
ll int power(ll int x, ll int y, ll int p) { // x ^ y % p
    ll int res = 1;
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y /= 2; 
        x = (x * x) % p; 
    } 
    return res; 
}
ll int modInverse(ll int n, ll int p) {
    return power(n, p - 2, p); 
}
ll int nCrModP(ll int n, ll int r, ll int p) {
    if (r == 0) return 1;
    else if (r > n) return 0;
    ll int fac[n + 1]; 
    fac[0] = 1; 
    for (ll int i = 1;i <= n;i++) {
        fac[i] = fac[i - 1] * i % p; 
    }
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
}
ll int nCr(ll int n, ll int r) {
    ll int ans = 1;
    if (r >= n - r) {
        for (ll int i = r + 1;i <= n;i++) ans *= i;
        for (ll int i = 1;i <= n - r;i++) ans /= i;
    } else {
        for (ll int i = n - r + 1;i <= n;i++) ans *= i;
        for (ll int i = 1;i <= r;i++) ans /= i;
    }
    return ans;
}
ll int string_to_int(string str) {
	int strl = str.length();
	ll int ans = 0;
	if (str[0] == '-') {
		for (int i = 1;i < strl;i++) ans += pow(10, strl - i - 1) * (str[i] - 48);
		ans = 0 - ans;
		return ans;
	}
	for (int i = 0;i < strl;i++) ans += pow(10, strl - i - 1) * (str[i] - 48);
	return ans;
}
struct edge_stru {
	int u, v, w; // node 1, node 2, weight
};
edge_stru make_edge_stru(int u, int v, int w) {
	edge_stru a = {u, v, w};
	return a;
}
class cmp { // sorting edges
	public:
	bool operator()(edge_stru a, edge_stru b) {
		return a.w > b.w; // sort in ascending order of weight
	}
};
void make_set(int v, int* parent, int* rank) {
    parent[v] = v; // set as the root
    rank[v] = 0; // first rank is 0
    return;
}
int find_set(int v, int* parent) {
    if (v == parent[v]) return v; // finds root
//    return parent[v] = find_set(parent[v], parent); // Path compression optimization
	return find_set(parent[v], parent);
}
void union_sets(int a, int b, int* parent, int* rank) {
//    a = find_set(a, parent); // find root of a
//    b = find_set(b, parent); // find root of b
    if (rank[a] > rank[b]) swap(a, b); // let a be the bigger rank (root a < root b)
    parent[b] = a; // set node b as root a's parent
    if (rank[a] == rank[b]) rank[b]++; // if same rank set b as the child of a
    return;
}
bool binSearch(ll* arr, ll n, ll target) {
    ull l=0, r=n-1;
    while(l<r) {
        int mid=(l+r)/2;
        if(arr[mid]>=target) {
            r=mid;
        }
        else {
            l=mid+1;
        }
    }
    if(arr[l]==target) {
        return true;
    }
    else {
        return false;
    }
}
void solve() {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0;i < n;i++) cin >> a[i];
	ll int tot = 1000;
	for (int i = 1;i < n;i++) {
		if (a[i - 1] < a[i]) {
			int cnt = 0;
			while (tot >= a[i - 1]) {
				tot -= a[i - 1];
				cnt++;
			}
			tot += cnt * a[i];
		}
	}
	cout << tot << endl;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // implementation
    solve();
}