K = gets.to_i
N = (K==1) ? 1 : (K+3)/4*2

grid = Array.new(N){Array.new(N)}
N.times do |i|
    N.times do |j|
        grid[i][j] = (i+j) % N + (j%2) * N
        grid[i][j] -= N if grid[i][j] >= K
    end
end

puts N
grid.each do |row|
    puts row.map{|a| a+1}.join(' ')
end