K = gets.to_i

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

if K == 1
    puts "1","1"
else
    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
end