import java.util.*;
import java.lang.*;
class Main
{
{
int year=1901;
boolean isLeapYear=false;
int totalSundays=0;
int currentDay=2;//Starts on a Monday
while(year<=2000){
isLeapYear=false;
if((year%4)==0){
if((year%100)==0 && (year%400)==0){
isLeapYear=true;
} else if((year%100)==0 && (year%400)!=0){
isLeapYear=false;
} else {
isLeapYear=true;
}
}
for(int month=1;month<=12;month++){
if(currentDay==7){
totalSundays++;
}
if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12){
//January,March,May,July,August,October,December
currentDay+=3;
} else if(month==4 || month==6 || month==9 || month==11){
//April,June,September,November
currentDay+=2;
} else if(month==2 && isLeapYear){
//February has 29 days in a Leap Year
currentDay+=1;
}
if(currentDay>7){
currentDay=currentDay-7;
}
}
year++;
}
System.
out.
println("The total number of Sundays that fell in the first of the month is: "+totalSundays
); }
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CgpjbGFzcyBNYWluCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJIGludCB5ZWFyPTE5MDE7CiAgICBib29sZWFuIGlzTGVhcFllYXI9ZmFsc2U7CiAgICBpbnQgdG90YWxTdW5kYXlzPTA7CiAgICBpbnQgY3VycmVudERheT0yOy8vU3RhcnRzIG9uIGEgTW9uZGF5CiAgICB3aGlsZSh5ZWFyPD0yMDAwKXsKICAgICAgICBpc0xlYXBZZWFyPWZhbHNlOwogICAgICAgIGlmKCh5ZWFyJTQpPT0wKXsKICAgICAgICAgICAgaWYoKHllYXIlMTAwKT09MCAmJiAoeWVhciU0MDApPT0wKXsKICAgICAgICAgICAgICAgIGlzTGVhcFllYXI9dHJ1ZTsKICAgICAgICAgICAgfSBlbHNlIGlmKCh5ZWFyJTEwMCk9PTAgJiYgKHllYXIlNDAwKSE9MCl7CiAgICAgICAgICAgICAgICBpc0xlYXBZZWFyPWZhbHNlOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgaXNMZWFwWWVhcj10cnVlOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvcihpbnQgbW9udGg9MTttb250aDw9MTI7bW9udGgrKyl7CiAgICAgICAgICAgIGlmKGN1cnJlbnREYXk9PTcpewogICAgICAgICAgICAgICAgdG90YWxTdW5kYXlzKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYobW9udGg9PTEgfHwgbW9udGg9PTMgfHwgbW9udGg9PTUgfHwgbW9udGg9PTcgfHwgbW9udGg9PTggfHwgbW9udGg9PTEwIHx8IG1vbnRoPT0xMil7CiAgICAgICAgICAgIC8vSmFudWFyeSxNYXJjaCxNYXksSnVseSxBdWd1c3QsT2N0b2JlcixEZWNlbWJlcgogICAgICAgICAgICAgICAgY3VycmVudERheSs9MzsKICAgICAgICAgICAgfSBlbHNlIGlmKG1vbnRoPT00IHx8IG1vbnRoPT02IHx8IG1vbnRoPT05IHx8IG1vbnRoPT0xMSl7IAogICAgICAgICAgICAvL0FwcmlsLEp1bmUsU2VwdGVtYmVyLE5vdmVtYmVyCiAgICAgICAgICAgICAgICBjdXJyZW50RGF5Kz0yOyAgICAgICAgICAgICAgCiAgICAgICAgICAgIH0gZWxzZSBpZihtb250aD09MiAmJiBpc0xlYXBZZWFyKXsKICAgICAgICAgICAgLy9GZWJydWFyeSBoYXMgMjkgZGF5cyBpbiBhIExlYXAgWWVhcgogICAgICAgICAgICAgICAgY3VycmVudERheSs9MTsKICAgICAgICAgICAgfSAKCiAgICAgICAgICAgIGlmKGN1cnJlbnREYXk+Nyl7CiAgICAgICAgICAgICAgICBjdXJyZW50RGF5PWN1cnJlbnREYXktNzsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB5ZWFyKys7CiAgICB9CiAgICBTeXN0ZW0ub3V0LnByaW50bG4oIlRoZSB0b3RhbCBudW1iZXIgb2YgU3VuZGF5cyB0aGF0IGZlbGwgaW4gdGhlIGZpcnN0IG9mIHRoZSBtb250aCBpczogIit0b3RhbFN1bmRheXMpOwkKCX0KfQ==