This page is still under construction.

Parts of this page are still being built. What you see may change.

Vertical Calendar

Time limit1sMemory limit512 MB

Level

Not classified yet

Solved
No attempts yet

Problem

Seonghyeon looked closely at a calendar and noticed that some of its columns have 5 cells.

Seonghyeon calls a calendar column with 5 cells a "vertical calendar".

Seonghyeon wants to know how many "vertical calendars" are in the calendar of year NN.

Help Seonghyeon by finding the number of "vertical calendars" in the calendar of year NN.

Input

The first line contains NN. (1 900≤N≤109)(1\ 900 \le N \le 10^9)

The second line contains the day of the week of January 1 of year NN. Days are given as numbers from 1 to 7, which stand for [Sun, Mon, Tue, Wed, Thu, Fri, Sat] in order. The input may differ from the real calendar.

Output

Print the number of "vertical calendars" in the calendar of year NN.

Hint

Account for leap years when calculating.

A year is a leap year if it is a multiple of 4 and not a multiple of 100, or if it is a multiple of 400.

2024 is a multiple of 4 and not a multiple of 100, so it is a leap year.

2100 is a multiple of both 4 and 100. It is not a multiple of 400, so it is not a leap year.

2400 is a multiple of 400, so it is a leap year.

In a common year, February ends on the 28th. In a leap year, it ends on the 29th. So a common year has 365 days and a leap year has 366 days.

Examples1

  1. Example 1

    Input
    2022
    7
    
    Expected output
    29