K = gets.to_i

x = (4 - K % 4)
n = (K + x) / 2
a = (1 .. K).to_a

for i in 1..x
    a << K + i - n
end

puts n

for i in 0 .. n - 1
    for j in 0 .. n - 1

        k = n * (i % 2) + (i + j) % n
        printf "#{a[k]}"

        if j == n - 1
            puts ""
            break
        end

        printf " "
    end
end