#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
 
const int N = 2e6 + 6;
const int M = 1e9+7;
int A[N];
int n , m;

void solve()
{
	cin >> n;

	loop(i,0,n)cin >> A[i];

	int ok = 0;

	vector<int> vec;
	int i = 0;
	while(i < n)
	{
		if(!ok)
		{
			if(A[i] < A[i+1])
			{
				vec.pb(A[i]);
				int j = i+1;
				while(j < n && A[j] >= A[j-1])j++;
				if(i==n)
				{
					vec.pb(A[n-1]);
				}
				else
				{
				vec.pb(A[j-1]);
				i = j-1;
				}
				ok = 1;
			}
			else i++;
		}
		else
		{
			if(A[i] > A[i+1])
			{
				// cout << i <<  endl;
				int j = i+1;
				while(j < n && A[j] <= A[j-1])j++;
				if(i==n)
				{
					continue;
				}
				else 
				{
					i = j - 1;
				}
				ok = 0;
			}
			else {
				// cout << i << endl;10
				i++;
			}
		}
	}

	int sz = vec.size();
	int cur = 1000;
	if(sz == 0)
	{
		cout << cur << endl;
	}
	else 
	{
		if(sz%2)sz--;
		for(int i = 0; i < sz;i += 2)
		{
			int rt = cur/vec[i];
			cur -= (rt*vec[i]);
			cur += (rt*vec[i+1]);
		}
		cout << cur;
	}
	cout << endl;
	for(auto &it : vec)cout << it << " ";
}			
 
int32_t main()
{
 
cout<<fixed<<setprecision(16);
 
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	
 
 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}