CodeEff/ECCO huggingface dataset:
# Original solution
N, X = [int(i) for i in input().split()]
sList = [int(i) for i in input().split()]
sList.sort(reverse=True)
mod = 10 ** 9 + 7

dp = [0 for _ in range(X + 1)]
dp[X] = 1
for i, s in enumerate(sList):
    new_dp = [0 for _ in range(X + 1)]
    for x in range(X + 1):
        new_dp[x] += dp[x] * (N - i - 1)
        new_dp[x] %= mod
        new_dp[x % s] += dp[x]
        new_dp[x % s] %= mod
    dp = new_dp

ans = 0
for i in range(len(dp)):
    ans += i * dp[i]
    ans %= mod

print(ans)

# Optimized solution
from collections import defaultdict as dd

N, X = [int(i) for i in input().split()]
sList = [int(i) for i in input().split()]
sList.sort(reverse=True)
mod = 10 ** 9 + 7

dp = dd(int)
dp[X] = 1
for i, s in enumerate(sList):
    new_dp = dd(int)
    for x in dp:
        new_dp[x] += dp[x] * (N - i - 1)
        new_dp[x] %= mod
        new_dp[x % s] += dp[x]
        new_dp[x % s] %= mod
    dp = new_dp

ans = 0
for x in dp:
    ans += x * dp[x]
    ans %= mod

print(ans)
# Original solution
from collections import defaultdict
n,x = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort(reverse=True)
mod = 10**9+7
rng = 300
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
def inv(a):
  return pow(a,mod-2,mod)
dp = [{} for i in range(n+1)]
dp[0][x] = 1
for i in range(n):
  for j in range(i+1,n+1):
    for k in list(dp[i].keys()):
      num = dp[i][k]
      k %= a[j-1]
      if k in dp[j]:
        dp[j][k] = (dp[j][k]+num*fctr[n-i-1]*inv(fctr[n-j]))%mod
      else:
        dp[j][k] = (num*fctr[n-i-1]*inv(fctr[n-j]))%mod
ans = 0
for i,x in list(dp[n].items()):
  ans = (ans+i*x)%mod
print(ans)

# Optimized solution
from collections import defaultdict
n,x = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort(reverse=True)
mod = 10**9+7
dp = [defaultdict(int) for i in range(n+1)]
dp[0][x] = 1
for i in range(1,n+1):
  for j in list(dp[i-1].keys()):
    k = j%a[i-1]
    dp[i][j] = (dp[i][j]+dp[i-1][j]*(n-i))%mod
    dp[i][k] = (dp[i][k]+dp[i-1][j])%mod
ans = 0
for i,x in list(dp[n].items()):
  ans = (ans+i*x)%mod
print(ans)
# Original solution
mod = 10**9+7
n, X = list(map(int, input().split()))
s = [int(x) for x in input().split()]
s = sorted(s)

dp = [[0 for _ in range(X+1)] for _ in range(n+1)]
inv = [pow(i, mod-2, mod) for i in range(n+1)]

for i in range(n+1):
    if i == 0:
        for x in range(X+1):
            dp[i][x] = x
    else:
        for x in range(X+1):
            dp[i][x] = dp[i-1][x % s[i-1]] * inv[i] + dp[i-1][x]*(1-inv[i])
            dp[i][x] %= mod

ans = dp[n][X]

for i in range(n):
    ans *= i+1
    ans %= mod

print(ans)


# Optimized solution
mod = 10**9+7
n, X = list(map(int, input().split()))
s = [int(x) for x in input().split()]
s = sorted(s)

dp = [[0 for _ in range(X+1)] for _ in range(n+1)]

for i in range(n+1):
    if i == 0:
        for x in range(X+1):
            dp[i][x] = x
    else:
        for x in range(X+1):
            dp[i][x] = dp[i-1][x % s[i-1]] + dp[i-1][x]*(i-1)
            dp[i][x] %= mod

ans = dp[n][X]

print(ans)
# Original solution
x,y,z=list(map(int,input().split()))
n=[i for i in range(z,x-z,y+z)]
if n[-1]+y+z<=x:
  print((len(n)))
else:
  print((len(n)-1))

# Optimized solution
x,y,z=list(map(int,input().split()));print(((x-z)//(y+z)))
# Original solution
x,y,z = list(map(int, input().split()))

print((int((x-z)/(y+z))))

# Optimized solution
x,y,z = list(map(int,input().split()))

print(((x-z)//(y+z)))
# Original solution
# -*- coding utf-8 -*-
x,y,z=list(map(int,input().split()))

print(((x-z)//(y+z)))


# Optimized solution
x,y,z=list(map(int,input().split()))
x=x-z

print((x//(y+z)))
# Original solution
X, Y, Z = (int(x) for x in input().split())

ans = (X-Z)//(Y+Z)
print(ans)

# Optimized solution
X, Y, Z = list(map(int, input().split()))
print(((X-Z)//(Y+Z)))
# Original solution

x,y,z = list(map(int,input().split()))

ans = 0

while (y + z) * ans <= (x - z):
    ans += 1
#    print((y + z) * ans)
#    print(ans)

print((ans-1))


# Optimized solution

x,y,z = list(map(int,input().split()))
ans = int((x-z)//(y+z))
print(ans)
# Original solution
def answer(x: int, y: int, z: int) -> int:
    return (x - z) // (y + z)


def main():
    x, y, z = list(map(int, input().split()))
    print((answer(x, y, z)))


if __name__ == '__main__':
    main()

# Optimized solution
def answer(x: int, y: int, z: int) -> int:
    return len(list(range(y + z * 2, x + 1, y + z)))


def main():
    x, y, z = list(map(int, input().split()))
    print((answer(x, y, z)))


if __name__ == '__main__':
    main()
# Original solution
X, Y, Z = list(map( int, input().split()))
m = X - Z
n = Y + Z
print((m//n))

# Optimized solution
X, Y, Z = list(map( int, input().split()))
m = X - Z
print((m//(Y+Z)))
# Original solution
X,Y,Z=list(map(int,input().split()))

for i in range(1,10**9):
  width=i*Y+(i+1)*Z
  if width>X:
    break

print((i-1))

# Optimized solution
X,Y,Z=list(map(int,input().split()))

answer=0
width=Y+2*Z
while(width<=X):
  answer+=1
  width+=Y+Z
  
print(answer)
# Original solution
x,y,z=list(map(int,input().split()))
w=y+2*z
ans=1
while w<=x-(y+z):
    w+=y+z
    ans+=1
print(ans)

# Optimized solution
x,y,z=list(map(int,input().split()))
ans=(x-z)//(y+z)
print(ans)
# Original solution
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    x, y, z = (int(i) for i in sys.stdin.read().split())
    n = 0
    while True:
        total = (n + 1) * z + n * y
        if total <= x: n += 1; continue
        else:
            if n == 0: print((0))
            else:print((n-1))
            exit()

if __name__ == "__main__":
    # execute only if run as a script
    main()


# Optimized solution
import sys

L, l, d = list(map(int, sys.stdin.readline().split()))

def main():
    x = (L - d) // (l + d)
    return x

if __name__ == '__main__':
    ans = main()
    print(ans)
# Original solution
X, Y, Z = list(map(int, input().split()))
print(((X-Z)//(Y+Z)))

# Optimized solution
x,y,z = list(map(int, input().split()))
x -= z
y += z
print((x//y))
# Original solution
x,y,z = list(map(int,input().split()))
p = y + z + z
c = 0

while p <= x:
    c += 1
    p = p + y + z

print(c)

# Optimized solution
x,y,z = list(map(int,input().split()))
yz = y + z
x -= z
print((x // yz))
# Original solution
x,y,z=list(map(int,input().split()))

x = x - z
sum = 0
cnt = 0
while sum <= x:
    sum += y + z
    cnt += 1
print((cnt - 1))


# Optimized solution
x,y,z=list(map(int,input().split()))
print(((x-z)//(y+z)))
# Original solution
X,Y,Z=list(map(int,input().split()))
ans=0
K=Z
while(True):
    if K+Y+Z>X:
        break
    K+=Y+Z
    ans+=1
print(ans)

# Optimized solution
X,Y,Z=list(map(int,input().split()))
A=X-Z
ans=A//(Y+Z)
print(ans)
# Original solution
x, y, z = list(map(int, input().split()))
cnt = 0
x -= z
while x > 0:
  if x-y-z >= 0:
    x -= y+z
    cnt += 1
  else:
    break
print(cnt)

# Optimized solution
x,y,z=list(map(int,input().split()))
print(((x-z)//(y+z)))
# Original solution
X, Y, Z = list(map(int, input().split()))
for n in range(10 ** 5, 0, -1):
    if X >= n * (Y + Z) + Z:
        break
print(n)

# Optimized solution
X, Y, Z = list(map(int, input().split()))
print(((X - Z) // (Y + Z)))
# Original solution
X, Y, Z = list(map(int, input().split()))
ans = 1
while ans * (Y + Z) + Z <= X:
	ans += 1
print((ans - 1))


# Optimized solution
X, Y, Z = list(map(int, input().split()))
print(((X - Z) // (Y + Z)))
# Original solution
X, Y, Z = list(map(int, input().split()))
ans = 0
X -= Z
while Y+Z <= X:
    X -= Y+Z
    ans += 1
print(ans)

# Optimized solution
X, Y, Z = list(map(int, input().split()))
print(((X - Z) // (Y + Z)))
# Original solution
#!/usr/bin/env python

def main():
    X, Y, Z = list(map(int, input().split(" ")))

    max_num = 0
    for i in range(100000):
        if Y * i + Z * (i + 1) <= X:
            max_num = i
        else:
            break
    print(max_num)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python

def main():
    X, Y, Z = list(map(int, input().split(" ")))

    # max_num = 0
    # for i in range(100000):
    #     if Y * i + Z * (i + 1) <= X:
    #         max_num = i
    #     else:
    #         break
    # print(max_num)

    print((int((X - Z) / (Y + Z))))

if __name__ == '__main__':
    main()
# Original solution
X,Y,Z = list(map(int,input().split()))
print(((X-Z) // (Y+Z)))


# Optimized solution
x,y,z = list(map(int,input().split()))
print(((x-z)//(y+z)))
# Original solution
x, y, z = list(map(int, input().split()))

n = 1

while True:
    if y * n + z * (n+1) <= x:
        n += 1
    else:
        print((n-1))
        break

# Optimized solution
x, y, z = list(map(int, input().split()))

s = z
cnt = 0
while True:
    s += y + z
    if s > x:
        break
    cnt += 1

print(cnt)
# Original solution
X, Y, Z = list(map(int, input().split()))

num = 0

for i in range(1, 100000):
    if X < i * Y + (i - 1) * Z + 2 * Z:
        break
    num = i

print(num)


# Optimized solution
X, Y, Z = list(map(int, input().split()))

for i in range(1, 100000):
    if X < i * Y + (i - 1) * Z + 2 * Z:
        break

print((i - 1))
# Original solution
x,y,z=list(map(int,input().split()))
ans=int(0)
x-=z
while x>=y+z:
    ans+=1
    x-=(y+z)

print(ans)

# Optimized solution
x,y,z=list(map(int,input().split()))
x-=z
print((int(x/(y+z))))
# Original solution
X,Y,Z = list(map(int,input().split()))
X -= Y+2*Z
answer = 1
while X >= Y+Z :
    X -= Y+Z
    answer += 1
print(answer)


# Optimized solution
X,Y,Z = list(map(int,input().split()))
answer = 0
X -= Y+2*Z
answer += 1
answer += X//(Y+Z)
print(answer)
# Original solution
x, y, z = list(map(int, input().split()))
ans = 1

for i in range(x // y):
    ans += 1
    if y * ans + z * (ans + 1) > x:
        print((ans - 1))
        exit()

# Optimized solution
x, y, z = list(map(int, input().split()))
ans = 1

q = x // (y + z)
r = x % (y + z)

if r < z:
    print((q - 1))
else:
    print(q)
# Original solution
#!/usr/bin/env python
# encoding: utf-8


class Solution:
    def __init__(self):
        self.count = 0

    def shell_sort(self):
        array_length = int(input())
        array = []
        # array = list(map(int, sys.stdin.readlines()))
        # array_length = 10
        # array = [15, 12, 8, 9, 3, 2, 7, 2, 11, 1]
        for m in range(array_length):
            array.append(int(input()))

        G = [1]
        while True:
            g = G[0] * 3 + 1
            if g > array_length:
                break
            G.insert(0, g)

        g_length = len(G)
        result = []
        for j in range(g_length):
            result = self.insertion_sort(array=array, array_length=array_length, g=G[j])
            # print(result, 'r', G[j])

        print(g_length)
        print(*G)
        print(self.count)
        print(*result, sep='\n')

    def insertion_sort(self, array, array_length, g):
        # write your code here

        for i in range(g, array_length):
            v = array[i]
            j = i - g
            while j >= 0 and array[j] > v:
                array[j + g] = array[j]
                j -= g
                self.count += 1
            array[j + g] = v

        # print(" ".join(map(str, array)))
        return array


if __name__ == '__main__':
    solution = Solution()
    solution.shell_sort()


# Optimized solution
#!/usr/bin/env python
# encoding: utf-8

import sys


class Solution:
    def __init__(self):
        self.count = 0

    def shell_sort(self):
        _input = sys.stdin.readlines()
        array_length = int(_input[0])
        array = list(map(int, _input[1:]))

        G = [1]
        while True:
            g = G[0] * 3 + 1
            if g > array_length:
                break
            G.insert(0, g)

        g_length = len(G)
        result = []
        for j in range(g_length):
            result = self.insertion_sort(array=array, array_length=array_length, g=G[j])
            # print(result, 'r', G[j])

        print(g_length)
        print(*G)
        print(self.count)
        print(*result, sep='\n')

    def insertion_sort(self, array, array_length, g):
        # write your code here

        for i in range(g, array_length):
            v = array[i]
            j = i - g
            while j >= 0 and array[j] > v:
                array[j + g] = array[j]
                j -= g
                self.count += 1
            array[j + g] = v

        # print(" ".join(map(str, array)))
        return array


if __name__ == '__main__':
    solution = Solution()
    solution.shell_sort()
# Original solution
n = int(input())
A = [int(input()) for _ in range(n)]
cnt = 0
G = [797161,265720,88573,29524,9841,3280,1093,364,121,40,13,4,1]
G = [v for v in G if v <= n]
m = len(G)
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
for g in G:
    insertionSort(A, n, g)
print(m)
print(*G)
print(cnt)
print(*A, sep='\n')


# Optimized solution
import sys
n = int(input())
A=[int(e)for e in sys.stdin]
cnt = 0
G = [797161,265720,88573,29524,9841,3280,1093,364,121,40,13,4,1]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
for g in G:
    insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print(*A,sep='\n')
# Original solution
import sys
n = int(input())
A=list(map(int,sys.stdin))
cnt = 0
G = [int((3**i-1)/2)for i in range(30,0,-1)]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
for g in G:
    insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print(*A,sep='\n')


# Optimized solution
import sys
n = int(input())
A=[int(e)for e in sys.stdin]
cnt = 0
G = [int((3**i-1)/2)for i in range(30,0,-1)]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
for g in G:
    insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print(*A,sep='\n')
# Original solution
def shellsort(a):
    l = len(a)
    intervals = [n for n in (40, 13, 4, 1) if n <= l]
    count = 0
    for interval in intervals:
        for i in range(interval, l):
            j = 0
            while i-interval*(j+1) >= 0:
                n, m = i-interval*j, i-interval*(j+1)
                if a[n] < a[m]:
                    a[n], a[m] = a[m], a[n]
                    j += 1
                    count += 1
                else:
                    break

    print((len(intervals)))
    print((" ".join([str(n) for n in intervals])))
    print(count)
    print(("\n".join([str(n) for n in a])))

shellsort([int(eval(input())) for _ in range(int(eval(input())))])

# Optimized solution
def shellsort(a):
    l = len(a)
    intervals = [n for n in (40, 13, 4, 1) if n <= l]
    count = 0
    for interval in intervals:
        for i in range(interval, l):
            v = a[i]
            j = i-interval
            while j >= 0 and v < a[j]:
                a[j+interval] = a[j]
                j -= interval
                count += 1
            a[j+interval] = v

    print((len(intervals)))
    print((" ".join([str(n) for n in intervals])))
    print(count)
    print(("\n".join([str(n) for n in a])))

shellsort([int(eval(input())) for _ in range(int(eval(input())))])
# Original solution
def insertion_sort(a, n, g):
    count = 0
    for i in range(g, n):
        for j in range(i, g-1, -g):
            if a[j-g] > a[j]:
                a[j-g], a[j] = a[j], a[j-g]
                count += 1

    return a, count


if __name__ == "__main__":
    import sys
    n = int(input())
    a = list(map(int, sys.stdin))
    count = 0

    G = [1]
    while n > 3*G[-1] + 1:
        G.append(3*G[-1] + 1)

    for g in G[::-1]:
        a, cnt = insertion_sort(a, n, g)
        count += cnt

    print(len(G))
    print(*G[::-1])
    print(count)
    print(*a, sep="\n")


# Optimized solution
def insertion_sort(a, n, g):
    count = 0
    for i in range(g, n):
        j = i
        while j >= g and a[j-g] > a[j]:
                a[j-g], a[j] = a[j], a[j-g]
                j -= g
                count += 1

    return a, count


if __name__ == "__main__":
    import sys
    n = int(input())
    a = list(map(int, sys.stdin))
    count = 0

    G = [1]
    while n >= 3*G[-1] + 1:
        G.append(3*G[-1] + 1)

    for g in G[::-1]:
        a, cnt = insertion_sort(a, n, g)
        count += cnt

    print(len(G))
    print(*G[::-1])
    print(count)
    print(*a, sep="\n")
# Original solution
def insertion_sort(A, N, gap):
    cnt = 0
    for i in range(gap, N):
        tmp = A[i]
        j = i - gap
        while j>=0 and A[j] > tmp:
            A[j+gap] = A[j]
            j = j - gap
            cnt = cnt + 1
        A[j+gap] = tmp
    return cnt

def shell_sort(A, N):
    cnt = 0
    gaps = [int((3**item-1)/2) for item in range(1, 100) if int((3**item-1)/2) <= N][::-1]
    m = len(gaps)
    for gap in gaps:
        cnt = cnt + insertion_sort(A, N, gap)
    print(m)
    print((' '.join([str(gap) for gap in gaps])))
    print(cnt)
    for i in range(0, N):
        print((A[i]))


N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]

shell_sort(A, N)

# Optimized solution
def insertion_sort(A, N, gap):
    global cnt
    for i in range(gap, N):
        tmp = A[i]
        j = i - gap
        while j>=0 and A[j] > tmp:
            A[j+gap] = A[j]
            j = j - gap
            cnt += 1
        A[j+gap] = tmp

def shell_sort(A, N):
    gaps = [int((3**item-1)/2) for item in range(1, 100) if int((3**item-1)/2) <= N][::-1]
    m = len(gaps)
    for gap in gaps:
        insertion_sort(A, N, gap)
    print(m)
    print((' '.join([str(gap) for gap in gaps])))
    print(cnt)
    print(('\n'.join([str(item) for item in A])))

cnt = 0
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]

shell_sort(A, N)
# Original solution
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v

n = int(input())
A = [int(input()) for i in range(n)]

cnt = 0
G = []
for i in range(100):
    if n < 1 + 3*i:
        break
    G.append(1 + 3*i)
m = len(G)
G.reverse()
for i in range(m):
    insertionSort(A, n, G[i])

print(m)
print(*G)
print(cnt)
print(*A, sep='\n')


# Optimized solution
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v

n = int(input())
A = [int(input()) for i in range(n)]

cnt = 0
G = [1]
for i in range(99):
    if n < 1 + 3*G[-1]:
        break
    G.append(1 + 3*G[-1])
m = len(G)
G.reverse()
for i in range(m):
    insertionSort(A, n, G[i])

print(m)
print(*G)
print(cnt)
print(*A, sep='\n')
# Original solution
import sys
 
def print_arr(arr):
    for i in range(len(arr)):
        sys.stdout.write(str(arr[i]))
        if i != len(arr) - 1:
            sys.stdout.write(' ')
    print()
 
def insertion_sort(arr, n, g):
    cnt = 0
    for i in range(g, n):
        v = arr[i]
        j = i - g
        while j >= 0 and arr[j] > v:
            arr[j + g] = arr[j]
            j = j - g
            cnt += 1
        arr[j + g] = v
    return cnt
 
def shell_sort(arr, g):
    cnt = 0
    for i in range(len(g)):
        cnt += insertion_sort(arr, len(arr), g[i])
    return cnt
 
def get_gap(n):
    lst = []
    v = 1
    cnt = 1
    while v <= n:
        lst.append(v)
        v += 3**cnt
        cnt += 1
    if len(lst) == 0: lst.append(1)
    return list(reversed(lst))
 
n = int(eval(input()))
arr = [0] * n
for i in range(n):
    arr[i] = int(eval(input()))
 
g = get_gap(n)
m = len(g)
cnt = shell_sort(arr, g)
 
print(m)
print_arr(g)
print(cnt)
for i in range(n):
    print((arr[i]))


# Optimized solution
import sys


def print_A(A):
    for i in range(len(A)):
        sys.stdout.write(str(A[i]))
        if i!= len(A) -1:
            sys.stdout.write(' ')
    print()


def insertionSort(A,n,g):
    cnt = 0
    for i in range(g,n):
        v = A[i]
        j = i - g
        while (j>=0) and (A[j] > v):
            A[j + g] = A[j]
            j -= g
            cnt +=1
        A[j + g] = v
    return cnt

def shellSort(A,n,G):
    cnt = 0
    for i in range(len(G)):
        cnt += insertionSort(A,n,G[i])
    return cnt
        

def get_gap(n):
    G = []
    h = 1
    cnt = 1
    while h <= n:
        G.append(h)
        h = 3*h + 1
        cnt +=1
    if len(G) == 0: G.append(1)
    return list(reversed(G))


n = int(eval(input()))
A = [0] * n
for i in range(n):
    A[i] = int(eval(input()))
    
G = get_gap(n)
m = len(G)
cnt = shellSort(A,n,G)

print(m)
print_A(G)
print(cnt)
for i in range(n):
    print((A[i]))
# Original solution
import sys
readline = sys.stdin.readline
def insertionSort(A, n, g, cnt):
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j -= g
            cnt += 1
        A[j + g] = v
    return cnt
def shellSort(A, n):
    cnt = 0
    h = 4
    G = [1]
    while h < n:
        G += [h]
        h = 3 * h + 1
    m = len(G)
    for i in range(m - 1, -1, -1):
        cnt = insertionSort(A, n, G[i], cnt)
    print(m)
    print(*G[::-1])
    print(cnt)
    print(*A, sep="\n")
n = int(input())
# A = [int(readline()) for _ in range(n)]
A = list(map(int, sys.stdin.readlines()))
shellSort(A, n)



# Optimized solution
import sys
readline = sys.stdin.readline
def insertionSort(A, n, g, cnt):
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j -= g
            cnt += 1
        A[j + g] = v
    return cnt
def shellSort(A, n):
    cnt = 0
    h = 4
    G = [1]
    while h < n:
        G += [h]
        h = 3 * h + 1
    m = len(G)
    for i in range(m - 1, -1, -1):
        cnt = insertionSort(A, n, G[i], cnt)
    print(m)
    print(*G[::-1])
    print(cnt)
    print(*A, sep="\n")
n = int(input())
# A = [int(readline()) for _ in range(n)]
A = list(map(int, sys.stdin))
shellSort(A, n)
# Original solution
def isort(a, n, g):
    global cnt
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j + g] = a[j]
            j -= g
            cnt += 1
        a[j + g] = v

# input data
n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))

# determine m, g
g = [1]
m = 1
while True:
    x = 3 * g[m - 1] + 1
    if x > n: break
    g.append(x)
    m += 1
g = g[::-1]

# 1 output m
print(m)
# 2 output g
print((' '.join(map(str, g))))

# sort it
cnt = 0
for i in range(m):
    isort(a, n, g[i])

# 3 output cnt
print(cnt)
# 4 output sorted a
for i in range(n):
    print((a[i]))

# Optimized solution
import sys

def isort(a, n, g):
    global cnt
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j + g] = a[j]
            j -= g
            cnt += 1
        a[j + g] = v

# input data
n = int(sys.stdin.readline())
a = []
for i in range(n):
    a.append(int(sys.stdin.readline()))

# determine m, g
g = [1]
m = 1
while True:
    x = 3 * g[m - 1] + 1
    if x >= n: break
    g.append(x)
    m += 1
g = g[::-1]

# 1 output m
print(m)
# 2 output g
print((' '.join(map(str, g))))

# sort it
cnt = 0
for i in range(m):
    isort(a, n, g[i])

# 3 output cnt
print(cnt)
# 4 output sorted a
for i in range(n):
    print((a[i]))