/*
 * d.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 1000000;
const int MAX_M = 20;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

int as[MAX_N], gs[MAX_M];

/* subroutines */
int insertion_sort(int as[], int n, int g) {
  int cnt = 0;
  for (int i = g; i < n; i++) {
    int v = as[i];
    int j = i - g;
    while (j >= 0 && as[j] > v) {
      as[j + g] = as[j];
      j = j - g;
      cnt++;
    }
    as[j + g] = v;
  }
  return cnt;
}

int shell_sort(int as[], int n, int gs[], int m) {
  int cnt = 0;
  for (int i = 0; i < m; i++)
    cnt += insertion_sort(as, n, gs[i]);
  return cnt;
}

/* main */

int main() {
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) cin >> as[i];

  int g;
  for (g = 1; g <= n; g <<= 1);

  int m = 0;
  for (g >>= 1; g > 0; g >>= 1, m++) gs[m] = g;

  int cnt = shell_sort(as, n, gs, m);

  printf("%d\n", m);
  for (int i = 0; i < m; i++) {
    if (i) putchar(' ');
    printf("%d", gs[i]);
  }
  putchar('\n');
  printf("%d\n", cnt);

  for (int i = 0; i < n; i++) printf("%d\n", as[i]);
  
  return 0;
}
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
inline int rd(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 5e5+5, oo = 0x3f3f3f3f;
int n, p, q, l[N], r[N], ans; pii v[N];
int main()
{
    n = rd(), p = oo; for(int i = 1; i <= n; ++i) l[i] = rd(), r[i] = rd(), p = min(p, r[i]), q = max(q, l[i]);
    for(int i = 1; i <= n; ++i) v[i].fi = p-l[i]+1, v[i].se = r[i]-q+1, ans = max(ans, r[i]-l[i]+1+max(p-q+1, 0));
    sort(v+1, v+n+1); for(int i = 1, w = oo; i < n; ++i) w = min(w, v[i].se), ans = max(ans, w+v[i+1].fi);
    printf("%d\n", ans);
    return 0;
}