import Data.Int (Int64) import Data.List (genericLength) import Data.Time.Calendar (fromGregorian) import Data.Time.Format (FormatTime, defaultTimeLocale, formatTime) dayOfWeek :: (FormatTime t) => t -> Int dayOfWeek = read . formatTime defaultTimeLocale "%w" naiveCount :: Integral a => a -> a naiveCount x = genericLength . filter (== d) . fmap year2day $ [2015 .. x] where year2day y = dayOfWeek $ fromGregorian (fromIntegral y) 7 23 d = year2day (2014 :: Int) solve :: Integral a => a -> a solve x = naiveCount (2015 + m) + 57 * d where (d, m) = divMod (x - 2015) 400 main :: IO () main = print . solve =<< (readLn :: IO Int64)