File standardInput readLines map(split map(asNumber)do(y:=at(0);writeln((((at(1)+if(at(1)<3,y=y-1;18,6))*13/5|0)+y+(y/4|0)-(y/100|0)+(y/400|0)+at(2))%7)))