require 'date' Y, N, D = gets.split.map(&:to_i) def c(y) (Date.new(y - 1, 4, 2)..Date.new(y, 4, 1)).to_a.size end d = if D <= 333 D else D + c(Y - 12) - c(Y + 1) end puts [N - [N, d].min, [N, c(Y - 12) - d].min].join(' ')