require 'date'



def cal(year, columns)

  
  
  
  
  
  
  date = Date.new(year, 1, 1, Date::ENGLAND)

  
  months = (1..12).collect do |month|
    rows = [Date::MONTHNAMES[month].center(20), ]

    
    days = []
    date.wday.times { days.push  }
    while date.month == month
      days.push( % date.mday)
      date += 1
    end
    (42 - days.length).times { days.push  }

    days.each_slice(7) { |week| rows.push(week.join ) }
    next rows
  end

  
  
  
  
  
  
  mpr = (columns + 2).div 22
  mpr = 12.div((12 + mpr - 1).div mpr)

  
  width = mpr * 22 - 2

  
  rows = [.center(width), .center(width)]
  months.each_slice(mpr) do |slice|
    slice[0].each_index do |i|
      rows.push(slice.map {|a| a[i]}.join )
    end
  end
  return rows.join()
end


ARGV.length == 1 or abort 






columns = begin Integer(ENV[] || )
          rescue
            begin require 'io/console'; IO.console.winsize[1]
            rescue LoadError
              begin Integer(`tput cols`)
              rescue
                80; end; end; end

puts cal(Integer(ARGV[0]), columns)