def dayoftheweek(year,month,day):
if (year,month,day)==(1900,1,1): return 0
if (month,day)==(1,1): return (dayoftheweek(year-1,12,31)+1)%7
if day==1:
if str(month) in '2468911': return (dayoftheweek(year,month-1,31)+1)%7
if month!=3: return (dayoftheweek(year,month-1,30)+1)%7
if year%4: return (dayoftheweek(year,month-1,28)+1)%7
if year%100: return (dayoftheweek(year,month-1,29)+1)%7
if year%400: return (dayoftheweek(year,month-1,28)+1)%7
if True: return (dayoftheweek(year,month-1,29)+1)%7