/**************
*	Shell Sort
*************/

#include <iostream>
#include <vector>	//??£?¨?
#include <algorithm>
using namespace std;
typedef vector<int> TList;

void insertionSort(TList* A, int g, int* cnt  ){

	for(unsigned int i=g ; i<(A->size()); i++){
		int v = (*A)[i];
		int j = i-g;
		while(j>=0 && (*A)[j]>v){
			(*A)[j+g] = (*A)[j];
			j = j-g;
			(*cnt)++;
		}
		(*A)[j+g] =v;
	}
	return ;
}
//---------------------------------------------------------
void shellSort(TList* A, TList* G, int* cnt){

	for(unsigned int i=0; i<(G->size()); i++){
		insertionSort(A, (*G)[i], cnt);
	}

	return;
}
//--<<???????????¢??°>>-------------------------------------------------------
int main(){

	//??????????¨????
	cin.tie(0);
	ios::sync_with_stdio(false);
	//??\???
	int n;
	cin >> n;
	vector<int> A;
	A.resize(n);
	for(unsigned int i=0; i< A.size(); i++){
		cin >> A[i];
	}
	
	//??????
	TList G;
//	G.reserve(100);//????????????????´???°???????????£??????????????¨????????????
	int sum = 1;
	while(sum <= n){
	    G.push_back(sum);
		sum = sum * 3 + 1;
	}
	reverse(G.begin(), G.end());

	int cnt = 0;
	shellSort(&A, &G, &cnt);

	//??????
	cout << G.size() << endl;
	for(unsigned int i=0; i<(G.size()); i++){
		cout << G[i];
		if(i!=(G.size()-1)){
			 cout <<" " ;
		}
	}
	cout << endl;
	cout << cnt << endl;
	for(int i=0; i< n; i++){
		cout << A[i]<< endl;
	}

	return 0;
}
//-----------------------------------------------
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  vi dp(N+1);
  rep(i,0,N) dp[i+1]=dp[i]+A[i];
  int ans=INF;
  REP(i,2,N){
    int X=disup(dp,dp[i]/2),Y=disup(dp,(dp[i]+dp[N])/2);
    rep(j,0,(1ll<<2)){
      bitset<2> B(j);
      int P=X,Q=Y;
      if(B.test(0)) P--;
      if(B.test(1)) Q--;
      vi C(4);
      C[0]=dp[P];
      C[1]=dp[i]-dp[P];
      C[2]=dp[Q]-dp[i];
      C[3]=dp[N]-dp[Q];
      sort(ALL(C));
      if(C[0]>0) ans=min(ans,C[3]-C[0]);
    }
  }
  cout<<ans<<endl;
  }
