#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define setbits(n) __builtin_popcountll(n)
#define mkunique(a) sort(a.begin(),a.end()); a.resize(unique(a.begin(),a.end())-a.begin());
#define print(s) for(ll u: s) cout<<u<<" "; cout<<"\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;

ll n;
 
pair<ll,ll> check(vector<ll> fin){
    ll x=0, y=0;
    for(ll i=0;i<fin.size();i++){
        if(fin[i]==1) x++;
        if(fin[i]==2) y++;
        if(fin[i]==3) x=(x+y);
        if(fin[i]==4) y=(x+y);
        //cout<<x<<" "<<y<<"\n";
    }
    return {x,y};
}
 
int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll TT=clock();
 
    vector<ll> f(100);
    f[0]=0; f[1]=1;
    for(ll i=2;i<90;i++)
        f[i]=f[i-1]+f[i-2];
    cin>>n;
    ll cur = n;
    vector<ll> ans;
    while(cur){
        auto it = --upper_bound(f.begin(),f.end(),cur);
        ans.pb(it-f.begin());
        cur = cur - *it;
    }
    //print(ans);
    ll mx = ans[0];
    set<ll> s;
    for(ll i=0;i<ans.size();i++){
        ans[i] = mx - ans[i];
        ans[i]++;
        s.insert(ans[i]);
    }
    assert(s.size()==ans.size());
    //print(ans);
    vector<ll> fin;
    ll j=0;
    for(ll i=1;i<mx;i++){
        if(j<ans.size() && ans[j]==i){
            if(i%2) fin.pb(2);
            else fin.pb(1);
            j++;
        }
        if(i%2) fin.pb(3);
        else fin.pb(4);
    }
    pair<ll,ll> v = check(fin);
    bool rev = false;
    if(v.ss == n) rev = true;
    for(ll &u: fin){
        if(rev){
            if(u==1) u=2;
            else if(u==2) u=1;
            else if(u==3) u=4;
            else u=3;
        }
    }
    assert(check(fin).ff == n);
    cout<<fin.size()<<"\n";
    for(ll u: fin)
        cout<<u<<" ";
 
 
    cerr<<"\n\nTIME: "<<(long double)(clock()-TT)/CLOCKS_PER_SEC<<" sec\n";
    TT = clock();
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x=min(x,y)
#define maxi(x,y) x=max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;
uniform_int_distribution<int> rng(1,1e9);

//DEBUG FUNCTIONS START
#define cerr cout
void __print(int x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = "; _print(x)
#else
#define deb(x...)
#endif
// DEBUG FUNCTIONS END




const int N = 2e6+5;



void solve(){
	
	int n;
	cin>>n;
	vi a(n+1), pos(n+1), pre(n+1);
	int mx = 0, ans = 0;
	fr(i,1,n){
		cin>>a[i];
		pre[i] = pre[i-1] + a[i];
		maxi(mx, pre[i]);
		maxi(ans, pos[i-1] + mx);
		pos[i] = pos[i-1] + pre[i];
	}
	cout << ans;
	
}



signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(15);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
#ifdef aa
    cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

int powm(int a, int b){
    int res = 1;
    while (b) {
        if (b & 1)
            res = (res*a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}
 
int divide(int a, int b) {
    return (a % mod) * powm(b % mod, mod - 2) % mod;
}
 
int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}