r=io.read g=math.floor y=r"*n" while y do m=r"*n"d=r"*n"if m<3 then m=m+12;y=y-1 end print((y+g(y/4)-g(y/100)+g(y/400)+g(2.6*m+1.6)+d)%7)y=r"*n"end