require 'date' n = gets.to_i M = 2015 Cycle = 400 * 7 def calc(y) a, res = 0, 0 y.times do |i| a += Date.leap?(M + i) ? 2 : 1 res += 1 if a % 7 == 0 end res end years = n - M + 1 ans = calc(M) * (years / M) + calc(years % M) puts ans