import java.util.Scanner;
public class Solution
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the year: ");
int year = input.nextInt();
System.out.print("Enter the weekday of the first day: ");
int weekday = input.nextInt();
input.close();
String[] stringOfMonths = {"January", "February", "March", "April", "May", "June",
"July", "August", "Sepetember", "October", "November", "December"};
int[] dayOfMonths = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
dayOfMonths[1]++;
int count;
for(int i = 0; i < 12; i++)
{
System.out.println(" " + stringOfMonths[i] + " " + year);
System.out.println("-----------------------------------");
System.out.printf("%5s%5s%5s%5s%5s%5s%5s", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
System.out.println();
count = 0;
for(int j = 0; j < weekday; j++)
{
System.out.printf("%5s", " ");
count++;
}
for(int j = 1; j <= dayOfMonths[i]; j++)
{
System.out.printf("%5d", j);
count++;
if(count == 7)
{
count = 0;
System.out.println();
}
}
weekday = (weekday + dayOfMonths[i]) % 7;
System.out.println("\n\n");
}
}
}