#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    ll N; cin >> N;
    vector<vector<ll>> p(N, vector<ll> (5));
    rep(i,N)rep(j,5) cin >> p[i][j];
    vector<vector<pair<ll,ll>>> x(5, vector<pair<ll,ll>> (N));
    rep(j,5)rep(i,N) x[j][i] ={p[i][j], i};
    rep(j,5) sort(x[j].begin(), x[j].end());

    if(N <= 10){
        ll ans = 0;
        rep(i,N)rep(j,i)rep(k,j){
            ll cnt = 1e18;
            rep(r,5){
                cnt = min(cnt, max({p[i][r], p[j][r], p[k][r]}));
            }
            ans = max(ans, cnt);
        }
        cout << ans << endl;
        return 0;
    }

    ll ans = 0;
    rep(i,N)rep(j,i){
        auto p1 = p[i];
        auto p2 = p[j];
        ll mi = 1e18, id = 0;
        rep(k,5){
            if(mi > max(p1[k], p2[k])){
                mi = max(p1[k], p2[k]);
                id = k;
            }
        }

        ll it = x[id][N - 1].second;
        if(it == i || it == j) it = x[id][N - 2].second;
        if(it == i || it == j) it = x[id][N - 3].second;
        auto p3 = p[it];

        ll cnt = 1e18;
        rep(k,5){
            cnt = min(cnt, max({p1[k], p2[k], p3[k]}));
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  ll N; cin >> N;
  vector<int> op;
  ll x=0,y=0;
  vector<ll> fib={1,1};
  for(int i=2;;i++){
    if(fib[i-1]+fib[i-2]>1e18) break;
    fib.pb(fib[i-1]+fib[i-2]);
  }
  int sf = sz(fib);
  int S=sf-1;
  int t = 0;
  while(1){
    if(x+fib[S-t]<=N){
      op.pb(1);
      N-=fib[S-t];
    }
    op.pb(4);
    t++;
    if(x+fib[S-t]<=N){
      N-=fib[S-t];
      op.pb(2);
    }
    op.pb(3);
    t++;
    if(t>=S) break;
  }
  
  cout << sz(op) << endl;
  rep(i,sz(op)) cout << op[i]  << endl;
  return 0;
}
