var y,m,d:comp;begin repeat read(y,m,d);y:=y-ord(m<3);writeln((y+y div 4-y div 100+y div 400+(26*m+312*ord(m<3)+16)div 10+d)mod 7)until 1=0end.